1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/prefs/mock_validation_delegate.h"
6
7MockValidationDelegate::MockValidationDelegate() {
8}
9
10MockValidationDelegate::~MockValidationDelegate() {
11}
12
13size_t MockValidationDelegate::CountValidationsOfState(
14    PrefHashStoreTransaction::ValueState value_state) const {
15  size_t count = 0;
16  for (size_t i = 0; i < validations_.size(); ++i) {
17    if (validations_[i].value_state == value_state)
18      ++count;
19  }
20  return count;
21}
22
23const MockValidationDelegate::ValidationEvent*
24MockValidationDelegate::GetEventForPath(const std::string& pref_path) const {
25  for (size_t i = 0; i < validations_.size(); ++i) {
26    if (validations_[i].pref_path == pref_path)
27      return &validations_[i];
28  }
29  return NULL;
30}
31
32void MockValidationDelegate::OnAtomicPreferenceValidation(
33    const std::string& pref_path,
34    const base::Value* value,
35    PrefHashStoreTransaction::ValueState value_state,
36    TrackedPreferenceHelper::ResetAction reset_action) {
37  RecordValidation(pref_path,
38                   value_state,
39                   reset_action,
40                   PrefHashFilter::TRACKING_STRATEGY_ATOMIC);
41}
42
43void MockValidationDelegate::OnSplitPreferenceValidation(
44    const std::string& pref_path,
45    const base::DictionaryValue* dict_value,
46    const std::vector<std::string>& invalid_keys,
47    PrefHashStoreTransaction::ValueState value_state,
48    TrackedPreferenceHelper::ResetAction reset_action) {
49  RecordValidation(pref_path,
50                   value_state,
51                   reset_action,
52                   PrefHashFilter::TRACKING_STRATEGY_SPLIT);
53}
54
55void MockValidationDelegate::RecordValidation(
56    const std::string& pref_path,
57    PrefHashStoreTransaction::ValueState value_state,
58    TrackedPreferenceHelper::ResetAction reset_action,
59    PrefHashFilter::PrefTrackingStrategy strategy) {
60  validations_.push_back(
61      ValidationEvent(pref_path, value_state, reset_action, strategy));
62}
63