| 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/content_settings/host_content_settings_map.h" | 5 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| 11 #include "chrome/browser/content_settings/content_settings_details.h" |
| 11 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
| 12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/notification_registrar.h" | 14 #include "chrome/common/notification_registrar.h" |
| 14 #include "chrome/common/notification_service.h" | 15 #include "chrome/common/notification_service.h" |
| 15 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/test/testing_pref_service.h" | 18 #include "chrome/test/testing_pref_service.h" |
| 18 #include "chrome/test/testing_profile.h" | 19 #include "chrome/test/testing_profile.h" |
| 19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| 20 #include "net/base/static_cookie_policy.h" | 21 #include "net/base/static_cookie_policy.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 37 StubSettingsObserver() : last_notifier(NULL), counter(0) { | 38 StubSettingsObserver() : last_notifier(NULL), counter(0) { |
| 38 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED, | 39 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED, |
| 39 NotificationService::AllSources()); | 40 NotificationService::AllSources()); |
| 40 } | 41 } |
| 41 | 42 |
| 42 virtual void Observe(NotificationType type, | 43 virtual void Observe(NotificationType type, |
| 43 const NotificationSource& source, | 44 const NotificationSource& source, |
| 44 const NotificationDetails& details) { | 45 const NotificationDetails& details) { |
| 45 ++counter; | 46 ++counter; |
| 46 Source<HostContentSettingsMap> content_settings(source); | 47 Source<HostContentSettingsMap> content_settings(source); |
| 47 Details<HostContentSettingsMap::ContentSettingsDetails> | 48 Details<ContentSettingsDetails> settings_details(details); |
| 48 settings_details(details); | |
| 49 last_notifier = content_settings.ptr(); | 49 last_notifier = content_settings.ptr(); |
| 50 last_pattern = settings_details.ptr()->pattern(); | 50 last_pattern = settings_details.ptr()->pattern(); |
| 51 last_update_all = settings_details.ptr()->update_all(); | 51 last_update_all = settings_details.ptr()->update_all(); |
| 52 last_update_all_types = settings_details.ptr()->update_all_types(); | 52 last_update_all_types = settings_details.ptr()->update_all_types(); |
| 53 last_type = settings_details.ptr()->type(); | 53 last_type = settings_details.ptr()->type(); |
| 54 // This checks that calling a Get function from an observer doesn't | 54 // This checks that calling a Get function from an observer doesn't |
| 55 // deadlock. | 55 // deadlock. |
| 56 last_notifier->GetContentSettings(GURL("http://random-hostname.com/")); | 56 last_notifier->GetContentSettings(GURL("http://random-hostname.com/")); |
| 57 } | 57 } |
| 58 | 58 |
| 59 HostContentSettingsMap* last_notifier; | 59 HostContentSettingsMap* last_notifier; |
| 60 HostContentSettingsMap::Pattern last_pattern; | 60 ContentSettingsPattern last_pattern; |
| 61 bool last_update_all; | 61 bool last_update_all; |
| 62 bool last_update_all_types; | 62 bool last_update_all_types; |
| 63 int counter; | 63 int counter; |
| 64 ContentSettingsType last_type; | 64 ContentSettingsType last_type; |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 NotificationRegistrar registrar_; | 67 NotificationRegistrar registrar_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 class HostContentSettingsMapTest : public testing::Test { | 70 class HostContentSettingsMapTest : public testing::Test { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 111 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 112 host_content_settings_map->GetDefaultContentSetting( | 112 host_content_settings_map->GetDefaultContentSetting( |
| 113 CONTENT_SETTINGS_TYPE_POPUPS)); | 113 CONTENT_SETTINGS_TYPE_POPUPS)); |
| 114 host_content_settings_map->ResetToDefaults(); | 114 host_content_settings_map->ResetToDefaults(); |
| 115 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 115 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 116 host_content_settings_map->GetDefaultContentSetting( | 116 host_content_settings_map->GetDefaultContentSetting( |
| 117 CONTENT_SETTINGS_TYPE_PLUGINS)); | 117 CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 118 | 118 |
| 119 // Check returning individual settings. | 119 // Check returning individual settings. |
| 120 GURL host("http://example.com/"); | 120 GURL host("http://example.com/"); |
| 121 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 121 ContentSettingsPattern pattern("[*.]example.com"); |
| 122 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 122 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 123 host_content_settings_map->GetContentSetting( | 123 host_content_settings_map->GetContentSetting( |
| 124 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 124 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 125 host_content_settings_map->SetContentSetting(pattern, | 125 host_content_settings_map->SetContentSetting(pattern, |
| 126 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); | 126 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); |
| 127 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 127 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 128 host_content_settings_map->GetContentSetting( | 128 host_content_settings_map->GetContentSetting( |
| 129 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 129 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 130 host_content_settings_map->SetContentSetting(pattern, | 130 host_content_settings_map->SetContentSetting(pattern, |
| 131 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 131 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 156 CONTENT_SETTING_BLOCK; | 156 CONTENT_SETTING_BLOCK; |
| 157 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = | 157 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = |
| 158 CONTENT_SETTING_ASK; | 158 CONTENT_SETTING_ASK; |
| 159 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = | 159 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = |
| 160 CONTENT_SETTING_ASK; | 160 CONTENT_SETTING_ASK; |
| 161 ContentSettings settings = | 161 ContentSettings settings = |
| 162 host_content_settings_map->GetContentSettings(host); | 162 host_content_settings_map->GetContentSettings(host); |
| 163 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); | 163 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
| 164 | 164 |
| 165 // Check returning all hosts for a setting. | 165 // Check returning all hosts for a setting. |
| 166 HostContentSettingsMap::Pattern pattern2("[*.]example.org"); | 166 ContentSettingsPattern pattern2("[*.]example.org"); |
| 167 host_content_settings_map->SetContentSetting(pattern2, | 167 host_content_settings_map->SetContentSetting(pattern2, |
| 168 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 168 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 169 host_content_settings_map->SetContentSetting(pattern2, | 169 host_content_settings_map->SetContentSetting(pattern2, |
| 170 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); | 170 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); |
| 171 HostContentSettingsMap::SettingsForOneType host_settings; | 171 HostContentSettingsMap::SettingsForOneType host_settings; |
| 172 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, | 172 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, |
| 173 "", | 173 "", |
| 174 &host_settings); | 174 &host_settings); |
| 175 EXPECT_EQ(1U, host_settings.size()); | 175 EXPECT_EQ(1U, host_settings.size()); |
| 176 host_content_settings_map->GetSettingsForOneType( | 176 host_content_settings_map->GetSettingsForOneType( |
| 177 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); | 177 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); |
| 178 EXPECT_EQ(2U, host_settings.size()); | 178 EXPECT_EQ(2U, host_settings.size()); |
| 179 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, | 179 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
| 180 "", | 180 "", |
| 181 &host_settings); | 181 &host_settings); |
| 182 EXPECT_EQ(0U, host_settings.size()); | 182 EXPECT_EQ(0U, host_settings.size()); |
| 183 host_content_settings_map->ResetToDefaults(); | 183 host_content_settings_map->ResetToDefaults(); |
| 184 host_content_settings_map->GetSettingsForOneType( | 184 host_content_settings_map->GetSettingsForOneType( |
| 185 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); | 185 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); |
| 186 EXPECT_EQ(0U, host_settings.size()); | 186 EXPECT_EQ(0U, host_settings.size()); |
| 187 | 187 |
| 188 // Check clearing one type. | 188 // Check clearing one type. |
| 189 HostContentSettingsMap::Pattern pattern3("[*.]example.net"); | 189 ContentSettingsPattern pattern3("[*.]example.net"); |
| 190 host_content_settings_map->SetContentSetting(pattern, | 190 host_content_settings_map->SetContentSetting(pattern, |
| 191 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 191 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 192 host_content_settings_map->SetContentSetting(pattern2, | 192 host_content_settings_map->SetContentSetting(pattern2, |
| 193 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 193 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 194 host_content_settings_map->SetContentSetting(pattern2, | 194 host_content_settings_map->SetContentSetting(pattern2, |
| 195 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); | 195 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); |
| 196 host_content_settings_map->SetContentSetting(pattern3, | 196 host_content_settings_map->SetContentSetting(pattern3, |
| 197 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 197 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 198 host_content_settings_map->ClearSettingsForOneType( | 198 host_content_settings_map->ClearSettingsForOneType( |
| 199 CONTENT_SETTINGS_TYPE_IMAGES); | 199 CONTENT_SETTINGS_TYPE_IMAGES); |
| 200 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, | 200 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_IMAGES, |
| 201 "", | 201 "", |
| 202 &host_settings); | 202 &host_settings); |
| 203 EXPECT_EQ(0U, host_settings.size()); | 203 EXPECT_EQ(0U, host_settings.size()); |
| 204 host_content_settings_map->GetSettingsForOneType( | 204 host_content_settings_map->GetSettingsForOneType( |
| 205 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); | 205 CONTENT_SETTINGS_TYPE_PLUGINS, "", &host_settings); |
| 206 EXPECT_EQ(1U, host_settings.size()); | 206 EXPECT_EQ(1U, host_settings.size()); |
| 207 } | 207 } |
| 208 | 208 |
| 209 TEST_F(HostContentSettingsMapTest, Patterns) { | 209 TEST_F(HostContentSettingsMapTest, Patterns) { |
| 210 TestingProfile profile; | 210 TestingProfile profile; |
| 211 HostContentSettingsMap* host_content_settings_map = | 211 HostContentSettingsMap* host_content_settings_map = |
| 212 profile.GetHostContentSettingsMap(); | 212 profile.GetHostContentSettingsMap(); |
| 213 | 213 |
| 214 GURL host1("http://example.com/"); | 214 GURL host1("http://example.com/"); |
| 215 GURL host2("http://www.example.com/"); | 215 GURL host2("http://www.example.com/"); |
| 216 GURL host3("http://example.org/"); | 216 GURL host3("http://example.org/"); |
| 217 HostContentSettingsMap::Pattern pattern1("[*.]example.com"); | 217 ContentSettingsPattern pattern1("[*.]example.com"); |
| 218 HostContentSettingsMap::Pattern pattern2("example.org"); | 218 ContentSettingsPattern pattern2("example.org"); |
| 219 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 219 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 220 host_content_settings_map->GetContentSetting( | 220 host_content_settings_map->GetContentSetting( |
| 221 host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 221 host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 222 host_content_settings_map->SetContentSetting(pattern1, | 222 host_content_settings_map->SetContentSetting(pattern1, |
| 223 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 223 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 224 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 224 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 225 host_content_settings_map->GetContentSetting( | 225 host_content_settings_map->GetContentSetting( |
| 226 host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 226 host1, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 227 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 227 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 228 host_content_settings_map->GetContentSetting( | 228 host_content_settings_map->GetContentSetting( |
| 229 host2, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 229 host2, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 230 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 230 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 231 host_content_settings_map->GetContentSetting( | 231 host_content_settings_map->GetContentSetting( |
| 232 host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 232 host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 233 host_content_settings_map->SetContentSetting(pattern2, | 233 host_content_settings_map->SetContentSetting(pattern2, |
| 234 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 234 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 235 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 235 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 236 host_content_settings_map->GetContentSetting( | 236 host_content_settings_map->GetContentSetting( |
| 237 host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 237 host3, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 238 } | 238 } |
| 239 | 239 |
| 240 TEST_F(HostContentSettingsMapTest, PatternSupport) { | |
| 241 EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").IsValid()); | |
| 242 EXPECT_TRUE(HostContentSettingsMap::Pattern("example.com").IsValid()); | |
| 243 EXPECT_TRUE(HostContentSettingsMap::Pattern("192.168.0.1").IsValid()); | |
| 244 EXPECT_TRUE(HostContentSettingsMap::Pattern("[::1]").IsValid()); | |
| 245 EXPECT_FALSE(HostContentSettingsMap::Pattern("*example.com").IsValid()); | |
| 246 EXPECT_FALSE(HostContentSettingsMap::Pattern("example.*").IsValid()); | |
| 247 EXPECT_FALSE(HostContentSettingsMap::Pattern("http://example.com").IsValid()); | |
| 248 | |
| 249 EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").Matches( | |
| 250 GURL("http://example.com/"))); | |
| 251 EXPECT_TRUE(HostContentSettingsMap::Pattern("[*.]example.com").Matches( | |
| 252 GURL("http://www.example.com/"))); | |
| 253 EXPECT_TRUE(HostContentSettingsMap::Pattern("www.example.com").Matches( | |
| 254 GURL("http://www.example.com/"))); | |
| 255 EXPECT_FALSE(HostContentSettingsMap::Pattern("").Matches( | |
| 256 GURL("http://www.example.com/"))); | |
| 257 EXPECT_FALSE(HostContentSettingsMap::Pattern("[*.]example.com").Matches( | |
| 258 GURL("http://example.org/"))); | |
| 259 EXPECT_FALSE(HostContentSettingsMap::Pattern("example.com").Matches( | |
| 260 GURL("http://example.org/"))); | |
| 261 } | |
| 262 | |
| 263 TEST_F(HostContentSettingsMapTest, CanonicalizePattern) { | |
| 264 // Basic patterns. | |
| 265 EXPECT_STREQ("[*.]ikea.com", HostContentSettingsMap::Pattern("[*.]ikea.com") | |
| 266 .CanonicalizePattern().c_str()); | |
| 267 EXPECT_STREQ("example.com", HostContentSettingsMap::Pattern("example.com") | |
| 268 .CanonicalizePattern().c_str()); | |
| 269 EXPECT_STREQ("192.168.1.1", HostContentSettingsMap::Pattern("192.168.1.1") | |
| 270 .CanonicalizePattern().c_str()); | |
| 271 EXPECT_STREQ("[::1]", HostContentSettingsMap::Pattern("[::1]") | |
| 272 .CanonicalizePattern().c_str()); | |
| 273 // IsValid returns false for file:/// patterns. | |
| 274 EXPECT_STREQ("", HostContentSettingsMap::Pattern( | |
| 275 "file:///temp/file.html").CanonicalizePattern().c_str()); | |
| 276 | |
| 277 // UTF-8 patterns. | |
| 278 EXPECT_STREQ("[*.]xn--ira-ppa.com", HostContentSettingsMap::Pattern( | |
| 279 "[*.]\xC4\x87ira.com").CanonicalizePattern().c_str()); | |
| 280 EXPECT_STREQ("xn--ira-ppa.com", HostContentSettingsMap::Pattern( | |
| 281 "\xC4\x87ira.com").CanonicalizePattern().c_str()); | |
| 282 // IsValid returns false for file:/// patterns. | |
| 283 EXPECT_STREQ("", HostContentSettingsMap::Pattern( | |
| 284 "file:///\xC4\x87ira.html").CanonicalizePattern().c_str()); | |
| 285 | |
| 286 // Invalid patterns. | |
| 287 EXPECT_STREQ("", HostContentSettingsMap::Pattern( | |
| 288 "*example.com").CanonicalizePattern().c_str()); | |
| 289 EXPECT_STREQ("", HostContentSettingsMap::Pattern( | |
| 290 "example.*").CanonicalizePattern().c_str()); | |
| 291 EXPECT_STREQ("", HostContentSettingsMap::Pattern( | |
| 292 "*\xC4\x87ira.com").CanonicalizePattern().c_str()); | |
| 293 EXPECT_STREQ("", HostContentSettingsMap::Pattern( | |
| 294 "\xC4\x87ira.*").CanonicalizePattern().c_str()); | |
| 295 } | |
| 296 | |
| 297 TEST_F(HostContentSettingsMapTest, Observer) { | 240 TEST_F(HostContentSettingsMapTest, Observer) { |
| 298 TestingProfile profile; | 241 TestingProfile profile; |
| 299 HostContentSettingsMap* host_content_settings_map = | 242 HostContentSettingsMap* host_content_settings_map = |
| 300 profile.GetHostContentSettingsMap(); | 243 profile.GetHostContentSettingsMap(); |
| 301 StubSettingsObserver observer; | 244 StubSettingsObserver observer; |
| 302 | 245 |
| 303 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 246 ContentSettingsPattern pattern("[*.]example.com"); |
| 304 host_content_settings_map->SetContentSetting(pattern, | 247 host_content_settings_map->SetContentSetting(pattern, |
| 305 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW); | 248 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_ALLOW); |
| 306 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | 249 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 307 EXPECT_EQ(pattern, observer.last_pattern); | 250 EXPECT_EQ(pattern, observer.last_pattern); |
| 308 EXPECT_FALSE(observer.last_update_all); | 251 EXPECT_FALSE(observer.last_update_all); |
| 309 EXPECT_FALSE(observer.last_update_all_types); | 252 EXPECT_FALSE(observer.last_update_all_types); |
| 310 EXPECT_EQ(1, observer.counter); | 253 EXPECT_EQ(1, observer.counter); |
| 311 | 254 |
| 312 host_content_settings_map->ClearSettingsForOneType( | 255 host_content_settings_map->ClearSettingsForOneType( |
| 313 CONTENT_SETTINGS_TYPE_IMAGES); | 256 CONTENT_SETTINGS_TYPE_IMAGES); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 TestingProfile profile; | 313 TestingProfile profile; |
| 371 HostContentSettingsMap* host_content_settings_map = | 314 HostContentSettingsMap* host_content_settings_map = |
| 372 profile.GetHostContentSettingsMap(); | 315 profile.GetHostContentSettingsMap(); |
| 373 | 316 |
| 374 PrefService* prefs = profile.GetPrefs(); | 317 PrefService* prefs = profile.GetPrefs(); |
| 375 | 318 |
| 376 // Make a copy of the default pref value so we can reset it later. | 319 // Make a copy of the default pref value so we can reset it later. |
| 377 scoped_ptr<Value> default_value(prefs->FindPreference( | 320 scoped_ptr<Value> default_value(prefs->FindPreference( |
| 378 prefs::kContentSettingsPatterns)->GetValue()->DeepCopy()); | 321 prefs::kContentSettingsPatterns)->GetValue()->DeepCopy()); |
| 379 | 322 |
| 380 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 323 ContentSettingsPattern pattern("[*.]example.com"); |
| 381 GURL host("http://example.com"); | 324 GURL host("http://example.com"); |
| 382 | 325 |
| 383 host_content_settings_map->SetContentSetting(pattern, | 326 host_content_settings_map->SetContentSetting(pattern, |
| 384 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); | 327 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); |
| 385 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 328 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 386 host_content_settings_map->GetContentSetting( | 329 host_content_settings_map->GetContentSetting( |
| 387 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); | 330 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 388 | 331 |
| 389 // Make a copy of the pref's new value so we can reset it later. | 332 // Make a copy of the pref's new value so we can reset it later. |
| 390 scoped_ptr<Value> new_value(prefs->FindPreference( | 333 scoped_ptr<Value> new_value(prefs->FindPreference( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 401 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 344 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 402 host_content_settings_map->GetContentSetting( | 345 host_content_settings_map->GetContentSetting( |
| 403 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); | 346 host, CONTENT_SETTINGS_TYPE_COOKIES, "")); |
| 404 } | 347 } |
| 405 | 348 |
| 406 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { | 349 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { |
| 407 TestingProfile profile; | 350 TestingProfile profile; |
| 408 HostContentSettingsMap* host_content_settings_map = | 351 HostContentSettingsMap* host_content_settings_map = |
| 409 profile.GetHostContentSettingsMap(); | 352 profile.GetHostContentSettingsMap(); |
| 410 | 353 |
| 411 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 354 ContentSettingsPattern pattern("[*.]example.com"); |
| 412 GURL host_ending_with_dot("http://example.com./"); | 355 GURL host_ending_with_dot("http://example.com./"); |
| 413 | 356 |
| 414 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 357 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 415 host_content_settings_map->GetContentSetting( | 358 host_content_settings_map->GetContentSetting( |
| 416 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 359 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 417 host_content_settings_map->SetContentSetting(pattern, | 360 host_content_settings_map->SetContentSetting(pattern, |
| 418 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); | 361 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_DEFAULT); |
| 419 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 362 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 420 host_content_settings_map->GetContentSetting( | 363 host_content_settings_map->GetContentSetting( |
| 421 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 364 host_ending_with_dot, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 host_content_settings_map->GetContentSetting( | 424 host_content_settings_map->GetContentSetting( |
| 482 host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS, "")); | 425 host_ending_with_dot, CONTENT_SETTINGS_TYPE_POPUPS, "")); |
| 483 } | 426 } |
| 484 | 427 |
| 485 TEST_F(HostContentSettingsMapTest, NestedSettings) { | 428 TEST_F(HostContentSettingsMapTest, NestedSettings) { |
| 486 TestingProfile profile; | 429 TestingProfile profile; |
| 487 HostContentSettingsMap* host_content_settings_map = | 430 HostContentSettingsMap* host_content_settings_map = |
| 488 profile.GetHostContentSettingsMap(); | 431 profile.GetHostContentSettingsMap(); |
| 489 | 432 |
| 490 GURL host("http://a.b.example.com/"); | 433 GURL host("http://a.b.example.com/"); |
| 491 HostContentSettingsMap::Pattern pattern1("[*.]example.com"); | 434 ContentSettingsPattern pattern1("[*.]example.com"); |
| 492 HostContentSettingsMap::Pattern pattern2("[*.]b.example.com"); | 435 ContentSettingsPattern pattern2("[*.]b.example.com"); |
| 493 HostContentSettingsMap::Pattern pattern3("a.b.example.com"); | 436 ContentSettingsPattern pattern3("a.b.example.com"); |
| 494 | 437 |
| 495 host_content_settings_map->SetContentSetting(pattern1, | 438 host_content_settings_map->SetContentSetting(pattern1, |
| 496 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 439 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 497 host_content_settings_map->SetContentSetting(pattern2, | 440 host_content_settings_map->SetContentSetting(pattern2, |
| 498 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); | 441 CONTENT_SETTINGS_TYPE_COOKIES, "", CONTENT_SETTING_BLOCK); |
| 499 host_content_settings_map->SetContentSetting(pattern3, | 442 host_content_settings_map->SetContentSetting(pattern3, |
| 500 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); | 443 CONTENT_SETTINGS_TYPE_PLUGINS, "", CONTENT_SETTING_BLOCK); |
| 501 host_content_settings_map->SetDefaultContentSetting( | 444 host_content_settings_map->SetDefaultContentSetting( |
| 502 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 445 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
| 503 | 446 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 TEST_F(HostContentSettingsMapTest, OffTheRecord) { | 479 TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
| 537 TestingProfile profile; | 480 TestingProfile profile; |
| 538 HostContentSettingsMap* host_content_settings_map = | 481 HostContentSettingsMap* host_content_settings_map = |
| 539 profile.GetHostContentSettingsMap(); | 482 profile.GetHostContentSettingsMap(); |
| 540 profile.set_off_the_record(true); | 483 profile.set_off_the_record(true); |
| 541 scoped_refptr<HostContentSettingsMap> otr_map( | 484 scoped_refptr<HostContentSettingsMap> otr_map( |
| 542 new HostContentSettingsMap(&profile)); | 485 new HostContentSettingsMap(&profile)); |
| 543 profile.set_off_the_record(false); | 486 profile.set_off_the_record(false); |
| 544 | 487 |
| 545 GURL host("http://example.com/"); | 488 GURL host("http://example.com/"); |
| 546 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 489 ContentSettingsPattern pattern("[*.]example.com"); |
| 547 | 490 |
| 548 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 491 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 549 host_content_settings_map->GetContentSetting( | 492 host_content_settings_map->GetContentSetting( |
| 550 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 493 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 551 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 494 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 552 otr_map->GetContentSetting( | 495 otr_map->GetContentSetting( |
| 553 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); | 496 host, CONTENT_SETTINGS_TYPE_IMAGES, "")); |
| 554 | 497 |
| 555 // Changing content settings on the main map should also affect the | 498 // Changing content settings on the main map should also affect the |
| 556 // off-the-record map. | 499 // off-the-record map. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 659 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com\":{\"per_plugin\":{\"pluginy\":2}}}", | 602 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com\":{\"per_plugin\":{\"pluginy\":2}}}", |
| 660 prefs_as_json.c_str()); | 603 prefs_as_json.c_str()); |
| 661 } | 604 } |
| 662 | 605 |
| 663 TEST_F(HostContentSettingsMapTest, NonDefaultSettings) { | 606 TEST_F(HostContentSettingsMapTest, NonDefaultSettings) { |
| 664 TestingProfile profile; | 607 TestingProfile profile; |
| 665 HostContentSettingsMap* host_content_settings_map = | 608 HostContentSettingsMap* host_content_settings_map = |
| 666 profile.GetHostContentSettingsMap(); | 609 profile.GetHostContentSettingsMap(); |
| 667 | 610 |
| 668 GURL host("http://example.com/"); | 611 GURL host("http://example.com/"); |
| 669 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 612 ContentSettingsPattern pattern("[*.]example.com"); |
| 670 | 613 |
| 671 ContentSettings desired_settings(CONTENT_SETTING_DEFAULT); | 614 ContentSettings desired_settings(CONTENT_SETTING_DEFAULT); |
| 672 ContentSettings settings = | 615 ContentSettings settings = |
| 673 host_content_settings_map->GetNonDefaultContentSettings(host); | 616 host_content_settings_map->GetNonDefaultContentSettings(host); |
| 674 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); | 617 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
| 675 | 618 |
| 676 host_content_settings_map->SetContentSetting(pattern, | 619 host_content_settings_map->SetContentSetting(pattern, |
| 677 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); | 620 CONTENT_SETTINGS_TYPE_IMAGES, "", CONTENT_SETTING_BLOCK); |
| 678 desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = | 621 desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = |
| 679 CONTENT_SETTING_BLOCK; | 622 CONTENT_SETTING_BLOCK; |
| 680 settings = | 623 settings = |
| 681 host_content_settings_map->GetNonDefaultContentSettings(host); | 624 host_content_settings_map->GetNonDefaultContentSettings(host); |
| 682 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); | 625 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); |
| 683 } | 626 } |
| 684 | 627 |
| 685 TEST_F(HostContentSettingsMapTest, ResourceIdentifier) { | 628 TEST_F(HostContentSettingsMapTest, ResourceIdentifier) { |
| 686 // This feature is currently behind a flag. | 629 // This feature is currently behind a flag. |
| 687 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 630 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 688 AutoReset<CommandLine> auto_reset(cmd, *cmd); | 631 AutoReset<CommandLine> auto_reset(cmd, *cmd); |
| 689 cmd->AppendSwitch(switches::kEnableResourceContentSettings); | 632 cmd->AppendSwitch(switches::kEnableResourceContentSettings); |
| 690 | 633 |
| 691 TestingProfile profile; | 634 TestingProfile profile; |
| 692 HostContentSettingsMap* host_content_settings_map = | 635 HostContentSettingsMap* host_content_settings_map = |
| 693 profile.GetHostContentSettingsMap(); | 636 profile.GetHostContentSettingsMap(); |
| 694 | 637 |
| 695 GURL host("http://example.com/"); | 638 GURL host("http://example.com/"); |
| 696 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 639 ContentSettingsPattern pattern("[*.]example.com"); |
| 697 std::string resource1("someplugin"); | 640 std::string resource1("someplugin"); |
| 698 std::string resource2("otherplugin"); | 641 std::string resource2("otherplugin"); |
| 699 | 642 |
| 700 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 643 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 701 host_content_settings_map->GetContentSetting( | 644 host_content_settings_map->GetContentSetting( |
| 702 host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); | 645 host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); |
| 703 host_content_settings_map->SetContentSetting(pattern, | 646 host_content_settings_map->SetContentSetting(pattern, |
| 704 CONTENT_SETTINGS_TYPE_PLUGINS, resource1, CONTENT_SETTING_BLOCK); | 647 CONTENT_SETTINGS_TYPE_PLUGINS, resource1, CONTENT_SETTING_BLOCK); |
| 705 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 648 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 706 host_content_settings_map->GetContentSetting( | 649 host_content_settings_map->GetContentSetting( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 717 cmd->AppendSwitch(switches::kEnableResourceContentSettings); | 660 cmd->AppendSwitch(switches::kEnableResourceContentSettings); |
| 718 | 661 |
| 719 TestingProfile profile; | 662 TestingProfile profile; |
| 720 scoped_ptr<Value> value(base::JSONReader::Read( | 663 scoped_ptr<Value> value(base::JSONReader::Read( |
| 721 "{\"[*.]example.com\":{\"per_plugin\":{\"someplugin\":2}}}", false)); | 664 "{\"[*.]example.com\":{\"per_plugin\":{\"someplugin\":2}}}", false)); |
| 722 profile.GetPrefs()->Set(prefs::kContentSettingsPatterns, *value); | 665 profile.GetPrefs()->Set(prefs::kContentSettingsPatterns, *value); |
| 723 HostContentSettingsMap* host_content_settings_map = | 666 HostContentSettingsMap* host_content_settings_map = |
| 724 profile.GetHostContentSettingsMap(); | 667 profile.GetHostContentSettingsMap(); |
| 725 | 668 |
| 726 GURL host("http://example.com/"); | 669 GURL host("http://example.com/"); |
| 727 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 670 ContentSettingsPattern pattern("[*.]example.com"); |
| 728 std::string resource1("someplugin"); | 671 std::string resource1("someplugin"); |
| 729 std::string resource2("otherplugin"); | 672 std::string resource2("otherplugin"); |
| 730 | 673 |
| 731 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 674 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 732 host_content_settings_map->GetContentSetting( | 675 host_content_settings_map->GetContentSetting( |
| 733 host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); | 676 host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); |
| 734 | 677 |
| 735 host_content_settings_map->SetContentSetting(pattern, | 678 host_content_settings_map->SetContentSetting(pattern, |
| 736 CONTENT_SETTINGS_TYPE_PLUGINS, resource1, CONTENT_SETTING_DEFAULT); | 679 CONTENT_SETTINGS_TYPE_PLUGINS, resource1, CONTENT_SETTING_DEFAULT); |
| 737 | 680 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 } | 734 } |
| 792 | 735 |
| 793 TEST_F(HostContentSettingsMapTest, | 736 TEST_F(HostContentSettingsMapTest, |
| 794 GetNonDefaultContentSettingsIfTypeManaged) { | 737 GetNonDefaultContentSettingsIfTypeManaged) { |
| 795 TestingProfile profile; | 738 TestingProfile profile; |
| 796 HostContentSettingsMap* host_content_settings_map = | 739 HostContentSettingsMap* host_content_settings_map = |
| 797 profile.GetHostContentSettingsMap(); | 740 profile.GetHostContentSettingsMap(); |
| 798 TestingPrefService* prefs = profile.GetTestingPrefService(); | 741 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 799 | 742 |
| 800 // Set pattern for JavaScript setting. | 743 // Set pattern for JavaScript setting. |
| 801 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 744 ContentSettingsPattern pattern("[*.]example.com"); |
| 802 host_content_settings_map->SetContentSetting(pattern, | 745 host_content_settings_map->SetContentSetting(pattern, |
| 803 CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_BLOCK); | 746 CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_BLOCK); |
| 804 | 747 |
| 805 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 748 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 806 host_content_settings_map->GetDefaultContentSetting( | 749 host_content_settings_map->GetDefaultContentSetting( |
| 807 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 750 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
| 808 | 751 |
| 809 GURL host("http://example.com/"); | 752 GURL host("http://example.com/"); |
| 810 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 753 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 811 host_content_settings_map->GetContentSetting( | 754 host_content_settings_map->GetContentSetting( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 826 TestingProfile profile; | 769 TestingProfile profile; |
| 827 HostContentSettingsMap* host_content_settings_map = | 770 HostContentSettingsMap* host_content_settings_map = |
| 828 profile.GetHostContentSettingsMap(); | 771 profile.GetHostContentSettingsMap(); |
| 829 TestingPrefService* prefs = profile.GetTestingPrefService(); | 772 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 830 | 773 |
| 831 // Block all JavaScript. | 774 // Block all JavaScript. |
| 832 host_content_settings_map->SetDefaultContentSetting( | 775 host_content_settings_map->SetDefaultContentSetting( |
| 833 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 776 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
| 834 | 777 |
| 835 // Set an exception to allow "[*.]example.com" | 778 // Set an exception to allow "[*.]example.com" |
| 836 HostContentSettingsMap::Pattern pattern("[*.]example.com"); | 779 ContentSettingsPattern pattern("[*.]example.com"); |
| 837 host_content_settings_map->SetContentSetting(pattern, | 780 host_content_settings_map->SetContentSetting(pattern, |
| 838 CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_ALLOW); | 781 CONTENT_SETTINGS_TYPE_JAVASCRIPT, "", CONTENT_SETTING_ALLOW); |
| 839 | 782 |
| 840 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 783 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 841 host_content_settings_map->GetDefaultContentSetting( | 784 host_content_settings_map->GetDefaultContentSetting( |
| 842 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); | 785 CONTENT_SETTINGS_TYPE_JAVASCRIPT)); |
| 843 GURL host("http://example.com/"); | 786 GURL host("http://example.com/"); |
| 844 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 787 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 845 host_content_settings_map->GetContentSetting( | 788 host_content_settings_map->GetContentSetting( |
| 846 host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); | 789 host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, "")); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 StubSettingsObserver observer; | 841 StubSettingsObserver observer; |
| 899 TestingPrefService* prefs = profile.GetTestingPrefService(); | 842 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 900 | 843 |
| 901 // TODO(markusheintz): I think it would be better to send notifications only | 844 // TODO(markusheintz): I think it would be better to send notifications only |
| 902 // for a specific content-settings-type. | 845 // for a specific content-settings-type. |
| 903 | 846 |
| 904 // Set the managed default-content-setting. | 847 // Set the managed default-content-setting. |
| 905 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, | 848 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, |
| 906 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); | 849 Value::CreateIntegerValue(CONTENT_SETTING_BLOCK)); |
| 907 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | 850 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 908 EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern); | 851 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern); |
| 909 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | 852 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); |
| 910 EXPECT_TRUE(observer.last_update_all); | 853 EXPECT_TRUE(observer.last_update_all); |
| 911 EXPECT_TRUE(observer.last_update_all_types); | 854 EXPECT_TRUE(observer.last_update_all_types); |
| 912 EXPECT_EQ(1, observer.counter); | 855 EXPECT_EQ(1, observer.counter); |
| 913 | 856 |
| 914 // Remove the managed default-content-setting. | 857 // Remove the managed default-content-setting. |
| 915 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); | 858 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); |
| 916 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | 859 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 917 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | 860 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); |
| 918 EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern); | 861 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern); |
| 919 EXPECT_TRUE(observer.last_update_all); | 862 EXPECT_TRUE(observer.last_update_all); |
| 920 EXPECT_TRUE(observer.last_update_all_types); | 863 EXPECT_TRUE(observer.last_update_all_types); |
| 921 EXPECT_EQ(2, observer.counter); | 864 EXPECT_EQ(2, observer.counter); |
| 922 } | 865 } |
| 923 | 866 |
| 924 // When a default-content-setting is set to a managed setting a | 867 // When a default-content-setting is set to a managed setting a |
| 925 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen | 868 // CONTENT_SETTINGS_CHANGED notification should be fired. The same should happen |
| 926 // if the managed setting is removed. In this test-case the actual managed | 869 // if the managed setting is removed. In this test-case the actual managed |
| 927 // setting is the same. Just the managed status of the default-content-setting | 870 // setting is the same. Just the managed status of the default-content-setting |
| 928 // changes. | 871 // changes. |
| 929 TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsNoChange) { | 872 TEST_F(HostContentSettingsMapTest, ObserveManagedSettingsNoChange) { |
| 930 TestingProfile profile; | 873 TestingProfile profile; |
| 931 HostContentSettingsMap* host_content_settings_map = | 874 HostContentSettingsMap* host_content_settings_map = |
| 932 profile.GetHostContentSettingsMap(); | 875 profile.GetHostContentSettingsMap(); |
| 933 StubSettingsObserver observer; | 876 StubSettingsObserver observer; |
| 934 TestingPrefService* prefs = profile.GetTestingPrefService(); | 877 TestingPrefService* prefs = profile.GetTestingPrefService(); |
| 935 | 878 |
| 936 // TODO(markusheintz): I think it would be better to send notifications only | 879 // TODO(markusheintz): I think it would be better to send notifications only |
| 937 // for a specific content-settings-type. | 880 // for a specific content-settings-type. |
| 938 | 881 |
| 939 // Set the managed default-content-setting. In this case the actual setting | 882 // Set the managed default-content-setting. In this case the actual setting |
| 940 // does not change. | 883 // does not change. |
| 941 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, | 884 prefs->SetManagedPref(prefs::kManagedDefaultImagesSetting, |
| 942 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); | 885 Value::CreateIntegerValue(CONTENT_SETTING_ALLOW)); |
| 943 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | 886 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 944 EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern); | 887 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern); |
| 945 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | 888 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); |
| 946 EXPECT_TRUE(observer.last_update_all); | 889 EXPECT_TRUE(observer.last_update_all); |
| 947 EXPECT_TRUE(observer.last_update_all_types); | 890 EXPECT_TRUE(observer.last_update_all_types); |
| 948 EXPECT_EQ(1, observer.counter); | 891 EXPECT_EQ(1, observer.counter); |
| 949 | 892 |
| 950 // Remove the managed default-content-setting. | 893 // Remove the managed default-content-setting. |
| 951 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); | 894 prefs->RemoveManagedPref(prefs::kManagedDefaultImagesSetting); |
| 952 EXPECT_EQ(host_content_settings_map, observer.last_notifier); | 895 EXPECT_EQ(host_content_settings_map, observer.last_notifier); |
| 953 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); | 896 EXPECT_EQ(CONTENT_SETTINGS_TYPE_DEFAULT, observer.last_type); |
| 954 EXPECT_EQ(HostContentSettingsMap::Pattern(), observer.last_pattern); | 897 EXPECT_EQ(ContentSettingsPattern(), observer.last_pattern); |
| 955 EXPECT_TRUE(observer.last_update_all); | 898 EXPECT_TRUE(observer.last_update_all); |
| 956 EXPECT_TRUE(observer.last_update_all_types); | 899 EXPECT_TRUE(observer.last_update_all_types); |
| 957 EXPECT_EQ(2, observer.counter); | 900 EXPECT_EQ(2, observer.counter); |
| 958 } | 901 } |
| 959 | 902 |
| 960 // If a setting for a default-content-setting-type is set while the type is | 903 // If a setting for a default-content-setting-type is set while the type is |
| 961 // managed, then the new setting should be preserved and used after the | 904 // managed, then the new setting should be preserved and used after the |
| 962 // default-content-setting-type is not managed anymore. | 905 // default-content-setting-type is not managed anymore. |
| 963 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { | 906 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { |
| 964 TestingProfile profile; | 907 TestingProfile profile; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 EXPECT_TRUE(host_content_settings_map->BlockThirdPartyCookies()); | 949 EXPECT_TRUE(host_content_settings_map->BlockThirdPartyCookies()); |
| 1007 | 950 |
| 1008 // After unsetting the managed value for the preference BlockThirdPartyCookies | 951 // After unsetting the managed value for the preference BlockThirdPartyCookies |
| 1009 // the default value should be returned now. | 952 // the default value should be returned now. |
| 1010 prefs->RemoveManagedPref(prefs::kBlockThirdPartyCookies); | 953 prefs->RemoveManagedPref(prefs::kBlockThirdPartyCookies); |
| 1011 EXPECT_FALSE(host_content_settings_map->IsBlockThirdPartyCookiesManaged()); | 954 EXPECT_FALSE(host_content_settings_map->IsBlockThirdPartyCookiesManaged()); |
| 1012 EXPECT_FALSE(host_content_settings_map->BlockThirdPartyCookies()); | 955 EXPECT_FALSE(host_content_settings_map->BlockThirdPartyCookies()); |
| 1013 } | 956 } |
| 1014 | 957 |
| 1015 } // namespace | 958 } // namespace |
| OLD | NEW |