Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 1442083002: Stop inheriting push notification permissions from regular to incognito (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mvanouwerkerk's review comments Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_map1 =
msramek 2015/11/27 16:30:04 otr_map1 and otr_map2 are the same, this is an imp
johnme 2015/11/30 14:56:58 They're not quite the same. otr_map2 uses profile.
msramek 2015/12/01 13:41:43 If we want to test the equivalence between the two
johnme 2015/12/02 15:13:16 Acknowledged.
684 new HostContentSettingsMap(profile.GetPrefs(), 685 HostContentSettingsMapFactory::GetForProfile(otr_profile);
685 true)); 686 scoped_refptr<HostContentSettingsMap> otr_map2(
687 new HostContentSettingsMap(profile.GetPrefs(), true /* incognito */));
686 688
687 GURL host("http://example.com/"); 689 GURL host("http://example.com/");
688 ContentSettingsPattern pattern = 690 ContentSettingsPattern pattern =
689 ContentSettingsPattern::FromString("[*.]example.com"); 691 ContentSettingsPattern::FromString("[*.]example.com");
690 692
691 EXPECT_EQ(CONTENT_SETTING_ALLOW, 693 EXPECT_EQ(CONTENT_SETTING_ALLOW,
692 host_content_settings_map->GetContentSetting( 694 host_content_settings_map->GetContentSetting(
693 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 695 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
694 EXPECT_EQ(CONTENT_SETTING_ALLOW, 696 EXPECT_EQ(CONTENT_SETTING_ALLOW,
695 otr_map->GetContentSetting( 697 otr_map1->GetContentSetting(
698 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
699 EXPECT_EQ(CONTENT_SETTING_ALLOW,
700 otr_map2->GetContentSetting(
696 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 701 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
697 702
698 // Changing content settings on the main map should also affect the 703 // Changing content settings on the main map should also affect the
699 // incognito map. 704 // incognito map.
700 host_content_settings_map->SetContentSetting( 705 host_content_settings_map->SetContentSetting(
701 pattern, 706 pattern,
702 ContentSettingsPattern::Wildcard(), 707 ContentSettingsPattern::Wildcard(),
703 CONTENT_SETTINGS_TYPE_IMAGES, 708 CONTENT_SETTINGS_TYPE_IMAGES,
704 std::string(), 709 std::string(),
705 CONTENT_SETTING_BLOCK); 710 CONTENT_SETTING_BLOCK);
706 EXPECT_EQ(CONTENT_SETTING_BLOCK, 711 EXPECT_EQ(CONTENT_SETTING_BLOCK,
707 host_content_settings_map->GetContentSetting( 712 host_content_settings_map->GetContentSetting(
708 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 713 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
709 EXPECT_EQ(CONTENT_SETTING_BLOCK, 714 EXPECT_EQ(CONTENT_SETTING_BLOCK,
710 otr_map->GetContentSetting( 715 otr_map1->GetContentSetting(
716 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
717 EXPECT_EQ(CONTENT_SETTING_BLOCK,
718 otr_map2->GetContentSetting(
711 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 719 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
712 720
713 // Changing content settings on the incognito map should NOT affect the 721 // Changing content settings on the incognito maps should NOT affect the
714 // main map. 722 // main map.
715 otr_map->SetContentSetting(pattern, 723 otr_map1->SetContentSetting(pattern,
716 ContentSettingsPattern::Wildcard(), 724 ContentSettingsPattern::Wildcard(),
717 CONTENT_SETTINGS_TYPE_IMAGES, 725 CONTENT_SETTINGS_TYPE_IMAGES,
718 std::string(), 726 std::string(),
727 CONTENT_SETTING_ALLOW);
728 otr_map2->SetContentSetting(pattern,
729 ContentSettingsPattern::Wildcard(),
730 CONTENT_SETTINGS_TYPE_IMAGES,
731 std::string(),
719 CONTENT_SETTING_ALLOW); 732 CONTENT_SETTING_ALLOW);
720 EXPECT_EQ(CONTENT_SETTING_BLOCK, 733 EXPECT_EQ(CONTENT_SETTING_BLOCK,
721 host_content_settings_map->GetContentSetting( 734 host_content_settings_map->GetContentSetting(
722 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 735 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
723 EXPECT_EQ(CONTENT_SETTING_ALLOW, 736 EXPECT_EQ(CONTENT_SETTING_ALLOW,
724 otr_map->GetContentSetting( 737 otr_map1->GetContentSetting(
738 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
739 EXPECT_EQ(CONTENT_SETTING_ALLOW,
740 otr_map2->GetContentSetting(
725 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 741 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
726 742
727 otr_map->ShutdownOnUIThread(); 743 otr_map2->ShutdownOnUIThread();
744 }
745
746 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) {
747 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in
748 // ContentSettingsRegistry (e.g. push & notifications) only inherit blocks
749 // from the regular to incognito pref provider.
750 TestingProfile profile;
751 Profile* otr_profile = profile.GetOffTheRecordProfile();
752 HostContentSettingsMap* host_content_settings_map =
753 HostContentSettingsMapFactory::GetForProfile(&profile);
754 HostContentSettingsMap* otr_map =
755 HostContentSettingsMapFactory::GetForProfile(otr_profile);
756
757 GURL host("http://example.com/");
758 ContentSettingsPattern pattern =
759 ContentSettingsPattern::FromString("[*.]example.com");
760
761 EXPECT_EQ(CONTENT_SETTING_ASK, host_content_settings_map->GetContentSetting(
762 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
763 EXPECT_EQ(CONTENT_SETTING_ASK, otr_map->GetContentSetting(
764 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
765
766 // BLOCK should be inherited from the main map to the incognito map.
767 host_content_settings_map->SetContentSetting(
768 pattern,
769 ContentSettingsPattern::Wildcard(),
770 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
771 std::string(),
772 CONTENT_SETTING_BLOCK);
773 EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting(
774 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
775 EXPECT_EQ(CONTENT_SETTING_BLOCK, otr_map->GetContentSetting(
776 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
777
778 // ALLOW should not be inherited from the main map to the incognito map (but
779 // it still overwrites the BLOCK, hence incognito reverts to ASK).
780 host_content_settings_map->SetContentSetting(
781 pattern,
782 ContentSettingsPattern::Wildcard(),
783 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
784 std::string(),
785 CONTENT_SETTING_ALLOW);
786 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting(
787 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
788 EXPECT_EQ(CONTENT_SETTING_ASK, otr_map->GetContentSetting(
789 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
790 }
791
792 TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritDefault) {
793 // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in
794 // ContentSettingsRegistry (e.g. push & notifications) only inherit blocks
795 // from the regular to incognito default provider.
796 TestingProfile profile;
797 Profile* otr_profile = profile.GetOffTheRecordProfile();
798 HostContentSettingsMap* host_content_settings_map =
799 HostContentSettingsMapFactory::GetForProfile(&profile);
800 HostContentSettingsMap* otr_map =
801 HostContentSettingsMapFactory::GetForProfile(otr_profile);
802
803 GURL host("http://example.com/");
804
805 EXPECT_EQ(CONTENT_SETTING_ASK,
806 host_content_settings_map->GetDefaultContentSetting(
807 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL));
808 EXPECT_EQ(CONTENT_SETTING_ASK,
809 host_content_settings_map->GetContentSetting(
810 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
811 std::string()));
812 EXPECT_EQ(CONTENT_SETTING_ASK,
813 otr_map->GetDefaultContentSetting(
814 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL));
815 EXPECT_EQ(CONTENT_SETTING_ASK,
816 otr_map->GetContentSetting(
817 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
818 std::string()));
819
820 // BLOCK should be inherited from the main map to the incognito map.
821 host_content_settings_map->SetDefaultContentSetting(
822 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
823 CONTENT_SETTING_BLOCK);
824 EXPECT_EQ(CONTENT_SETTING_BLOCK,
825 host_content_settings_map->GetDefaultContentSetting(
826 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL));
827 EXPECT_EQ(CONTENT_SETTING_BLOCK,
828 host_content_settings_map->GetContentSetting(
829 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
830 std::string()));
831 EXPECT_EQ(CONTENT_SETTING_BLOCK,
832 otr_map->GetDefaultContentSetting(
833 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL));
834 EXPECT_EQ(CONTENT_SETTING_BLOCK,
835 otr_map->GetContentSetting(
836 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
837 std::string()));
838
839 // ALLOW should not be inherited from the main map to the incognito map (but
840 // it still overwrites the BLOCK, hence incognito reverts to ASK).
841 host_content_settings_map->SetDefaultContentSetting(
842 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
843 CONTENT_SETTING_ALLOW);
844 EXPECT_EQ(CONTENT_SETTING_ALLOW,
845 host_content_settings_map->GetDefaultContentSetting(
846 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL));
847 EXPECT_EQ(CONTENT_SETTING_ALLOW,
848 host_content_settings_map->GetContentSetting(
849 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
850 std::string()));
851 EXPECT_EQ(CONTENT_SETTING_ASK,
852 otr_map->GetDefaultContentSetting(
853 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL));
854 EXPECT_EQ(CONTENT_SETTING_ASK,
855 otr_map->GetContentSetting(
856 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
857 std::string()));
728 } 858 }
729 859
730 // For a single Unicode encoded pattern, check if it gets converted to punycode 860 // For a single Unicode encoded pattern, check if it gets converted to punycode
731 // and old pattern gets deleted. 861 // and old pattern gets deleted.
732 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { 862 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
733 TestingProfile profile; 863 TestingProfile profile;
734 PrefService* prefs = profile.GetPrefs(); 864 PrefService* prefs = profile.GetPrefs();
735 865
736 // Set utf-8 data. 866 // Set utf-8 data.
737 { 867 {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1163 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1034 host_content_settings_map->GetContentSetting( 1164 host_content_settings_map->GetContentSetting(
1035 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1165 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1036 host_content_settings_map->SetContentSetting( 1166 host_content_settings_map->SetContentSetting(
1037 pattern, 1167 pattern,
1038 ContentSettingsPattern::Wildcard(), 1168 ContentSettingsPattern::Wildcard(),
1039 CONTENT_SETTINGS_TYPE_IMAGES, 1169 CONTENT_SETTINGS_TYPE_IMAGES,
1040 std::string(), 1170 std::string(),
1041 CONTENT_SETTING_DEFAULT); 1171 CONTENT_SETTING_DEFAULT);
1042 } 1172 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698