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

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

Issue 2158743002: Register a pref to control migration status (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@change_scoping_type
Patch Set: address review comments 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 1408 matching lines...) Expand 10 before | Expand all | Expand 10 after
1419 1419
1420 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, 1420 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS,
1421 std::string(), &settings); 1421 std::string(), &settings);
1422 // |host_content_settings_map| contains default setting and a domain scoped 1422 // |host_content_settings_map| contains default setting and a domain scoped
1423 // setting. 1423 // setting.
1424 EXPECT_EQ(2U, settings.size()); 1424 EXPECT_EQ(2U, settings.size());
1425 EXPECT_TRUE(settings[0].primary_pattern.ToString() == 1425 EXPECT_TRUE(settings[0].primary_pattern.ToString() ==
1426 "https://[*.]example.com:443"); 1426 "https://[*.]example.com:443");
1427 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); 1427 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*");
1428 1428
1429 host_content_settings_map->MigrateDomainScopedSettings(); 1429 host_content_settings_map->MigrateDomainScopedSettings(false);
1430 1430
1431 // After migration, settings only affect origins. 1431 // After migration, settings only affect origins.
1432 EXPECT_EQ( 1432 EXPECT_EQ(
1433 CONTENT_SETTING_ALLOW, 1433 CONTENT_SETTING_ALLOW,
1434 host_content_settings_map->GetContentSetting( 1434 host_content_settings_map->GetContentSetting(
1435 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 1435 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1436 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1436 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1437 host_content_settings_map->GetContentSetting( 1437 host_content_settings_map->GetContentSetting(
1438 http_host_narrower, http_host_narrower, 1438 http_host_narrower, http_host_narrower,
1439 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); 1439 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
(...skipping 17 matching lines...) Expand all
1457 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, 1457 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS,
1458 std::string(), &settings); 1458 std::string(), &settings);
1459 // |host_content_settings_map| contains default setting and a origin scoped 1459 // |host_content_settings_map| contains default setting and a origin scoped
1460 // setting. 1460 // setting.
1461 EXPECT_EQ(2U, settings.size()); 1461 EXPECT_EQ(2U, settings.size());
1462 EXPECT_TRUE(settings[0].primary_pattern.ToString() == 1462 EXPECT_TRUE(settings[0].primary_pattern.ToString() ==
1463 "https://example.com:443"); 1463 "https://example.com:443");
1464 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*"); 1464 EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*");
1465 } 1465 }
1466 1466
1467 TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) {
raymes 2016/07/25 03:56:38 nit: add a comment explaining what this test does.
lshang 2016/07/25 04:51:09 Done.
1468 TestingProfile profile;
1469
1470 HostContentSettingsMap* host_content_settings_map =
1471 HostContentSettingsMapFactory::GetForProfile(&profile);
1472
1473 GURL http_host("http://example.com/");
1474 GURL http_host_narrower("http://a.example.com/");
1475
1476 // Change default setting to BLOCK.
1477 host_content_settings_map->SetDefaultContentSetting(
1478 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1479 EXPECT_EQ(
1480 CONTENT_SETTING_BLOCK,
1481 host_content_settings_map->GetContentSetting(
1482 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
raymes 2016/07/25 03:56:38 nit: I don't think we need this.
lshang 2016/07/25 04:51:09 Done.
1483 // Set domain scoped settings.
1484 host_content_settings_map->SetContentSettingCustomScope(
1485 ContentSettingsPattern::FromURL(http_host),
1486 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
1487 std::string(), CONTENT_SETTING_ALLOW);
1488 EXPECT_EQ(
1489 CONTENT_SETTING_ALLOW,
1490 host_content_settings_map->GetContentSetting(
1491 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1492 // Settings apply to subdomains.
1493 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1494 host_content_settings_map->GetContentSetting(
1495 http_host_narrower, http_host_narrower,
1496 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1497
1498 // Do migration before sync.
1499 host_content_settings_map->MigrateDomainScopedSettings(false);
1500
1501 // Settings only apply to origins. Migration got executed.
1502 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1503 host_content_settings_map->GetContentSetting(
1504 http_host_narrower, http_host_narrower,
1505 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1506
1507 GURL https_host("https://example.com/");
1508 GURL https_host_narrower("https://a.example.com/");
1509
1510 host_content_settings_map->SetContentSettingCustomScope(
1511 ContentSettingsPattern::FromURL(https_host),
1512 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
1513 std::string(), CONTENT_SETTING_ALLOW);
1514 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1515 host_content_settings_map->GetContentSetting(
1516 https_host, https_host, CONTENT_SETTINGS_TYPE_COOKIES,
1517 std::string()));
1518 // Settings apply to subdomains.
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()));
1523
1524 // Try to do migration again before sync.
1525 host_content_settings_map->MigrateDomainScopedSettings(false);
1526
1527 // Settings still apply to subdomains. Migration didn't get executed.
1528 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1529 host_content_settings_map->GetContentSetting(
1530 https_host_narrower, https_host_narrower,
1531 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1532
1533 // Do migration after sync.
1534 host_content_settings_map->MigrateDomainScopedSettings(true);
1535
1536 // Settings only apply to origins. Migration got executed.
1537 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1538 host_content_settings_map->GetContentSetting(
1539 https_host_narrower, https_host_narrower,
1540 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1541
1542 GURL http1_host("http://google.com/");
1543 GURL http1_host_narrower("http://a.google.com/");
1544
1545 host_content_settings_map->SetContentSettingCustomScope(
1546 ContentSettingsPattern::FromURL(http1_host),
1547 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
1548 std::string(), CONTENT_SETTING_ALLOW);
1549 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1550 host_content_settings_map->GetContentSetting(
1551 http1_host, http1_host, CONTENT_SETTINGS_TYPE_COOKIES,
1552 std::string()));
1553 // Settings apply to subdomains.
1554 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1555 host_content_settings_map->GetContentSetting(
1556 http1_host_narrower, http1_host_narrower,
1557 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1558
1559 // Try to do migration again after sync.
1560 host_content_settings_map->MigrateDomainScopedSettings(true);
1561
1562 // Settings still apply to subdomains. Migration didn't get executed.
1563 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1564 host_content_settings_map->GetContentSetting(
1565 http1_host_narrower, http1_host_narrower,
1566 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1567 }
1568
1467 TEST_F(HostContentSettingsMapTest, InvalidPattern) { 1569 TEST_F(HostContentSettingsMapTest, InvalidPattern) {
1468 // This is a regression test for crbug.com/618529, which fixed a memory leak 1570 // This is a regression test for crbug.com/618529, which fixed a memory leak
1469 // when a website setting was set under a URL that mapped to an invalid 1571 // when a website setting was set under a URL that mapped to an invalid
1470 // pattern. 1572 // pattern.
1471 TestingProfile profile; 1573 TestingProfile profile;
1472 HostContentSettingsMap* host_content_settings_map = 1574 HostContentSettingsMap* host_content_settings_map =
1473 HostContentSettingsMapFactory::GetForProfile(&profile); 1575 HostContentSettingsMapFactory::GetForProfile(&profile);
1474 GURL unsupported_url = GURL("view-source:http://www.google.com"); 1576 GURL unsupported_url = GURL("view-source:http://www.google.com");
1475 base::DictionaryValue test_value; 1577 base::DictionaryValue test_value;
1476 test_value.SetString("test", "value"); 1578 test_value.SetString("test", "value");
1477 host_content_settings_map->SetWebsiteSettingDefaultScope( 1579 host_content_settings_map->SetWebsiteSettingDefaultScope(
1478 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, 1580 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER,
1479 std::string(), base::WrapUnique(test_value.DeepCopy())); 1581 std::string(), base::WrapUnique(test_value.DeepCopy()));
1480 EXPECT_EQ(nullptr, 1582 EXPECT_EQ(nullptr,
1481 host_content_settings_map->GetWebsiteSetting( 1583 host_content_settings_map->GetWebsiteSetting(
1482 unsupported_url, unsupported_url, 1584 unsupported_url, unsupported_url,
1483 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); 1585 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr));
1484 } 1586 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698