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

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

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed another test. 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/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/prefs/browser_prefs.h" 11 #include "chrome/browser/prefs/browser_prefs.h"
12 #include "chrome/browser/prefs/command_line_pref_store.h" 12 #include "chrome/browser/prefs/command_line_pref_store.h"
13 #include "chrome/common/chrome_switches.h" 13 #include "chrome/common/chrome_switches.h"
14 #include "components/policy/core/common/external_data_fetcher.h" 14 #include "components/policy/core/common/external_data_fetcher.h"
15 #include "components/policy/core/common/mock_configuration_policy_provider.h" 15 #include "components/policy/core/common/mock_configuration_policy_provider.h"
16 #include "components/policy/core/common/policy_map.h" 16 #include "components/policy/core/common/policy_map.h"
17 #include "components/policy/core/common/policy_service_impl.h" 17 #include "components/policy/core/common/policy_service_impl.h"
18 #include "components/policy/core/common/policy_types.h"
18 #include "components/pref_registry/pref_registry_syncable.h" 19 #include "components/pref_registry/pref_registry_syncable.h"
19 #include "components/proxy_config/proxy_config_dictionary.h" 20 #include "components/proxy_config/proxy_config_dictionary.h"
20 #include "components/proxy_config/proxy_config_pref_names.h" 21 #include "components/proxy_config/proxy_config_pref_names.h"
21 #include "components/syncable_prefs/pref_service_mock_factory.h" 22 #include "components/syncable_prefs/pref_service_mock_factory.h"
22 #include "components/syncable_prefs/pref_service_syncable.h" 23 #include "components/syncable_prefs/pref_service_syncable.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 24 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "policy/policy_constants.h" 25 #include "policy/policy_constants.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 using ::testing::Return; 28 using ::testing::Return;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 scoped_ptr<PolicyServiceImpl> policy_service_; 120 scoped_ptr<PolicyServiceImpl> policy_service_;
120 }; 121 };
121 122
122 TEST_F(ProxyPolicyTest, OverridesCommandLineOptions) { 123 TEST_F(ProxyPolicyTest, OverridesCommandLineOptions) {
123 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 124 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
124 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 125 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
125 base::Value* mode_name = 126 base::Value* mode_name =
126 new base::StringValue(ProxyPrefs::kFixedServersProxyModeName); 127 new base::StringValue(ProxyPrefs::kFixedServersProxyModeName);
127 PolicyMap policy; 128 PolicyMap policy;
128 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 129 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
129 mode_name, NULL); 130 POLICY_SOURCE_CLOUD, mode_name, nullptr);
130 policy.Set(key::kProxyBypassList, 131 policy.Set(key::kProxyBypassList,
131 POLICY_LEVEL_MANDATORY, 132 POLICY_LEVEL_MANDATORY,
132 POLICY_SCOPE_USER, 133 POLICY_SCOPE_USER,
134 POLICY_SOURCE_CLOUD,
133 new base::StringValue("abc"), 135 new base::StringValue("abc"),
134 NULL); 136 NULL);
135 policy.Set(key::kProxyServer, 137 policy.Set(key::kProxyServer,
136 POLICY_LEVEL_MANDATORY, 138 POLICY_LEVEL_MANDATORY,
137 POLICY_SCOPE_USER, 139 POLICY_SCOPE_USER,
140 POLICY_SOURCE_CLOUD,
138 new base::StringValue("ghi"), 141 new base::StringValue("ghi"),
139 NULL); 142 NULL);
140 provider_.UpdateChromePolicy(policy); 143 provider_.UpdateChromePolicy(policy);
141 144
142 // First verify that command-line options are set correctly when 145 // First verify that command-line options are set correctly when
143 // there is no policy in effect. 146 // there is no policy in effect.
144 scoped_ptr<PrefService> prefs(CreatePrefService(false)); 147 scoped_ptr<PrefService> prefs(CreatePrefService(false));
145 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); 148 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
146 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 149 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
147 assertProxyServer(dict, "789"); 150 assertProxyServer(dict, "789");
(...skipping 12 matching lines...) Expand all
160 assertBypassList(dict2, "abc"); 163 assertBypassList(dict2, "abc");
161 } 164 }
162 165
163 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { 166 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) {
164 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 167 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
165 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 168 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
166 base::Value* mode_name = 169 base::Value* mode_name =
167 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName); 170 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName);
168 PolicyMap policy; 171 PolicyMap policy;
169 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 172 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
170 mode_name, NULL); 173 POLICY_SOURCE_CLOUD, mode_name, nullptr);
171 provider_.UpdateChromePolicy(policy); 174 provider_.UpdateChromePolicy(policy);
172 175
173 // First verify that command-line options are set correctly when 176 // First verify that command-line options are set correctly when
174 // there is no policy in effect. 177 // there is no policy in effect.
175 scoped_ptr<PrefService> prefs = CreatePrefService(false); 178 scoped_ptr<PrefService> prefs = CreatePrefService(false);
176 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); 179 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
177 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 180 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
178 assertProxyServer(dict, "789"); 181 assertProxyServer(dict, "789");
179 assertPacUrl(dict, std::string()); 182 assertPacUrl(dict, std::string());
180 assertBypassList(dict, "123"); 183 assertBypassList(dict, "123");
181 184
182 // Try a second time time with the managed PrefStore in place, the 185 // Try a second time time with the managed PrefStore in place, the
183 // no proxy policy should have removed all traces of the command 186 // no proxy policy should have removed all traces of the command
184 // line proxy settings, even though they were not the specific one 187 // line proxy settings, even though they were not the specific one
185 // set in policy. 188 // set in policy.
186 prefs = CreatePrefService(true); 189 prefs = CreatePrefService(true);
187 ProxyConfigDictionary dict2( 190 ProxyConfigDictionary dict2(
188 prefs->GetDictionary(proxy_config::prefs::kProxy)); 191 prefs->GetDictionary(proxy_config::prefs::kProxy));
189 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 192 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
190 } 193 }
191 194
192 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) { 195 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) {
193 command_line_.AppendSwitch(switches::kNoProxyServer); 196 command_line_.AppendSwitch(switches::kNoProxyServer);
194 base::Value* mode_name = 197 base::Value* mode_name =
195 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName); 198 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName);
196 PolicyMap policy; 199 PolicyMap policy;
197 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 200 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
198 mode_name, NULL); 201 POLICY_SOURCE_CLOUD, mode_name, nullptr);
199 provider_.UpdateChromePolicy(policy); 202 provider_.UpdateChromePolicy(policy);
200 203
201 // First verify that command-line options are set correctly when 204 // First verify that command-line options are set correctly when
202 // there is no policy in effect. 205 // there is no policy in effect.
203 scoped_ptr<PrefService> prefs = CreatePrefService(false); 206 scoped_ptr<PrefService> prefs = CreatePrefService(false);
204 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); 207 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
205 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); 208 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT);
206 209
207 // Try a second time time with the managed PrefStore in place, the 210 // Try a second time time with the managed PrefStore in place, the
208 // auto-detect should be overridden. The default pref store must be 211 // auto-detect should be overridden. The default pref store must be
209 // in place with the appropriate default value for this to work. 212 // in place with the appropriate default value for this to work.
210 prefs = CreatePrefService(true); 213 prefs = CreatePrefService(true);
211 ProxyConfigDictionary dict2( 214 ProxyConfigDictionary dict2(
212 prefs->GetDictionary(proxy_config::prefs::kProxy)); 215 prefs->GetDictionary(proxy_config::prefs::kProxy));
213 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 216 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
214 } 217 }
215 218
216 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) { 219 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) {
217 command_line_.AppendSwitch(switches::kProxyAutoDetect); 220 command_line_.AppendSwitch(switches::kProxyAutoDetect);
218 base::Value* mode_name = 221 base::Value* mode_name =
219 new base::StringValue(ProxyPrefs::kDirectProxyModeName); 222 new base::StringValue(ProxyPrefs::kDirectProxyModeName);
220 PolicyMap policy; 223 PolicyMap policy;
221 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 224 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
222 mode_name, NULL); 225 POLICY_SOURCE_CLOUD, mode_name, nullptr);
223 provider_.UpdateChromePolicy(policy); 226 provider_.UpdateChromePolicy(policy);
224 227
225 // First verify that the auto-detect is set if there is no managed 228 // First verify that the auto-detect is set if there is no managed
226 // PrefStore. 229 // PrefStore.
227 scoped_ptr<PrefService> prefs = CreatePrefService(false); 230 scoped_ptr<PrefService> prefs = CreatePrefService(false);
228 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); 231 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
229 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); 232 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT);
230 233
231 // Try a second time time with the managed PrefStore in place, the 234 // Try a second time time with the managed PrefStore in place, the
232 // auto-detect should be overridden. The default pref store must be 235 // auto-detect should be overridden. The default pref store must be
233 // in place with the appropriate default value for this to work. 236 // in place with the appropriate default value for this to work.
234 prefs = CreatePrefService(true); 237 prefs = CreatePrefService(true);
235 ProxyConfigDictionary dict2( 238 ProxyConfigDictionary dict2(
236 prefs->GetDictionary(proxy_config::prefs::kProxy)); 239 prefs->GetDictionary(proxy_config::prefs::kProxy));
237 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); 240 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT);
238 } 241 }
239 242
240 } // namespace policy 243 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698