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