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

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, 4 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
« no previous file with comments | « no previous file | components/content_settings/core/browser/host_content_settings_map.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // Ensure that migration only happens once upon construction of the HCSM and
1468 // once after syncing (even when these events occur multiple times).
1469 TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) {
1470 TestingProfile profile;
1471
1472 HostContentSettingsMap* host_content_settings_map =
1473 HostContentSettingsMapFactory::GetForProfile(&profile);
1474
1475 GURL http_host("http://example.com/");
1476 GURL http_host_narrower("http://a.example.com/");
1477
1478 // Change default setting to BLOCK.
1479 host_content_settings_map->SetDefaultContentSetting(
1480 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
1481 // Set domain scoped settings.
1482 host_content_settings_map->SetContentSettingCustomScope(
1483 ContentSettingsPattern::FromURL(http_host),
1484 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
1485 std::string(), CONTENT_SETTING_ALLOW);
1486 EXPECT_EQ(
1487 CONTENT_SETTING_ALLOW,
1488 host_content_settings_map->GetContentSetting(
1489 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1490 // Settings apply to subdomains.
1491 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1492 host_content_settings_map->GetContentSetting(
1493 http_host_narrower, http_host_narrower,
1494 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1495
1496 // Do migration before sync.
1497 host_content_settings_map->MigrateDomainScopedSettings(false);
1498
1499 // Settings only apply to origins. Migration got executed.
1500 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1501 host_content_settings_map->GetContentSetting(
1502 http_host_narrower, http_host_narrower,
1503 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1504
1505 GURL https_host("https://example.com/");
1506 GURL https_host_narrower("https://a.example.com/");
1507
1508 host_content_settings_map->SetContentSettingCustomScope(
1509 ContentSettingsPattern::FromURL(https_host),
1510 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
1511 std::string(), CONTENT_SETTING_ALLOW);
1512 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1513 host_content_settings_map->GetContentSetting(
1514 https_host, https_host, CONTENT_SETTINGS_TYPE_COOKIES,
1515 std::string()));
1516 // Settings apply to subdomains.
1517 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1518 host_content_settings_map->GetContentSetting(
1519 https_host_narrower, https_host_narrower,
1520 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1521
1522 // Try to do migration again before sync.
1523 host_content_settings_map->MigrateDomainScopedSettings(false);
1524
1525 // Settings still apply to subdomains. Migration didn't get executed.
1526 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1527 host_content_settings_map->GetContentSetting(
1528 https_host_narrower, https_host_narrower,
1529 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1530
1531 // Do migration after sync.
1532 host_content_settings_map->MigrateDomainScopedSettings(true);
1533
1534 // Settings only apply to origins. Migration got executed.
1535 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1536 host_content_settings_map->GetContentSetting(
1537 https_host_narrower, https_host_narrower,
1538 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1539
1540 GURL http1_host("http://google.com/");
1541 GURL http1_host_narrower("http://a.google.com/");
1542
1543 host_content_settings_map->SetContentSettingCustomScope(
1544 ContentSettingsPattern::FromURL(http1_host),
1545 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
1546 std::string(), CONTENT_SETTING_ALLOW);
1547 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1548 host_content_settings_map->GetContentSetting(
1549 http1_host, http1_host, CONTENT_SETTINGS_TYPE_COOKIES,
1550 std::string()));
1551 // Settings apply to subdomains.
1552 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1553 host_content_settings_map->GetContentSetting(
1554 http1_host_narrower, http1_host_narrower,
1555 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1556
1557 // Try to do migration again after sync.
1558 host_content_settings_map->MigrateDomainScopedSettings(true);
1559
1560 // Settings still apply to subdomains. Migration didn't get executed.
1561 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1562 host_content_settings_map->GetContentSetting(
1563 http1_host_narrower, http1_host_narrower,
1564 CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
1565 }
1566
1467 TEST_F(HostContentSettingsMapTest, InvalidPattern) { 1567 TEST_F(HostContentSettingsMapTest, InvalidPattern) {
1468 // This is a regression test for crbug.com/618529, which fixed a memory leak 1568 // 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 1569 // when a website setting was set under a URL that mapped to an invalid
1470 // pattern. 1570 // pattern.
1471 TestingProfile profile; 1571 TestingProfile profile;
1472 HostContentSettingsMap* host_content_settings_map = 1572 HostContentSettingsMap* host_content_settings_map =
1473 HostContentSettingsMapFactory::GetForProfile(&profile); 1573 HostContentSettingsMapFactory::GetForProfile(&profile);
1474 GURL unsupported_url = GURL("view-source:http://www.google.com"); 1574 GURL unsupported_url = GURL("view-source:http://www.google.com");
1475 base::DictionaryValue test_value; 1575 base::DictionaryValue test_value;
1476 test_value.SetString("test", "value"); 1576 test_value.SetString("test", "value");
1477 host_content_settings_map->SetWebsiteSettingDefaultScope( 1577 host_content_settings_map->SetWebsiteSettingDefaultScope(
1478 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, 1578 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER,
1479 std::string(), base::WrapUnique(test_value.DeepCopy())); 1579 std::string(), base::WrapUnique(test_value.DeepCopy()));
1480 EXPECT_EQ(nullptr, 1580 EXPECT_EQ(nullptr,
1481 host_content_settings_map->GetWebsiteSetting( 1581 host_content_settings_map->GetWebsiteSetting(
1482 unsupported_url, unsupported_url, 1582 unsupported_url, unsupported_url,
1483 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); 1583 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr));
1484 } 1584 }
OLDNEW
« no previous file with comments | « no previous file | components/content_settings/core/browser/host_content_settings_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698