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

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: enhance tests 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 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 BLOCK.
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 cookies 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 ContentSettingsForOneType settings;
1313 host_content_settings_map->GetSettingsForOneType(
1314 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings);
1315 // |host_content_settings_map| contains default setting and a custom setting.
1316 EXPECT_EQ(2U, settings.size());
1317 bool found_setting = false;
msramek 2016/06/30 16:16:21 This can be simplified as: EXPECT_TRUE(settings[0
lshang 2016/07/04 02:46:00 Done.
1318 for (const ContentSettingPatternSource& setting_entry : settings) {
1319 if (setting_entry.primary_pattern.ToString() == "[*.]example.com") {
1320 EXPECT_FALSE(found_setting);
1321 found_setting = true;
1322 }
1323 }
1324 EXPECT_TRUE(found_setting);
1325
1326 // Set old formatted https settings.
1327 GURL https_host("https://example.com/");
1328 GURL https_host_narrower("https://a.example.com/");
1329
1330 // Change default setting to BLOCK.
1331 host_content_settings_map->SetDefaultContentSetting(
1332 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK);
1333 EXPECT_EQ(
1334 CONTENT_SETTING_BLOCK,
1335 host_content_settings_map->GetContentSetting(
1336 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1337 // Patterns generated for popups used to be domain scoped.
1338 host_content_settings_map->SetContentSettingCustomScope(
1339 ContentSettingsPattern::FromURL(https_host),
1340 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS,
1341 std::string(), CONTENT_SETTING_ALLOW);
1342 EXPECT_EQ(
1343 CONTENT_SETTING_ALLOW,
1344 host_content_settings_map->GetContentSetting(
1345 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1346 // Settings also apply to subdomains.
1347 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1348 host_content_settings_map->GetContentSetting(
1349 https_host_narrower, https_host_narrower,
1350 CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1351
1352 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS,
1353 std::string(), &settings);
1354 // |host_content_settings_map| contains default setting and a custom setting.
1355 EXPECT_EQ(2U, settings.size());
1356 found_setting = false;
1357 for (const ContentSettingPatternSource& setting_entry : settings) {
1358 if (setting_entry.primary_pattern.ToString() ==
1359 "https://[*.]example.com:443") {
1360 EXPECT_FALSE(found_setting);
1361 found_setting = true;
1362 }
1363 }
1364 EXPECT_TRUE(found_setting);
1365
1366 host_content_settings_map->MigrateDomainScopedSettings();
1367
1368 // After migration, settings only affect origins.
1369 EXPECT_EQ(
1370 CONTENT_SETTING_ALLOW,
1371 host_content_settings_map->GetContentSetting(
1372 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1373 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1374 host_content_settings_map->GetContentSetting(
1375 http_host_narrower, http_host_narrower,
1376 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1377 host_content_settings_map->GetSettingsForOneType(
1378 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings);
1379 // |host_content_settings_map| contains default setting and a custom setting.
msramek 2016/06/30 16:16:21 In my understanding, "custom setting" is a setting
lshang 2016/07/04 02:46:00 Done. Yeah you're right, 'custom setting' should r
1380 EXPECT_EQ(2U, settings.size());
1381 found_setting = false;
1382 for (const ContentSettingPatternSource& setting_entry : settings) {
1383 if (setting_entry.primary_pattern.ToString() == "http://example.com:80") {
1384 EXPECT_FALSE(found_setting);
1385 found_setting = true;
1386 }
1387 }
1388 EXPECT_TRUE(found_setting);
1389
1390 EXPECT_EQ(
1391 CONTENT_SETTING_ALLOW,
1392 host_content_settings_map->GetContentSetting(
1393 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1394 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1395 host_content_settings_map->GetContentSetting(
1396 https_host_narrower, https_host_narrower,
1397 CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
1398 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS,
1399 std::string(), &settings);
1400 // |host_content_settings_map| contains default setting and a custom setting.
1401 EXPECT_EQ(2U, settings.size());
1402 found_setting = false;
1403 for (const ContentSettingPatternSource& setting_entry : settings) {
1404 if (setting_entry.primary_pattern.ToString() == "https://example.com:443") {
1405 EXPECT_FALSE(found_setting);
1406 found_setting = true;
1407 }
1408 }
1409 EXPECT_TRUE(found_setting);
1410 }
1411
1281 TEST_F(HostContentSettingsMapTest, InvalidPattern) { 1412 TEST_F(HostContentSettingsMapTest, InvalidPattern) {
1282 // This is a regression test for crbug.com/618529, which fixed a memory leak 1413 // 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 1414 // when a website setting was set under a URL that mapped to an invalid
1284 // pattern. 1415 // pattern.
1285 TestingProfile profile; 1416 TestingProfile profile;
1286 HostContentSettingsMap* host_content_settings_map = 1417 HostContentSettingsMap* host_content_settings_map =
1287 HostContentSettingsMapFactory::GetForProfile(&profile); 1418 HostContentSettingsMapFactory::GetForProfile(&profile);
1288 GURL unsupported_url = GURL("view-source:http://www.google.com"); 1419 GURL unsupported_url = GURL("view-source:http://www.google.com");
1289 base::DictionaryValue test_value; 1420 base::DictionaryValue test_value;
1290 test_value.SetString("test", "value"); 1421 test_value.SetString("test", "value");
1291 host_content_settings_map->SetWebsiteSettingDefaultScope( 1422 host_content_settings_map->SetWebsiteSettingDefaultScope(
1292 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, 1423 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER,
1293 std::string(), base::WrapUnique(test_value.DeepCopy())); 1424 std::string(), base::WrapUnique(test_value.DeepCopy()));
1294 EXPECT_EQ(nullptr, 1425 EXPECT_EQ(nullptr,
1295 host_content_settings_map->GetWebsiteSetting( 1426 host_content_settings_map->GetWebsiteSetting(
1296 unsupported_url, unsupported_url, 1427 unsupported_url, unsupported_url,
1297 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); 1428 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr));
1298 } 1429 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698