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

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

Issue 7713034: HostContentSettingsMap refactoring. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Code review comments. Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/auto_reset.h" 5 #include "base/auto_reset.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "chrome/browser/content_settings/content_settings_details.h" 9 #include "chrome/browser/content_settings/content_settings_details.h"
10 #include "chrome/browser/content_settings/cookie_settings.h"
11 #include "chrome/browser/content_settings/cookie_settings_factory.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 12 #include "chrome/browser/content_settings/host_content_settings_map.h"
11 #include "chrome/browser/content_settings/mock_settings_observer.h" 13 #include "chrome/browser/content_settings/mock_settings_observer.h"
12 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" 15 #include "chrome/browser/prefs/scoped_user_pref_update.h"
14 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
16 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
17 #include "chrome/test/base/testing_pref_service.h" 19 #include "chrome/test/base/testing_pref_service.h"
18 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
19 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = 154 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] =
153 CONTENT_SETTING_BLOCK; 155 CONTENT_SETTING_BLOCK;
154 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = 156 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] =
155 CONTENT_SETTING_ASK; 157 CONTENT_SETTING_ASK;
156 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = 158 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] =
157 CONTENT_SETTING_ASK; 159 CONTENT_SETTING_ASK;
158 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = 160 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] =
159 CONTENT_SETTING_ASK; 161 CONTENT_SETTING_ASK;
160 desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] = 162 desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] =
161 CONTENT_SETTING_ASK; 163 CONTENT_SETTING_ASK;
164 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY] =
165 CONTENT_SETTING_ALLOW;
162 ContentSettings settings = 166 ContentSettings settings =
163 host_content_settings_map->GetContentSettings(host, host); 167 host_content_settings_map->GetContentSettings(host, host);
164 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); 168 EXPECT_TRUE(SettingsEqual(desired_settings, settings));
165 169
166 // Check returning all hosts for a setting. 170 // Check returning all hosts for a setting.
167 ContentSettingsPattern pattern2 = 171 ContentSettingsPattern pattern2 =
168 ContentSettingsPattern::FromString("[*.]example.org"); 172 ContentSettingsPattern::FromString("[*.]example.org");
169 host_content_settings_map->SetContentSetting( 173 host_content_settings_map->SetContentSetting(
170 pattern2, 174 pattern2,
171 ContentSettingsPattern::Wildcard(), 175 ContentSettingsPattern::Wildcard(),
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 331
328 PrefService* prefs = profile.GetPrefs(); 332 PrefService* prefs = profile.GetPrefs();
329 333
330 // Make a copy of the default pref value so we can reset it later. 334 // Make a copy of the default pref value so we can reset it later.
331 scoped_ptr<Value> default_value(prefs->FindPreference( 335 scoped_ptr<Value> default_value(prefs->FindPreference(
332 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 336 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
333 337
334 GURL host("http://example.com"); 338 GURL host("http://example.com");
335 339
336 host_content_settings_map->SetDefaultContentSetting( 340 host_content_settings_map->SetDefaultContentSetting(
337 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); 341 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
338 EXPECT_EQ(CONTENT_SETTING_BLOCK, 342 EXPECT_EQ(CONTENT_SETTING_BLOCK,
339 host_content_settings_map->GetCookieContentSetting( 343 host_content_settings_map->GetContentSetting(
340 host, host, true)); 344 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
341 345
342 // Make a copy of the pref's new value so we can reset it later. 346 // Make a copy of the pref's new value so we can reset it later.
343 scoped_ptr<Value> new_value(prefs->FindPreference( 347 scoped_ptr<Value> new_value(prefs->FindPreference(
344 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 348 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
345 349
346 // Clearing the backing pref should also clear the internal cache. 350 // Clearing the backing pref should also clear the internal cache.
347 prefs->Set(prefs::kDefaultContentSettings, *default_value); 351 prefs->Set(prefs::kDefaultContentSettings, *default_value);
348 EXPECT_EQ(CONTENT_SETTING_ALLOW, 352 EXPECT_EQ(CONTENT_SETTING_ALLOW,
349 host_content_settings_map->GetCookieContentSetting( 353 host_content_settings_map->GetContentSetting(
350 host, host, true)); 354 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
351 355
352 // Reseting the pref to its previous value should update the cache. 356 // Reseting the pref to its previous value should update the cache.
353 prefs->Set(prefs::kDefaultContentSettings, *new_value); 357 prefs->Set(prefs::kDefaultContentSettings, *new_value);
354 EXPECT_EQ(CONTENT_SETTING_BLOCK, 358 EXPECT_EQ(CONTENT_SETTING_BLOCK,
355 host_content_settings_map->GetCookieContentSetting( 359 host_content_settings_map->GetContentSetting(
356 host, host, true)); 360 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
357 } 361 }
358 362
359 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { 363 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
360 TestingProfile profile; 364 TestingProfile profile;
361 HostContentSettingsMap* host_content_settings_map = 365 HostContentSettingsMap* host_content_settings_map =
362 profile.GetHostContentSettingsMap(); 366 profile.GetHostContentSettingsMap();
363 367
364 PrefService* prefs = profile.GetPrefs(); 368 PrefService* prefs = profile.GetPrefs();
365 369
366 // Make a copy of the default pref value so we can reset it later. 370 // Make a copy of the default pref value so we can reset it later.
367 scoped_ptr<Value> default_value(prefs->FindPreference( 371 scoped_ptr<Value> default_value(prefs->FindPreference(
368 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 372 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
369 373
370 ContentSettingsPattern pattern = 374 ContentSettingsPattern pattern =
371 ContentSettingsPattern::FromString("[*.]example.com"); 375 ContentSettingsPattern::FromString("[*.]example.com");
372 GURL host("http://example.com"); 376 GURL host("http://example.com");
373 377
374 host_content_settings_map->SetContentSetting( 378 host_content_settings_map->SetContentSetting(
375 pattern, 379 pattern,
376 ContentSettingsPattern::Wildcard(), 380 ContentSettingsPattern::Wildcard(),
377 CONTENT_SETTINGS_TYPE_COOKIES, 381 CONTENT_SETTINGS_TYPE_IMAGES,
378 std::string(), 382 std::string(),
379 CONTENT_SETTING_BLOCK); 383 CONTENT_SETTING_BLOCK);
384
380 EXPECT_EQ(CONTENT_SETTING_BLOCK, 385 EXPECT_EQ(CONTENT_SETTING_BLOCK,
381 host_content_settings_map->GetCookieContentSetting( 386 host_content_settings_map->GetContentSetting(
382 host, host, true)); 387 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
383 388
384 // Make a copy of the pref's new value so we can reset it later. 389 // Make a copy of the pref's new value so we can reset it later.
385 scoped_ptr<Value> new_value(prefs->FindPreference( 390 scoped_ptr<Value> new_value(prefs->FindPreference(
386 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 391 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
387 392
388 // Clearing the backing pref should also clear the internal cache. 393 // Clearing the backing pref should also clear the internal cache.
389 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); 394 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value);
390 EXPECT_EQ(CONTENT_SETTING_ALLOW, 395 EXPECT_EQ(CONTENT_SETTING_ALLOW,
391 host_content_settings_map->GetCookieContentSetting( 396 host_content_settings_map->GetContentSetting(
392 host, host, true)); 397 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
393 398
394 // Reseting the pref to its previous value should update the cache. 399 // Reseting the pref to its previous value should update the cache.
395 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); 400 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value);
396 EXPECT_EQ(CONTENT_SETTING_BLOCK, 401 EXPECT_EQ(CONTENT_SETTING_BLOCK,
397 host_content_settings_map->GetCookieContentSetting( 402 host_content_settings_map->GetContentSetting(
398 host, host, true)); 403 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
399 } 404 }
400 405
401 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { 406 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
402 TestingProfile profile; 407 TestingProfile profile;
403 HostContentSettingsMap* host_content_settings_map = 408 HostContentSettingsMap* host_content_settings_map =
404 profile.GetHostContentSettingsMap(); 409 profile.GetHostContentSettingsMap();
410 CookieSettings* cookie_settings =
411 CookieSettingsFactory::GetForProfile(&profile);
405 412
406 ContentSettingsPattern pattern = 413 ContentSettingsPattern pattern =
407 ContentSettingsPattern::FromString("[*.]example.com"); 414 ContentSettingsPattern::FromString("[*.]example.com");
408 GURL host_ending_with_dot("http://example.com./"); 415 GURL host_ending_with_dot("http://example.com./");
409 416
410 EXPECT_EQ(CONTENT_SETTING_ALLOW, 417 EXPECT_EQ(CONTENT_SETTING_ALLOW,
411 host_content_settings_map->GetContentSetting( 418 host_content_settings_map->GetContentSetting(
412 host_ending_with_dot, 419 host_ending_with_dot,
413 host_ending_with_dot, 420 host_ending_with_dot,
414 CONTENT_SETTINGS_TYPE_IMAGES, 421 CONTENT_SETTINGS_TYPE_IMAGES,
(...skipping 16 matching lines...) Expand all
431 CONTENT_SETTINGS_TYPE_IMAGES, 438 CONTENT_SETTINGS_TYPE_IMAGES,
432 "", 439 "",
433 CONTENT_SETTING_BLOCK); 440 CONTENT_SETTING_BLOCK);
434 EXPECT_EQ(CONTENT_SETTING_BLOCK, 441 EXPECT_EQ(CONTENT_SETTING_BLOCK,
435 host_content_settings_map->GetContentSetting( 442 host_content_settings_map->GetContentSetting(
436 host_ending_with_dot, 443 host_ending_with_dot,
437 host_ending_with_dot, 444 host_ending_with_dot,
438 CONTENT_SETTINGS_TYPE_IMAGES, 445 CONTENT_SETTINGS_TYPE_IMAGES,
439 "")); 446 ""));
440 447
441 EXPECT_EQ(CONTENT_SETTING_ALLOW, 448 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
442 host_content_settings_map->GetCookieContentSetting( 449 host_ending_with_dot, host_ending_with_dot));
443 host_ending_with_dot, host_ending_with_dot, true));
444 host_content_settings_map->SetContentSetting( 450 host_content_settings_map->SetContentSetting(
445 pattern, 451 pattern,
446 ContentSettingsPattern::Wildcard(), 452 ContentSettingsPattern::Wildcard(),
447 CONTENT_SETTINGS_TYPE_COOKIES, 453 CONTENT_SETTINGS_TYPE_COOKIES,
448 "", 454 "",
449 CONTENT_SETTING_DEFAULT); 455 CONTENT_SETTING_DEFAULT);
450 EXPECT_EQ(CONTENT_SETTING_ALLOW, 456 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed(
451 host_content_settings_map->GetCookieContentSetting( 457 host_ending_with_dot, host_ending_with_dot));
452 host_ending_with_dot, host_ending_with_dot, true));
453 host_content_settings_map->SetContentSetting( 458 host_content_settings_map->SetContentSetting(
454 pattern, 459 pattern,
455 ContentSettingsPattern::Wildcard(), 460 ContentSettingsPattern::Wildcard(),
456 CONTENT_SETTINGS_TYPE_COOKIES, 461 CONTENT_SETTINGS_TYPE_COOKIES,
457 "", 462 "",
458 CONTENT_SETTING_BLOCK); 463 CONTENT_SETTING_BLOCK);
459 EXPECT_EQ(CONTENT_SETTING_BLOCK, 464 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed(
460 host_content_settings_map->GetCookieContentSetting( 465 host_ending_with_dot, host_ending_with_dot));
461 host_ending_with_dot, host_ending_with_dot, true));
462 466
463 EXPECT_EQ(CONTENT_SETTING_ALLOW, 467 EXPECT_EQ(CONTENT_SETTING_ALLOW,
464 host_content_settings_map->GetContentSetting( 468 host_content_settings_map->GetContentSetting(
465 host_ending_with_dot, 469 host_ending_with_dot,
466 host_ending_with_dot, 470 host_ending_with_dot,
467 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 471 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
468 "")); 472 ""));
469 host_content_settings_map->SetContentSetting( 473 host_content_settings_map->SetContentSetting(
470 pattern, 474 pattern,
471 ContentSettingsPattern::Wildcard(), 475 ContentSettingsPattern::Wildcard(),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = 606 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] =
603 CONTENT_SETTING_BLOCK; 607 CONTENT_SETTING_BLOCK;
604 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = 608 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] =
605 CONTENT_SETTING_ASK; 609 CONTENT_SETTING_ASK;
606 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = 610 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] =
607 CONTENT_SETTING_ASK; 611 CONTENT_SETTING_ASK;
608 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = 612 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] =
609 CONTENT_SETTING_ASK; 613 CONTENT_SETTING_ASK;
610 desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] = 614 desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] =
611 CONTENT_SETTING_ASK; 615 CONTENT_SETTING_ASK;
616 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY] =
617 CONTENT_SETTING_ALLOW;
612 ContentSettings settings = 618 ContentSettings settings =
613 host_content_settings_map->GetContentSettings(host, host); 619 host_content_settings_map->GetContentSettings(host, host);
614 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); 620 EXPECT_TRUE(SettingsEqual(desired_settings, settings));
615 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES], 621 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES],
616 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]); 622 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]);
617 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES], 623 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES],
618 settings.settings[CONTENT_SETTINGS_TYPE_IMAGES]); 624 settings.settings[CONTENT_SETTINGS_TYPE_IMAGES]);
619 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS], 625 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS],
620 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); 626 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]);
621 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS], 627 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS],
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 EXPECT_EQ(CONTENT_SETTING_BLOCK, 678 EXPECT_EQ(CONTENT_SETTING_BLOCK,
673 host_content_settings_map->GetContentSetting( 679 host_content_settings_map->GetContentSetting(
674 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 680 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
675 EXPECT_EQ(CONTENT_SETTING_ALLOW, 681 EXPECT_EQ(CONTENT_SETTING_ALLOW,
676 otr_map->GetContentSetting( 682 otr_map->GetContentSetting(
677 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 683 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
678 684
679 otr_map->ShutdownOnUIThread(); 685 otr_map->ShutdownOnUIThread();
680 } 686 }
681 687
682 TEST_F(HostContentSettingsMapTest, MigrateObsoletePrefs) { 688 TEST_F(HostContentSettingsMapTest, MigrateObsoletePopupPrefs) {
683 // This feature is currently behind a flag. 689 // This feature is currently behind a flag.
684 CommandLine* cmd = CommandLine::ForCurrentProcess(); 690 CommandLine* cmd = CommandLine::ForCurrentProcess();
685 AutoReset<CommandLine> auto_reset(cmd, *cmd); 691 AutoReset<CommandLine> auto_reset(cmd, *cmd);
686 cmd->AppendSwitch(switches::kEnableResourceContentSettings); 692 cmd->AppendSwitch(switches::kEnableResourceContentSettings);
687 693
688 TestingProfile profile; 694 TestingProfile profile;
689 PrefService* prefs = profile.GetPrefs(); 695 PrefService* prefs = profile.GetPrefs();
690 696
691 // Set obsolete data. 697 // Set obsolete data.
692 prefs->SetInteger(prefs::kCookieBehavior,
693 net::StaticCookiePolicy::BLOCK_ALL_COOKIES);
694
695 ListValue popup_hosts; 698 ListValue popup_hosts;
696 popup_hosts.Append(new StringValue("[*.]example.com")); 699 popup_hosts.Append(new StringValue("[*.]example.com"));
697 prefs->Set(prefs::kPopupWhitelistedHosts, popup_hosts); 700 prefs->Set(prefs::kPopupWhitelistedHosts, popup_hosts);
698 701
699 HostContentSettingsMap* host_content_settings_map = 702 HostContentSettingsMap* host_content_settings_map =
700 profile.GetHostContentSettingsMap(); 703 profile.GetHostContentSettingsMap();
701 704
702 EXPECT_EQ(CONTENT_SETTING_BLOCK,
703 host_content_settings_map->GetDefaultContentSetting(
704 CONTENT_SETTINGS_TYPE_COOKIES));
705
706 GURL host("http://example.com"); 705 GURL host("http://example.com");
707 EXPECT_EQ(CONTENT_SETTING_ALLOW, 706 EXPECT_EQ(CONTENT_SETTING_ALLOW,
708 host_content_settings_map->GetContentSetting( 707 host_content_settings_map->GetContentSetting(
709 host, host, CONTENT_SETTINGS_TYPE_POPUPS, "")); 708 host, host, CONTENT_SETTINGS_TYPE_POPUPS, ""));
710 } 709 }
711 710
712 TEST_F(HostContentSettingsMapTest, MigrateObsoleteNotificationsPrefs) { 711 TEST_F(HostContentSettingsMapTest, MigrateObsoleteNotificationsPrefs) {
713 TestingProfile profile; 712 TestingProfile profile;
714 PrefService* prefs = profile.GetPrefs(); 713 PrefService* prefs = profile.GetPrefs();
715 714
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 1080 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
1082 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1081 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1083 host_content_settings_map->GetDefaultContentSetting( 1082 host_content_settings_map->GetDefaultContentSetting(
1084 CONTENT_SETTINGS_TYPE_PLUGINS)); 1083 CONTENT_SETTINGS_TYPE_PLUGINS));
1085 1084
1086 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 1085 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
1087 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1086 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1088 host_content_settings_map->GetDefaultContentSetting( 1087 host_content_settings_map->GetDefaultContentSetting(
1089 CONTENT_SETTINGS_TYPE_PLUGINS)); 1088 CONTENT_SETTINGS_TYPE_PLUGINS));
1090 } 1089 }
1091
1092 // Tests for cookie content settings.
1093 const GURL kBlockedSite = GURL("http://ads.thirdparty.com");
1094 const GURL kAllowedSite = GURL("http://good.allays.com");
1095 const GURL kFirstPartySite = GURL("http://cool.things.com");
1096 const GURL kExtensionURL = GURL("chrome-extension://deadbeef");
1097
1098 TEST_F(HostContentSettingsMapTest, CookiesBlockSingle) {
1099 TestingProfile profile;
1100 HostContentSettingsMap* host_content_settings_map =
1101 profile.GetHostContentSettingsMap();
1102 host_content_settings_map->AddExceptionForURL(
1103 kBlockedSite,
1104 kBlockedSite,
1105 CONTENT_SETTINGS_TYPE_COOKIES,
1106 "",
1107 CONTENT_SETTING_BLOCK);
1108 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1109 host_content_settings_map->GetCookieContentSetting(
1110 kBlockedSite, kBlockedSite, false));
1111 }
1112
1113 TEST_F(HostContentSettingsMapTest, CookiesBlockThirdParty) {
1114 TestingProfile profile;
1115 HostContentSettingsMap* host_content_settings_map =
1116 profile.GetHostContentSettingsMap();
1117 host_content_settings_map->SetBlockThirdPartyCookies(true);
1118 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1119 host_content_settings_map->GetCookieContentSetting(
1120 kBlockedSite, kFirstPartySite, false));
1121 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1122 host_content_settings_map->GetCookieContentSetting(
1123 kBlockedSite, kFirstPartySite, true));
1124
1125 CommandLine* cmd = CommandLine::ForCurrentProcess();
1126 AutoReset<CommandLine> auto_reset(cmd, *cmd);
1127 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies);
1128
1129 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1130 host_content_settings_map->GetCookieContentSetting(
1131 kBlockedSite, kFirstPartySite, false));
1132 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1133 host_content_settings_map->GetCookieContentSetting(
1134 kBlockedSite, kFirstPartySite, true));
1135 }
1136
1137 TEST_F(HostContentSettingsMapTest, CookiesAllowThirdParty) {
1138 TestingProfile profile;
1139 HostContentSettingsMap* host_content_settings_map =
1140 profile.GetHostContentSettingsMap();
1141 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1142 host_content_settings_map->GetCookieContentSetting(
1143 kBlockedSite, kFirstPartySite, false));
1144 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1145 host_content_settings_map->GetCookieContentSetting(
1146 kBlockedSite, kFirstPartySite, true));
1147 }
1148
1149 TEST_F(HostContentSettingsMapTest, CookiesExplicitBlockSingleThirdParty) {
1150 TestingProfile profile;
1151 HostContentSettingsMap* host_content_settings_map =
1152 profile.GetHostContentSettingsMap();
1153 host_content_settings_map->AddExceptionForURL(
1154 kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
1155 CONTENT_SETTING_BLOCK);
1156 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1157 host_content_settings_map->GetCookieContentSetting(
1158 kBlockedSite, kFirstPartySite, false));
1159 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1160 host_content_settings_map->GetCookieContentSetting(
1161 kBlockedSite, kFirstPartySite, true));
1162 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1163 host_content_settings_map->GetCookieContentSetting(
1164 kAllowedSite, kFirstPartySite, true));
1165 }
1166
1167 TEST_F(HostContentSettingsMapTest, CookiesExplicitSessionOnly) {
1168 TestingProfile profile;
1169 HostContentSettingsMap* host_content_settings_map =
1170 profile.GetHostContentSettingsMap();
1171 host_content_settings_map->AddExceptionForURL(
1172 kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
1173 CONTENT_SETTING_SESSION_ONLY);
1174 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1175 host_content_settings_map->GetCookieContentSetting(
1176 kBlockedSite, kFirstPartySite, false));
1177 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1178 host_content_settings_map->GetCookieContentSetting(
1179 kBlockedSite, kFirstPartySite, true));
1180
1181 host_content_settings_map->SetBlockThirdPartyCookies(true);
1182 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1183 host_content_settings_map->GetCookieContentSetting(
1184 kBlockedSite, kFirstPartySite, false));
1185 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1186 host_content_settings_map->GetCookieContentSetting(
1187 kBlockedSite, kFirstPartySite, true));
1188 }
1189
1190 TEST_F(HostContentSettingsMapTest, CookiesThirdPartyBlockedExplicitAllow) {
1191 TestingProfile profile;
1192 HostContentSettingsMap* host_content_settings_map =
1193 profile.GetHostContentSettingsMap();
1194 host_content_settings_map->AddExceptionForURL(
1195 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
1196 CONTENT_SETTING_ALLOW);
1197 host_content_settings_map->SetBlockThirdPartyCookies(true);
1198 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1199 host_content_settings_map->GetCookieContentSetting(
1200 kAllowedSite, kFirstPartySite, false));
1201 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1202 host_content_settings_map->GetCookieContentSetting(
1203 kAllowedSite, kFirstPartySite, true));
1204
1205 // Extensions should always be allowed to use cookies.
1206 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1207 host_content_settings_map->GetCookieContentSetting(
1208 kAllowedSite, kExtensionURL, false));
1209 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1210 host_content_settings_map->GetCookieContentSetting(
1211 kAllowedSite, kExtensionURL, true));
1212
1213 CommandLine* cmd = CommandLine::ForCurrentProcess();
1214 AutoReset<CommandLine> auto_reset(cmd, *cmd);
1215 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies);
1216
1217 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1218 host_content_settings_map->GetCookieContentSetting(
1219 kAllowedSite, kFirstPartySite, false));
1220
1221 // Extensions should always be allowed to use cookies.
1222 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1223 host_content_settings_map->GetCookieContentSetting(
1224 kAllowedSite, kExtensionURL, false));
1225 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1226 host_content_settings_map->GetCookieContentSetting(
1227 kAllowedSite, kExtensionURL, true));
1228 }
1229
1230 TEST_F(HostContentSettingsMapTest, CookiesBlockEverything) {
1231 TestingProfile profile;
1232 HostContentSettingsMap* host_content_settings_map =
1233 profile.GetHostContentSettingsMap();
1234 host_content_settings_map->SetDefaultContentSetting(
1235 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1236
1237 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1238 host_content_settings_map->GetCookieContentSetting(
1239 kFirstPartySite, kFirstPartySite, false));
1240 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1241 host_content_settings_map->GetCookieContentSetting(
1242 kFirstPartySite, kFirstPartySite, true));
1243 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1244 host_content_settings_map->GetCookieContentSetting(
1245 kAllowedSite, kFirstPartySite, true));
1246 }
1247
1248 TEST_F(HostContentSettingsMapTest, CookiesBlockEverythingExceptAllowed) {
1249 TestingProfile profile;
1250 HostContentSettingsMap* host_content_settings_map =
1251 profile.GetHostContentSettingsMap();
1252 host_content_settings_map->SetDefaultContentSetting(
1253 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1254 host_content_settings_map->AddExceptionForURL(
1255 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
1256 CONTENT_SETTING_ALLOW);
1257
1258 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1259 host_content_settings_map->GetCookieContentSetting(
1260 kFirstPartySite, kFirstPartySite, false));
1261 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1262 host_content_settings_map->GetCookieContentSetting(
1263 kFirstPartySite, kFirstPartySite, true));
1264 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1265 host_content_settings_map->GetCookieContentSetting(
1266 kAllowedSite, kFirstPartySite, false));
1267 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1268 host_content_settings_map->GetCookieContentSetting(
1269 kAllowedSite, kFirstPartySite, true));
1270 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1271 host_content_settings_map->GetCookieContentSetting(
1272 kAllowedSite, kAllowedSite, false));
1273 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1274 host_content_settings_map->GetCookieContentSetting(
1275 kAllowedSite, kAllowedSite, true));
1276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698