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