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

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

Issue 2030013003: Remove ListValue::Append(new {Fundamental,String}Value(...)) pattern in //chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 "chrome/browser/extensions/api/proxy/proxy_api_helpers.h" 7 #include "chrome/browser/extensions/api/proxy/proxy_api_helpers.h"
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // Currently we are still missing a proxy config entry. 199 // Currently we are still missing a proxy config entry.
200 // This is silently ignored. 200 // This is silently ignored.
201 ASSERT_TRUE( 201 ASSERT_TRUE(
202 GetBypassListFromExtensionPref(&proxy_config, &out, &error, 202 GetBypassListFromExtensionPref(&proxy_config, &out, &error,
203 &bad_message)); 203 &bad_message));
204 EXPECT_EQ(std::string(), out); 204 EXPECT_EQ(std::string(), out);
205 EXPECT_EQ(std::string(), error); 205 EXPECT_EQ(std::string(), error);
206 EXPECT_FALSE(bad_message); 206 EXPECT_FALSE(bad_message);
207 207
208 base::ListValue* bypass_list = new base::ListValue; 208 base::ListValue* bypass_list = new base::ListValue;
209 bypass_list->Append(new base::StringValue("host1")); 209 bypass_list->AppendString("host1");
210 bypass_list->Append(new base::StringValue("host2")); 210 bypass_list->AppendString("host2");
211 base::DictionaryValue* proxy_rules = new base::DictionaryValue; 211 base::DictionaryValue* proxy_rules = new base::DictionaryValue;
212 proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list); 212 proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list);
213 proxy_config.Set(keys::kProxyConfigRules, proxy_rules); 213 proxy_config.Set(keys::kProxyConfigRules, proxy_rules);
214 214
215 ASSERT_TRUE( 215 ASSERT_TRUE(
216 GetBypassListFromExtensionPref(&proxy_config, &out, &error, 216 GetBypassListFromExtensionPref(&proxy_config, &out, &error,
217 &bad_message)); 217 &bad_message));
218 EXPECT_EQ("host1,host2", out); 218 EXPECT_EQ("host1,host2", out);
219 EXPECT_EQ(std::string(), error); 219 EXPECT_EQ(std::string(), error);
220 EXPECT_FALSE(bad_message); 220 EXPECT_FALSE(bad_message);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 ASSERT_TRUE( 288 ASSERT_TRUE(
289 GetProxyServer(&proxy_server_dict, net::ProxyServer::SCHEME_HTTP, 289 GetProxyServer(&proxy_server_dict, net::ProxyServer::SCHEME_HTTP,
290 &created, &error, &bad_message)); 290 &created, &error, &bad_message));
291 EXPECT_EQ("SOCKS proxy_server:1234", created.ToPacString()); 291 EXPECT_EQ("SOCKS proxy_server:1234", created.ToPacString());
292 EXPECT_FALSE(bad_message); 292 EXPECT_FALSE(bad_message);
293 } 293 }
294 294
295 TEST(ExtensionProxyApiHelpers, JoinUrlList) { 295 TEST(ExtensionProxyApiHelpers, JoinUrlList) {
296 bool bad_message = false; 296 bool bad_message = false;
297 base::ListValue list; 297 base::ListValue list;
298 list.Append(new base::StringValue("s1")); 298 list.AppendString("s1");
299 list.Append(new base::StringValue("s2")); 299 list.AppendString("s2");
300 list.Append(new base::StringValue("s3")); 300 list.AppendString("s3");
301 301
302 std::string out; 302 std::string out;
303 std::string error; 303 std::string error;
304 ASSERT_TRUE(JoinUrlList(&list, ";", &out, &error, &bad_message)); 304 ASSERT_TRUE(JoinUrlList(&list, ";", &out, &error, &bad_message));
305 EXPECT_EQ("s1;s2;s3", out); 305 EXPECT_EQ("s1;s2;s3", out);
306 EXPECT_FALSE(bad_message); 306 EXPECT_FALSE(bad_message);
307 } 307 }
308 308
309 // This tests CreateProxyServerDict as well. 309 // This tests CreateProxyServerDict as well.
310 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDict) { 310 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDict) {
311 std::unique_ptr<base::DictionaryValue> browser_pref( 311 std::unique_ptr<base::DictionaryValue> browser_pref(
312 ProxyConfigDictionary::CreateFixedServers( 312 ProxyConfigDictionary::CreateFixedServers(
313 "http=proxy1:80;https=proxy2:80;ftp=proxy3:80;socks=proxy4:80", 313 "http=proxy1:80;https=proxy2:80;ftp=proxy3:80;socks=proxy4:80",
314 "localhost")); 314 "localhost"));
315 ProxyConfigDictionary config(browser_pref.get()); 315 ProxyConfigDictionary config(browser_pref.get());
316 std::unique_ptr<base::DictionaryValue> extension_pref( 316 std::unique_ptr<base::DictionaryValue> extension_pref(
317 CreateProxyRulesDict(config)); 317 CreateProxyRulesDict(config));
318 ASSERT_TRUE(extension_pref.get()); 318 ASSERT_TRUE(extension_pref.get());
319 319
320 std::unique_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 320 std::unique_ptr<base::DictionaryValue> expected(new base::DictionaryValue);
321 expected->Set("proxyForHttp", 321 expected->Set("proxyForHttp",
322 CreateTestProxyServerDict("http", "proxy1", 80)); 322 CreateTestProxyServerDict("http", "proxy1", 80));
323 expected->Set("proxyForHttps", 323 expected->Set("proxyForHttps",
324 CreateTestProxyServerDict("http", "proxy2", 80)); 324 CreateTestProxyServerDict("http", "proxy2", 80));
325 expected->Set("proxyForFtp", 325 expected->Set("proxyForFtp",
326 CreateTestProxyServerDict("http", "proxy3", 80)); 326 CreateTestProxyServerDict("http", "proxy3", 80));
327 expected->Set("fallbackProxy", 327 expected->Set("fallbackProxy",
328 CreateTestProxyServerDict("socks4", "proxy4", 80)); 328 CreateTestProxyServerDict("socks4", "proxy4", 80));
329 base::ListValue* bypass_list = new base::ListValue; 329 base::ListValue* bypass_list = new base::ListValue;
330 bypass_list->Append(new base::StringValue("localhost")); 330 bypass_list->AppendString("localhost");
331 expected->Set(keys::kProxyConfigBypassList, bypass_list); 331 expected->Set(keys::kProxyConfigBypassList, bypass_list);
332 332
333 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get())); 333 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get()));
334 } 334 }
335 335
336 // Test multiple proxies per scheme -- expect that only the first is returned. 336 // Test multiple proxies per scheme -- expect that only the first is returned.
337 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDictMultipleProxies) { 337 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDictMultipleProxies) {
338 std::unique_ptr<base::DictionaryValue> browser_pref( 338 std::unique_ptr<base::DictionaryValue> browser_pref(
339 ProxyConfigDictionary::CreateFixedServers( 339 ProxyConfigDictionary::CreateFixedServers(
340 "http=proxy1:80,default://;https=proxy2:80,proxy1:80;ftp=proxy3:80," 340 "http=proxy1:80,default://;https=proxy2:80,proxy1:80;ftp=proxy3:80,"
341 "https://proxy5:443;socks=proxy4:80,proxy1:80", 341 "https://proxy5:443;socks=proxy4:80,proxy1:80",
342 "localhost")); 342 "localhost"));
343 ProxyConfigDictionary config(browser_pref.get()); 343 ProxyConfigDictionary config(browser_pref.get());
344 std::unique_ptr<base::DictionaryValue> extension_pref( 344 std::unique_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 std::unique_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 348 std::unique_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(new base::StringValue("localhost")); 358 bypass_list->AppendString("localhost");
359 expected->Set(keys::kProxyConfigBypassList, bypass_list); 359 expected->Set(keys::kProxyConfigBypassList, bypass_list);
360 360
361 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get())); 361 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get()));
362 } 362 }
363 363
364 // Test if a PAC script URL is specified. 364 // Test if a PAC script URL is specified.
365 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) { 365 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) {
366 std::unique_ptr<base::DictionaryValue> browser_pref( 366 std::unique_ptr<base::DictionaryValue> browser_pref(
367 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false)); 367 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false));
368 ProxyConfigDictionary config(browser_pref.get()); 368 ProxyConfigDictionary config(browser_pref.get());
(...skipping 19 matching lines...) Expand all
388 388
389 std::unique_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 389 std::unique_ptr<base::DictionaryValue> expected(new base::DictionaryValue);
390 expected->SetString(keys::kProxyConfigPacScriptData, kSamplePacScript); 390 expected->SetString(keys::kProxyConfigPacScriptData, kSamplePacScript);
391 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false); 391 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false);
392 392
393 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get())); 393 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get()));
394 } 394 }
395 395
396 TEST(ExtensionProxyApiHelpers, TokenizeToStringList) { 396 TEST(ExtensionProxyApiHelpers, TokenizeToStringList) {
397 base::ListValue expected; 397 base::ListValue expected;
398 expected.Append(new base::StringValue("s1")); 398 expected.AppendString("s1");
399 expected.Append(new base::StringValue("s2")); 399 expected.AppendString("s2");
400 expected.Append(new base::StringValue("s3")); 400 expected.AppendString("s3");
401 401
402 std::unique_ptr<base::ListValue> out(TokenizeToStringList("s1;s2;s3", ";")); 402 std::unique_ptr<base::ListValue> out(TokenizeToStringList("s1;s2;s3", ";"));
403 EXPECT_TRUE(base::Value::Equals(&expected, out.get())); 403 EXPECT_TRUE(base::Value::Equals(&expected, out.get()));
404 } 404 }
405 405
406 } // namespace proxy_api_helpers 406 } // namespace proxy_api_helpers
407 } // namespace extensions 407 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698