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

Side by Side Diff: chrome/browser/extensions/extension_proxy_api_helpers_unittest.cc

Issue 6871019: Enable (optional) blocking of webrequests in case a PAC script cannot be fetched or is invalid. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 // Unit tests for helper functions for the Chrome Extensions Proxy Settings API. 5 // Unit tests for helper functions for the Chrome Extensions Proxy Settings API.
6 6
7 #include "base/scoped_ptr.h" 7 #include "base/scoped_ptr.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_proxy_api_constants.h" 9 #include "chrome/browser/extensions/extension_proxy_api_constants.h"
10 #include "chrome/browser/extensions/extension_proxy_api_helpers.h" 10 #include "chrome/browser/extensions/extension_proxy_api_helpers.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ASSERT_TRUE( 182 ASSERT_TRUE(
183 GetBypassListFromExtensionPref(&proxy_config, &out, &error)); 183 GetBypassListFromExtensionPref(&proxy_config, &out, &error));
184 EXPECT_EQ("host1,host2", out); 184 EXPECT_EQ("host1,host2", out);
185 EXPECT_EQ(std::string(), error); 185 EXPECT_EQ(std::string(), error);
186 } 186 }
187 187
188 TEST(ExtensionProxyApiHelpers, CreateProxyConfigDict) { 188 TEST(ExtensionProxyApiHelpers, CreateProxyConfigDict) {
189 std::string error; 189 std::string error;
190 scoped_ptr<DictionaryValue> exp_direct(ProxyConfigDictionary::CreateDirect()); 190 scoped_ptr<DictionaryValue> exp_direct(ProxyConfigDictionary::CreateDirect());
191 scoped_ptr<DictionaryValue> out_direct( 191 scoped_ptr<DictionaryValue> out_direct(
192 CreateProxyConfigDict(ProxyPrefs::MODE_DIRECT, "", "", "", "", &error)); 192 CreateProxyConfigDict(ProxyPrefs::MODE_DIRECT, false, "", "", "", "",
193 &error));
193 EXPECT_TRUE(Value::Equals(exp_direct.get(), out_direct.get())); 194 EXPECT_TRUE(Value::Equals(exp_direct.get(), out_direct.get()));
194 195
195 scoped_ptr<DictionaryValue> exp_auto( 196 scoped_ptr<DictionaryValue> exp_auto(
196 ProxyConfigDictionary::CreateAutoDetect()); 197 ProxyConfigDictionary::CreateAutoDetect());
197 scoped_ptr<DictionaryValue> out_auto( 198 scoped_ptr<DictionaryValue> out_auto(
198 CreateProxyConfigDict(ProxyPrefs::MODE_AUTO_DETECT, "", "", "", "", 199 CreateProxyConfigDict(ProxyPrefs::MODE_AUTO_DETECT, false, "", "", "", "",
199 &error)); 200 &error));
200 EXPECT_TRUE(Value::Equals(exp_auto.get(), out_auto.get())); 201 EXPECT_TRUE(Value::Equals(exp_auto.get(), out_auto.get()));
201 202
202 scoped_ptr<DictionaryValue> exp_pac_url( 203 scoped_ptr<DictionaryValue> exp_pac_url(
203 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl)); 204 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false));
204 scoped_ptr<DictionaryValue> out_pac_url( 205 scoped_ptr<DictionaryValue> out_pac_url(
205 CreateProxyConfigDict(ProxyPrefs::MODE_PAC_SCRIPT, kSamplePacScriptUrl, 206 CreateProxyConfigDict(ProxyPrefs::MODE_PAC_SCRIPT, false,
206 "", "", "", &error)); 207 kSamplePacScriptUrl, "", "", "", &error));
207 EXPECT_TRUE(Value::Equals(exp_pac_url.get(), out_pac_url.get())); 208 EXPECT_TRUE(Value::Equals(exp_pac_url.get(), out_pac_url.get()));
208 209
209 scoped_ptr<DictionaryValue> exp_pac_data( 210 scoped_ptr<DictionaryValue> exp_pac_data(
210 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptAsDataUrl)); 211 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptAsDataUrl, false));
211 scoped_ptr<DictionaryValue> out_pac_data( 212 scoped_ptr<DictionaryValue> out_pac_data(
212 CreateProxyConfigDict(ProxyPrefs::MODE_PAC_SCRIPT, "", 213 CreateProxyConfigDict(ProxyPrefs::MODE_PAC_SCRIPT, false, "",
213 kSamplePacScript, "", "", &error)); 214 kSamplePacScript, "", "", &error));
214 EXPECT_TRUE(Value::Equals(exp_pac_data.get(), out_pac_data.get())); 215 EXPECT_TRUE(Value::Equals(exp_pac_data.get(), out_pac_data.get()));
215 216
216 scoped_ptr<DictionaryValue> exp_fixed( 217 scoped_ptr<DictionaryValue> exp_fixed(
217 ProxyConfigDictionary::CreateFixedServers("foo:80", "localhost")); 218 ProxyConfigDictionary::CreateFixedServers("foo:80", "localhost"));
218 scoped_ptr<DictionaryValue> out_fixed( 219 scoped_ptr<DictionaryValue> out_fixed(
219 CreateProxyConfigDict(ProxyPrefs::MODE_FIXED_SERVERS, "", "", 220 CreateProxyConfigDict(ProxyPrefs::MODE_FIXED_SERVERS, false, "", "",
220 "foo:80", "localhost", &error)); 221 "foo:80", "localhost", &error));
221 EXPECT_TRUE(Value::Equals(exp_fixed.get(), out_fixed.get())); 222 EXPECT_TRUE(Value::Equals(exp_fixed.get(), out_fixed.get()));
222 223
223 scoped_ptr<DictionaryValue> exp_system(ProxyConfigDictionary::CreateSystem()); 224 scoped_ptr<DictionaryValue> exp_system(ProxyConfigDictionary::CreateSystem());
224 scoped_ptr<DictionaryValue> out_system( 225 scoped_ptr<DictionaryValue> out_system(
225 CreateProxyConfigDict(ProxyPrefs::MODE_SYSTEM, "", "", "", "", &error)); 226 CreateProxyConfigDict(ProxyPrefs::MODE_SYSTEM, false, "", "", "", "",
227 &error));
226 EXPECT_TRUE(Value::Equals(exp_system.get(), out_system.get())); 228 EXPECT_TRUE(Value::Equals(exp_system.get(), out_system.get()));
227 229
228 // Neither of them should have set an error. 230 // Neither of them should have set an error.
229 EXPECT_EQ(std::string(), error); 231 EXPECT_EQ(std::string(), error);
230 } 232 }
231 233
232 TEST(ExtensionProxyApiHelpers, GetProxyServer) { 234 TEST(ExtensionProxyApiHelpers, GetProxyServer) {
233 DictionaryValue proxy_server_dict; 235 DictionaryValue proxy_server_dict;
234 net::ProxyServer created; 236 net::ProxyServer created;
235 std::string error; 237 std::string error;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 ListValue* bypass_list = new ListValue; 286 ListValue* bypass_list = new ListValue;
285 bypass_list->Append(Value::CreateStringValue("localhost")); 287 bypass_list->Append(Value::CreateStringValue("localhost"));
286 expected->Set(keys::kProxyConfigBypassList, bypass_list); 288 expected->Set(keys::kProxyConfigBypassList, bypass_list);
287 289
288 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get())); 290 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get()));
289 } 291 }
290 292
291 // Test if a PAC script URL is specified. 293 // Test if a PAC script URL is specified.
292 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) { 294 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) {
293 scoped_ptr<DictionaryValue> browser_pref( 295 scoped_ptr<DictionaryValue> browser_pref(
294 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl)); 296 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false));
295 ProxyConfigDictionary config(browser_pref.get()); 297 ProxyConfigDictionary config(browser_pref.get());
296 scoped_ptr<DictionaryValue> extension_pref(CreatePacScriptDict(config)); 298 scoped_ptr<DictionaryValue> extension_pref(CreatePacScriptDict(config));
297 ASSERT_TRUE(extension_pref.get()); 299 ASSERT_TRUE(extension_pref.get());
298 300
299 scoped_ptr<DictionaryValue> expected(new DictionaryValue); 301 scoped_ptr<DictionaryValue> expected(new DictionaryValue);
300 expected->SetString(keys::kProxyConfigPacScriptUrl, kSamplePacScriptUrl); 302 expected->SetString(keys::kProxyConfigPacScriptUrl, kSamplePacScriptUrl);
303 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false);
301 304
302 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get())); 305 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get()));
303 } 306 }
304 307
305 // Test if a PAC script is encoded in a data URL. 308 // Test if a PAC script is encoded in a data URL.
306 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWidthData) { 309 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWidthData) {
307 scoped_ptr<DictionaryValue> browser_pref( 310 scoped_ptr<DictionaryValue> browser_pref(
308 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptAsDataUrl)); 311 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptAsDataUrl, false));
309 ProxyConfigDictionary config(browser_pref.get()); 312 ProxyConfigDictionary config(browser_pref.get());
310 scoped_ptr<DictionaryValue> extension_pref(CreatePacScriptDict(config)); 313 scoped_ptr<DictionaryValue> extension_pref(CreatePacScriptDict(config));
311 ASSERT_TRUE(extension_pref.get()); 314 ASSERT_TRUE(extension_pref.get());
312 315
313 scoped_ptr<DictionaryValue> expected(new DictionaryValue); 316 scoped_ptr<DictionaryValue> expected(new DictionaryValue);
314 expected->SetString(keys::kProxyConfigPacScriptData, kSamplePacScript); 317 expected->SetString(keys::kProxyConfigPacScriptData, kSamplePacScript);
318 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false);
315 319
316 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get())); 320 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get()));
317 } 321 }
318 322
319 TEST(ExtensionProxyApiHelpers, TokenizeToStringList) { 323 TEST(ExtensionProxyApiHelpers, TokenizeToStringList) {
320 ListValue expected; 324 ListValue expected;
321 expected.Append(Value::CreateStringValue("s1")); 325 expected.Append(Value::CreateStringValue("s1"));
322 expected.Append(Value::CreateStringValue("s2")); 326 expected.Append(Value::CreateStringValue("s2"));
323 expected.Append(Value::CreateStringValue("s3")); 327 expected.Append(Value::CreateStringValue("s3"));
324 328
325 scoped_ptr<ListValue> out(TokenizeToStringList("s1;s2;s3", ";")); 329 scoped_ptr<ListValue> out(TokenizeToStringList("s1;s2;s3", ";"));
326 EXPECT_TRUE(Value::Equals(&expected, out.get())); 330 EXPECT_TRUE(Value::Equals(&expected, out.get()));
327 } 331 }
328 332
329 } // namespace extension_proxy_api_helpers 333 } // namespace extension_proxy_api_helpers
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_proxy_api_helpers.cc ('k') | chrome/browser/net/pref_proxy_config_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698