| 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 294 } |
| 295 | 295 |
| 296 TEST_F(HostContentSettingsMapTest, Patterns) { | 296 TEST_F(HostContentSettingsMapTest, Patterns) { |
| 297 TestingProfile profile; | 297 TestingProfile profile; |
| 298 HostContentSettingsMap* host_content_settings_map = | 298 HostContentSettingsMap* host_content_settings_map = |
| 299 HostContentSettingsMapFactory::GetForProfile(&profile); | 299 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 300 | 300 |
| 301 GURL host1("http://example.com/"); | 301 GURL host1("http://example.com/"); |
| 302 GURL host2("http://www.example.com/"); | 302 GURL host2("http://www.example.com/"); |
| 303 GURL host3("http://example.org/"); | 303 GURL host3("http://example.org/"); |
| 304 ContentSettingsPattern pattern1 = |
| 305 ContentSettingsPattern::FromString("[*.]example.com"); |
| 306 ContentSettingsPattern pattern2 = |
| 307 ContentSettingsPattern::FromString("example.org"); |
| 304 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 308 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 305 host_content_settings_map->GetContentSetting( | 309 host_content_settings_map->GetContentSetting( |
| 306 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 310 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 307 host_content_settings_map->SetContentSettingDefaultScope( | 311 host_content_settings_map->SetContentSettingCustomScope( |
| 308 host1, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 312 pattern1, ContentSettingsPattern::Wildcard(), |
| 309 CONTENT_SETTING_BLOCK); | 313 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| 310 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 314 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 311 host_content_settings_map->GetContentSetting( | 315 host_content_settings_map->GetContentSetting( |
| 312 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 316 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 313 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 317 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 314 host_content_settings_map->GetContentSetting( | 318 host_content_settings_map->GetContentSetting( |
| 315 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 319 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 316 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 320 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 317 host_content_settings_map->GetContentSetting( | 321 host_content_settings_map->GetContentSetting( |
| 318 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 322 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 319 host_content_settings_map->SetContentSettingDefaultScope( | 323 host_content_settings_map->SetContentSettingCustomScope( |
| 320 host3, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 324 pattern2, ContentSettingsPattern::Wildcard(), |
| 321 CONTENT_SETTING_BLOCK); | 325 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| 322 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 326 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 323 host_content_settings_map->GetContentSetting( | 327 host_content_settings_map->GetContentSetting( |
| 324 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 328 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 325 } | 329 } |
| 326 | 330 |
| 331 // Changing a setting for one origin doesn't affect subdomains. |
| 332 TEST_F(HostContentSettingsMapTest, Origins) { |
| 333 TestingProfile profile; |
| 334 HostContentSettingsMap* host_content_settings_map = |
| 335 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 336 |
| 337 GURL host1("http://example.com/"); |
| 338 GURL host2("http://www.example.com/"); |
| 339 GURL host3("http://example.org/"); |
| 340 GURL host4("http://example.com:8080"); |
| 341 ContentSettingsPattern pattern = |
| 342 ContentSettingsPattern::FromURLNoWildcard(host1); |
| 343 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 344 host_content_settings_map->GetContentSetting( |
| 345 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 346 host_content_settings_map->SetContentSettingCustomScope( |
| 347 pattern, ContentSettingsPattern::Wildcard(), |
| 348 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| 349 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 350 host_content_settings_map->GetContentSetting( |
| 351 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 352 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 353 host_content_settings_map->GetContentSetting( |
| 354 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 355 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 356 host_content_settings_map->GetContentSetting( |
| 357 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 358 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 359 host_content_settings_map->GetContentSetting( |
| 360 host4, host4, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 361 } |
| 362 |
| 327 TEST_F(HostContentSettingsMapTest, Observer) { | 363 TEST_F(HostContentSettingsMapTest, Observer) { |
| 328 TestingProfile profile; | 364 TestingProfile profile; |
| 329 HostContentSettingsMap* host_content_settings_map = | 365 HostContentSettingsMap* host_content_settings_map = |
| 330 HostContentSettingsMapFactory::GetForProfile(&profile); | 366 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 331 MockSettingsObserver observer(host_content_settings_map); | 367 MockSettingsObserver observer(host_content_settings_map); |
| 332 | 368 |
| 333 GURL host("http://example.com/"); | 369 GURL host("http://example.com/"); |
| 334 ContentSettingsPattern primary_pattern = | 370 ContentSettingsPattern primary_pattern = |
| 335 ContentSettingsPattern::FromString("[*.]example.com"); | 371 ContentSettingsPattern::FromString("[*.]example.com"); |
| 336 ContentSettingsPattern secondary_pattern = | 372 ContentSettingsPattern secondary_pattern = |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 569 host_content_settings_map->GetContentSetting( | 605 host_content_settings_map->GetContentSetting( |
| 570 host_ending_with_dot, host_ending_with_dot, | 606 host_ending_with_dot, host_ending_with_dot, |
| 571 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); | 607 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); |
| 572 } | 608 } |
| 573 | 609 |
| 574 TEST_F(HostContentSettingsMapTest, NestedSettings) { | 610 TEST_F(HostContentSettingsMapTest, NestedSettings) { |
| 575 TestingProfile profile; | 611 TestingProfile profile; |
| 576 HostContentSettingsMap* host_content_settings_map = | 612 HostContentSettingsMap* host_content_settings_map = |
| 577 HostContentSettingsMapFactory::GetForProfile(&profile); | 613 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 578 | 614 |
| 579 GURL host("http://a.b.example.com/"); | |
| 580 GURL host1("http://example.com/"); | 615 GURL host1("http://example.com/"); |
| 581 GURL host2("http://b.example.com/"); | 616 GURL host2("http://b.example.com/"); |
| 617 GURL host3("http://a.b.example.com/"); |
| 618 GURL host4("http://a.example.com/"); |
| 619 GURL host5("http://b.b.example.com/"); |
| 620 ContentSettingsPattern pattern1 = |
| 621 ContentSettingsPattern::FromString("[*.]example.com"); |
| 622 ContentSettingsPattern pattern2 = |
| 623 ContentSettingsPattern::FromString("[*.]b.example.com"); |
| 624 ContentSettingsPattern pattern3 = |
| 625 ContentSettingsPattern::FromString("a.b.example.com"); |
| 626 |
| 627 // Test nested patterns for one type. |
| 628 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 629 host_content_settings_map->GetDefaultContentSetting( |
| 630 CONTENT_SETTINGS_TYPE_COOKIES, nullptr)); |
| 631 host_content_settings_map->SetContentSettingCustomScope( |
| 632 pattern1, ContentSettingsPattern::Wildcard(), |
| 633 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| 634 host_content_settings_map->SetContentSettingCustomScope( |
| 635 pattern2, ContentSettingsPattern::Wildcard(), |
| 636 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_ALLOW); |
| 637 host_content_settings_map->SetContentSettingCustomScope( |
| 638 pattern3, ContentSettingsPattern::Wildcard(), |
| 639 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| 640 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 641 host_content_settings_map->GetContentSetting( |
| 642 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 643 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 644 host_content_settings_map->GetContentSetting( |
| 645 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 646 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 647 host_content_settings_map->GetContentSetting( |
| 648 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 649 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 650 host_content_settings_map->GetContentSetting( |
| 651 host4, host4, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 652 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 653 host_content_settings_map->GetContentSetting( |
| 654 host5, host5, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 655 |
| 656 host_content_settings_map->ClearSettingsForOneType( |
| 657 CONTENT_SETTINGS_TYPE_COOKIES); |
| 658 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 659 host_content_settings_map->GetDefaultContentSetting( |
| 660 CONTENT_SETTINGS_TYPE_COOKIES, nullptr)); |
| 661 |
| 662 GURL https_host1("https://b.example.com/"); |
| 663 GURL https_host2("https://a.b.example.com/"); |
| 664 ContentSettingsPattern pattern4 = |
| 665 ContentSettingsPattern::FromString("b.example.com"); |
| 666 |
| 667 host_content_settings_map->SetContentSettingCustomScope( |
| 668 pattern4, ContentSettingsPattern::Wildcard(), |
| 669 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| 670 // Pattern "b.example.com" will affect (http|https)://b.example.com |
| 671 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 672 host_content_settings_map->GetContentSetting( |
| 673 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 674 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 675 host_content_settings_map->GetContentSetting( |
| 676 https_host1, https_host1, CONTENT_SETTINGS_TYPE_COOKIES, |
| 677 std::string())); |
| 678 // Pattern "b.example.com" will not affect (http|https)://a.b.example.com |
| 679 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 680 host_content_settings_map->GetContentSetting( |
| 681 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 682 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 683 host_content_settings_map->GetContentSetting( |
| 684 https_host2, https_host2, CONTENT_SETTINGS_TYPE_COOKIES, |
| 685 std::string())); |
| 686 } |
| 687 |
| 688 TEST_F(HostContentSettingsMapTest, TypeIsolatedSettings) { |
| 689 TestingProfile profile; |
| 690 HostContentSettingsMap* host_content_settings_map = |
| 691 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 692 |
| 693 GURL host("http://example.com/"); |
| 582 | 694 |
| 583 host_content_settings_map->SetContentSettingDefaultScope( | 695 host_content_settings_map->SetContentSettingDefaultScope( |
| 584 host1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), | 696 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 585 CONTENT_SETTING_BLOCK); | 697 CONTENT_SETTING_BLOCK); |
| 586 | |
| 587 host_content_settings_map->SetContentSettingDefaultScope( | |
| 588 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | |
| 589 CONTENT_SETTING_BLOCK); | |
| 590 | |
| 591 host_content_settings_map->SetContentSettingDefaultScope( | |
| 592 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), | |
| 593 CONTENT_SETTING_BLOCK); | |
| 594 host_content_settings_map->SetDefaultContentSetting( | |
| 595 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | |
| 596 | |
| 597 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 698 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 598 host_content_settings_map->GetContentSetting( | 699 host_content_settings_map->GetContentSetting( |
| 599 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 700 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 600 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 601 host_content_settings_map->GetContentSetting( | |
| 602 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | |
| 603 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 604 host_content_settings_map->GetContentSetting( | |
| 605 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | |
| 606 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 607 host_content_settings_map->GetContentSetting( | |
| 608 host, host, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | |
| 609 std::string())); | |
| 610 EXPECT_EQ(CONTENT_SETTING_ASK, | 701 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 611 host_content_settings_map->GetContentSetting( | 702 host_content_settings_map->GetContentSetting( |
| 612 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 703 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| 613 EXPECT_EQ( | |
| 614 CONTENT_SETTING_ASK, | |
| 615 host_content_settings_map->GetContentSetting( | |
| 616 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | |
| 617 EXPECT_EQ(CONTENT_SETTING_ASK, | |
| 618 host_content_settings_map->GetContentSetting( | |
| 619 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); | |
| 620 #if !defined(OS_ANDROID) | |
| 621 EXPECT_EQ(CONTENT_SETTING_ASK, | |
| 622 host_content_settings_map->GetContentSetting( | |
| 623 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); | |
| 624 #endif | |
| 625 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 626 host_content_settings_map->GetContentSetting( | |
| 627 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | |
| 628 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 629 host_content_settings_map->GetContentSetting( | |
| 630 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); | |
| 631 } | 704 } |
| 632 | 705 |
| 633 TEST_F(HostContentSettingsMapTest, OffTheRecord) { | 706 TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
| 634 TestingProfile profile; | 707 TestingProfile profile; |
| 635 Profile* otr_profile = profile.GetOffTheRecordProfile(); | 708 Profile* otr_profile = profile.GetOffTheRecordProfile(); |
| 636 HostContentSettingsMap* host_content_settings_map = | 709 HostContentSettingsMap* host_content_settings_map = |
| 637 HostContentSettingsMapFactory::GetForProfile(&profile); | 710 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 638 HostContentSettingsMap* otr_map = | 711 HostContentSettingsMap* otr_map = |
| 639 HostContentSettingsMapFactory::GetForProfile(otr_profile); | 712 HostContentSettingsMapFactory::GetForProfile(otr_profile); |
| 640 | 713 |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1289 base::DictionaryValue test_value; | 1362 base::DictionaryValue test_value; |
| 1290 test_value.SetString("test", "value"); | 1363 test_value.SetString("test", "value"); |
| 1291 host_content_settings_map->SetWebsiteSettingDefaultScope( | 1364 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 1292 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, | 1365 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, |
| 1293 std::string(), base::WrapUnique(test_value.DeepCopy())); | 1366 std::string(), base::WrapUnique(test_value.DeepCopy())); |
| 1294 EXPECT_EQ(nullptr, | 1367 EXPECT_EQ(nullptr, |
| 1295 host_content_settings_map->GetWebsiteSetting( | 1368 host_content_settings_map->GetWebsiteSetting( |
| 1296 unsupported_url, unsupported_url, | 1369 unsupported_url, unsupported_url, |
| 1297 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); | 1370 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); |
| 1298 } | 1371 } |
| OLD | NEW |