| 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 <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("abc"), | 137 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("abc"), |
| 138 nullptr); | 138 nullptr); |
| 139 policy.Set(key::kProxyServer, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 139 policy.Set(key::kProxyServer, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 140 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("ghi"), | 140 POLICY_SOURCE_CLOUD, base::MakeUnique<base::Value>("ghi"), |
| 141 nullptr); | 141 nullptr); |
| 142 provider_.UpdateChromePolicy(policy); | 142 provider_.UpdateChromePolicy(policy); |
| 143 | 143 |
| 144 // First verify that command-line options are set correctly when | 144 // First verify that command-line options are set correctly when |
| 145 // there is no policy in effect. | 145 // there is no policy in effect. |
| 146 std::unique_ptr<PrefService> prefs(CreatePrefService(false)); | 146 std::unique_ptr<PrefService> prefs(CreatePrefService(false)); |
| 147 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); | 147 ProxyConfigDictionary dict( |
| 148 prefs->GetDictionary(proxy_config::prefs::kProxy)->CreateDeepCopy()); |
| 148 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); | 149 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); |
| 149 assertProxyServer(dict, "789"); | 150 assertProxyServer(dict, "789"); |
| 150 assertPacUrl(dict, std::string()); | 151 assertPacUrl(dict, std::string()); |
| 151 assertBypassList(dict, "123"); | 152 assertBypassList(dict, "123"); |
| 152 | 153 |
| 153 // Try a second time time with the managed PrefStore in place, the | 154 // Try a second time time with the managed PrefStore in place, the |
| 154 // manual proxy policy should have removed all traces of the command | 155 // manual proxy policy should have removed all traces of the command |
| 155 // line and replaced them with the policy versions. | 156 // line and replaced them with the policy versions. |
| 156 prefs = CreatePrefService(true); | 157 prefs = CreatePrefService(true); |
| 157 ProxyConfigDictionary dict2( | 158 ProxyConfigDictionary dict2( |
| 158 prefs->GetDictionary(proxy_config::prefs::kProxy)); | 159 prefs->GetDictionary(proxy_config::prefs::kProxy)->CreateDeepCopy()); |
| 159 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS); | 160 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS); |
| 160 assertProxyServer(dict2, "ghi"); | 161 assertProxyServer(dict2, "ghi"); |
| 161 assertPacUrl(dict2, std::string()); | 162 assertPacUrl(dict2, std::string()); |
| 162 assertBypassList(dict2, "abc"); | 163 assertBypassList(dict2, "abc"); |
| 163 } | 164 } |
| 164 | 165 |
| 165 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { | 166 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { |
| 166 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); | 167 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); |
| 167 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); | 168 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); |
| 168 std::unique_ptr<base::Value> mode_name( | 169 std::unique_ptr<base::Value> mode_name( |
| 169 new base::Value(ProxyPrefs::kAutoDetectProxyModeName)); | 170 new base::Value(ProxyPrefs::kAutoDetectProxyModeName)); |
| 170 PolicyMap policy; | 171 PolicyMap policy; |
| 171 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 172 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 172 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); | 173 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); |
| 173 provider_.UpdateChromePolicy(policy); | 174 provider_.UpdateChromePolicy(policy); |
| 174 | 175 |
| 175 // First verify that command-line options are set correctly when | 176 // First verify that command-line options are set correctly when |
| 176 // there is no policy in effect. | 177 // there is no policy in effect. |
| 177 std::unique_ptr<PrefService> prefs = CreatePrefService(false); | 178 std::unique_ptr<PrefService> prefs = CreatePrefService(false); |
| 178 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); | 179 ProxyConfigDictionary dict( |
| 180 prefs->GetDictionary(proxy_config::prefs::kProxy)->CreateDeepCopy()); |
| 179 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); | 181 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); |
| 180 assertProxyServer(dict, "789"); | 182 assertProxyServer(dict, "789"); |
| 181 assertPacUrl(dict, std::string()); | 183 assertPacUrl(dict, std::string()); |
| 182 assertBypassList(dict, "123"); | 184 assertBypassList(dict, "123"); |
| 183 | 185 |
| 184 // Try a second time time with the managed PrefStore in place, the | 186 // Try a second time time with the managed PrefStore in place, the |
| 185 // no proxy policy should have removed all traces of the command | 187 // no proxy policy should have removed all traces of the command |
| 186 // line proxy settings, even though they were not the specific one | 188 // line proxy settings, even though they were not the specific one |
| 187 // set in policy. | 189 // set in policy. |
| 188 prefs = CreatePrefService(true); | 190 prefs = CreatePrefService(true); |
| 189 ProxyConfigDictionary dict2( | 191 ProxyConfigDictionary dict2( |
| 190 prefs->GetDictionary(proxy_config::prefs::kProxy)); | 192 prefs->GetDictionary(proxy_config::prefs::kProxy)->CreateDeepCopy()); |
| 191 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); | 193 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); |
| 192 } | 194 } |
| 193 | 195 |
| 194 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) { | 196 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) { |
| 195 command_line_.AppendSwitch(switches::kNoProxyServer); | 197 command_line_.AppendSwitch(switches::kNoProxyServer); |
| 196 std::unique_ptr<base::Value> mode_name( | 198 std::unique_ptr<base::Value> mode_name( |
| 197 new base::Value(ProxyPrefs::kAutoDetectProxyModeName)); | 199 new base::Value(ProxyPrefs::kAutoDetectProxyModeName)); |
| 198 PolicyMap policy; | 200 PolicyMap policy; |
| 199 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 201 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 200 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); | 202 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); |
| 201 provider_.UpdateChromePolicy(policy); | 203 provider_.UpdateChromePolicy(policy); |
| 202 | 204 |
| 203 // First verify that command-line options are set correctly when | 205 // First verify that command-line options are set correctly when |
| 204 // there is no policy in effect. | 206 // there is no policy in effect. |
| 205 std::unique_ptr<PrefService> prefs = CreatePrefService(false); | 207 std::unique_ptr<PrefService> prefs = CreatePrefService(false); |
| 206 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); | 208 ProxyConfigDictionary dict( |
| 209 prefs->GetDictionary(proxy_config::prefs::kProxy)->CreateDeepCopy()); |
| 207 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); | 210 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); |
| 208 | 211 |
| 209 // Try a second time time with the managed PrefStore in place, the | 212 // Try a second time time with the managed PrefStore in place, the |
| 210 // auto-detect should be overridden. The default pref store must be | 213 // auto-detect should be overridden. The default pref store must be |
| 211 // in place with the appropriate default value for this to work. | 214 // in place with the appropriate default value for this to work. |
| 212 prefs = CreatePrefService(true); | 215 prefs = CreatePrefService(true); |
| 213 ProxyConfigDictionary dict2( | 216 ProxyConfigDictionary dict2( |
| 214 prefs->GetDictionary(proxy_config::prefs::kProxy)); | 217 prefs->GetDictionary(proxy_config::prefs::kProxy)->CreateDeepCopy()); |
| 215 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); | 218 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); |
| 216 } | 219 } |
| 217 | 220 |
| 218 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) { | 221 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) { |
| 219 command_line_.AppendSwitch(switches::kProxyAutoDetect); | 222 command_line_.AppendSwitch(switches::kProxyAutoDetect); |
| 220 std::unique_ptr<base::Value> mode_name( | 223 std::unique_ptr<base::Value> mode_name( |
| 221 new base::Value(ProxyPrefs::kDirectProxyModeName)); | 224 new base::Value(ProxyPrefs::kDirectProxyModeName)); |
| 222 PolicyMap policy; | 225 PolicyMap policy; |
| 223 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, | 226 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, |
| 224 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); | 227 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); |
| 225 provider_.UpdateChromePolicy(policy); | 228 provider_.UpdateChromePolicy(policy); |
| 226 | 229 |
| 227 // First verify that the auto-detect is set if there is no managed | 230 // First verify that the auto-detect is set if there is no managed |
| 228 // PrefStore. | 231 // PrefStore. |
| 229 std::unique_ptr<PrefService> prefs = CreatePrefService(false); | 232 std::unique_ptr<PrefService> prefs = CreatePrefService(false); |
| 230 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); | 233 ProxyConfigDictionary dict( |
| 234 prefs->GetDictionary(proxy_config::prefs::kProxy)->CreateDeepCopy()); |
| 231 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); | 235 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); |
| 232 | 236 |
| 233 // Try a second time time with the managed PrefStore in place, the | 237 // Try a second time time with the managed PrefStore in place, the |
| 234 // auto-detect should be overridden. The default pref store must be | 238 // auto-detect should be overridden. The default pref store must be |
| 235 // in place with the appropriate default value for this to work. | 239 // in place with the appropriate default value for this to work. |
| 236 prefs = CreatePrefService(true); | 240 prefs = CreatePrefService(true); |
| 237 ProxyConfigDictionary dict2( | 241 ProxyConfigDictionary dict2( |
| 238 prefs->GetDictionary(proxy_config::prefs::kProxy)); | 242 prefs->GetDictionary(proxy_config::prefs::kProxy)->CreateDeepCopy()); |
| 239 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); | 243 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); |
| 240 } | 244 } |
| 241 | 245 |
| 242 } // namespace policy | 246 } // namespace policy |
| OLD | NEW |