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

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

Issue 1312453005: Removed Profile::GetHostContentSettingsMap (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed redundant functions Created 5 years, 3 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
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 "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"
11 #include "base/prefs/scoped_user_pref_update.h" 11 #include "base/prefs/scoped_user_pref_update.h"
12 #include "chrome/browser/content_settings/content_settings_mock_observer.h" 12 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
13 #include "chrome/browser/content_settings/cookie_settings_factory.h" 13 #include "chrome/browser/content_settings/cookie_settings_factory.h"
14 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
14 #include "chrome/browser/content_settings/mock_settings_observer.h" 15 #include "chrome/browser/content_settings/mock_settings_observer.h"
15 #include "chrome/common/pref_names.h" 16 #include "chrome/common/pref_names.h"
16 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
17 #include "chrome/test/base/testing_pref_service_syncable.h" 18 #include "chrome/test/base/testing_pref_service_syncable.h"
18 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
19 #include "components/content_settings/core/browser/content_settings_details.h" 20 #include "components/content_settings/core/browser/content_settings_details.h"
20 #include "components/content_settings/core/browser/cookie_settings.h" 21 #include "components/content_settings/core/browser/cookie_settings.h"
21 #include "components/content_settings/core/browser/host_content_settings_map.h" 22 #include "components/content_settings/core/browser/host_content_settings_map.h"
22 #include "components/content_settings/core/browser/website_settings_info.h" 23 #include "components/content_settings/core/browser/website_settings_info.h"
23 #include "components/content_settings/core/browser/website_settings_registry.h" 24 #include "components/content_settings/core/browser/website_settings_registry.h"
(...skipping 18 matching lines...) Expand all
42 ->pref_name(); 43 ->pref_name();
43 } 44 }
44 45
45 base::MessageLoop message_loop_; 46 base::MessageLoop message_loop_;
46 content::TestBrowserThread ui_thread_; 47 content::TestBrowserThread ui_thread_;
47 }; 48 };
48 49
49 TEST_F(HostContentSettingsMapTest, DefaultValues) { 50 TEST_F(HostContentSettingsMapTest, DefaultValues) {
50 TestingProfile profile; 51 TestingProfile profile;
51 HostContentSettingsMap* host_content_settings_map = 52 HostContentSettingsMap* host_content_settings_map =
52 profile.GetHostContentSettingsMap(); 53 HostContentSettingsMapFactory::GetForProfile(&profile);
53 54
54 // Check setting defaults. 55 // Check setting defaults.
55 EXPECT_EQ(CONTENT_SETTING_ALLOW, 56 EXPECT_EQ(CONTENT_SETTING_ALLOW,
56 host_content_settings_map->GetDefaultContentSetting( 57 host_content_settings_map->GetDefaultContentSetting(
57 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 58 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
58 host_content_settings_map->SetDefaultContentSetting( 59 host_content_settings_map->SetDefaultContentSetting(
59 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 60 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
60 EXPECT_EQ(CONTENT_SETTING_BLOCK, 61 EXPECT_EQ(CONTENT_SETTING_BLOCK,
61 host_content_settings_map->GetDefaultContentSetting( 62 host_content_settings_map->GetDefaultContentSetting(
62 CONTENT_SETTINGS_TYPE_IMAGES, NULL)); 63 CONTENT_SETTINGS_TYPE_IMAGES, NULL));
(...skipping 22 matching lines...) Expand all
85 host_content_settings_map->SetDefaultContentSetting( 86 host_content_settings_map->SetDefaultContentSetting(
86 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); 87 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW);
87 EXPECT_EQ(CONTENT_SETTING_ALLOW, 88 EXPECT_EQ(CONTENT_SETTING_ALLOW,
88 host_content_settings_map->GetDefaultContentSetting( 89 host_content_settings_map->GetDefaultContentSetting(
89 CONTENT_SETTINGS_TYPE_POPUPS, NULL)); 90 CONTENT_SETTINGS_TYPE_POPUPS, NULL));
90 } 91 }
91 92
92 TEST_F(HostContentSettingsMapTest, IndividualSettings) { 93 TEST_F(HostContentSettingsMapTest, IndividualSettings) {
93 TestingProfile profile; 94 TestingProfile profile;
94 HostContentSettingsMap* host_content_settings_map = 95 HostContentSettingsMap* host_content_settings_map =
95 profile.GetHostContentSettingsMap(); 96 HostContentSettingsMapFactory::GetForProfile(&profile);
96 97
97 // Check returning individual settings. 98 // Check returning individual settings.
98 GURL host("http://example.com/"); 99 GURL host("http://example.com/");
99 ContentSettingsPattern pattern = 100 ContentSettingsPattern pattern =
100 ContentSettingsPattern::FromString("[*.]example.com"); 101 ContentSettingsPattern::FromString("[*.]example.com");
101 EXPECT_EQ(CONTENT_SETTING_ALLOW, 102 EXPECT_EQ(CONTENT_SETTING_ALLOW,
102 host_content_settings_map->GetContentSetting( 103 host_content_settings_map->GetContentSetting(
103 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 104 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
104 host_content_settings_map->SetContentSetting( 105 host_content_settings_map->SetContentSetting(
105 pattern, 106 pattern,
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 EXPECT_EQ(3U, host_settings.size()); 195 EXPECT_EQ(3U, host_settings.size());
195 host_content_settings_map->GetSettingsForOneType( 196 host_content_settings_map->GetSettingsForOneType(
196 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); 197 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings);
197 // |host_settings| contains only the default setting. 198 // |host_settings| contains only the default setting.
198 EXPECT_EQ(1U, host_settings.size()); 199 EXPECT_EQ(1U, host_settings.size());
199 } 200 }
200 201
201 TEST_F(HostContentSettingsMapTest, Clear) { 202 TEST_F(HostContentSettingsMapTest, Clear) {
202 TestingProfile profile; 203 TestingProfile profile;
203 HostContentSettingsMap* host_content_settings_map = 204 HostContentSettingsMap* host_content_settings_map =
204 profile.GetHostContentSettingsMap(); 205 HostContentSettingsMapFactory::GetForProfile(&profile);
205 206
206 // Check clearing one type. 207 // Check clearing one type.
207 ContentSettingsPattern pattern = 208 ContentSettingsPattern pattern =
208 ContentSettingsPattern::FromString("[*.]example.org"); 209 ContentSettingsPattern::FromString("[*.]example.org");
209 ContentSettingsPattern pattern2 = 210 ContentSettingsPattern pattern2 =
210 ContentSettingsPattern::FromString("[*.]example.net"); 211 ContentSettingsPattern::FromString("[*.]example.net");
211 host_content_settings_map->SetContentSetting( 212 host_content_settings_map->SetContentSetting(
212 pattern2, 213 pattern2,
213 ContentSettingsPattern::Wildcard(), 214 ContentSettingsPattern::Wildcard(),
214 CONTENT_SETTINGS_TYPE_IMAGES, 215 CONTENT_SETTINGS_TYPE_IMAGES,
(...skipping 26 matching lines...) Expand all
241 EXPECT_EQ(1U, host_settings.size()); 242 EXPECT_EQ(1U, host_settings.size());
242 host_content_settings_map->GetSettingsForOneType( 243 host_content_settings_map->GetSettingsForOneType(
243 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings); 244 CONTENT_SETTINGS_TYPE_PLUGINS, std::string(), &host_settings);
244 // |host_settings| contains the default setting and an exception. 245 // |host_settings| contains the default setting and an exception.
245 EXPECT_EQ(2U, host_settings.size()); 246 EXPECT_EQ(2U, host_settings.size());
246 } 247 }
247 248
248 TEST_F(HostContentSettingsMapTest, Patterns) { 249 TEST_F(HostContentSettingsMapTest, Patterns) {
249 TestingProfile profile; 250 TestingProfile profile;
250 HostContentSettingsMap* host_content_settings_map = 251 HostContentSettingsMap* host_content_settings_map =
251 profile.GetHostContentSettingsMap(); 252 HostContentSettingsMapFactory::GetForProfile(&profile);
252 253
253 GURL host1("http://example.com/"); 254 GURL host1("http://example.com/");
254 GURL host2("http://www.example.com/"); 255 GURL host2("http://www.example.com/");
255 GURL host3("http://example.org/"); 256 GURL host3("http://example.org/");
256 ContentSettingsPattern pattern1 = 257 ContentSettingsPattern pattern1 =
257 ContentSettingsPattern::FromString("[*.]example.com"); 258 ContentSettingsPattern::FromString("[*.]example.com");
258 ContentSettingsPattern pattern2 = 259 ContentSettingsPattern pattern2 =
259 ContentSettingsPattern::FromString("example.org"); 260 ContentSettingsPattern::FromString("example.org");
260 EXPECT_EQ(CONTENT_SETTING_ALLOW, 261 EXPECT_EQ(CONTENT_SETTING_ALLOW,
261 host_content_settings_map->GetContentSetting( 262 host_content_settings_map->GetContentSetting(
(...skipping 20 matching lines...) Expand all
282 std::string(), 283 std::string(),
283 CONTENT_SETTING_BLOCK); 284 CONTENT_SETTING_BLOCK);
284 EXPECT_EQ(CONTENT_SETTING_BLOCK, 285 EXPECT_EQ(CONTENT_SETTING_BLOCK,
285 host_content_settings_map->GetContentSetting( 286 host_content_settings_map->GetContentSetting(
286 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 287 host3, host3, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
287 } 288 }
288 289
289 TEST_F(HostContentSettingsMapTest, Observer) { 290 TEST_F(HostContentSettingsMapTest, Observer) {
290 TestingProfile profile; 291 TestingProfile profile;
291 HostContentSettingsMap* host_content_settings_map = 292 HostContentSettingsMap* host_content_settings_map =
292 profile.GetHostContentSettingsMap(); 293 HostContentSettingsMapFactory::GetForProfile(&profile);
293 MockSettingsObserver observer(host_content_settings_map); 294 MockSettingsObserver observer(host_content_settings_map);
294 295
295 ContentSettingsPattern primary_pattern = 296 ContentSettingsPattern primary_pattern =
296 ContentSettingsPattern::FromString("[*.]example.com"); 297 ContentSettingsPattern::FromString("[*.]example.com");
297 ContentSettingsPattern secondary_pattern = 298 ContentSettingsPattern secondary_pattern =
298 ContentSettingsPattern::Wildcard(); 299 ContentSettingsPattern::Wildcard();
299 EXPECT_CALL(observer, 300 EXPECT_CALL(observer,
300 OnContentSettingsChanged(host_content_settings_map, 301 OnContentSettingsChanged(host_content_settings_map,
301 CONTENT_SETTINGS_TYPE_IMAGES, 302 CONTENT_SETTINGS_TYPE_IMAGES,
302 false, 303 false,
(...skipping 20 matching lines...) Expand all
323 OnContentSettingsChanged(host_content_settings_map, 324 OnContentSettingsChanged(host_content_settings_map,
324 CONTENT_SETTINGS_TYPE_IMAGES, false, 325 CONTENT_SETTINGS_TYPE_IMAGES, false,
325 _, _, true)); 326 _, _, true));
326 host_content_settings_map->SetDefaultContentSetting( 327 host_content_settings_map->SetDefaultContentSetting(
327 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 328 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
328 } 329 }
329 330
330 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) { 331 TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {
331 TestingProfile profile; 332 TestingProfile profile;
332 HostContentSettingsMap* host_content_settings_map = 333 HostContentSettingsMap* host_content_settings_map =
333 profile.GetHostContentSettingsMap(); 334 HostContentSettingsMapFactory::GetForProfile(&profile);
334 335
335 PrefService* prefs = profile.GetPrefs(); 336 PrefService* prefs = profile.GetPrefs();
336 GURL host("http://example.com"); 337 GURL host("http://example.com");
337 338
338 host_content_settings_map->SetDefaultContentSetting( 339 host_content_settings_map->SetDefaultContentSetting(
339 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK); 340 CONTENT_SETTINGS_TYPE_IMAGES, CONTENT_SETTING_BLOCK);
340 EXPECT_EQ(CONTENT_SETTING_BLOCK, 341 EXPECT_EQ(CONTENT_SETTING_BLOCK,
341 host_content_settings_map->GetContentSetting( 342 host_content_settings_map->GetContentSetting(
342 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 343 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
343 344
344 const content_settings::WebsiteSettingsInfo* info = 345 const content_settings::WebsiteSettingsInfo* info =
345 content_settings::WebsiteSettingsRegistry::GetInstance()->Get( 346 content_settings::WebsiteSettingsRegistry::GetInstance()->Get(
346 CONTENT_SETTINGS_TYPE_IMAGES); 347 CONTENT_SETTINGS_TYPE_IMAGES);
347 // Clearing the backing pref should also clear the internal cache. 348 // Clearing the backing pref should also clear the internal cache.
348 prefs->ClearPref(info->default_value_pref_name()); 349 prefs->ClearPref(info->default_value_pref_name());
349 EXPECT_EQ(CONTENT_SETTING_ALLOW, 350 EXPECT_EQ(CONTENT_SETTING_ALLOW,
350 host_content_settings_map->GetContentSetting( 351 host_content_settings_map->GetContentSetting(
351 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 352 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
352 353
353 // Reseting the pref to its previous value should update the cache. 354 // Reseting the pref to its previous value should update the cache.
354 prefs->SetInteger(info->default_value_pref_name(), CONTENT_SETTING_BLOCK); 355 prefs->SetInteger(info->default_value_pref_name(), CONTENT_SETTING_BLOCK);
355 EXPECT_EQ(CONTENT_SETTING_BLOCK, 356 EXPECT_EQ(CONTENT_SETTING_BLOCK,
356 host_content_settings_map->GetContentSetting( 357 host_content_settings_map->GetContentSetting(
357 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 358 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
358 } 359 }
359 360
360 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { 361 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
361 TestingProfile profile; 362 TestingProfile profile;
362 HostContentSettingsMap* host_content_settings_map = 363 HostContentSettingsMap* host_content_settings_map =
363 profile.GetHostContentSettingsMap(); 364 HostContentSettingsMapFactory::GetForProfile(&profile);
364 365
365 PrefService* prefs = profile.GetPrefs(); 366 PrefService* prefs = profile.GetPrefs();
366 367
367 // Make a copy of the default pref value so we can reset it later. 368 // Make a copy of the default pref value so we can reset it later.
368 scoped_ptr<base::Value> default_value( 369 scoped_ptr<base::Value> default_value(
369 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES)) 370 prefs->FindPreference(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES))
370 ->GetValue() 371 ->GetValue()
371 ->DeepCopy()); 372 ->DeepCopy());
372 373
373 ContentSettingsPattern pattern = 374 ContentSettingsPattern pattern =
(...skipping 29 matching lines...) Expand all
403 // Reseting the pref to its previous value should update the cache. 404 // Reseting the pref to its previous value should update the cache.
404 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *new_value); 405 prefs->Set(GetPrefName(CONTENT_SETTINGS_TYPE_IMAGES), *new_value);
405 EXPECT_EQ(CONTENT_SETTING_BLOCK, 406 EXPECT_EQ(CONTENT_SETTING_BLOCK,
406 host_content_settings_map->GetContentSetting( 407 host_content_settings_map->GetContentSetting(
407 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 408 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
408 } 409 }
409 410
410 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { 411 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
411 TestingProfile profile; 412 TestingProfile profile;
412 HostContentSettingsMap* host_content_settings_map = 413 HostContentSettingsMap* host_content_settings_map =
413 profile.GetHostContentSettingsMap(); 414 HostContentSettingsMapFactory::GetForProfile(&profile);
414 content_settings::CookieSettings* cookie_settings = 415 content_settings::CookieSettings* cookie_settings =
415 CookieSettingsFactory::GetForProfile(&profile).get(); 416 CookieSettingsFactory::GetForProfile(&profile).get();
416 417
417 ContentSettingsPattern pattern = 418 ContentSettingsPattern pattern =
418 ContentSettingsPattern::FromString("[*.]example.com"); 419 ContentSettingsPattern::FromString("[*.]example.com");
419 GURL host_ending_with_dot("http://example.com./"); 420 GURL host_ending_with_dot("http://example.com./");
420 421
421 EXPECT_EQ(CONTENT_SETTING_ALLOW, 422 EXPECT_EQ(CONTENT_SETTING_ALLOW,
422 host_content_settings_map->GetContentSetting( 423 host_content_settings_map->GetContentSetting(
423 host_ending_with_dot, 424 host_ending_with_dot,
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 CONTENT_SETTING_ALLOW, 559 CONTENT_SETTING_ALLOW,
559 host_content_settings_map->GetContentSetting(host_ending_with_dot, 560 host_content_settings_map->GetContentSetting(host_ending_with_dot,
560 host_ending_with_dot, 561 host_ending_with_dot,
561 CONTENT_SETTINGS_TYPE_POPUPS, 562 CONTENT_SETTINGS_TYPE_POPUPS,
562 std::string())); 563 std::string()));
563 } 564 }
564 565
565 TEST_F(HostContentSettingsMapTest, NestedSettings) { 566 TEST_F(HostContentSettingsMapTest, NestedSettings) {
566 TestingProfile profile; 567 TestingProfile profile;
567 HostContentSettingsMap* host_content_settings_map = 568 HostContentSettingsMap* host_content_settings_map =
568 profile.GetHostContentSettingsMap(); 569 HostContentSettingsMapFactory::GetForProfile(&profile);
569 570
570 GURL host("http://a.b.example.com/"); 571 GURL host("http://a.b.example.com/");
571 ContentSettingsPattern pattern1 = 572 ContentSettingsPattern pattern1 =
572 ContentSettingsPattern::FromString("[*.]example.com"); 573 ContentSettingsPattern::FromString("[*.]example.com");
573 ContentSettingsPattern pattern2 = 574 ContentSettingsPattern pattern2 =
574 ContentSettingsPattern::FromString("[*.]b.example.com"); 575 ContentSettingsPattern::FromString("[*.]b.example.com");
575 ContentSettingsPattern pattern3 = 576 ContentSettingsPattern pattern3 =
576 ContentSettingsPattern::FromString("a.b.example.com"); 577 ContentSettingsPattern::FromString("a.b.example.com");
577 578
578 host_content_settings_map->SetContentSetting( 579 host_content_settings_map->SetContentSetting(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 host_content_settings_map->GetContentSetting( 625 host_content_settings_map->GetContentSetting(
625 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); 626 host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string()));
626 EXPECT_EQ(CONTENT_SETTING_ASK, 627 EXPECT_EQ(CONTENT_SETTING_ASK,
627 host_content_settings_map->GetContentSetting( 628 host_content_settings_map->GetContentSetting(
628 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); 629 host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string()));
629 } 630 }
630 631
631 TEST_F(HostContentSettingsMapTest, OffTheRecord) { 632 TEST_F(HostContentSettingsMapTest, OffTheRecord) {
632 TestingProfile profile; 633 TestingProfile profile;
633 HostContentSettingsMap* host_content_settings_map = 634 HostContentSettingsMap* host_content_settings_map =
634 profile.GetHostContentSettingsMap(); 635 HostContentSettingsMapFactory::GetForProfile(&profile);
635 scoped_refptr<HostContentSettingsMap> otr_map( 636 scoped_refptr<HostContentSettingsMap> otr_map(
636 new HostContentSettingsMap(profile.GetPrefs(), 637 new HostContentSettingsMap(profile.GetPrefs(),
637 true)); 638 true));
638 639
639 GURL host("http://example.com/"); 640 GURL host("http://example.com/");
640 ContentSettingsPattern pattern = 641 ContentSettingsPattern pattern =
641 ContentSettingsPattern::FromString("[*.]example.com"); 642 ContentSettingsPattern::FromString("[*.]example.com");
642 643
643 EXPECT_EQ(CONTENT_SETTING_ALLOW, 644 EXPECT_EQ(CONTENT_SETTING_ALLOW,
644 host_content_settings_map->GetContentSetting( 645 host_content_settings_map->GetContentSetting(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 GetPrefName(CONTENT_SETTINGS_TYPE_PLUGINS)); 692 GetPrefName(CONTENT_SETTINGS_TYPE_PLUGINS));
692 base::DictionaryValue* all_settings_dictionary = update.Get(); 693 base::DictionaryValue* all_settings_dictionary = update.Get();
693 ASSERT_TRUE(NULL != all_settings_dictionary); 694 ASSERT_TRUE(NULL != all_settings_dictionary);
694 695
695 base::DictionaryValue* dummy_payload = new base::DictionaryValue; 696 base::DictionaryValue* dummy_payload = new base::DictionaryValue;
696 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW); 697 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW);
697 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", 698 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
698 dummy_payload); 699 dummy_payload);
699 } 700 }
700 701
701 profile.GetHostContentSettingsMap(); 702 HostContentSettingsMapFactory::GetForProfile(&profile);
702 703
703 const base::DictionaryValue* all_settings_dictionary = 704 const base::DictionaryValue* all_settings_dictionary =
704 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_PLUGINS)); 705 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_PLUGINS));
705 const base::DictionaryValue* result = NULL; 706 const base::DictionaryValue* result = NULL;
706 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 707 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
707 "[*.]\xC4\x87ira.com,*", &result)); 708 "[*.]\xC4\x87ira.com,*", &result));
708 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 709 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
709 "[*.]xn--ira-ppa.com,*", &result)); 710 "[*.]xn--ira-ppa.com,*", &result));
710 } 711 }
711 712
712 // If both Unicode and its punycode pattern exist, make sure we don't touch the 713 // If both Unicode and its punycode pattern exist, make sure we don't touch the
713 // settings for the punycode, and that Unicode pattern gets deleted. 714 // settings for the punycode, and that Unicode pattern gets deleted.
714 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { 715 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
715 TestingProfile profile; 716 TestingProfile profile;
716 717
717 scoped_ptr<base::Value> value(base::JSONReader::DeprecatedRead( 718 scoped_ptr<base::Value> value(base::JSONReader::DeprecatedRead(
718 "{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}")); 719 "{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"));
719 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *value); 720 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *value);
720 721
721 // Set punycode equivalent, with different setting. 722 // Set punycode equivalent, with different setting.
722 scoped_ptr<base::Value> puny_value(base::JSONReader::DeprecatedRead( 723 scoped_ptr<base::Value> puny_value(base::JSONReader::DeprecatedRead(
723 "{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}")); 724 "{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}"));
724 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), 725 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES),
725 *puny_value); 726 *puny_value);
726 727
727 // Initialize the content map. 728 // Initialize the content map.
728 profile.GetHostContentSettingsMap(); 729 HostContentSettingsMapFactory::GetForProfile(&profile);
729 730
730 const base::DictionaryValue& content_setting_prefs = 731 const base::DictionaryValue& content_setting_prefs =
731 *profile.GetPrefs()->GetDictionary( 732 *profile.GetPrefs()->GetDictionary(
732 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); 733 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
733 std::string prefs_as_json; 734 std::string prefs_as_json;
734 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); 735 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json);
735 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}", 736 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}",
736 prefs_as_json.c_str()); 737 prefs_as_json.c_str());
737 } 738 }
738 739
739 // If a default-content-setting is managed, the managed value should be used 740 // If a default-content-setting is managed, the managed value should be used
740 // instead of the default value. 741 // instead of the default value.
741 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { 742 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) {
742 TestingProfile profile; 743 TestingProfile profile;
743 HostContentSettingsMap* host_content_settings_map = 744 HostContentSettingsMap* host_content_settings_map =
744 profile.GetHostContentSettingsMap(); 745 HostContentSettingsMapFactory::GetForProfile(&profile);
745 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 746 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
746 747
747 EXPECT_EQ(CONTENT_SETTING_ALLOW, 748 EXPECT_EQ(CONTENT_SETTING_ALLOW,
748 host_content_settings_map->GetDefaultContentSetting( 749 host_content_settings_map->GetDefaultContentSetting(
749 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL)); 750 CONTENT_SETTINGS_TYPE_JAVASCRIPT, NULL));
750 751
751 // Set managed-default-content-setting through the coresponding preferences. 752 // Set managed-default-content-setting through the coresponding preferences.
752 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting, 753 prefs->SetManagedPref(prefs::kManagedDefaultJavaScriptSetting,
753 new base::FundamentalValue(CONTENT_SETTING_BLOCK)); 754 new base::FundamentalValue(CONTENT_SETTING_BLOCK));
754 EXPECT_EQ(CONTENT_SETTING_BLOCK, 755 EXPECT_EQ(CONTENT_SETTING_BLOCK,
(...skipping 17 matching lines...) Expand all
772 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 773 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
773 EXPECT_EQ(CONTENT_SETTING_ALLOW, 774 EXPECT_EQ(CONTENT_SETTING_ALLOW,
774 host_content_settings_map->GetDefaultContentSetting( 775 host_content_settings_map->GetDefaultContentSetting(
775 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 776 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
776 } 777 }
777 778
778 TEST_F(HostContentSettingsMapTest, 779 TEST_F(HostContentSettingsMapTest,
779 GetNonDefaultContentSettingsIfTypeManaged) { 780 GetNonDefaultContentSettingsIfTypeManaged) {
780 TestingProfile profile; 781 TestingProfile profile;
781 HostContentSettingsMap* host_content_settings_map = 782 HostContentSettingsMap* host_content_settings_map =
782 profile.GetHostContentSettingsMap(); 783 HostContentSettingsMapFactory::GetForProfile(&profile);
783 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 784 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
784 785
785 // Set pattern for JavaScript setting. 786 // Set pattern for JavaScript setting.
786 ContentSettingsPattern pattern = 787 ContentSettingsPattern pattern =
787 ContentSettingsPattern::FromString("[*.]example.com"); 788 ContentSettingsPattern::FromString("[*.]example.com");
788 host_content_settings_map->SetContentSetting( 789 host_content_settings_map->SetContentSetting(
789 pattern, 790 pattern,
790 ContentSettingsPattern::Wildcard(), 791 ContentSettingsPattern::Wildcard(),
791 CONTENT_SETTINGS_TYPE_JAVASCRIPT, 792 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
792 std::string(), 793 std::string(),
(...skipping 15 matching lines...) Expand all
808 host_content_settings_map->GetContentSetting( 809 host_content_settings_map->GetContentSetting(
809 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 810 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
810 } 811 }
811 812
812 // Managed default content setting should have higher priority 813 // Managed default content setting should have higher priority
813 // than user defined patterns. 814 // than user defined patterns.
814 TEST_F(HostContentSettingsMapTest, 815 TEST_F(HostContentSettingsMapTest,
815 ManagedDefaultContentSettingIgnoreUserPattern) { 816 ManagedDefaultContentSettingIgnoreUserPattern) {
816 TestingProfile profile; 817 TestingProfile profile;
817 HostContentSettingsMap* host_content_settings_map = 818 HostContentSettingsMap* host_content_settings_map =
818 profile.GetHostContentSettingsMap(); 819 HostContentSettingsMapFactory::GetForProfile(&profile);
819 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 820 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
820 821
821 // Block all JavaScript. 822 // Block all JavaScript.
822 host_content_settings_map->SetDefaultContentSetting( 823 host_content_settings_map->SetDefaultContentSetting(
823 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); 824 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
824 825
825 // Set an exception to allow "[*.]example.com" 826 // Set an exception to allow "[*.]example.com"
826 ContentSettingsPattern pattern = 827 ContentSettingsPattern pattern =
827 ContentSettingsPattern::FromString("[*.]example.com"); 828 ContentSettingsPattern::FromString("[*.]example.com");
828 829
(...skipping 24 matching lines...) Expand all
853 EXPECT_EQ(CONTENT_SETTING_ALLOW, 854 EXPECT_EQ(CONTENT_SETTING_ALLOW,
854 host_content_settings_map->GetContentSetting( 855 host_content_settings_map->GetContentSetting(
855 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); 856 host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
856 } 857 }
857 858
858 // If a default-content-setting is set to managed setting, the user defined 859 // If a default-content-setting is set to managed setting, the user defined
859 // setting should be preserved. 860 // setting should be preserved.
860 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { 861 TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {
861 TestingProfile profile; 862 TestingProfile profile;
862 HostContentSettingsMap* host_content_settings_map = 863 HostContentSettingsMap* host_content_settings_map =
863 profile.GetHostContentSettingsMap(); 864 HostContentSettingsMapFactory::GetForProfile(&profile);
864 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 865 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
865 866
866 // Set user defined default-content-setting for Cookies. 867 // Set user defined default-content-setting for Cookies.
867 host_content_settings_map->SetDefaultContentSetting( 868 host_content_settings_map->SetDefaultContentSetting(
868 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); 869 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
869 EXPECT_EQ(CONTENT_SETTING_BLOCK, 870 EXPECT_EQ(CONTENT_SETTING_BLOCK,
870 host_content_settings_map->GetDefaultContentSetting( 871 host_content_settings_map->GetDefaultContentSetting(
871 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 872 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
872 873
873 // Set preference to manage the default-content-setting for Cookies. 874 // Set preference to manage the default-content-setting for Cookies.
874 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting, 875 prefs->SetManagedPref(prefs::kManagedDefaultCookiesSetting,
875 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 876 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
876 EXPECT_EQ(CONTENT_SETTING_ALLOW, 877 EXPECT_EQ(CONTENT_SETTING_ALLOW,
877 host_content_settings_map->GetDefaultContentSetting( 878 host_content_settings_map->GetDefaultContentSetting(
878 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 879 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
879 880
880 // Remove the preference to manage the default-content-setting for Cookies. 881 // Remove the preference to manage the default-content-setting for Cookies.
881 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting); 882 prefs->RemoveManagedPref(prefs::kManagedDefaultCookiesSetting);
882 EXPECT_EQ(CONTENT_SETTING_BLOCK, 883 EXPECT_EQ(CONTENT_SETTING_BLOCK,
883 host_content_settings_map->GetDefaultContentSetting( 884 host_content_settings_map->GetDefaultContentSetting(
884 CONTENT_SETTINGS_TYPE_COOKIES, NULL)); 885 CONTENT_SETTINGS_TYPE_COOKIES, NULL));
885 } 886 }
886 887
887 // If a setting for a default-content-setting-type is set while the type is 888 // If a setting for a default-content-setting-type is set while the type is
888 // managed, then the new setting should be preserved and used after the 889 // managed, then the new setting should be preserved and used after the
889 // default-content-setting-type is not managed anymore. 890 // default-content-setting-type is not managed anymore.
890 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { 891 TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {
891 TestingProfile profile; 892 TestingProfile profile;
892 HostContentSettingsMap* host_content_settings_map = 893 HostContentSettingsMap* host_content_settings_map =
893 profile.GetHostContentSettingsMap(); 894 HostContentSettingsMapFactory::GetForProfile(&profile);
894 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService(); 895 TestingPrefServiceSyncable* prefs = profile.GetTestingPrefService();
895 896
896 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting, 897 prefs->SetManagedPref(prefs::kManagedDefaultPluginsSetting,
897 new base::FundamentalValue(CONTENT_SETTING_ALLOW)); 898 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
898 EXPECT_EQ(CONTENT_SETTING_ALLOW, 899 EXPECT_EQ(CONTENT_SETTING_ALLOW,
899 host_content_settings_map->GetDefaultContentSetting( 900 host_content_settings_map->GetDefaultContentSetting(
900 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 901 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
901 902
902 host_content_settings_map->SetDefaultContentSetting( 903 host_content_settings_map->SetDefaultContentSetting(
903 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK); 904 CONTENT_SETTINGS_TYPE_PLUGINS, CONTENT_SETTING_BLOCK);
904 EXPECT_EQ(CONTENT_SETTING_ALLOW, 905 EXPECT_EQ(CONTENT_SETTING_ALLOW,
905 host_content_settings_map->GetDefaultContentSetting( 906 host_content_settings_map->GetDefaultContentSetting(
906 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 907 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
907 908
908 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 909 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
909 EXPECT_EQ(CONTENT_SETTING_BLOCK, 910 EXPECT_EQ(CONTENT_SETTING_BLOCK,
910 host_content_settings_map->GetDefaultContentSetting( 911 host_content_settings_map->GetDefaultContentSetting(
911 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 912 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
912 } 913 }
913 914
914 TEST_F(HostContentSettingsMapTest, GetContentSetting) { 915 TEST_F(HostContentSettingsMapTest, GetContentSetting) {
915 TestingProfile profile; 916 TestingProfile profile;
916 HostContentSettingsMap* host_content_settings_map = 917 HostContentSettingsMap* host_content_settings_map =
917 profile.GetHostContentSettingsMap(); 918 HostContentSettingsMapFactory::GetForProfile(&profile);
918 919
919 GURL host("http://example.com/"); 920 GURL host("http://example.com/");
920 GURL embedder("chrome://foo"); 921 GURL embedder("chrome://foo");
921 ContentSettingsPattern pattern = 922 ContentSettingsPattern pattern =
922 ContentSettingsPattern::FromString("[*.]example.com"); 923 ContentSettingsPattern::FromString("[*.]example.com");
923 host_content_settings_map->SetContentSetting( 924 host_content_settings_map->SetContentSetting(
924 pattern, 925 pattern,
925 ContentSettingsPattern::Wildcard(), 926 ContentSettingsPattern::Wildcard(),
926 CONTENT_SETTINGS_TYPE_IMAGES, 927 CONTENT_SETTINGS_TYPE_IMAGES,
927 std::string(), 928 std::string(),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 prefs, CONTENT_SETTING_ALLOW, 969 prefs, CONTENT_SETTING_ALLOW,
969 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA)); 970 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
970 971
971 // TODO(msramek): Add more checks for setting type - setting pairs where 972 // TODO(msramek): Add more checks for setting type - setting pairs where
972 // it is not obvious whether or not they are allowed. 973 // it is not obvious whether or not they are allowed.
973 } 974 }
974 975
975 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { 976 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {
976 TestingProfile profile; 977 TestingProfile profile;
977 HostContentSettingsMap* host_content_settings_map = 978 HostContentSettingsMap* host_content_settings_map =
978 profile.GetHostContentSettingsMap(); 979 HostContentSettingsMapFactory::GetForProfile(&profile);
979 content_settings::MockObserver mock_observer; 980 content_settings::MockObserver mock_observer;
980 981
981 GURL host("http://example.com/"); 982 GURL host("http://example.com/");
982 ContentSettingsPattern pattern = 983 ContentSettingsPattern pattern =
983 ContentSettingsPattern::FromString("[*.]example.com"); 984 ContentSettingsPattern::FromString("[*.]example.com");
984 EXPECT_CALL(mock_observer, 985 EXPECT_CALL(mock_observer,
985 OnContentSettingChanged(pattern, 986 OnContentSettingChanged(pattern,
986 ContentSettingsPattern::Wildcard(), 987 ContentSettingsPattern::Wildcard(),
987 CONTENT_SETTINGS_TYPE_IMAGES, 988 CONTENT_SETTINGS_TYPE_IMAGES,
988 "")); 989 ""));
989 990
990 host_content_settings_map->AddObserver(&mock_observer); 991 host_content_settings_map->AddObserver(&mock_observer);
991 992
992 EXPECT_EQ(CONTENT_SETTING_ALLOW, 993 EXPECT_EQ(CONTENT_SETTING_ALLOW,
993 host_content_settings_map->GetContentSetting( 994 host_content_settings_map->GetContentSetting(
994 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 995 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
995 host_content_settings_map->SetContentSetting( 996 host_content_settings_map->SetContentSetting(
996 pattern, 997 pattern,
997 ContentSettingsPattern::Wildcard(), 998 ContentSettingsPattern::Wildcard(),
998 CONTENT_SETTINGS_TYPE_IMAGES, 999 CONTENT_SETTINGS_TYPE_IMAGES,
999 std::string(), 1000 std::string(),
1000 CONTENT_SETTING_DEFAULT); 1001 CONTENT_SETTING_DEFAULT);
1001 } 1002 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698