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

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

Issue 2337873002: Revert cookies back to be domain scoped (Closed)
Patch Set: Created 4 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 <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 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 371 }
372 372
373 TEST_F(HostContentSettingsMapTest, Observer) { 373 TEST_F(HostContentSettingsMapTest, Observer) {
374 TestingProfile profile; 374 TestingProfile profile;
375 HostContentSettingsMap* host_content_settings_map = 375 HostContentSettingsMap* host_content_settings_map =
376 HostContentSettingsMapFactory::GetForProfile(&profile); 376 HostContentSettingsMapFactory::GetForProfile(&profile);
377 MockSettingsObserver observer(host_content_settings_map); 377 MockSettingsObserver observer(host_content_settings_map);
378 378
379 GURL host("http://example.com/"); 379 GURL host("http://example.com/");
380 ContentSettingsPattern primary_pattern = 380 ContentSettingsPattern primary_pattern =
381 ContentSettingsPattern::FromString("http://example.com:80"); 381 ContentSettingsPattern::FromString("[*.]example.com");
382 ContentSettingsPattern secondary_pattern = 382 ContentSettingsPattern secondary_pattern =
383 ContentSettingsPattern::Wildcard(); 383 ContentSettingsPattern::Wildcard();
384 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map, 384 EXPECT_CALL(observer, OnContentSettingsChanged(host_content_settings_map,
385 CONTENT_SETTINGS_TYPE_COOKIES, 385 CONTENT_SETTINGS_TYPE_COOKIES,
386 false, primary_pattern, 386 false, primary_pattern,
387 secondary_pattern, false)); 387 secondary_pattern, false));
388 host_content_settings_map->SetContentSettingDefaultScope( 388 host_content_settings_map->SetContentSettingDefaultScope(
389 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 389 host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
390 CONTENT_SETTING_ALLOW); 390 CONTENT_SETTING_ALLOW);
391 ::testing::Mock::VerifyAndClearExpectations(&observer); 391 ::testing::Mock::VerifyAndClearExpectations(&observer);
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 952
953 // Set utf-8 data. 953 // Set utf-8 data.
954 { 954 {
955 DictionaryPrefUpdate update(prefs, 955 DictionaryPrefUpdate update(prefs,
956 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); 956 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
957 base::DictionaryValue* all_settings_dictionary = update.Get(); 957 base::DictionaryValue* all_settings_dictionary = update.Get();
958 ASSERT_TRUE(NULL != all_settings_dictionary); 958 ASSERT_TRUE(NULL != all_settings_dictionary);
959 959
960 base::DictionaryValue* dummy_payload = new base::DictionaryValue; 960 base::DictionaryValue* dummy_payload = new base::DictionaryValue;
961 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW); 961 dummy_payload->SetInteger("setting", CONTENT_SETTING_ALLOW);
962 all_settings_dictionary->SetWithoutPathExpansion("www.\xC4\x87ira.com,*", 962 all_settings_dictionary->SetWithoutPathExpansion("[*.]\xC4\x87ira.com,*",
963 dummy_payload); 963 dummy_payload);
964 } 964 }
965 965
966 HostContentSettingsMapFactory::GetForProfile(&profile); 966 HostContentSettingsMapFactory::GetForProfile(&profile);
967 967
968 const base::DictionaryValue* all_settings_dictionary = 968 const base::DictionaryValue* all_settings_dictionary =
969 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); 969 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
970 const base::DictionaryValue* result = NULL; 970 const base::DictionaryValue* result = NULL;
971 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 971 EXPECT_FALSE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
972 "www.\xC4\x87ira.com,*", &result)); 972 "[*.]\xC4\x87ira.com,*", &result));
973 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( 973 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
974 "www.xn--ira-ppa.com,*", &result)); 974 "[*.]xn--ira-ppa.com,*", &result));
975 } 975 }
976 976
977 // If both Unicode and its punycode pattern exist, make sure we don't touch the 977 // If both Unicode and its punycode pattern exist, make sure we don't touch the
978 // settings for the punycode, and that Unicode pattern gets deleted. 978 // settings for the punycode, and that Unicode pattern gets deleted.
979 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { 979 TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {
980 TestingProfile profile; 980 TestingProfile profile;
981 981
982 std::unique_ptr<base::Value> value = 982 std::unique_ptr<base::Value> value =
983 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}"); 983 base::JSONReader::Read("{\"[*.]\\xC4\\x87ira.com,*\":{\"setting\":1}}");
984 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *value); 984 profile.GetPrefs()->Set(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES), *value);
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 } 1217 }
1218 1218
1219 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { 1219 TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {
1220 TestingProfile profile; 1220 TestingProfile profile;
1221 HostContentSettingsMap* host_content_settings_map = 1221 HostContentSettingsMap* host_content_settings_map =
1222 HostContentSettingsMapFactory::GetForProfile(&profile); 1222 HostContentSettingsMapFactory::GetForProfile(&profile);
1223 content_settings::MockObserver mock_observer; 1223 content_settings::MockObserver mock_observer;
1224 1224
1225 GURL host("http://example.com/"); 1225 GURL host("http://example.com/");
1226 ContentSettingsPattern pattern = 1226 ContentSettingsPattern pattern =
1227 ContentSettingsPattern::FromString("http://example.com:80"); 1227 ContentSettingsPattern::FromString("[*.]example.com");
1228 EXPECT_CALL(mock_observer, OnContentSettingChanged( 1228 EXPECT_CALL(mock_observer, OnContentSettingChanged(
1229 pattern, ContentSettingsPattern::Wildcard(), 1229 pattern, ContentSettingsPattern::Wildcard(),
1230 CONTENT_SETTINGS_TYPE_COOKIES, "")); 1230 CONTENT_SETTINGS_TYPE_COOKIES, ""));
1231 1231
1232 host_content_settings_map->AddObserver(&mock_observer); 1232 host_content_settings_map->AddObserver(&mock_observer);
1233 1233
1234 EXPECT_EQ(CONTENT_SETTING_ALLOW, 1234 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1235 host_content_settings_map->GetContentSetting( 1235 host_content_settings_map->GetContentSetting(
1236 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 1236 host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1237 host_content_settings_map->SetContentSettingDefaultScope( 1237 host_content_settings_map->SetContentSettingDefaultScope(
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1737 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( 1737 host_content_settings_map->ClearSettingsForOneTypeWithPredicate(
1738 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, 1738 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT,
1739 base::Bind(&MatchPrimaryPattern, http_pattern)); 1739 base::Bind(&MatchPrimaryPattern, http_pattern));
1740 // Verify we only have one, and it's url1. 1740 // Verify we only have one, and it's url1.
1741 host_content_settings_map->GetSettingsForOneType( 1741 host_content_settings_map->GetSettingsForOneType(
1742 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); 1742 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings);
1743 EXPECT_EQ(1u, host_settings.size()); 1743 EXPECT_EQ(1u, host_settings.size());
1744 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), 1744 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1),
1745 host_settings[0].primary_pattern); 1745 host_settings[0].primary_pattern);
1746 } 1746 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698