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

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

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header Created 4 years, 8 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 "chrome/browser/extensions/api/proxy/proxy_api_helpers.h"
8
9 #include <memory>
10
8 #include "base/values.h" 11 #include "base/values.h"
9 #include "chrome/browser/extensions/api/proxy/proxy_api_constants.h" 12 #include "chrome/browser/extensions/api/proxy/proxy_api_constants.h"
10 #include "chrome/browser/extensions/api/proxy/proxy_api_helpers.h"
11 #include "components/proxy_config/proxy_config_dictionary.h" 13 #include "components/proxy_config/proxy_config_dictionary.h"
12 #include "components/proxy_config/proxy_prefs.h" 14 #include "components/proxy_config/proxy_prefs.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 namespace extensions { 17 namespace extensions {
16 18
17 namespace keys = proxy_api_constants; 19 namespace keys = proxy_api_constants;
18 20
19 namespace { 21 namespace {
20 22
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 ASSERT_TRUE( 215 ASSERT_TRUE(
214 GetBypassListFromExtensionPref(&proxy_config, &out, &error, 216 GetBypassListFromExtensionPref(&proxy_config, &out, &error,
215 &bad_message)); 217 &bad_message));
216 EXPECT_EQ("host1,host2", out); 218 EXPECT_EQ("host1,host2", out);
217 EXPECT_EQ(std::string(), error); 219 EXPECT_EQ(std::string(), error);
218 EXPECT_FALSE(bad_message); 220 EXPECT_FALSE(bad_message);
219 } 221 }
220 222
221 TEST(ExtensionProxyApiHelpers, CreateProxyConfigDict) { 223 TEST(ExtensionProxyApiHelpers, CreateProxyConfigDict) {
222 std::string error; 224 std::string error;
223 scoped_ptr<base::DictionaryValue> exp_direct( 225 std::unique_ptr<base::DictionaryValue> exp_direct(
224 ProxyConfigDictionary::CreateDirect()); 226 ProxyConfigDictionary::CreateDirect());
225 scoped_ptr<base::DictionaryValue> out_direct( 227 std::unique_ptr<base::DictionaryValue> out_direct(CreateProxyConfigDict(
226 CreateProxyConfigDict(ProxyPrefs::MODE_DIRECT, 228 ProxyPrefs::MODE_DIRECT, false, std::string(), std::string(),
227 false, 229 std::string(), std::string(), &error));
228 std::string(),
229 std::string(),
230 std::string(),
231 std::string(),
232 &error));
233 EXPECT_TRUE(base::Value::Equals(exp_direct.get(), out_direct.get())); 230 EXPECT_TRUE(base::Value::Equals(exp_direct.get(), out_direct.get()));
234 231
235 scoped_ptr<base::DictionaryValue> exp_auto( 232 std::unique_ptr<base::DictionaryValue> exp_auto(
236 ProxyConfigDictionary::CreateAutoDetect()); 233 ProxyConfigDictionary::CreateAutoDetect());
237 scoped_ptr<base::DictionaryValue> out_auto( 234 std::unique_ptr<base::DictionaryValue> out_auto(CreateProxyConfigDict(
238 CreateProxyConfigDict(ProxyPrefs::MODE_AUTO_DETECT, 235 ProxyPrefs::MODE_AUTO_DETECT, false, std::string(), std::string(),
239 false, 236 std::string(), std::string(), &error));
240 std::string(),
241 std::string(),
242 std::string(),
243 std::string(),
244 &error));
245 EXPECT_TRUE(base::Value::Equals(exp_auto.get(), out_auto.get())); 237 EXPECT_TRUE(base::Value::Equals(exp_auto.get(), out_auto.get()));
246 238
247 scoped_ptr<base::DictionaryValue> exp_pac_url( 239 std::unique_ptr<base::DictionaryValue> exp_pac_url(
248 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false)); 240 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false));
249 scoped_ptr<base::DictionaryValue> out_pac_url( 241 std::unique_ptr<base::DictionaryValue> out_pac_url(CreateProxyConfigDict(
250 CreateProxyConfigDict(ProxyPrefs::MODE_PAC_SCRIPT, 242 ProxyPrefs::MODE_PAC_SCRIPT, false, kSamplePacScriptUrl, std::string(),
251 false, 243 std::string(), std::string(), &error));
252 kSamplePacScriptUrl,
253 std::string(),
254 std::string(),
255 std::string(),
256 &error));
257 EXPECT_TRUE(base::Value::Equals(exp_pac_url.get(), out_pac_url.get())); 244 EXPECT_TRUE(base::Value::Equals(exp_pac_url.get(), out_pac_url.get()));
258 245
259 scoped_ptr<base::DictionaryValue> exp_pac_data( 246 std::unique_ptr<base::DictionaryValue> exp_pac_data(
260 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptAsDataUrl, false)); 247 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptAsDataUrl, false));
261 scoped_ptr<base::DictionaryValue> out_pac_data( 248 std::unique_ptr<base::DictionaryValue> out_pac_data(CreateProxyConfigDict(
262 CreateProxyConfigDict(ProxyPrefs::MODE_PAC_SCRIPT, 249 ProxyPrefs::MODE_PAC_SCRIPT, false, std::string(), kSamplePacScript,
263 false, 250 std::string(), std::string(), &error));
264 std::string(),
265 kSamplePacScript,
266 std::string(),
267 std::string(),
268 &error));
269 EXPECT_TRUE(base::Value::Equals(exp_pac_data.get(), out_pac_data.get())); 251 EXPECT_TRUE(base::Value::Equals(exp_pac_data.get(), out_pac_data.get()));
270 252
271 scoped_ptr<base::DictionaryValue> exp_fixed( 253 std::unique_ptr<base::DictionaryValue> exp_fixed(
272 ProxyConfigDictionary::CreateFixedServers("foo:80", "localhost")); 254 ProxyConfigDictionary::CreateFixedServers("foo:80", "localhost"));
273 scoped_ptr<base::DictionaryValue> out_fixed( 255 std::unique_ptr<base::DictionaryValue> out_fixed(CreateProxyConfigDict(
274 CreateProxyConfigDict(ProxyPrefs::MODE_FIXED_SERVERS, 256 ProxyPrefs::MODE_FIXED_SERVERS, false, std::string(), std::string(),
275 false, 257 "foo:80", "localhost", &error));
276 std::string(),
277 std::string(),
278 "foo:80",
279 "localhost",
280 &error));
281 EXPECT_TRUE(base::Value::Equals(exp_fixed.get(), out_fixed.get())); 258 EXPECT_TRUE(base::Value::Equals(exp_fixed.get(), out_fixed.get()));
282 259
283 scoped_ptr<base::DictionaryValue> exp_system( 260 std::unique_ptr<base::DictionaryValue> exp_system(
284 ProxyConfigDictionary::CreateSystem()); 261 ProxyConfigDictionary::CreateSystem());
285 scoped_ptr<base::DictionaryValue> out_system( 262 std::unique_ptr<base::DictionaryValue> out_system(CreateProxyConfigDict(
286 CreateProxyConfigDict(ProxyPrefs::MODE_SYSTEM, 263 ProxyPrefs::MODE_SYSTEM, false, std::string(), std::string(),
287 false, 264 std::string(), std::string(), &error));
288 std::string(),
289 std::string(),
290 std::string(),
291 std::string(),
292 &error));
293 EXPECT_TRUE(base::Value::Equals(exp_system.get(), out_system.get())); 265 EXPECT_TRUE(base::Value::Equals(exp_system.get(), out_system.get()));
294 266
295 // Neither of them should have set an error. 267 // Neither of them should have set an error.
296 EXPECT_EQ(std::string(), error); 268 EXPECT_EQ(std::string(), error);
297 } 269 }
298 270
299 TEST(ExtensionProxyApiHelpers, GetProxyServer) { 271 TEST(ExtensionProxyApiHelpers, GetProxyServer) {
300 base::DictionaryValue proxy_server_dict; 272 base::DictionaryValue proxy_server_dict;
301 net::ProxyServer created; 273 net::ProxyServer created;
302 std::string error; 274 std::string error;
(...skipping 26 matching lines...) Expand all
329 301
330 std::string out; 302 std::string out;
331 std::string error; 303 std::string error;
332 ASSERT_TRUE(JoinUrlList(&list, ";", &out, &error, &bad_message)); 304 ASSERT_TRUE(JoinUrlList(&list, ";", &out, &error, &bad_message));
333 EXPECT_EQ("s1;s2;s3", out); 305 EXPECT_EQ("s1;s2;s3", out);
334 EXPECT_FALSE(bad_message); 306 EXPECT_FALSE(bad_message);
335 } 307 }
336 308
337 // This tests CreateProxyServerDict as well. 309 // This tests CreateProxyServerDict as well.
338 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDict) { 310 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDict) {
339 scoped_ptr<base::DictionaryValue> browser_pref( 311 std::unique_ptr<base::DictionaryValue> browser_pref(
340 ProxyConfigDictionary::CreateFixedServers( 312 ProxyConfigDictionary::CreateFixedServers(
341 "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",
342 "localhost")); 314 "localhost"));
343 ProxyConfigDictionary config(browser_pref.get()); 315 ProxyConfigDictionary config(browser_pref.get());
344 scoped_ptr<base::DictionaryValue> extension_pref( 316 std::unique_ptr<base::DictionaryValue> extension_pref(
345 CreateProxyRulesDict(config)); 317 CreateProxyRulesDict(config));
346 ASSERT_TRUE(extension_pref.get()); 318 ASSERT_TRUE(extension_pref.get());
347 319
348 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 320 std::unique_ptr<base::DictionaryValue> expected(new base::DictionaryValue);
349 expected->Set("proxyForHttp", 321 expected->Set("proxyForHttp",
350 CreateTestProxyServerDict("http", "proxy1", 80)); 322 CreateTestProxyServerDict("http", "proxy1", 80));
351 expected->Set("proxyForHttps", 323 expected->Set("proxyForHttps",
352 CreateTestProxyServerDict("http", "proxy2", 80)); 324 CreateTestProxyServerDict("http", "proxy2", 80));
353 expected->Set("proxyForFtp", 325 expected->Set("proxyForFtp",
354 CreateTestProxyServerDict("http", "proxy3", 80)); 326 CreateTestProxyServerDict("http", "proxy3", 80));
355 expected->Set("fallbackProxy", 327 expected->Set("fallbackProxy",
356 CreateTestProxyServerDict("socks4", "proxy4", 80)); 328 CreateTestProxyServerDict("socks4", "proxy4", 80));
357 base::ListValue* bypass_list = new base::ListValue; 329 base::ListValue* bypass_list = new base::ListValue;
358 bypass_list->Append(new base::StringValue("localhost")); 330 bypass_list->Append(new base::StringValue("localhost"));
359 expected->Set(keys::kProxyConfigBypassList, bypass_list); 331 expected->Set(keys::kProxyConfigBypassList, bypass_list);
360 332
361 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get())); 333 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get()));
362 } 334 }
363 335
364 // 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.
365 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDictMultipleProxies) { 337 TEST(ExtensionProxyApiHelpers, CreateProxyRulesDictMultipleProxies) {
366 scoped_ptr<base::DictionaryValue> browser_pref( 338 std::unique_ptr<base::DictionaryValue> browser_pref(
367 ProxyConfigDictionary::CreateFixedServers( 339 ProxyConfigDictionary::CreateFixedServers(
368 "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,"
369 "https://proxy5:443;socks=proxy4:80,proxy1:80", 341 "https://proxy5:443;socks=proxy4:80,proxy1:80",
370 "localhost")); 342 "localhost"));
371 ProxyConfigDictionary config(browser_pref.get()); 343 ProxyConfigDictionary config(browser_pref.get());
372 scoped_ptr<base::DictionaryValue> extension_pref( 344 std::unique_ptr<base::DictionaryValue> extension_pref(
373 CreateProxyRulesDict(config)); 345 CreateProxyRulesDict(config));
374 ASSERT_TRUE(extension_pref.get()); 346 ASSERT_TRUE(extension_pref.get());
375 347
376 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 348 std::unique_ptr<base::DictionaryValue> expected(new base::DictionaryValue);
377 expected->Set("proxyForHttp", 349 expected->Set("proxyForHttp",
378 CreateTestProxyServerDict("http", "proxy1", 80)); 350 CreateTestProxyServerDict("http", "proxy1", 80));
379 expected->Set("proxyForHttps", 351 expected->Set("proxyForHttps",
380 CreateTestProxyServerDict("http", "proxy2", 80)); 352 CreateTestProxyServerDict("http", "proxy2", 80));
381 expected->Set("proxyForFtp", 353 expected->Set("proxyForFtp",
382 CreateTestProxyServerDict("http", "proxy3", 80)); 354 CreateTestProxyServerDict("http", "proxy3", 80));
383 expected->Set("fallbackProxy", 355 expected->Set("fallbackProxy",
384 CreateTestProxyServerDict("socks4", "proxy4", 80)); 356 CreateTestProxyServerDict("socks4", "proxy4", 80));
385 base::ListValue* bypass_list = new base::ListValue; 357 base::ListValue* bypass_list = new base::ListValue;
386 bypass_list->Append(new base::StringValue("localhost")); 358 bypass_list->Append(new base::StringValue("localhost"));
387 expected->Set(keys::kProxyConfigBypassList, bypass_list); 359 expected->Set(keys::kProxyConfigBypassList, bypass_list);
388 360
389 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get())); 361 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get()));
390 } 362 }
391 363
392 // Test if a PAC script URL is specified. 364 // Test if a PAC script URL is specified.
393 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) { 365 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWithUrl) {
394 scoped_ptr<base::DictionaryValue> browser_pref( 366 std::unique_ptr<base::DictionaryValue> browser_pref(
395 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false)); 367 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptUrl, false));
396 ProxyConfigDictionary config(browser_pref.get()); 368 ProxyConfigDictionary config(browser_pref.get());
397 scoped_ptr<base::DictionaryValue> extension_pref(CreatePacScriptDict(config)); 369 std::unique_ptr<base::DictionaryValue> extension_pref(
370 CreatePacScriptDict(config));
398 ASSERT_TRUE(extension_pref.get()); 371 ASSERT_TRUE(extension_pref.get());
399 372
400 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 373 std::unique_ptr<base::DictionaryValue> expected(new base::DictionaryValue);
401 expected->SetString(keys::kProxyConfigPacScriptUrl, kSamplePacScriptUrl); 374 expected->SetString(keys::kProxyConfigPacScriptUrl, kSamplePacScriptUrl);
402 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false); 375 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false);
403 376
404 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get())); 377 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get()));
405 } 378 }
406 379
407 // Test if a PAC script is encoded in a data URL. 380 // Test if a PAC script is encoded in a data URL.
408 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWidthData) { 381 TEST(ExtensionProxyApiHelpers, CreatePacScriptDictWidthData) {
409 scoped_ptr<base::DictionaryValue> browser_pref( 382 std::unique_ptr<base::DictionaryValue> browser_pref(
410 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptAsDataUrl, false)); 383 ProxyConfigDictionary::CreatePacScript(kSamplePacScriptAsDataUrl, false));
411 ProxyConfigDictionary config(browser_pref.get()); 384 ProxyConfigDictionary config(browser_pref.get());
412 scoped_ptr<base::DictionaryValue> extension_pref(CreatePacScriptDict(config)); 385 std::unique_ptr<base::DictionaryValue> extension_pref(
386 CreatePacScriptDict(config));
413 ASSERT_TRUE(extension_pref.get()); 387 ASSERT_TRUE(extension_pref.get());
414 388
415 scoped_ptr<base::DictionaryValue> expected(new base::DictionaryValue); 389 std::unique_ptr<base::DictionaryValue> expected(new base::DictionaryValue);
416 expected->SetString(keys::kProxyConfigPacScriptData, kSamplePacScript); 390 expected->SetString(keys::kProxyConfigPacScriptData, kSamplePacScript);
417 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false); 391 expected->SetBoolean(keys::kProxyConfigPacScriptMandatory, false);
418 392
419 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get())); 393 EXPECT_TRUE(base::Value::Equals(expected.get(), extension_pref.get()));
420 } 394 }
421 395
422 TEST(ExtensionProxyApiHelpers, TokenizeToStringList) { 396 TEST(ExtensionProxyApiHelpers, TokenizeToStringList) {
423 base::ListValue expected; 397 base::ListValue expected;
424 expected.Append(new base::StringValue("s1")); 398 expected.Append(new base::StringValue("s1"));
425 expected.Append(new base::StringValue("s2")); 399 expected.Append(new base::StringValue("s2"));
426 expected.Append(new base::StringValue("s3")); 400 expected.Append(new base::StringValue("s3"));
427 401
428 scoped_ptr<base::ListValue> out(TokenizeToStringList("s1;s2;s3", ";")); 402 std::unique_ptr<base::ListValue> out(TokenizeToStringList("s1;s2;s3", ";"));
429 EXPECT_TRUE(base::Value::Equals(&expected, out.get())); 403 EXPECT_TRUE(base::Value::Equals(&expected, out.get()));
430 } 404 }
431 405
432 } // namespace proxy_api_helpers 406 } // namespace proxy_api_helpers
433 } // namespace extensions 407 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698