| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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; |
| 160 desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] = | 161 desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] = |
| 161 CONTENT_SETTING_ASK; | 162 CONTENT_SETTING_ASK; |
| 163 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY] = |
| 164 CONTENT_SETTING_ALLOW; |
| 162 ContentSettings settings = | 165 ContentSettings settings = |
| 163 host_content_settings_map->GetContentSettings(host, host); | 166 host_content_settings_map->GetContentSettings(host, host); |
| 164 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); | 167 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
| 165 | 168 |
| 166 // Check returning all hosts for a setting. | 169 // Check returning all hosts for a setting. |
| 167 ContentSettingsPattern pattern2 = | 170 ContentSettingsPattern pattern2 = |
| 168 ContentSettingsPattern::FromString("[*.]example.org"); | 171 ContentSettingsPattern::FromString("[*.]example.org"); |
| 169 host_content_settings_map->SetContentSetting( | 172 host_content_settings_map->SetContentSetting( |
| 170 pattern2, | 173 pattern2, |
| 171 ContentSettingsPattern::Wildcard(), | 174 ContentSettingsPattern::Wildcard(), |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 | 330 |
| 328 PrefService* prefs = profile.GetPrefs(); | 331 PrefService* prefs = profile.GetPrefs(); |
| 329 | 332 |
| 330 // Make a copy of the default pref value so we can reset it later. | 333 // Make a copy of the default pref value so we can reset it later. |
| 331 scoped_ptr<Value> default_value(prefs->FindPreference( | 334 scoped_ptr<Value> default_value(prefs->FindPreference( |
| 332 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 335 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
| 333 | 336 |
| 334 GURL host("http://example.com"); | 337 GURL host("http://example.com"); |
| 335 | 338 |
| 336 host_content_settings_map->SetDefaultContentSetting( | 339 host_content_settings_map->SetDefaultContentSetting( |
| 337 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 340 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
| 338 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 341 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 339 host_content_settings_map->GetCookieContentSetting( | 342 host_content_settings_map->GetContentSetting( |
| 340 host, host, true)); | 343 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 341 | 344 |
| 342 // Make a copy of the pref's new value so we can reset it later. | 345 // Make a copy of the pref's new value so we can reset it later. |
| 343 scoped_ptr<Value> new_value(prefs->FindPreference( | 346 scoped_ptr<Value> new_value(prefs->FindPreference( |
| 344 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 347 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
| 345 | 348 |
| 346 // Clearing the backing pref should also clear the internal cache. | 349 // Clearing the backing pref should also clear the internal cache. |
| 347 prefs->Set(prefs::kDefaultContentSettings, *default_value); | 350 prefs->Set(prefs::kDefaultContentSettings, *default_value); |
| 348 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 351 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 349 host_content_settings_map->GetCookieContentSetting( | 352 host_content_settings_map->GetContentSetting( |
| 350 host, host, true)); | 353 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 351 | 354 |
| 352 // Reseting the pref to its previous value should update the cache. | 355 // Reseting the pref to its previous value should update the cache. |
| 353 prefs->Set(prefs::kDefaultContentSettings, *new_value); | 356 prefs->Set(prefs::kDefaultContentSettings, *new_value); |
| 354 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 357 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 355 host_content_settings_map->GetCookieContentSetting( | 358 host_content_settings_map->GetContentSetting( |
| 356 host, host, true)); | 359 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 357 } | 360 } |
| 358 | 361 |
| 359 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { | 362 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { |
| 360 TestingProfile profile; | 363 TestingProfile profile; |
| 361 HostContentSettingsMap* host_content_settings_map = | 364 HostContentSettingsMap* host_content_settings_map = |
| 362 profile.GetHostContentSettingsMap(); | 365 profile.GetHostContentSettingsMap(); |
| 363 | 366 |
| 364 PrefService* prefs = profile.GetPrefs(); | 367 PrefService* prefs = profile.GetPrefs(); |
| 365 | 368 |
| 366 // Make a copy of the default pref value so we can reset it later. | 369 // Make a copy of the default pref value so we can reset it later. |
| 367 scoped_ptr<Value> default_value(prefs->FindPreference( | 370 scoped_ptr<Value> default_value(prefs->FindPreference( |
| 368 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); | 371 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); |
| 369 | 372 |
| 370 ContentSettingsPattern pattern = | 373 ContentSettingsPattern pattern = |
| 371 ContentSettingsPattern::FromString("[*.]example.com"); | 374 ContentSettingsPattern::FromString("[*.]example.com"); |
| 372 GURL host("http://example.com"); | 375 GURL host("http://example.com"); |
| 373 | 376 |
| 374 host_content_settings_map->SetContentSetting( | 377 host_content_settings_map->SetContentSetting( |
| 375 pattern, | 378 pattern, |
| 376 ContentSettingsPattern::Wildcard(), | 379 ContentSettingsPattern::Wildcard(), |
| 377 CONTENT_SETTINGS_TYPE_COOKIES, | 380 CONTENT_SETTINGS_TYPE_IMAGES, |
| 378 std::string(), | 381 std::string(), |
| 379 CONTENT_SETTING_BLOCK); | 382 CONTENT_SETTING_BLOCK); |
| 383 |
| 380 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 384 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 381 host_content_settings_map->GetCookieContentSetting( | 385 host_content_settings_map->GetContentSetting( |
| 382 host, host, true)); | 386 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 383 | 387 |
| 384 // Make a copy of the pref's new value so we can reset it later. | 388 // Make a copy of the pref's new value so we can reset it later. |
| 385 scoped_ptr<Value> new_value(prefs->FindPreference( | 389 scoped_ptr<Value> new_value(prefs->FindPreference( |
| 386 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); | 390 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); |
| 387 | 391 |
| 388 // Clearing the backing pref should also clear the internal cache. | 392 // Clearing the backing pref should also clear the internal cache. |
| 389 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); | 393 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); |
| 390 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 394 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 391 host_content_settings_map->GetCookieContentSetting( | 395 host_content_settings_map->GetContentSetting( |
| 392 host, host, true)); | 396 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 393 | 397 |
| 394 // Reseting the pref to its previous value should update the cache. | 398 // Reseting the pref to its previous value should update the cache. |
| 395 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); | 399 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); |
| 396 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 400 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 397 host_content_settings_map->GetCookieContentSetting( | 401 host_content_settings_map->GetContentSetting( |
| 398 host, host, true)); | 402 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 399 } | 403 } |
| 400 | 404 |
| 401 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { | 405 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { |
| 402 TestingProfile profile; | 406 TestingProfile profile; |
| 403 HostContentSettingsMap* host_content_settings_map = | 407 HostContentSettingsMap* host_content_settings_map = |
| 404 profile.GetHostContentSettingsMap(); | 408 profile.GetHostContentSettingsMap(); |
| 409 CookieSettings* cookie_settings = |
| 410 CookieSettings::GetForProfile(&profile); |
| 405 | 411 |
| 406 ContentSettingsPattern pattern = | 412 ContentSettingsPattern pattern = |
| 407 ContentSettingsPattern::FromString("[*.]example.com"); | 413 ContentSettingsPattern::FromString("[*.]example.com"); |
| 408 GURL host_ending_with_dot("http://example.com./"); | 414 GURL host_ending_with_dot("http://example.com./"); |
| 409 | 415 |
| 410 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 416 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 411 host_content_settings_map->GetContentSetting( | 417 host_content_settings_map->GetContentSetting( |
| 412 host_ending_with_dot, | 418 host_ending_with_dot, |
| 413 host_ending_with_dot, | 419 host_ending_with_dot, |
| 414 CONTENT_SETTINGS_TYPE_IMAGES, | 420 CONTENT_SETTINGS_TYPE_IMAGES, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 431 CONTENT_SETTINGS_TYPE_IMAGES, | 437 CONTENT_SETTINGS_TYPE_IMAGES, |
| 432 "", | 438 "", |
| 433 CONTENT_SETTING_BLOCK); | 439 CONTENT_SETTING_BLOCK); |
| 434 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 440 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 435 host_content_settings_map->GetContentSetting( | 441 host_content_settings_map->GetContentSetting( |
| 436 host_ending_with_dot, | 442 host_ending_with_dot, |
| 437 host_ending_with_dot, | 443 host_ending_with_dot, |
| 438 CONTENT_SETTINGS_TYPE_IMAGES, | 444 CONTENT_SETTINGS_TYPE_IMAGES, |
| 439 "")); | 445 "")); |
| 440 | 446 |
| 441 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 447 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
| 442 host_content_settings_map->GetCookieContentSetting( | 448 host_ending_with_dot, host_ending_with_dot)); |
| 443 host_ending_with_dot, host_ending_with_dot, true)); | |
| 444 host_content_settings_map->SetContentSetting( | 449 host_content_settings_map->SetContentSetting( |
| 445 pattern, | 450 pattern, |
| 446 ContentSettingsPattern::Wildcard(), | 451 ContentSettingsPattern::Wildcard(), |
| 447 CONTENT_SETTINGS_TYPE_COOKIES, | 452 CONTENT_SETTINGS_TYPE_COOKIES, |
| 448 "", | 453 "", |
| 449 CONTENT_SETTING_DEFAULT); | 454 CONTENT_SETTING_DEFAULT); |
| 450 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 455 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
| 451 host_content_settings_map->GetCookieContentSetting( | 456 host_ending_with_dot, host_ending_with_dot)); |
| 452 host_ending_with_dot, host_ending_with_dot, true)); | |
| 453 host_content_settings_map->SetContentSetting( | 457 host_content_settings_map->SetContentSetting( |
| 454 pattern, | 458 pattern, |
| 455 ContentSettingsPattern::Wildcard(), | 459 ContentSettingsPattern::Wildcard(), |
| 456 CONTENT_SETTINGS_TYPE_COOKIES, | 460 CONTENT_SETTINGS_TYPE_COOKIES, |
| 457 "", | 461 "", |
| 458 CONTENT_SETTING_BLOCK); | 462 CONTENT_SETTING_BLOCK); |
| 459 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 463 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( |
| 460 host_content_settings_map->GetCookieContentSetting( | 464 host_ending_with_dot, host_ending_with_dot)); |
| 461 host_ending_with_dot, host_ending_with_dot, true)); | |
| 462 | 465 |
| 463 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 466 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 464 host_content_settings_map->GetContentSetting( | 467 host_content_settings_map->GetContentSetting( |
| 465 host_ending_with_dot, | 468 host_ending_with_dot, |
| 466 host_ending_with_dot, | 469 host_ending_with_dot, |
| 467 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 470 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 468 "")); | 471 "")); |
| 469 host_content_settings_map->SetContentSetting( | 472 host_content_settings_map->SetContentSetting( |
| 470 pattern, | 473 pattern, |
| 471 ContentSettingsPattern::Wildcard(), | 474 ContentSettingsPattern::Wildcard(), |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = | 605 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = |
| 603 CONTENT_SETTING_BLOCK; | 606 CONTENT_SETTING_BLOCK; |
| 604 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = | 607 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = |
| 605 CONTENT_SETTING_ASK; | 608 CONTENT_SETTING_ASK; |
| 606 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = | 609 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = |
| 607 CONTENT_SETTING_ASK; | 610 CONTENT_SETTING_ASK; |
| 608 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = | 611 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = |
| 609 CONTENT_SETTING_ASK; | 612 CONTENT_SETTING_ASK; |
| 610 desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] = | 613 desired_settings.settings[CONTENT_SETTINGS_TYPE_AUTO_SELECT_CERTIFICATE] = |
| 611 CONTENT_SETTING_ASK; | 614 CONTENT_SETTING_ASK; |
| 615 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES_SESSION_ONLY] = |
| 616 CONTENT_SETTING_ALLOW; |
| 612 ContentSettings settings = | 617 ContentSettings settings = |
| 613 host_content_settings_map->GetContentSettings(host, host); | 618 host_content_settings_map->GetContentSettings(host, host); |
| 614 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); | 619 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
| 615 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES], | 620 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES], |
| 616 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]); | 621 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]); |
| 617 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES], | 622 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES], |
| 618 settings.settings[CONTENT_SETTINGS_TYPE_IMAGES]); | 623 settings.settings[CONTENT_SETTINGS_TYPE_IMAGES]); |
| 619 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS], | 624 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS], |
| 620 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); | 625 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); |
| 621 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS], | 626 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS], |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 677 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 673 host_content_settings_map->GetContentSetting( | 678 host_content_settings_map->GetContentSetting( |
| 674 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 679 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 675 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 680 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 676 otr_map->GetContentSetting( | 681 otr_map->GetContentSetting( |
| 677 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 682 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 678 | 683 |
| 679 otr_map->ShutdownOnUIThread(); | 684 otr_map->ShutdownOnUIThread(); |
| 680 } | 685 } |
| 681 | 686 |
| 682 TEST_F(HostContentSettingsMapTest, MigrateObsoletePrefs) { | 687 TEST_F(HostContentSettingsMapTest, MigrateObsoletePopupPrefs) { |
| 683 // This feature is currently behind a flag. | 688 // This feature is currently behind a flag. |
| 684 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 689 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 685 AutoReset<CommandLine> auto_reset(cmd, *cmd); | 690 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
| 686 cmd->AppendSwitch(switches::kEnableResourceContentSettings); | 691 cmd->AppendSwitch(switches::kEnableResourceContentSettings); |
| 687 | 692 |
| 688 TestingProfile profile; | 693 TestingProfile profile; |
| 689 PrefService* prefs = profile.GetPrefs(); | 694 PrefService* prefs = profile.GetPrefs(); |
| 690 | 695 |
| 691 // Set obsolete data. | 696 // Set obsolete data. |
| 692 prefs->SetInteger(prefs::kCookieBehavior, | |
| 693 net::StaticCookiePolicy::BLOCK_ALL_COOKIES); | |
| 694 | |
| 695 ListValue popup_hosts; | 697 ListValue popup_hosts; |
| 696 popup_hosts.Append(new StringValue("[*.]example.com")); | 698 popup_hosts.Append(new StringValue("[*.]example.com")); |
| 697 prefs->Set(prefs::kPopupWhitelistedHosts, popup_hosts); | 699 prefs->Set(prefs::kPopupWhitelistedHosts, popup_hosts); |
| 698 | 700 |
| 699 HostContentSettingsMap* host_content_settings_map = | 701 HostContentSettingsMap* host_content_settings_map = |
| 700 profile.GetHostContentSettingsMap(); | 702 profile.GetHostContentSettingsMap(); |
| 701 | 703 |
| 702 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 703 host_content_settings_map->GetDefaultContentSetting( | |
| 704 CONTENT_SETTINGS_TYPE_COOKIES)); | |
| 705 | |
| 706 GURL host("http://example.com"); | 704 GURL host("http://example.com"); |
| 707 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 705 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 708 host_content_settings_map->GetContentSetting( | 706 host_content_settings_map->GetContentSetting( |
| 709 host, host, CONTENT_SETTINGS_TYPE_POPUPS, "")); | 707 host, host, CONTENT_SETTINGS_TYPE_POPUPS, "")); |
| 710 } | 708 } |
| 711 | 709 |
| 712 TEST_F(HostContentSettingsMapTest, MigrateObsoleteNotificationsPrefs) { | 710 TEST_F(HostContentSettingsMapTest, MigrateObsoleteNotificationsPrefs) { |
| 713 TestingProfile profile; | 711 TestingProfile profile; |
| 714 PrefService* prefs = profile.GetPrefs(); | 712 PrefService* prefs = profile.GetPrefs(); |
| 715 | 713 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1081 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 1079 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
| 1082 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1080 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1083 host_content_settings_map->GetDefaultContentSetting( | 1081 host_content_settings_map->GetDefaultContentSetting( |
| 1084 CONTENT_SETTINGS_TYPE_PLUGINS)); | 1082 CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 1085 | 1083 |
| 1086 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); | 1084 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); |
| 1087 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1085 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1088 host_content_settings_map->GetDefaultContentSetting( | 1086 host_content_settings_map->GetDefaultContentSetting( |
| 1089 CONTENT_SETTINGS_TYPE_PLUGINS)); | 1087 CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 1090 } | 1088 } |
| 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 } | |
| OLD | NEW |