| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 TEST_F(HostContentSettingsMapTest, IndividualSettings) { | 98 TEST_F(HostContentSettingsMapTest, IndividualSettings) { |
| 99 TestingProfile profile; | 99 TestingProfile profile; |
| 100 HostContentSettingsMap* host_content_settings_map = | 100 HostContentSettingsMap* host_content_settings_map = |
| 101 HostContentSettingsMapFactory::GetForProfile(&profile); | 101 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 102 | 102 |
| 103 // Check returning individual settings. | 103 // Check returning individual settings. |
| 104 GURL host("http://example.com/"); | 104 GURL host("http://example.com/"); |
| 105 ContentSettingsPattern pattern = | 105 ContentSettingsPattern pattern = |
| 106 ContentSettingsPattern::FromString("[*.]example.com"); | 106 ContentSettingsPattern::FromString("[*.]example.com"); |
| 107 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 107 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 108 host_content_settings_map->GetContentSetting( | 108 host_content_settings_map->GetContentSetting( |
| 109 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 109 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 110 host_content_settings_map->SetContentSetting( | 110 host_content_settings_map->SetContentSetting( |
| 111 pattern, | 111 pattern, |
| 112 ContentSettingsPattern::Wildcard(), | 112 ContentSettingsPattern::Wildcard(), |
| 113 CONTENT_SETTINGS_TYPE_IMAGES, | 113 CONTENT_SETTINGS_TYPE_IMAGES, |
| 114 std::string(), | 114 std::string(), |
| 115 CONTENT_SETTING_DEFAULT); | 115 CONTENT_SETTING_DEFAULT); |
| 116 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 116 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); | 179 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); |
| 180 host_content_settings_map->SetContentSetting( | 180 host_content_settings_map->SetContentSetting( |
| 181 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, | 181 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, |
| 182 std::string(), CONTENT_SETTING_ALLOW); | 182 std::string(), CONTENT_SETTING_ALLOW); |
| 183 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 183 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 184 host_content_settings_map->GetContentSetting( | 184 host_content_settings_map->GetContentSetting( |
| 185 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 185 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
| 186 | 186 |
| 187 // Check returning all hosts for a setting. | 187 // Check returning all hosts for a setting. |
| 188 ContentSettingsPattern pattern2 = | 188 ContentSettingsPattern pattern2 = |
| 189 ContentSettingsPattern::FromString("[*.]example.org"); | 189 ContentSettingsPattern::FromString("[*.]example.org"); |
| 190 host_content_settings_map->SetContentSetting( | 190 host_content_settings_map->SetContentSetting( |
| 191 pattern2, | 191 pattern2, |
| 192 ContentSettingsPattern::Wildcard(), | 192 ContentSettingsPattern::Wildcard(), |
| 193 CONTENT_SETTINGS_TYPE_IMAGES, | 193 CONTENT_SETTINGS_TYPE_IMAGES, |
| 194 std::string(), | 194 std::string(), |
| 195 CONTENT_SETTING_BLOCK); | 195 CONTENT_SETTING_BLOCK); |
| 196 #if defined(ENABLE_PLUGINS) | 196 #if defined(ENABLE_PLUGINS) |
| 197 host_content_settings_map->SetContentSetting( | 197 host_content_settings_map->SetContentSetting( |
| 198 pattern2, | 198 pattern2, |
| 199 ContentSettingsPattern::Wildcard(), | 199 ContentSettingsPattern::Wildcard(), |
| (...skipping 18 matching lines...) Expand all Loading... |
| 218 EXPECT_EQ(1U, host_settings.size()); | 218 EXPECT_EQ(1U, host_settings.size()); |
| 219 } | 219 } |
| 220 | 220 |
| 221 TEST_F(HostContentSettingsMapTest, Clear) { | 221 TEST_F(HostContentSettingsMapTest, Clear) { |
| 222 TestingProfile profile; | 222 TestingProfile profile; |
| 223 HostContentSettingsMap* host_content_settings_map = | 223 HostContentSettingsMap* host_content_settings_map = |
| 224 HostContentSettingsMapFactory::GetForProfile(&profile); | 224 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 225 | 225 |
| 226 // Check clearing one type. | 226 // Check clearing one type. |
| 227 ContentSettingsPattern pattern = | 227 ContentSettingsPattern pattern = |
| 228 ContentSettingsPattern::FromString("[*.]example.org"); | 228 ContentSettingsPattern::FromString("[*.]example.org"); |
| 229 ContentSettingsPattern pattern2 = | 229 ContentSettingsPattern pattern2 = |
| 230 ContentSettingsPattern::FromString("[*.]example.net"); | 230 ContentSettingsPattern::FromString("[*.]example.net"); |
| 231 host_content_settings_map->SetContentSetting( | 231 host_content_settings_map->SetContentSetting( |
| 232 pattern2, | 232 pattern2, |
| 233 ContentSettingsPattern::Wildcard(), | 233 ContentSettingsPattern::Wildcard(), |
| 234 CONTENT_SETTINGS_TYPE_IMAGES, | 234 CONTENT_SETTINGS_TYPE_IMAGES, |
| 235 std::string(), | 235 std::string(), |
| 236 CONTENT_SETTING_BLOCK); | 236 CONTENT_SETTING_BLOCK); |
| 237 host_content_settings_map->SetContentSetting( | 237 host_content_settings_map->SetContentSetting( |
| 238 pattern, | 238 pattern, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 TEST_F(HostContentSettingsMapTest, Patterns) { | 272 TEST_F(HostContentSettingsMapTest, Patterns) { |
| 273 TestingProfile profile; | 273 TestingProfile profile; |
| 274 HostContentSettingsMap* host_content_settings_map = | 274 HostContentSettingsMap* host_content_settings_map = |
| 275 HostContentSettingsMapFactory::GetForProfile(&profile); | 275 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 276 | 276 |
| 277 GURL host1("http://example.com/"); | 277 GURL host1("http://example.com/"); |
| 278 GURL host2("http://www.example.com/"); | 278 GURL host2("http://www.example.com/"); |
| 279 GURL host3("http://example.org/"); | 279 GURL host3("http://example.org/"); |
| 280 ContentSettingsPattern pattern1 = | 280 ContentSettingsPattern pattern1 = |
| 281 ContentSettingsPattern::FromString("[*.]example.com"); | 281 ContentSettingsPattern::FromString("[*.]example.com"); |
| 282 ContentSettingsPattern pattern2 = | 282 ContentSettingsPattern pattern2 = |
| 283 ContentSettingsPattern::FromString("example.org"); | 283 ContentSettingsPattern::FromString("example.org"); |
| 284 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 284 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 285 host_content_settings_map->GetContentSetting( | 285 host_content_settings_map->GetContentSetting( |
| 286 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 286 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 287 host_content_settings_map->SetContentSetting( | 287 host_content_settings_map->SetContentSetting( |
| 288 pattern1, | 288 pattern1, |
| 289 ContentSettingsPattern::Wildcard(), | 289 ContentSettingsPattern::Wildcard(), |
| 290 CONTENT_SETTINGS_TYPE_IMAGES, | 290 CONTENT_SETTINGS_TYPE_IMAGES, |
| 291 std::string(), | 291 std::string(), |
| 292 CONTENT_SETTING_BLOCK); | 292 CONTENT_SETTING_BLOCK); |
| 293 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 293 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 | 388 |
| 389 PrefService* prefs = profile.GetPrefs(); | 389 PrefService* prefs = profile.GetPrefs(); |
| 390 | 390 |
| 391 // Make a copy of the default pref value so we can reset it later. | 391 // Make a copy of the default pref value so we can reset it later. |
| 392 scoped_ptr<base::Value> default_value( | 392 scoped_ptr<base::Value> default_value( |
| 393 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) | 393 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) |
| 394 ->GetValue() | 394 ->GetValue() |
| 395 ->DeepCopy()); | 395 ->DeepCopy()); |
| 396 | 396 |
| 397 ContentSettingsPattern pattern = | 397 ContentSettingsPattern pattern = |
| 398 ContentSettingsPattern::FromString("[*.]example.com"); | 398 ContentSettingsPattern::FromString("[*.]example.com"); |
| 399 GURL host("http://example.com"); | 399 GURL host("http://example.com"); |
| 400 | 400 |
| 401 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 401 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 402 host_content_settings_map->GetContentSetting( | 402 host_content_settings_map->GetContentSetting( |
| 403 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 403 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 404 | 404 |
| 405 host_content_settings_map->SetContentSetting( | 405 host_content_settings_map->SetContentSetting( |
| 406 pattern, | 406 pattern, |
| 407 ContentSettingsPattern::Wildcard(), | 407 ContentSettingsPattern::Wildcard(), |
| 408 CONTENT_SETTINGS_TYPE_IMAGES, | 408 CONTENT_SETTINGS_TYPE_IMAGES, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 432 } | 432 } |
| 433 | 433 |
| 434 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { | 434 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { |
| 435 TestingProfile profile; | 435 TestingProfile profile; |
| 436 HostContentSettingsMap* host_content_settings_map = | 436 HostContentSettingsMap* host_content_settings_map = |
| 437 HostContentSettingsMapFactory::GetForProfile(&profile); | 437 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 438 content_settings::CookieSettings* cookie_settings = | 438 content_settings::CookieSettings* cookie_settings = |
| 439 CookieSettingsFactory::GetForProfile(&profile).get(); | 439 CookieSettingsFactory::GetForProfile(&profile).get(); |
| 440 | 440 |
| 441 ContentSettingsPattern pattern = | 441 ContentSettingsPattern pattern = |
| 442 ContentSettingsPattern::FromString("[*.]example.com"); | 442 ContentSettingsPattern::FromString("[*.]example.com"); |
| 443 GURL host_ending_with_dot("http://example.com./"); | 443 GURL host_ending_with_dot("http://example.com./"); |
| 444 | 444 |
| 445 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 445 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 446 host_content_settings_map->GetContentSetting( | 446 host_content_settings_map->GetContentSetting( |
| 447 host_ending_with_dot, | 447 host_ending_with_dot, |
| 448 host_ending_with_dot, | 448 host_ending_with_dot, |
| 449 CONTENT_SETTINGS_TYPE_IMAGES, | 449 CONTENT_SETTINGS_TYPE_IMAGES, |
| 450 std::string())); | 450 std::string())); |
| 451 host_content_settings_map->SetContentSetting( | 451 host_content_settings_map->SetContentSetting( |
| 452 pattern, | 452 pattern, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 607 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
| 608 } | 608 } |
| 609 | 609 |
| 610 TEST_F(HostContentSettingsMapTest, NestedSettings) { | 610 TEST_F(HostContentSettingsMapTest, NestedSettings) { |
| 611 TestingProfile profile; | 611 TestingProfile profile; |
| 612 HostContentSettingsMap* host_content_settings_map = | 612 HostContentSettingsMap* host_content_settings_map = |
| 613 HostContentSettingsMapFactory::GetForProfile(&profile); | 613 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 614 | 614 |
| 615 GURL host("http://a.b.example.com/"); | 615 GURL host("http://a.b.example.com/"); |
| 616 ContentSettingsPattern pattern1 = | 616 ContentSettingsPattern pattern1 = |
| 617 ContentSettingsPattern::FromString("[*.]example.com"); | 617 ContentSettingsPattern::FromString("[*.]example.com"); |
| 618 ContentSettingsPattern pattern2 = | 618 ContentSettingsPattern pattern2 = |
| 619 ContentSettingsPattern::FromString("[*.]b.example.com"); | 619 ContentSettingsPattern::FromString("[*.]b.example.com"); |
| 620 ContentSettingsPattern pattern3 = | 620 ContentSettingsPattern pattern3 = |
| 621 ContentSettingsPattern::FromString("a.b.example.com"); | 621 ContentSettingsPattern::FromString("a.b.example.com"); |
| 622 | 622 |
| 623 host_content_settings_map->SetContentSetting( | 623 host_content_settings_map->SetContentSetting( |
| 624 pattern1, | 624 pattern1, |
| 625 ContentSettingsPattern::Wildcard(), | 625 ContentSettingsPattern::Wildcard(), |
| 626 CONTENT_SETTINGS_TYPE_IMAGES, | 626 CONTENT_SETTINGS_TYPE_IMAGES, |
| 627 std::string(), | 627 std::string(), |
| 628 CONTENT_SETTING_BLOCK); | 628 CONTENT_SETTING_BLOCK); |
| 629 | 629 |
| 630 host_content_settings_map->SetContentSetting( | 630 host_content_settings_map->SetContentSetting( |
| 631 pattern2, | 631 pattern2, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 EXPECT_EQ(CONTENT_SETTING_ASK, | 671 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 672 host_content_settings_map->GetContentSetting( | 672 host_content_settings_map->GetContentSetting( |
| 673 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); | 673 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); |
| 674 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 674 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 675 host_content_settings_map->GetContentSetting( | 675 host_content_settings_map->GetContentSetting( |
| 676 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 676 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
| 677 } | 677 } |
| 678 | 678 |
| 679 TEST_F(HostContentSettingsMapTest, OffTheRecord) { | 679 TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
| 680 TestingProfile profile; | 680 TestingProfile profile; |
| 681 Profile* otr_profile = profile.GetOffTheRecordProfile(); |
| 681 HostContentSettingsMap* host_content_settings_map = | 682 HostContentSettingsMap* host_content_settings_map = |
| 682 HostContentSettingsMapFactory::GetForProfile(&profile); | 683 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 683 scoped_refptr<HostContentSettingsMap> otr_map( | 684 HostContentSettingsMap* otr_map = |
| 684 new HostContentSettingsMap(profile.GetPrefs(), | 685 HostContentSettingsMapFactory::GetForProfile(otr_profile); |
| 685 true)); | |
| 686 | 686 |
| 687 GURL host("http://example.com/"); | 687 GURL host("http://example.com/"); |
| 688 ContentSettingsPattern pattern = | 688 ContentSettingsPattern pattern = |
| 689 ContentSettingsPattern::FromString("[*.]example.com"); | 689 ContentSettingsPattern::FromString("[*.]example.com"); |
| 690 | 690 |
| 691 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 691 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 692 host_content_settings_map->GetContentSetting( | 692 host_content_settings_map->GetContentSetting( |
| 693 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 693 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 694 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 694 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 695 otr_map->GetContentSetting( | 695 otr_map->GetContentSetting( |
| 696 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 696 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 697 | 697 |
| 698 // Changing content settings on the main map should also affect the | 698 // Changing content settings on the main map should also affect the |
| 699 // incognito map. | 699 // incognito map. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 716 ContentSettingsPattern::Wildcard(), | 716 ContentSettingsPattern::Wildcard(), |
| 717 CONTENT_SETTINGS_TYPE_IMAGES, | 717 CONTENT_SETTINGS_TYPE_IMAGES, |
| 718 std::string(), | 718 std::string(), |
| 719 CONTENT_SETTING_ALLOW); | 719 CONTENT_SETTING_ALLOW); |
| 720 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 720 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 721 host_content_settings_map->GetContentSetting( | 721 host_content_settings_map->GetContentSetting( |
| 722 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 722 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 723 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 723 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 724 otr_map->GetContentSetting( | 724 otr_map->GetContentSetting( |
| 725 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 725 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 726 } |
| 726 | 727 |
| 727 otr_map->ShutdownOnUIThread(); | 728 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) { |
| 729 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in |
| 730 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK |
| 731 // settings from regular to incognito. |
| 732 TestingProfile profile; |
| 733 Profile* otr_profile = profile.GetOffTheRecordProfile(); |
| 734 HostContentSettingsMap* host_content_settings_map = |
| 735 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 736 HostContentSettingsMap* otr_map = |
| 737 HostContentSettingsMapFactory::GetForProfile(otr_profile); |
| 738 |
| 739 GURL host("http://example.com/"); |
| 740 ContentSettingsPattern pattern = |
| 741 ContentSettingsPattern::FromURLNoWildcard(host); |
| 742 |
| 743 EXPECT_EQ( |
| 744 CONTENT_SETTING_ASK, |
| 745 host_content_settings_map->GetContentSetting( |
| 746 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 747 EXPECT_EQ( |
| 748 CONTENT_SETTING_ASK, |
| 749 otr_map->GetContentSetting( |
| 750 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 751 |
| 752 // BLOCK should be inherited from the main map to the incognito map. |
| 753 host_content_settings_map->SetContentSetting( |
| 754 pattern, |
| 755 ContentSettingsPattern::Wildcard(), |
| 756 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 757 std::string(), |
| 758 CONTENT_SETTING_BLOCK); |
| 759 EXPECT_EQ( |
| 760 CONTENT_SETTING_BLOCK, |
| 761 host_content_settings_map->GetContentSetting( |
| 762 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 763 EXPECT_EQ( |
| 764 CONTENT_SETTING_BLOCK, |
| 765 otr_map->GetContentSetting( |
| 766 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 767 |
| 768 // ALLOW should not be inherited from the main map to the incognito map (but |
| 769 // it still overwrites the BLOCK, hence incognito reverts to ASK). |
| 770 host_content_settings_map->SetContentSetting( |
| 771 pattern, |
| 772 ContentSettingsPattern::Wildcard(), |
| 773 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 774 std::string(), |
| 775 CONTENT_SETTING_ALLOW); |
| 776 EXPECT_EQ( |
| 777 CONTENT_SETTING_ALLOW, |
| 778 host_content_settings_map->GetContentSetting( |
| 779 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 780 EXPECT_EQ( |
| 781 CONTENT_SETTING_ASK, |
| 782 otr_map->GetContentSetting( |
| 783 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 784 } |
| 785 |
| 786 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritDefault) { |
| 787 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in |
| 788 // ContentSettingsRegistry (e.g. push & notifications) only inherit BLOCK |
| 789 // default settings from regular to incognito. |
| 790 TestingProfile profile; |
| 791 Profile* otr_profile = profile.GetOffTheRecordProfile(); |
| 792 HostContentSettingsMap* host_content_settings_map = |
| 793 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 794 HostContentSettingsMap* otr_map = |
| 795 HostContentSettingsMapFactory::GetForProfile(otr_profile); |
| 796 |
| 797 GURL host("http://example.com/"); |
| 798 |
| 799 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 800 host_content_settings_map->GetDefaultContentSetting( |
| 801 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| 802 EXPECT_EQ( |
| 803 CONTENT_SETTING_ASK, |
| 804 host_content_settings_map->GetContentSetting( |
| 805 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 806 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 807 otr_map->GetDefaultContentSetting( |
| 808 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| 809 EXPECT_EQ( |
| 810 CONTENT_SETTING_ASK, |
| 811 otr_map->GetContentSetting( |
| 812 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 813 |
| 814 // BLOCK should be inherited from the main map to the incognito map. |
| 815 host_content_settings_map->SetDefaultContentSetting( |
| 816 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_BLOCK); |
| 817 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 818 host_content_settings_map->GetDefaultContentSetting( |
| 819 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| 820 EXPECT_EQ( |
| 821 CONTENT_SETTING_BLOCK, |
| 822 host_content_settings_map->GetContentSetting( |
| 823 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 824 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 825 otr_map->GetDefaultContentSetting( |
| 826 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| 827 EXPECT_EQ( |
| 828 CONTENT_SETTING_BLOCK, |
| 829 otr_map->GetContentSetting( |
| 830 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 831 |
| 832 // ALLOW should not be inherited from the main map to the incognito map (but |
| 833 // it still overwrites the BLOCK, hence incognito reverts to ASK). |
| 834 host_content_settings_map->SetDefaultContentSetting( |
| 835 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW); |
| 836 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 837 host_content_settings_map->GetDefaultContentSetting( |
| 838 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| 839 EXPECT_EQ( |
| 840 CONTENT_SETTING_ALLOW, |
| 841 host_content_settings_map->GetContentSetting( |
| 842 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 843 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 844 otr_map->GetDefaultContentSetting( |
| 845 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| 846 EXPECT_EQ( |
| 847 CONTENT_SETTING_ASK, |
| 848 otr_map->GetContentSetting( |
| 849 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 728 } | 850 } |
| 729 | 851 |
| 730 // For a single Unicode encoded pattern, check if it gets converted to punycode | 852 // For a single Unicode encoded pattern, check if it gets converted to punycode |
| 731 // and old pattern gets deleted. | 853 // and old pattern gets deleted. |
| 732 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { | 854 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { |
| 733 TestingProfile profile; | 855 TestingProfile profile; |
| 734 PrefService* prefs = profile.GetPrefs(); | 856 PrefService* prefs = profile.GetPrefs(); |
| 735 | 857 |
| 736 // Set utf-8 data. | 858 // Set utf-8 data. |
| 737 { | 859 { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 TEST_F(HostContentSettingsMapTest, | 968 TEST_F(HostContentSettingsMapTest, |
| 847 GetNonDefaultContentSettingsIfTypeManaged) { | 969 GetNonDefaultContentSettingsIfTypeManaged) { |
| 848 TestingProfile profile; | 970 TestingProfile profile; |
| 849 HostContentSettingsMap* host_content_settings_map = | 971 HostContentSettingsMap* host_content_settings_map = |
| 850 HostContentSettingsMapFactory::GetForProfile(&profile); | 972 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 851 syncable_prefs::TestingPrefServiceSyncable* prefs = | 973 syncable_prefs::TestingPrefServiceSyncable* prefs = |
| 852 profile.GetTestingPrefService(); | 974 profile.GetTestingPrefService(); |
| 853 | 975 |
| 854 // Set pattern for JavaScript setting. | 976 // Set pattern for JavaScript setting. |
| 855 ContentSettingsPattern pattern = | 977 ContentSettingsPattern pattern = |
| 856 ContentSettingsPattern::FromString("[*.]example.com"); | 978 ContentSettingsPattern::FromString("[*.]example.com"); |
| 857 host_content_settings_map->SetContentSetting( | 979 host_content_settings_map->SetContentSetting( |
| 858 pattern, | 980 pattern, |
| 859 ContentSettingsPattern::Wildcard(), | 981 ContentSettingsPattern::Wildcard(), |
| 860 CONTENT_SETTINGS_TYPE_JAVASCRIPT, | 982 CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 861 std::string(), | 983 std::string(), |
| 862 CONTENT_SETTING_BLOCK); | 984 CONTENT_SETTING_BLOCK); |
| 863 | 985 |
| 864 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 986 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 865 host_content_settings_map->GetDefaultContentSetting( | 987 host_content_settings_map->GetDefaultContentSetting( |
| 866 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); | 988 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 } | 1106 } |
| 985 | 1107 |
| 986 TEST_F(HostContentSettingsMapTest, GetContentSetting) { | 1108 TEST_F(HostContentSettingsMapTest, GetContentSetting) { |
| 987 TestingProfile profile; | 1109 TestingProfile profile; |
| 988 HostContentSettingsMap* host_content_settings_map = | 1110 HostContentSettingsMap* host_content_settings_map = |
| 989 HostContentSettingsMapFactory::GetForProfile(&profile); | 1111 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 990 | 1112 |
| 991 GURL host("http://example.com/"); | 1113 GURL host("http://example.com/"); |
| 992 GURL embedder("chrome://foo"); | 1114 GURL embedder("chrome://foo"); |
| 993 ContentSettingsPattern pattern = | 1115 ContentSettingsPattern pattern = |
| 994 ContentSettingsPattern::FromString("[*.]example.com"); | 1116 ContentSettingsPattern::FromString("[*.]example.com"); |
| 995 host_content_settings_map->SetContentSetting( | 1117 host_content_settings_map->SetContentSetting( |
| 996 pattern, | 1118 pattern, |
| 997 ContentSettingsPattern::Wildcard(), | 1119 ContentSettingsPattern::Wildcard(), |
| 998 CONTENT_SETTINGS_TYPE_IMAGES, | 1120 CONTENT_SETTINGS_TYPE_IMAGES, |
| 999 std::string(), | 1121 std::string(), |
| 1000 CONTENT_SETTING_BLOCK); | 1122 CONTENT_SETTING_BLOCK); |
| 1001 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1123 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1002 host_content_settings_map->GetContentSetting( | 1124 host_content_settings_map->GetContentSetting( |
| 1003 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1125 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 1004 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1126 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1033 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1155 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1034 host_content_settings_map->GetContentSetting( | 1156 host_content_settings_map->GetContentSetting( |
| 1035 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1157 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 1036 host_content_settings_map->SetContentSetting( | 1158 host_content_settings_map->SetContentSetting( |
| 1037 pattern, | 1159 pattern, |
| 1038 ContentSettingsPattern::Wildcard(), | 1160 ContentSettingsPattern::Wildcard(), |
| 1039 CONTENT_SETTINGS_TYPE_IMAGES, | 1161 CONTENT_SETTINGS_TYPE_IMAGES, |
| 1040 std::string(), | 1162 std::string(), |
| 1041 CONTENT_SETTING_DEFAULT); | 1163 CONTENT_SETTING_DEFAULT); |
| 1042 } | 1164 } |
| OLD | NEW |