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 COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_
6 #define COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_
11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "components/user_prefs/tracked/pref_hash_filter.h"
14 #include "components/user_prefs/tracked/pref_hash_store_transaction.h"
15 #include "components/user_prefs/tracked/tracked_preference_validation_delegate.h"
17 // A mock tracked preference validation delegate for use by tests.
18 class MockValidationDelegate
: public TrackedPreferenceValidationDelegate
{
20 struct ValidationEvent
{
21 ValidationEvent(const std::string
& path
,
22 PrefHashStoreTransaction::ValueState state
,
24 PrefHashFilter::PrefTrackingStrategy tracking_strategy
)
27 is_personal(is_personal
),
28 strategy(tracking_strategy
) {}
30 std::string pref_path
;
31 PrefHashStoreTransaction::ValueState value_state
;
33 PrefHashFilter::PrefTrackingStrategy strategy
;
36 MockValidationDelegate();
37 ~MockValidationDelegate() override
;
39 // Returns the number of recorded validations.
40 size_t recorded_validations_count() const { return validations_
.size(); }
42 // Returns the number of validations of a given value state.
43 size_t CountValidationsOfState(
44 PrefHashStoreTransaction::ValueState value_state
) const;
46 // Returns the event for the preference with a given path.
47 const ValidationEvent
* GetEventForPath(const std::string
& pref_path
) const;
49 // TrackedPreferenceValidationDelegate implementation.
50 void OnAtomicPreferenceValidation(
51 const std::string
& pref_path
,
52 const base::Value
* value
,
53 PrefHashStoreTransaction::ValueState value_state
,
54 bool is_personal
) override
;
55 void OnSplitPreferenceValidation(
56 const std::string
& pref_path
,
57 const base::DictionaryValue
* dict_value
,
58 const std::vector
<std::string
>& invalid_keys
,
59 PrefHashStoreTransaction::ValueState value_state
,
60 bool is_personal
) override
;
63 // Adds a new validation event.
64 void RecordValidation(const std::string
& pref_path
,
65 PrefHashStoreTransaction::ValueState value_state
,
67 PrefHashFilter::PrefTrackingStrategy strategy
);
69 std::vector
<ValidationEvent
> validations_
;
71 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate
);
74 #endif // COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_