Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(227)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 8538004: Take script URLs into account when applying script content settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/content_settings/content_settings_details.h" 9 #include "chrome/browser/content_settings/content_settings_details.h"
10 #include "chrome/browser/content_settings/cookie_settings.h" 10 #include "chrome/browser/content_settings/cookie_settings.h"
11 #include "chrome/browser/content_settings/host_content_settings_map.h" 11 #include "chrome/browser/content_settings/host_content_settings_map.h"
12 #include "chrome/browser/content_settings/mock_settings_observer.h" 12 #include "chrome/browser/content_settings/mock_settings_observer.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/prefs/scoped_user_pref_update.h" 14 #include "chrome/browser/prefs/scoped_user_pref_update.h"
15 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
17 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
18 #include "chrome/test/base/testing_pref_service.h" 18 #include "chrome/test/base/testing_pref_service.h"
19 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
20 #include "content/test/test_browser_thread.h" 20 #include "content/test/test_browser_thread.h"
21 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
22 #include "net/base/static_cookie_policy.h" 22 #include "net/base/static_cookie_policy.h"
23 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
24 24
25 using content::BrowserThread; 25 using content::BrowserThread;
26 26
27 using ::testing::_; 27 using ::testing::_;
28 28
29 namespace {
30
31 bool SettingsEqual(const ContentSettings& settings1,
32 const ContentSettings& settings2) {
33 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
34 if (settings1.settings[i] != settings2.settings[i]) {
35 LOG(ERROR) << "type: " << i
36 << " [expected: " << settings1.settings[i]
37 << " actual: " << settings2.settings[i] << "]";
38 return false;
39 }
40 }
41 return true;
42 }
43
44 } // namespace
45
46 class HostContentSettingsMapTest : public testing::Test { 29 class HostContentSettingsMapTest : public testing::Test {
47 public: 30 public:
48 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) { 31 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) {
49 } 32 }
50 33
51 protected: 34 protected:
52 MessageLoop message_loop_; 35 MessageLoop message_loop_;
53 content::TestBrowserThread ui_thread_; 36 content::TestBrowserThread ui_thread_;
54 }; 37 };
55 38
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 std::string(), 102 std::string(),
120 CONTENT_SETTING_BLOCK); 103 CONTENT_SETTING_BLOCK);
121 EXPECT_EQ(CONTENT_SETTING_BLOCK, 104 EXPECT_EQ(CONTENT_SETTING_BLOCK,
122 host_content_settings_map->GetContentSetting( 105 host_content_settings_map->GetContentSetting(
123 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 106 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
124 EXPECT_EQ(CONTENT_SETTING_ALLOW, 107 EXPECT_EQ(CONTENT_SETTING_ALLOW,
125 host_content_settings_map->GetContentSetting( 108 host_content_settings_map->GetContentSetting(
126 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, "")); 109 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, ""));
127 110
128 // Check returning all settings for a host. 111 // Check returning all settings for a host.
129 ContentSettings desired_settings;
130 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES] =
131 CONTENT_SETTING_ALLOW;
132 host_content_settings_map->SetContentSetting( 112 host_content_settings_map->SetContentSetting(
133 pattern, 113 pattern,
134 ContentSettingsPattern::Wildcard(), 114 ContentSettingsPattern::Wildcard(),
135 CONTENT_SETTINGS_TYPE_IMAGES, 115 CONTENT_SETTINGS_TYPE_IMAGES,
136 std::string(), 116 std::string(),
137 CONTENT_SETTING_DEFAULT); 117 CONTENT_SETTING_DEFAULT);
138 desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = 118 EXPECT_EQ(CONTENT_SETTING_ALLOW,
139 CONTENT_SETTING_ALLOW; 119 host_content_settings_map->GetContentSetting(
120 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
140 host_content_settings_map->SetContentSetting( 121 host_content_settings_map->SetContentSetting(
141 pattern, 122 pattern,
142 ContentSettingsPattern::Wildcard(), 123 ContentSettingsPattern::Wildcard(),
143 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 124 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
144 std::string(), 125 std::string(),
145 CONTENT_SETTING_BLOCK); 126 CONTENT_SETTING_BLOCK);
146 desired_settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] = 127 EXPECT_EQ(CONTENT_SETTING_BLOCK,
147 CONTENT_SETTING_BLOCK; 128 host_content_settings_map->GetContentSetting(
129 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, ""));
148 host_content_settings_map->SetContentSetting( 130 host_content_settings_map->SetContentSetting(
149 pattern, 131 pattern,
150 ContentSettingsPattern::Wildcard(), 132 ContentSettingsPattern::Wildcard(),
151 CONTENT_SETTINGS_TYPE_PLUGINS, 133 CONTENT_SETTINGS_TYPE_PLUGINS,
152 std::string(), 134 std::string(),
153 CONTENT_SETTING_ALLOW); 135 CONTENT_SETTING_ALLOW);
154 desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] = 136 EXPECT_EQ(CONTENT_SETTING_ALLOW,
155 CONTENT_SETTING_ALLOW; 137 host_content_settings_map->GetContentSetting(
156 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = 138 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, ""));
157 CONTENT_SETTING_BLOCK; 139 EXPECT_EQ(CONTENT_SETTING_BLOCK,
158 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = 140 host_content_settings_map->GetContentSetting(
159 CONTENT_SETTING_ASK; 141 host, host, CONTENT_SETTINGS_TYPE_POPUPS, ""));
160 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = 142 EXPECT_EQ(CONTENT_SETTING_ASK,
161 CONTENT_SETTING_ASK; 143 host_content_settings_map->GetContentSetting(
162 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = 144 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
163 CONTENT_SETTING_ASK; 145 EXPECT_EQ(CONTENT_SETTING_ASK,
164 desired_settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN] = 146 host_content_settings_map->GetContentSetting(
165 CONTENT_SETTING_ASK; 147 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, ""));
166 desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK] = 148 EXPECT_EQ(CONTENT_SETTING_ASK,
167 CONTENT_SETTING_ASK; 149 host_content_settings_map->GetContentSetting(
168 ContentSettings settings = 150 host, host, CONTENT_SETTINGS_TYPE_INTENTS, ""));
169 host_content_settings_map->GetContentSettings(host); 151 EXPECT_EQ(CONTENT_SETTING_ASK,
170 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); 152 host_content_settings_map->GetContentSetting(
153 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, ""));
154 EXPECT_EQ(CONTENT_SETTING_ASK,
155 host_content_settings_map->GetContentSetting(
156 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, ""));
171 157
172 // Check returning all hosts for a setting. 158 // Check returning all hosts for a setting.
173 ContentSettingsPattern pattern2 = 159 ContentSettingsPattern pattern2 =
174 ContentSettingsPattern::FromString("[*.]example.org"); 160 ContentSettingsPattern::FromString("[*.]example.org");
175 host_content_settings_map->SetContentSetting( 161 host_content_settings_map->SetContentSetting(
176 pattern2, 162 pattern2,
177 ContentSettingsPattern::Wildcard(), 163 ContentSettingsPattern::Wildcard(),
178 CONTENT_SETTINGS_TYPE_IMAGES, 164 CONTENT_SETTINGS_TYPE_IMAGES,
179 std::string(), 165 std::string(),
180 CONTENT_SETTING_BLOCK); 166 CONTENT_SETTING_BLOCK);
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 582
597 host_content_settings_map->SetContentSetting( 583 host_content_settings_map->SetContentSetting(
598 pattern3, 584 pattern3,
599 ContentSettingsPattern::Wildcard(), 585 ContentSettingsPattern::Wildcard(),
600 CONTENT_SETTINGS_TYPE_PLUGINS, 586 CONTENT_SETTINGS_TYPE_PLUGINS,
601 "", 587 "",
602 CONTENT_SETTING_BLOCK); 588 CONTENT_SETTING_BLOCK);
603 host_content_settings_map->SetDefaultContentSetting( 589 host_content_settings_map->SetDefaultContentSetting(
604 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 590 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
605 591
606 ContentSettings desired_settings; 592 EXPECT_EQ(CONTENT_SETTING_BLOCK,
607 desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES] = 593 host_content_settings_map->GetContentSetting(
608 CONTENT_SETTING_BLOCK; 594 host, host, CONTENT_SETTINGS_TYPE_COOKIES, ""));
609 desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES] = 595 EXPECT_EQ(CONTENT_SETTING_BLOCK,
610 CONTENT_SETTING_BLOCK; 596 host_content_settings_map->GetContentSetting(
611 desired_settings.settings[CONTENT_SETTINGS_TYPE_JAVASCRIPT] = 597 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
612 CONTENT_SETTING_BLOCK; 598 EXPECT_EQ(CONTENT_SETTING_BLOCK,
613 desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS] = 599 host_content_settings_map->GetContentSetting(
614 CONTENT_SETTING_BLOCK; 600 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, ""));
615 desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS] = 601 EXPECT_EQ(CONTENT_SETTING_BLOCK,
616 CONTENT_SETTING_BLOCK; 602 host_content_settings_map->GetContentSetting(
617 desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION] = 603 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, ""));
618 CONTENT_SETTING_ASK; 604 EXPECT_EQ(CONTENT_SETTING_BLOCK,
619 desired_settings.settings[CONTENT_SETTINGS_TYPE_NOTIFICATIONS] = 605 host_content_settings_map->GetContentSetting(
620 CONTENT_SETTING_ASK; 606 host, host, CONTENT_SETTINGS_TYPE_POPUPS, ""));
621 desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS] = 607 EXPECT_EQ(CONTENT_SETTING_ASK,
622 CONTENT_SETTING_ASK; 608 host_content_settings_map->GetContentSetting(
623 desired_settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN] = 609 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
624 CONTENT_SETTING_ASK; 610 EXPECT_EQ(CONTENT_SETTING_ASK,
625 desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK] = 611 host_content_settings_map->GetContentSetting(
626 CONTENT_SETTING_ASK; 612 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, ""));
627 ContentSettings settings = 613 EXPECT_EQ(CONTENT_SETTING_ASK,
628 host_content_settings_map->GetContentSettings(host); 614 host_content_settings_map->GetContentSetting(
629 EXPECT_TRUE(SettingsEqual(desired_settings, settings)); 615 host, host, CONTENT_SETTINGS_TYPE_INTENTS, ""));
630 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES], 616 EXPECT_EQ(CONTENT_SETTING_ASK,
631 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]); 617 host_content_settings_map->GetContentSetting(
632 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_IMAGES], 618 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, ""));
633 settings.settings[CONTENT_SETTINGS_TYPE_IMAGES]); 619 EXPECT_EQ(CONTENT_SETTING_ASK,
634 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS], 620 host_content_settings_map->GetContentSetting(
635 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); 621 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, ""));
636 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_POPUPS],
637 settings.settings[CONTENT_SETTINGS_TYPE_POPUPS]);
638 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION],
639 settings.settings[CONTENT_SETTINGS_TYPE_GEOLOCATION]);
640 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_COOKIES],
641 settings.settings[CONTENT_SETTINGS_TYPE_COOKIES]);
642 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_INTENTS],
643 settings.settings[CONTENT_SETTINGS_TYPE_INTENTS]);
644 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN],
645 settings.settings[CONTENT_SETTINGS_TYPE_FULLSCREEN]);
646 EXPECT_EQ(desired_settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK],
647 settings.settings[CONTENT_SETTINGS_TYPE_MOUSELOCK]);
648 } 622 }
649 623
650 TEST_F(HostContentSettingsMapTest, OffTheRecord) { 624 TEST_F(HostContentSettingsMapTest, OffTheRecord) {
651 TestingProfile profile; 625 TestingProfile profile;
652 HostContentSettingsMap* host_content_settings_map = 626 HostContentSettingsMap* host_content_settings_map =
653 profile.GetHostContentSettingsMap(); 627 profile.GetHostContentSettingsMap();
654 scoped_refptr<HostContentSettingsMap> otr_map( 628 scoped_refptr<HostContentSettingsMap> otr_map(
655 new HostContentSettingsMap(profile.GetPrefs(), 629 new HostContentSettingsMap(profile.GetPrefs(),
656 profile.GetExtensionService(), 630 profile.GetExtensionService(),
657 true)); 631 true));
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 ContentSettingsPattern pattern = 781 ContentSettingsPattern pattern =
808 ContentSettingsPattern::FromString("[*.]example.com"); 782 ContentSettingsPattern::FromString("[*.]example.com");
809 std::string resource1("someplugin"); 783 std::string resource1("someplugin");
810 std::string resource2("otherplugin"); 784 std::string resource2("otherplugin");
811 785
812 // If resource content settings are enabled, GetContentSettings should return 786 // If resource content settings are enabled, GetContentSettings should return
813 // the default values for all plugins 787 // the default values for all plugins
814 ContentSetting default_plugin_setting = 788 ContentSetting default_plugin_setting =
815 host_content_settings_map->GetDefaultContentSetting( 789 host_content_settings_map->GetDefaultContentSetting(
816 CONTENT_SETTINGS_TYPE_PLUGINS, NULL); 790 CONTENT_SETTINGS_TYPE_PLUGINS, NULL);
817 ContentSettings settings =
818 host_content_settings_map->GetContentSettings(host);
819 EXPECT_EQ(default_plugin_setting, 791 EXPECT_EQ(default_plugin_setting,
820 settings.settings[CONTENT_SETTINGS_TYPE_PLUGINS]); 792 host_content_settings_map->GetContentSetting(
793 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, ""));
821 794
822 // If no resource-specific content settings are defined, the setting should be 795 // If no resource-specific content settings are defined, the setting should be
823 // DEFAULT. 796 // DEFAULT.
824 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 797 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
825 host_content_settings_map->GetContentSetting( 798 host_content_settings_map->GetContentSetting(
826 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); 799 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
827 800
828 host_content_settings_map->SetContentSetting( 801 host_content_settings_map->SetContentSetting(
829 pattern, 802 pattern,
830 ContentSettingsPattern::Wildcard(), 803 ContentSettingsPattern::Wildcard(),
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 CONTENT_SETTINGS_TYPE_IMAGES, 1054 CONTENT_SETTINGS_TYPE_IMAGES,
1082 std::string(), 1055 std::string(),
1083 CONTENT_SETTING_BLOCK); 1056 CONTENT_SETTING_BLOCK);
1084 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1057 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1085 host_content_settings_map->GetContentSetting( 1058 host_content_settings_map->GetContentSetting(
1086 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 1059 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
1087 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1060 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1088 host_content_settings_map->GetContentSetting( 1061 host_content_settings_map->GetContentSetting(
1089 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 1062 embedder, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
1090 } 1063 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698