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

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

Issue 388963002: Get rid of the rest of CreateStringValue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bad rebase Created 6 years, 5 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 | Annotate | Revision Log
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 "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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 base::MessageLoop loop_; 114 base::MessageLoop loop_;
115 CommandLine command_line_; 115 CommandLine command_line_;
116 MockConfigurationPolicyProvider provider_; 116 MockConfigurationPolicyProvider provider_;
117 scoped_ptr<PolicyServiceImpl> policy_service_; 117 scoped_ptr<PolicyServiceImpl> policy_service_;
118 }; 118 };
119 119
120 TEST_F(ProxyPolicyTest, OverridesCommandLineOptions) { 120 TEST_F(ProxyPolicyTest, OverridesCommandLineOptions) {
121 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 121 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
122 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 122 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
123 base::Value* mode_name = base::Value::CreateStringValue( 123 base::Value* mode_name =
124 ProxyPrefs::kFixedServersProxyModeName); 124 new base::StringValue(ProxyPrefs::kFixedServersProxyModeName);
125 PolicyMap policy; 125 PolicyMap policy;
126 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 126 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
127 mode_name, NULL); 127 mode_name, NULL);
128 policy.Set(key::kProxyBypassList, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 128 policy.Set(key::kProxyBypassList,
129 base::Value::CreateStringValue("abc"), NULL); 129 POLICY_LEVEL_MANDATORY,
130 policy.Set(key::kProxyServer, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 130 POLICY_SCOPE_USER,
131 base::Value::CreateStringValue("ghi"), NULL); 131 new base::StringValue("abc"),
132 NULL);
133 policy.Set(key::kProxyServer,
134 POLICY_LEVEL_MANDATORY,
135 POLICY_SCOPE_USER,
136 new base::StringValue("ghi"),
137 NULL);
132 provider_.UpdateChromePolicy(policy); 138 provider_.UpdateChromePolicy(policy);
133 139
134 // First verify that command-line options are set correctly when 140 // First verify that command-line options are set correctly when
135 // there is no policy in effect. 141 // there is no policy in effect.
136 scoped_ptr<PrefService> prefs(CreatePrefService(false)); 142 scoped_ptr<PrefService> prefs(CreatePrefService(false));
137 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 143 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
138 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 144 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
139 assertProxyServer(dict, "789"); 145 assertProxyServer(dict, "789");
140 assertPacUrl(dict, std::string()); 146 assertPacUrl(dict, std::string());
141 assertBypassList(dict, "123"); 147 assertBypassList(dict, "123");
142 148
143 // Try a second time time with the managed PrefStore in place, the 149 // Try a second time time with the managed PrefStore in place, the
144 // manual proxy policy should have removed all traces of the command 150 // manual proxy policy should have removed all traces of the command
145 // line and replaced them with the policy versions. 151 // line and replaced them with the policy versions.
146 prefs = CreatePrefService(true); 152 prefs = CreatePrefService(true);
147 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 153 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy));
148 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS); 154 assertProxyMode(dict2, ProxyPrefs::MODE_FIXED_SERVERS);
149 assertProxyServer(dict2, "ghi"); 155 assertProxyServer(dict2, "ghi");
150 assertPacUrl(dict2, std::string()); 156 assertPacUrl(dict2, std::string());
151 assertBypassList(dict2, "abc"); 157 assertBypassList(dict2, "abc");
152 } 158 }
153 159
154 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) { 160 TEST_F(ProxyPolicyTest, OverridesUnrelatedCommandLineOptions) {
155 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123"); 161 command_line_.AppendSwitchASCII(switches::kProxyBypassList, "123");
156 command_line_.AppendSwitchASCII(switches::kProxyServer, "789"); 162 command_line_.AppendSwitchASCII(switches::kProxyServer, "789");
157 base::Value* mode_name = base::Value::CreateStringValue( 163 base::Value* mode_name =
158 ProxyPrefs::kAutoDetectProxyModeName); 164 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName);
159 PolicyMap policy; 165 PolicyMap policy;
160 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 166 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
161 mode_name, NULL); 167 mode_name, NULL);
162 provider_.UpdateChromePolicy(policy); 168 provider_.UpdateChromePolicy(policy);
163 169
164 // First verify that command-line options are set correctly when 170 // First verify that command-line options are set correctly when
165 // there is no policy in effect. 171 // there is no policy in effect.
166 scoped_ptr<PrefService> prefs = CreatePrefService(false); 172 scoped_ptr<PrefService> prefs = CreatePrefService(false);
167 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 173 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
168 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS); 174 assertProxyMode(dict, ProxyPrefs::MODE_FIXED_SERVERS);
169 assertProxyServer(dict, "789"); 175 assertProxyServer(dict, "789");
170 assertPacUrl(dict, std::string()); 176 assertPacUrl(dict, std::string());
171 assertBypassList(dict, "123"); 177 assertBypassList(dict, "123");
172 178
173 // Try a second time time with the managed PrefStore in place, the 179 // Try a second time time with the managed PrefStore in place, the
174 // no proxy policy should have removed all traces of the command 180 // no proxy policy should have removed all traces of the command
175 // line proxy settings, even though they were not the specific one 181 // line proxy settings, even though they were not the specific one
176 // set in policy. 182 // set in policy.
177 prefs = CreatePrefService(true); 183 prefs = CreatePrefService(true);
178 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 184 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy));
179 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 185 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
180 } 186 }
181 187
182 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) { 188 TEST_F(ProxyPolicyTest, OverridesCommandLineNoProxy) {
183 command_line_.AppendSwitch(switches::kNoProxyServer); 189 command_line_.AppendSwitch(switches::kNoProxyServer);
184 base::Value* mode_name = base::Value::CreateStringValue( 190 base::Value* mode_name =
185 ProxyPrefs::kAutoDetectProxyModeName); 191 new base::StringValue(ProxyPrefs::kAutoDetectProxyModeName);
186 PolicyMap policy; 192 PolicyMap policy;
187 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 193 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
188 mode_name, NULL); 194 mode_name, NULL);
189 provider_.UpdateChromePolicy(policy); 195 provider_.UpdateChromePolicy(policy);
190 196
191 // First verify that command-line options are set correctly when 197 // First verify that command-line options are set correctly when
192 // there is no policy in effect. 198 // there is no policy in effect.
193 scoped_ptr<PrefService> prefs = CreatePrefService(false); 199 scoped_ptr<PrefService> prefs = CreatePrefService(false);
194 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 200 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
195 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT); 201 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_DIRECT);
196 202
197 // Try a second time time with the managed PrefStore in place, the 203 // Try a second time time with the managed PrefStore in place, the
198 // auto-detect should be overridden. The default pref store must be 204 // auto-detect should be overridden. The default pref store must be
199 // in place with the appropriate default value for this to work. 205 // in place with the appropriate default value for this to work.
200 prefs = CreatePrefService(true); 206 prefs = CreatePrefService(true);
201 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 207 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy));
202 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT); 208 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_AUTO_DETECT);
203 } 209 }
204 210
205 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) { 211 TEST_F(ProxyPolicyTest, OverridesCommandLineAutoDetect) {
206 command_line_.AppendSwitch(switches::kProxyAutoDetect); 212 command_line_.AppendSwitch(switches::kProxyAutoDetect);
207 base::Value* mode_name = base::Value::CreateStringValue( 213 base::Value* mode_name =
208 ProxyPrefs::kDirectProxyModeName); 214 new base::StringValue(ProxyPrefs::kDirectProxyModeName);
209 PolicyMap policy; 215 PolicyMap policy;
210 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 216 policy.Set(key::kProxyMode, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER,
211 mode_name, NULL); 217 mode_name, NULL);
212 provider_.UpdateChromePolicy(policy); 218 provider_.UpdateChromePolicy(policy);
213 219
214 // First verify that the auto-detect is set if there is no managed 220 // First verify that the auto-detect is set if there is no managed
215 // PrefStore. 221 // PrefStore.
216 scoped_ptr<PrefService> prefs = CreatePrefService(false); 222 scoped_ptr<PrefService> prefs = CreatePrefService(false);
217 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy)); 223 ProxyConfigDictionary dict(prefs->GetDictionary(prefs::kProxy));
218 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT); 224 assertProxyModeWithoutParams(dict, ProxyPrefs::MODE_AUTO_DETECT);
219 225
220 // Try a second time time with the managed PrefStore in place, the 226 // Try a second time time with the managed PrefStore in place, the
221 // auto-detect should be overridden. The default pref store must be 227 // auto-detect should be overridden. The default pref store must be
222 // in place with the appropriate default value for this to work. 228 // in place with the appropriate default value for this to work.
223 prefs = CreatePrefService(true); 229 prefs = CreatePrefService(true);
224 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy)); 230 ProxyConfigDictionary dict2(prefs->GetDictionary(prefs::kProxy));
225 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT); 231 assertProxyModeWithoutParams(dict2, ProxyPrefs::MODE_DIRECT);
226 } 232 }
227 233
228 } // namespace policy 234 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/prefs/pref_model_associator_unittest.cc ('k') | chrome/browser/prefs/session_startup_pref_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698