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