| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/host_content_settings_map.h" | 5 #include "chrome/browser/host_content_settings_map.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" |
| 7 #include "chrome/browser/pref_service.h" | 10 #include "chrome/browser/pref_service.h" |
| 11 #include "chrome/common/chrome_switches.h" |
| 8 #include "chrome/common/notification_registrar.h" | 12 #include "chrome/common/notification_registrar.h" |
| 9 #include "chrome/common/notification_service.h" | 13 #include "chrome/common/notification_service.h" |
| 10 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 11 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 12 #include "chrome/test/testing_profile.h" | 16 #include "chrome/test/testing_profile.h" |
| 13 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 19 |
| 16 | 20 |
| 17 namespace { | 21 namespace { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 80 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 77 host_content_settings_map->GetDefaultContentSetting( | 81 host_content_settings_map->GetDefaultContentSetting( |
| 78 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 82 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
| 79 host_content_settings_map->SetDefaultContentSetting( | 83 host_content_settings_map->SetDefaultContentSetting( |
| 80 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 84 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
| 81 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 85 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 82 host_content_settings_map->GetDefaultContentSetting( | 86 host_content_settings_map->GetDefaultContentSetting( |
| 83 CONTENT_SETTINGS_TYPE_IMAGES)); | 87 CONTENT_SETTINGS_TYPE_IMAGES)); |
| 84 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( | 88 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( |
| 85 GURL(chrome::kChromeUINewTabURL), | 89 GURL(chrome::kChromeUINewTabURL), |
| 86 CONTENT_SETTINGS_TYPE_IMAGES)); | 90 CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 87 host_content_settings_map->SetDefaultContentSetting( | 91 host_content_settings_map->SetDefaultContentSetting( |
| 88 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ASK); | 92 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ASK); |
| 89 EXPECT_EQ(CONTENT_SETTING_ASK, | 93 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 90 host_content_settings_map->GetDefaultContentSetting( | 94 host_content_settings_map->GetDefaultContentSetting( |
| 91 CONTENT_SETTINGS_TYPE_PLUGINS)); | 95 CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 92 host_content_settings_map->SetDefaultContentSetting( | 96 host_content_settings_map->SetDefaultContentSetting( |
| 93 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); | 97 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); |
| 94 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 98 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 95 host_content_settings_map->GetDefaultContentSetting( | 99 host_content_settings_map->GetDefaultContentSetting( |
| 96 CONTENT_SETTINGS_TYPE_POPUPS)); | 100 CONTENT_SETTINGS_TYPE_POPUPS)); |
| 97 host_content_settings_map->ResetToDefaults(); | 101 host_content_settings_map->ResetToDefaults(); |
| 98 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 102 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 99 host_content_settings_map->GetDefaultContentSetting( | 103 host_content_settings_map->GetDefaultContentSetting( |
| 100 CONTENT_SETTINGS_TYPE_PLUGINS)); | 104 CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 101 | 105 |
| 102 // Check returning individual settings. | 106 // Check returning individual settings. |
| 103 GURL host("http://example.com/"); | 107 GURL host("http://example.com/"); |
| 104 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 108 HostContentSettingsMap::Pattern pattern("[*.]example.com"); |
| 105 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 109 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 106 host_content_settings_map->GetContentSetting( | 110 host_content_settings_map->GetContentSetting( |
| 107 host, CONTENT_SETTINGS_TYPE_IMAGES)); | 111 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 108 host_content_settings_map->SetContentSetting(pattern, | 112 host_content_settings_map->SetContentSetting(pattern, |
| 109 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_DEFAULT); | 113 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); |
| 110 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 114 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 111 host_content_settings_map->GetContentSetting( | 115 host_content_settings_map->GetContentSetting( |
| 112 host, CONTENT_SETTINGS_TYPE_IMAGES)); | 116 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 113 host_content_settings_map->SetContentSetting(pattern, | 117 host_content_settings_map->SetContentSetting(pattern, |
| 114 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 118 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 115 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 119 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 116 host_content_settings_map->GetContentSetting( | 120 host_content_settings_map->GetContentSetting( |
| 117 host, CONTENT_SETTINGS_TYPE_IMAGES)); | 121 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 118 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 122 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 119 host_content_settings_map->GetContentSetting( | 123 host_content_settings_map->GetContentSetting( |
| 120 host, CONTENT_SETTINGS_TYPE_PLUGINS)); | 124 host, CONTENT_SETTINGS_TYPE_PLUGINS, "")); |
| 121 | 125 |
| 122 // Check returning all settings for a host. | 126 // Check returning all settings for a host. |
| 123 ContentSettings desired_settings; | 127 ContentSettings desired_settings; |
| 124 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES] = | 128 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES] = |
| 125 CONTENT_SETTING_ALLOW; | 129 CONTENT_SETTING_ALLOW; |
| 126 host_content_settings_map->SetContentSetting(pattern, | 130 host_content_settings_map->SetContentSetting(pattern, |
| 127 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_DEFAULT); | 131 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); |
| 128 desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = | 132 desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = |
| 129 CONTENT_SETTING_ALLOW; | 133 CONTENT_SETTING_ALLOW; |
| 130 host_content_settings_map->SetContentSetting(pattern, | 134 host_content_settings_map->SetContentSetting(pattern, |
| 131 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 135 CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_BLOCK); |
| 132 desired_settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] = | 136 desired_settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] = |
| 133 CONTENT_SETTING_BLOCK; | 137 CONTENT_SETTING_BLOCK; |
| 134 host_content_settings_map->SetContentSetting(pattern, | 138 host_content_settings_map->SetContentSetting(pattern, |
| 135 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_ALLOW); | 139 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_ALLOW); |
| 136 desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] = | 140 desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] = |
| 137 CONTENT_SETTING_ALLOW; | 141 CONTENT_SETTING_ALLOW; |
| 138 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = | 142 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = |
| 139 CONTENT_SETTING_BLOCK; | 143 CONTENT_SETTING_BLOCK; |
| 140 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = | 144 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = |
| 141 CONTENT_SETTING_ASK; | 145 CONTENT_SETTING_ASK; |
| 142 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = | 146 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = |
| 143 CONTENT_SETTING_ASK; | 147 CONTENT_SETTING_ASK; |
| 144 ContentSettings settings = | 148 ContentSettings settings = |
| 145 host_content_settings_map->GetContentSettings(host); | 149 host_content_settings_map->GetContentSettings(host); |
| 146 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); | 150 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
| 147 | 151 |
| 148 // Check returning all hosts for a setting. | 152 // Check returning all hosts for a setting. |
| 149 HostContentSettingsMap::Pattern pattern2("[*.]example.org"); | 153 HostContentSettingsMap::Pattern pattern2("[*.]example.org"); |
| 150 host_content_settings_map->SetContentSetting(pattern2, | 154 host_content_settings_map->SetContentSetting(pattern2, |
| 151 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 155 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 152 host_content_settings_map->SetContentSetting(pattern2, | 156 host_content_settings_map->SetContentSetting(pattern2, |
| 153 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 157 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); |
| 154 HostContentSettingsMap::SettingsForOneType host_settings; | 158 HostContentSettingsMap::SettingsForOneType host_settings; |
| 155 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, | 159 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, |
| 160 "", |
| 156 &host_settings); | 161 &host_settings); |
| 157 EXPECT_EQ(1U, host_settings.size()); | 162 EXPECT_EQ(1U, host_settings.size()); |
| 158 host_content_settings_map->GetSettingsForOneType( | 163 host_content_settings_map->GetSettingsForOneType( |
| 159 CONTENT_SETTINGS_TYPE_PLUGINS, &host_settings); | 164 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); |
| 160 EXPECT_EQ(2U, host_settings.size()); | 165 EXPECT_EQ(2U, host_settings.size()); |
| 161 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, | 166 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
| 167 "", |
| 162 &host_settings); | 168 &host_settings); |
| 163 EXPECT_EQ(0U, host_settings.size()); | 169 EXPECT_EQ(0U, host_settings.size()); |
| 164 host_content_settings_map->ResetToDefaults(); | 170 host_content_settings_map->ResetToDefaults(); |
| 165 host_content_settings_map->GetSettingsForOneType( | 171 host_content_settings_map->GetSettingsForOneType( |
| 166 CONTENT_SETTINGS_TYPE_PLUGINS, &host_settings); | 172 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); |
| 167 EXPECT_EQ(0U, host_settings.size()); | 173 EXPECT_EQ(0U, host_settings.size()); |
| 168 | 174 |
| 169 // Check clearing one type. | 175 // Check clearing one type. |
| 170 HostContentSettingsMap::Pattern pattern3("[*.]example.net"); | 176 HostContentSettingsMap::Pattern pattern3("[*.]example.net"); |
| 171 host_content_settings_map->SetContentSetting(pattern, | 177 host_content_settings_map->SetContentSetting(pattern, |
| 172 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 178 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 173 host_content_settings_map->SetContentSetting(pattern2, | 179 host_content_settings_map->SetContentSetting(pattern2, |
| 174 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 180 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 175 host_content_settings_map->SetContentSetting(pattern2, | 181 host_content_settings_map->SetContentSetting(pattern2, |
| 176 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 182 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); |
| 177 host_content_settings_map->SetContentSetting(pattern3, | 183 host_content_settings_map->SetContentSetting(pattern3, |
| 178 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 184 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 179 host_content_settings_map->ClearSettingsForOneType( | 185 host_content_settings_map->ClearSettingsForOneType( |
| 180 CONTENT_SETTINGS_TYPE_IMAGES); | 186 CONTENT_SETTINGS_TYPE_IMAGES); |
| 181 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, | 187 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, |
| 188 "", |
| 182 &host_settings); | 189 &host_settings); |
| 183 EXPECT_EQ(0U, host_settings.size()); | 190 EXPECT_EQ(0U, host_settings.size()); |
| 184 host_content_settings_map->GetSettingsForOneType( | 191 host_content_settings_map->GetSettingsForOneType( |
| 185 CONTENT_SETTINGS_TYPE_PLUGINS, &host_settings); | 192 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); |
| 186 EXPECT_EQ(1U, host_settings.size()); | 193 EXPECT_EQ(1U, host_settings.size()); |
| 187 } | 194 } |
| 188 | 195 |
| 189 TEST_F(HostContentSettingsMapTest, Patterns) { | 196 TEST_F(HostContentSettingsMapTest, Patterns) { |
| 190 TestingProfile profile; | 197 TestingProfile profile; |
| 191 HostContentSettingsMap* host_content_settings_map = | 198 HostContentSettingsMap* host_content_settings_map = |
| 192 profile.GetHostContentSettingsMap(); | 199 profile.GetHostContentSettingsMap(); |
| 193 | 200 |
| 194 GURL host1("http://example.com/"); | 201 GURL host1("http://example.com/"); |
| 195 GURL host2("http://www.example.com/"); | 202 GURL host2("http://www.example.com/"); |
| 196 GURL host3("http://example.org/"); | 203 GURL host3("http://example.org/"); |
| 197 HostContentSettingsMap::Pattern pattern1("[*.]example.com"); | 204 HostContentSettingsMap::Pattern pattern1("[*.]example.com"); |
| 198 HostContentSettingsMap::Pattern pattern2("example.org"); | 205 HostContentSettingsMap::Pattern pattern2("example.org"); |
| 199 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 206 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 200 host_content_settings_map->GetContentSetting( | 207 host_content_settings_map->GetContentSetting( |
| 201 host1, CONTENT_SETTINGS_TYPE_IMAGES)); | 208 host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 202 host_content_settings_map->SetContentSetting(pattern1, | 209 host_content_settings_map->SetContentSetting(pattern1, |
| 203 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 210 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 204 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 211 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 205 host_content_settings_map->GetContentSetting( | 212 host_content_settings_map->GetContentSetting( |
| 206 host1, CONTENT_SETTINGS_TYPE_IMAGES)); | 213 host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 207 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 214 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 208 host_content_settings_map->GetContentSetting( | 215 host_content_settings_map->GetContentSetting( |
| 209 host2, CONTENT_SETTINGS_TYPE_IMAGES)); | 216 host2, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 210 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 217 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 211 host_content_settings_map->GetContentSetting( | 218 host_content_settings_map->GetContentSetting( |
| 212 host3, CONTENT_SETTINGS_TYPE_IMAGES)); | 219 host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 213 host_content_settings_map->SetContentSetting(pattern2, | 220 host_content_settings_map->SetContentSetting(pattern2, |
| 214 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 221 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 215 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 222 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 216 host_content_settings_map->GetContentSetting( | 223 host_content_settings_map->GetContentSetting( |
| 217 host3, CONTENT_SETTINGS_TYPE_IMAGES)); | 224 host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 218 } | 225 } |
| 219 | 226 |
| 220 TEST_F(HostContentSettingsMapTest, PatternSupport) { | 227 TEST_F(HostContentSettingsMapTest, PatternSupport) { |
| 221 EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").IsValid()); | 228 EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").IsValid()); |
| 222 EXPECT_TRUE(HostContentSettingsMap::Pattern("example.com").IsValid()); | 229 EXPECT_TRUE(HostContentSettingsMap::Pattern("example.com").IsValid()); |
| 223 EXPECT_TRUE(HostContentSettingsMap::Pattern("192.168.0.1").IsValid()); | 230 EXPECT_TRUE(HostContentSettingsMap::Pattern("192.168.0.1").IsValid()); |
| 224 EXPECT_TRUE(HostContentSettingsMap::Pattern("[::1]").IsValid()); | 231 EXPECT_TRUE(HostContentSettingsMap::Pattern("[::1]").IsValid()); |
| 225 EXPECT_FALSE(HostContentSettingsMap::Pattern("*example.com").IsValid()); | 232 EXPECT_FALSE(HostContentSettingsMap::Pattern("*example.com").IsValid()); |
| 226 EXPECT_FALSE(HostContentSettingsMap::Pattern("example.*").IsValid()); | 233 EXPECT_FALSE(HostContentSettingsMap::Pattern("example.*").IsValid()); |
| 227 EXPECT_FALSE(HostContentSettingsMap::Pattern("http://example.com").IsValid()); | 234 EXPECT_FALSE(HostContentSettingsMap::Pattern("http://example.com").IsValid()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 241 } | 248 } |
| 242 | 249 |
| 243 TEST_F(HostContentSettingsMapTest, Observer) { | 250 TEST_F(HostContentSettingsMapTest, Observer) { |
| 244 TestingProfile profile; | 251 TestingProfile profile; |
| 245 HostContentSettingsMap* host_content_settings_map = | 252 HostContentSettingsMap* host_content_settings_map = |
| 246 profile.GetHostContentSettingsMap(); | 253 profile.GetHostContentSettingsMap(); |
| 247 StubSettingsObserver observer; | 254 StubSettingsObserver observer; |
| 248 | 255 |
| 249 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 256 HostContentSettingsMap::Pattern pattern("[*.]example.com"); |
| 250 host_content_settings_map->SetContentSetting(pattern, | 257 host_content_settings_map->SetContentSetting(pattern, |
| 251 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_ALLOW); | 258 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW); |
| 252 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | 259 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 253 EXPECT_EQ(pattern, observer.last_pattern); | 260 EXPECT_EQ(pattern, observer.last_pattern); |
| 254 EXPECT_FALSE(observer.last_update_all); | 261 EXPECT_FALSE(observer.last_update_all); |
| 255 EXPECT_FALSE(observer.last_update_all_types); | 262 EXPECT_FALSE(observer.last_update_all_types); |
| 256 EXPECT_EQ(1, observer.counter); | 263 EXPECT_EQ(1, observer.counter); |
| 257 | 264 |
| 258 host_content_settings_map->ClearSettingsForOneType( | 265 host_content_settings_map->ClearSettingsForOneType( |
| 259 CONTENT_SETTINGS_TYPE_IMAGES); | 266 CONTENT_SETTINGS_TYPE_IMAGES); |
| 260 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | 267 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 261 EXPECT_TRUE(observer.last_update_all); | 268 EXPECT_TRUE(observer.last_update_all); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 286 // Make a copy of the default pref value so we can reset it later. | 293 // Make a copy of the default pref value so we can reset it later. |
| 287 scoped_ptr<Value> default_value(prefs->FindPreference( | 294 scoped_ptr<Value> default_value(prefs->FindPreference( |
| 288 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 295 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
| 289 | 296 |
| 290 GURL host("http://example.com"); | 297 GURL host("http://example.com"); |
| 291 | 298 |
| 292 host_content_settings_map->SetDefaultContentSetting( | 299 host_content_settings_map->SetDefaultContentSetting( |
| 293 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 300 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| 294 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 301 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 295 host_content_settings_map->GetContentSetting( | 302 host_content_settings_map->GetContentSetting( |
| 296 host, CONTENT_SETTINGS_TYPE_COOKIES)); | 303 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 297 | 304 |
| 298 // Make a copy of the pref's new value so we can reset it later. | 305 // Make a copy of the pref's new value so we can reset it later. |
| 299 scoped_ptr<Value> new_value(prefs->FindPreference( | 306 scoped_ptr<Value> new_value(prefs->FindPreference( |
| 300 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); | 307 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); |
| 301 | 308 |
| 302 // Clearing the backing pref should also clear the internal cache. | 309 // Clearing the backing pref should also clear the internal cache. |
| 303 prefs->Set(prefs::kDefaultContentSettings, *default_value); | 310 prefs->Set(prefs::kDefaultContentSettings, *default_value); |
| 304 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 311 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 305 host_content_settings_map->GetContentSetting( | 312 host_content_settings_map->GetContentSetting( |
| 306 host, CONTENT_SETTINGS_TYPE_COOKIES)); | 313 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 307 | 314 |
| 308 // Reseting the pref to its previous value should update the cache. | 315 // Reseting the pref to its previous value should update the cache. |
| 309 prefs->Set(prefs::kDefaultContentSettings, *new_value); | 316 prefs->Set(prefs::kDefaultContentSettings, *new_value); |
| 310 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 317 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 311 host_content_settings_map->GetContentSetting( | 318 host_content_settings_map->GetContentSetting( |
| 312 host, CONTENT_SETTINGS_TYPE_COOKIES)); | 319 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 313 } | 320 } |
| 314 | 321 |
| 315 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { | 322 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { |
| 316 TestingProfile profile; | 323 TestingProfile profile; |
| 317 HostContentSettingsMap* host_content_settings_map = | 324 HostContentSettingsMap* host_content_settings_map = |
| 318 profile.GetHostContentSettingsMap(); | 325 profile.GetHostContentSettingsMap(); |
| 319 | 326 |
| 320 PrefService* prefs = profile.GetPrefs(); | 327 PrefService* prefs = profile.GetPrefs(); |
| 321 | 328 |
| 322 // Make a copy of the default pref value so we can reset it later. | 329 // Make a copy of the default pref value so we can reset it later. |
| 323 scoped_ptr<Value> default_value(prefs->FindPreference( | 330 scoped_ptr<Value> default_value(prefs->FindPreference( |
| 324 prefs::kContentSettingsPatterns)->GetValue()->DeepCopy()); | 331 prefs::kContentSettingsPatterns)->GetValue()->DeepCopy()); |
| 325 | 332 |
| 326 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 333 HostContentSettingsMap::Pattern pattern("[*.]example.com"); |
| 327 GURL host("http://example.com"); | 334 GURL host("http://example.com"); |
| 328 | 335 |
| 329 host_content_settings_map->SetContentSetting(pattern, | 336 host_content_settings_map->SetContentSetting(pattern, |
| 330 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 337 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); |
| 331 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 338 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 332 host_content_settings_map->GetContentSetting( | 339 host_content_settings_map->GetContentSetting( |
| 333 host, CONTENT_SETTINGS_TYPE_COOKIES)); | 340 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 334 | 341 |
| 335 // Make a copy of the pref's new value so we can reset it later. | 342 // Make a copy of the pref's new value so we can reset it later. |
| 336 scoped_ptr<Value> new_value(prefs->FindPreference( | 343 scoped_ptr<Value> new_value(prefs->FindPreference( |
| 337 prefs::kContentSettingsPatterns)->GetValue()->DeepCopy()); | 344 prefs::kContentSettingsPatterns)->GetValue()->DeepCopy()); |
| 338 | 345 |
| 339 // Clearing the backing pref should also clear the internal cache. | 346 // Clearing the backing pref should also clear the internal cache. |
| 340 prefs->Set(prefs::kContentSettingsPatterns, *default_value); | 347 prefs->Set(prefs::kContentSettingsPatterns, *default_value); |
| 341 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 348 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 342 host_content_settings_map->GetContentSetting( | 349 host_content_settings_map->GetContentSetting( |
| 343 host, CONTENT_SETTINGS_TYPE_COOKIES)); | 350 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 344 | 351 |
| 345 // Reseting the pref to its previous value should update the cache. | 352 // Reseting the pref to its previous value should update the cache. |
| 346 prefs->Set(prefs::kContentSettingsPatterns, *new_value); | 353 prefs->Set(prefs::kContentSettingsPatterns, *new_value); |
| 347 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 354 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 348 host_content_settings_map->GetContentSetting( | 355 host_content_settings_map->GetContentSetting( |
| 349 host, CONTENT_SETTINGS_TYPE_COOKIES)); | 356 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 350 } | 357 } |
| 351 | 358 |
| 352 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { | 359 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { |
| 353 TestingProfile profile; | 360 TestingProfile profile; |
| 354 HostContentSettingsMap* host_content_settings_map = | 361 HostContentSettingsMap* host_content_settings_map = |
| 355 profile.GetHostContentSettingsMap(); | 362 profile.GetHostContentSettingsMap(); |
| 356 | 363 |
| 357 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 364 HostContentSettingsMap::Pattern pattern("[*.]example.com"); |
| 358 GURL host_ending_with_dot("http://example.com./"); | 365 GURL host_ending_with_dot("http://example.com./"); |
| 359 | 366 |
| 360 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 367 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 361 host_content_settings_map->GetContentSetting( | 368 host_content_settings_map->GetContentSetting( |
| 362 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES)); | 369 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 363 host_content_settings_map->SetContentSetting(pattern, | 370 host_content_settings_map->SetContentSetting(pattern, |
| 364 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_DEFAULT); | 371 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); |
| 365 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 372 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 366 host_content_settings_map->GetContentSetting( | 373 host_content_settings_map->GetContentSetting( |
| 367 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES)); | 374 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 368 host_content_settings_map->SetContentSetting(pattern, | 375 host_content_settings_map->SetContentSetting(pattern, |
| 369 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 376 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 370 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 377 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 371 host_content_settings_map->GetContentSetting( | 378 host_content_settings_map->GetContentSetting( |
| 372 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES)); | 379 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 373 | 380 |
| 374 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 381 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 375 host_content_settings_map->GetContentSetting( | 382 host_content_settings_map->GetContentSetting( |
| 376 host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES)); | 383 host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 377 host_content_settings_map->SetContentSetting(pattern, | 384 host_content_settings_map->SetContentSetting(pattern, |
| 378 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_DEFAULT); | 385 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_DEFAULT); |
| 379 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 386 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 380 host_content_settings_map->GetContentSetting( | 387 host_content_settings_map->GetContentSetting( |
| 381 host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES)); | 388 host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 382 host_content_settings_map->SetContentSetting(pattern, | 389 host_content_settings_map->SetContentSetting(pattern, |
| 383 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 390 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); |
| 384 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 391 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 385 host_content_settings_map->GetContentSetting( | 392 host_content_settings_map->GetContentSetting( |
| 386 host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES)); | 393 host_ending_with_dot, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 387 | 394 |
| 388 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 395 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 389 host_content_settings_map->GetContentSetting( | 396 host_content_settings_map->GetContentSetting( |
| 390 host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 397 host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); |
| 391 host_content_settings_map->SetContentSetting(pattern, | 398 host_content_settings_map->SetContentSetting(pattern, |
| 392 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_DEFAULT); | 399 CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_DEFAULT); |
| 393 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 400 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 394 host_content_settings_map->GetContentSetting( | 401 host_content_settings_map->GetContentSetting( |
| 395 host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 402 host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); |
| 396 host_content_settings_map->SetContentSetting(pattern, | 403 host_content_settings_map->SetContentSetting(pattern, |
| 397 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 404 CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_BLOCK); |
| 398 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 405 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 399 host_content_settings_map->GetContentSetting( | 406 host_content_settings_map->GetContentSetting( |
| 400 host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 407 host_ending_with_dot, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); |
| 401 | 408 |
| 402 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 409 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 403 host_content_settings_map->GetContentSetting( | 410 host_content_settings_map->GetContentSetting( |
| 404 host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS)); | 411 host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS, "")); |
| 405 host_content_settings_map->SetContentSetting(pattern, | 412 host_content_settings_map->SetContentSetting(pattern, |
| 406 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_DEFAULT); | 413 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_DEFAULT); |
| 407 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 414 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 408 host_content_settings_map->GetContentSetting( | 415 host_content_settings_map->GetContentSetting( |
| 409 host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS)); | 416 host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS, "")); |
| 410 host_content_settings_map->SetContentSetting(pattern, | 417 host_content_settings_map->SetContentSetting(pattern, |
| 411 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 418 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); |
| 412 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 419 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 413 host_content_settings_map->GetContentSetting( | 420 host_content_settings_map->GetContentSetting( |
| 414 host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS)); | 421 host_ending_with_dot, CONTENT_SETTINGS_TYPE_PLUGINS, "")); |
| 415 | 422 |
| 416 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 423 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 417 host_content_settings_map->GetContentSetting( | 424 host_content_settings_map->GetContentSetting( |
| 418 host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS)); | 425 host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS, "")); |
| 419 host_content_settings_map->SetContentSetting(pattern, | 426 host_content_settings_map->SetContentSetting(pattern, |
| 420 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_DEFAULT); | 427 CONTENT_SETTINGS_TYPE_POPUPS, "", CONTENT_SETTING_DEFAULT); |
| 421 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 428 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 422 host_content_settings_map->GetContentSetting( | 429 host_content_settings_map->GetContentSetting( |
| 423 host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS)); | 430 host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS, "")); |
| 424 host_content_settings_map->SetContentSetting(pattern, | 431 host_content_settings_map->SetContentSetting(pattern, |
| 425 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); | 432 CONTENT_SETTINGS_TYPE_POPUPS, "", CONTENT_SETTING_ALLOW); |
| 426 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 433 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 427 host_content_settings_map->GetContentSetting( | 434 host_content_settings_map->GetContentSetting( |
| 428 host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS)); | 435 host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS, "")); |
| 429 } | 436 } |
| 430 | 437 |
| 431 TEST_F(HostContentSettingsMapTest, NestedSettings) { | 438 TEST_F(HostContentSettingsMapTest, NestedSettings) { |
| 432 TestingProfile profile; | 439 TestingProfile profile; |
| 433 HostContentSettingsMap* host_content_settings_map = | 440 HostContentSettingsMap* host_content_settings_map = |
| 434 profile.GetHostContentSettingsMap(); | 441 profile.GetHostContentSettingsMap(); |
| 435 | 442 |
| 436 GURL host("http://a.b.example.com/"); | 443 GURL host("http://a.b.example.com/"); |
| 437 HostContentSettingsMap::Pattern pattern1("[*.]example.com"); | 444 HostContentSettingsMap::Pattern pattern1("[*.]example.com"); |
| 438 HostContentSettingsMap::Pattern pattern2("[*.]b.example.com"); | 445 HostContentSettingsMap::Pattern pattern2("[*.]b.example.com"); |
| 439 HostContentSettingsMap::Pattern pattern3("a.b.example.com"); | 446 HostContentSettingsMap::Pattern pattern3("a.b.example.com"); |
| 440 | 447 |
| 441 host_content_settings_map->SetContentSetting(pattern1, | 448 host_content_settings_map->SetContentSetting(pattern1, |
| 442 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 449 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 443 host_content_settings_map->SetContentSetting(pattern2, | 450 host_content_settings_map->SetContentSetting(pattern2, |
| 444 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 451 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); |
| 445 host_content_settings_map->SetContentSetting(pattern3, | 452 host_content_settings_map->SetContentSetting(pattern3, |
| 446 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); | 453 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); |
| 447 host_content_settings_map->SetDefaultContentSetting( | 454 host_content_settings_map->SetDefaultContentSetting( |
| 448 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 455 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
| 449 | 456 |
| 450 ContentSettings desired_settings; | 457 ContentSettings desired_settings; |
| 451 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES] = | 458 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES] = |
| 452 CONTENT_SETTING_BLOCK; | 459 CONTENT_SETTING_BLOCK; |
| 453 desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = | 460 desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = |
| 454 CONTENT_SETTING_BLOCK; | 461 CONTENT_SETTING_BLOCK; |
| 455 desired_settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] = | 462 desired_settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] = |
| 456 CONTENT_SETTING_BLOCK; | 463 CONTENT_SETTING_BLOCK; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 486 profile.set_off_the_record(true); | 493 profile.set_off_the_record(true); |
| 487 scoped_refptr<HostContentSettingsMap> otr_map = | 494 scoped_refptr<HostContentSettingsMap> otr_map = |
| 488 new HostContentSettingsMap(&profile); | 495 new HostContentSettingsMap(&profile); |
| 489 profile.set_off_the_record(false); | 496 profile.set_off_the_record(false); |
| 490 | 497 |
| 491 GURL host("http://example.com/"); | 498 GURL host("http://example.com/"); |
| 492 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 499 HostContentSettingsMap::Pattern pattern("[*.]example.com"); |
| 493 | 500 |
| 494 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 501 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 495 host_content_settings_map->GetContentSetting( | 502 host_content_settings_map->GetContentSetting( |
| 496 host, CONTENT_SETTINGS_TYPE_IMAGES)); | 503 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 497 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 504 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 498 otr_map->GetContentSetting( | 505 otr_map->GetContentSetting( |
| 499 host, CONTENT_SETTINGS_TYPE_IMAGES)); | 506 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 500 | 507 |
| 501 // Changing content settings on the main map should also affect the | 508 // Changing content settings on the main map should also affect the |
| 502 // off-the-record map. | 509 // off-the-record map. |
| 503 host_content_settings_map->SetContentSetting(pattern, | 510 host_content_settings_map->SetContentSetting(pattern, |
| 504 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 511 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 505 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 512 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 506 host_content_settings_map->GetContentSetting( | 513 host_content_settings_map->GetContentSetting( |
| 507 host, CONTENT_SETTINGS_TYPE_IMAGES)); | 514 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 508 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 515 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 509 otr_map->GetContentSetting( | 516 otr_map->GetContentSetting( |
| 510 host, CONTENT_SETTINGS_TYPE_IMAGES)); | 517 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 511 | 518 |
| 512 // Changing content settings on the off-the-record map should NOT affect the | 519 // Changing content settings on the off-the-record map should NOT affect the |
| 513 // main map. | 520 // main map. |
| 514 otr_map->SetContentSetting(pattern, | 521 otr_map->SetContentSetting(pattern, |
| 515 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_ALLOW); | 522 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW); |
| 516 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 523 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 517 host_content_settings_map->GetContentSetting( | 524 host_content_settings_map->GetContentSetting( |
| 518 host, CONTENT_SETTINGS_TYPE_IMAGES)); | 525 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 519 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 526 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 520 otr_map->GetContentSetting( | 527 otr_map->GetContentSetting( |
| 521 host, CONTENT_SETTINGS_TYPE_IMAGES)); | 528 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 522 } | 529 } |
| 523 | 530 |
| 531 TEST_F(HostContentSettingsMapTest, NonDefaultSettings) { |
| 532 TestingProfile profile; |
| 533 HostContentSettingsMap* host_content_settings_map = |
| 534 profile.GetHostContentSettingsMap(); |
| 535 |
| 536 GURL host("http://example.com/"); |
| 537 HostContentSettingsMap::Pattern pattern("[*.]example.com"); |
| 538 |
| 539 ContentSettings desired_settings(CONTENT_SETTING_DEFAULT); |
| 540 ContentSettings settings = |
| 541 host_content_settings_map->GetNonDefaultContentSettings(host); |
| 542 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
| 543 |
| 544 host_content_settings_map->SetContentSetting(pattern, |
| 545 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 546 desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = |
| 547 CONTENT_SETTING_BLOCK; |
| 548 settings = |
| 549 host_content_settings_map->GetNonDefaultContentSettings(host); |
| 550 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
| 551 } |
| 552 |
| 553 // TODO(bauerb): Enable once HostContentSettingsMap::RequiersResourceIdentifier |
| 554 // is changed. |
| 555 #if 0 |
| 556 TEST_F(HostContentSettingsMapTest, ResourceIdentifier) { |
| 557 // This feature is currently behind a flag. |
| 558 CommandLine cl(*CommandLine::ForCurrentProcess()); |
| 559 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableClickToPlay); |
| 560 |
| 561 TestingProfile profile; |
| 562 HostContentSettingsMap* host_content_settings_map = |
| 563 profile.GetHostContentSettingsMap(); |
| 564 |
| 565 GURL host("http://example.com/"); |
| 566 HostContentSettingsMap::Pattern pattern("[*.]example.com"); |
| 567 std::string resource1("someplugin"); |
| 568 std::string resource2("otherplugin"); |
| 569 |
| 570 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 571 host_content_settings_map->GetContentSetting( |
| 572 host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); |
| 573 host_content_settings_map->SetContentSetting(pattern, |
| 574 CONTENT_SETTINGS_TYPE_PLUGINS, resource1, CONTENT_SETTING_BLOCK); |
| 575 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 576 host_content_settings_map->GetContentSetting( |
| 577 host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); |
| 578 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 579 host_content_settings_map->GetContentSetting( |
| 580 host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2)); |
| 581 *CommandLine::ForCurrentProcess() = cl; |
| 582 } |
| 583 |
| 584 TEST_F(HostContentSettingsMapTest, ResourceIdentifierPrefs) { |
| 585 // This feature is currently behind a flag. |
| 586 CommandLine cl(*CommandLine::ForCurrentProcess()); |
| 587 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kEnableClickToPlay); |
| 588 |
| 589 TestingProfile profile; |
| 590 profile.GetPrefs()->SetUserPref(prefs::kContentSettingsPatterns, |
| 591 base::JSONReader::Read( |
| 592 "{\"[*.]example.com\":{\"per_plugin\":{\"someplugin\":2}}}", false)); |
| 593 HostContentSettingsMap* host_content_settings_map = |
| 594 profile.GetHostContentSettingsMap(); |
| 595 |
| 596 GURL host("http://example.com/"); |
| 597 HostContentSettingsMap::Pattern pattern("[*.]example.com"); |
| 598 std::string resource1("someplugin"); |
| 599 std::string resource2("otherplugin"); |
| 600 |
| 601 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 602 host_content_settings_map->GetContentSetting( |
| 603 host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); |
| 604 |
| 605 host_content_settings_map->SetContentSetting(pattern, |
| 606 CONTENT_SETTINGS_TYPE_PLUGINS, resource1, CONTENT_SETTING_DEFAULT); |
| 607 |
| 608 const DictionaryValue* content_setting_prefs = |
| 609 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatterns); |
| 610 std::string prefs_as_json; |
| 611 base::JSONWriter::Write(content_setting_prefs, false, &prefs_as_json); |
| 612 EXPECT_STREQ("{}", prefs_as_json.c_str()); |
| 613 |
| 614 host_content_settings_map->SetContentSetting(pattern, |
| 615 CONTENT_SETTINGS_TYPE_PLUGINS, resource2, CONTENT_SETTING_BLOCK); |
| 616 |
| 617 content_setting_prefs = |
| 618 profile.GetPrefs()->GetDictionary(prefs::kContentSettingsPatterns); |
| 619 base::JSONWriter::Write(content_setting_prefs, false, &prefs_as_json); |
| 620 EXPECT_STREQ("{\"[*.]example.com\":{\"per_plugin\":{\"otherplugin\":2}}}", |
| 621 prefs_as_json.c_str()); |
| 622 *CommandLine::ForCurrentProcess() = cl; |
| 623 } |
| 624 #endif |
| 625 |
| 524 } // namespace | 626 } // namespace |
| OLD | NEW |