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

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

Issue 10827141: Move handling of dialog preferences to Preferences class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed PrefCheckbox. Created 8 years, 3 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
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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "chrome/browser/api/prefs/pref_change_registrar.h"
13 #include "chrome/browser/policy/mock_configuration_policy_provider.h" 14 #include "chrome/browser/policy/mock_configuration_policy_provider.h"
14 #include "chrome/browser/policy/policy_constants.h" 15 #include "chrome/browser/policy/policy_constants.h"
16 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "content/public/browser/notification_observer.h"
19 #include "testing/gmock/include/gmock/gmock.h"
16 20
17 namespace base { 21 namespace base {
18 class DictionaryValue; 22 class DictionaryValue;
19 class Value; 23 class Value;
20 } 24 }
21 25
22 namespace content { 26 namespace content {
27 class NotificationDetails;
28 class NotificationSource;
23 class RenderViewHost; 29 class RenderViewHost;
24 } 30 }
25 31
26 // Tests verifying that the JavaScript Preferences class, the underlying C++ 32 // Tests verifying that the JavaScript Preferences class, the underlying C++
27 // CoreOptionsHandler and the specialized classes handling Chrome OS device and 33 // CoreOptionsHandler and the specialized classes handling Chrome OS device and
28 // proxy prefs behave correctly. 34 // proxy prefs behave correctly.
29 class PreferencesBrowserTest : public InProcessBrowserTest { 35 class PreferencesBrowserTest : public InProcessBrowserTest,
36 public content::NotificationObserver {
30 public: 37 public:
31 PreferencesBrowserTest(); 38 PreferencesBrowserTest();
39 ~PreferencesBrowserTest();
40
41 // InProcessBrowserTest implementation:
42 virtual void SetUpOnMainThread() OVERRIDE;
43
44 // content::NotificationObserver implementation:
45 virtual void Observe(int type,
46 const content::NotificationSource& source,
47 const content::NotificationDetails& details) OVERRIDE;
48
49 protected:
50 MOCK_METHOD1(OnCommit, void(const PrefService::Preference*));
32 51
33 // InProcessBrowserTest implementation: 52 // InProcessBrowserTest implementation:
34 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; 53 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
35 virtual void SetUpOnMainThread() OVERRIDE; 54 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE;
36 55
37 protected: 56 // Sets user policies through the mock policy provider.
57 void SetUserPolicies(const std::vector<std::string>& names,
58 const std::vector<base::Value*>& values,
59 policy::PolicyLevel level);
60 // Clears user policies.
61 void ClearUserPolicies();
62 // Set user-modified pref values directly in the C++ backend.
63 void SetUserValues(const std::vector<std::string>& names,
64 const std::vector<base::Value*>& values);
65 // Helper deleting a vector of values.
66 void DeleteValues(std::vector<base::Value*>& values);
67
38 // Verifies that a dictionary contains a (key, value) pair. Takes ownership of 68 // Verifies that a dictionary contains a (key, value) pair. Takes ownership of
39 // |expected|. 69 // |expected|.
40 void VerifyValue(const base::DictionaryValue* dict, 70 void VerifyKeyValue(const base::DictionaryValue* dict,
41 const std::string& key, 71 const std::string& key,
42 base::Value* expected); 72 base::Value* expected);
43 // Verifies that a pref value has been decorated correctly.
44 void VerifyDict(const base::DictionaryValue* dict,
45 const base::Value* value,
46 const std::string& controlledBy,
47 bool disabled);
48 // Verifies that a dictionary contains a given pref and that its value has 73 // Verifies that a dictionary contains a given pref and that its value has
49 // been decorated correctly. 74 // been decorated correctly.
50 void VerifyPref(const base::DictionaryValue* prefs, 75 void VerifyPref(const base::DictionaryValue* prefs,
51 const std::string& name, 76 const std::string& name,
52 const base::Value* value, 77 const base::Value* value,
53 const std::string& controlledBy, 78 const std::string& controlledBy,
54 bool disabled); 79 bool disabled);
55 // Verifies that a dictionary contains a given list of prefs and that their 80 // Verifies that a notification received from the JavaScript Preferences
56 // values have been decorated correctly. 81 // class contains a given pref and that its value has been decorated
57 void VerifyPrefs(const base::DictionaryValue* prefs, 82 // correctly.
58 const std::vector<std::string>& names, 83 void VerifyObservedPref(const std::string& observed_json,
59 const std::vector<base::Value*>& values, 84 const std::string& name,
60 const std::string& controlledBy, 85 const base::Value* value,
61 bool disabled); 86 const std::string& controlledBy,
62 // Sets a pref value from JavaScript, waits for an observer callback to fire 87 bool disabled);
63 // and returns the decorated value received. 88 // Verifies that notifications received from the JavaScript Preferences class
89 // contain the given prefs and that their values have been decorated
90 // correctly.
91 void VerifyObservedPrefs(const std::string& observed_json,
92 const std::vector<std::string>& names,
93 const std::vector<base::Value*>& values,
94 const std::string& controlledBy,
95 bool disabled);
96
97 // Sets up the expectation that the JavaScript Preferences class will make no
98 // change to a user-modified pref value in the C++ backend.
99 void ExpectNoCommit(const std::string& name);
100 // Sets up the expectation that the JavaScript Preferences class will set a
101 // user-modified pref value in the C++ backend.
102 void ExpectSetCommit(const std::string& name,
103 const base::Value* value);
104 // Sets up the expectation that the JavaScript Preferences class will clear a
105 // user-modified pref value in the C++ backend.
106 void ExpectClearCommit(const std::string& name);
107 // Verifies that previously set expectations are met and clears them.
108 void VerifyAndClearExpectations();
109
110 // Sets up the JavaScript part of the test environment.
111 void SetupJavaScriptTestEnvironment(
112 const std::vector<std::string>& pref_names,
113 std::string* observed_json) const;
114 // Verifies that setting a user-modified pref value through the JavaScript
115 // Preferences class fires the correct notification in JavaScript and does
116 // respectively does not cause the change to be committed to the C++ backend.
64 void VerifySetPref(const std::string& name, 117 void VerifySetPref(const std::string& name,
65 const std::string& type, 118 const std::string& type,
66 base::Value* set_value, 119 const base::Value* value,
67 base::Value* expected_value); 120 bool commit);
121 // Verifies that clearing a user-modified pref value through the JavaScript
122 // Preferences class fires the correct notification in JavaScript and does
123 // respectively does not cause the change to be committed to the C++ backend.
124 void VerifyClearPref(const std::string& name,
125 const base::Value* value,
126 bool commit);
127 // Verifies that committing a previously made change of a user-modified pref
128 // value through the JavaScript Preferences class fires the correct
129 // notification in JavaScript.
130 void VerifyCommit(const std::string& name,
131 const base::Value* value,
132 const std::string& controlledBy);
133 // Verifies that committing a previously set user-modified pref value through
134 // the JavaScript Preferences class fires the correct notification in
135 // JavaScript and causes the change to be committed to the C++ backend.
136 void VerifySetCommit(const std::string& name,
137 const base::Value* value);
138 // Verifies that committing the previously cleared user-modified pref value
139 // through the JavaScript Preferences class fires the correct notification in
140 // JavaScript and causes the change to be committed to the C++ backend.
141 void VerifyClearCommit(const std::string& name,
142 const base::Value* value);
143 // Verifies that rolling back a previously made change of a user-modified pref
144 // value through the JavaScript Preferences class fires the correct
145 // notification in JavaScript and does not cause the change to be committed to
146 // the C++ backend.
147 void VerifyRollback(const std::string& name,
148 const base::Value* value,
149 const std::string& controlledBy);
150 // Start observing notifications sent by the JavaScript Preferences class for
151 // pref values changes.
152 void StartObserving();
153 // Change the value of a sentinel pref in the C++ backend and finish observing
154 // notifications sent by the JavaScript Preferences class when the
155 // notification for this pref is received.
156 void FinishObserving(std::string* observed_json);
68 157
69 // Requests a list of pref values from JavaScript, waits for a callback to 158 // Populate the lists of test prefs and corresponding policies with default
70 // fire and returns the decorated values received. 159 // values used by most tests.
71 void FetchPrefs(const std::vector<std::string>& names, 160 void UseDefaultTestPrefs(bool includeListPref);
72 base::DictionaryValue** prefs);
73
74 // Sets user policies through the mock policy provider.
75 void SetUserPolicies(const std::vector<std::string>& names,
76 const std::vector<base::Value*>& values,
77 policy::PolicyLevel level);
78
79 // Helper deleting a vector of values.
80 void DeleteValues(std::vector<base::Value*>& values);
81 161
82 // The current tab's render view host, required to inject JavaScript code into 162 // The current tab's render view host, required to inject JavaScript code into
83 // the tab. 163 // the tab.
84 content::RenderViewHost* render_view_host_; 164 content::RenderViewHost* render_view_host_;
85 165
86 // Mock user policy provider. 166 // Mock user policy provider.
87 policy::MockConfigurationPolicyProvider policy_provider_; 167 policy::MockConfigurationPolicyProvider policy_provider_;
88 168
169 // Pref change registrar that detects changes to user-modified pref values
170 // made in the C++ backend by the JavaScript Preferences class.
171 PrefChangeRegistrar pref_change_registrar_;
172
173 // The pref service that holds the current pref values in the C++ backend.
174 PrefService* pref_service_;
175
176 // The prefs and corresponding policies used by the current test.
177 std::vector<std::string> types_;
178 std::vector<std::string> pref_names_;
179 std::vector<std::string> policy_names_;
180 std::vector<base::Value*> default_values_;
181 std::vector<base::Value*> non_default_values_;
182
89 private: 183 private:
90 DISALLOW_COPY_AND_ASSIGN(PreferencesBrowserTest); 184 DISALLOW_COPY_AND_ASSIGN(PreferencesBrowserTest);
91 }; 185 };
92 186
93 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PREFERENCES_BROWSERTEST_H_ 187 #endif // CHROME_BROWSER_UI_WEBUI_OPTIONS_PREFERENCES_BROWSERTEST_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/core_options_handler.cc ('k') | chrome/browser/ui/webui/options/preferences_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698