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

Side by Side Diff: chrome/browser/prefs/proxy_policy_unittest.cc

Issue 104493005: Update some uses of Value in chrome/browser to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years 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 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "chrome/browser/prefs/browser_prefs.h" 10 #include "chrome/browser/prefs/browser_prefs.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 base::MessageLoop loop_; 114 base::MessageLoop loop_;
115 CommandLine command_line_; 115 CommandLine command_line_;
116 MockConfigurationPolicyProvider provider_; 116 MockConfigurationPolicyProvider provider_;
117 scoped_ptr<PolicyServiceImpl> policy_service_; 117 scoped_ptr<PolicyServiceImpl> policy_service_;
118 }; 118 };
119 119
120 TEST_F(ProxyPolicyTest, OverridesCommandLineOptions) { 120 TEST_F(ProxyPolicyTest, OverridesCommandLineOptions) {
121 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 121 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
122 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 122 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
123 Value* mode_name = Value::CreateStringValue( 123 base::Value* mode_name = base::Value::CreateStringValue(
124 ProxyPrefs::kFixedServersProxyModeName); 124 ProxyPrefs::kFixedServersProxyModeName);
125 PolicyMap policy; 125 PolicyMap policy;
126 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 126 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
127 mode_name, NULL); 127 mode_name, NULL);
128 policy.Set(key::kProxyBypassList, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 128 policy.Set(key::kProxyBypassList, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
129 Value::CreateStringValue("abc"), NULL); 129 base::Value::CreateStringValue("abc"), NULL);
130 policy.Set(key::kProxyServer, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 130 policy.Set(key::kProxyServer, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
131 Value::CreateStringValue("ghi"), NULL); 131 base::Value::CreateStringValue("ghi"), NULL);
132 provider_.UpdateChromePolicy(policy); 132 provider_.UpdateChromePolicy(policy);
133 133
134 // First verify that command-line options are set correctly when 134 // First verify that command-line options are set correctly when
135 // there is no policy in effect. 135 // there is no policy in effect.
136 scoped_ptr<PrefService> prefs(CreatePrefService(false)); 136 scoped_ptr<PrefService> prefs(CreatePrefService(false));
137 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 137 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
138 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 138 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
139 assertProxyServer(dict, "789"); 139 assertProxyServer(dict, "789");
140 assertPacUrl(dict, std::string()); 140 assertPacUrl(dict, std::string());
141 assertBypassList(dict, "123"); 141 assertBypassList(dict, "123");
142 142
143 // Try a second time time with the managed PrefStore in place, the 143 // Try a second time time with the managed PrefStore in place, the
144 // manual proxy policy should have removed all traces of the command 144 // manual proxy policy should have removed all traces of the command
145 // line and replaced them with the policy versions. 145 // line and replaced them with the policy versions.
146 prefs = CreatePrefService(true); 146 prefs = CreatePrefService(true);
147 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 147 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy));
148 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS); 148 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS);
149 assertProxyServer(dict2, "ghi"); 149 assertProxyServer(dict2, "ghi");
150 assertPacUrl(dict2, std::string()); 150 assertPacUrl(dict2, std::string());
151 assertBypassList(dict2, "abc"); 151 assertBypassList(dict2, "abc");
152 } 152 }
153 153
154 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { 154 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) {
155 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 155 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
156 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 156 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
157 Value* mode_name = Value::CreateStringValue( 157 base::Value* mode_name = base::Value::CreateStringValue(
158 ProxyPrefs::kAutoDetectProxyModeName); 158 ProxyPrefs::kAutoDetectProxyModeName);
159 PolicyMap policy; 159 PolicyMap policy;
160 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 160 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
161 mode_name, NULL); 161 mode_name, NULL);
162 provider_.UpdateChromePolicy(policy); 162 provider_.UpdateChromePolicy(policy);
163 163
164 // First verify that command-line options are set correctly when 164 // First verify that command-line options are set correctly when
165 // there is no policy in effect. 165 // there is no policy in effect.
166 scoped_ptr<PrefService> prefs = CreatePrefService(false); 166 scoped_ptr<PrefService> prefs = CreatePrefService(false);
167 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 167 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
168 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 168 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
169 assertProxyServer(dict, "789"); 169 assertProxyServer(dict, "789");
170 assertPacUrl(dict, std::string()); 170 assertPacUrl(dict, std::string());
171 assertBypassList(dict, "123"); 171 assertBypassList(dict, "123");
172 172
173 // Try a second time time with the managed PrefStore in place, the 173 // Try a second time time with the managed PrefStore in place, the
174 // no proxy policy should have removed all traces of the command 174 // no proxy policy should have removed all traces of the command
175 // line proxy settings, even though they were not the specific one 175 // line proxy settings, even though they were not the specific one
176 // set in policy. 176 // set in policy.
177 prefs = CreatePrefService(true); 177 prefs = CreatePrefService(true);
178 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 178 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy));
179 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 179 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
180 } 180 }
181 181
182 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) { 182 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) {
183 command_line_.AppendSwitch(switches::kNoProxyServer); 183 command_line_.AppendSwitch(switches::kNoProxyServer);
184 Value* mode_name = Value::CreateStringValue( 184 base::Value* mode_name = base::Value::CreateStringValue(
185 ProxyPrefs::kAutoDetectProxyModeName); 185 ProxyPrefs::kAutoDetectProxyModeName);
186 PolicyMap policy; 186 PolicyMap policy;
187 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 187 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
188 mode_name, NULL); 188 mode_name, NULL);
189 provider_.UpdateChromePolicy(policy); 189 provider_.UpdateChromePolicy(policy);
190 190
191 // First verify that command-line options are set correctly when 191 // First verify that command-line options are set correctly when
192 // there is no policy in effect. 192 // there is no policy in effect.
193 scoped_ptr<PrefService> prefs = CreatePrefService(false); 193 scoped_ptr<PrefService> prefs = CreatePrefService(false);
194 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 194 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
195 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); 195 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT);
196 196
197 // Try a second time time with the managed PrefStore in place, the 197 // Try a second time time with the managed PrefStore in place, the
198 // auto-detect should be overridden. The default pref store must be 198 // auto-detect should be overridden. The default pref store must be
199 // in place with the appropriate default value for this to work. 199 // in place with the appropriate default value for this to work.
200 prefs = CreatePrefService(true); 200 prefs = CreatePrefService(true);
201 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 201 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy));
202 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 202 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
203 } 203 }
204 204
205 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) { 205 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) {
206 command_line_.AppendSwitch(switches::kProxyAutoDetect); 206 command_line_.AppendSwitch(switches::kProxyAutoDetect);
207 Value* mode_name = Value::CreateStringValue( 207 base::Value* mode_name = base::Value::CreateStringValue(
208 ProxyPrefs::kDirectProxyModeName); 208 ProxyPrefs::kDirectProxyModeName);
209 PolicyMap policy; 209 PolicyMap policy;
210 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 210 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
211 mode_name, NULL); 211 mode_name, NULL);
212 provider_.UpdateChromePolicy(policy); 212 provider_.UpdateChromePolicy(policy);
213 213
214 // First verify that the auto-detect is set if there is no managed 214 // First verify that the auto-detect is set if there is no managed
215 // PrefStore. 215 // PrefStore.
216 scoped_ptr<PrefService> prefs = CreatePrefService(false); 216 scoped_ptr<PrefService> prefs = CreatePrefService(false);
217 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 217 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
218 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); 218 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT);
219 219
220 // Try a second time time with the managed PrefStore in place, the 220 // Try a second time time with the managed PrefStore in place, the
221 // auto-detect should be overridden. The default pref store must be 221 // auto-detect should be overridden. The default pref store must be
222 // in place with the appropriate default value for this to work. 222 // in place with the appropriate default value for this to work.
223 prefs = CreatePrefService(true); 223 prefs = CreatePrefService(true);
224 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 224 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy));
225 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); 225 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT);
226 } 226 }
227 227
228 } // namespace policy 228 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/prefs/proxy_config_dictionary_unittest.cc ('k') | chrome/browser/prefs/session_startup_pref.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698