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 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1271 | 1271 |
1272 // After migrating old settings, changes to the setting works. | 1272 // After migrating old settings, changes to the setting works. |
1273 host_content_settings_map->SetContentSettingDefaultScope( | 1273 host_content_settings_map->SetContentSettingDefaultScope( |
1274 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), | 1274 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(), |
1275 CONTENT_SETTING_BLOCK); | 1275 CONTENT_SETTING_BLOCK); |
1276 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 1276 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
1277 host_content_settings_map->GetContentSetting( | 1277 host_content_settings_map->GetContentSetting( |
1278 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); | 1278 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
1279 } | 1279 } |
1280 | 1280 |
1281 TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) { | |
1282 TestingProfile profile; | |
1283 HostContentSettingsMap* host_content_settings_map = | |
1284 HostContentSettingsMapFactory::GetForProfile(&profile); | |
1285 | |
1286 // Set old formatted http settings. | |
1287 GURL http_host("http://example.com/"); | |
1288 GURL http_host_narrower("http://a.example.com/"); | |
1289 | |
1290 // Change default setting to BLOCK. | |
1291 host_content_settings_map->SetDefaultContentSetting( | |
1292 CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK); | |
1293 EXPECT_EQ( | |
1294 CONTENT_SETTING_BLOCK, | |
1295 host_content_settings_map->GetContentSetting( | |
1296 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
1297 // Patterns generated for cookies used to be domain scoped. | |
1298 host_content_settings_map->SetContentSettingCustomScope( | |
1299 ContentSettingsPattern::FromURL(http_host), | |
1300 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES, | |
1301 std::string(), CONTENT_SETTING_ALLOW); | |
1302 EXPECT_EQ( | |
1303 CONTENT_SETTING_ALLOW, | |
1304 host_content_settings_map->GetContentSetting( | |
1305 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
1306 // Settings also apply to subdomains. | |
1307 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1308 host_content_settings_map->GetContentSetting( | |
1309 http_host_narrower, http_host_narrower, | |
1310 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
1311 | |
1312 ContentSettingsForOneType settings; | |
1313 host_content_settings_map->GetSettingsForOneType( | |
1314 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); | |
1315 // |host_settings| contains default setting and a custom setting. | |
raymes
2016/06/27 07:23:29
host_content_settings_map? (here and below)
lshang
2016/06/28 07:14:41
Done.
| |
1316 EXPECT_EQ(2U, settings.size()); | |
1317 for (const ContentSettingPatternSource& setting_entry : settings) { | |
1318 if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) | |
1319 continue; | |
1320 EXPECT_EQ("[*.]example.com", setting_entry.primary_pattern.ToString()); | |
raymes
2016/06/27 07:23:29
This won't exactly check that things are what we e
lshang
2016/06/28 07:14:41
There should be a default setting (*, *) and a cus
raymes
2016/06/30 01:11:27
Note: as discussed we should still change this :)
lshang
2016/06/30 05:10:35
Done.
| |
1321 } | |
1322 | |
1323 // Set old formatted https settings. | |
1324 GURL https_host("https://example.com/"); | |
1325 GURL https_host_narrower("https://a.example.com/"); | |
1326 | |
1327 // Change default setting to BLOCK. | |
1328 host_content_settings_map->SetDefaultContentSetting( | |
1329 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK); | |
1330 EXPECT_EQ( | |
1331 CONTENT_SETTING_BLOCK, | |
1332 host_content_settings_map->GetContentSetting( | |
1333 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | |
1334 // Patterns generated for popups used to be domain scoped. | |
1335 host_content_settings_map->SetContentSettingCustomScope( | |
1336 ContentSettingsPattern::FromURL(https_host), | |
1337 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, | |
1338 std::string(), CONTENT_SETTING_ALLOW); | |
1339 EXPECT_EQ( | |
1340 CONTENT_SETTING_ALLOW, | |
1341 host_content_settings_map->GetContentSetting( | |
1342 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | |
1343 // Settings also apply to subdomains. | |
1344 EXPECT_EQ(CONTENT_SETTING_ALLOW, | |
1345 host_content_settings_map->GetContentSetting( | |
1346 https_host_narrower, https_host_narrower, | |
1347 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | |
1348 | |
1349 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, | |
1350 std::string(), &settings); | |
1351 // |host_settings| contains default setting and a custom setting. | |
1352 EXPECT_EQ(2U, settings.size()); | |
1353 for (const ContentSettingPatternSource& setting_entry : settings) { | |
1354 if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) | |
1355 continue; | |
1356 EXPECT_EQ("https://[*.]example.com:443", | |
1357 setting_entry.primary_pattern.ToString()); | |
1358 } | |
1359 | |
1360 host_content_settings_map->MigrateDomainScopedSettings(); | |
1361 | |
1362 // After migration, settings only affect origins. | |
1363 EXPECT_EQ( | |
1364 CONTENT_SETTING_ALLOW, | |
1365 host_content_settings_map->GetContentSetting( | |
1366 http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
1367 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1368 host_content_settings_map->GetContentSetting( | |
1369 http_host_narrower, http_host_narrower, | |
1370 CONTENT_SETTINGS_TYPE_COOKIES, std::string())); | |
1371 host_content_settings_map->GetSettingsForOneType( | |
1372 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &settings); | |
1373 // |host_settings| contains default setting and a custom setting. | |
1374 EXPECT_EQ(2U, settings.size()); | |
1375 for (const ContentSettingPatternSource& setting_entry : settings) { | |
1376 if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) | |
1377 continue; | |
1378 EXPECT_EQ("http://example.com:80", | |
1379 setting_entry.primary_pattern.ToString()); | |
1380 } | |
1381 | |
1382 EXPECT_EQ( | |
1383 CONTENT_SETTING_ALLOW, | |
1384 host_content_settings_map->GetContentSetting( | |
1385 https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | |
1386 EXPECT_EQ(CONTENT_SETTING_BLOCK, | |
1387 host_content_settings_map->GetContentSetting( | |
1388 https_host_narrower, https_host_narrower, | |
1389 CONTENT_SETTINGS_TYPE_POPUPS, std::string())); | |
1390 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, | |
1391 std::string(), &settings); | |
1392 // |host_settings| contains default setting and a custom setting. | |
1393 EXPECT_EQ(2U, settings.size()); | |
1394 for (const ContentSettingPatternSource& setting_entry : settings) { | |
1395 if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard()) | |
1396 continue; | |
1397 EXPECT_EQ("https://example.com:443", | |
1398 setting_entry.primary_pattern.ToString()); | |
1399 } | |
1400 } | |
1401 | |
1281 TEST_F(HostContentSettingsMapTest, InvalidPattern) { | 1402 TEST_F(HostContentSettingsMapTest, InvalidPattern) { |
1282 // This is a regression test for crbug.com/618529, which fixed a memory leak | 1403 // This is a regression test for crbug.com/618529, which fixed a memory leak |
1283 // when a website setting was set under a URL that mapped to an invalid | 1404 // when a website setting was set under a URL that mapped to an invalid |
1284 // pattern. | 1405 // pattern. |
1285 TestingProfile profile; | 1406 TestingProfile profile; |
1286 HostContentSettingsMap* host_content_settings_map = | 1407 HostContentSettingsMap* host_content_settings_map = |
1287 HostContentSettingsMapFactory::GetForProfile(&profile); | 1408 HostContentSettingsMapFactory::GetForProfile(&profile); |
1288 GURL unsupported_url = GURL("view-source:http://www.google.com"); | 1409 GURL unsupported_url = GURL("view-source:http://www.google.com"); |
1289 base::DictionaryValue test_value; | 1410 base::DictionaryValue test_value; |
1290 test_value.SetString("test", "value"); | 1411 test_value.SetString("test", "value"); |
1291 host_content_settings_map->SetWebsiteSettingDefaultScope( | 1412 host_content_settings_map->SetWebsiteSettingDefaultScope( |
1292 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, | 1413 unsupported_url, unsupported_url, CONTENT_SETTINGS_TYPE_APP_BANNER, |
1293 std::string(), base::WrapUnique(test_value.DeepCopy())); | 1414 std::string(), base::WrapUnique(test_value.DeepCopy())); |
1294 EXPECT_EQ(nullptr, | 1415 EXPECT_EQ(nullptr, |
1295 host_content_settings_map->GetWebsiteSetting( | 1416 host_content_settings_map->GetWebsiteSetting( |
1296 unsupported_url, unsupported_url, | 1417 unsupported_url, unsupported_url, |
1297 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); | 1418 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), nullptr)); |
1298 } | 1419 } |
OLD | NEW |