Chromium Code Reviews| 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 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1362 prefs->GetDefaultPrefValue(prefs::kDomainToOriginMigrationStatus) | 1362 prefs->GetDefaultPrefValue(prefs::kDomainToOriginMigrationStatus) |
| 1363 ->GetAsInteger(&default_value); | 1363 ->GetAsInteger(&default_value); |
| 1364 prefs->SetInteger(prefs::kDomainToOriginMigrationStatus, default_value); | 1364 prefs->SetInteger(prefs::kDomainToOriginMigrationStatus, default_value); |
| 1365 | 1365 |
| 1366 // Set old formatted http settings. | 1366 // Set old formatted http settings. |
| 1367 GURL http_host("http://example.com/"); | 1367 GURL http_host("http://example.com/"); |
| 1368 GURL http_host_narrower("http://a.example.com/"); | 1368 GURL http_host_narrower("http://a.example.com/"); |
| 1369 | 1369 |
| 1370 // Change default setting to BLOCK. | 1370 // Change default setting to BLOCK. |
| 1371 host_content_settings_map->SetDefaultContentSetting( | 1371 host_content_settings_map->SetDefaultContentSetting( |
| 1372 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 1372 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK); |
| 1373 EXPECT_EQ( | 1373 EXPECT_EQ( |
| 1374 CONTENT_SETTING_BLOCK, | 1374 CONTENT_SETTING_BLOCK, |
| 1375 host_content_settings_map->GetContentSetting( | 1375 host_content_settings_map->GetContentSetting( |
| 1376 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1376 http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1377 // Patterns generated for cookies used to be domain scoped. | 1377 // Patterns generated for cookies used to be domain scoped. |
| 1378 host_content_settings_map->SetContentSettingCustomScope( | 1378 host_content_settings_map->SetContentSettingCustomScope( |
| 1379 ContentSettingsPattern::FromURL(http_host), | 1379 ContentSettingsPattern::FromURL(http_host), |
| 1380 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES, | 1380 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 1381 std::string(), CONTENT_SETTING_ALLOW); | 1381 std::string(), CONTENT_SETTING_ALLOW); |
| 1382 EXPECT_EQ( | 1382 EXPECT_EQ( |
| 1383 CONTENT_SETTING_ALLOW, | 1383 CONTENT_SETTING_ALLOW, |
| 1384 host_content_settings_map->GetContentSetting( | 1384 host_content_settings_map->GetContentSetting( |
| 1385 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1385 http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1386 // Settings also apply to subdomains. | 1386 // Settings also apply to subdomains. |
| 1387 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1387 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1388 host_content_settings_map->GetContentSetting( | 1388 host_content_settings_map->GetContentSetting( |
| 1389 http_host_narrower, http_host_narrower, | 1389 http_host_narrower, http_host_narrower, |
| 1390 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1390 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1391 | 1391 |
| 1392 ContentSettingsForOneType settings; | 1392 ContentSettingsForOneType settings; |
| 1393 host_content_settings_map->GetSettingsForOneType( | 1393 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
| 1394 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); | 1394 std::string(), &settings); |
| 1395 // |host_content_settings_map| contains default setting and a domain scoped | 1395 // |host_content_settings_map| contains default setting and a domain scoped |
| 1396 // setting. | 1396 // setting. |
| 1397 EXPECT_EQ(2U, settings.size()); | 1397 EXPECT_EQ(2U, settings.size()); |
| 1398 EXPECT_TRUE(settings[0].primary_pattern.ToString() == "[*.]example.com"); | 1398 EXPECT_TRUE(settings[0].primary_pattern.ToString() == "[*.]example.com"); |
| 1399 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); | 1399 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| 1400 | 1400 |
| 1401 // Set old formatted https settings. | 1401 // Set old formatted https settings. |
| 1402 GURL https_host("https://example.com/"); | 1402 GURL https_host("https://example.com/"); |
| 1403 GURL https_host_narrower("https://a.example.com/"); | 1403 GURL https_host_narrower("https://a.example.com/"); |
| 1404 | 1404 |
| 1405 // Change default setting to BLOCK. | 1405 // Change default setting to BLOCK. |
| 1406 host_content_settings_map->SetDefaultContentSetting( | 1406 host_content_settings_map->SetDefaultContentSetting( |
| 1407 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK); | 1407 CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
| 1408 EXPECT_EQ( | 1408 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1409 CONTENT_SETTING_BLOCK, | 1409 host_content_settings_map->GetContentSetting( |
| 1410 host_content_settings_map->GetContentSetting( | 1410 https_host, https_host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 1411 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | 1411 std::string())); |
| 1412 // Patterns generated for popups used to be domain scoped. | 1412 // Patterns generated for popups used to be domain scoped. |
| 1413 host_content_settings_map->SetContentSettingCustomScope( | 1413 host_content_settings_map->SetContentSettingCustomScope( |
| 1414 ContentSettingsPattern::FromURL(https_host), | 1414 ContentSettingsPattern::FromURL(https_host), |
| 1415 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, | 1415 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 1416 std::string(), CONTENT_SETTING_ALLOW); | 1416 std::string(), CONTENT_SETTING_ALLOW); |
| 1417 EXPECT_EQ( | 1417 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1418 CONTENT_SETTING_ALLOW, | 1418 host_content_settings_map->GetContentSetting( |
| 1419 host_content_settings_map->GetContentSetting( | 1419 https_host, https_host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 1420 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | 1420 std::string())); |
| 1421 // Settings also apply to subdomains. | 1421 // Settings also apply to subdomains. |
| 1422 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1422 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1423 host_content_settings_map->GetContentSetting( | 1423 host_content_settings_map->GetContentSetting( |
| 1424 https_host_narrower, https_host_narrower, | 1424 https_host_narrower, https_host_narrower, |
| 1425 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | 1425 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| 1426 | 1426 |
| 1427 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, | 1427 host_content_settings_map->GetSettingsForOneType( |
| 1428 std::string(), &settings); | 1428 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &settings); |
| 1429 // |host_content_settings_map| contains default setting and a domain scoped | 1429 // |host_content_settings_map| contains default setting and a domain scoped |
| 1430 // setting. | 1430 // setting. |
| 1431 EXPECT_EQ(2U, settings.size()); | 1431 EXPECT_EQ(2U, settings.size()); |
| 1432 EXPECT_TRUE(settings[0].primary_pattern.ToString() == | 1432 EXPECT_TRUE(settings[0].primary_pattern.ToString() == |
| 1433 "https://[*.]example.com:443"); | 1433 "https://[*.]example.com:443"); |
| 1434 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); | 1434 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| 1435 | 1435 |
| 1436 // Set domain scoped settings for cookies. | |
| 1437 host_content_settings_map->SetDefaultContentSetting( | |
| 1438 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | |
| 1439 EXPECT_EQ( | |
| 1440 CONTENT_SETTING_BLOCK, | |
| 1441 host_content_settings_map->GetContentSetting( | |
| 1442 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 1443 host_content_settings_map->SetContentSettingCustomScope( | |
| 1444 ContentSettingsPattern::FromURL(http_host), | |
| 1445 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES, | |
| 1446 std::string(), CONTENT_SETTING_ALLOW); | |
| 1447 EXPECT_EQ( | |
| 1448 CONTENT_SETTING_ALLOW, | |
| 1449 host_content_settings_map->GetContentSetting( | |
| 1450 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 1451 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1452 host_content_settings_map->GetContentSetting( | |
| 1453 http_host_narrower, http_host_narrower, | |
| 1454 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 1455 host_content_settings_map->SetContentSettingCustomScope( | |
| 1456 ContentSettingsPattern::FromURL(https_host), | |
| 1457 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES, | |
| 1458 std::string(), CONTENT_SETTING_ALLOW); | |
| 1459 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1460 host_content_settings_map->GetContentSetting( | |
| 1461 https_host, https_host, CONTENT_SETTINGS_TYPE_COOKIES, | |
| 1462 std::string())); | |
| 1463 // Settings also apply to subdomains. | |
|
msramek
2016/08/05 09:04:03
nit: This comment seems misplaced, since it also a
| |
| 1464 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1465 host_content_settings_map->GetContentSetting( | |
| 1466 https_host_narrower, https_host_narrower, | |
| 1467 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 1468 | |
| 1436 host_content_settings_map->MigrateDomainScopedSettings(false); | 1469 host_content_settings_map->MigrateDomainScopedSettings(false); |
| 1437 | 1470 |
| 1438 // After migration, settings only affect origins. | 1471 // After migration, settings only affect origins. |
| 1439 EXPECT_EQ( | 1472 EXPECT_EQ( |
| 1440 CONTENT_SETTING_ALLOW, | 1473 CONTENT_SETTING_ALLOW, |
| 1441 host_content_settings_map->GetContentSetting( | 1474 host_content_settings_map->GetContentSetting( |
| 1442 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1475 http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1443 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1476 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1444 host_content_settings_map->GetContentSetting( | 1477 host_content_settings_map->GetContentSetting( |
| 1445 http_host_narrower, http_host_narrower, | 1478 http_host_narrower, http_host_narrower, |
| 1446 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1479 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1447 host_content_settings_map->GetSettingsForOneType( | 1480 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, |
| 1448 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); | 1481 std::string(), &settings); |
| 1449 // |host_content_settings_map| contains default setting and a origin scoped | 1482 // |host_content_settings_map| contains default setting and a origin scoped |
| 1450 // setting. | 1483 // setting. |
| 1451 EXPECT_EQ(2U, settings.size()); | 1484 EXPECT_EQ(2U, settings.size()); |
| 1452 EXPECT_TRUE(settings[0].primary_pattern.ToString() == | 1485 EXPECT_TRUE(settings[0].primary_pattern.ToString() == |
| 1453 "http://example.com:80"); | 1486 "http://example.com:80"); |
| 1454 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); | 1487 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| 1455 | 1488 |
| 1456 EXPECT_EQ( | 1489 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1457 CONTENT_SETTING_ALLOW, | 1490 host_content_settings_map->GetContentSetting( |
| 1458 host_content_settings_map->GetContentSetting( | 1491 https_host, https_host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 1459 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | 1492 std::string())); |
| 1460 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1493 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1461 host_content_settings_map->GetContentSetting( | 1494 host_content_settings_map->GetContentSetting( |
| 1462 https_host_narrower, https_host_narrower, | 1495 https_host_narrower, https_host_narrower, |
| 1463 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | 1496 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| 1464 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, | 1497 host_content_settings_map->GetSettingsForOneType( |
| 1465 std::string(), &settings); | 1498 CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &settings); |
| 1466 // |host_content_settings_map| contains default setting and a origin scoped | 1499 // |host_content_settings_map| contains default setting and a origin scoped |
| 1467 // setting. | 1500 // setting. |
| 1468 EXPECT_EQ(2U, settings.size()); | 1501 EXPECT_EQ(2U, settings.size()); |
| 1469 EXPECT_TRUE(settings[0].primary_pattern.ToString() == | 1502 EXPECT_TRUE(settings[0].primary_pattern.ToString() == |
| 1470 "https://example.com:443"); | 1503 "https://example.com:443"); |
| 1471 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); | 1504 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); |
| 1505 | |
| 1506 // Cookie settings didn't get migrated. | |
| 1507 EXPECT_EQ( | |
| 1508 CONTENT_SETTING_ALLOW, | |
| 1509 host_content_settings_map->GetContentSetting( | |
| 1510 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 1511 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1512 host_content_settings_map->GetContentSetting( | |
| 1513 http_host_narrower, http_host_narrower, | |
| 1514 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 1515 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1516 host_content_settings_map->GetContentSetting( | |
| 1517 https_host, https_host, CONTENT_SETTINGS_TYPE_COOKIES, | |
| 1518 std::string())); | |
| 1519 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
| 1520 host_content_settings_map->GetContentSetting( | |
| 1521 https_host_narrower, https_host_narrower, | |
| 1522 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
| 1472 } | 1523 } |
| 1473 | 1524 |
| 1474 // Ensure that migration only happens once upon construction of the HCSM and | 1525 // Ensure that migration only happens once upon construction of the HCSM and |
| 1475 // once after syncing (even when these events occur multiple times). | 1526 // once after syncing (even when these events occur multiple times). |
| 1476 TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) { | 1527 TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) { |
| 1477 TestingProfile profile; | 1528 TestingProfile profile; |
| 1478 PrefService* prefs = profile.GetPrefs(); | 1529 PrefService* prefs = profile.GetPrefs(); |
| 1479 | 1530 |
| 1480 GURL http_host("http://example.com/"); | 1531 GURL http_host("http://example.com/"); |
| 1481 GURL http_host_narrower("http://a.example.com/"); | 1532 GURL http_host_narrower("http://a.example.com/"); |
| 1482 std::string host_pattern_string = | 1533 std::string host_pattern_string = |
| 1483 ContentSettingsPattern::FromURL(http_host).ToString(); | 1534 ContentSettingsPattern::FromURL(http_host).ToString(); |
| 1484 | 1535 |
| 1485 { | 1536 { |
| 1486 DictionaryPrefUpdate update(prefs, | 1537 DictionaryPrefUpdate update(prefs, |
| 1487 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); | 1538 GetPrefName(CONTENT_SETTINGS_TYPE_POPUPS)); |
| 1488 base::DictionaryValue* all_settings_dictionary = update.Get(); | 1539 base::DictionaryValue* all_settings_dictionary = update.Get(); |
| 1489 ASSERT_TRUE(NULL != all_settings_dictionary); | 1540 ASSERT_TRUE(NULL != all_settings_dictionary); |
| 1490 | 1541 |
| 1491 base::DictionaryValue* domain_setting = new base::DictionaryValue; | 1542 base::DictionaryValue* domain_setting = new base::DictionaryValue; |
| 1492 domain_setting->SetInteger("setting", CONTENT_SETTING_ALLOW); | 1543 domain_setting->SetInteger("setting", CONTENT_SETTING_ALLOW); |
| 1493 all_settings_dictionary->SetWithoutPathExpansion(host_pattern_string + ",*", | 1544 all_settings_dictionary->SetWithoutPathExpansion(host_pattern_string + ",*", |
| 1494 domain_setting); | 1545 domain_setting); |
| 1495 } | 1546 } |
| 1496 | 1547 |
| 1497 const base::DictionaryValue* all_settings_dictionary = | 1548 const base::DictionaryValue* all_settings_dictionary = |
| 1498 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); | 1549 prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_POPUPS)); |
| 1499 const base::DictionaryValue* result = NULL; | 1550 const base::DictionaryValue* result = NULL; |
| 1500 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( | 1551 EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion( |
| 1501 "[*.]example.com,*", &result)); | 1552 "[*.]example.com,*", &result)); |
| 1502 | 1553 |
| 1503 // Migration is done on construction of HostContentSettingsMap. | 1554 // Migration is done on construction of HostContentSettingsMap. |
| 1504 HostContentSettingsMap* host_content_settings_map = | 1555 HostContentSettingsMap* host_content_settings_map = |
| 1505 HostContentSettingsMapFactory::GetForProfile(&profile); | 1556 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1506 | 1557 |
| 1507 // Change default setting to BLOCK. | 1558 // Change default setting to BLOCK. |
| 1508 host_content_settings_map->SetDefaultContentSetting( | 1559 host_content_settings_map->SetDefaultContentSetting( |
| 1509 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | 1560 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK); |
| 1510 EXPECT_EQ( | 1561 EXPECT_EQ( |
| 1511 CONTENT_SETTING_ALLOW, | 1562 CONTENT_SETTING_ALLOW, |
| 1512 host_content_settings_map->GetContentSetting( | 1563 host_content_settings_map->GetContentSetting( |
| 1513 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1564 http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1514 // Settings only apply to origins. Migration got executed. | 1565 // Settings only apply to origins. Migration got executed. |
| 1515 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1566 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1516 host_content_settings_map->GetContentSetting( | 1567 host_content_settings_map->GetContentSetting( |
| 1517 http_host_narrower, http_host_narrower, | 1568 http_host_narrower, http_host_narrower, |
| 1518 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1569 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1519 | 1570 |
| 1520 GURL https_host("https://example.com/"); | 1571 GURL https_host("https://example.com/"); |
| 1521 GURL https_host_narrower("https://a.example.com/"); | 1572 GURL https_host_narrower("https://a.example.com/"); |
| 1522 | 1573 |
| 1523 host_content_settings_map->SetContentSettingCustomScope( | 1574 host_content_settings_map->SetContentSettingCustomScope( |
| 1524 ContentSettingsPattern::FromURL(https_host), | 1575 ContentSettingsPattern::FromURL(https_host), |
| 1525 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES, | 1576 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 1526 std::string(), CONTENT_SETTING_ALLOW); | 1577 std::string(), CONTENT_SETTING_ALLOW); |
| 1527 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1578 EXPECT_EQ( |
| 1528 host_content_settings_map->GetContentSetting( | 1579 CONTENT_SETTING_ALLOW, |
| 1529 https_host, https_host, CONTENT_SETTINGS_TYPE_COOKIES, | 1580 host_content_settings_map->GetContentSetting( |
| 1530 std::string())); | 1581 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1531 // Settings apply to subdomains. | 1582 // Settings apply to subdomains. |
| 1532 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1583 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1533 host_content_settings_map->GetContentSetting( | 1584 host_content_settings_map->GetContentSetting( |
| 1534 https_host_narrower, https_host_narrower, | 1585 https_host_narrower, https_host_narrower, |
| 1535 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1586 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1536 | 1587 |
| 1537 // Try to do migration again before sync. | 1588 // Try to do migration again before sync. |
| 1538 host_content_settings_map->MigrateDomainScopedSettings(false); | 1589 host_content_settings_map->MigrateDomainScopedSettings(false); |
| 1539 | 1590 |
| 1540 // Settings still apply to subdomains. Migration didn't get executed. | 1591 // Settings still apply to subdomains. Migration didn't get executed. |
| 1541 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1592 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1542 host_content_settings_map->GetContentSetting( | 1593 host_content_settings_map->GetContentSetting( |
| 1543 https_host_narrower, https_host_narrower, | 1594 https_host_narrower, https_host_narrower, |
| 1544 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1595 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1545 | 1596 |
| 1546 // Do migration after sync. | 1597 // Do migration after sync. |
| 1547 host_content_settings_map->MigrateDomainScopedSettings(true); | 1598 host_content_settings_map->MigrateDomainScopedSettings(true); |
| 1548 | 1599 |
| 1549 // Settings only apply to origins. Migration got executed. | 1600 // Settings only apply to origins. Migration got executed. |
| 1550 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1601 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| 1551 host_content_settings_map->GetContentSetting( | 1602 host_content_settings_map->GetContentSetting( |
| 1552 https_host_narrower, https_host_narrower, | 1603 https_host_narrower, https_host_narrower, |
| 1553 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1604 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1554 | 1605 |
| 1555 GURL http1_host("http://google.com/"); | 1606 GURL http1_host("http://google.com/"); |
| 1556 GURL http1_host_narrower("http://a.google.com/"); | 1607 GURL http1_host_narrower("http://a.google.com/"); |
| 1557 | 1608 |
| 1558 host_content_settings_map->SetContentSettingCustomScope( | 1609 host_content_settings_map->SetContentSettingCustomScope( |
| 1559 ContentSettingsPattern::FromURL(http1_host), | 1610 ContentSettingsPattern::FromURL(http1_host), |
| 1560 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES, | 1611 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 1561 std::string(), CONTENT_SETTING_ALLOW); | 1612 std::string(), CONTENT_SETTING_ALLOW); |
| 1562 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1613 EXPECT_EQ( |
| 1563 host_content_settings_map->GetContentSetting( | 1614 CONTENT_SETTING_ALLOW, |
| 1564 http1_host, http1_host, CONTENT_SETTINGS_TYPE_COOKIES, | 1615 host_content_settings_map->GetContentSetting( |
| 1565 std::string())); | 1616 http1_host, http1_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1566 // Settings apply to subdomains. | 1617 // Settings apply to subdomains. |
| 1567 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1618 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1568 host_content_settings_map->GetContentSetting( | 1619 host_content_settings_map->GetContentSetting( |
| 1569 http1_host_narrower, http1_host_narrower, | 1620 http1_host_narrower, http1_host_narrower, |
| 1570 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1621 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1571 | 1622 |
| 1572 // Try to do migration again after sync. | 1623 // Try to do migration again after sync. |
| 1573 host_content_settings_map->MigrateDomainScopedSettings(true); | 1624 host_content_settings_map->MigrateDomainScopedSettings(true); |
| 1574 | 1625 |
| 1575 // Settings still apply to subdomains. Migration didn't get executed. | 1626 // Settings still apply to subdomains. Migration didn't get executed. |
| 1576 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 1627 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| 1577 host_content_settings_map->GetContentSetting( | 1628 host_content_settings_map->GetContentSetting( |
| 1578 http1_host_narrower, http1_host_narrower, | 1629 http1_host_narrower, http1_host_narrower, |
| 1579 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | 1630 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| 1580 } | 1631 } |
| 1581 | 1632 |
| 1582 TEST_F(HostContentSettingsMapTest, InvalidPattern) { | 1633 TEST_F(HostContentSettingsMapTest, InvalidPattern) { |
| 1583 // This is a regression test for crbug.com/618529, which fixed a memory leak | 1634 // This is a regression test for crbug.com/618529, which fixed a memory leak |
| 1584 // when a website setting was set under a URL that mapped to an invalid | 1635 // when a website setting was set under a URL that mapped to an invalid |
| 1585 // pattern. | 1636 // pattern. |
| 1586 TestingProfile profile; | 1637 TestingProfile profile; |
| 1587 HostContentSettingsMap* host_content_settings_map = | 1638 HostContentSettingsMap* host_content_settings_map = |
| 1588 HostContentSettingsMapFactory::GetForProfile(&profile); | 1639 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1589 GURL unsupported_url = GURL("view-source:http://www.google.com"); | 1640 GURL unsupported_url = GURL("view-source:http://www.google.com"); |
| 1590 base::DictionaryValue test_value; | 1641 base::DictionaryValue test_value; |
| 1591 test_value.SetString("test", "value"); | 1642 test_value.SetString("test", "value"); |
| 1592 host_content_settings_map->SetWebsiteSettingDefaultScope( | 1643 host_content_settings_map->SetWebsiteSettingDefaultScope( |
| 1593 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, | 1644 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, |
| 1594 std::string(), base::WrapUnique(test_value.DeepCopy())); | 1645 std::string(), base::WrapUnique(test_value.DeepCopy())); |
| 1595 EXPECT_EQ(nullptr, | 1646 EXPECT_EQ(nullptr, |
| 1596 host_content_settings_map->GetWebsiteSetting( | 1647 host_content_settings_map->GetWebsiteSetting( |
| 1597 unsupported_url, unsupported_url, | 1648 unsupported_url, unsupported_url, |
| 1598 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); | 1649 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); |
| 1599 } | 1650 } |
| OLD | NEW |