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

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

Issue 1257093002: Remove the migration code from content_settings::PrefProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed the tests. Created 5 years, 4 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"
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 357
358 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) { 358 TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {
359 TestingProfile profile; 359 TestingProfile profile;
360 HostContentSettingsMap* host_content_settings_map = 360 HostContentSettingsMap* host_content_settings_map =
361 profile.GetHostContentSettingsMap(); 361 profile.GetHostContentSettingsMap();
362 362
363 PrefService* prefs = profile.GetPrefs(); 363 PrefService* prefs = profile.GetPrefs();
364 364
365 // Make a copy of the default pref value so we can reset it later. 365 // Make a copy of the default pref value so we can reset it later.
366 scoped_ptr<base::Value> default_value(prefs->FindPreference( 366 scoped_ptr<base::Value> default_value(prefs->FindPreference(
367 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 367 prefs::kContentSettingsImagesPatternPairs)->GetValue()->DeepCopy());
368 368
369 ContentSettingsPattern pattern = 369 ContentSettingsPattern pattern =
370 ContentSettingsPattern::FromString("[*.]example.com"); 370 ContentSettingsPattern::FromString("[*.]example.com");
371 GURL host("http://example.com"); 371 GURL host("http://example.com");
372 372
373 EXPECT_EQ(CONTENT_SETTING_ALLOW, 373 EXPECT_EQ(CONTENT_SETTING_ALLOW,
374 host_content_settings_map->GetContentSetting( 374 host_content_settings_map->GetContentSetting(
375 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 375 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
376 376
377 host_content_settings_map->SetContentSetting( 377 host_content_settings_map->SetContentSetting(
378 pattern, 378 pattern,
379 ContentSettingsPattern::Wildcard(), 379 ContentSettingsPattern::Wildcard(),
380 CONTENT_SETTINGS_TYPE_IMAGES, 380 CONTENT_SETTINGS_TYPE_IMAGES,
381 std::string(), 381 std::string(),
382 CONTENT_SETTING_BLOCK); 382 CONTENT_SETTING_BLOCK);
383 EXPECT_EQ(CONTENT_SETTING_BLOCK, 383 EXPECT_EQ(CONTENT_SETTING_BLOCK,
384 host_content_settings_map->GetContentSetting( 384 host_content_settings_map->GetContentSetting(
385 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 385 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
386 386
387 // Make a copy of the pref's new value so we can reset it later. 387 // Make a copy of the pref's new value so we can reset it later.
388 scoped_ptr<base::Value> new_value(prefs->FindPreference( 388 scoped_ptr<base::Value> new_value(prefs->FindPreference(
389 prefs::kContentSettingsPatternPairs)->GetValue()->DeepCopy()); 389 prefs::kContentSettingsImagesPatternPairs)->GetValue()->DeepCopy());
390 390
391 // Clearing the backing pref should also clear the internal cache. 391 // Clearing the backing pref should also clear the internal cache.
392 prefs->Set(prefs::kContentSettingsPatternPairs, *default_value); 392 prefs->Set(prefs::kContentSettingsImagesPatternPairs, *default_value);
393 EXPECT_EQ(CONTENT_SETTING_ALLOW, 393 EXPECT_EQ(CONTENT_SETTING_ALLOW,
394 host_content_settings_map->GetContentSetting( 394 host_content_settings_map->GetContentSetting(
395 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 395 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
396 396
397 // Reseting the pref to its previous value should update the cache. 397 // Reseting the pref to its previous value should update the cache.
398 prefs->Set(prefs::kContentSettingsPatternPairs, *new_value); 398 prefs->Set(prefs::kContentSettingsImagesPatternPairs, *new_value);
399 EXPECT_EQ(CONTENT_SETTING_BLOCK, 399 EXPECT_EQ(CONTENT_SETTING_BLOCK,
400 host_content_settings_map->GetContentSetting( 400 host_content_settings_map->GetContentSetting(
401 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 401 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
402 } 402 }
403 403
404 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) { 404 TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {
405 TestingProfile profile; 405 TestingProfile profile;
406 HostContentSettingsMap* host_content_settings_map = 406 HostContentSettingsMap* host_content_settings_map =
407 profile.GetHostContentSettingsMap(); 407 profile.GetHostContentSettingsMap();
408 content_settings::CookieSettings* cookie_settings = 408 content_settings::CookieSettings* cookie_settings =
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 675
676 // For a single Unicode encoded pattern, check if it gets converted to punycode 676 // For a single Unicode encoded pattern, check if it gets converted to punycode
677 // and old pattern gets deleted. 677 // and old pattern gets deleted.
678 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { 678 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {
679 TestingProfile profile; 679 TestingProfile profile;
680 PrefService* prefs = profile.GetPrefs(); 680 PrefService* prefs = profile.GetPrefs();
681 681
682 // Set utf-8 data. 682 // Set utf-8 data.
683 { 683 {
684 DictionaryPrefUpdate update( 684 DictionaryPrefUpdate update(
685 prefs, prefs::kContentSettingsPatternPairs); 685 prefs, prefs::kContentSettingsPluginsPatternPairs);
686 base::DictionaryValue* all_settings_dictionary = update.Get(); 686 base::DictionaryValue* all_settings_dictionary = update.Get();
687 ASSERT_TRUE(NULL != all_settings_dictionary); 687 ASSERT_TRUE(NULL != all_settings_dictionary);
688 688
689 base::DictionaryValue* dummy_payload = new base::DictionaryValue; 689 base::DictionaryValue* dummy_payload = new base::DictionaryValue;
690 dummy_payload->SetInteger("images", CONTENT_SETTING_ALLOW); 690 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW);
691 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", 691 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
692 dummy_payload); 692 dummy_payload);
693 } 693 }
694 694
695 profile.GetHostContentSettingsMap(); 695 profile.GetHostContentSettingsMap();
696 696
697 const base::DictionaryValue* all_settings_dictionary = 697 const base::DictionaryValue* all_settings_dictionary =
698 prefs->GetDictionary(prefs::kContentSettingsImagesPatternPairs); 698 prefs->GetDictionary(prefs::kContentSettingsPluginsPatternPairs);
699 const base::DictionaryValue* result = NULL; 699 const base::DictionaryValue* result = NULL;
700 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 700 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
701 "[*.]\xC4\x87ira.com,*", &result)); 701 "[*.]\xC4\x87ira.com,*", &result));
702 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 702 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
703 "[*.]xn--ira-ppa.com,*", &result)); 703 "[*.]xn--ira-ppa.com,*", &result));
704 } 704 }
705 705
706 // If both Unicode and its punycode pattern exist, make sure we don't touch the 706 // If both Unicode and its punycode pattern exist, make sure we don't touch the
707 // settings for the punycode, and that Unicode pattern gets deleted. 707 // settings for the punycode, and that Unicode pattern gets deleted.
708 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { 708 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
709 TestingProfile profile; 709 TestingProfile profile;
710 710
711 scoped_ptr<base::Value> value(base::JSONReader::DeprecatedRead( 711 scoped_ptr<base::Value> value(base::JSONReader::DeprecatedRead(
712 "{\"[*.]\\xC4\\x87ira.com,*\":{\"images\":1}}")); 712 "{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"));
713 profile.GetPrefs()->Set(prefs::kContentSettingsPatternPairs, *value); 713 profile.GetPrefs()->Set(prefs::kContentSettingsCookiesPatternPairs, *value);
714 714
715 // Set punycode equivalent, with different setting. 715 // Set punycode equivalent, with different setting.
716 scoped_ptr<base::Value> puny_value(base::JSONReader::DeprecatedRead( 716 scoped_ptr<base::Value> puny_value(base::JSONReader::DeprecatedRead(
717 "{\"[*.]xn--ira-ppa.com,*\":{\"images\":2}}")); 717 "{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}"));
718 profile.GetPrefs()->Set( 718 profile.GetPrefs()->Set(
719 prefs::kContentSettingsPatternPairs, *puny_value); 719 prefs::kContentSettingsCookiesPatternPairs, *puny_value);
720 720
721 // Initialize the content map. 721 // Initialize the content map.
722 profile.GetHostContentSettingsMap(); 722 profile.GetHostContentSettingsMap();
723 723
724 const base::DictionaryValue& content_setting_prefs = 724 const base::DictionaryValue& content_setting_prefs =
725 *profile.GetPrefs()->GetDictionary( 725 *profile.GetPrefs()->GetDictionary(
726 prefs::kContentSettingsImagesPatternPairs); 726 prefs::kContentSettingsCookiesPatternPairs);
727 std::string prefs_as_json; 727 std::string prefs_as_json;
728 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json); 728 base::JSONWriter::Write(content_setting_prefs, &prefs_as_json);
729 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}", 729 EXPECT_STREQ("{\"[*.]xn--ira-ppa.com,*\":{\"setting\":2}}",
730 prefs_as_json.c_str()); 730 prefs_as_json.c_str());
731 } 731 }
732 732
733 // If a default-content-setting is managed, the managed value should be used 733 // If a default-content-setting is managed, the managed value should be used
734 // instead of the default value. 734 // instead of the default value.
735 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { 735 TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) {
736 TestingProfile profile; 736 TestingProfile profile;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1016 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1017 host_content_settings_map->GetContentSetting( 1017 host_content_settings_map->GetContentSetting(
1018 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); 1018 host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string()));
1019 host_content_settings_map->SetContentSetting( 1019 host_content_settings_map->SetContentSetting(
1020 pattern, 1020 pattern,
1021 ContentSettingsPattern::Wildcard(), 1021 ContentSettingsPattern::Wildcard(),
1022 CONTENT_SETTINGS_TYPE_IMAGES, 1022 CONTENT_SETTINGS_TYPE_IMAGES,
1023 std::string(), 1023 std::string(),
1024 CONTENT_SETTING_DEFAULT); 1024 CONTENT_SETTING_DEFAULT);
1025 } 1025 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698