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

Side by Side Diff: chrome/browser/content_settings/content_settings_pref_provider_unittest.cc

Issue 2666093002: Remove base::FundamentalValue (Closed)
Patch Set: Rebase Created 3 years, 9 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 #include "components/content_settings/core/browser/content_settings_pref_provide r.h" 5 #include "components/content_settings/core/browser/content_settings_pref_provide r.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 MockObserver mock_observer; 121 MockObserver mock_observer;
122 EXPECT_CALL(mock_observer, OnContentSettingChanged( 122 EXPECT_CALL(mock_observer, OnContentSettingChanged(
123 pattern, ContentSettingsPattern::Wildcard(), 123 pattern, ContentSettingsPattern::Wildcard(),
124 CONTENT_SETTINGS_TYPE_COOKIES, "")); 124 CONTENT_SETTINGS_TYPE_COOKIES, ""));
125 125
126 pref_content_settings_provider.AddObserver(&mock_observer); 126 pref_content_settings_provider.AddObserver(&mock_observer);
127 127
128 pref_content_settings_provider.SetWebsiteSetting( 128 pref_content_settings_provider.SetWebsiteSetting(
129 pattern, ContentSettingsPattern::Wildcard(), 129 pattern, ContentSettingsPattern::Wildcard(),
130 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 130 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
131 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 131 new base::Value(CONTENT_SETTING_ALLOW));
132 132
133 pref_content_settings_provider.ShutdownOnUIThread(); 133 pref_content_settings_provider.ShutdownOnUIThread();
134 } 134 }
135 135
136 // Tests that fullscreen and mouselock content settings are cleared. 136 // Tests that fullscreen and mouselock content settings are cleared.
137 TEST_F(PrefProviderTest, DiscardObsoleteFullscreenAndMouselockPreferences) { 137 TEST_F(PrefProviderTest, DiscardObsoleteFullscreenAndMouselockPreferences) {
138 static const char kFullscreenPrefPath[] = 138 static const char kFullscreenPrefPath[] =
139 "profile.content_settings.exceptions.fullscreen"; 139 "profile.content_settings.exceptions.fullscreen";
140 #if !defined(OS_ANDROID) 140 #if !defined(OS_ANDROID)
141 static const char kMouselockPrefPath[] = 141 static const char kMouselockPrefPath[] =
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 TestingProfile::Builder otr_profile_builder; 272 TestingProfile::Builder otr_profile_builder;
273 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs)); 273 otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs));
274 otr_profile_builder.BuildIncognito(profile.get()); 274 otr_profile_builder.BuildIncognito(profile.get());
275 275
276 PrefProvider pref_content_settings_provider(regular_prefs, false); 276 PrefProvider pref_content_settings_provider(regular_prefs, false);
277 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true); 277 PrefProvider pref_content_settings_provider_incognito(otr_prefs, true);
278 ContentSettingsPattern pattern = 278 ContentSettingsPattern pattern =
279 ContentSettingsPattern::FromString("[*.]example.com"); 279 ContentSettingsPattern::FromString("[*.]example.com");
280 pref_content_settings_provider.SetWebsiteSetting( 280 pref_content_settings_provider.SetWebsiteSetting(
281 pattern, pattern, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 281 pattern, pattern, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
282 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 282 new base::Value(CONTENT_SETTING_ALLOW));
283 283
284 GURL host("http://example.com/"); 284 GURL host("http://example.com/");
285 // The value should of course be visible in the regular PrefProvider. 285 // The value should of course be visible in the regular PrefProvider.
286 EXPECT_EQ(CONTENT_SETTING_ALLOW, 286 EXPECT_EQ(CONTENT_SETTING_ALLOW,
287 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 287 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
288 host, CONTENT_SETTINGS_TYPE_COOKIES, 288 host, CONTENT_SETTINGS_TYPE_COOKIES,
289 std::string(), false)); 289 std::string(), false));
290 // And also in the OTR version. 290 // And also in the OTR version.
291 EXPECT_EQ(CONTENT_SETTING_ALLOW, 291 EXPECT_EQ(CONTENT_SETTING_ALLOW,
292 TestUtils::GetContentSetting( 292 TestUtils::GetContentSetting(
(...skipping 20 matching lines...) Expand all
313 TestUtils::GetContentSetting(&provider, primary_url, primary_url, 313 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
314 CONTENT_SETTINGS_TYPE_COOKIES, 314 CONTENT_SETTINGS_TYPE_COOKIES,
315 std::string(), false)); 315 std::string(), false));
316 316
317 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue( 317 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue(
318 &provider, primary_url, primary_url, 318 &provider, primary_url, primary_url,
319 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); 319 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
320 320
321 provider.SetWebsiteSetting(primary_pattern, primary_pattern, 321 provider.SetWebsiteSetting(primary_pattern, primary_pattern,
322 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 322 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
323 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 323 new base::Value(CONTENT_SETTING_BLOCK));
324 EXPECT_EQ(CONTENT_SETTING_BLOCK, 324 EXPECT_EQ(CONTENT_SETTING_BLOCK,
325 TestUtils::GetContentSetting(&provider, primary_url, primary_url, 325 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
326 CONTENT_SETTINGS_TYPE_COOKIES, 326 CONTENT_SETTINGS_TYPE_COOKIES,
327 std::string(), false)); 327 std::string(), false));
328 std::unique_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue( 328 std::unique_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue(
329 &provider, primary_url, primary_url, CONTENT_SETTINGS_TYPE_COOKIES, 329 &provider, primary_url, primary_url, CONTENT_SETTINGS_TYPE_COOKIES,
330 std::string(), false)); 330 std::string(), false));
331 int int_value = -1; 331 int int_value = -1;
332 value_ptr->GetAsInteger(&int_value); 332 value_ptr->GetAsInteger(&int_value);
333 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); 333 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value));
(...skipping 22 matching lines...) Expand all
356 ContentSettingsPattern::FromString("example.org"); 356 ContentSettingsPattern::FromString("example.org");
357 ContentSettingsPattern pattern3 = 357 ContentSettingsPattern pattern3 =
358 ContentSettingsPattern::FromString("file:///tmp/test.html"); 358 ContentSettingsPattern::FromString("file:///tmp/test.html");
359 359
360 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 360 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
361 TestUtils::GetContentSetting(&pref_content_settings_provider, host1, 361 TestUtils::GetContentSetting(&pref_content_settings_provider, host1,
362 host1, CONTENT_SETTINGS_TYPE_COOKIES, 362 host1, CONTENT_SETTINGS_TYPE_COOKIES,
363 std::string(), false)); 363 std::string(), false));
364 pref_content_settings_provider.SetWebsiteSetting( 364 pref_content_settings_provider.SetWebsiteSetting(
365 pattern1, pattern1, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 365 pattern1, pattern1, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
366 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 366 new base::Value(CONTENT_SETTING_BLOCK));
367 EXPECT_EQ(CONTENT_SETTING_BLOCK, 367 EXPECT_EQ(CONTENT_SETTING_BLOCK,
368 TestUtils::GetContentSetting(&pref_content_settings_provider, host1, 368 TestUtils::GetContentSetting(&pref_content_settings_provider, host1,
369 host1, CONTENT_SETTINGS_TYPE_COOKIES, 369 host1, CONTENT_SETTINGS_TYPE_COOKIES,
370 std::string(), false)); 370 std::string(), false));
371 EXPECT_EQ(CONTENT_SETTING_BLOCK, 371 EXPECT_EQ(CONTENT_SETTING_BLOCK,
372 TestUtils::GetContentSetting(&pref_content_settings_provider, host2, 372 TestUtils::GetContentSetting(&pref_content_settings_provider, host2,
373 host2, CONTENT_SETTINGS_TYPE_COOKIES, 373 host2, CONTENT_SETTINGS_TYPE_COOKIES,
374 std::string(), false)); 374 std::string(), false));
375 375
376 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 376 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
377 TestUtils::GetContentSetting(&pref_content_settings_provider, host3, 377 TestUtils::GetContentSetting(&pref_content_settings_provider, host3,
378 host3, CONTENT_SETTINGS_TYPE_COOKIES, 378 host3, CONTENT_SETTINGS_TYPE_COOKIES,
379 std::string(), false)); 379 std::string(), false));
380 pref_content_settings_provider.SetWebsiteSetting( 380 pref_content_settings_provider.SetWebsiteSetting(
381 pattern2, pattern2, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 381 pattern2, pattern2, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
382 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 382 new base::Value(CONTENT_SETTING_BLOCK));
383 EXPECT_EQ(CONTENT_SETTING_BLOCK, 383 EXPECT_EQ(CONTENT_SETTING_BLOCK,
384 TestUtils::GetContentSetting(&pref_content_settings_provider, host3, 384 TestUtils::GetContentSetting(&pref_content_settings_provider, host3,
385 host3, CONTENT_SETTINGS_TYPE_COOKIES, 385 host3, CONTENT_SETTINGS_TYPE_COOKIES,
386 std::string(), false)); 386 std::string(), false));
387 387
388 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 388 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
389 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, 389 TestUtils::GetContentSetting(&pref_content_settings_provider, host4,
390 host4, CONTENT_SETTINGS_TYPE_COOKIES, 390 host4, CONTENT_SETTINGS_TYPE_COOKIES,
391 std::string(), false)); 391 std::string(), false));
392 pref_content_settings_provider.SetWebsiteSetting( 392 pref_content_settings_provider.SetWebsiteSetting(
393 pattern3, pattern3, CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 393 pattern3, pattern3, CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
394 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 394 new base::Value(CONTENT_SETTING_BLOCK));
395 EXPECT_EQ(CONTENT_SETTING_BLOCK, 395 EXPECT_EQ(CONTENT_SETTING_BLOCK,
396 TestUtils::GetContentSetting(&pref_content_settings_provider, host4, 396 TestUtils::GetContentSetting(&pref_content_settings_provider, host4,
397 host4, CONTENT_SETTINGS_TYPE_COOKIES, 397 host4, CONTENT_SETTINGS_TYPE_COOKIES,
398 std::string(), false)); 398 std::string(), false));
399 399
400 pref_content_settings_provider.ShutdownOnUIThread(); 400 pref_content_settings_provider.ShutdownOnUIThread();
401 } 401 }
402 402
403 #if BUILDFLAG(ENABLE_PLUGINS) 403 #if BUILDFLAG(ENABLE_PLUGINS)
404 TEST_F(PrefProviderTest, ResourceIdentifier) { 404 TEST_F(PrefProviderTest, ResourceIdentifier) {
405 TestingProfile testing_profile; 405 TestingProfile testing_profile;
406 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), 406 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
407 false); 407 false);
408 408
409 GURL host("http://example.com/"); 409 GURL host("http://example.com/");
410 ContentSettingsPattern pattern = 410 ContentSettingsPattern pattern =
411 ContentSettingsPattern::FromString("[*.]example.com"); 411 ContentSettingsPattern::FromString("[*.]example.com");
412 std::string resource1("someplugin"); 412 std::string resource1("someplugin");
413 std::string resource2("otherplugin"); 413 std::string resource2("otherplugin");
414 414
415 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 415 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
416 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 416 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
417 host, CONTENT_SETTINGS_TYPE_PLUGINS, 417 host, CONTENT_SETTINGS_TYPE_PLUGINS,
418 resource1, false)); 418 resource1, false));
419 pref_content_settings_provider.SetWebsiteSetting( 419 pref_content_settings_provider.SetWebsiteSetting(
420 pattern, 420 pattern, pattern, CONTENT_SETTINGS_TYPE_PLUGINS, resource1,
421 pattern, 421 new base::Value(CONTENT_SETTING_BLOCK));
422 CONTENT_SETTINGS_TYPE_PLUGINS,
423 resource1,
424 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
425 EXPECT_EQ(CONTENT_SETTING_BLOCK, 422 EXPECT_EQ(CONTENT_SETTING_BLOCK,
426 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 423 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
427 host, CONTENT_SETTINGS_TYPE_PLUGINS, 424 host, CONTENT_SETTINGS_TYPE_PLUGINS,
428 resource1, false)); 425 resource1, false));
429 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 426 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
430 TestUtils::GetContentSetting(&pref_content_settings_provider, host, 427 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
431 host, CONTENT_SETTINGS_TYPE_PLUGINS, 428 host, CONTENT_SETTINGS_TYPE_PLUGINS,
432 resource2, false)); 429 resource2, false));
433 430
434 pref_content_settings_provider.ShutdownOnUIThread(); 431 pref_content_settings_provider.ShutdownOnUIThread();
(...skipping 28 matching lines...) Expand all
463 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) { 460 TEST_F(PrefProviderTest, IncognitoInheritsValueMap) {
464 sync_preferences::TestingPrefServiceSyncable prefs; 461 sync_preferences::TestingPrefServiceSyncable prefs;
465 PrefProvider::RegisterProfilePrefs(prefs.registry()); 462 PrefProvider::RegisterProfilePrefs(prefs.registry());
466 463
467 ContentSettingsPattern pattern_1 = 464 ContentSettingsPattern pattern_1 =
468 ContentSettingsPattern::FromString("google.com"); 465 ContentSettingsPattern::FromString("google.com");
469 ContentSettingsPattern pattern_2 = 466 ContentSettingsPattern pattern_2 =
470 ContentSettingsPattern::FromString("www.google.com"); 467 ContentSettingsPattern::FromString("www.google.com");
471 ContentSettingsPattern wildcard = 468 ContentSettingsPattern wildcard =
472 ContentSettingsPattern::FromString("*"); 469 ContentSettingsPattern::FromString("*");
473 std::unique_ptr<base::Value> value( 470 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
474 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
475 471
476 // Create a normal provider and set a setting. 472 // Create a normal provider and set a setting.
477 PrefProvider normal_provider(&prefs, false); 473 PrefProvider normal_provider(&prefs, false);
478 normal_provider.SetWebsiteSetting(pattern_1, wildcard, 474 normal_provider.SetWebsiteSetting(pattern_1, wildcard,
479 CONTENT_SETTINGS_TYPE_COOKIES, 475 CONTENT_SETTINGS_TYPE_COOKIES,
480 std::string(), value->DeepCopy()); 476 std::string(), value->DeepCopy());
481 477
482 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1). 478 // Non-OTR provider, Non-OTR iterator has one setting (pattern 1).
483 { 479 {
484 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator( 480 std::unique_ptr<RuleIterator> it(normal_provider.GetRuleIterator(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 } 520 }
525 521
526 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) { 522 TEST_F(PrefProviderTest, ClearAllContentSettingsRules) {
527 sync_preferences::TestingPrefServiceSyncable prefs; 523 sync_preferences::TestingPrefServiceSyncable prefs;
528 PrefProvider::RegisterProfilePrefs(prefs.registry()); 524 PrefProvider::RegisterProfilePrefs(prefs.registry());
529 525
530 ContentSettingsPattern pattern = 526 ContentSettingsPattern pattern =
531 ContentSettingsPattern::FromString("google.com"); 527 ContentSettingsPattern::FromString("google.com");
532 ContentSettingsPattern wildcard = 528 ContentSettingsPattern wildcard =
533 ContentSettingsPattern::FromString("*"); 529 ContentSettingsPattern::FromString("*");
534 std::unique_ptr<base::Value> value( 530 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
535 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
536 ResourceIdentifier res_id("abcde"); 531 ResourceIdentifier res_id("abcde");
537 532
538 PrefProvider provider(&prefs, false); 533 PrefProvider provider(&prefs, false);
539 534
540 // Non-empty pattern, syncable, empty resource identifier. 535 // Non-empty pattern, syncable, empty resource identifier.
541 provider.SetWebsiteSetting(pattern, wildcard, 536 provider.SetWebsiteSetting(pattern, wildcard,
542 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 537 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
543 ResourceIdentifier(), value->DeepCopy()); 538 ResourceIdentifier(), value->DeepCopy());
544 539
545 // Non-empty pattern, non-syncable, empty resource identifier. 540 // Non-empty pattern, non-syncable, empty resource identifier.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 for (const char* pref : nonempty_prefs) { 590 for (const char* pref : nonempty_prefs) {
596 DictionaryPrefUpdate update(&prefs, pref); 591 DictionaryPrefUpdate update(&prefs, pref);
597 const base::DictionaryValue* dictionary = update.Get(); 592 const base::DictionaryValue* dictionary = update.Get();
598 EXPECT_EQ(1u, dictionary->size()); 593 EXPECT_EQ(1u, dictionary->size());
599 } 594 }
600 595
601 provider.ShutdownOnUIThread(); 596 provider.ShutdownOnUIThread();
602 } 597 }
603 598
604 } // namespace content_settings 599 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698