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"); | |
| 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 TEST_F(HostContentSettingsMapTest, Origins) { | |
| 332 TestingProfile profile; | |
| 333 HostContentSettingsMap* host_content_settings_map = | |
| 334 HostContentSettingsMapFactory::GetForProfile(&profile); | |
| 335 | |
| 336 GURL host1("http://example.com/"); | |
| 337 GURL host2("http://www.example.com/"); | |
| 338 GURL host3("http://example.org/"); | |
| 339 ContentSettingsPattern pattern = | |
| 340 ContentSettingsPattern::FromString("example.com"); | |
|
raymes
2016/06/23 01:15:19
How about we use FromURLNoWildcard here (or SetDef
lshang
2016/06/23 04:29:42
Done.
| |
| 341 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 342 host_content_settings_map->GetContentSetting( | |
| 343 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 344 host_content_settings_map->SetContentSettingCustomScope( | |
| 345 pattern, ContentSettingsPattern::Wildcard(), | |
| 346 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 347 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 348 host_content_settings_map->GetContentSetting( | |
| 349 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 350 // Changing a setting for one origin doesn't affect subdomains. | |
|
raymes
2016/06/23 01:15:19
Maybe move this (and the comment below) as comment
lshang
2016/06/23 04:29:42
Done.
| |
| 351 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 352 host_content_settings_map->GetContentSetting( | |
| 353 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 354 // Changing a setting for one origin doesn't affect other origins. | |
| 355 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 356 host_content_settings_map->GetContentSetting( | |
| 357 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 358 } | |
| 359 | |
| 327 TEST_F(HostContentSettingsMapTest, Observer) { | 360 TEST_F(HostContentSettingsMapTest, Observer) { |
| 328 TestingProfile profile; | 361 TestingProfile profile; |
| 329 HostContentSettingsMap* host_content_settings_map = | 362 HostContentSettingsMap* host_content_settings_map = |
| 330 HostContentSettingsMapFactory::GetForProfile(&profile); | 363 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 331 MockSettingsObserver observer(host_content_settings_map); | 364 MockSettingsObserver observer(host_content_settings_map); |
| 332 | 365 |
| 333 GURL host("http://example.com/"); | 366 GURL host("http://example.com/"); |
| 334 ContentSettingsPattern primary_pattern = | 367 ContentSettingsPattern primary_pattern = |
| 335 ContentSettingsPattern::FromString("[*.]example.com"); | 368 ContentSettingsPattern::FromString("[*.]example.com"); |
| 336 ContentSettingsPattern secondary_pattern = | 369 ContentSettingsPattern secondary_pattern = |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 host_content_settings_map->GetContentSetting( | 602 host_content_settings_map->GetContentSetting( |
| 570 host_ending_with_dot, host_ending_with_dot, | 603 host_ending_with_dot, host_ending_with_dot, |
| 571 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); | 604 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); |
| 572 } | 605 } |
| 573 | 606 |
| 574 TEST_F(HostContentSettingsMapTest, NestedSettings) { | 607 TEST_F(HostContentSettingsMapTest, NestedSettings) { |
| 575 TestingProfile profile; | 608 TestingProfile profile; |
| 576 HostContentSettingsMap* host_content_settings_map = | 609 HostContentSettingsMap* host_content_settings_map = |
| 577 HostContentSettingsMapFactory::GetForProfile(&profile); | 610 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 578 | 611 |
| 579 GURL host("http://a.b.example.com/"); | |
| 580 GURL host1("http://example.com/"); | 612 GURL host1("http://example.com/"); |
| 581 GURL host2("http://b.example.com/"); | 613 GURL host2("http://b.example.com/"); |
| 614 GURL host3("http://a.b.example.com/"); | |
| 615 ContentSettingsPattern pattern1 = | |
| 616 ContentSettingsPattern::FromString("[*.]example.com"); | |
| 617 ContentSettingsPattern pattern2 = | |
| 618 ContentSettingsPattern::FromString("[*.]b.example.com"); | |
| 619 ContentSettingsPattern pattern3 = | |
| 620 ContentSettingsPattern::FromString("a.b.example.com"); | |
| 582 | 621 |
| 583 host_content_settings_map->SetContentSettingDefaultScope( | 622 // Test nested patterns for one type. |
| 584 host1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), | 623 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 585 CONTENT_SETTING_BLOCK); | 624 host_content_settings_map->GetDefaultContentSetting( |
| 625 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | |
|
raymes
2016/06/23 01:15:18
nullptr
lshang
2016/06/23 04:29:42
Done.
| |
| 626 host_content_settings_map->SetContentSettingCustomScope( | |
| 627 pattern1, ContentSettingsPattern::Wildcard(), | |
| 628 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 629 host_content_settings_map->SetContentSettingCustomScope( | |
| 630 pattern2, ContentSettingsPattern::Wildcard(), | |
| 631 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_ALLOW); | |
| 632 host_content_settings_map->SetContentSettingCustomScope( | |
| 633 pattern3, ContentSettingsPattern::Wildcard(), | |
| 634 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 635 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 636 host_content_settings_map->GetContentSetting( | |
| 637 host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 638 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 639 host_content_settings_map->GetContentSetting( | |
| 640 host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 641 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 642 host_content_settings_map->GetContentSetting( | |
| 643 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 644 GURL host4("http://a.example.com/"); | |
|
raymes
2016/06/23 01:15:19
We should be consistent and either have all of the
lshang
2016/06/23 04:29:42
Done.
Move them all at the top.
| |
| 645 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 646 host_content_settings_map->GetContentSetting( | |
| 647 host4, host4, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 648 GURL host5("http://b.b.example.com/"); | |
| 649 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 650 host_content_settings_map->GetContentSetting( | |
| 651 host5, host5, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 586 | 652 |
| 587 host_content_settings_map->SetContentSettingDefaultScope( | 653 host_content_settings_map->ClearSettingsForOneType( |
| 588 host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 654 CONTENT_SETTINGS_TYPE_COOKIES); |
| 589 CONTENT_SETTING_BLOCK); | 655 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 656 host_content_settings_map->GetDefaultContentSetting( | |
| 657 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); | |
|
raymes
2016/06/23 01:15:19
nullptr
lshang
2016/06/23 04:29:42
Done.
| |
| 590 | 658 |
| 591 host_content_settings_map->SetContentSettingDefaultScope( | 659 GURL https_host2("https://b.example.com/"); |
| 592 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), | 660 GURL https_host3("https://a.b.example.com/"); |
| 661 ContentSettingsPattern pattern4 = | |
| 662 ContentSettingsPattern::FromString("b.example.com"); | |
| 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 host_content_settings_map->ClearSettingsForOneType( | |
| 684 CONTENT_SETTINGS_TYPE_COOKIES); | |
| 685 | |
| 686 // Nested setting of one type doesn't affect other types. | |
|
raymes
2016/06/23 01:15:19
I think we could move this (from here down) into a
lshang
2016/06/23 04:29:43
Done.
| |
| 687 host_content_settings_map->SetContentSettingCustomScope( | |
| 688 pattern1, ContentSettingsPattern::Wildcard(), | |
| 689 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), CONTENT_SETTING_BLOCK); | |
| 690 | |
| 691 host_content_settings_map->SetContentSettingCustomScope( | |
| 692 pattern2, ContentSettingsPattern::Wildcard(), | |
| 693 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | |
| 694 | |
| 695 host_content_settings_map->SetContentSettingCustomScope( | |
| 696 pattern3, ContentSettingsPattern::Wildcard(), | |
| 697 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), | |
| 593 CONTENT_SETTING_BLOCK); | 698 CONTENT_SETTING_BLOCK); |
| 594 host_content_settings_map->SetDefaultContentSetting( | 699 host_content_settings_map->SetDefaultContentSetting( |
| 595 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); | 700 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
| 596 | 701 |
| 597 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 702 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 598 host_content_settings_map->GetContentSetting( | 703 host_content_settings_map->GetContentSetting( |
| 599 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 704 host3, host3, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 600 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 705 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 601 host_content_settings_map->GetContentSetting( | 706 host_content_settings_map->GetContentSetting( |
| 602 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | 707 host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 603 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 708 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 604 host_content_settings_map->GetContentSetting( | 709 host_content_settings_map->GetContentSetting( |
| 605 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); | 710 host3, host3, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| 711 std::string())); | |
| 606 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 712 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 607 host_content_settings_map->GetContentSetting( | 713 host_content_settings_map->GetContentSetting( |
| 608 host, host, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, | 714 host3, host3, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
|
raymes
2016/06/23 01:15:19
It's not completely clear to me why we need to hav
lshang
2016/06/23 04:29:43
I agree.
| |
| 609 std::string())); | |
| 610 EXPECT_EQ(CONTENT_SETTING_ASK, | |
| 611 host_content_settings_map->GetContentSetting( | |
| 612 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | |
| 613 EXPECT_EQ( | 715 EXPECT_EQ( |
| 614 CONTENT_SETTING_ASK, | 716 CONTENT_SETTING_ASK, |
| 615 host_content_settings_map->GetContentSetting( | 717 host_content_settings_map->GetContentSetting( |
| 616 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | 718 host3, host3, CONTENT_SETTINGS_TYPE_GEOLOCATION, 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 } | 719 } |
| 632 | 720 |
| 633 TEST_F(HostContentSettingsMapTest, OffTheRecord) { | 721 TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
| 634 TestingProfile profile; | 722 TestingProfile profile; |
| 635 Profile* otr_profile = profile.GetOffTheRecordProfile(); | 723 Profile* otr_profile = profile.GetOffTheRecordProfile(); |
| 636 HostContentSettingsMap* host_content_settings_map = | 724 HostContentSettingsMap* host_content_settings_map = |
| 637 HostContentSettingsMapFactory::GetForProfile(&profile); | 725 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 638 HostContentSettingsMap* otr_map = | 726 HostContentSettingsMap* otr_map = |
| 639 HostContentSettingsMapFactory::GetForProfile(otr_profile); | 727 HostContentSettingsMapFactory::GetForProfile(otr_profile); |
| 640 | 728 |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1289 base::DictionaryValue test_value; | 1377 base::DictionaryValue test_value; |
| 1290 test_value.SetString("test", "value"); | 1378 test_value.SetString("test", "value"); |
| 1291 host_content_settings_map->SetWebsiteSettingDefaultScope( | 1379 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 1292 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, | 1380 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, |
| 1293 std::string(), base::WrapUnique(test_value.DeepCopy())); | 1381 std::string(), base::WrapUnique(test_value.DeepCopy())); |
| 1294 EXPECT_EQ(nullptr, | 1382 EXPECT_EQ(nullptr, |
| 1295 host_content_settings_map->GetWebsiteSetting( | 1383 host_content_settings_map->GetWebsiteSetting( |
| 1296 unsupported_url, unsupported_url, | 1384 unsupported_url, unsupported_url, |
| 1297 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); | 1385 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); |
| 1298 } | 1386 } |
| OLD | NEW |