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 <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"); | |
|
msramek
2016/06/24 19:53:48
We should also have tests for crazier patterns suc
lshang
2016/06/27 00:31:00
Now I realized how we lack of full coverage of pat
| |
| 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/"); | |
|
msramek
2016/06/24 19:53:48
Consider also adding a test for different port, e.
lshang
2016/06/27 00:31:00
Done.
| |
| 340 ContentSettingsPattern pattern = | |
| 341 ContentSettingsPattern::FromURLNoWildcard(host1); | |
| 342 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 343 host_content_settings_map->GetContentSetting( | |
| 344 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 345 host_content_settings_map->SetContentSettingCustomScope( | |
| 346 pattern, ContentSettingsPattern::Wildcard(), | |
| 347 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 348 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 349 host_content_settings_map->GetContentSetting( | |
| 350 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 351 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 352 host_content_settings_map->GetContentSetting( | |
| 353 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 354 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 355 host_content_settings_map->GetContentSetting( | |
| 356 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 357 } | |
| 358 | |
| 327 TEST_F(HostContentSettingsMapTest, Observer) { | 359 TEST_F(HostContentSettingsMapTest, Observer) { |
| 328 TestingProfile profile; | 360 TestingProfile profile; |
| 329 HostContentSettingsMap* host_content_settings_map = | 361 HostContentSettingsMap* host_content_settings_map = |
| 330 HostContentSettingsMapFactory::GetForProfile(&profile); | 362 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 331 MockSettingsObserver observer(host_content_settings_map); | 363 MockSettingsObserver observer(host_content_settings_map); |
| 332 | 364 |
| 333 GURL host("http://example.com/"); | 365 GURL host("http://example.com/"); |
| 334 ContentSettingsPattern primary_pattern = | 366 ContentSettingsPattern primary_pattern = |
| 335 ContentSettingsPattern::FromString("[*.]example.com"); | 367 ContentSettingsPattern::FromString("[*.]example.com"); |
| 336 ContentSettingsPattern secondary_pattern = | 368 ContentSettingsPattern secondary_pattern = |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 host_content_settings_map->GetContentSetting( | 601 host_content_settings_map->GetContentSetting( |
| 570 host_ending_with_dot, host_ending_with_dot, | 602 host_ending_with_dot, host_ending_with_dot, |
| 571 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); | 603 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); |
| 572 } | 604 } |
| 573 | 605 |
| 574 TEST_F(HostContentSettingsMapTest, NestedSettings) { | 606 TEST_F(HostContentSettingsMapTest, NestedSettings) { |
| 575 TestingProfile profile; | 607 TestingProfile profile; |
| 576 HostContentSettingsMap* host_content_settings_map = | 608 HostContentSettingsMap* host_content_settings_map = |
| 577 HostContentSettingsMapFactory::GetForProfile(&profile); | 609 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 578 | 610 |
| 579 GURL host("http://a.b.example.com/"); | |
| 580 GURL host1("http://example.com/"); | 611 GURL host1("http://example.com/"); |
| 581 GURL host2("http://b.example.com/"); | 612 GURL host2("http://b.example.com/"); |
| 613 GURL host3("http://a.b.example.com/"); | |
| 614 GURL host4("http://a.example.com/"); | |
| 615 GURL host5("http://b.b.example.com/"); | |
| 616 ContentSettingsPattern pattern1 = | |
| 617 ContentSettingsPattern::FromString("[*.]example.com"); | |
| 618 ContentSettingsPattern pattern2 = | |
| 619 ContentSettingsPattern::FromString("[*.]b.example.com"); | |
| 620 ContentSettingsPattern pattern3 = | |
| 621 ContentSettingsPattern::FromString("a.b.example.com"); | |
| 622 | |
| 623 // Test nested patterns for one type. | |
| 624 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 625 host_content_settings_map->GetDefaultContentSetting( | |
| 626 CONTENT_SETTINGS_TYPE_COOKIES, nullptr)); | |
| 627 host_content_settings_map->SetContentSettingCustomScope( | |
| 628 pattern1, ContentSettingsPattern::Wildcard(), | |
| 629 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 630 host_content_settings_map->SetContentSettingCustomScope( | |
| 631 pattern2, ContentSettingsPattern::Wildcard(), | |
| 632 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_ALLOW); | |
| 633 host_content_settings_map->SetContentSettingCustomScope( | |
| 634 pattern3, ContentSettingsPattern::Wildcard(), | |
| 635 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 636 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 637 host_content_settings_map->GetContentSetting( | |
| 638 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 639 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 640 host_content_settings_map->GetContentSetting( | |
| 641 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 642 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 643 host_content_settings_map->GetContentSetting( | |
| 644 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 645 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 646 host_content_settings_map->GetContentSetting( | |
| 647 host4, host4, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 648 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 649 host_content_settings_map->GetContentSetting( | |
| 650 host5, host5, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 651 | |
| 652 host_content_settings_map->ClearSettingsForOneType( | |
| 653 CONTENT_SETTINGS_TYPE_COOKIES); | |
| 654 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 655 host_content_settings_map->GetDefaultContentSetting( | |
| 656 CONTENT_SETTINGS_TYPE_COOKIES, nullptr)); | |
| 657 | |
| 658 GURL https_host2("https://b.example.com/"); | |
|
msramek
2016/06/24 19:53:48
nit: 1,2 instead of 2,3
lshang
2016/06/27 00:31:00
Done.
| |
| 659 GURL https_host3("https://a.b.example.com/"); | |
| 660 ContentSettingsPattern pattern4 = | |
| 661 ContentSettingsPattern::FromString("b.example.com"); | |
| 662 | |
| 663 host_content_settings_map->SetContentSettingCustomScope( | |
| 664 pattern4, ContentSettingsPattern::Wildcard(), | |
| 665 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 666 // Pattern "b.example.com" will affect (http|https)://b.example.com | |
| 667 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 668 host_content_settings_map->GetContentSetting( | |
| 669 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 670 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 671 host_content_settings_map->GetContentSetting( | |
| 672 https_host2, https_host2, CONTENT_SETTINGS_TYPE_COOKIES, | |
| 673 std::string())); | |
| 674 // Pattern "b.example.com" will not affect (http|https)://a.b.example.com | |
| 675 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 676 host_content_settings_map->GetContentSetting( | |
| 677 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 678 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 679 host_content_settings_map->GetContentSetting( | |
| 680 https_host3, https_host3, CONTENT_SETTINGS_TYPE_COOKIES, | |
| 681 std::string())); | |
| 682 } | |
| 683 | |
| 684 TEST_F(HostContentSettingsMapTest, TypeIsolatedSettings) { | |
| 685 TestingProfile profile; | |
| 686 HostContentSettingsMap* host_content_settings_map = | |
| 687 HostContentSettingsMapFactory::GetForProfile(&profile); | |
| 688 | |
| 689 GURL host("http://example.com/"); | |
| 582 | 690 |
| 583 host_content_settings_map->SetContentSettingDefaultScope( | 691 host_content_settings_map->SetContentSettingDefaultScope( |
| 584 host1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), | 692 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 585 CONTENT_SETTING_BLOCK); | 693 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, | 694 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 598 host_content_settings_map->GetContentSetting( | 695 host_content_settings_map->GetContentSetting( |
| 599 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 696 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, | 697 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 611 host_content_settings_map->GetContentSetting( | 698 host_content_settings_map->GetContentSetting( |
| 612 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 699 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 } | 700 } |
| 632 | 701 |
| 633 TEST_F(HostContentSettingsMapTest, OffTheRecord) { | 702 TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
| 634 TestingProfile profile; | 703 TestingProfile profile; |
| 635 Profile* otr_profile = profile.GetOffTheRecordProfile(); | 704 Profile* otr_profile = profile.GetOffTheRecordProfile(); |
| 636 HostContentSettingsMap* host_content_settings_map = | 705 HostContentSettingsMap* host_content_settings_map = |
| 637 HostContentSettingsMapFactory::GetForProfile(&profile); | 706 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 638 HostContentSettingsMap* otr_map = | 707 HostContentSettingsMap* otr_map = |
| 639 HostContentSettingsMapFactory::GetForProfile(otr_profile); | 708 HostContentSettingsMapFactory::GetForProfile(otr_profile); |
| 640 | 709 |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1289 base::DictionaryValue test_value; | 1358 base::DictionaryValue test_value; |
| 1290 test_value.SetString("test", "value"); | 1359 test_value.SetString("test", "value"); |
| 1291 host_content_settings_map->SetWebsiteSettingDefaultScope( | 1360 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 1292 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, | 1361 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, |
| 1293 std::string(), base::WrapUnique(test_value.DeepCopy())); | 1362 std::string(), base::WrapUnique(test_value.DeepCopy())); |
| 1294 EXPECT_EQ(nullptr, | 1363 EXPECT_EQ(nullptr, |
| 1295 host_content_settings_map->GetWebsiteSetting( | 1364 host_content_settings_map->GetWebsiteSetting( |
| 1296 unsupported_url, unsupported_url, | 1365 unsupported_url, unsupported_url, |
| 1297 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); | 1366 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); |
| 1298 } | 1367 } |
| OLD | NEW |