Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/auto_reset.h" | 5 #include "base/auto_reset.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/values.h" | |
| 10 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 11 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
| 11 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 12 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 13 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 13 #include "chrome/browser/content_settings/mock_settings_observer.h" | 14 #include "chrome/browser/content_settings/mock_settings_observer.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "components/content_settings/core/browser/content_settings_details.h" | 17 #include "components/content_settings/core/browser/content_settings_details.h" |
| 17 #include "components/content_settings/core/browser/cookie_settings.h" | 18 #include "components/content_settings/core/browser/cookie_settings.h" |
| 18 #include "components/content_settings/core/browser/host_content_settings_map.h" | 19 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 19 #include "components/content_settings/core/browser/website_settings_info.h" | 20 #include "components/content_settings/core/browser/website_settings_info.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 CONTENT_SETTINGS_TYPE_IMAGES, | 255 CONTENT_SETTINGS_TYPE_IMAGES, |
| 255 std::string(), | 256 std::string(), |
| 256 CONTENT_SETTING_BLOCK); | 257 CONTENT_SETTING_BLOCK); |
| 257 host_content_settings_map->ClearSettingsForOneType( | 258 host_content_settings_map->ClearSettingsForOneType( |
| 258 CONTENT_SETTINGS_TYPE_IMAGES); | 259 CONTENT_SETTINGS_TYPE_IMAGES); |
| 259 ContentSettingsForOneType host_settings; | 260 ContentSettingsForOneType host_settings; |
| 260 host_content_settings_map->GetSettingsForOneType( | 261 host_content_settings_map->GetSettingsForOneType( |
| 261 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); | 262 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); |
| 262 // |host_settings| contains only the default setting. | 263 // |host_settings| contains only the default setting. |
| 263 EXPECT_EQ(1U, host_settings.size()); | 264 EXPECT_EQ(1U, host_settings.size()); |
| 265 | |
| 264 #if defined(ENABLE_PLUGINS) | 266 #if defined(ENABLE_PLUGINS) |
| 267 // Check that it's there, and then clear to test. | |
| 265 host_content_settings_map->GetSettingsForOneType( | 268 host_content_settings_map->GetSettingsForOneType( |
| 266 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); | 269 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); |
| 267 // |host_settings| contains the default setting and an exception. | 270 // |host_settings| contains the default setting and an exception. |
| 268 EXPECT_EQ(2U, host_settings.size()); | 271 EXPECT_EQ(2U, host_settings.size()); |
| 272 host_content_settings_map->ClearSettingsForOneType( | |
|
msramek
2016/02/29 17:46:07
Is this related to this CL?
dmurph
2016/03/01 00:10:00
No, I can remove.
| |
| 273 CONTENT_SETTINGS_TYPE_PLUGINS); | |
| 274 host_content_settings_map->GetSettingsForOneType( | |
| 275 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); | |
| 276 // |host_settings| contains the default setting. | |
| 277 EXPECT_EQ(1U, host_settings.size()); | |
| 269 #endif | 278 #endif |
| 270 } | 279 } |
| 271 | 280 |
| 281 bool MatchPrimaryPatter(const ContentSettingsPattern& expected_primary, | |
|
msramek
2016/02/29 17:46:07
nit: Pattern
dmurph
2016/03/01 00:10:00
Done.
| |
| 282 const ContentSettingsPattern& primary_pattern, | |
| 283 const ContentSettingsPattern& secondary_pattern) { | |
| 284 return expected_primary == primary_pattern; | |
| 285 } | |
| 286 | |
| 287 TEST_F(HostContentSettingsMapTest, ClearWithPredicate) { | |
| 288 TestingProfile profile; | |
| 289 HostContentSettingsMap* host_content_settings_map = | |
| 290 HostContentSettingsMapFactory::GetForProfile(&profile); | |
| 291 ContentSettingsForOneType host_settings; | |
| 292 | |
| 293 // Patterns with wildcards. | |
| 294 ContentSettingsPattern pattern = | |
| 295 ContentSettingsPattern::FromString("[*.]example.org"); | |
| 296 ContentSettingsPattern pattern2 = | |
| 297 ContentSettingsPattern::FromString("[*.]example.net"); | |
| 298 | |
| 299 // Patterns without wildcards. | |
| 300 GURL url1("https://www.google.com/"); | |
| 301 GURL url2("https://www.google.com/maps"); | |
| 302 GURL url3("http://www.google.com/maps"); | |
| 303 GURL url3_origin_only("http://www.google.com/"); | |
| 304 | |
| 305 host_content_settings_map->SetContentSetting( | |
| 306 pattern2, | |
| 307 ContentSettingsPattern::Wildcard(), | |
| 308 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 309 std::string(), | |
| 310 CONTENT_SETTING_BLOCK); | |
| 311 host_content_settings_map->SetContentSetting( | |
| 312 pattern, | |
| 313 ContentSettingsPattern::Wildcard(), | |
| 314 CONTENT_SETTINGS_TYPE_IMAGES, | |
| 315 std::string(), | |
| 316 CONTENT_SETTING_BLOCK); | |
| 317 host_content_settings_map->SetContentSetting( | |
| 318 pattern2, | |
| 319 ContentSettingsPattern::Wildcard(), | |
| 320 CONTENT_SETTINGS_TYPE_APP_BANNER, | |
| 321 std::string(), | |
| 322 CONTENT_SETTING_BLOCK); | |
| 323 | |
| 324 // First, test that we clear only IMAGES (not app banner), and pattern1. | |
|
msramek
2016/02/29 17:46:07
s/pattern1/pattern2/
also nit: APP_BANNER (just f
dmurph
2016/03/01 00:10:00
Done.
| |
| 325 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( | |
| 326 CONTENT_SETTINGS_TYPE_IMAGES, base::Bind(&MatchPrimaryPatter, pattern2)); | |
| 327 host_content_settings_map->GetSettingsForOneType( | |
| 328 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), &host_settings); | |
| 329 // |host_settings| contains default & block. | |
|
msramek
2016/02/29 17:46:07
Can you also test that what remains in the array i
dmurph
2016/03/01 00:10:00
Done.
| |
| 330 EXPECT_EQ(2U, host_settings.size()); | |
| 331 host_content_settings_map->GetSettingsForOneType( | |
| 332 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), &host_settings); | |
| 333 // |host_settings| contains block. | |
| 334 EXPECT_EQ(1U, host_settings.size()); | |
| 335 | |
| 336 | |
| 337 // Next, test that we do correct pattern stuff w/ an origin policy item. | |
|
msramek
2016/02/29 17:46:07
Please improve the comment (pattern stuff?)
dmurph
2016/03/01 00:10:00
Done.
| |
| 338 // We verify that we have no settings stored. | |
| 339 host_content_settings_map->GetSettingsForOneType( | |
| 340 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | |
| 341 EXPECT_EQ(0u, host_settings.size()); | |
| 342 // Add settings. | |
| 343 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 344 url1, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 345 new base::FundamentalValue(10)); | |
| 346 // This setting should override the one above, as it's the same origin. | |
| 347 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 348 url2, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 349 new base::FundamentalValue(10)); | |
| 350 host_content_settings_map->SetWebsiteSettingDefaultScope( | |
| 351 url3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), | |
| 352 new base::FundamentalValue(10)); | |
| 353 // Verify we only have two. | |
| 354 host_content_settings_map->GetSettingsForOneType( | |
| 355 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | |
| 356 EXPECT_EQ(2u, host_settings.size()); | |
| 357 | |
| 358 // Clear the http one, which we should be able to do w/ the origin only, as | |
| 359 // the scope of CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT is | |
| 360 // REQUESTING_ORIGIN_ONLY_SCOPE. | |
| 361 ContentSettingsPattern http_pattern = | |
| 362 ContentSettingsPattern::FromURLNoWildcard(url3_origin_only); | |
| 363 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( | |
| 364 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | |
| 365 base::Bind(&MatchPrimaryPatter, http_pattern)); | |
| 366 // Verify we only have one. | |
|
msramek
2016/02/29 17:46:07
Please also verify that we actually have the corre
dmurph
2016/03/01 00:10:00
Done.
| |
| 367 host_content_settings_map->GetSettingsForOneType( | |
| 368 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | |
| 369 EXPECT_EQ(1u, host_settings.size()); | |
| 370 } | |
| 371 | |
| 272 TEST_F(HostContentSettingsMapTest, Patterns) { | 372 TEST_F(HostContentSettingsMapTest, Patterns) { |
| 273 TestingProfile profile; | 373 TestingProfile profile; |
| 274 HostContentSettingsMap* host_content_settings_map = | 374 HostContentSettingsMap* host_content_settings_map = |
| 275 HostContentSettingsMapFactory::GetForProfile(&profile); | 375 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 276 | 376 |
| 277 GURL host1("http://example.com/"); | 377 GURL host1("http://example.com/"); |
| 278 GURL host2("http://www.example.com/"); | 378 GURL host2("http://www.example.com/"); |
| 279 GURL host3("http://example.org/"); | 379 GURL host3("http://example.org/"); |
| 280 ContentSettingsPattern pattern1 = | 380 ContentSettingsPattern pattern1 = |
| 281 ContentSettingsPattern::FromString("[*.]example.com"); | 381 ContentSettingsPattern::FromString("[*.]example.com"); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 _, _, true)); | 449 _, _, true)); |
| 350 host_content_settings_map->SetDefaultContentSetting( | 450 host_content_settings_map->SetDefaultContentSetting( |
| 351 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 451 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
| 352 } | 452 } |
| 353 | 453 |
| 354 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { | 454 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { |
| 355 TestingProfile profile; | 455 TestingProfile profile; |
| 356 HostContentSettingsMap* host_content_settings_map = | 456 HostContentSettingsMap* host_content_settings_map = |
| 357 HostContentSettingsMapFactory::GetForProfile(&profile); | 457 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 358 | 458 |
| 459 | |
| 359 PrefService* prefs = profile.GetPrefs(); | 460 PrefService* prefs = profile.GetPrefs(); |
| 360 GURL host("http://example.com"); | 461 GURL host("http://example.com"); |
| 361 | 462 |
| 362 host_content_settings_map->SetDefaultContentSetting( | 463 host_content_settings_map->SetDefaultContentSetting( |
| 363 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); | 464 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); |
| 364 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 465 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 365 host_content_settings_map->GetContentSetting( | 466 host_content_settings_map->GetContentSetting( |
| 366 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 467 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 367 | 468 |
| 368 const content_settings::WebsiteSettingsInfo* info = | 469 const content_settings::WebsiteSettingsInfo* info = |
| (...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1265 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); | 1366 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *value); |
| 1266 | 1367 |
| 1267 // Test that during construction all the prefs get cleared. | 1368 // Test that during construction all the prefs get cleared. |
| 1268 HostContentSettingsMapFactory::GetForProfile(&profile); | 1369 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1269 | 1370 |
| 1270 const base::DictionaryValue* all_settings_dictionary = | 1371 const base::DictionaryValue* all_settings_dictionary = |
| 1271 profile.GetPrefs()->GetDictionary( | 1372 profile.GetPrefs()->GetDictionary( |
| 1272 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); | 1373 GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)); |
| 1273 EXPECT_TRUE(all_settings_dictionary->empty()); | 1374 EXPECT_TRUE(all_settings_dictionary->empty()); |
| 1274 } | 1375 } |
| OLD | NEW |