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

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: updated build errors Created 5 years, 4 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(ProxyPrefs::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(prefs->GetDictionary(ProxyPrefs::prefs::kProxy));
152 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS); 151 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS);
153 assertProxyServer(dict2, "ghi"); 152 assertProxyServer(dict2, "ghi");
154 assertPacUrl(dict2, std::string()); 153 assertPacUrl(dict2, std::string());
155 assertBypassList(dict2, "abc"); 154 assertBypassList(dict2, "abc");
156 } 155 }
157 156
158 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { 157 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) {
159 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 158 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
160 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 159 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
161 base::Value* mode_name = 160 base::Value* mode_name =
162 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName); 161 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName);
163 PolicyMap policy; 162 PolicyMap policy;
164 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 163 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
165 mode_name, NULL); 164 mode_name, NULL);
166 provider_.UpdateChromePolicy(policy); 165 provider_.UpdateChromePolicy(policy);
167 166
168 // First verify that command-line options are set correctly when 167 // First verify that command-line options are set correctly when
169 // there is no policy in effect. 168 // there is no policy in effect.
170 scoped_ptr<PrefService> prefs = CreatePrefService(false); 169 scoped_ptr<PrefService> prefs = CreatePrefService(false);
171 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 170 ProxyConfigDictionary dict(prefs->GetDictionary(ProxyPrefs::prefs::kProxy));
172 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 171 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
173 assertProxyServer(dict, "789"); 172 assertProxyServer(dict, "789");
174 assertPacUrl(dict, std::string()); 173 assertPacUrl(dict, std::string());
175 assertBypassList(dict, "123"); 174 assertBypassList(dict, "123");
176 175
177 // Try a second time time with the managed PrefStore in place, the 176 // Try a second time time with the managed PrefStore in place, the
178 // no proxy policy should have removed all traces of the command 177 // no proxy policy should have removed all traces of the command
179 // line proxy settings, even though they were not the specific one 178 // line proxy settings, even though they were not the specific one
180 // set in policy. 179 // set in policy.
181 prefs = CreatePrefService(true); 180 prefs = CreatePrefService(true);
182 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 181 ProxyConfigDictionary dict2(prefs->GetDictionary(ProxyPrefs::prefs::kProxy));
183 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 182 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
184 } 183 }
185 184
186 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) { 185 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) {
187 command_line_.AppendSwitch(switches::kNoProxyServer); 186 command_line_.AppendSwitch(switches::kNoProxyServer);
188 base::Value* mode_name = 187 base::Value* mode_name =
189 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName); 188 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName);
190 PolicyMap policy; 189 PolicyMap policy;
191 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 190 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
192 mode_name, NULL); 191 mode_name, NULL);
193 provider_.UpdateChromePolicy(policy); 192 provider_.UpdateChromePolicy(policy);
194 193
195 // First verify that command-line options are set correctly when 194 // First verify that command-line options are set correctly when
196 // there is no policy in effect. 195 // there is no policy in effect.
197 scoped_ptr<PrefService> prefs = CreatePrefService(false); 196 scoped_ptr<PrefService> prefs = CreatePrefService(false);
198 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 197 ProxyConfigDictionary dict(prefs->GetDictionary(ProxyPrefs::prefs::kProxy));
199 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); 198 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT);
200 199
201 // Try a second time time with the managed PrefStore in place, the 200 // Try a second time time with the managed PrefStore in place, the
202 // auto-detect should be overridden. The default pref store must be 201 // auto-detect should be overridden. The default pref store must be
203 // in place with the appropriate default value for this to work. 202 // in place with the appropriate default value for this to work.
204 prefs = CreatePrefService(true); 203 prefs = CreatePrefService(true);
205 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 204 ProxyConfigDictionary dict2(prefs->GetDictionary(ProxyPrefs::prefs::kProxy));
206 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 205 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
207 } 206 }
208 207
209 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) { 208 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) {
210 command_line_.AppendSwitch(switches::kProxyAutoDetect); 209 command_line_.AppendSwitch(switches::kProxyAutoDetect);
211 base::Value* mode_name = 210 base::Value* mode_name =
212 new base::StringValue(ProxyPrefs::kDirectProxyModeName); 211 new base::StringValue(ProxyPrefs::kDirectProxyModeName);
213 PolicyMap policy; 212 PolicyMap policy;
214 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 213 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
215 mode_name, NULL); 214 mode_name, NULL);
216 provider_.UpdateChromePolicy(policy); 215 provider_.UpdateChromePolicy(policy);
217 216
218 // First verify that the auto-detect is set if there is no managed 217 // First verify that the auto-detect is set if there is no managed
219 // PrefStore. 218 // PrefStore.
220 scoped_ptr<PrefService> prefs = CreatePrefService(false); 219 scoped_ptr<PrefService> prefs = CreatePrefService(false);
221 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 220 ProxyConfigDictionary dict(prefs->GetDictionary(ProxyPrefs::prefs::kProxy));
222 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); 221 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT);
223 222
224 // Try a second time time with the managed PrefStore in place, the 223 // Try a second time time with the managed PrefStore in place, the
225 // auto-detect should be overridden. The default pref store must be 224 // auto-detect should be overridden. The default pref store must be
226 // in place with the appropriate default value for this to work. 225 // in place with the appropriate default value for this to work.
227 prefs = CreatePrefService(true); 226 prefs = CreatePrefService(true);
228 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 227 ProxyConfigDictionary dict2(prefs->GetDictionary(ProxyPrefs::prefs::kProxy));
229 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); 228 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT);
230 } 229 }
231 230
232 } // namespace policy 231 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698