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

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: add some comments to test 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) {
1468 TestingProfile profile;
1469 PrefService* prefs = profile.GetPrefs();
1470
1471 HostContentSettingsMap* host_content_settings_map =
1472 HostContentSettingsMapFactory::GetForProfile(&profile);
1473
1474 // Initial state is NOT_MIGRATED.
1475 EXPECT_EQ(0, prefs->GetInteger(prefs::kDomainToOriginMigrationStatus));
1476
1477 // Do migration on HostContentSettingsMap construction will change the state
1478 // to MIGRATED_BEFORE_SYNC.
1479 host_content_settings_map->MigrateDomainScopedSettings(false);
1480 EXPECT_EQ(1, prefs->GetInteger(prefs::kDomainToOriginMigrationStatus));
raymes 2016/07/21 00:58:54 Rather than checking the value of the pref (which
lshang 2016/07/22 01:33:06 Done.
1481
1482 // Another call on HostContentSettingsMap construction to do migration will
1483 // not change the state(i.e. migration code don't acturally get executed).
1484 host_content_settings_map->MigrateDomainScopedSettings(false);
1485 EXPECT_EQ(1, prefs->GetInteger(prefs::kDomainToOriginMigrationStatus));
1486
1487 // Do migration after sync will change the state to MIGRATED_AFTER_SYNC.
1488 host_content_settings_map->MigrateDomainScopedSettings(true);
1489 EXPECT_EQ(2, prefs->GetInteger(prefs::kDomainToOriginMigrationStatus));
1490
1491 // Another call after sync to do migration will not change the state
1492 // (i.e. migration has finished, won't get executed anymore).
1493 host_content_settings_map->MigrateDomainScopedSettings(true);
1494 EXPECT_EQ(2, prefs->GetInteger(prefs::kDomainToOriginMigrationStatus));
1495 }
1496
1467 TEST_F(HostContentSettingsMapTest, InvalidPattern) { 1497 TEST_F(HostContentSettingsMapTest, InvalidPattern) {
1468 // This is a regression test for crbug.com/618529, which fixed a memory leak 1498 // 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 1499 // when a website setting was set under a URL that mapped to an invalid
1470 // pattern. 1500 // pattern.
1471 TestingProfile profile; 1501 TestingProfile profile;
1472 HostContentSettingsMap* host_content_settings_map = 1502 HostContentSettingsMap* host_content_settings_map =
1473 HostContentSettingsMapFactory::GetForProfile(&profile); 1503 HostContentSettingsMapFactory::GetForProfile(&profile);
1474 GURL unsupported_url = GURL("view-source:http://www.google.com"); 1504 GURL unsupported_url = GURL("view-source:http://www.google.com");
1475 base::DictionaryValue test_value; 1505 base::DictionaryValue test_value;
1476 test_value.SetString("test", "value"); 1506 test_value.SetString("test", "value");
1477 host_content_settings_map->SetWebsiteSettingDefaultScope( 1507 host_content_settings_map->SetWebsiteSettingDefaultScope(
1478 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, 1508 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER,
1479 std::string(), base::WrapUnique(test_value.DeepCopy())); 1509 std::string(), base::WrapUnique(test_value.DeepCopy()));
1480 EXPECT_EQ(nullptr, 1510 EXPECT_EQ(nullptr,
1481 host_content_settings_map->GetWebsiteSetting( 1511 host_content_settings_map->GetWebsiteSetting(
1482 unsupported_url, unsupported_url, 1512 unsupported_url, unsupported_url,
1483 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); 1513 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr));
1484 } 1514 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698