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

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

Issue 7218073: Explicitly ShutdownOnUIThread the HostContentSettingsMap when destroying the Profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 9 years, 5 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
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 "chrome/browser/content_settings/content_settings_pref_provider.h" 5 #include "chrome/browser/content_settings/content_settings_pref_provider.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "chrome/browser/content_settings/mock_settings_observer.h" 9 #include "chrome/browser/content_settings/mock_settings_observer.h"
10 #include "chrome/browser/prefs/browser_prefs.h" 10 #include "chrome/browser/prefs/browser_prefs.h"
(...skipping 12 matching lines...) Expand all
23 #include "googleurl/src/gurl.h" 23 #include "googleurl/src/gurl.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 25
26 using ::testing::_; 26 using ::testing::_;
27 27
28 namespace content_settings { 28 namespace content_settings {
29 29
30 class PrefDefaultProviderTest : public TestingBrowserProcessTest { 30 class PrefDefaultProviderTest : public TestingBrowserProcessTest {
31 public: 31 public:
32 PrefDefaultProviderTest() 32 PrefDefaultProviderTest()
33 : ui_thread_(BrowserThread::UI, &message_loop_) { 33 : ui_thread_(BrowserThread::UI, &message_loop_),
34 provider_(profile_.GetHostContentSettingsMap(),
35 profile_.GetPrefs(),
36 false) {
37 }
38 ~PrefDefaultProviderTest() {
39 provider_.ShutdownOnUIThread();
34 } 40 }
35 41
36 protected: 42 protected:
37 MessageLoop message_loop_; 43 MessageLoop message_loop_;
38 BrowserThread ui_thread_; 44 BrowserThread ui_thread_;
45 TestingProfile profile_;
46 PrefDefaultProvider provider_;
39 }; 47 };
40 48
41 TEST_F(PrefDefaultProviderTest, DefaultValues) { 49 TEST_F(PrefDefaultProviderTest, DefaultValues) {
42 TestingProfile profile;
43 content_settings::PrefDefaultProvider provider(&profile);
44
45 ASSERT_FALSE( 50 ASSERT_FALSE(
46 provider.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES)); 51 provider_.DefaultSettingIsManaged(CONTENT_SETTINGS_TYPE_COOKIES));
47 52
48 // Check setting defaults. 53 // Check setting defaults.
49 EXPECT_EQ(CONTENT_SETTING_ALLOW, 54 EXPECT_EQ(CONTENT_SETTING_ALLOW,
50 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 55 provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
51 provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES, 56 provider_.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES,
52 CONTENT_SETTING_BLOCK); 57 CONTENT_SETTING_BLOCK);
53 EXPECT_EQ(CONTENT_SETTING_BLOCK, 58 EXPECT_EQ(CONTENT_SETTING_BLOCK,
54 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 59 provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
55 } 60 }
56 61
57 TEST_F(PrefDefaultProviderTest, Observer) { 62 TEST_F(PrefDefaultProviderTest, Observer) {
58 TestingProfile profile;
59 PrefDefaultProvider provider(&profile);
60 MockSettingsObserver observer; 63 MockSettingsObserver observer;
61 64
62 EXPECT_CALL(observer, 65 EXPECT_CALL(observer,
63 OnContentSettingsChanged(profile.GetHostContentSettingsMap(), 66 OnContentSettingsChanged(profile_.GetHostContentSettingsMap(),
64 CONTENT_SETTINGS_TYPE_IMAGES, false, 67 CONTENT_SETTINGS_TYPE_IMAGES, false,
65 _, _, true)); 68 _, _, true));
66 // Expect a second call because the PrefDefaultProvider in the TestingProfile 69 // Expect a second call because the PrefDefaultProvider in the TestingProfile
67 // also observes the default content settings preference. 70 // also observes the default content settings preference.
68 EXPECT_CALL(observer, 71 EXPECT_CALL(observer,
69 OnContentSettingsChanged(profile.GetHostContentSettingsMap(), 72 OnContentSettingsChanged(profile_.GetHostContentSettingsMap(),
70 CONTENT_SETTINGS_TYPE_DEFAULT, true, 73 CONTENT_SETTINGS_TYPE_DEFAULT, true,
71 _, _, true)); 74 _, _, true));
72 provider.UpdateDefaultSetting( 75 provider_.UpdateDefaultSetting(
73 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 76 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
74 } 77 }
75 78
76 TEST_F(PrefDefaultProviderTest, ObserveDefaultPref) { 79 TEST_F(PrefDefaultProviderTest, ObserveDefaultPref) {
77 TestingProfile profile; 80 PrefService* prefs = profile_.GetPrefs();
78 PrefDefaultProvider provider(&profile);
79
80 PrefService* prefs = profile.GetPrefs();
81 81
82 // Make a copy of the default pref value so we can reset it later. 82 // Make a copy of the default pref value so we can reset it later.
83 scoped_ptr<Value> default_value(prefs->FindPreference( 83 scoped_ptr<Value> default_value(prefs->FindPreference(
84 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 84 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
85 85
86 provider.UpdateDefaultSetting( 86 provider_.UpdateDefaultSetting(
87 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); 87 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
88 EXPECT_EQ(CONTENT_SETTING_BLOCK, 88 EXPECT_EQ(CONTENT_SETTING_BLOCK,
89 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 89 provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
90 90
91 // Make a copy of the pref's new value so we can reset it later. 91 // Make a copy of the pref's new value so we can reset it later.
92 scoped_ptr<Value> new_value(prefs->FindPreference( 92 scoped_ptr<Value> new_value(prefs->FindPreference(
93 prefs::kDefaultContentSettings)->GetValue()->DeepCopy()); 93 prefs::kDefaultContentSettings)->GetValue()->DeepCopy());
94 94
95 // Clearing the backing pref should also clear the internal cache. 95 // Clearing the backing pref should also clear the internal cache.
96 prefs->Set(prefs::kDefaultContentSettings, *default_value); 96 prefs->Set(prefs::kDefaultContentSettings, *default_value);
97 EXPECT_EQ(CONTENT_SETTING_ALLOW, 97 EXPECT_EQ(CONTENT_SETTING_ALLOW,
98 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 98 provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
99 99
100 // Reseting the pref to its previous value should update the cache. 100 // Reseting the pref to its previous value should update the cache.
101 prefs->Set(prefs::kDefaultContentSettings, *new_value); 101 prefs->Set(prefs::kDefaultContentSettings, *new_value);
102 EXPECT_EQ(CONTENT_SETTING_BLOCK, 102 EXPECT_EQ(CONTENT_SETTING_BLOCK,
103 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 103 provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
104 } 104 }
105 105
106 TEST_F(PrefDefaultProviderTest, OffTheRecord) { 106 TEST_F(PrefDefaultProviderTest, OffTheRecord) {
107 TestingProfile profile; 107 PrefDefaultProvider otr_provider(profile_.GetHostContentSettingsMap(),
108 PrefDefaultProvider provider(&profile); 108 profile_.GetPrefs(),
109 109 true);
110 profile.set_incognito(true);
111 PrefDefaultProvider otr_provider(&profile);
112 profile.set_incognito(false);
113 110
114 EXPECT_EQ(CONTENT_SETTING_ALLOW, 111 EXPECT_EQ(CONTENT_SETTING_ALLOW,
115 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 112 provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
116 EXPECT_EQ(CONTENT_SETTING_ALLOW, 113 EXPECT_EQ(CONTENT_SETTING_ALLOW,
117 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 114 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
118 115
119 // Changing content settings on the main provider should also affect the 116 // Changing content settings on the main provider should also affect the
120 // incognito map. 117 // incognito map.
121 provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES, 118 provider_.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES,
122 CONTENT_SETTING_BLOCK); 119 CONTENT_SETTING_BLOCK);
123 EXPECT_EQ(CONTENT_SETTING_BLOCK, 120 EXPECT_EQ(CONTENT_SETTING_BLOCK,
124 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 121 provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
125 EXPECT_EQ(CONTENT_SETTING_BLOCK, 122 EXPECT_EQ(CONTENT_SETTING_BLOCK,
126 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 123 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
127 124
128 // Changing content settings on the incognito provider should be ignored. 125 // Changing content settings on the incognito provider should be ignored.
129 otr_provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES, 126 otr_provider.UpdateDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES,
130 CONTENT_SETTING_ALLOW); 127 CONTENT_SETTING_ALLOW);
131 EXPECT_EQ(CONTENT_SETTING_BLOCK, 128 EXPECT_EQ(CONTENT_SETTING_BLOCK,
132 provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 129 provider_.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
133 EXPECT_EQ(CONTENT_SETTING_BLOCK, 130 EXPECT_EQ(CONTENT_SETTING_BLOCK,
134 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES)); 131 otr_provider.ProvideDefaultSetting(CONTENT_SETTINGS_TYPE_COOKIES));
132
133 otr_provider.ShutdownOnUIThread();
135 } 134 }
136 135
137 // //////////////////////////////////////////////////////////////////////////// 136 // ////////////////////////////////////////////////////////////////////////////
138 // PrefProviderTest 137 // PrefProviderTest
139 // 138 //
140 139
141 bool SettingsEqual(const ContentSettings& settings1, 140 bool SettingsEqual(const ContentSettings& settings1,
142 const ContentSettings& settings2) { 141 const ContentSettings& settings2) {
143 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { 142 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
144 if (settings1.settings[i] != settings2.settings[i]) 143 if (settings1.settings[i] != settings2.settings[i])
145 return false; 144 return false;
146 } 145 }
147 return true; 146 return true;
148 } 147 }
149 148
150 class PrefProviderTest : public TestingBrowserProcessTest { 149 class PrefProviderTest : public TestingBrowserProcessTest {
151 public: 150 public:
152 PrefProviderTest() : ui_thread_( 151 PrefProviderTest() : ui_thread_(
153 BrowserThread::UI, &message_loop_) { 152 BrowserThread::UI, &message_loop_) {
154 } 153 }
155 154
156 protected: 155 protected:
157 MessageLoop message_loop_; 156 MessageLoop message_loop_;
158 BrowserThread ui_thread_; 157 BrowserThread ui_thread_;
159 }; 158 };
160 159
161 TEST_F(PrefProviderTest, Observer) { 160 TEST_F(PrefProviderTest, Observer) {
162 TestingProfile profile; 161 TestingProfile profile;
163 // Get the |HostContentSettingsMap| one time in order to initialize it. 162 PrefProvider pref_content_settings_provider(
164 // Otherwise we end up in a dead lock when the |PrefProvider| tries to notify 163 profile.GetHostContentSettingsMap(), profile.GetPrefs(), false);
165 // content settings change observers. The |PrefProvider| set's the
166 // |HostContentSettingsMap| as notification source and would trigger in
167 // infinite recursive instantiation loop.
168 // TODO(markusheintz): Let the HostContentSettingsMap sent out notifications.
169 // Providers and HostContentSettingsMap should communicate via a observer
170 // pattern.
171 profile.GetHostContentSettingsMap();
172 Profile* p = &profile;
173 PrefProvider pref_content_settings_provider(p);
174 MockSettingsObserver observer; 164 MockSettingsObserver observer;
175 ContentSettingsPattern pattern = 165 ContentSettingsPattern pattern =
176 ContentSettingsPattern::FromString("[*.]example.com"); 166 ContentSettingsPattern::FromString("[*.]example.com");
177 167
178 // There are two PrefProvider instances, one in the host content settings map 168 // There are two PrefProvider instances, one in the host content settings map
179 // and one instance that is created here. Setting a content setting will fire 169 // and one instance that is created here. Setting a content setting will fire
180 // one notification. This will change the underlying preferences which will 170 // one notification. This will change the underlying preferences which will
181 // cause the second PrefProvider instance to reload these and to 171 // cause the second PrefProvider instance to reload these and to
182 // sync the obsolete prefences. Hence we get two more notifications which we 172 // sync the obsolete prefences. Hence we get two more notifications which we
183 // will not get in the real world. 173 // will not get in the real world.
184 EXPECT_CALL(observer, 174 EXPECT_CALL(observer,
185 OnContentSettingsChanged(profile.GetHostContentSettingsMap(), 175 OnContentSettingsChanged(profile.GetHostContentSettingsMap(),
186 CONTENT_SETTINGS_TYPE_IMAGES, 176 CONTENT_SETTINGS_TYPE_IMAGES,
187 false, 177 false,
188 pattern, 178 pattern,
189 ContentSettingsPattern::Wildcard(), 179 ContentSettingsPattern::Wildcard(),
190 false)); 180 false));
191 EXPECT_CALL(observer, 181 EXPECT_CALL(observer,
192 OnContentSettingsChanged(profile.GetHostContentSettingsMap(), 182 OnContentSettingsChanged(profile.GetHostContentSettingsMap(),
193 CONTENT_SETTINGS_TYPE_DEFAULT, true, 183 CONTENT_SETTINGS_TYPE_DEFAULT, true,
194 _, _, true)).Times(2); 184 _, _, true)).Times(2);
195 pref_content_settings_provider.SetContentSetting( 185 pref_content_settings_provider.SetContentSetting(
196 pattern, 186 pattern,
197 ContentSettingsPattern::Wildcard(), 187 ContentSettingsPattern::Wildcard(),
198 CONTENT_SETTINGS_TYPE_IMAGES, 188 CONTENT_SETTINGS_TYPE_IMAGES,
199 "", 189 "",
200 CONTENT_SETTING_ALLOW); 190 CONTENT_SETTING_ALLOW);
191
192 pref_content_settings_provider.ShutdownOnUIThread();
201 } 193 }
202 194
203 // Test for regression in which the PrefProvider modified the user pref store 195 // Test for regression in which the PrefProvider modified the user pref store
204 // of the OTR unintentionally: http://crbug.com/74466. 196 // of the OTR unintentionally: http://crbug.com/74466.
205 TEST_F(PrefProviderTest, Incognito) { 197 TEST_F(PrefProviderTest, Incognito) {
206 PersistentPrefStore* user_prefs = new TestingPrefStore(); 198 PersistentPrefStore* user_prefs = new TestingPrefStore();
207 OverlayPersistentPrefStore* otr_user_prefs = 199 OverlayPersistentPrefStore* otr_user_prefs =
208 new OverlayPersistentPrefStore(user_prefs); 200 new OverlayPersistentPrefStore(user_prefs);
209 201
210 PrefServiceMockBuilder builder; 202 PrefServiceMockBuilder builder;
211 PrefService* regular_prefs = builder.WithUserPrefs(user_prefs).Create(); 203 PrefService* regular_prefs = builder.WithUserPrefs(user_prefs).Create();
212 204
213 Profile::RegisterUserPrefs(regular_prefs); 205 Profile::RegisterUserPrefs(regular_prefs);
214 browser::RegisterUserPrefs(regular_prefs); 206 browser::RegisterUserPrefs(regular_prefs);
215 207
216 PrefService* otr_prefs = builder.WithUserPrefs(otr_user_prefs).Create(); 208 PrefService* otr_prefs = builder.WithUserPrefs(otr_user_prefs).Create();
217 209
218 Profile::RegisterUserPrefs(otr_prefs); 210 Profile::RegisterUserPrefs(otr_prefs);
219 browser::RegisterUserPrefs(otr_prefs); 211 browser::RegisterUserPrefs(otr_prefs);
220 212
221 TestingProfile profile; 213 TestingProfile profile;
222 TestingProfile* otr_profile = new TestingProfile; 214 TestingProfile* otr_profile = new TestingProfile;
223 profile.SetOffTheRecordProfile(otr_profile); 215 profile.SetOffTheRecordProfile(otr_profile);
224 profile.SetPrefService(regular_prefs); 216 profile.SetPrefService(regular_prefs);
225 otr_profile->set_incognito(true); 217 otr_profile->set_incognito(true);
226 otr_profile->SetPrefService(otr_prefs); 218 otr_profile->SetPrefService(otr_prefs);
227 profile.GetHostContentSettingsMap();
228 219
229 PrefProvider pref_content_settings_provider(&profile); 220 PrefProvider pref_content_settings_provider(
230 PrefProvider pref_content_settings_provider_incognito(otr_profile); 221 profile.GetHostContentSettingsMap(), regular_prefs, false);
222 PrefProvider pref_content_settings_provider_incognito(
223 otr_profile->GetHostContentSettingsMap(), otr_prefs, true);
231 ContentSettingsPattern pattern = 224 ContentSettingsPattern pattern =
232 ContentSettingsPattern::FromString("[*.]example.com"); 225 ContentSettingsPattern::FromString("[*.]example.com");
233 pref_content_settings_provider.SetContentSetting( 226 pref_content_settings_provider.SetContentSetting(
234 pattern, 227 pattern,
235 pattern, 228 pattern,
236 CONTENT_SETTINGS_TYPE_IMAGES, 229 CONTENT_SETTINGS_TYPE_IMAGES,
237 "", 230 "",
238 CONTENT_SETTING_ALLOW); 231 CONTENT_SETTING_ALLOW);
239 232
240 GURL host("http://example.com/"); 233 GURL host("http://example.com/");
241 // The value should of course be visible in the regular PrefProvider. 234 // The value should of course be visible in the regular PrefProvider.
242 EXPECT_EQ(CONTENT_SETTING_ALLOW, 235 EXPECT_EQ(CONTENT_SETTING_ALLOW,
243 pref_content_settings_provider.GetContentSetting( 236 pref_content_settings_provider.GetContentSetting(
244 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 237 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
245 // And also in the OTR version. 238 // And also in the OTR version.
246 EXPECT_EQ(CONTENT_SETTING_ALLOW, 239 EXPECT_EQ(CONTENT_SETTING_ALLOW,
247 pref_content_settings_provider_incognito.GetContentSetting( 240 pref_content_settings_provider_incognito.GetContentSetting(
248 host, host, CONTENT_SETTINGS_TYPE_IMAGES, "")); 241 host, host, CONTENT_SETTINGS_TYPE_IMAGES, ""));
249 // But the value should not be overridden in the OTR user prefs accidentally. 242 // But the value should not be overridden in the OTR user prefs accidentally.
250 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(prefs::kContentSettingsPatterns)); 243 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(prefs::kContentSettingsPatterns));
244
245 pref_content_settings_provider.ShutdownOnUIThread();
246 pref_content_settings_provider_incognito.ShutdownOnUIThread();
251 } 247 }
252 248
253 TEST_F(PrefProviderTest, Patterns) { 249 TEST_F(PrefProviderTest, Patterns) {
254 TestingProfile testing_profile; 250 TestingProfile testing_profile;
255 testing_profile.GetHostContentSettingsMap();
256 PrefProvider pref_content_settings_provider( 251 PrefProvider pref_content_settings_provider(
257 testing_profile.GetOriginalProfile()); 252 testing_profile.GetHostContentSettingsMap(),
253 testing_profile.GetPrefs(), false);
258 254
259 GURL host1("http://example.com/"); 255 GURL host1("http://example.com/");
260 GURL host2("http://www.example.com/"); 256 GURL host2("http://www.example.com/");
261 GURL host3("http://example.org/"); 257 GURL host3("http://example.org/");
262 GURL host4("file:///tmp/test.html"); 258 GURL host4("file:///tmp/test.html");
263 ContentSettingsPattern pattern1 = 259 ContentSettingsPattern pattern1 =
264 ContentSettingsPattern::FromString("[*.]example.com"); 260 ContentSettingsPattern::FromString("[*.]example.com");
265 ContentSettingsPattern pattern2 = 261 ContentSettingsPattern pattern2 =
266 ContentSettingsPattern::FromString("example.org"); 262 ContentSettingsPattern::FromString("example.org");
267 ContentSettingsPattern pattern3 = 263 ContentSettingsPattern pattern3 =
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 host4, host4, CONTENT_SETTINGS_TYPE_IMAGES, "")); 297 host4, host4, CONTENT_SETTINGS_TYPE_IMAGES, ""));
302 pref_content_settings_provider.SetContentSetting( 298 pref_content_settings_provider.SetContentSetting(
303 pattern3, 299 pattern3,
304 pattern3, 300 pattern3,
305 CONTENT_SETTINGS_TYPE_IMAGES, 301 CONTENT_SETTINGS_TYPE_IMAGES,
306 "", 302 "",
307 CONTENT_SETTING_BLOCK); 303 CONTENT_SETTING_BLOCK);
308 EXPECT_EQ(CONTENT_SETTING_BLOCK, 304 EXPECT_EQ(CONTENT_SETTING_BLOCK,
309 pref_content_settings_provider.GetContentSetting( 305 pref_content_settings_provider.GetContentSetting(
310 host4, host4, CONTENT_SETTINGS_TYPE_IMAGES, "")); 306 host4, host4, CONTENT_SETTINGS_TYPE_IMAGES, ""));
307
308 pref_content_settings_provider.ShutdownOnUIThread();
311 } 309 }
312 310
313 TEST_F(PrefProviderTest, ResourceIdentifier) { 311 TEST_F(PrefProviderTest, ResourceIdentifier) {
314 // This feature is currently behind a flag. 312 // This feature is currently behind a flag.
315 CommandLine* cmd = CommandLine::ForCurrentProcess(); 313 CommandLine* cmd = CommandLine::ForCurrentProcess();
316 AutoReset<CommandLine> auto_reset(cmd, *cmd); 314 AutoReset<CommandLine> auto_reset(cmd, *cmd);
317 cmd->AppendSwitch(switches::kEnableResourceContentSettings); 315 cmd->AppendSwitch(switches::kEnableResourceContentSettings);
318 316
319 TestingProfile testing_profile; 317 TestingProfile testing_profile;
320 testing_profile.GetHostContentSettingsMap();
321 PrefProvider pref_content_settings_provider( 318 PrefProvider pref_content_settings_provider(
322 testing_profile.GetOriginalProfile()); 319 testing_profile.GetHostContentSettingsMap(),
320 testing_profile.GetPrefs(),
321 false);
323 322
324 GURL host("http://example.com/"); 323 GURL host("http://example.com/");
325 ContentSettingsPattern pattern = 324 ContentSettingsPattern pattern =
326 ContentSettingsPattern::FromString("[*.]example.com"); 325 ContentSettingsPattern::FromString("[*.]example.com");
327 std::string resource1("someplugin"); 326 std::string resource1("someplugin");
328 std::string resource2("otherplugin"); 327 std::string resource2("otherplugin");
329 328
330 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 329 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
331 pref_content_settings_provider.GetContentSetting( 330 pref_content_settings_provider.GetContentSetting(
332 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); 331 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
333 pref_content_settings_provider.SetContentSetting( 332 pref_content_settings_provider.SetContentSetting(
334 pattern, 333 pattern,
335 pattern, 334 pattern,
336 CONTENT_SETTINGS_TYPE_PLUGINS, 335 CONTENT_SETTINGS_TYPE_PLUGINS,
337 resource1, 336 resource1,
338 CONTENT_SETTING_BLOCK); 337 CONTENT_SETTING_BLOCK);
339 EXPECT_EQ(CONTENT_SETTING_BLOCK, 338 EXPECT_EQ(CONTENT_SETTING_BLOCK,
340 pref_content_settings_provider.GetContentSetting( 339 pref_content_settings_provider.GetContentSetting(
341 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1)); 340 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource1));
342 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 341 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
343 pref_content_settings_provider.GetContentSetting( 342 pref_content_settings_provider.GetContentSetting(
344 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2)); 343 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, resource2));
344
345 pref_content_settings_provider.ShutdownOnUIThread();
345 } 346 }
346 347
347 TEST_F(PrefProviderTest, MigrateSinglePatternSettings) { 348 TEST_F(PrefProviderTest, MigrateSinglePatternSettings) {
348 // Setup single pattern settings. 349 // Setup single pattern settings.
349 TestingProfile profile; 350 TestingProfile profile;
350 PrefService* prefs = profile.GetPrefs(); 351 PrefService* prefs = profile.GetPrefs();
351 352
352 DictionaryValue* settings_dictionary = new DictionaryValue(); 353 DictionaryValue* settings_dictionary = new DictionaryValue();
353 settings_dictionary->SetInteger("cookies", 2); 354 settings_dictionary->SetInteger("cookies", 2);
354 settings_dictionary->SetInteger("images", 2); 355 settings_dictionary->SetInteger("images", 2);
355 settings_dictionary->SetInteger("popups", 2); 356 settings_dictionary->SetInteger("popups", 2);
356 357
357 ContentSettingsPattern pattern = 358 ContentSettingsPattern pattern =
358 ContentSettingsPattern::FromString("http://www.example.com"); 359 ContentSettingsPattern::FromString("http://www.example.com");
359 scoped_ptr<DictionaryValue> all_settings_dictionary(new DictionaryValue()); 360 scoped_ptr<DictionaryValue> all_settings_dictionary(new DictionaryValue());
360 all_settings_dictionary->SetWithoutPathExpansion( 361 all_settings_dictionary->SetWithoutPathExpansion(
361 pattern.ToString(), settings_dictionary); 362 pattern.ToString(), settings_dictionary);
362 363
363 // Set Obsolete preference. 364 // Set Obsolete preference.
364 prefs->Set(prefs::kContentSettingsPatterns, *all_settings_dictionary); 365 prefs->Set(prefs::kContentSettingsPatterns, *all_settings_dictionary);
365 366
366 // Test if single pattern settings are properly migrated. 367 // Test if single pattern settings are properly migrated.
367 content_settings::PrefProvider provider(profile.GetOriginalProfile()); 368 content_settings::PrefProvider provider(profile.GetHostContentSettingsMap(),
369 prefs, false);
368 370
369 // Validate migrated preferences 371 // Validate migrated preferences
370 const DictionaryValue* const_all_settings_dictionary = 372 const DictionaryValue* const_all_settings_dictionary =
371 prefs->GetDictionary(prefs::kContentSettingsPatternPairs); 373 prefs->GetDictionary(prefs::kContentSettingsPatternPairs);
372 EXPECT_EQ(1U, const_all_settings_dictionary->size()); 374 EXPECT_EQ(1U, const_all_settings_dictionary->size());
373 EXPECT_FALSE(const_all_settings_dictionary->HasKey(pattern.ToString())); 375 EXPECT_FALSE(const_all_settings_dictionary->HasKey(pattern.ToString()));
374 EXPECT_TRUE(const_all_settings_dictionary->HasKey( 376 EXPECT_TRUE(const_all_settings_dictionary->HasKey(
375 pattern.ToString() + "," + 377 pattern.ToString() + "," +
376 ContentSettingsPattern::Wildcard().ToString())); 378 ContentSettingsPattern::Wildcard().ToString()));
377 379
378 EXPECT_EQ(CONTENT_SETTING_BLOCK, provider.GetContentSetting( 380 EXPECT_EQ(CONTENT_SETTING_BLOCK, provider.GetContentSetting(
379 GURL("http://www.example.com"), 381 GURL("http://www.example.com"),
380 GURL("http://www.example.com"), 382 GURL("http://www.example.com"),
381 CONTENT_SETTINGS_TYPE_IMAGES, 383 CONTENT_SETTINGS_TYPE_IMAGES,
382 "")); 384 ""));
383 385
384 EXPECT_EQ(CONTENT_SETTING_BLOCK, provider.GetContentSetting( 386 EXPECT_EQ(CONTENT_SETTING_BLOCK, provider.GetContentSetting(
385 GURL("http://www.example.com"), 387 GURL("http://www.example.com"),
386 GURL("http://www.example.com"), 388 GURL("http://www.example.com"),
387 CONTENT_SETTINGS_TYPE_POPUPS, 389 CONTENT_SETTINGS_TYPE_POPUPS,
388 "")); 390 ""));
391
392 provider.ShutdownOnUIThread();
389 } 393 }
390 394
391 } // namespace content_settings 395 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698