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

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

Issue 1895993003: Add migration code to change existing domain scoped content settings to be origin scoped (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments and split the CL Created 4 years, 6 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 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after
1271 1271
1272 // After migrating old settings, changes to the setting works. 1272 // After migrating old settings, changes to the setting works.
1273 host_content_settings_map->SetContentSettingDefaultScope( 1273 host_content_settings_map->SetContentSettingDefaultScope(
1274 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), 1274 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
1275 CONTENT_SETTING_BLOCK); 1275 CONTENT_SETTING_BLOCK);
1276 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1276 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1277 host_content_settings_map->GetContentSetting( 1277 host_content_settings_map->GetContentSetting(
1278 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); 1278 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
1279 } 1279 }
1280 1280
1281 TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) {
1282 TestingProfile profile;
1283 HostContentSettingsMap* host_content_settings_map =
1284 HostContentSettingsMapFactory::GetForProfile(&profile);
1285
1286 // Set old formatted http settings.
1287 GURL http_host("http://example.com/");
1288 GURL http_host_narrower("http://a.example.com/");
1289
1290 // Change default setting to BLCOK.
raymes 2016/06/20 04:03:26 nit: BLOCK
lshang 2016/06/23 01:32:31 Done.
1291 host_content_settings_map->SetDefaultContentSetting(
1292 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1293 EXPECT_EQ(
1294 CONTENT_SETTING_BLOCK,
1295 host_content_settings_map->GetContentSetting(
1296 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1297 // Patterns generated for images used to be domain scoped.
1298 host_content_settings_map->SetContentSettingCustomScope(
1299 ContentSettingsPattern::FromURL(http_host),
1300 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
1301 std::string(), CONTENT_SETTING_ALLOW);
1302 EXPECT_EQ(
1303 CONTENT_SETTING_ALLOW,
1304 host_content_settings_map->GetContentSetting(
1305 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1306 // Settings also apply to subdomains.
1307 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1308 host_content_settings_map->GetContentSetting(
1309 http_host_narrower, http_host_narrower,
1310 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1311
1312 // Set old formatted https settings.
1313 GURL https_host("https://example.com/");
1314 GURL https_host_narrower("https://a.example.com/");
1315
1316 // Change default setting to BLCOK.
raymes 2016/06/20 04:03:25 nit: BLOCK
lshang 2016/06/23 01:32:31 Done.
1317 host_content_settings_map->SetDefaultContentSetting(
1318 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK);
1319 EXPECT_EQ(
1320 CONTENT_SETTING_BLOCK,
1321 host_content_settings_map->GetContentSetting(
1322 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1323 // Patterns generated for cookies used to be domain scoped.
1324 host_content_settings_map->SetContentSettingCustomScope(
1325 ContentSettingsPattern::FromURL(https_host),
1326 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS,
1327 std::string(), CONTENT_SETTING_ALLOW);
1328 EXPECT_EQ(
1329 CONTENT_SETTING_ALLOW,
1330 host_content_settings_map->GetContentSetting(
1331 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1332 // Settings also apply to subdomains.
1333 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1334 host_content_settings_map->GetContentSetting(
1335 https_host_narrower, https_host_narrower,
1336 CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1337
1338 host_content_settings_map->MigrateDomainScopedSettings();
1339
1340 // After migration, settings only affect origins.
1341 EXPECT_EQ(
1342 CONTENT_SETTING_ALLOW,
1343 host_content_settings_map->GetContentSetting(
1344 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1345 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1346 host_content_settings_map->GetContentSetting(
1347 http_host_narrower, http_host_narrower,
1348 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1349
1350 EXPECT_EQ(
1351 CONTENT_SETTING_ALLOW,
1352 host_content_settings_map->GetContentSetting(
1353 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1354 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1355 host_content_settings_map->GetContentSetting(
1356 https_host_narrower, https_host_narrower,
1357 CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1358 }
1359
1281 TEST_F(HostContentSettingsMapTest, InvalidPattern) { 1360 TEST_F(HostContentSettingsMapTest, InvalidPattern) {
1282 // This is a regression test for crbug.com/618529, which fixed a memory leak 1361 // This is a regression test for crbug.com/618529, which fixed a memory leak
1283 // when a website setting was set under a URL that mapped to an invalid 1362 // when a website setting was set under a URL that mapped to an invalid
1284 // pattern. 1363 // pattern.
1285 TestingProfile profile; 1364 TestingProfile profile;
1286 HostContentSettingsMap* host_content_settings_map = 1365 HostContentSettingsMap* host_content_settings_map =
1287 HostContentSettingsMapFactory::GetForProfile(&profile); 1366 HostContentSettingsMapFactory::GetForProfile(&profile);
1288 GURL unsupported_url = GURL("view-source:http://www.google.com"); 1367 GURL unsupported_url = GURL("view-source:http://www.google.com");
1289 base::DictionaryValue test_value; 1368 base::DictionaryValue test_value;
1290 test_value.SetString("test", "value"); 1369 test_value.SetString("test", "value");
1291 host_content_settings_map->SetWebsiteSettingDefaultScope( 1370 host_content_settings_map->SetWebsiteSettingDefaultScope(
1292 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, 1371 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER,
1293 std::string(), base::WrapUnique(test_value.DeepCopy())); 1372 std::string(), base::WrapUnique(test_value.DeepCopy()));
1294 EXPECT_EQ(nullptr, 1373 EXPECT_EQ(nullptr,
1295 host_content_settings_map->GetWebsiteSetting( 1374 host_content_settings_map->GetWebsiteSetting(
1296 unsupported_url, unsupported_url, 1375 unsupported_url, unsupported_url,
1297 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); 1376 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr));
1298 } 1377 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698