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