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

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

Issue 1442083002: Stop inheriting push notification permissions from regular to incognito (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review nits Created 5 years 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
OLDNEW
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 "components/content_settings/core/browser/content_settings_pref_provide r.h" 5 #include "components/content_settings/core/browser/content_settings_pref_provide r.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 "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 pref_content_settings_provider.SetWebsiteSetting( 173 pref_content_settings_provider.SetWebsiteSetting(
174 pattern, 174 pattern,
175 pattern, 175 pattern,
176 CONTENT_SETTINGS_TYPE_IMAGES, 176 CONTENT_SETTINGS_TYPE_IMAGES,
177 std::string(), 177 std::string(),
178 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 178 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
179 179
180 GURL host("http://example.com/"); 180 GURL host("http://example.com/");
181 // The value should of course be visible in the regular PrefProvider. 181 // The value should of course be visible in the regular PrefProvider.
182 EXPECT_EQ(CONTENT_SETTING_ALLOW, 182 EXPECT_EQ(CONTENT_SETTING_ALLOW,
183 GetContentSetting(&pref_content_settings_provider, 183 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
184 host, 184 host, CONTENT_SETTINGS_TYPE_IMAGES,
185 host, 185 std::string(), false));
186 CONTENT_SETTINGS_TYPE_IMAGES,
187 std::string(),
188 false));
189 // And also in the OTR version. 186 // And also in the OTR version.
190 EXPECT_EQ(CONTENT_SETTING_ALLOW, 187 EXPECT_EQ(CONTENT_SETTING_ALLOW,
191 GetContentSetting(&pref_content_settings_provider_incognito, 188 TestUtils::GetContentSetting(
192 host, 189 &pref_content_settings_provider_incognito, host, host,
193 host, 190 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false));
194 CONTENT_SETTINGS_TYPE_IMAGES,
195 std::string(),
196 false));
197 const WebsiteSettingsInfo* info = 191 const WebsiteSettingsInfo* info =
198 WebsiteSettingsRegistry::GetInstance()->Get(CONTENT_SETTINGS_TYPE_IMAGES); 192 WebsiteSettingsRegistry::GetInstance()->Get(CONTENT_SETTINGS_TYPE_IMAGES);
199 // But the value should not be overridden in the OTR user prefs accidentally. 193 // But the value should not be overridden in the OTR user prefs accidentally.
200 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name())); 194 EXPECT_FALSE(otr_user_prefs->IsSetInOverlay(info->pref_name()));
201 195
202 pref_content_settings_provider.ShutdownOnUIThread(); 196 pref_content_settings_provider.ShutdownOnUIThread();
203 pref_content_settings_provider_incognito.ShutdownOnUIThread(); 197 pref_content_settings_provider_incognito.ShutdownOnUIThread();
204 } 198 }
205 199
206 TEST_F(PrefProviderTest, GetContentSettingsValue) { 200 TEST_F(PrefProviderTest, GetContentSettingsValue) {
207 TestingProfile testing_profile; 201 TestingProfile testing_profile;
208 PrefProvider provider(testing_profile.GetPrefs(), false); 202 PrefProvider provider(testing_profile.GetPrefs(), false);
209 203
210 GURL primary_url("http://example.com/"); 204 GURL primary_url("http://example.com/");
211 ContentSettingsPattern primary_pattern = 205 ContentSettingsPattern primary_pattern =
212 ContentSettingsPattern::FromString("[*.]example.com"); 206 ContentSettingsPattern::FromString("[*.]example.com");
213 207
214 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 208 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
215 GetContentSetting(&provider, 209 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
216 primary_url, 210 CONTENT_SETTINGS_TYPE_IMAGES,
217 primary_url, 211 std::string(), false));
218 CONTENT_SETTINGS_TYPE_IMAGES,
219 std::string(),
220 false));
221 212
222 EXPECT_EQ(NULL, 213 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue(
223 GetContentSettingValue(&provider, 214 &provider, primary_url, primary_url,
224 primary_url, 215 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false));
225 primary_url,
226 CONTENT_SETTINGS_TYPE_IMAGES,
227 std::string(),
228 false));
229 216
230 provider.SetWebsiteSetting(primary_pattern, 217 provider.SetWebsiteSetting(primary_pattern,
231 primary_pattern, 218 primary_pattern,
232 CONTENT_SETTINGS_TYPE_IMAGES, 219 CONTENT_SETTINGS_TYPE_IMAGES,
233 std::string(), 220 std::string(),
234 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 221 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
235 EXPECT_EQ(CONTENT_SETTING_BLOCK, 222 EXPECT_EQ(CONTENT_SETTING_BLOCK,
236 GetContentSetting(&provider, 223 TestUtils::GetContentSetting(&provider, primary_url, primary_url,
237 primary_url, 224 CONTENT_SETTINGS_TYPE_IMAGES,
238 primary_url, 225 std::string(), false));
239 CONTENT_SETTINGS_TYPE_IMAGES, 226 scoped_ptr<base::Value> value_ptr(TestUtils::GetContentSettingValue(
240 std::string(), 227 &provider, primary_url, primary_url, CONTENT_SETTINGS_TYPE_IMAGES,
241 false)); 228 std::string(), false));
242 scoped_ptr<base::Value> value_ptr(
243 GetContentSettingValue(&provider,
244 primary_url,
245 primary_url,
246 CONTENT_SETTINGS_TYPE_IMAGES,
247 std::string(),
248 false));
249 int int_value = -1; 229 int int_value = -1;
250 value_ptr->GetAsInteger(&int_value); 230 value_ptr->GetAsInteger(&int_value);
251 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value)); 231 EXPECT_EQ(CONTENT_SETTING_BLOCK, IntToContentSetting(int_value));
252 232
253 provider.SetWebsiteSetting(primary_pattern, 233 provider.SetWebsiteSetting(primary_pattern,
254 primary_pattern, 234 primary_pattern,
255 CONTENT_SETTINGS_TYPE_IMAGES, 235 CONTENT_SETTINGS_TYPE_IMAGES,
256 std::string(), 236 std::string(),
257 NULL); 237 NULL);
258 EXPECT_EQ(NULL, 238 EXPECT_EQ(NULL, TestUtils::GetContentSettingValue(
259 GetContentSettingValue(&provider, 239 &provider, primary_url, primary_url,
260 primary_url, 240 CONTENT_SETTINGS_TYPE_IMAGES, std::string(), false));
261 primary_url,
262 CONTENT_SETTINGS_TYPE_IMAGES,
263 std::string(),
264 false));
265 provider.ShutdownOnUIThread(); 241 provider.ShutdownOnUIThread();
266 } 242 }
267 243
268 TEST_F(PrefProviderTest, Patterns) { 244 TEST_F(PrefProviderTest, Patterns) {
269 TestingProfile testing_profile; 245 TestingProfile testing_profile;
270 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), 246 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
271 false); 247 false);
272 248
273 GURL host1("http://example.com/"); 249 GURL host1("http://example.com/");
274 GURL host2("http://www.example.com/"); 250 GURL host2("http://www.example.com/");
275 GURL host3("http://example.org/"); 251 GURL host3("http://example.org/");
276 GURL host4("file:///tmp/test.html"); 252 GURL host4("file:///tmp/test.html");
277 ContentSettingsPattern pattern1 = 253 ContentSettingsPattern pattern1 =
278 ContentSettingsPattern::FromString("[*.]example.com"); 254 ContentSettingsPattern::FromString("[*.]example.com");
279 ContentSettingsPattern pattern2 = 255 ContentSettingsPattern pattern2 =
280 ContentSettingsPattern::FromString("example.org"); 256 ContentSettingsPattern::FromString("example.org");
281 ContentSettingsPattern pattern3 = 257 ContentSettingsPattern pattern3 =
282 ContentSettingsPattern::FromString("file:///tmp/test.html"); 258 ContentSettingsPattern::FromString("file:///tmp/test.html");
283 259
284 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 260 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
285 GetContentSetting(&pref_content_settings_provider, 261 TestUtils::GetContentSetting(&pref_content_settings_provider, host1,
286 host1, 262 host1, CONTENT_SETTINGS_TYPE_IMAGES,
287 host1, 263 std::string(), false));
288 CONTENT_SETTINGS_TYPE_IMAGES,
289 std::string(),
290 false));
291 pref_content_settings_provider.SetWebsiteSetting( 264 pref_content_settings_provider.SetWebsiteSetting(
292 pattern1, 265 pattern1,
293 pattern1, 266 pattern1,
294 CONTENT_SETTINGS_TYPE_IMAGES, 267 CONTENT_SETTINGS_TYPE_IMAGES,
295 std::string(), 268 std::string(),
296 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 269 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
297 EXPECT_EQ(CONTENT_SETTING_BLOCK, 270 EXPECT_EQ(CONTENT_SETTING_BLOCK,
298 GetContentSetting(&pref_content_settings_provider, 271 TestUtils::GetContentSetting(&pref_content_settings_provider, host1,
299 host1, 272 host1, CONTENT_SETTINGS_TYPE_IMAGES,
300 host1, 273 std::string(), false));
301 CONTENT_SETTINGS_TYPE_IMAGES,
302 std::string(),
303 false));
304 EXPECT_EQ(CONTENT_SETTING_BLOCK, 274 EXPECT_EQ(CONTENT_SETTING_BLOCK,
305 GetContentSetting(&pref_content_settings_provider, 275 TestUtils::GetContentSetting(&pref_content_settings_provider, host2,
306 host2, 276 host2, CONTENT_SETTINGS_TYPE_IMAGES,
307 host2, 277 std::string(), false));
308 CONTENT_SETTINGS_TYPE_IMAGES,
309 std::string(),
310 false));
311 278
312 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 279 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
313 GetContentSetting(&pref_content_settings_provider, 280 TestUtils::GetContentSetting(&pref_content_settings_provider, host3,
314 host3, 281 host3, CONTENT_SETTINGS_TYPE_IMAGES,
315 host3, 282 std::string(), false));
316 CONTENT_SETTINGS_TYPE_IMAGES,
317 std::string(),
318 false));
319 pref_content_settings_provider.SetWebsiteSetting( 283 pref_content_settings_provider.SetWebsiteSetting(
320 pattern2, 284 pattern2,
321 pattern2, 285 pattern2,
322 CONTENT_SETTINGS_TYPE_IMAGES, 286 CONTENT_SETTINGS_TYPE_IMAGES,
323 std::string(), 287 std::string(),
324 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 288 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
325 EXPECT_EQ(CONTENT_SETTING_BLOCK, 289 EXPECT_EQ(CONTENT_SETTING_BLOCK,
326 GetContentSetting(&pref_content_settings_provider, 290 TestUtils::GetContentSetting(&pref_content_settings_provider, host3,
327 host3, 291 host3, CONTENT_SETTINGS_TYPE_IMAGES,
328 host3, 292 std::string(), false));
329 CONTENT_SETTINGS_TYPE_IMAGES,
330 std::string(),
331 false));
332 293
333 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 294 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
334 GetContentSetting(&pref_content_settings_provider, 295 TestUtils::GetContentSetting(&pref_content_settings_provider, host4,
335 host4, 296 host4, CONTENT_SETTINGS_TYPE_IMAGES,
336 host4, 297 std::string(), false));
337 CONTENT_SETTINGS_TYPE_IMAGES,
338 std::string(),
339 false));
340 pref_content_settings_provider.SetWebsiteSetting( 298 pref_content_settings_provider.SetWebsiteSetting(
341 pattern3, 299 pattern3,
342 pattern3, 300 pattern3,
343 CONTENT_SETTINGS_TYPE_IMAGES, 301 CONTENT_SETTINGS_TYPE_IMAGES,
344 std::string(), 302 std::string(),
345 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 303 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
346 EXPECT_EQ(CONTENT_SETTING_BLOCK, 304 EXPECT_EQ(CONTENT_SETTING_BLOCK,
347 GetContentSetting(&pref_content_settings_provider, 305 TestUtils::GetContentSetting(&pref_content_settings_provider, host4,
348 host4, 306 host4, CONTENT_SETTINGS_TYPE_IMAGES,
349 host4, 307 std::string(), false));
350 CONTENT_SETTINGS_TYPE_IMAGES,
351 std::string(),
352 false));
353 308
354 pref_content_settings_provider.ShutdownOnUIThread(); 309 pref_content_settings_provider.ShutdownOnUIThread();
355 } 310 }
356 311
357 TEST_F(PrefProviderTest, ResourceIdentifier) { 312 TEST_F(PrefProviderTest, ResourceIdentifier) {
358 TestingProfile testing_profile; 313 TestingProfile testing_profile;
359 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), 314 PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
360 false); 315 false);
361 316
362 GURL host("http://example.com/"); 317 GURL host("http://example.com/");
363 ContentSettingsPattern pattern = 318 ContentSettingsPattern pattern =
364 ContentSettingsPattern::FromString("[*.]example.com"); 319 ContentSettingsPattern::FromString("[*.]example.com");
365 std::string resource1("someplugin"); 320 std::string resource1("someplugin");
366 std::string resource2("otherplugin"); 321 std::string resource2("otherplugin");
367 322
368 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 323 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
369 GetContentSetting( 324 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
370 &pref_content_settings_provider, 325 host, CONTENT_SETTINGS_TYPE_PLUGINS,
371 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, 326 resource1, false));
372 resource1, false));
373 pref_content_settings_provider.SetWebsiteSetting( 327 pref_content_settings_provider.SetWebsiteSetting(
374 pattern, 328 pattern,
375 pattern, 329 pattern,
376 CONTENT_SETTINGS_TYPE_PLUGINS, 330 CONTENT_SETTINGS_TYPE_PLUGINS,
377 resource1, 331 resource1,
378 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 332 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
379 EXPECT_EQ(CONTENT_SETTING_BLOCK, 333 EXPECT_EQ(CONTENT_SETTING_BLOCK,
380 GetContentSetting( 334 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
381 &pref_content_settings_provider, 335 host, CONTENT_SETTINGS_TYPE_PLUGINS,
382 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, 336 resource1, false));
383 resource1, false));
384 EXPECT_EQ(CONTENT_SETTING_DEFAULT, 337 EXPECT_EQ(CONTENT_SETTING_DEFAULT,
385 GetContentSetting( 338 TestUtils::GetContentSetting(&pref_content_settings_provider, host,
386 &pref_content_settings_provider, 339 host, CONTENT_SETTINGS_TYPE_PLUGINS,
387 host, host, CONTENT_SETTINGS_TYPE_PLUGINS, 340 resource2, false));
388 resource2, false));
389 341
390 pref_content_settings_provider.ShutdownOnUIThread(); 342 pref_content_settings_provider.ShutdownOnUIThread();
391 } 343 }
392 344
393 // http://crosbug.com/17760 345 // http://crosbug.com/17760
394 TEST_F(PrefProviderTest, Deadlock) { 346 TEST_F(PrefProviderTest, Deadlock) {
395 syncable_prefs::TestingPrefServiceSyncable prefs; 347 syncable_prefs::TestingPrefServiceSyncable prefs;
396 PrefProvider::RegisterProfilePrefs(prefs.registry()); 348 PrefProvider::RegisterProfilePrefs(prefs.registry());
397 349
398 // Chain of events: a preference changes, |PrefProvider| notices it, and reads 350 // Chain of events: a preference changes, |PrefProvider| notices it, and reads
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 for (const char* pref : nonempty_prefs) { 536 for (const char* pref : nonempty_prefs) {
585 DictionaryPrefUpdate update(&prefs, pref); 537 DictionaryPrefUpdate update(&prefs, pref);
586 const base::DictionaryValue* dictionary = update.Get(); 538 const base::DictionaryValue* dictionary = update.Get();
587 EXPECT_EQ(1u, dictionary->size()); 539 EXPECT_EQ(1u, dictionary->size());
588 } 540 }
589 541
590 provider.ShutdownOnUIThread(); 542 provider.ShutdownOnUIThread();
591 } 543 }
592 544
593 } // namespace content_settings 545 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698