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 "chrome/browser/content_settings/content_settings_mock_observer.h" | 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
(...skipping 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1063 host_content_settings_map->AddObserver(&mock_observer); | 1063 host_content_settings_map->AddObserver(&mock_observer); |
1064 | 1064 |
1065 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1065 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
1066 host_content_settings_map->GetContentSetting( | 1066 host_content_settings_map->GetContentSetting( |
1067 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1067 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
1068 host_content_settings_map->SetContentSettingDefaultScope( | 1068 host_content_settings_map->SetContentSettingDefaultScope( |
1069 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), | 1069 host, GURL(), CONTENT_SETTINGS_TYPE_IMAGES, std::string(), |
1070 CONTENT_SETTING_DEFAULT); | 1070 CONTENT_SETTING_DEFAULT); |
1071 } | 1071 } |
1072 | 1072 |
1073 TEST_F(HostContentSettingsMapTest, RevocationObserver) { | |
1074 TestingProfile profile; | |
1075 HostContentSettingsMap* map = | |
1076 HostContentSettingsMapFactory::GetForProfile(&profile); | |
1077 content_settings::MockObserver mock_observer; | |
1078 map->AddRevocationObserver(&mock_observer); | |
1079 | |
1080 GURL host("http://example.com/"); | |
1081 | |
1082 ContentSettingsPattern pattern = | |
1083 ContentSettingsPattern::FromURLNoWildcard(host); | |
1084 | |
1085 // Allow->Block triggers a revocation. | |
1086 | |
1087 EXPECT_CALL(mock_observer, | |
1088 OnContentSettingRevoked(host, host, | |
1089 CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); | |
1090 | |
1091 map->SetContentSettingDefaultScope( | |
1092 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, "", CONTENT_SETTING_ALLOW); | |
1093 | |
1094 map->SetContentSettingDefaultScope( | |
1095 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, "", CONTENT_SETTING_BLOCK); | |
1096 | |
1097 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); | |
1098 | |
1099 // Block->Allow does not trigger a revocation. | |
1100 EXPECT_CALL(mock_observer, | |
1101 OnContentSettingRevoked(host, host, | |
1102 CONTENT_SETTINGS_TYPE_GEOLOCATION, "")) | |
1103 .Times(0); | |
1104 | |
1105 map->SetContentSettingDefaultScope( | |
1106 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, "", CONTENT_SETTING_ALLOW); | |
1107 | |
1108 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); | |
1109 | |
1110 // Allow->Default triggers a revocation when default is 'ask'. | |
kcarattini
2016/03/17 02:51:22
There's no way to clear or reset all permissions f
tsergeant
2016/03/17 06:25:40
Hmm, good point. Under this system the 'Clear & Re
| |
1111 EXPECT_CALL(mock_observer, | |
1112 OnContentSettingRevoked(host, host, | |
1113 CONTENT_SETTINGS_TYPE_GEOLOCATION, "")); | |
1114 | |
1115 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
1116 CONTENT_SETTING_ASK); | |
1117 | |
1118 map->SetContentSettingDefaultScope(host, host, | |
1119 CONTENT_SETTINGS_TYPE_GEOLOCATION, "", | |
1120 CONTENT_SETTING_DEFAULT); | |
1121 | |
1122 // Allow->Default does not trigger a revocation when default is 'allow'. | |
1123 EXPECT_CALL(mock_observer, | |
1124 OnContentSettingRevoked(host, host, | |
1125 CONTENT_SETTINGS_TYPE_GEOLOCATION, "")) | |
1126 .Times(0); | |
1127 | |
1128 map->SetDefaultContentSetting(CONTENT_SETTINGS_TYPE_GEOLOCATION, | |
1129 CONTENT_SETTING_ALLOW); | |
1130 | |
1131 map->SetContentSettingDefaultScope(host, host, | |
1132 CONTENT_SETTINGS_TYPE_GEOLOCATION, "", | |
1133 CONTENT_SETTING_ALLOW); | |
1134 map->SetContentSettingDefaultScope(host, host, | |
1135 CONTENT_SETTINGS_TYPE_GEOLOCATION, "", | |
1136 CONTENT_SETTING_DEFAULT); | |
1137 | |
1138 ::testing::Mock::VerifyAndClearExpectations(&mock_observer); | |
1139 } | |
1140 | |
1073 TEST_F(HostContentSettingsMapTest, GuestProfile) { | 1141 TEST_F(HostContentSettingsMapTest, GuestProfile) { |
1074 TestingProfile profile; | 1142 TestingProfile profile; |
1075 profile.SetGuestSession(true); | 1143 profile.SetGuestSession(true); |
1076 HostContentSettingsMap* host_content_settings_map = | 1144 HostContentSettingsMap* host_content_settings_map = |
1077 HostContentSettingsMapFactory::GetForProfile(&profile); | 1145 HostContentSettingsMapFactory::GetForProfile(&profile); |
1078 | 1146 |
1079 GURL host("http://example.com/"); | 1147 GURL host("http://example.com/"); |
1080 ContentSettingsPattern pattern = | 1148 ContentSettingsPattern pattern = |
1081 ContentSettingsPattern::FromString("[*.]example.com"); | 1149 ContentSettingsPattern::FromString("[*.]example.com"); |
1082 | 1150 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1134 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); | 1202 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); |
1135 | 1203 |
1136 // Test that during construction all the prefs get cleared. | 1204 // Test that during construction all the prefs get cleared. |
1137 HostContentSettingsMapFactory::GetForProfile(&profile); | 1205 HostContentSettingsMapFactory::GetForProfile(&profile); |
1138 | 1206 |
1139 const base::DictionaryValue* all_settings_dictionary = | 1207 const base::DictionaryValue* all_settings_dictionary = |
1140 profile.GetPrefs()->GetDictionary( | 1208 profile.GetPrefs()->GetDictionary( |
1141 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); | 1209 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); |
1142 EXPECT_TRUE(all_settings_dictionary->empty()); | 1210 EXPECT_TRUE(all_settings_dictionary->empty()); |
1143 } | 1211 } |
OLD | NEW |