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

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

Issue 6410022: Add content_settings::PrefProvider to HostContentSettingsMap. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years, 10 months 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
« no previous file with comments | « chrome/browser/content_settings/pref_content_settings_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/content_settings/pref_content_settings_provider.h" 5 #include "chrome/browser/content_settings/pref_content_settings_provider.h"
6 6
7 #include "base/auto_reset.h"
8 #include "base/command_line.h"
7 #include "chrome/browser/content_settings/host_content_settings_map_unittest.h" 9 #include "chrome/browser/content_settings/host_content_settings_map_unittest.h"
8 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
10 #include "chrome/common/url_constants.h" 13 #include "chrome/common/url_constants.h"
11 #include "chrome/test/testing_pref_service.h" 14 #include "chrome/test/testing_pref_service.h"
12 #include "chrome/test/testing_profile.h" 15 #include "chrome/test/testing_profile.h"
13 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
14 17
15 18
16 namespace content_settings { 19 namespace content_settings {
17 20
18 class PrefDefaultProviderTest : public testing::Test { 21 class PrefDefaultProviderTest : public testing::Test {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 115
113 // Changing content settings on the off-the-record provider should be ignored. 116 // Changing content settings on the off-the-record provider should be ignored.
114 otr_provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES, 117 otr_provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES,
115 CONTENT_SETTING_ALLOW); 118 CONTENT_SETTING_ALLOW);
116 EXPECT_EQ(CONTENT_SETTING_BLOCK, 119 EXPECT_EQ(CONTENT_SETTING_BLOCK,
117 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 120 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
118 EXPECT_EQ(CONTENT_SETTING_BLOCK, 121 EXPECT_EQ(CONTENT_SETTING_BLOCK,
119 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 122 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
120 } 123 }
121 124
125 // ////////////////////////////////////////////////////////////////////////////
126 // PrefProviderTest
127 //
128
129 bool SettingsEqual(const ContentSettings& settings1,
130 const ContentSettings& settings2) {
131 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
132 if (settings1.settings[i] != settings2.settings[i])
133 return false;
134 }
135 return true;
136 }
137
138 class PrefProviderTest : public testing::Test {
139 public:
140 PrefProviderTest() : ui_thread_(
141 BrowserThread::UI, &message_loop_) {
142 }
143
144 protected:
145 MessageLoop message_loop_;
146 BrowserThread ui_thread_;
147 };
148
149 TEST_F(PrefProviderTest, Observer) {
150 TestingProfile profile;
151 Profile* p = &profile;
152 PrefProvider pref_content_settings_provider(p);
153 StubSettingsObserver observer;
154 ContentSettingsPattern pattern("[*.]example.com");
155
156 pref_content_settings_provider.SetContentSetting(
157 pattern,
158 pattern,
159 CONTENT_SETTINGS_TYPE_IMAGES,
160 "",
161 CONTENT_SETTING_ALLOW);
162 EXPECT_EQ(profile.GetHostContentSettingsMap(), observer.last_notifier);
163 EXPECT_EQ(pattern, observer.last_pattern);
164 EXPECT_FALSE(observer.last_update_all);
165 EXPECT_FALSE(observer.last_update_all_types);
166 EXPECT_EQ(1, observer.counter);
167 }
168
169 TEST_F(PrefProviderTest, Patterns) {
170 TestingProfile testing_profile;
171 PrefProvider pref_content_settings_provider(
172 testing_profile.GetOriginalProfile());
173
174 GURL host1("http://example.com/");
175 GURL host2("http://www.example.com/");
176 GURL host3("http://example.org/");
177 ContentSettingsPattern pattern1("[*.]example.com");
178 ContentSettingsPattern pattern2("example.org");
179
180 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
181 pref_content_settings_provider.GetContentSetting(
182 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, ""));
183 pref_content_settings_provider.SetContentSetting(
184 pattern1,
185 pattern1,
186 CONTENT_SETTINGS_TYPE_IMAGES,
187 "",
188 CONTENT_SETTING_BLOCK);
189 EXPECT_EQ(CONTENT_SETTING_BLOCK,
190 pref_content_settings_provider.GetContentSetting(
191 host1, host1, CONTENT_SETTINGS_TYPE_IMAGES, ""));
192 EXPECT_EQ(CONTENT_SETTING_BLOCK,
193 pref_content_settings_provider.GetContentSetting(
194 host2, host2, CONTENT_SETTINGS_TYPE_IMAGES, ""));
195
196 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
197 pref_content_settings_provider.GetContentSetting(
198 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, ""));
199 pref_content_settings_provider.SetContentSetting(
200 pattern2,
201 pattern2,
202 CONTENT_SETTINGS_TYPE_IMAGES,
203 "",
204 CONTENT_SETTING_BLOCK);
205 EXPECT_EQ(CONTENT_SETTING_BLOCK,
206 pref_content_settings_provider.GetContentSetting(
207 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, ""));
208 }
209
210 TEST_F(PrefProviderTest, ResourceIdentifier) {
211 // This feature is currently behind a flag.
212 CommandLine* cmd = CommandLine::ForCurrentProcess();
213 AutoReset<CommandLine> auto_reset(cmd, *cmd);
214 cmd->AppendSwitch(switches::kEnableResourceContentSettings);
215
216 TestingProfile testing_profile;
217 PrefProvider pref_content_settings_provider(
218 testing_profile.GetOriginalProfile());
219
220 GURL host("http://example.com/");
221 ContentSettingsPattern pattern("[*.]example.com");
222 std::string resource1("someplugin");
223 std::string resource2("otherplugin");
224
225 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
226 pref_content_settings_provider.GetContentSetting(
227 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
228 pref_content_settings_provider.SetContentSetting(
229 pattern,
230 pattern,
231 CONTENT_SETTINGS_TYPE_PLUGINS,
232 resource1,
233 CONTENT_SETTING_BLOCK);
234 EXPECT_EQ(CONTENT_SETTING_BLOCK,
235 pref_content_settings_provider.GetContentSetting(
236 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
237 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
238 pref_content_settings_provider.GetContentSetting(
239 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2));
240 }
241
122 } // namespace content_settings 242 } // namespace content_settings
OLDNEW
« no previous file with comments | « chrome/browser/content_settings/pref_content_settings_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698