Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: chrome/browser/prefs/proxy_policy_unittest.cc

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 content::TestBrowserThreadBundle thread_bundle_; 122 content::TestBrowserThreadBundle thread_bundle_;
123 base::CommandLine command_line_; 123 base::CommandLine command_line_;
124 MockConfigurationPolicyProvider provider_; 124 MockConfigurationPolicyProvider provider_;
125 std::unique_ptr<PolicyServiceImpl> policy_service_; 125 std::unique_ptr<PolicyServiceImpl> policy_service_;
126 }; 126 };
127 127
128 TEST_F(ProxyPolicyTest, OverridesCommandLineOptions) { 128 TEST_F(ProxyPolicyTest, OverridesCommandLineOptions) {
129 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 129 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
130 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 130 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
131 std::unique_ptr<base::Value> mode_name( 131 std::unique_ptr<base::Value> mode_name(
132 new base::StringValue(ProxyPrefs::kFixedServersProxyModeName)); 132 new base::Value(ProxyPrefs::kFixedServersProxyModeName));
133 PolicyMap policy; 133 PolicyMap policy;
134 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 134 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
135 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); 135 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr);
136 policy.Set(key::kProxyBypassList, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 136 policy.Set(key::kProxyBypassList, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
137 POLICY_SOURCE_CLOUD, base::MakeUnique<base::StringValue>("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::StringValue>("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(prefs->GetDictionary(proxy_config::prefs::kProxy));
148 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 148 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
149 assertProxyServer(dict, "789"); 149 assertProxyServer(dict, "789");
150 assertPacUrl(dict, std::string()); 150 assertPacUrl(dict, std::string());
151 assertBypassList(dict, "123"); 151 assertBypassList(dict, "123");
152 152
153 // Try a second time time with the managed PrefStore in place, the 153 // Try a second time time with the managed PrefStore in place, the
154 // manual proxy policy should have removed all traces of the command 154 // manual proxy policy should have removed all traces of the command
155 // line and replaced them with the policy versions. 155 // line and replaced them with the policy versions.
156 prefs = CreatePrefService(true); 156 prefs = CreatePrefService(true);
157 ProxyConfigDictionary dict2( 157 ProxyConfigDictionary dict2(
158 prefs->GetDictionary(proxy_config::prefs::kProxy)); 158 prefs->GetDictionary(proxy_config::prefs::kProxy));
159 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS); 159 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS);
160 assertProxyServer(dict2, "ghi"); 160 assertProxyServer(dict2, "ghi");
161 assertPacUrl(dict2, std::string()); 161 assertPacUrl(dict2, std::string());
162 assertBypassList(dict2, "abc"); 162 assertBypassList(dict2, "abc");
163 } 163 }
164 164
165 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { 165 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) {
166 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 166 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
167 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 167 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
168 std::unique_ptr<base::Value> mode_name( 168 std::unique_ptr<base::Value> mode_name(
169 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName)); 169 new base::Value(ProxyPrefs::kAutoDetectProxyModeName));
170 PolicyMap policy; 170 PolicyMap policy;
171 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 171 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
172 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); 172 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr);
173 provider_.UpdateChromePolicy(policy); 173 provider_.UpdateChromePolicy(policy);
174 174
175 // First verify that command-line options are set correctly when 175 // First verify that command-line options are set correctly when
176 // there is no policy in effect. 176 // there is no policy in effect.
177 std::unique_ptr<PrefService> prefs = CreatePrefService(false); 177 std::unique_ptr<PrefService> prefs = CreatePrefService(false);
178 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); 178 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
179 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 179 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
180 assertProxyServer(dict, "789"); 180 assertProxyServer(dict, "789");
181 assertPacUrl(dict, std::string()); 181 assertPacUrl(dict, std::string());
182 assertBypassList(dict, "123"); 182 assertBypassList(dict, "123");
183 183
184 // Try a second time time with the managed PrefStore in place, the 184 // Try a second time time with the managed PrefStore in place, the
185 // no proxy policy should have removed all traces of the command 185 // no proxy policy should have removed all traces of the command
186 // line proxy settings, even though they were not the specific one 186 // line proxy settings, even though they were not the specific one
187 // set in policy. 187 // set in policy.
188 prefs = CreatePrefService(true); 188 prefs = CreatePrefService(true);
189 ProxyConfigDictionary dict2( 189 ProxyConfigDictionary dict2(
190 prefs->GetDictionary(proxy_config::prefs::kProxy)); 190 prefs->GetDictionary(proxy_config::prefs::kProxy));
191 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 191 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
192 } 192 }
193 193
194 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) { 194 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) {
195 command_line_.AppendSwitch(switches::kNoProxyServer); 195 command_line_.AppendSwitch(switches::kNoProxyServer);
196 std::unique_ptr<base::Value> mode_name( 196 std::unique_ptr<base::Value> mode_name(
197 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName)); 197 new base::Value(ProxyPrefs::kAutoDetectProxyModeName));
198 PolicyMap policy; 198 PolicyMap policy;
199 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 199 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
200 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); 200 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr);
201 provider_.UpdateChromePolicy(policy); 201 provider_.UpdateChromePolicy(policy);
202 202
203 // First verify that command-line options are set correctly when 203 // First verify that command-line options are set correctly when
204 // there is no policy in effect. 204 // there is no policy in effect.
205 std::unique_ptr<PrefService> prefs = CreatePrefService(false); 205 std::unique_ptr<PrefService> prefs = CreatePrefService(false);
206 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); 206 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
207 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); 207 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT);
208 208
209 // Try a second time time with the managed PrefStore in place, the 209 // Try a second time time with the managed PrefStore in place, the
210 // auto-detect should be overridden. The default pref store must be 210 // auto-detect should be overridden. The default pref store must be
211 // in place with the appropriate default value for this to work. 211 // in place with the appropriate default value for this to work.
212 prefs = CreatePrefService(true); 212 prefs = CreatePrefService(true);
213 ProxyConfigDictionary dict2( 213 ProxyConfigDictionary dict2(
214 prefs->GetDictionary(proxy_config::prefs::kProxy)); 214 prefs->GetDictionary(proxy_config::prefs::kProxy));
215 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 215 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
216 } 216 }
217 217
218 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) { 218 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) {
219 command_line_.AppendSwitch(switches::kProxyAutoDetect); 219 command_line_.AppendSwitch(switches::kProxyAutoDetect);
220 std::unique_ptr<base::Value> mode_name( 220 std::unique_ptr<base::Value> mode_name(
221 new base::StringValue(ProxyPrefs::kDirectProxyModeName)); 221 new base::Value(ProxyPrefs::kDirectProxyModeName));
222 PolicyMap policy; 222 PolicyMap policy;
223 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 223 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
224 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr); 224 POLICY_SOURCE_CLOUD, std::move(mode_name), nullptr);
225 provider_.UpdateChromePolicy(policy); 225 provider_.UpdateChromePolicy(policy);
226 226
227 // First verify that the auto-detect is set if there is no managed 227 // First verify that the auto-detect is set if there is no managed
228 // PrefStore. 228 // PrefStore.
229 std::unique_ptr<PrefService> prefs = CreatePrefService(false); 229 std::unique_ptr<PrefService> prefs = CreatePrefService(false);
230 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy)); 230 ProxyConfigDictionary dict(prefs->GetDictionary(proxy_config::prefs::kProxy));
231 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); 231 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT);
232 232
233 // Try a second time time with the managed PrefStore in place, the 233 // Try a second time time with the managed PrefStore in place, the
234 // auto-detect should be overridden. The default pref store must be 234 // auto-detect should be overridden. The default pref store must be
235 // in place with the appropriate default value for this to work. 235 // in place with the appropriate default value for this to work.
236 prefs = CreatePrefService(true); 236 prefs = CreatePrefService(true);
237 ProxyConfigDictionary dict2( 237 ProxyConfigDictionary dict2(
238 prefs->GetDictionary(proxy_config::prefs::kProxy)); 238 prefs->GetDictionary(proxy_config::prefs::kProxy));
239 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); 239 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT);
240 } 240 }
241 241
242 } // namespace policy 242 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/prefs/profile_pref_store_manager_unittest.cc ('k') | chrome/browser/prefs/session_startup_pref.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698