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

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

Issue 2075103002: Change ContentSettingsType's scoping type and hookup migration code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@do_migration_after_sync
Patch Set: rebase Created 4 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
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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 7
8 #include "base/auto_reset.h" 8 #include "base/auto_reset.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 361 }
362 362
363 TEST_F(HostContentSettingsMapTest, Observer) { 363 TEST_F(HostContentSettingsMapTest, Observer) {
364 TestingProfile profile; 364 TestingProfile profile;
365 HostContentSettingsMap* host_content_settings_map = 365 HostContentSettingsMap* host_content_settings_map =
366 HostContentSettingsMapFactory::GetForProfile(&profile); 366 HostContentSettingsMapFactory::GetForProfile(&profile);
367 MockSettingsObserver observer(host_content_settings_map); 367 MockSettingsObserver observer(host_content_settings_map);
368 368
369 GURL host("http://example.com/"); 369 GURL host("http://example.com/");
370 ContentSettingsPattern primary_pattern = 370 ContentSettingsPattern primary_pattern =
371 ContentSettingsPattern::FromString("[*.]example.com"); 371 ContentSettingsPattern::FromString("http://example.com:80");
372 ContentSettingsPattern secondary_pattern = 372 ContentSettingsPattern secondary_pattern =
373 ContentSettingsPattern::Wildcard(); 373 ContentSettingsPattern::Wildcard();
374 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map, 374 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map,
375 CONTENT_SETTINGS_TYPE_COOKIES, 375 CONTENT_SETTINGS_TYPE_COOKIES,
376 false, primary_pattern, 376 false, primary_pattern,
377 secondary_pattern, false)); 377 secondary_pattern, false));
378 host_content_settings_map->SetContentSettingDefaultScope( 378 host_content_settings_map->SetContentSettingDefaultScope(
379 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 379 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
380 CONTENT_SETTING_ALLOW); 380 CONTENT_SETTING_ALLOW);
381 ::testing::Mock::VerifyAndClearExpectations(&observer); 381 ::testing::Mock::VerifyAndClearExpectations(&observer);
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
942 942
943 // Set utf-8 data. 943 // Set utf-8 data.
944 { 944 {
945 DictionaryPrefUpdate update(prefs, 945 DictionaryPrefUpdate update(prefs,
946 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); 946 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
947 base::DictionaryValue* all_settings_dictionary = update.Get(); 947 base::DictionaryValue* all_settings_dictionary = update.Get();
948 ASSERT_TRUE(NULL != all_settings_dictionary); 948 ASSERT_TRUE(NULL != all_settings_dictionary);
949 949
950 base::DictionaryValue* dummy_payload = new base::DictionaryValue; 950 base::DictionaryValue* dummy_payload = new base::DictionaryValue;
951 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW); 951 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW);
952 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*", 952 all_settings_dictionary->SetWithoutPathExpansion("www.\xC4\x87ira.com,*",
953 dummy_payload); 953 dummy_payload);
954 } 954 }
955 955
956 HostContentSettingsMapFactory::GetForProfile(&profile); 956 HostContentSettingsMapFactory::GetForProfile(&profile);
957 957
958 const base::DictionaryValue* all_settings_dictionary = 958 const base::DictionaryValue* all_settings_dictionary =
959 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); 959 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
960 const base::DictionaryValue* result = NULL; 960 const base::DictionaryValue* result = NULL;
961 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 961 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
962 "[*.]\xC4\x87ira.com,*", &result)); 962 "www.\xC4\x87ira.com,*", &result));
963 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 963 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
964 "[*.]xn--ira-ppa.com,*", &result)); 964 "www.xn--ira-ppa.com,*", &result));
965 } 965 }
966 966
967 // If both Unicode and its punycode pattern exist, make sure we don't touch the 967 // If both Unicode and its punycode pattern exist, make sure we don't touch the
968 // settings for the punycode, and that Unicode pattern gets deleted. 968 // settings for the punycode, and that Unicode pattern gets deleted.
969 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { 969 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
970 TestingProfile profile; 970 TestingProfile profile;
971 971
972 std::unique_ptr<base::Value> value = 972 std::unique_ptr<base::Value> value =
973 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"); 973 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}");
974 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *value); 974 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *value);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 } 1207 }
1208 1208
1209 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { 1209 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {
1210 TestingProfile profile; 1210 TestingProfile profile;
1211 HostContentSettingsMap* host_content_settings_map = 1211 HostContentSettingsMap* host_content_settings_map =
1212 HostContentSettingsMapFactory::GetForProfile(&profile); 1212 HostContentSettingsMapFactory::GetForProfile(&profile);
1213 content_settings::MockObserver mock_observer; 1213 content_settings::MockObserver mock_observer;
1214 1214
1215 GURL host("http://example.com/"); 1215 GURL host("http://example.com/");
1216 ContentSettingsPattern pattern = 1216 ContentSettingsPattern pattern =
1217 ContentSettingsPattern::FromString("[*.]example.com"); 1217 ContentSettingsPattern::FromString("http://example.com:80");
1218 EXPECT_CALL(mock_observer, OnContentSettingChanged( 1218 EXPECT_CALL(mock_observer, OnContentSettingChanged(
1219 pattern, ContentSettingsPattern::Wildcard(), 1219 pattern, ContentSettingsPattern::Wildcard(),
1220 CONTENT_SETTINGS_TYPE_COOKIES, "")); 1220 CONTENT_SETTINGS_TYPE_COOKIES, ""));
1221 1221
1222 host_content_settings_map->AddObserver(&mock_observer); 1222 host_content_settings_map->AddObserver(&mock_observer);
1223 1223
1224 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1224 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1225 host_content_settings_map->GetContentSetting( 1225 host_content_settings_map->GetContentSetting(
1226 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 1226 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1227 host_content_settings_map->SetContentSettingDefaultScope( 1227 host_content_settings_map->SetContentSettingDefaultScope(
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 base::DictionaryValue test_value; 1475 base::DictionaryValue test_value;
1476 test_value.SetString("test", "value"); 1476 test_value.SetString("test", "value");
1477 host_content_settings_map->SetWebsiteSettingDefaultScope( 1477 host_content_settings_map->SetWebsiteSettingDefaultScope(
1478 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, 1478 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER,
1479 std::string(), base::WrapUnique(test_value.DeepCopy())); 1479 std::string(), base::WrapUnique(test_value.DeepCopy()));
1480 EXPECT_EQ(nullptr, 1480 EXPECT_EQ(nullptr,
1481 host_content_settings_map->GetWebsiteSetting( 1481 host_content_settings_map->GetWebsiteSetting(
1482 unsupported_url, unsupported_url, 1482 unsupported_url, unsupported_url,
1483 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); 1483 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr));
1484 } 1484 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698