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

Side by Side Diff: chrome/browser/ui/webui/options/preferences_browsertest.h

Issue 2606293002: Remove ScopedVector from chrome/browser/ui. (Closed)
Patch Set: nits Created 3 years, 11 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_PREFERENCES_BROWSERTEST_H_ 5 #ifndef CHROME_BROWSER_UI_WEBUI_OPTIONS_PREFERENCES_BROWSERTEST_H_
6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_PREFERENCES_BROWSERTEST_H_ 6 #define CHROME_BROWSER_UI_WEBUI_OPTIONS_PREFERENCES_BROWSERTEST_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_vector.h"
15 #include "chrome/test/base/in_process_browser_test.h" 14 #include "chrome/test/base/in_process_browser_test.h"
16 #include "components/policy/core/common/mock_configuration_policy_provider.h" 15 #include "components/policy/core/common/mock_configuration_policy_provider.h"
17 #include "components/policy/core/common/policy_types.h" 16 #include "components/policy/core/common/policy_types.h"
18 #include "components/prefs/pref_change_registrar.h" 17 #include "components/prefs/pref_change_registrar.h"
19 #include "components/prefs/pref_service.h" 18 #include "components/prefs/pref_service.h"
20 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
21 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
22 21
23 namespace base { 22 namespace base {
24 class DictionaryValue; 23 class DictionaryValue;
(...skipping 24 matching lines...) Expand all
49 // The pref service that holds the current pref values in the C++ backend. 48 // The pref service that holds the current pref values in the C++ backend.
50 PrefService* pref_service(); 49 PrefService* pref_service();
51 50
52 void SetUpPrefs(); 51 void SetUpPrefs();
53 52
54 // InProcessBrowserTest implementation: 53 // InProcessBrowserTest implementation:
55 void SetUpInProcessBrowserTestFixture() override; 54 void SetUpInProcessBrowserTestFixture() override;
56 55
57 // Sets user policies through the mock policy provider. 56 // Sets user policies through the mock policy provider.
58 void SetUserPolicies(const std::vector<std::string>& names, 57 void SetUserPolicies(const std::vector<std::string>& names,
59 const std::vector<base::Value*>& values, 58 const std::vector<std::unique_ptr<base::Value>>& values,
60 policy::PolicyLevel level); 59 policy::PolicyLevel level);
61 // Clears user policies. 60 // Clears user policies.
62 void ClearUserPolicies(); 61 void ClearUserPolicies();
63 // Set user-modified pref values directly in the C++ backend. 62 // Set user-modified pref values directly in the C++ backend.
64 void SetUserValues(const std::vector<std::string>& names, 63 void SetUserValues(const std::vector<std::string>& names,
65 const std::vector<base::Value*>& values); 64 const std::vector<std::unique_ptr<base::Value>>& values);
66 65
67 // Verifies that a dictionary contains a (key, value) pair. Takes ownership of 66 // Verifies that a dictionary contains a (key, value) pair. Takes ownership of
68 // |expected|. 67 // |expected|.
69 void VerifyKeyValue(const base::DictionaryValue& dict, 68 void VerifyKeyValue(const base::DictionaryValue& dict,
70 const std::string& key, 69 const std::string& key,
71 const base::Value& expected); 70 const base::Value& expected);
72 // Verifies that a dictionary contains a given pref and that its value has 71 // Verifies that a dictionary contains a given pref and that its value has
73 // been decorated correctly. 72 // been decorated correctly.
74 void VerifyPref(const base::DictionaryValue* prefs, 73 void VerifyPref(const base::DictionaryValue* prefs,
75 const std::string& name, 74 const std::string& name,
76 const base::Value* value, 75 const std::unique_ptr<base::Value>& value,
77 const std::string& controlledBy, 76 const std::string& controlledBy,
78 bool disabled, 77 bool disabled,
79 bool uncommitted); 78 bool uncommitted);
80 // Verifies that a notification received from the JavaScript Preferences 79 // Verifies that a notification received from the JavaScript Preferences
81 // class contains a given pref and that its value has been decorated 80 // class contains a given pref and that its value has been decorated
82 // correctly. 81 // correctly.
83 void VerifyObservedPref(const std::string& observed_json, 82 void VerifyObservedPref(const std::string& observed_json,
84 const std::string& name, 83 const std::string& name,
85 const base::Value* value, 84 const std::unique_ptr<base::Value>& value,
86 const std::string& controlledBy, 85 const std::string& controlledBy,
87 bool disabled, 86 bool disabled,
88 bool uncommitted); 87 bool uncommitted);
89 // Verifies that notifications received from the JavaScript Preferences class 88 // Verifies that notifications received from the JavaScript Preferences class
90 // contain the given prefs and that their values have been decorated 89 // contain the given prefs and that their values have been decorated
91 // correctly. 90 // correctly.
92 void VerifyObservedPrefs(const std::string& observed_json, 91 void VerifyObservedPrefs(
93 const std::vector<std::string>& names, 92 const std::string& observed_json,
94 const std::vector<base::Value*>& values, 93 const std::vector<std::string>& names,
95 const std::string& controlledBy, 94 const std::vector<std::unique_ptr<base::Value>>& values,
96 bool disabled, 95 const std::string& controlledBy,
97 bool uncommitted); 96 bool disabled,
97 bool uncommitted);
98 98
99 // Sets up the expectation that the JavaScript Preferences class will make no 99 // Sets up the expectation that the JavaScript Preferences class will make no
100 // change to a user-modified pref value in the C++ backend. 100 // change to a user-modified pref value in the C++ backend.
101 void ExpectNoCommit(const std::string& name); 101 void ExpectNoCommit(const std::string& name);
102 // Sets up the expectation that the JavaScript Preferences class will set a 102 // Sets up the expectation that the JavaScript Preferences class will set a
103 // user-modified pref value in the C++ backend. 103 // user-modified pref value in the C++ backend.
104 void ExpectSetCommit(const std::string& name, 104 void ExpectSetCommit(const std::string& name,
105 const base::Value* value); 105 const std::unique_ptr<base::Value>& value);
106 // Sets up the expectation that the JavaScript Preferences class will clear a 106 // Sets up the expectation that the JavaScript Preferences class will clear a
107 // user-modified pref value in the C++ backend. 107 // user-modified pref value in the C++ backend.
108 void ExpectClearCommit(const std::string& name); 108 void ExpectClearCommit(const std::string& name);
109 // Verifies that previously set expectations are met and clears them. 109 // Verifies that previously set expectations are met and clears them.
110 void VerifyAndClearExpectations(); 110 void VerifyAndClearExpectations();
111 111
112 // Sets up the JavaScript part of the test environment. 112 // Sets up the JavaScript part of the test environment.
113 void SetupJavaScriptTestEnvironment( 113 void SetupJavaScriptTestEnvironment(
114 const std::vector<std::string>& pref_names, 114 const std::vector<std::string>& pref_names,
115 std::string* observed_json) const; 115 std::string* observed_json) const;
116 116
117 // Sets a value through the JavaScript Preferences class as if the user had 117 // Sets a value through the JavaScript Preferences class as if the user had
118 // modified it. Returns the observation which can be verified using the 118 // modified it. Returns the observation which can be verified using the
119 // VerifyObserved* methods. 119 // VerifyObserved* methods.
120 void SetPref(const std::string& name, 120 void SetPref(const std::string& name,
121 const std::string& type, 121 const std::string& type,
122 const base::Value* value, 122 const std::unique_ptr<base::Value>& value,
123 bool commit, 123 bool commit,
124 std::string* observed_json); 124 std::string* observed_json);
125 125
126 // Verifies that setting a user-modified pref value through the JavaScript 126 // Verifies that setting a user-modified pref value through the JavaScript
127 // Preferences class fires the correct notification in JavaScript and commits 127 // Preferences class fires the correct notification in JavaScript and commits
128 // the change to C++ if |commit| is true. 128 // the change to C++ if |commit| is true.
129 void VerifySetPref(const std::string& name, 129 void VerifySetPref(const std::string& name,
130 const std::string& type, 130 const std::string& type,
131 const base::Value* value, 131 const std::unique_ptr<base::Value>& value,
132 bool commit); 132 bool commit);
133 // Verifies that clearing a user-modified pref value through the JavaScript 133 // Verifies that clearing a user-modified pref value through the JavaScript
134 // Preferences class fires the correct notification in JavaScript and does 134 // Preferences class fires the correct notification in JavaScript and does
135 // respectively does not cause the change to be committed to the C++ backend. 135 // respectively does not cause the change to be committed to the C++ backend.
136 void VerifyClearPref(const std::string& name, 136 void VerifyClearPref(const std::string& name,
137 const base::Value* value, 137 const std::unique_ptr<base::Value>& value,
138 bool commit); 138 bool commit);
139 // Verifies that committing a previously made change of a user-modified pref 139 // Verifies that committing a previously made change of a user-modified pref
140 // value through the JavaScript Preferences class fires the correct 140 // value through the JavaScript Preferences class fires the correct
141 // notification in JavaScript. 141 // notification in JavaScript.
142 void VerifyCommit(const std::string& name, 142 void VerifyCommit(const std::string& name,
143 const base::Value* value, 143 const std::unique_ptr<base::Value>& value,
144 const std::string& controlledBy); 144 const std::string& controlledBy);
145 // Verifies that committing a previously set user-modified pref value through 145 // Verifies that committing a previously set user-modified pref value through
146 // the JavaScript Preferences class fires the correct notification in 146 // the JavaScript Preferences class fires the correct notification in
147 // JavaScript and causes the change to be committed to the C++ backend. 147 // JavaScript and causes the change to be committed to the C++ backend.
148 void VerifySetCommit(const std::string& name, 148 void VerifySetCommit(const std::string& name,
149 const base::Value* value); 149 const std::unique_ptr<base::Value>& value);
150 // Verifies that committing the previously cleared user-modified pref value 150 // Verifies that committing the previously cleared user-modified pref value
151 // through the JavaScript Preferences class fires the correct notification in 151 // through the JavaScript Preferences class fires the correct notification in
152 // JavaScript and causes the change to be committed to the C++ backend. 152 // JavaScript and causes the change to be committed to the C++ backend.
153 void VerifyClearCommit(const std::string& name, 153 void VerifyClearCommit(const std::string& name,
154 const base::Value* value); 154 const std::unique_ptr<base::Value>& value);
155 // Verifies that rolling back a previously made change of a user-modified pref 155 // Verifies that rolling back a previously made change of a user-modified pref
156 // value through the JavaScript Preferences class fires the correct 156 // value through the JavaScript Preferences class fires the correct
157 // notification in JavaScript and does not cause the change to be committed to 157 // notification in JavaScript and does not cause the change to be committed to
158 // the C++ backend. 158 // the C++ backend.
159 void VerifyRollback(const std::string& name, 159 void VerifyRollback(const std::string& name,
160 const base::Value* value, 160 const std::unique_ptr<base::Value>& value,
161 const std::string& controlledBy); 161 const std::string& controlledBy);
162 // Start observing notifications sent by the JavaScript Preferences class for 162 // Start observing notifications sent by the JavaScript Preferences class for
163 // pref values changes. 163 // pref values changes.
164 void StartObserving(); 164 void StartObserving();
165 // Change the value of a sentinel pref in the C++ backend and finish observing 165 // Change the value of a sentinel pref in the C++ backend and finish observing
166 // notifications sent by the JavaScript Preferences class when the 166 // notifications sent by the JavaScript Preferences class when the
167 // notification for this pref is received. 167 // notification for this pref is received.
168 void FinishObserving(std::string* observed_json); 168 void FinishObserving(std::string* observed_json);
169 169
170 // Populate the lists of test prefs and corresponding policies with default 170 // Populate the lists of test prefs and corresponding policies with default
171 // values used by most tests. 171 // values used by most tests.
172 void UseDefaultTestPrefs(bool includeListPref); 172 void UseDefaultTestPrefs(bool includeListPref);
173 173
174 // The current tab's render view host, required to inject JavaScript code into 174 // The current tab's render view host, required to inject JavaScript code into
175 // the tab. 175 // the tab.
176 content::RenderViewHost* render_view_host_; 176 content::RenderViewHost* render_view_host_;
177 177
178 // Mock policy provider for both user and device policies. 178 // Mock policy provider for both user and device policies.
179 policy::MockConfigurationPolicyProvider policy_provider_; 179 policy::MockConfigurationPolicyProvider policy_provider_;
180 180
181 // Pref change registrar that detects changes to user-modified pref values 181 // Pref change registrar that detects changes to user-modified pref values
182 // made in the C++ backend by the JavaScript Preferences class. 182 // made in the C++ backend by the JavaScript Preferences class.
183 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_; 183 std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
184 184
185 // The prefs and corresponding policies used by the current test. 185 // The prefs and corresponding policies used by the current test.
186 std::vector<std::string> types_; 186 std::vector<std::string> types_;
187 std::vector<std::string> pref_names_; 187 std::vector<std::string> pref_names_;
188 std::vector<std::string> policy_names_; 188 std::vector<std::string> policy_names_;
189 ScopedVector<base::Value> default_values_; 189 std::vector<std::unique_ptr<base::Value>> default_values_;
190 ScopedVector<base::Value> non_default_values_; 190 std::vector<std::unique_ptr<base::Value>> non_default_values_;
191 191
192 private: 192 private:
193 DISALLOW_COPY_AND_ASSIGN(PreferencesBrowserTest); 193 DISALLOW_COPY_AND_ASSIGN(PreferencesBrowserTest);
194 }; 194 };
195 195
196 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PREFERENCES_BROWSERTEST_H_ 196 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PREFERENCES_BROWSERTEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698