| 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 // 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/api/proxy/proxy_api_constants.h" | 9 #include "chrome/browser/extensions/api/proxy/proxy_api_constants.h" |
| 10 #include "chrome/browser/extensions/api/proxy/proxy_api_helpers.h" | 10 #include "chrome/browser/extensions/api/proxy/proxy_api_helpers.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 CreateTestProxyServerDict("http", "proxy3", 80)); | 321 CreateTestProxyServerDict("http", "proxy3", 80)); |
| 322 expected->Set("fallbackProxy", | 322 expected->Set("fallbackProxy", |
| 323 CreateTestProxyServerDict("socks4", "proxy4", 80)); | 323 CreateTestProxyServerDict("socks4", "proxy4", 80)); |
| 324 ListValue* bypass_list = new ListValue; | 324 ListValue* bypass_list = new ListValue; |
| 325 bypass_list->Append(Value::CreateStringValue("localhost")); | 325 bypass_list->Append(Value::CreateStringValue("localhost")); |
| 326 expected->Set(keys::kProxyConfigBypassList, bypass_list); | 326 expected->Set(keys::kProxyConfigBypassList, bypass_list); |
| 327 | 327 |
| 328 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get())); | 328 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get())); |
| 329 } | 329 } |
| 330 | 330 |
| 331 // Test multiple proxies per scheme -- expect that only the first is returned. |
| 332 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDictMultipleProxies) { |
| 333 scoped_ptr<DictionaryValue> browser_pref( |
| 334 ProxyConfigDictionary::CreateFixedServers( |
| 335 "http=proxy1:80,default://;https=proxy2:80,proxy1:80;ftp=proxy3:80," |
| 336 "https://proxy5:443;socks=proxy4:80,proxy1:80", |
| 337 "localhost")); |
| 338 ProxyConfigDictionary config(browser_pref.get()); |
| 339 scoped_ptr<DictionaryValue> extension_pref(CreateProxyRulesDict(config)); |
| 340 ASSERT_TRUE(extension_pref.get()); |
| 341 |
| 342 scoped_ptr<DictionaryValue> expected(new DictionaryValue); |
| 343 expected->Set("proxyForHttp", |
| 344 CreateTestProxyServerDict("http", "proxy1", 80)); |
| 345 expected->Set("proxyForHttps", |
| 346 CreateTestProxyServerDict("http", "proxy2", 80)); |
| 347 expected->Set("proxyForFtp", |
| 348 CreateTestProxyServerDict("http", "proxy3", 80)); |
| 349 expected->Set("fallbackProxy", |
| 350 CreateTestProxyServerDict("socks4", "proxy4", 80)); |
| 351 ListValue* bypass_list = new ListValue; |
| 352 bypass_list->Append(Value::CreateStringValue("localhost")); |
| 353 expected->Set(keys::kProxyConfigBypassList, bypass_list); |
| 354 |
| 355 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get())); |
| 356 } |
| 357 |
| 331 // Test if a PAC script URL is specified. | 358 // Test if a PAC script URL is specified. |
| 332 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) { | 359 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) { |
| 333 scoped_ptr<DictionaryValue> browser_pref( | 360 scoped_ptr<DictionaryValue> browser_pref( |
| 334 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false)); | 361 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false)); |
| 335 ProxyConfigDictionary config(browser_pref.get()); | 362 ProxyConfigDictionary config(browser_pref.get()); |
| 336 scoped_ptr<DictionaryValue> extension_pref(CreatePacScriptDict(config)); | 363 scoped_ptr<DictionaryValue> extension_pref(CreatePacScriptDict(config)); |
| 337 ASSERT_TRUE(extension_pref.get()); | 364 ASSERT_TRUE(extension_pref.get()); |
| 338 | 365 |
| 339 scoped_ptr<DictionaryValue> expected(new DictionaryValue); | 366 scoped_ptr<DictionaryValue> expected(new DictionaryValue); |
| 340 expected->SetString(keys::kProxyConfigPacScriptUrl, kSamplePacScriptUrl); | 367 expected->SetString(keys::kProxyConfigPacScriptUrl, kSamplePacScriptUrl); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 363 expected.Append(Value::CreateStringValue("s1")); | 390 expected.Append(Value::CreateStringValue("s1")); |
| 364 expected.Append(Value::CreateStringValue("s2")); | 391 expected.Append(Value::CreateStringValue("s2")); |
| 365 expected.Append(Value::CreateStringValue("s3")); | 392 expected.Append(Value::CreateStringValue("s3")); |
| 366 | 393 |
| 367 scoped_ptr<ListValue> out(TokenizeToStringList("s1;s2;s3", ";")); | 394 scoped_ptr<ListValue> out(TokenizeToStringList("s1;s2;s3", ";")); |
| 368 EXPECT_TRUE(Value::Equals(&expected, out.get())); | 395 EXPECT_TRUE(Value::Equals(&expected, out.get())); |
| 369 } | 396 } |
| 370 | 397 |
| 371 } // namespace proxy_api_helpers | 398 } // namespace proxy_api_helpers |
| 372 } // namespace extensions | 399 } // namespace extensions |
| OLD | NEW |