OLD | NEW |
| (Empty) |
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 #ifndef CHROME_BROWSER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ | |
6 #define CHROME_BROWSER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ | |
7 | |
8 #include <string> | |
9 #include <vector> | |
10 | |
11 #include "base/compiler_specific.h" | |
12 #include "base/macros.h" | |
13 #include "chrome/browser/prefs/tracked/pref_hash_filter.h" | |
14 #include "chrome/browser/prefs/tracked/pref_hash_store_transaction.h" | |
15 #include "chrome/browser/prefs/tracked/tracked_preference_validation_delegate.h" | |
16 | |
17 // A mock tracked preference validation delegate for use by tests. | |
18 class MockValidationDelegate : public TrackedPreferenceValidationDelegate { | |
19 public: | |
20 struct ValidationEvent { | |
21 ValidationEvent(const std::string& path, | |
22 PrefHashStoreTransaction::ValueState state, | |
23 bool is_personal, | |
24 PrefHashFilter::PrefTrackingStrategy tracking_strategy) | |
25 : pref_path(path), | |
26 value_state(state), | |
27 is_personal(is_personal), | |
28 strategy(tracking_strategy) {} | |
29 | |
30 std::string pref_path; | |
31 PrefHashStoreTransaction::ValueState value_state; | |
32 bool is_personal; | |
33 PrefHashFilter::PrefTrackingStrategy strategy; | |
34 }; | |
35 | |
36 MockValidationDelegate(); | |
37 ~MockValidationDelegate() override; | |
38 | |
39 // Returns the number of recorded validations. | |
40 size_t recorded_validations_count() const { return validations_.size(); } | |
41 | |
42 // Returns the number of validations of a given value state. | |
43 size_t CountValidationsOfState( | |
44 PrefHashStoreTransaction::ValueState value_state) const; | |
45 | |
46 // Returns the event for the preference with a given path. | |
47 const ValidationEvent* GetEventForPath(const std::string& pref_path) const; | |
48 | |
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; | |
61 | |
62 private: | |
63 // Adds a new validation event. | |
64 void RecordValidation(const std::string& pref_path, | |
65 PrefHashStoreTransaction::ValueState value_state, | |
66 bool is_personal, | |
67 PrefHashFilter::PrefTrackingStrategy strategy); | |
68 | |
69 std::vector<ValidationEvent> validations_; | |
70 | |
71 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate); | |
72 }; | |
73 | |
74 #endif // CHROME_BROWSER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_ | |
OLD | NEW |