OLD | NEW |
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 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 | 1344 |
1345 // After migrating old settings, changes to the setting works. | 1345 // After migrating old settings, changes to the setting works. |
1346 host_content_settings_map->SetContentSettingDefaultScope( | 1346 host_content_settings_map->SetContentSettingDefaultScope( |
1347 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), | 1347 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), |
1348 CONTENT_SETTING_BLOCK); | 1348 CONTENT_SETTING_BLOCK); |
1349 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1349 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1350 host_content_settings_map->GetContentSetting( | 1350 host_content_settings_map->GetContentSetting( |
1351 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 1351 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
1352 } | 1352 } |
1353 | 1353 |
| 1354 TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) { |
| 1355 TestingProfile profile; |
| 1356 HostContentSettingsMap* host_content_settings_map = |
| 1357 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1358 |
| 1359 // Set old formatted http settings. |
| 1360 GURL http_host("http://example.com/"); |
| 1361 GURL http_host_narrower("http://a.example.com/"); |
| 1362 |
| 1363 // Change default setting to BLOCK. |
| 1364 host_content_settings_map->SetDefaultContentSetting( |
| 1365 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); |
| 1366 EXPECT_EQ( |
| 1367 CONTENT_SETTING_BLOCK, |
| 1368 host_content_settings_map->GetContentSetting( |
| 1369 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 1370 // Patterns generated for cookies used to be domain scoped. |
| 1371 host_content_settings_map->SetContentSettingCustomScope( |
| 1372 ContentSettingsPattern::FromURL(http_host), |
| 1373 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES, |
| 1374 std::string(), CONTENT_SETTING_ALLOW); |
| 1375 EXPECT_EQ( |
| 1376 CONTENT_SETTING_ALLOW, |
| 1377 host_content_settings_map->GetContentSetting( |
| 1378 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 1379 // Settings also apply to subdomains. |
| 1380 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1381 host_content_settings_map->GetContentSetting( |
| 1382 http_host_narrower, http_host_narrower, |
| 1383 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 1384 |
| 1385 ContentSettingsForOneType settings; |
| 1386 host_content_settings_map->GetSettingsForOneType( |
| 1387 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); |
| 1388 // |host_content_settings_map| contains default setting and a domain scoped |
| 1389 // setting. |
| 1390 EXPECT_EQ(2U, settings.size()); |
| 1391 EXPECT_TRUE(settings[0].primary_pattern.ToString() == "[*.]example.com"); |
| 1392 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| 1393 |
| 1394 // Set old formatted https settings. |
| 1395 GURL https_host("https://example.com/"); |
| 1396 GURL https_host_narrower("https://a.example.com/"); |
| 1397 |
| 1398 // Change default setting to BLOCK. |
| 1399 host_content_settings_map->SetDefaultContentSetting( |
| 1400 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK); |
| 1401 EXPECT_EQ( |
| 1402 CONTENT_SETTING_BLOCK, |
| 1403 host_content_settings_map->GetContentSetting( |
| 1404 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1405 // Patterns generated for popups used to be domain scoped. |
| 1406 host_content_settings_map->SetContentSettingCustomScope( |
| 1407 ContentSettingsPattern::FromURL(https_host), |
| 1408 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 1409 std::string(), CONTENT_SETTING_ALLOW); |
| 1410 EXPECT_EQ( |
| 1411 CONTENT_SETTING_ALLOW, |
| 1412 host_content_settings_map->GetContentSetting( |
| 1413 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1414 // Settings also apply to subdomains. |
| 1415 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1416 host_content_settings_map->GetContentSetting( |
| 1417 https_host_narrower, https_host_narrower, |
| 1418 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1419 |
| 1420 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
| 1421 std::string(), &settings); |
| 1422 // |host_content_settings_map| contains default setting and a domain scoped |
| 1423 // setting. |
| 1424 EXPECT_EQ(2U, settings.size()); |
| 1425 EXPECT_TRUE(settings[0].primary_pattern.ToString() == |
| 1426 "https://[*.]example.com:443"); |
| 1427 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| 1428 |
| 1429 host_content_settings_map->MigrateDomainScopedSettings(); |
| 1430 |
| 1431 // After migration, settings only affect origins. |
| 1432 EXPECT_EQ( |
| 1433 CONTENT_SETTING_ALLOW, |
| 1434 host_content_settings_map->GetContentSetting( |
| 1435 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 1436 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1437 host_content_settings_map->GetContentSetting( |
| 1438 http_host_narrower, http_host_narrower, |
| 1439 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| 1440 host_content_settings_map->GetSettingsForOneType( |
| 1441 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); |
| 1442 // |host_content_settings_map| contains default setting and a origin scoped |
| 1443 // setting. |
| 1444 EXPECT_EQ(2U, settings.size()); |
| 1445 EXPECT_TRUE(settings[0].primary_pattern.ToString() == |
| 1446 "http://example.com:80"); |
| 1447 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| 1448 |
| 1449 EXPECT_EQ( |
| 1450 CONTENT_SETTING_ALLOW, |
| 1451 host_content_settings_map->GetContentSetting( |
| 1452 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1453 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1454 host_content_settings_map->GetContentSetting( |
| 1455 https_host_narrower, https_host_narrower, |
| 1456 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1457 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
| 1458 std::string(), &settings); |
| 1459 // |host_content_settings_map| contains default setting and a origin scoped |
| 1460 // setting. |
| 1461 EXPECT_EQ(2U, settings.size()); |
| 1462 EXPECT_TRUE(settings[0].primary_pattern.ToString() == |
| 1463 "https://example.com:443"); |
| 1464 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| 1465 } |
| 1466 |
1354 TEST_F(HostContentSettingsMapTest, InvalidPattern) { | 1467 TEST_F(HostContentSettingsMapTest, InvalidPattern) { |
1355 // This is a regression test for crbug.com/618529, which fixed a memory leak | 1468 // This is a regression test for crbug.com/618529, which fixed a memory leak |
1356 // when a website setting was set under a URL that mapped to an invalid | 1469 // when a website setting was set under a URL that mapped to an invalid |
1357 // pattern. | 1470 // pattern. |
1358 TestingProfile profile; | 1471 TestingProfile profile; |
1359 HostContentSettingsMap* host_content_settings_map = | 1472 HostContentSettingsMap* host_content_settings_map = |
1360 HostContentSettingsMapFactory::GetForProfile(&profile); | 1473 HostContentSettingsMapFactory::GetForProfile(&profile); |
1361 GURL unsupported_url = GURL("view-source:http://www.google.com"); | 1474 GURL unsupported_url = GURL("view-source:http://www.google.com"); |
1362 base::DictionaryValue test_value; | 1475 base::DictionaryValue test_value; |
1363 test_value.SetString("test", "value"); | 1476 test_value.SetString("test", "value"); |
1364 host_content_settings_map->SetWebsiteSettingDefaultScope( | 1477 host_content_settings_map->SetWebsiteSettingDefaultScope( |
1365 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, | 1478 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, |
1366 std::string(), base::WrapUnique(test_value.DeepCopy())); | 1479 std::string(), base::WrapUnique(test_value.DeepCopy())); |
1367 EXPECT_EQ(nullptr, | 1480 EXPECT_EQ(nullptr, |
1368 host_content_settings_map->GetWebsiteSetting( | 1481 host_content_settings_map->GetWebsiteSetting( |
1369 unsupported_url, unsupported_url, | 1482 unsupported_url, unsupported_url, |
1370 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); | 1483 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); |
1371 } | 1484 } |
OLD | NEW |