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/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, | 83 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, |
| 84 host_content_settings_map->GetDefaultContentSetting( | 84 host_content_settings_map->GetDefaultContentSetting( |
| 85 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 85 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
| 86 #endif | 86 #endif |
| 87 | 87 |
| 88 host_content_settings_map->SetDefaultContentSetting( | 88 host_content_settings_map->SetDefaultContentSetting( |
| 89 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); | 89 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); |
| 90 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 90 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 91 host_content_settings_map->GetDefaultContentSetting( | 91 host_content_settings_map->GetDefaultContentSetting( |
| 92 CONTENT_SETTINGS_TYPE_POPUPS, NULL)); | 92 CONTENT_SETTINGS_TYPE_POPUPS, NULL)); |
| 93 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 94 host_content_settings_map->GetDefaultContentSetting( | |
| 95 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); | |
| 93 } | 96 } |
| 94 | 97 |
| 95 TEST_F(HostContentSettingsMapTest, IndividualSettings) { | 98 TEST_F(HostContentSettingsMapTest, IndividualSettings) { |
| 96 TestingProfile profile; | 99 TestingProfile profile; |
| 97 HostContentSettingsMap* host_content_settings_map = | 100 HostContentSettingsMap* host_content_settings_map = |
| 98 HostContentSettingsMapFactory::GetForProfile(&profile); | 101 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 99 | 102 |
| 100 // Check returning individual settings. | 103 // Check returning individual settings. |
| 101 GURL host("http://example.com/"); | 104 GURL host("http://example.com/"); |
| 102 ContentSettingsPattern pattern = | 105 ContentSettingsPattern pattern = |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 EXPECT_EQ( | 170 EXPECT_EQ( |
| 168 CONTENT_SETTING_ASK, | 171 CONTENT_SETTING_ASK, |
| 169 host_content_settings_map->GetContentSetting( | 172 host_content_settings_map->GetContentSetting( |
| 170 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | 173 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 171 EXPECT_EQ(CONTENT_SETTING_ASK, | 174 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 172 host_content_settings_map->GetContentSetting( | 175 host_content_settings_map->GetContentSetting( |
| 173 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); | 176 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); |
| 174 EXPECT_EQ(CONTENT_SETTING_ASK, | 177 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 175 host_content_settings_map->GetContentSetting( | 178 host_content_settings_map->GetContentSetting( |
| 176 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); | 179 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); |
| 180 host_content_settings_map->SetContentSetting( | |
| 181 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, | |
| 182 std::string(), CONTENT_SETTING_BLOCK); | |
| 183 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 184 host_content_settings_map->GetContentSetting( | |
| 185 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | |
| 177 | 186 |
| 178 // Check returning all hosts for a setting. | 187 // Check returning all hosts for a setting. |
| 179 ContentSettingsPattern pattern2 = | 188 ContentSettingsPattern pattern2 = |
| 180 ContentSettingsPattern::FromString("[*.]example.org"); | 189 ContentSettingsPattern::FromString("[*.]example.org"); |
| 181 host_content_settings_map->SetContentSetting( | 190 host_content_settings_map->SetContentSetting( |
| 182 pattern2, | 191 pattern2, |
| 183 ContentSettingsPattern::Wildcard(), | 192 ContentSettingsPattern::Wildcard(), |
| 184 CONTENT_SETTINGS_TYPE_IMAGES, | 193 CONTENT_SETTINGS_TYPE_IMAGES, |
| 185 std::string(), | 194 std::string(), |
| 186 CONTENT_SETTING_BLOCK); | 195 CONTENT_SETTING_BLOCK); |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 570 ContentSettingsPattern::Wildcard(), | 579 ContentSettingsPattern::Wildcard(), |
| 571 CONTENT_SETTINGS_TYPE_POPUPS, | 580 CONTENT_SETTINGS_TYPE_POPUPS, |
| 572 std::string(), | 581 std::string(), |
| 573 CONTENT_SETTING_ALLOW); | 582 CONTENT_SETTING_ALLOW); |
| 574 EXPECT_EQ( | 583 EXPECT_EQ( |
| 575 CONTENT_SETTING_ALLOW, | 584 CONTENT_SETTING_ALLOW, |
| 576 host_content_settings_map->GetContentSetting(host_ending_with_dot, | 585 host_content_settings_map->GetContentSetting(host_ending_with_dot, |
| 577 host_ending_with_dot, | 586 host_ending_with_dot, |
| 578 CONTENT_SETTINGS_TYPE_POPUPS, | 587 CONTENT_SETTINGS_TYPE_POPUPS, |
| 579 std::string())); | 588 std::string())); |
| 589 | |
| 590 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 591 host_content_settings_map->GetContentSetting( | |
| 592 host_ending_with_dot, host_ending_with_dot, | |
| 593 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | |
| 594 host_content_settings_map->SetContentSetting( | |
| 595 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, | |
| 596 std::string(), CONTENT_SETTING_DEFAULT); | |
| 597 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 598 host_content_settings_map->GetContentSetting( | |
| 599 host_ending_with_dot, host_ending_with_dot, | |
| 600 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | |
| 601 host_content_settings_map->SetContentSetting( | |
| 602 pattern, ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_KEYGEN, | |
| 603 std::string(), CONTENT_SETTING_BLOCK); | |
| 604 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 605 host_content_settings_map->GetContentSetting( | |
| 606 host_ending_with_dot, host_ending_with_dot, | |
| 607 CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | |
| 580 } | 608 } |
| 581 | 609 |
| 582 TEST_F(HostContentSettingsMapTest, NestedSettings) { | 610 TEST_F(HostContentSettingsMapTest, NestedSettings) { |
| 583 TestingProfile profile; | 611 TestingProfile profile; |
| 584 HostContentSettingsMap* host_content_settings_map = | 612 HostContentSettingsMap* host_content_settings_map = |
| 585 HostContentSettingsMapFactory::GetForProfile(&profile); | 613 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 586 | 614 |
| 587 GURL host("http://a.b.example.com/"); | 615 GURL host("http://a.b.example.com/"); |
| 588 ContentSettingsPattern pattern1 = | 616 ContentSettingsPattern pattern1 = |
| 589 ContentSettingsPattern::FromString("[*.]example.com"); | 617 ContentSettingsPattern::FromString("[*.]example.com"); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 EXPECT_EQ( | 664 EXPECT_EQ( |
| 637 CONTENT_SETTING_ASK, | 665 CONTENT_SETTING_ASK, |
| 638 host_content_settings_map->GetContentSetting( | 666 host_content_settings_map->GetContentSetting( |
| 639 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); | 667 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| 640 EXPECT_EQ(CONTENT_SETTING_ASK, | 668 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 641 host_content_settings_map->GetContentSetting( | 669 host_content_settings_map->GetContentSetting( |
| 642 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); | 670 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); |
| 643 EXPECT_EQ(CONTENT_SETTING_ASK, | 671 EXPECT_EQ(CONTENT_SETTING_ASK, |
| 644 host_content_settings_map->GetContentSetting( | 672 host_content_settings_map->GetContentSetting( |
| 645 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); | 673 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); |
| 674 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 675 host_content_settings_map->GetContentSetting( | |
| 676 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | |
| 646 } | 677 } |
| 647 | 678 |
| 648 TEST_F(HostContentSettingsMapTest, OffTheRecord) { | 679 TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
| 649 TestingProfile profile; | 680 TestingProfile profile; |
| 650 HostContentSettingsMap* host_content_settings_map = | 681 HostContentSettingsMap* host_content_settings_map = |
| 651 HostContentSettingsMapFactory::GetForProfile(&profile); | 682 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 652 scoped_refptr<HostContentSettingsMap> otr_map( | 683 scoped_refptr<HostContentSettingsMap> otr_map( |
| 653 new HostContentSettingsMap(profile.GetPrefs(), | 684 new HostContentSettingsMap(profile.GetPrefs(), |
| 654 true)); | 685 true)); |
| 655 | 686 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 786 host_content_settings_map->GetDefaultContentSetting( | 817 host_content_settings_map->GetDefaultContentSetting( |
| 787 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 818 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
| 788 | 819 |
| 789 #if defined(ENABLE_PLUGINS) | 820 #if defined(ENABLE_PLUGINS) |
| 790 // Remove the preference to manage the default-content-setting for Plugins. | 821 // Remove the preference to manage the default-content-setting for Plugins. |
| 791 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); | 822 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); |
| 792 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, | 823 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, |
| 793 host_content_settings_map->GetDefaultContentSetting( | 824 host_content_settings_map->GetDefaultContentSetting( |
| 794 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); | 825 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); |
| 795 #endif | 826 #endif |
| 827 | |
| 828 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 829 host_content_settings_map->GetDefaultContentSetting( | |
| 830 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); | |
| 831 | |
| 832 // Set managed-default-content-setting through the coresponding preferences. | |
| 833 prefs->SetManagedPref(prefs::kManagedDefaultKeygenSetting, | |
| 834 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); | |
| 835 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 836 host_content_settings_map->GetDefaultContentSetting( | |
| 837 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); | |
| 838 | |
| 839 // Remove managed-default-content-settings-preferences. | |
|
Bernhard Bauer
2015/11/06 11:36:53
Nit: there are way too many dashes here 😉
svaldez
2015/11/06 14:40:45
Done.
| |
| 840 prefs->RemoveManagedPref(prefs::kManagedDefaultKeygenSetting); | |
| 841 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
| 842 host_content_settings_map->GetDefaultContentSetting( | |
| 843 CONTENT_SETTINGS_TYPE_KEYGEN, NULL)); | |
| 796 } | 844 } |
| 797 | 845 |
| 798 TEST_F(HostContentSettingsMapTest, | 846 TEST_F(HostContentSettingsMapTest, |
| 799 GetNonDefaultContentSettingsIfTypeManaged) { | 847 GetNonDefaultContentSettingsIfTypeManaged) { |
| 800 TestingProfile profile; | 848 TestingProfile profile; |
| 801 HostContentSettingsMap* host_content_settings_map = | 849 HostContentSettingsMap* host_content_settings_map = |
| 802 HostContentSettingsMapFactory::GetForProfile(&profile); | 850 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 803 syncable_prefs::TestingPrefServiceSyncable* prefs = | 851 syncable_prefs::TestingPrefServiceSyncable* prefs = |
| 804 profile.GetTestingPrefService(); | 852 profile.GetTestingPrefService(); |
| 805 | 853 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 985 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1033 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 986 host_content_settings_map->GetContentSetting( | 1034 host_content_settings_map->GetContentSetting( |
| 987 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); | 1035 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| 988 host_content_settings_map->SetContentSetting( | 1036 host_content_settings_map->SetContentSetting( |
| 989 pattern, | 1037 pattern, |
| 990 ContentSettingsPattern::Wildcard(), | 1038 ContentSettingsPattern::Wildcard(), |
| 991 CONTENT_SETTINGS_TYPE_IMAGES, | 1039 CONTENT_SETTINGS_TYPE_IMAGES, |
| 992 std::string(), | 1040 std::string(), |
| 993 CONTENT_SETTING_DEFAULT); | 1041 CONTENT_SETTING_DEFAULT); |
| 994 } | 1042 } |
| OLD | NEW |