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 660 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( |
(...skipping 20 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 blocks | |
msramek
2015/12/01 13:41:43
nit: s/blocks/BLOCK/g
johnme
2015/12/02 15:13:16
Done.
| |
731 // from the regular to incognito pref provider. | |
msramek
2015/12/01 13:41:43
nit: it might be better to just talk about default
johnme
2015/12/02 15:13:16
Done.
| |
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::FromString("[*.]example.com"); | |
msramek
2015/12/01 13:41:43
nit: indentation
johnme
2015/12/02 15:13:16
Done. I also fixed it in the 13 other places in th
| |
742 | |
743 EXPECT_EQ(CONTENT_SETTING_ASK, host_content_settings_map->GetContentSetting( | |
744 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | |
745 EXPECT_EQ(CONTENT_SETTING_ASK, otr_map->GetContentSetting( | |
746 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | |
747 | |
748 // BLOCK should be inherited from the main map to the incognito map. | |
749 host_content_settings_map->SetContentSetting( | |
750 pattern, | |
751 ContentSettingsPattern::Wildcard(), | |
752 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
753 std::string(), | |
754 CONTENT_SETTING_BLOCK); | |
755 EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( | |
756 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | |
757 EXPECT_EQ(CONTENT_SETTING_BLOCK, otr_map->GetContentSetting( | |
758 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | |
759 | |
760 // ALLOW should not be inherited from the main map to the incognito map (but | |
761 // it still overwrites the BLOCK, hence incognito reverts to ASK). | |
762 host_content_settings_map->SetContentSetting( | |
763 pattern, | |
764 ContentSettingsPattern::Wildcard(), | |
765 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
766 std::string(), | |
767 CONTENT_SETTING_ALLOW); | |
768 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( | |
769 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | |
770 EXPECT_EQ(CONTENT_SETTING_ASK, otr_map->GetContentSetting( | |
771 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | |
772 } | |
773 | |
774 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritDefault) { | |
775 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in | |
776 // ContentSettingsRegistry (e.g. push & notifications) only inherit blocks | |
777 // from the regular to incognito default provider. | |
778 TestingProfile profile; | |
779 Profile* otr_profile = profile.GetOffTheRecordProfile(); | |
780 HostContentSettingsMap* host_content_settings_map = | |
781 HostContentSettingsMapFactory::GetForProfile(&profile); | |
782 HostContentSettingsMap* otr_map = | |
783 HostContentSettingsMapFactory::GetForProfile(otr_profile); | |
784 | |
785 GURL host("http://example.com/"); | |
786 | |
787 EXPECT_EQ(CONTENT_SETTING_ASK, | |
788 host_content_settings_map->GetDefaultContentSetting( | |
789 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); | |
790 EXPECT_EQ(CONTENT_SETTING_ASK, | |
791 host_content_settings_map->GetContentSetting( | |
792 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
793 std::string())); | |
794 EXPECT_EQ(CONTENT_SETTING_ASK, | |
795 otr_map->GetDefaultContentSetting( | |
796 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); | |
797 EXPECT_EQ(CONTENT_SETTING_ASK, | |
798 otr_map->GetContentSetting( | |
799 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
800 std::string())); | |
801 | |
802 // BLOCK should be inherited from the main map to the incognito map. | |
803 host_content_settings_map->SetDefaultContentSetting( | |
804 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
805 CONTENT_SETTING_BLOCK); | |
806 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
807 host_content_settings_map->GetDefaultContentSetting( | |
808 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); | |
809 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
810 host_content_settings_map->GetContentSetting( | |
811 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
812 std::string())); | |
813 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
814 otr_map->GetDefaultContentSetting( | |
815 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); | |
816 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
817 otr_map->GetContentSetting( | |
818 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
819 std::string())); | |
820 | |
821 // ALLOW should not be inherited from the main map to the incognito map (but | |
822 // it still overwrites the BLOCK, hence incognito reverts to ASK). | |
823 host_content_settings_map->SetDefaultContentSetting( | |
824 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
825 CONTENT_SETTING_ALLOW); | |
826 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
827 host_content_settings_map->GetDefaultContentSetting( | |
828 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); | |
829 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
830 host_content_settings_map->GetContentSetting( | |
831 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
832 std::string())); | |
833 EXPECT_EQ(CONTENT_SETTING_ASK, | |
834 otr_map->GetDefaultContentSetting( | |
835 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); | |
836 EXPECT_EQ(CONTENT_SETTING_ASK, | |
837 otr_map->GetContentSetting( | |
838 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, | |
839 std::string())); | |
728 } | 840 } |
729 | 841 |
730 // For a single Unicode encoded pattern, check if it gets converted to punycode | 842 // For a single Unicode encoded pattern, check if it gets converted to punycode |
731 // and old pattern gets deleted. | 843 // and old pattern gets deleted. |
732 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { | 844 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { |
733 TestingProfile profile; | 845 TestingProfile profile; |
734 PrefService* prefs = profile.GetPrefs(); | 846 PrefService* prefs = profile.GetPrefs(); |
735 | 847 |
736 // Set utf-8 data. | 848 // Set utf-8 data. |
737 { | 849 { |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1033 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1145 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1034 host_content_settings_map->GetContentSetting( | 1146 host_content_settings_map->GetContentSetting( |
1035 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1147 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
1036 host_content_settings_map->SetContentSetting( | 1148 host_content_settings_map->SetContentSetting( |
1037 pattern, | 1149 pattern, |
1038 ContentSettingsPattern::Wildcard(), | 1150 ContentSettingsPattern::Wildcard(), |
1039 CONTENT_SETTINGS_TYPE_IMAGES, | 1151 CONTENT_SETTINGS_TYPE_IMAGES, |
1040 std::string(), | 1152 std::string(), |
1041 CONTENT_SETTING_DEFAULT); | 1153 CONTENT_SETTING_DEFAULT); |
1042 } | 1154 } |
OLD | NEW |