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