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

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: fix expectations for android and cros 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/memory/ref_counted.h"
12 #include "chrome/browser/prefs/pref_hash_filter.h"
13 #include "chrome/browser/prefs/tracked/tracked_preference_validation_observer.h"
14
15 // A mock tracked preference validation observer for use by tests.
16 class MockValidationObserver : public TrackedPreferenceValidationObserver {
17 public:
18 // A container of observed validation events.
19 class ValidationData : public base::RefCounted<ValidationData> {
erikwright (departed) 2014/05/14 00:39:26 Personally I would just make this a regular class,
grt (UTC plus 2) 2014/05/14 18:57:22 If you don't mind, I'm inclined to leave this as-i
20 public:
21 struct ValidationEvent {
22 ValidationEvent(const std::string& path,
23 PrefHashStoreTransaction::ValueState state,
24 TrackedPreferenceHelper::ResetAction action,
25 PrefHashFilter::PrefTrackingStrategy tracking_strategy)
26 : pref_path(path),
27 value_state(state),
28 reset_action(action),
29 strategy(tracking_strategy) {}
30
31 std::string pref_path;
erikwright (departed) 2014/05/14 00:39:26 #include pref_hash_store_transaction, tracked_pref
grt (UTC plus 2) 2014/05/14 18:57:22 Since these types are used here as a consequence o
erikwright (departed) 2014/05/14 21:24:06 My rule of thumb is that you don't need to include
grt (UTC plus 2) 2014/05/15 01:43:11 That makes sense, and is consistent with the name
erikwright (departed) 2014/05/15 13:49:02 You often won't end up with a compile error as the
32 PrefHashStoreTransaction::ValueState value_state;
33 TrackedPreferenceHelper::ResetAction reset_action;
34 PrefHashFilter::PrefTrackingStrategy strategy;
35 };
36 ValidationData();
37
38 // Adds a new validation event.
39 void RecordValidation(const std::string& pref_path,
40 PrefHashStoreTransaction::ValueState value_state,
41 TrackedPreferenceHelper::ResetAction reset_action,
42 PrefHashFilter::PrefTrackingStrategy strategy);
43
44 // Returns the number of recorded validations.
45 size_t recorded_validations_count() const { return validations_.size(); }
46
47 // Returns the number of validations of a given value state.
48 size_t CountValidationsOfState(
49 PrefHashStoreTransaction::ValueState value_state) const;
50
51 // Returns the event for the preference with a given path.
52 const ValidationEvent* GetEventForPath(const std::string& pref_path) const;
53
54 // Returns all recorded validation.
55 void GetAllEvents(std::vector<ValidationEvent>* validations) const;
56
57 private:
58 friend class base::RefCounted<ValidationData>;
59 ~ValidationData();
60
61 std::vector<ValidationEvent> validations_;
62 DISALLOW_COPY_AND_ASSIGN(ValidationData);
erikwright (departed) 2014/05/14 00:39:26 base/macros.h
grt (UTC plus 2) 2014/05/14 18:57:22 Done.
63 };
64
65 explicit MockValidationObserver(
66 const scoped_refptr<ValidationData>& validation_data);
67 virtual ~MockValidationObserver();
68
69 virtual void OnAtomicPreferenceValidation(
70 const std::string& pref_path,
erikwright (departed) 2014/05/14 00:39:26 // ValidationObserver implementation
grt (UTC plus 2) 2014/05/14 18:57:22 Done.
71 const base::Value* value,
72 PrefHashStoreTransaction::ValueState value_state,
73 TrackedPreferenceHelper::ResetAction reset_action) OVERRIDE;
erikwright (departed) 2014/05/14 00:39:26 base/compiler_specific.h
grt (UTC plus 2) 2014/05/14 18:57:22 Done.
74 virtual void OnSplitPreferenceValidation(
75 const std::string& pref_path,
76 const base::DictionaryValue* dict_value,
77 const std::vector<std::string>& invalid_keys,
78 PrefHashStoreTransaction::ValueState value_state,
79 TrackedPreferenceHelper::ResetAction reset_action) OVERRIDE;
80
81 private:
82 scoped_refptr<ValidationData> validation_data_;
83 DISALLOW_COPY_AND_ASSIGN(MockValidationObserver);
84 };
85
86 #endif // CHROME_BROWSER_PREFS_MOCK_VALIDATION_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698