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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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_FULLSCREEN] = | 161 desired_settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN] = |
161 CONTENT_SETTING_ASK; | 162 CONTENT_SETTING_ASK; |
162 desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK] = | 163 desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK] = |
163 CONTENT_SETTING_ASK; | 164 CONTENT_SETTING_ASK; |
164 ContentSettings settings = | 165 ContentSettings settings = |
165 host_content_settings_map->GetContentSettings(host, host); | 166 host_content_settings_map->GetContentSettings(host); |
166 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); | 167 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
167 | 168 |
168 // Check returning all hosts for a setting. | 169 // Check returning all hosts for a setting. |
169 ContentSettingsPattern pattern2 = | 170 ContentSettingsPattern pattern2 = |
170 ContentSettingsPattern::FromString("[*.]example.org"); | 171 ContentSettingsPattern::FromString("[*.]example.org"); |
171 host_content_settings_map->SetContentSetting( | 172 host_content_settings_map->SetContentSetting( |
172 pattern2, | 173 pattern2, |
173 ContentSettingsPattern::Wildcard(), | 174 ContentSettingsPattern::Wildcard(), |
174 CONTENT_SETTINGS_TYPE_IMAGES, | 175 CONTENT_SETTINGS_TYPE_IMAGES, |
175 std::string(), | 176 std::string(), |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 | 335 |
335 PrefService* prefs = profile.GetPrefs(); | 336 PrefService* prefs = profile.GetPrefs(); |
336 | 337 |
337 // Make a copy of the default pref value so we can reset it later. | 338 // Make a copy of the default pref value so we can reset it later. |
338 scoped_ptr<Value> default_value(prefs->FindPreference( | 339 scoped_ptr<Value> default_value(prefs->FindPreference( |
339 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 340 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
340 | 341 |
341 GURL host("http://example.com"); | 342 GURL host("http://example.com"); |
342 | 343 |
343 host_content_settings_map->SetDefaultContentSetting( | 344 host_content_settings_map->SetDefaultContentSetting( |
344 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 345 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
345 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 346 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
346 host_content_settings_map->GetCookieContentSetting( | 347 host_content_settings_map->GetContentSetting( |
347 host, host, true)); | 348 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
348 | 349 |
349 // Make a copy of the pref's new value so we can reset it later. | 350 // Make a copy of the pref's new value so we can reset it later. |
350 scoped_ptr<Value> new_value(prefs->FindPreference( | 351 scoped_ptr<Value> new_value(prefs->FindPreference( |
351 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 352 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
352 | 353 |
353 // Clearing the backing pref should also clear the internal cache. | 354 // Clearing the backing pref should also clear the internal cache. |
354 prefs->Set(prefs::kDefaultContentSettings, *default_value); | 355 prefs->Set(prefs::kDefaultContentSettings, *default_value); |
355 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 356 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
356 host_content_settings_map->GetCookieContentSetting( | 357 host_content_settings_map->GetContentSetting( |
357 host, host, true)); | 358 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
358 | 359 |
359 // Reseting the pref to its previous value should update the cache. | 360 // Reseting the pref to its previous value should update the cache. |
360 prefs->Set(prefs::kDefaultContentSettings, *new_value); | 361 prefs->Set(prefs::kDefaultContentSettings, *new_value); |
361 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 362 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
362 host_content_settings_map->GetCookieContentSetting( | 363 host_content_settings_map->GetContentSetting( |
363 host, host, true)); | 364 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
364 } | 365 } |
365 | 366 |
366 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { | 367 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { |
367 TestingProfile profile; | 368 TestingProfile profile; |
368 HostContentSettingsMap* host_content_settings_map = | 369 HostContentSettingsMap* host_content_settings_map = |
369 profile.GetHostContentSettingsMap(); | 370 profile.GetHostContentSettingsMap(); |
370 | 371 |
371 PrefService* prefs = profile.GetPrefs(); | 372 PrefService* prefs = profile.GetPrefs(); |
372 | 373 |
373 // Make a copy of the default pref value so we can reset it later. | 374 // Make a copy of the default pref value so we can reset it later. |
374 scoped_ptr<Value> default_value(prefs->FindPreference( | 375 scoped_ptr<Value> default_value(prefs->FindPreference( |
375 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); | 376 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); |
376 | 377 |
377 ContentSettingsPattern pattern = | 378 ContentSettingsPattern pattern = |
378 ContentSettingsPattern::FromString("[*.]example.com"); | 379 ContentSettingsPattern::FromString("[*.]example.com"); |
379 GURL host("http://example.com"); | 380 GURL host("http://example.com"); |
380 | 381 |
381 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 382 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
382 host_content_settings_map->GetCookieContentSetting( | 383 host_content_settings_map->GetContentSetting( |
383 host, host, true)); | 384 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
384 | 385 |
385 host_content_settings_map->SetContentSetting( | 386 host_content_settings_map->SetContentSetting( |
386 pattern, | 387 pattern, |
387 ContentSettingsPattern::Wildcard(), | 388 ContentSettingsPattern::Wildcard(), |
388 CONTENT_SETTINGS_TYPE_COOKIES, | 389 CONTENT_SETTINGS_TYPE_IMAGES, |
389 std::string(), | 390 std::string(), |
390 CONTENT_SETTING_BLOCK); | 391 CONTENT_SETTING_BLOCK); |
391 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 392 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
392 host_content_settings_map->GetCookieContentSetting( | 393 host_content_settings_map->GetContentSetting( |
393 host, host, true)); | 394 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
394 | 395 |
395 // Make a copy of the pref's new value so we can reset it later. | 396 // Make a copy of the pref's new value so we can reset it later. |
396 scoped_ptr<Value> new_value(prefs->FindPreference( | 397 scoped_ptr<Value> new_value(prefs->FindPreference( |
397 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); | 398 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); |
398 | 399 |
399 // Clearing the backing pref should also clear the internal cache. | 400 // Clearing the backing pref should also clear the internal cache. |
400 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); | 401 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); |
401 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 402 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
402 host_content_settings_map->GetCookieContentSetting( | 403 host_content_settings_map->GetContentSetting( |
403 host, host, true)); | 404 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
404 | 405 |
405 // Reseting the pref to its previous value should update the cache. | 406 // Reseting the pref to its previous value should update the cache. |
406 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); | 407 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); |
407 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 408 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
408 host_content_settings_map->GetCookieContentSetting( | 409 host_content_settings_map->GetContentSetting( |
409 host, host, true)); | 410 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
410 } | 411 } |
411 | 412 |
412 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { | 413 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { |
413 TestingProfile profile; | 414 TestingProfile profile; |
414 HostContentSettingsMap* host_content_settings_map = | 415 HostContentSettingsMap* host_content_settings_map = |
415 profile.GetHostContentSettingsMap(); | 416 profile.GetHostContentSettingsMap(); |
417 CookieSettings* cookie_settings = CookieSettings::GetForProfile(&profile); | |
416 | 418 |
417 ContentSettingsPattern pattern = | 419 ContentSettingsPattern pattern = |
418 ContentSettingsPattern::FromString("[*.]example.com"); | 420 ContentSettingsPattern::FromString("[*.]example.com"); |
419 GURL host_ending_with_dot("http://example.com./"); | 421 GURL host_ending_with_dot("http://example.com./"); |
420 | 422 |
421 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 423 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
422 host_content_settings_map->GetContentSetting( | 424 host_content_settings_map->GetContentSetting( |
423 host_ending_with_dot, | 425 host_ending_with_dot, |
424 host_ending_with_dot, | 426 host_ending_with_dot, |
425 CONTENT_SETTINGS_TYPE_IMAGES, | 427 CONTENT_SETTINGS_TYPE_IMAGES, |
(...skipping 16 matching lines...) Expand all Loading... | |
442 CONTENT_SETTINGS_TYPE_IMAGES, | 444 CONTENT_SETTINGS_TYPE_IMAGES, |
443 "", | 445 "", |
444 CONTENT_SETTING_BLOCK); | 446 CONTENT_SETTING_BLOCK); |
445 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 447 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
446 host_content_settings_map->GetContentSetting( | 448 host_content_settings_map->GetContentSetting( |
447 host_ending_with_dot, | 449 host_ending_with_dot, |
448 host_ending_with_dot, | 450 host_ending_with_dot, |
449 CONTENT_SETTINGS_TYPE_IMAGES, | 451 CONTENT_SETTINGS_TYPE_IMAGES, |
450 "")); | 452 "")); |
451 | 453 |
452 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 454 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
453 host_content_settings_map->GetCookieContentSetting( | 455 host_ending_with_dot, host_ending_with_dot)); |
454 host_ending_with_dot, host_ending_with_dot, true)); | |
455 host_content_settings_map->SetContentSetting( | 456 host_content_settings_map->SetContentSetting( |
456 pattern, | 457 pattern, |
457 ContentSettingsPattern::Wildcard(), | 458 ContentSettingsPattern::Wildcard(), |
458 CONTENT_SETTINGS_TYPE_COOKIES, | 459 CONTENT_SETTINGS_TYPE_COOKIES, |
459 "", | 460 "", |
460 CONTENT_SETTING_DEFAULT); | 461 CONTENT_SETTING_DEFAULT); |
461 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 462 EXPECT_TRUE(cookie_settings->IsSettingCookieAllowed( |
462 host_content_settings_map->GetCookieContentSetting( | 463 host_ending_with_dot, host_ending_with_dot)); |
463 host_ending_with_dot, host_ending_with_dot, true)); | |
464 host_content_settings_map->SetContentSetting( | 464 host_content_settings_map->SetContentSetting( |
465 pattern, | 465 pattern, |
466 ContentSettingsPattern::Wildcard(), | 466 ContentSettingsPattern::Wildcard(), |
467 CONTENT_SETTINGS_TYPE_COOKIES, | 467 CONTENT_SETTINGS_TYPE_COOKIES, |
468 "", | 468 "", |
469 CONTENT_SETTING_BLOCK); | 469 CONTENT_SETTING_BLOCK); |
470 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 470 EXPECT_FALSE(cookie_settings->IsSettingCookieAllowed( |
471 host_content_settings_map->GetCookieContentSetting( | 471 host_ending_with_dot, host_ending_with_dot)); |
472 host_ending_with_dot, host_ending_with_dot, true)); | |
473 | 472 |
474 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 473 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
475 host_content_settings_map->GetContentSetting( | 474 host_content_settings_map->GetContentSetting( |
476 host_ending_with_dot, | 475 host_ending_with_dot, |
477 host_ending_with_dot, | 476 host_ending_with_dot, |
478 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 477 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
479 "")); | 478 "")); |
480 host_content_settings_map->SetContentSetting( | 479 host_content_settings_map->SetContentSetting( |
481 pattern, | 480 pattern, |
482 ContentSettingsPattern::Wildcard(), | 481 ContentSettingsPattern::Wildcard(), |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
616 CONTENT_SETTING_ASK; | 615 CONTENT_SETTING_ASK; |
617 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = | 616 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = |
618 CONTENT_SETTING_ASK; | 617 CONTENT_SETTING_ASK; |
619 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = | 618 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = |
620 CONTENT_SETTING_ASK; | 619 CONTENT_SETTING_ASK; |
621 desired_settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN] = | 620 desired_settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN] = |
622 CONTENT_SETTING_ASK; | 621 CONTENT_SETTING_ASK; |
623 desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK] = | 622 desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK] = |
624 CONTENT_SETTING_ASK; | 623 CONTENT_SETTING_ASK; |
625 ContentSettings settings = | 624 ContentSettings settings = |
626 host_content_settings_map->GetContentSettings(host, host); | 625 host_content_settings_map->GetContentSettings(host); |
627 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); | 626 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
628 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES], | 627 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES], |
629 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]); | 628 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]); |
630 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES], | 629 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES], |
631 settings.settings[CONTENT_SETTINGS_TYPE_IMAGES]); | 630 settings.settings[CONTENT_SETTINGS_TYPE_IMAGES]); |
632 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS], | 631 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS], |
633 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); | 632 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); |
634 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS], | 633 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS], |
635 settings.settings[CONTENT_SETTINGS_TYPE_POPUPS]); | 634 settings.settings[CONTENT_SETTINGS_TYPE_POPUPS]); |
636 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION], | 635 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION], |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 688 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
690 host_content_settings_map->GetContentSetting( | 689 host_content_settings_map->GetContentSetting( |
691 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 690 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
692 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 691 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
693 otr_map->GetContentSetting( | 692 otr_map->GetContentSetting( |
694 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 693 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
695 | 694 |
696 otr_map->ShutdownOnUIThread(); | 695 otr_map->ShutdownOnUIThread(); |
697 } | 696 } |
698 | 697 |
699 TEST_F(HostContentSettingsMapTest, MigrateObsoletePrefs) { | 698 TEST_F(HostContentSettingsMapTest, MigrateObsoletePopupPrefs) { |
700 TestingProfile profile; | 699 TestingProfile profile; |
701 PrefService* prefs = profile.GetPrefs(); | 700 PrefService* prefs = profile.GetPrefs(); |
702 | 701 |
703 // Set obsolete data. | 702 // Set obsolete data. |
704 prefs->SetInteger(prefs::kCookieBehavior, | |
Bernhard Bauer
2011/10/25 13:11:21
Can you update the CL description that this remove
marja
2011/10/26 13:03:21
Did that, and removed the migration code, and the
| |
705 net::StaticCookiePolicy::BLOCK_ALL_COOKIES); | |
706 | |
707 ListValue popup_hosts; | 703 ListValue popup_hosts; |
708 popup_hosts.Append(new StringValue("[*.]example.com")); | 704 popup_hosts.Append(new StringValue("[*.]example.com")); |
709 prefs->Set(prefs::kPopupWhitelistedHosts, popup_hosts); | 705 prefs->Set(prefs::kPopupWhitelistedHosts, popup_hosts); |
710 | 706 |
711 HostContentSettingsMap* host_content_settings_map = | 707 HostContentSettingsMap* host_content_settings_map = |
712 profile.GetHostContentSettingsMap(); | 708 profile.GetHostContentSettingsMap(); |
713 | 709 |
714 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
715 host_content_settings_map->GetDefaultContentSetting( | |
716 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | |
717 | |
718 GURL host("http://example.com"); | 710 GURL host("http://example.com"); |
719 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 711 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
720 host_content_settings_map->GetContentSetting( | 712 host_content_settings_map->GetContentSetting( |
721 host, host, CONTENT_SETTINGS_TYPE_POPUPS, "")); | 713 host, host, CONTENT_SETTINGS_TYPE_POPUPS, "")); |
722 } | 714 } |
723 | 715 |
724 TEST_F(HostContentSettingsMapTest, MigrateObsoleteNotificationsPrefs) { | 716 TEST_F(HostContentSettingsMapTest, MigrateObsoleteNotificationsPrefs) { |
725 TestingProfile profile; | 717 TestingProfile profile; |
726 PrefService* prefs = profile.GetPrefs(); | 718 PrefService* prefs = profile.GetPrefs(); |
727 | 719 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
813 ContentSettingsPattern::FromString("[*.]example.com"); | 805 ContentSettingsPattern::FromString("[*.]example.com"); |
814 std::string resource1("someplugin"); | 806 std::string resource1("someplugin"); |
815 std::string resource2("otherplugin"); | 807 std::string resource2("otherplugin"); |
816 | 808 |
817 // If resource content settings are enabled, GetContentSettings should return | 809 // If resource content settings are enabled, GetContentSettings should return |
818 // the default values for all plugins | 810 // the default values for all plugins |
819 ContentSetting default_plugin_setting = | 811 ContentSetting default_plugin_setting = |
820 host_content_settings_map->GetDefaultContentSetting( | 812 host_content_settings_map->GetDefaultContentSetting( |
821 CONTENT_SETTINGS_TYPE_PLUGINS, NULL); | 813 CONTENT_SETTINGS_TYPE_PLUGINS, NULL); |
822 ContentSettings settings = | 814 ContentSettings settings = |
823 host_content_settings_map->GetContentSettings(host, host); | 815 host_content_settings_map->GetContentSettings(host); |
824 EXPECT_EQ(default_plugin_setting, | 816 EXPECT_EQ(default_plugin_setting, |
825 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); | 817 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); |
826 | 818 |
827 // If no resource-specific content settings are defined, the setting should be | 819 // If no resource-specific content settings are defined, the setting should be |
828 // DEFAULT. | 820 // DEFAULT. |
829 EXPECT_EQ(CONTENT_SETTING_DEFAULT, | 821 EXPECT_EQ(CONTENT_SETTING_DEFAULT, |
830 host_content_settings_map->GetContentSetting( | 822 host_content_settings_map->GetContentSetting( |
831 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); | 823 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); |
832 | 824 |
833 host_content_settings_map->SetContentSetting( | 825 host_content_settings_map->SetContentSetting( |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1063 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 1055 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); |
1064 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1056 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1065 host_content_settings_map->GetDefaultContentSetting( | 1057 host_content_settings_map->GetDefaultContentSetting( |
1066 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 1058 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
1067 | 1059 |
1068 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); | 1060 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); |
1069 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1061 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1070 host_content_settings_map->GetDefaultContentSetting( | 1062 host_content_settings_map->GetDefaultContentSetting( |
1071 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 1063 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
1072 } | 1064 } |
1073 | |
1074 // Tests for cookie content settings. | |
1075 const GURL kBlockedSite = GURL("http://ads.thirdparty.com"); | |
1076 const GURL kAllowedSite = GURL("http://good.allays.com"); | |
1077 const GURL kFirstPartySite = GURL("http://cool.things.com"); | |
1078 const GURL kExtensionURL = GURL("chrome-extension://deadbeef"); | |
1079 | |
1080 TEST_F(HostContentSettingsMapTest, CookiesBlockSingle) { | |
1081 TestingProfile profile; | |
1082 HostContentSettingsMap* host_content_settings_map = | |
1083 profile.GetHostContentSettingsMap(); | |
1084 host_content_settings_map->AddExceptionForURL( | |
1085 kBlockedSite, | |
1086 kBlockedSite, | |
1087 CONTENT_SETTINGS_TYPE_COOKIES, | |
1088 "", | |
1089 CONTENT_SETTING_BLOCK); | |
1090 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1091 host_content_settings_map->GetCookieContentSetting( | |
1092 kBlockedSite, kBlockedSite, false)); | |
1093 } | |
1094 | |
1095 TEST_F(HostContentSettingsMapTest, CookiesBlockThirdParty) { | |
1096 TestingProfile profile; | |
1097 HostContentSettingsMap* host_content_settings_map = | |
1098 profile.GetHostContentSettingsMap(); | |
1099 host_content_settings_map->SetBlockThirdPartyCookies(true); | |
1100 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1101 host_content_settings_map->GetCookieContentSetting( | |
1102 kBlockedSite, kFirstPartySite, false)); | |
1103 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1104 host_content_settings_map->GetCookieContentSetting( | |
1105 kBlockedSite, kFirstPartySite, true)); | |
1106 | |
1107 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
1108 AutoReset<CommandLine> auto_reset(cmd, *cmd); | |
1109 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); | |
1110 | |
1111 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1112 host_content_settings_map->GetCookieContentSetting( | |
1113 kBlockedSite, kFirstPartySite, false)); | |
1114 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1115 host_content_settings_map->GetCookieContentSetting( | |
1116 kBlockedSite, kFirstPartySite, true)); | |
1117 } | |
1118 | |
1119 TEST_F(HostContentSettingsMapTest, CookiesAllowThirdParty) { | |
1120 TestingProfile profile; | |
1121 HostContentSettingsMap* host_content_settings_map = | |
1122 profile.GetHostContentSettingsMap(); | |
1123 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1124 host_content_settings_map->GetCookieContentSetting( | |
1125 kBlockedSite, kFirstPartySite, false)); | |
1126 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1127 host_content_settings_map->GetCookieContentSetting( | |
1128 kBlockedSite, kFirstPartySite, true)); | |
1129 } | |
1130 | |
1131 TEST_F(HostContentSettingsMapTest, CookiesExplicitBlockSingleThirdParty) { | |
1132 TestingProfile profile; | |
1133 HostContentSettingsMap* host_content_settings_map = | |
1134 profile.GetHostContentSettingsMap(); | |
1135 host_content_settings_map->AddExceptionForURL( | |
1136 kBlockedSite, kBlockedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", | |
1137 CONTENT_SETTING_BLOCK); | |
1138 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1139 host_content_settings_map->GetCookieContentSetting( | |
1140 kBlockedSite, kFirstPartySite, false)); | |
1141 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1142 host_content_settings_map->GetCookieContentSetting( | |
1143 kBlockedSite, kFirstPartySite, true)); | |
1144 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1145 host_content_settings_map->GetCookieContentSetting( | |
1146 kAllowedSite, kFirstPartySite, true)); | |
1147 } | |
1148 | |
1149 TEST_F(HostContentSettingsMapTest, CookiesExplicitSessionOnly) { | |
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_SESSION_ONLY); | |
1156 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | |
1157 host_content_settings_map->GetCookieContentSetting( | |
1158 kBlockedSite, kFirstPartySite, false)); | |
1159 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | |
1160 host_content_settings_map->GetCookieContentSetting( | |
1161 kBlockedSite, kFirstPartySite, true)); | |
1162 | |
1163 host_content_settings_map->SetBlockThirdPartyCookies(true); | |
1164 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | |
1165 host_content_settings_map->GetCookieContentSetting( | |
1166 kBlockedSite, kFirstPartySite, false)); | |
1167 EXPECT_EQ(CONTENT_SETTING_SESSION_ONLY, | |
1168 host_content_settings_map->GetCookieContentSetting( | |
1169 kBlockedSite, kFirstPartySite, true)); | |
1170 } | |
1171 | |
1172 TEST_F(HostContentSettingsMapTest, CookiesThirdPartyBlockedExplicitAllow) { | |
1173 TestingProfile profile; | |
1174 HostContentSettingsMap* host_content_settings_map = | |
1175 profile.GetHostContentSettingsMap(); | |
1176 host_content_settings_map->AddExceptionForURL( | |
1177 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", | |
1178 CONTENT_SETTING_ALLOW); | |
1179 host_content_settings_map->SetBlockThirdPartyCookies(true); | |
1180 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1181 host_content_settings_map->GetCookieContentSetting( | |
1182 kAllowedSite, kFirstPartySite, false)); | |
1183 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1184 host_content_settings_map->GetCookieContentSetting( | |
1185 kAllowedSite, kFirstPartySite, true)); | |
1186 | |
1187 // Extensions should always be allowed to use cookies. | |
1188 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1189 host_content_settings_map->GetCookieContentSetting( | |
1190 kAllowedSite, kExtensionURL, false)); | |
1191 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1192 host_content_settings_map->GetCookieContentSetting( | |
1193 kAllowedSite, kExtensionURL, true)); | |
1194 | |
1195 CommandLine* cmd = CommandLine::ForCurrentProcess(); | |
1196 AutoReset<CommandLine> auto_reset(cmd, *cmd); | |
1197 cmd->AppendSwitch(switches::kBlockReadingThirdPartyCookies); | |
1198 | |
1199 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1200 host_content_settings_map->GetCookieContentSetting( | |
1201 kAllowedSite, kFirstPartySite, false)); | |
1202 | |
1203 // Extensions should always be allowed to use cookies. | |
1204 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1205 host_content_settings_map->GetCookieContentSetting( | |
1206 kAllowedSite, kExtensionURL, false)); | |
1207 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1208 host_content_settings_map->GetCookieContentSetting( | |
1209 kAllowedSite, kExtensionURL, true)); | |
1210 } | |
1211 | |
1212 TEST_F(HostContentSettingsMapTest, CookiesBlockEverything) { | |
1213 TestingProfile profile; | |
1214 HostContentSettingsMap* host_content_settings_map = | |
1215 profile.GetHostContentSettingsMap(); | |
1216 host_content_settings_map->SetDefaultContentSetting( | |
1217 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | |
1218 | |
1219 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1220 host_content_settings_map->GetCookieContentSetting( | |
1221 kFirstPartySite, kFirstPartySite, false)); | |
1222 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1223 host_content_settings_map->GetCookieContentSetting( | |
1224 kFirstPartySite, kFirstPartySite, true)); | |
1225 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1226 host_content_settings_map->GetCookieContentSetting( | |
1227 kAllowedSite, kFirstPartySite, true)); | |
1228 } | |
1229 | |
1230 TEST_F(HostContentSettingsMapTest, CookiesBlockEverythingExceptAllowed) { | |
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 host_content_settings_map->AddExceptionForURL( | |
1237 kAllowedSite, kAllowedSite, CONTENT_SETTINGS_TYPE_COOKIES, "", | |
1238 CONTENT_SETTING_ALLOW); | |
1239 | |
1240 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1241 host_content_settings_map->GetCookieContentSetting( | |
1242 kFirstPartySite, kFirstPartySite, false)); | |
1243 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1244 host_content_settings_map->GetCookieContentSetting( | |
1245 kFirstPartySite, kFirstPartySite, true)); | |
1246 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1247 host_content_settings_map->GetCookieContentSetting( | |
1248 kAllowedSite, kFirstPartySite, false)); | |
1249 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1250 host_content_settings_map->GetCookieContentSetting( | |
1251 kAllowedSite, kFirstPartySite, true)); | |
1252 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1253 host_content_settings_map->GetCookieContentSetting( | |
1254 kAllowedSite, kAllowedSite, false)); | |
1255 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1256 host_content_settings_map->GetCookieContentSetting( | |
1257 kAllowedSite, kAllowedSite, true)); | |
1258 } | |
OLD | NEW |