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

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: Fixing the previous patch set. 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"
10 #include "chrome/browser/content_settings/host_content_settings_map.h" 11 #include "chrome/browser/content_settings/host_content_settings_map.h"
11 #include "chrome/browser/content_settings/mock_settings_observer.h" 12 #include "chrome/browser/content_settings/mock_settings_observer.h"
12 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/browser/prefs/scoped_user_pref_update.h" 14 #include "chrome/browser/prefs/scoped_user_pref_update.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
17 #include "chrome/test/base/testing_browser_process_test.h" 18 #include "chrome/test/base/testing_browser_process_test.h"
18 #include "chrome/test/base/testing_pref_service.h" 19 #include "chrome/test/base/testing_pref_service.h"
19 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] = 146 desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] =
146 CONTENT_SETTING_ALLOW; 147 CONTENT_SETTING_ALLOW;
147 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = 148 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] =
148 CONTENT_SETTING_BLOCK; 149 CONTENT_SETTING_BLOCK;
149 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = 150 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] =
150 CONTENT_SETTING_ASK; 151 CONTENT_SETTING_ASK;
151 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = 152 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] =
152 CONTENT_SETTING_ASK; 153 CONTENT_SETTING_ASK;
153 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = 154 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] =
154 CONTENT_SETTING_ASK; 155 CONTENT_SETTING_ASK;
156 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY] =
157 CONTENT_SETTING_ALLOW;
155 ContentSettings settings = 158 ContentSettings settings =
156 host_content_settings_map->GetContentSettings(host, host); 159 host_content_settings_map->GetContentSettings(host, host);
157 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); 160 EXPECT_TRUE(SettingsEqual(desired_settings, settings));
158 161
159 // Check returning all hosts for a setting. 162 // Check returning all hosts for a setting.
160 ContentSettingsPattern pattern2 = 163 ContentSettingsPattern pattern2 =
161 ContentSettingsPattern::FromString("[*.]example.org"); 164 ContentSettingsPattern::FromString("[*.]example.org");
162 host_content_settings_map->SetContentSetting( 165 host_content_settings_map->SetContentSetting(
163 pattern2, 166 pattern2,
164 ContentSettingsPattern::Wildcard(), 167 ContentSettingsPattern::Wildcard(),
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 323
321 PrefService* prefs = profile.GetPrefs(); 324 PrefService* prefs = profile.GetPrefs();
322 325
323 // Make a copy of the default pref value so we can reset it later. 326 // Make a copy of the default pref value so we can reset it later.
324 scoped_ptr<Value> default_value(prefs->FindPreference( 327 scoped_ptr<Value> default_value(prefs->FindPreference(
325 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 328 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
326 329
327 GURL host("http://example.com"); 330 GURL host("http://example.com");
328 331
329 host_content_settings_map->SetDefaultContentSetting( 332 host_content_settings_map->SetDefaultContentSetting(
330 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); 333 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
331 EXPECT_EQ(CONTENT_SETTING_BLOCK, 334 EXPECT_EQ(CONTENT_SETTING_BLOCK,
332 host_content_settings_map->GetCookieContentSetting( 335 host_content_settings_map->GetContentSetting(
333 host, host, true)); 336 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
334 337
335 // Make a copy of the pref's new value so we can reset it later. 338 // Make a copy of the pref's new value so we can reset it later.
336 scoped_ptr<Value> new_value(prefs->FindPreference( 339 scoped_ptr<Value> new_value(prefs->FindPreference(
337 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 340 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
338 341
339 // Clearing the backing pref should also clear the internal cache. 342 // Clearing the backing pref should also clear the internal cache.
340 prefs->Set(prefs::kDefaultContentSettings, *default_value); 343 prefs->Set(prefs::kDefaultContentSettings, *default_value);
341 EXPECT_EQ(CONTENT_SETTING_ALLOW, 344 EXPECT_EQ(CONTENT_SETTING_ALLOW,
342 host_content_settings_map->GetCookieContentSetting( 345 host_content_settings_map->GetContentSetting(
343 host, host, true)); 346 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
344 347
345 // Reseting the pref to its previous value should update the cache. 348 // Reseting the pref to its previous value should update the cache.
346 prefs->Set(prefs::kDefaultContentSettings, *new_value); 349 prefs->Set(prefs::kDefaultContentSettings, *new_value);
347 EXPECT_EQ(CONTENT_SETTING_BLOCK, 350 EXPECT_EQ(CONTENT_SETTING_BLOCK,
348 host_content_settings_map->GetCookieContentSetting( 351 host_content_settings_map->GetContentSetting(
349 host, host, true)); 352 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
350 } 353 }
351 354
352 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { 355 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
353 TestingProfile profile; 356 TestingProfile profile;
354 HostContentSettingsMap* host_content_settings_map = 357 HostContentSettingsMap* host_content_settings_map =
355 profile.GetHostContentSettingsMap(); 358 profile.GetHostContentSettingsMap();
356 359
357 PrefService* prefs = profile.GetPrefs(); 360 PrefService* prefs = profile.GetPrefs();
358 361
359 // Make a copy of the default pref value so we can reset it later. 362 // Make a copy of the default pref value so we can reset it later.
360 scoped_ptr<Value> default_value(prefs->FindPreference( 363 scoped_ptr<Value> default_value(prefs->FindPreference(
361 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 364 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
362 365
363 ContentSettingsPattern pattern = 366 ContentSettingsPattern pattern =
364 ContentSettingsPattern::FromString("[*.]example.com"); 367 ContentSettingsPattern::FromString("[*.]example.com");
365 GURL host("http://example.com"); 368 GURL host("http://example.com");
366 369
367 host_content_settings_map->SetContentSetting( 370 host_content_settings_map->SetContentSetting(
368 pattern, 371 pattern,
369 ContentSettingsPattern::Wildcard(), 372 ContentSettingsPattern::Wildcard(),
370 CONTENT_SETTINGS_TYPE_COOKIES, 373 CONTENT_SETTINGS_TYPE_IMAGES,
371 std::string(), 374 std::string(),
372 CONTENT_SETTING_BLOCK); 375 CONTENT_SETTING_BLOCK);
376
373 EXPECT_EQ(CONTENT_SETTING_BLOCK, 377 EXPECT_EQ(CONTENT_SETTING_BLOCK,
374 host_content_settings_map->GetCookieContentSetting( 378 host_content_settings_map->GetContentSetting(
375 host, host, true)); 379 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
376 380
377 // Make a copy of the pref's new value so we can reset it later. 381 // Make a copy of the pref's new value so we can reset it later.
378 scoped_ptr<Value> new_value(prefs->FindPreference( 382 scoped_ptr<Value> new_value(prefs->FindPreference(
379 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 383 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy());
380 384
381 // Clearing the backing pref should also clear the internal cache. 385 // Clearing the backing pref should also clear the internal cache.
382 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); 386 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value);
383 EXPECT_EQ(CONTENT_SETTING_ALLOW, 387 EXPECT_EQ(CONTENT_SETTING_ALLOW,
384 host_content_settings_map->GetCookieContentSetting( 388 host_content_settings_map->GetContentSetting(
385 host, host, true)); 389 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
386 390
387 // Reseting the pref to its previous value should update the cache. 391 // Reseting the pref to its previous value should update the cache.
388 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); 392 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value);
389 EXPECT_EQ(CONTENT_SETTING_BLOCK, 393 EXPECT_EQ(CONTENT_SETTING_BLOCK,
390 host_content_settings_map->GetCookieContentSetting( 394 host_content_settings_map->GetContentSetting(
391 host, host, true)); 395 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
392 } 396 }
393 397
394 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { 398 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
395 TestingProfile profile; 399 TestingProfile profile;
396 HostContentSettingsMap* host_content_settings_map = 400 HostContentSettingsMap* host_content_settings_map =
397 profile.GetHostContentSettingsMap(); 401 profile.GetHostContentSettingsMap();
402 CookieSettings* cookie_settings =
403 host_content_settings_map->GetCookieSettings();
398 404
399 ContentSettingsPattern pattern = 405 ContentSettingsPattern pattern =
400 ContentSettingsPattern::FromString("[*.]example.com"); 406 ContentSettingsPattern::FromString("[*.]example.com");
401 GURL host_ending_with_dot("http://example.com./"); 407 GURL host_ending_with_dot("http://example.com./");
402 408
403 EXPECT_EQ(CONTENT_SETTING_ALLOW, 409 EXPECT_EQ(CONTENT_SETTING_ALLOW,
404 host_content_settings_map->GetContentSetting( 410 host_content_settings_map->GetContentSetting(
405 host_ending_with_dot, 411 host_ending_with_dot,
406 host_ending_with_dot, 412 host_ending_with_dot,
407 CONTENT_SETTINGS_TYPE_IMAGES, 413 CONTENT_SETTINGS_TYPE_IMAGES,
(...skipping 16 matching lines...) Expand all
424 CONTENT_SETTINGS_TYPE_IMAGES, 430 CONTENT_SETTINGS_TYPE_IMAGES,
425 "", 431 "",
426 CONTENT_SETTING_BLOCK); 432 CONTENT_SETTING_BLOCK);
427 EXPECT_EQ(CONTENT_SETTING_BLOCK, 433 EXPECT_EQ(CONTENT_SETTING_BLOCK,
428 host_content_settings_map->GetContentSetting( 434 host_content_settings_map->GetContentSetting(
429 host_ending_with_dot, 435 host_ending_with_dot,
430 host_ending_with_dot, 436 host_ending_with_dot,
431 CONTENT_SETTINGS_TYPE_IMAGES, 437 CONTENT_SETTINGS_TYPE_IMAGES,
432 "")); 438 ""));
433 439
434 EXPECT_EQ(CONTENT_SETTING_ALLOW, 440 EXPECT_TRUE(cookie_settings->IsCookieAllowed(
435 host_content_settings_map->GetCookieContentSetting( 441 host_ending_with_dot, host_ending_with_dot, true));
436 host_ending_with_dot, host_ending_with_dot, true));
437 host_content_settings_map->SetContentSetting( 442 host_content_settings_map->SetContentSetting(
438 pattern, 443 pattern,
439 ContentSettingsPattern::Wildcard(), 444 ContentSettingsPattern::Wildcard(),
440 CONTENT_SETTINGS_TYPE_COOKIES, 445 CONTENT_SETTINGS_TYPE_COOKIES,
441 "", 446 "",
442 CONTENT_SETTING_DEFAULT); 447 CONTENT_SETTING_DEFAULT);
443 EXPECT_EQ(CONTENT_SETTING_ALLOW, 448 EXPECT_TRUE(cookie_settings->IsCookieAllowed(
444 host_content_settings_map->GetCookieContentSetting( 449 host_ending_with_dot, host_ending_with_dot, true));
445 host_ending_with_dot, host_ending_with_dot, true));
446 host_content_settings_map->SetContentSetting( 450 host_content_settings_map->SetContentSetting(
447 pattern, 451 pattern,
448 ContentSettingsPattern::Wildcard(), 452 ContentSettingsPattern::Wildcard(),
449 CONTENT_SETTINGS_TYPE_COOKIES, 453 CONTENT_SETTINGS_TYPE_COOKIES,
450 "", 454 "",
451 CONTENT_SETTING_BLOCK); 455 CONTENT_SETTING_BLOCK);
452 EXPECT_EQ(CONTENT_SETTING_BLOCK, 456 EXPECT_FALSE(cookie_settings->IsCookieAllowed(
453 host_content_settings_map->GetCookieContentSetting( 457 host_ending_with_dot, host_ending_with_dot, true));
454 host_ending_with_dot, host_ending_with_dot, true));
455 458
456 EXPECT_EQ(CONTENT_SETTING_ALLOW, 459 EXPECT_EQ(CONTENT_SETTING_ALLOW,
457 host_content_settings_map->GetContentSetting( 460 host_content_settings_map->GetContentSetting(
458 host_ending_with_dot, 461 host_ending_with_dot,
459 host_ending_with_dot, 462 host_ending_with_dot,
460 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 463 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
461 "")); 464 ""));
462 host_content_settings_map->SetContentSetting( 465 host_content_settings_map->SetContentSetting(
463 pattern, 466 pattern,
464 ContentSettingsPattern::Wildcard(), 467 ContentSettingsPattern::Wildcard(),
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] = 596 desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] =
594 CONTENT_SETTING_BLOCK; 597 CONTENT_SETTING_BLOCK;
595 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = 598 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] =
596 CONTENT_SETTING_BLOCK; 599 CONTENT_SETTING_BLOCK;
597 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = 600 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] =
598 CONTENT_SETTING_ASK; 601 CONTENT_SETTING_ASK;
599 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = 602 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] =
600 CONTENT_SETTING_ASK; 603 CONTENT_SETTING_ASK;
601 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = 604 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] =
602 CONTENT_SETTING_ASK; 605 CONTENT_SETTING_ASK;
606 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY] =
607 CONTENT_SETTING_ALLOW;
603 ContentSettings settings = 608 ContentSettings settings =
604 host_content_settings_map->GetContentSettings(host, host); 609 host_content_settings_map->GetContentSettings(host, host);
605 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); 610 EXPECT_TRUE(SettingsEqual(desired_settings, settings));
606 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES], 611 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES],
607 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]); 612 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]);
608 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES], 613 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES],
609 settings.settings[CONTENT_SETTINGS_TYPE_IMAGES]); 614 settings.settings[CONTENT_SETTINGS_TYPE_IMAGES]);
610 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS], 615 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS],
611 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); 616 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]);
612 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS], 617 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS],
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 EXPECT_EQ(CONTENT_SETTING_BLOCK, 668 EXPECT_EQ(CONTENT_SETTING_BLOCK,
664 host_content_settings_map->GetContentSetting( 669 host_content_settings_map->GetContentSetting(
665 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 670 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
666 EXPECT_EQ(CONTENT_SETTING_ALLOW, 671 EXPECT_EQ(CONTENT_SETTING_ALLOW,
667 otr_map->GetContentSetting( 672 otr_map->GetContentSetting(
668 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 673 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
669 674
670 otr_map->ShutdownOnUIThread(); 675 otr_map->ShutdownOnUIThread();
671 } 676 }
672 677
673 TEST_F(HostContentSettingsMapTest, MigrateObsoletePrefs) { 678 TEST_F(HostContentSettingsMapTest, MigrateObsoletePopupPrefs) {
674 // This feature is currently behind a flag. 679 // This feature is currently behind a flag.
675 CommandLine* cmd = CommandLine::ForCurrentProcess(); 680 CommandLine* cmd = CommandLine::ForCurrentProcess();
676 AutoReset<CommandLine> auto_reset(cmd, *cmd); 681 AutoReset<CommandLine> auto_reset(cmd, *cmd);
677 cmd->AppendSwitch(switches::kEnableResourceContentSettings); 682 cmd->AppendSwitch(switches::kEnableResourceContentSettings);
678 683
679 TestingProfile profile; 684 TestingProfile profile;
680 PrefService* prefs = profile.GetPrefs(); 685 PrefService* prefs = profile.GetPrefs();
681 686
682 // Set obsolete data. 687 // Set obsolete data.
683 prefs->SetInteger(prefs::kCookieBehavior,
684 net::StaticCookiePolicy::BLOCK_ALL_COOKIES);
685
686 ListValue popup_hosts; 688 ListValue popup_hosts;
687 popup_hosts.Append(new StringValue("[*.]example.com")); 689 popup_hosts.Append(new StringValue("[*.]example.com"));
688 prefs->Set(prefs::kPopupWhitelistedHosts, popup_hosts); 690 prefs->Set(prefs::kPopupWhitelistedHosts, popup_hosts);
689 691
690 HostContentSettingsMap* host_content_settings_map = 692 HostContentSettingsMap* host_content_settings_map =
691 profile.GetHostContentSettingsMap(); 693 profile.GetHostContentSettingsMap();
692 694
693 EXPECT_EQ(CONTENT_SETTING_BLOCK,
694 host_content_settings_map->GetDefaultContentSetting(
695 CONTENT_SETTINGS_TYPE_COOKIES));
696
697 GURL host("http://example.com"); 695 GURL host("http://example.com");
698 EXPECT_EQ(CONTENT_SETTING_ALLOW, 696 EXPECT_EQ(CONTENT_SETTING_ALLOW,
699 host_content_settings_map->GetContentSetting( 697 host_content_settings_map->GetContentSetting(
700 host, host, CONTENT_SETTINGS_TYPE_POPUPS, "")); 698 host, host, CONTENT_SETTINGS_TYPE_POPUPS, ""));
701 } 699 }
702 700
703 TEST_F(HostContentSettingsMapTest, MigrateObsoleteNotificationsPrefs) { 701 TEST_F(HostContentSettingsMapTest, MigrateObsoleteNotificationsPrefs) {
704 TestingProfile profile; 702 TestingProfile profile;
705 PrefService* prefs = profile.GetPrefs(); 703 PrefService* prefs = profile.GetPrefs();
706 704
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1071 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1069 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1072 host_content_settings_map->GetDefaultContentSetting( 1070 host_content_settings_map->GetDefaultContentSetting(
1073 CONTENT_SETTINGS_TYPE_PLUGINS)); 1071 CONTENT_SETTINGS_TYPE_PLUGINS));
1074 1072
1075 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 1073 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
1076 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1074 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1077 host_content_settings_map->GetDefaultContentSetting( 1075 host_content_settings_map->GetDefaultContentSetting(
1078 CONTENT_SETTINGS_TYPE_PLUGINS)); 1076 CONTENT_SETTINGS_TYPE_PLUGINS));
1079 } 1077 }
1080 1078
1081 // Tests for cookie content settings.
1082 const GURL kBlockedSite = GURL("http://ads.thirdparty.com");
1083 const GURL kAllowedSite = GURL("http://good.allays.com");
1084 const GURL kFirstPartySite = GURL("http://cool.things.com");
1085 const GURL kExtensionURL = GURL("chrome-extension://deadbeef");
1086
1087 TEST_F(HostContentSettingsMapTest, CookiesBlockSingle) {
1088 TestingProfile profile;
1089 HostContentSettingsMap* host_content_settings_map =
1090 profile.GetHostContentSettingsMap();
1091 host_content_settings_map->AddExceptionForURL(
1092 kBlockedSite,
1093 kBlockedSite,
1094 CONTENT_SETTINGS_TYPE_COOKIES,
1095 "",
1096 CONTENT_SETTING_BLOCK);
1097 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1098 host_content_settings_map->GetCookieContentSetting(
1099 kBlockedSite, kBlockedSite, false));
1100 }
1101
1102 TEST_F(HostContentSettingsMapTest, CookiesBlockThirdParty) {
1103 TestingProfile profile;
1104 HostContentSettingsMap* host_content_settings_map =
1105 profile.GetHostContentSettingsMap();
1106 host_content_settings_map->SetBlockThirdPartyCookies(true);
1107 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1108 host_content_settings_map->GetCookieContentSetting(
1109 kBlockedSite, kFirstPartySite, false));
1110 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1111 host_content_settings_map->GetCookieContentSetting(
1112 kBlockedSite, kFirstPartySite, true));
1113
1114 CommandLine* cmd = CommandLine::ForCurrentProcess();
1115 AutoReset<CommandLine> auto_reset(cmd, *cmd);
1116 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies);
1117
1118 EXPECT_EQ(CONTENT_SETTING_BLOCK,
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
1126 TEST_F(HostContentSettingsMapTest, CookiesAllowThirdParty) {
1127 TestingProfile profile;
1128 HostContentSettingsMap* host_content_settings_map =
1129 profile.GetHostContentSettingsMap();
1130 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1131 host_content_settings_map->GetCookieContentSetting(
1132 kBlockedSite, kFirstPartySite, false));
1133 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1134 host_content_settings_map->GetCookieContentSetting(
1135 kBlockedSite, kFirstPartySite, true));
1136 }
1137
1138 TEST_F(HostContentSettingsMapTest, CookiesExplicitBlockSingleThirdParty) {
1139 TestingProfile profile;
1140 HostContentSettingsMap* host_content_settings_map =
1141 profile.GetHostContentSettingsMap();
1142 host_content_settings_map->AddExceptionForURL(
1143 kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
1144 CONTENT_SETTING_BLOCK);
1145 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1146 host_content_settings_map->GetCookieContentSetting(
1147 kBlockedSite, kFirstPartySite, false));
1148 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1149 host_content_settings_map->GetCookieContentSetting(
1150 kBlockedSite, kFirstPartySite, true));
1151 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1152 host_content_settings_map->GetCookieContentSetting(
1153 kAllowedSite, kFirstPartySite, true));
1154 }
1155
1156 TEST_F(HostContentSettingsMapTest, CookiesExplicitSessionOnly) {
1157 TestingProfile profile;
1158 HostContentSettingsMap* host_content_settings_map =
1159 profile.GetHostContentSettingsMap();
1160 host_content_settings_map->AddExceptionForURL(
1161 kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
1162 CONTENT_SETTING_SESSION_ONLY);
1163 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1164 host_content_settings_map->GetCookieContentSetting(
1165 kBlockedSite, kFirstPartySite, false));
1166 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1167 host_content_settings_map->GetCookieContentSetting(
1168 kBlockedSite, kFirstPartySite, true));
1169
1170 host_content_settings_map->SetBlockThirdPartyCookies(true);
1171 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1172 host_content_settings_map->GetCookieContentSetting(
1173 kBlockedSite, kFirstPartySite, false));
1174 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY,
1175 host_content_settings_map->GetCookieContentSetting(
1176 kBlockedSite, kFirstPartySite, true));
1177 }
1178
1179 TEST_F(HostContentSettingsMapTest, CookiesThirdPartyBlockedExplicitAllow) {
1180 TestingProfile profile;
1181 HostContentSettingsMap* host_content_settings_map =
1182 profile.GetHostContentSettingsMap();
1183 host_content_settings_map->AddExceptionForURL(
1184 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
1185 CONTENT_SETTING_ALLOW);
1186 host_content_settings_map->SetBlockThirdPartyCookies(true);
1187 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1188 host_content_settings_map->GetCookieContentSetting(
1189 kAllowedSite, kFirstPartySite, false));
1190 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1191 host_content_settings_map->GetCookieContentSetting(
1192 kAllowedSite, kFirstPartySite, true));
1193
1194 // Extensions should always be allowed to use cookies.
1195 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1196 host_content_settings_map->GetCookieContentSetting(
1197 kAllowedSite, kExtensionURL, false));
1198 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1199 host_content_settings_map->GetCookieContentSetting(
1200 kAllowedSite, kExtensionURL, true));
1201
1202 CommandLine* cmd = CommandLine::ForCurrentProcess();
1203 AutoReset<CommandLine> auto_reset(cmd, *cmd);
1204 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies);
1205
1206 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1207 host_content_settings_map->GetCookieContentSetting(
1208 kAllowedSite, kFirstPartySite, false));
1209
1210 // Extensions should always be allowed to use cookies.
1211 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1212 host_content_settings_map->GetCookieContentSetting(
1213 kAllowedSite, kExtensionURL, false));
1214 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1215 host_content_settings_map->GetCookieContentSetting(
1216 kAllowedSite, kExtensionURL, true));
1217 }
1218
1219 TEST_F(HostContentSettingsMapTest, CookiesBlockEverything) {
1220 TestingProfile profile;
1221 HostContentSettingsMap* host_content_settings_map =
1222 profile.GetHostContentSettingsMap();
1223 host_content_settings_map->SetDefaultContentSetting(
1224 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1225
1226 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1227 host_content_settings_map->GetCookieContentSetting(
1228 kFirstPartySite, kFirstPartySite, false));
1229 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1230 host_content_settings_map->GetCookieContentSetting(
1231 kFirstPartySite, kFirstPartySite, true));
1232 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1233 host_content_settings_map->GetCookieContentSetting(
1234 kAllowedSite, kFirstPartySite, true));
1235 }
1236
1237 TEST_F(HostContentSettingsMapTest, CookiesBlockEverythingExceptAllowed) {
1238 TestingProfile profile;
1239 HostContentSettingsMap* host_content_settings_map =
1240 profile.GetHostContentSettingsMap();
1241 host_content_settings_map->SetDefaultContentSetting(
1242 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1243 host_content_settings_map->AddExceptionForURL(
1244 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "",
1245 CONTENT_SETTING_ALLOW);
1246
1247 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1248 host_content_settings_map->GetCookieContentSetting(
1249 kFirstPartySite, kFirstPartySite, false));
1250 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1251 host_content_settings_map->GetCookieContentSetting(
1252 kFirstPartySite, kFirstPartySite, true));
1253 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1254 host_content_settings_map->GetCookieContentSetting(
1255 kAllowedSite, kFirstPartySite, false));
1256 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1257 host_content_settings_map->GetCookieContentSetting(
1258 kAllowedSite, kFirstPartySite, true));
1259 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1260 host_content_settings_map->GetCookieContentSetting(
1261 kAllowedSite, kAllowedSite, false));
1262 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1263 host_content_settings_map->GetCookieContentSetting(
1264 kAllowedSite, kAllowedSite, true));
1265 }
1266
1267 } // namespace 1079 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698