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

Side by Side Diff: chrome/browser/prefs/mock_validation_observer.h

Issue 266553002: Add TrackedPreferenceValidationDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test fix Created 6 years, 7 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 | Annotate | Revision Log
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 CHROME_BROWSER_PREFS_MOCK_VALIDATION_OBSERVER_H_
6 #define CHROME_BROWSER_PREFS_MOCK_VALIDATION_OBSERVER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/compiler_specific.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "chrome/browser/prefs/pref_hash_filter.h"
15 #include "chrome/browser/prefs/pref_hash_store_transaction.h"
16 #include "chrome/browser/prefs/tracked/tracked_preference_helper.h"
17 #include "chrome/browser/prefs/tracked/tracked_preference_validation_observer.h"
18
19 // A mock tracked preference validation observer for use by tests.
20 class MockValidationObserver : public TrackedPreferenceValidationObserver {
21 public:
22 // A container of observed validation events.
23 class ValidationData : public base::RefCounted<ValidationData> {
Mattias Nissler (ping if slow) 2014/05/15 14:32:25 Is there a good reason to split the observer imple
grt (UTC plus 2) 2014/05/15 18:21:35 This is a consequence of the decision to have owne
24 public:
25 struct ValidationEvent {
26 ValidationEvent(const std::string& path,
27 PrefHashStoreTransaction::ValueState state,
28 TrackedPreferenceHelper::ResetAction action,
29 PrefHashFilter::PrefTrackingStrategy tracking_strategy)
30 : pref_path(path),
31 value_state(state),
32 reset_action(action),
33 strategy(tracking_strategy) {}
34
35 std::string pref_path;
36 PrefHashStoreTransaction::ValueState value_state;
37 TrackedPreferenceHelper::ResetAction reset_action;
38 PrefHashFilter::PrefTrackingStrategy strategy;
39 };
40 ValidationData();
41
42 // Adds a new validation event.
43 void RecordValidation(const std::string& pref_path,
44 PrefHashStoreTransaction::ValueState value_state,
45 TrackedPreferenceHelper::ResetAction reset_action,
46 PrefHashFilter::PrefTrackingStrategy strategy);
47
48 // Returns the number of recorded validations.
49 size_t recorded_validations_count() const { return validations_.size(); }
50
51 // Returns the number of validations of a given value state.
52 size_t CountValidationsOfState(
53 PrefHashStoreTransaction::ValueState value_state) const;
54
55 // Returns the event for the preference with a given path.
56 const ValidationEvent* GetEventForPath(const std::string& pref_path) const;
57
58 // Returns all recorded validation.
59 void GetAllEvents(std::vector<ValidationEvent>* validations) const;
60
61 private:
62 friend class base::RefCounted<ValidationData>;
63 ~ValidationData();
64
65 std::vector<ValidationEvent> validations_;
66 DISALLOW_COPY_AND_ASSIGN(ValidationData);
67 };
68
69 explicit MockValidationObserver(
70 const scoped_refptr<ValidationData>& validation_data);
71 virtual ~MockValidationObserver();
72
73 // TrackedPreferenceValidationObserver implementation.
74 virtual void OnAtomicPreferenceValidation(
75 const std::string& pref_path,
76 const base::Value* value,
77 PrefHashStoreTransaction::ValueState value_state,
78 TrackedPreferenceHelper::ResetAction reset_action) OVERRIDE;
79 virtual void OnSplitPreferenceValidation(
80 const std::string& pref_path,
81 const base::DictionaryValue* dict_value,
82 const std::vector<std::string>& invalid_keys,
83 PrefHashStoreTransaction::ValueState value_state,
84 TrackedPreferenceHelper::ResetAction reset_action) OVERRIDE;
85
86 private:
87 scoped_refptr<ValidationData> validation_data_;
88 DISALLOW_COPY_AND_ASSIGN(MockValidationObserver);
89 };
90
91 #endif // CHROME_BROWSER_PREFS_MOCK_VALIDATION_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698