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

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

Issue 1296663003: Componentize proxy code from chrome/browser/net (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updating for win p/f Created 5 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
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"
11 #include "chrome/browser/prefs/pref_service_mock_factory.h" 11 #include "chrome/browser/prefs/pref_service_mock_factory.h"
12 #include "chrome/browser/prefs/pref_service_syncable.h" 12 #include "chrome/browser/prefs/pref_service_syncable.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/pref_names.h"
15 #include "components/policy/core/common/external_data_fetcher.h" 14 #include "components/policy/core/common/external_data_fetcher.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_map.h" 16 #include "components/policy/core/common/policy_map.h"
18 #include "components/policy/core/common/policy_service_impl.h" 17 #include "components/policy/core/common/policy_service_impl.h"
19 #include "components/pref_registry/pref_registry_syncable.h" 18 #include "components/pref_registry/pref_registry_syncable.h"
20 #include "components/proxy_config/proxy_config_dictionary.h" 19 #include "components/proxy_config/proxy_config_dictionary.h"
21 #include "components/proxy_config/proxy_prefs.h" 20 #include "components/proxy_config/proxy_config_pref_names.h"
22 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "policy/policy_constants.h" 22 #include "policy/policy_constants.h"
24 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
25 24
26 using ::testing::Return; 25 using ::testing::Return;
27 using ::testing::_; 26 using ::testing::_;
28 27
29 namespace policy { 28 namespace policy {
30 29
31 namespace { 30 namespace {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 policy.Set(key::kProxyServer, 130 policy.Set(key::kProxyServer,
132 POLICY_LEVEL_MANDATORY, 131 POLICY_LEVEL_MANDATORY,
133 POLICY_SCOPE_USER, 132 POLICY_SCOPE_USER,
134 new base::StringValue("ghi"), 133 new base::StringValue("ghi"),
135 NULL); 134 NULL);
136 provider_.UpdateChromePolicy(policy); 135 provider_.UpdateChromePolicy(policy);
137 136
138 // First verify that command-line options are set correctly when 137 // First verify that command-line options are set correctly when
139 // there is no policy in effect. 138 // there is no policy in effect.
140 scoped_ptr<PrefService> prefs(CreatePrefService(false)); 139 scoped_ptr<PrefService> prefs(CreatePrefService(false));
141 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 140 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
142 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 141 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
143 assertProxyServer(dict, "789"); 142 assertProxyServer(dict, "789");
144 assertPacUrl(dict, std::string()); 143 assertPacUrl(dict, std::string());
145 assertBypassList(dict, "123"); 144 assertBypassList(dict, "123");
146 145
147 // Try a second time time with the managed PrefStore in place, the 146 // Try a second time time with the managed PrefStore in place, the
148 // manual proxy policy should have removed all traces of the command 147 // manual proxy policy should have removed all traces of the command
149 // line and replaced them with the policy versions. 148 // line and replaced them with the policy versions.
150 prefs = CreatePrefService(true); 149 prefs = CreatePrefService(true);
151 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 150 ProxyConfigDictionary dict2(
151 prefs->GetDictionary(proxy_config::prefs::kProxy));
152 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS); 152 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS);
153 assertProxyServer(dict2, "ghi"); 153 assertProxyServer(dict2, "ghi");
154 assertPacUrl(dict2, std::string()); 154 assertPacUrl(dict2, std::string());
155 assertBypassList(dict2, "abc"); 155 assertBypassList(dict2, "abc");
156 } 156 }
157 157
158 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { 158 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) {
159 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 159 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
160 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 160 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
161 base::Value* mode_name = 161 base::Value* mode_name =
162 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName); 162 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName);
163 PolicyMap policy; 163 PolicyMap policy;
164 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 164 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
165 mode_name, NULL); 165 mode_name, NULL);
166 provider_.UpdateChromePolicy(policy); 166 provider_.UpdateChromePolicy(policy);
167 167
168 // First verify that command-line options are set correctly when 168 // First verify that command-line options are set correctly when
169 // there is no policy in effect. 169 // there is no policy in effect.
170 scoped_ptr<PrefService> prefs = CreatePrefService(false); 170 scoped_ptr<PrefService> prefs = CreatePrefService(false);
171 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 171 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
172 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 172 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
173 assertProxyServer(dict, "789"); 173 assertProxyServer(dict, "789");
174 assertPacUrl(dict, std::string()); 174 assertPacUrl(dict, std::string());
175 assertBypassList(dict, "123"); 175 assertBypassList(dict, "123");
176 176
177 // Try a second time time with the managed PrefStore in place, the 177 // Try a second time time with the managed PrefStore in place, the
178 // no proxy policy should have removed all traces of the command 178 // no proxy policy should have removed all traces of the command
179 // line proxy settings, even though they were not the specific one 179 // line proxy settings, even though they were not the specific one
180 // set in policy. 180 // set in policy.
181 prefs = CreatePrefService(true); 181 prefs = CreatePrefService(true);
182 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 182 ProxyConfigDictionary dict2(
183 prefs->GetDictionary(proxy_config::prefs::kProxy));
183 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 184 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
184 } 185 }
185 186
186 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) { 187 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) {
187 command_line_.AppendSwitch(switches::kNoProxyServer); 188 command_line_.AppendSwitch(switches::kNoProxyServer);
188 base::Value* mode_name = 189 base::Value* mode_name =
189 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName); 190 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName);
190 PolicyMap policy; 191 PolicyMap policy;
191 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 192 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
192 mode_name, NULL); 193 mode_name, NULL);
193 provider_.UpdateChromePolicy(policy); 194 provider_.UpdateChromePolicy(policy);
194 195
195 // First verify that command-line options are set correctly when 196 // First verify that command-line options are set correctly when
196 // there is no policy in effect. 197 // there is no policy in effect.
197 scoped_ptr<PrefService> prefs = CreatePrefService(false); 198 scoped_ptr<PrefService> prefs = CreatePrefService(false);
198 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 199 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
199 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); 200 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT);
200 201
201 // Try a second time time with the managed PrefStore in place, the 202 // Try a second time time with the managed PrefStore in place, the
202 // auto-detect should be overridden. The default pref store must be 203 // auto-detect should be overridden. The default pref store must be
203 // in place with the appropriate default value for this to work. 204 // in place with the appropriate default value for this to work.
204 prefs = CreatePrefService(true); 205 prefs = CreatePrefService(true);
205 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 206 ProxyConfigDictionary dict2(
207 prefs->GetDictionary(proxy_config::prefs::kProxy));
206 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 208 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
207 } 209 }
208 210
209 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) { 211 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) {
210 command_line_.AppendSwitch(switches::kProxyAutoDetect); 212 command_line_.AppendSwitch(switches::kProxyAutoDetect);
211 base::Value* mode_name = 213 base::Value* mode_name =
212 new base::StringValue(ProxyPrefs::kDirectProxyModeName); 214 new base::StringValue(ProxyPrefs::kDirectProxyModeName);
213 PolicyMap policy; 215 PolicyMap policy;
214 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 216 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
215 mode_name, NULL); 217 mode_name, NULL);
216 provider_.UpdateChromePolicy(policy); 218 provider_.UpdateChromePolicy(policy);
217 219
218 // First verify that the auto-detect is set if there is no managed 220 // First verify that the auto-detect is set if there is no managed
219 // PrefStore. 221 // PrefStore.
220 scoped_ptr<PrefService> prefs = CreatePrefService(false); 222 scoped_ptr<PrefService> prefs = CreatePrefService(false);
221 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 223 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
222 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); 224 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT);
223 225
224 // Try a second time time with the managed PrefStore in place, the 226 // Try a second time time with the managed PrefStore in place, the
225 // auto-detect should be overridden. The default pref store must be 227 // auto-detect should be overridden. The default pref store must be
226 // in place with the appropriate default value for this to work. 228 // in place with the appropriate default value for this to work.
227 prefs = CreatePrefService(true); 229 prefs = CreatePrefService(true);
228 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 230 ProxyConfigDictionary dict2(
231 prefs->GetDictionary(proxy_config::prefs::kProxy));
229 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); 232 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT);
230 } 233 }
231 234
232 } // namespace policy 235 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/prefs/command_line_pref_store_unittest.cc ('k') | chrome/browser/profiles/off_the_record_profile_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698