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

Side by Side Diff: chrome/browser/extensions/api/proxy/proxy_api_helpers_unittest.cc

Issue 22885002: c/b/extensions, json_schema_compiler: Do not use Value::Create*. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed C-style casts. Created 7 years, 4 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 // 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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 // Currently we are still missing a proxy config entry. 197 // Currently we are still missing a proxy config entry.
198 // This is silently ignored. 198 // This is silently ignored.
199 ASSERT_TRUE( 199 ASSERT_TRUE(
200 GetBypassListFromExtensionPref(&proxy_config, &out, &error, 200 GetBypassListFromExtensionPref(&proxy_config, &out, &error,
201 &bad_message)); 201 &bad_message));
202 EXPECT_EQ(std::string(), out); 202 EXPECT_EQ(std::string(), out);
203 EXPECT_EQ(std::string(), error); 203 EXPECT_EQ(std::string(), error);
204 EXPECT_FALSE(bad_message); 204 EXPECT_FALSE(bad_message);
205 205
206 base::ListValue* bypass_list = new base::ListValue; 206 base::ListValue* bypass_list = new base::ListValue;
207 bypass_list->Append(Value::CreateStringValue("host1")); 207 bypass_list->Append(new base::StringValue("host1"));
208 bypass_list->Append(Value::CreateStringValue("host2")); 208 bypass_list->Append(new base::StringValue("host2"));
209 base::DictionaryValue* proxy_rules = new base::DictionaryValue; 209 base::DictionaryValue* proxy_rules = new base::DictionaryValue;
210 proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list); 210 proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list);
211 proxy_config.Set(keys::kProxyConfigRules, proxy_rules); 211 proxy_config.Set(keys::kProxyConfigRules, proxy_rules);
212 212
213 ASSERT_TRUE( 213 ASSERT_TRUE(
214 GetBypassListFromExtensionPref(&proxy_config, &out, &error, 214 GetBypassListFromExtensionPref(&proxy_config, &out, &error,
215 &bad_message)); 215 &bad_message));
216 EXPECT_EQ("host1,host2", out); 216 EXPECT_EQ("host1,host2", out);
217 EXPECT_EQ(std::string(), error); 217 EXPECT_EQ(std::string(), error);
218 EXPECT_FALSE(bad_message); 218 EXPECT_FALSE(bad_message);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 ASSERT_TRUE( 316 ASSERT_TRUE(
317 GetProxyServer(&proxy_server_dict, net::ProxyServer::SCHEME_HTTP, 317 GetProxyServer(&proxy_server_dict, net::ProxyServer::SCHEME_HTTP,
318 &created, &error, &bad_message)); 318 &created, &error, &bad_message));
319 EXPECT_EQ("SOCKS proxy_server:1234", created.ToPacString()); 319 EXPECT_EQ("SOCKS proxy_server:1234", created.ToPacString());
320 EXPECT_FALSE(bad_message); 320 EXPECT_FALSE(bad_message);
321 } 321 }
322 322
323 TEST(ExtensionProxyApiHelpers, JoinUrlList) { 323 TEST(ExtensionProxyApiHelpers, JoinUrlList) {
324 bool bad_message = false; 324 bool bad_message = false;
325 base::ListValue list; 325 base::ListValue list;
326 list.Append(Value::CreateStringValue("s1")); 326 list.Append(new base::StringValue("s1"));
327 list.Append(Value::CreateStringValue("s2")); 327 list.Append(new base::StringValue("s2"));
328 list.Append(Value::CreateStringValue("s3")); 328 list.Append(new base::StringValue("s3"));
329 329
330 std::string out; 330 std::string out;
331 std::string error; 331 std::string error;
332 ASSERT_TRUE(JoinUrlList(&list, ";", &out, &error, &bad_message)); 332 ASSERT_TRUE(JoinUrlList(&list, ";", &out, &error, &bad_message));
333 EXPECT_EQ("s1;s2;s3", out); 333 EXPECT_EQ("s1;s2;s3", out);
334 EXPECT_FALSE(bad_message); 334 EXPECT_FALSE(bad_message);
335 } 335 }
336 336
337 // This tests CreateProxyServerDict as well. 337 // This tests CreateProxyServerDict as well.
338 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDict) { 338 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDict) {
339 scoped_ptr<base::DictionaryValue> browser_pref( 339 scoped_ptr<base::DictionaryValue> browser_pref(
340 ProxyConfigDictionary::CreateFixedServers( 340 ProxyConfigDictionary::CreateFixedServers(
341 "http=proxy1:80;https=proxy2:80;ftp=proxy3:80;socks=proxy4:80", 341 "http=proxy1:80;https=proxy2:80;ftp=proxy3:80;socks=proxy4:80",
342 "localhost")); 342 "localhost"));
343 ProxyConfigDictionary config(browser_pref.get()); 343 ProxyConfigDictionary config(browser_pref.get());
344 scoped_ptr<base::DictionaryValue> extension_pref( 344 scoped_ptr<base::DictionaryValue> extension_pref(
345 CreateProxyRulesDict(config)); 345 CreateProxyRulesDict(config));
346 ASSERT_TRUE(extension_pref.get()); 346 ASSERT_TRUE(extension_pref.get());
347 347
348 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 348 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue);
349 expected->Set("proxyForHttp", 349 expected->Set("proxyForHttp",
350 CreateTestProxyServerDict("http", "proxy1", 80)); 350 CreateTestProxyServerDict("http", "proxy1", 80));
351 expected->Set("proxyForHttps", 351 expected->Set("proxyForHttps",
352 CreateTestProxyServerDict("http", "proxy2", 80)); 352 CreateTestProxyServerDict("http", "proxy2", 80));
353 expected->Set("proxyForFtp", 353 expected->Set("proxyForFtp",
354 CreateTestProxyServerDict("http", "proxy3", 80)); 354 CreateTestProxyServerDict("http", "proxy3", 80));
355 expected->Set("fallbackProxy", 355 expected->Set("fallbackProxy",
356 CreateTestProxyServerDict("socks4", "proxy4", 80)); 356 CreateTestProxyServerDict("socks4", "proxy4", 80));
357 base::ListValue* bypass_list = new base::ListValue; 357 base::ListValue* bypass_list = new base::ListValue;
358 bypass_list->Append(Value::CreateStringValue("localhost")); 358 bypass_list->Append(new base::StringValue("localhost"));
359 expected->Set(keys::kProxyConfigBypassList, bypass_list); 359 expected->Set(keys::kProxyConfigBypassList, bypass_list);
360 360
361 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get())); 361 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get()));
362 } 362 }
363 363
364 // Test multiple proxies per scheme -- expect that only the first is returned. 364 // Test multiple proxies per scheme -- expect that only the first is returned.
365 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDictMultipleProxies) { 365 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDictMultipleProxies) {
366 scoped_ptr<base::DictionaryValue> browser_pref( 366 scoped_ptr<base::DictionaryValue> browser_pref(
367 ProxyConfigDictionary::CreateFixedServers( 367 ProxyConfigDictionary::CreateFixedServers(
368 "http=proxy1:80,default://;https=proxy2:80,proxy1:80;ftp=proxy3:80," 368 "http=proxy1:80,default://;https=proxy2:80,proxy1:80;ftp=proxy3:80,"
369 "https://proxy5:443;socks=proxy4:80,proxy1:80", 369 "https://proxy5:443;socks=proxy4:80,proxy1:80",
370 "localhost")); 370 "localhost"));
371 ProxyConfigDictionary config(browser_pref.get()); 371 ProxyConfigDictionary config(browser_pref.get());
372 scoped_ptr<base::DictionaryValue> extension_pref( 372 scoped_ptr<base::DictionaryValue> extension_pref(
373 CreateProxyRulesDict(config)); 373 CreateProxyRulesDict(config));
374 ASSERT_TRUE(extension_pref.get()); 374 ASSERT_TRUE(extension_pref.get());
375 375
376 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 376 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue);
377 expected->Set("proxyForHttp", 377 expected->Set("proxyForHttp",
378 CreateTestProxyServerDict("http", "proxy1", 80)); 378 CreateTestProxyServerDict("http", "proxy1", 80));
379 expected->Set("proxyForHttps", 379 expected->Set("proxyForHttps",
380 CreateTestProxyServerDict("http", "proxy2", 80)); 380 CreateTestProxyServerDict("http", "proxy2", 80));
381 expected->Set("proxyForFtp", 381 expected->Set("proxyForFtp",
382 CreateTestProxyServerDict("http", "proxy3", 80)); 382 CreateTestProxyServerDict("http", "proxy3", 80));
383 expected->Set("fallbackProxy", 383 expected->Set("fallbackProxy",
384 CreateTestProxyServerDict("socks4", "proxy4", 80)); 384 CreateTestProxyServerDict("socks4", "proxy4", 80));
385 base::ListValue* bypass_list = new base::ListValue; 385 base::ListValue* bypass_list = new base::ListValue;
386 bypass_list->Append(Value::CreateStringValue("localhost")); 386 bypass_list->Append(new base::StringValue("localhost"));
387 expected->Set(keys::kProxyConfigBypassList, bypass_list); 387 expected->Set(keys::kProxyConfigBypassList, bypass_list);
388 388
389 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get())); 389 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get()));
390 } 390 }
391 391
392 // Test if a PAC script URL is specified. 392 // Test if a PAC script URL is specified.
393 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) { 393 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) {
394 scoped_ptr<base::DictionaryValue> browser_pref( 394 scoped_ptr<base::DictionaryValue> browser_pref(
395 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false)); 395 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false));
396 ProxyConfigDictionary config(browser_pref.get()); 396 ProxyConfigDictionary config(browser_pref.get());
(...skipping 17 matching lines...) Expand all
414 414
415 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 415 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue);
416 expected->SetString(keys::kProxyConfigPacScriptData, kSamplePacScript); 416 expected->SetString(keys::kProxyConfigPacScriptData, kSamplePacScript);
417 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false); 417 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false);
418 418
419 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get())); 419 EXPECT_TRUE(Value::Equals(expected.get(), extension_pref.get()));
420 } 420 }
421 421
422 TEST(ExtensionProxyApiHelpers, TokenizeToStringList) { 422 TEST(ExtensionProxyApiHelpers, TokenizeToStringList) {
423 base::ListValue expected; 423 base::ListValue expected;
424 expected.Append(Value::CreateStringValue("s1")); 424 expected.Append(new base::StringValue("s1"));
425 expected.Append(Value::CreateStringValue("s2")); 425 expected.Append(new base::StringValue("s2"));
426 expected.Append(Value::CreateStringValue("s3")); 426 expected.Append(new base::StringValue("s3"));
427 427
428 scoped_ptr<base::ListValue> out(TokenizeToStringList("s1;s2;s3", ";")); 428 scoped_ptr<base::ListValue> out(TokenizeToStringList("s1;s2;s3", ";"));
429 EXPECT_TRUE(Value::Equals(&expected, out.get())); 429 EXPECT_TRUE(Value::Equals(&expected, out.get()));
430 } 430 }
431 431
432 } // namespace proxy_api_helpers 432 } // namespace proxy_api_helpers
433 } // namespace extensions 433 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/proxy/proxy_api_helpers.cc ('k') | chrome/browser/extensions/api/rtc_private/rtc_private_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698