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.
5 #ifndef CHROME_BROWSER_PREFS_MOCK_VALIDATION_DELEGATE_H_
6 #define CHROME_BROWSER_PREFS_MOCK_VALIDATION_DELEGATE_H_
11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "chrome/browser/prefs/pref_hash_filter.h"
14 #include "chrome/browser/prefs/pref_hash_store_transaction.h"
15 #include "chrome/browser/prefs/tracked/tracked_preference_helper.h"
16 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h"
18 // A mock tracked preference validation delegate for use by tests.
19 class MockValidationDelegate
: public TrackedPreferenceValidationDelegate
{
21 struct ValidationEvent
{
22 ValidationEvent(const std::string
& path
,
23 PrefHashStoreTransaction::ValueState state
,
24 TrackedPreferenceHelper::ResetAction action
,
25 PrefHashFilter::PrefTrackingStrategy tracking_strategy
)
29 strategy(tracking_strategy
) {}
31 std::string pref_path
;
32 PrefHashStoreTransaction::ValueState value_state
;
33 TrackedPreferenceHelper::ResetAction reset_action
;
34 PrefHashFilter::PrefTrackingStrategy strategy
;
37 MockValidationDelegate();
38 virtual ~MockValidationDelegate();
40 // Returns the number of recorded validations.
41 size_t recorded_validations_count() const { return validations_
.size(); }
43 // Returns the number of validations of a given value state.
44 size_t CountValidationsOfState(
45 PrefHashStoreTransaction::ValueState value_state
) const;
47 // Returns the event for the preference with a given path.
48 const ValidationEvent
* GetEventForPath(const std::string
& pref_path
) const;
50 // TrackedPreferenceValidationDelegate implementation.
51 virtual void OnAtomicPreferenceValidation(
52 const std::string
& pref_path
,
53 const base::Value
* value
,
54 PrefHashStoreTransaction::ValueState value_state
,
55 TrackedPreferenceHelper::ResetAction reset_action
) OVERRIDE
;
56 virtual void OnSplitPreferenceValidation(
57 const std::string
& pref_path
,
58 const base::DictionaryValue
* dict_value
,
59 const std::vector
<std::string
>& invalid_keys
,
60 PrefHashStoreTransaction::ValueState value_state
,
61 TrackedPreferenceHelper::ResetAction reset_action
) OVERRIDE
;
64 // Adds a new validation event.
65 void RecordValidation(const std::string
& pref_path
,
66 PrefHashStoreTransaction::ValueState value_state
,
67 TrackedPreferenceHelper::ResetAction reset_action
,
68 PrefHashFilter::PrefTrackingStrategy strategy
);
70 std::vector
<ValidationEvent
> validations_
;
72 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate
);
75 #endif // CHROME_BROWSER_PREFS_MOCK_VALIDATION_DELEGATE_H_