Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Side by Side Diff: components/user_prefs/tracked/mock_validation_delegate.h

Issue 2782803002: Move tracked prefs into services/preferences/tracked. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_
6 #define COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_
7
8 #include <stddef.h>
9
10 #include <string>
11 #include <vector>
12
13 #include "base/compiler_specific.h"
14 #include "base/macros.h"
15 #include "components/user_prefs/tracked/pref_hash_filter.h"
16 #include "components/user_prefs/tracked/pref_hash_store_transaction.h"
17 #include "services/preferences/public/interfaces/tracked_preference_validation_d elegate.mojom.h"
18
19 class MockValidationDelegate;
20
21 // A mock tracked preference validation delegate for use by tests.
22 class MockValidationDelegateRecord
23 : public base::RefCounted<MockValidationDelegateRecord> {
24 public:
25 struct ValidationEvent {
26 ValidationEvent(
27 const std::string& path,
28 PrefHashStoreTransaction::ValueState state,
29 PrefHashStoreTransaction::ValueState external_validation_state,
30 bool is_personal,
31 PrefHashFilter::PrefTrackingStrategy tracking_strategy)
32 : pref_path(path),
33 value_state(state),
34 external_validation_value_state(external_validation_state),
35 is_personal(is_personal),
36 strategy(tracking_strategy) {}
37
38 std::string pref_path;
39 PrefHashStoreTransaction::ValueState value_state;
40 PrefHashStoreTransaction::ValueState external_validation_value_state;
41 bool is_personal;
42 PrefHashFilter::PrefTrackingStrategy strategy;
43 };
44
45 MockValidationDelegateRecord();
46
47 // Returns the number of recorded validations.
48 size_t recorded_validations_count() const { return validations_.size(); }
49
50 // Returns the number of validations of a given value state.
51 size_t CountValidationsOfState(
52 PrefHashStoreTransaction::ValueState value_state) const;
53
54 // Returns the number of external validations of a given value state.
55 size_t CountExternalValidationsOfState(
56 PrefHashStoreTransaction::ValueState value_state) const;
57
58 // Returns the event for the preference with a given path.
59 const ValidationEvent* GetEventForPath(const std::string& pref_path) const;
60
61 private:
62 friend class MockValidationDelegate;
63 friend class base::RefCounted<MockValidationDelegateRecord>;
64
65 ~MockValidationDelegateRecord();
66
67 // Adds a new validation event.
68 void RecordValidation(
69 const std::string& pref_path,
70 PrefHashStoreTransaction::ValueState value_state,
71 PrefHashStoreTransaction::ValueState external_validation_value_state,
72 bool is_personal,
73 PrefHashFilter::PrefTrackingStrategy strategy);
74
75 std::vector<ValidationEvent> validations_;
76
77 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegateRecord);
78 };
79
80 class MockValidationDelegate
81 : public prefs::mojom::TrackedPreferenceValidationDelegate {
82 public:
83 explicit MockValidationDelegate(
84 scoped_refptr<MockValidationDelegateRecord> record);
85 ~MockValidationDelegate() override;
86
87 // TrackedPreferenceValidationDelegate implementation.
88 void OnAtomicPreferenceValidation(
89 const std::string& pref_path,
90 std::unique_ptr<base::Value> value,
91 PrefHashStoreTransaction::ValueState value_state,
92 PrefHashStoreTransaction::ValueState external_validation_value_state,
93 bool is_personal) override;
94 void OnSplitPreferenceValidation(
95 const std::string& pref_path,
96 const std::vector<std::string>& invalid_keys,
97 const std::vector<std::string>& external_validation_invalid_keys,
98 PrefHashStoreTransaction::ValueState value_state,
99 PrefHashStoreTransaction::ValueState external_validation_value_state,
100 bool is_personal) override;
101
102 private:
103 // Adds a new validation event.
104 void RecordValidation(
105 const std::string& pref_path,
106 PrefHashStoreTransaction::ValueState value_state,
107 PrefHashStoreTransaction::ValueState external_validation_value_state,
108 bool is_personal,
109 PrefHashFilter::PrefTrackingStrategy strategy);
110
111 scoped_refptr<MockValidationDelegateRecord> record_;
112
113 DISALLOW_COPY_AND_ASSIGN(MockValidationDelegate);
114 };
115
116 #endif // COMPONENTS_USER_PREFS_TRACKED_MOCK_VALIDATION_DELEGATE_H_
OLDNEW
« no previous file with comments | « components/user_prefs/tracked/interceptable_pref_filter.cc ('k') | components/user_prefs/tracked/mock_validation_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698