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

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

Issue 2536993002: Remove support for the keygen tag (Closed)
Patch Set: Rebased Created 4 years 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 157 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
158 host_content_settings_map->GetDefaultContentSetting( 158 host_content_settings_map->GetDefaultContentSetting(
159 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 159 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
160 #endif 160 #endif
161 161
162 host_content_settings_map->SetDefaultContentSetting( 162 host_content_settings_map->SetDefaultContentSetting(
163 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW); 163 CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_ALLOW);
164 EXPECT_EQ(CONTENT_SETTING_ALLOW, 164 EXPECT_EQ(CONTENT_SETTING_ALLOW,
165 host_content_settings_map->GetDefaultContentSetting( 165 host_content_settings_map->GetDefaultContentSetting(
166 CONTENT_SETTINGS_TYPE_POPUPS, NULL)); 166 CONTENT_SETTINGS_TYPE_POPUPS, NULL));
167 EXPECT_EQ(CONTENT_SETTING_BLOCK,
168 host_content_settings_map->GetDefaultContentSetting(
169 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
170 } 167 }
171 168
172 TEST_F(HostContentSettingsMapTest, IndividualSettings) { 169 TEST_F(HostContentSettingsMapTest, IndividualSettings) {
173 TestingProfile profile; 170 TestingProfile profile;
174 HostContentSettingsMap* host_content_settings_map = 171 HostContentSettingsMap* host_content_settings_map =
175 HostContentSettingsMapFactory::GetForProfile(&profile); 172 HostContentSettingsMapFactory::GetForProfile(&profile);
176 173
177 // Check returning individual settings. 174 // Check returning individual settings.
178 GURL host("http://example.com/"); 175 GURL host("http://example.com/");
179 EXPECT_EQ(CONTENT_SETTING_ALLOW, 176 EXPECT_EQ(CONTENT_SETTING_ALLOW,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); 214 host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
218 EXPECT_EQ(CONTENT_SETTING_ASK, 215 EXPECT_EQ(CONTENT_SETTING_ASK,
219 host_content_settings_map->GetContentSetting( 216 host_content_settings_map->GetContentSetting(
220 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); 217 host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string()));
221 EXPECT_EQ( 218 EXPECT_EQ(
222 CONTENT_SETTING_ASK, 219 CONTENT_SETTING_ASK,
223 host_content_settings_map->GetContentSetting( 220 host_content_settings_map->GetContentSetting(
224 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); 221 host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string()));
225 222
226 host_content_settings_map->SetContentSettingDefaultScope( 223 host_content_settings_map->SetContentSettingDefaultScope(
227 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
228 CONTENT_SETTING_ALLOW);
229 EXPECT_EQ(CONTENT_SETTING_ALLOW,
230 host_content_settings_map->GetContentSetting(
231 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
232
233 host_content_settings_map->SetContentSettingDefaultScope(
234 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string(), 224 host, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string(),
235 CONTENT_SETTING_BLOCK); 225 CONTENT_SETTING_BLOCK);
236 EXPECT_EQ(CONTENT_SETTING_BLOCK, 226 EXPECT_EQ(CONTENT_SETTING_BLOCK,
237 host_content_settings_map->GetContentSetting( 227 host_content_settings_map->GetContentSetting(
238 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); 228 host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string()));
239 229
240 // Check returning all hosts for a setting. 230 // Check returning all hosts for a setting.
241 GURL host2("http://example.org/"); 231 GURL host2("http://example.org/");
242 host_content_settings_map->SetContentSettingDefaultScope( 232 host_content_settings_map->SetContentSettingDefaultScope(
243 host2, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), 233 host2, GURL(), CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(),
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 host_content_settings_map->SetContentSettingDefaultScope( 559 host_content_settings_map->SetContentSettingDefaultScope(
570 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), 560 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(),
571 CONTENT_SETTING_ALLOW); 561 CONTENT_SETTING_ALLOW);
572 EXPECT_EQ( 562 EXPECT_EQ(
573 CONTENT_SETTING_ALLOW, 563 CONTENT_SETTING_ALLOW,
574 host_content_settings_map->GetContentSetting(host_ending_with_dot, 564 host_content_settings_map->GetContentSetting(host_ending_with_dot,
575 host_ending_with_dot, 565 host_ending_with_dot,
576 CONTENT_SETTINGS_TYPE_POPUPS, 566 CONTENT_SETTINGS_TYPE_POPUPS,
577 std::string())); 567 std::string()));
578 568
579 EXPECT_EQ(CONTENT_SETTING_BLOCK,
580 host_content_settings_map->GetContentSetting(
581 host_ending_with_dot, host_ending_with_dot,
582 CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
583 host_content_settings_map->SetContentSettingDefaultScope(
584 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
585 CONTENT_SETTING_ALLOW);
586 EXPECT_EQ(CONTENT_SETTING_ALLOW,
587 host_content_settings_map->GetContentSetting(
588 host_ending_with_dot, host_ending_with_dot,
589 CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
590 host_content_settings_map->SetContentSettingDefaultScope(
591 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
592 CONTENT_SETTING_DEFAULT);
593 EXPECT_EQ(CONTENT_SETTING_BLOCK,
594 host_content_settings_map->GetContentSetting(
595 host_ending_with_dot, host_ending_with_dot,
596 CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
597
598 EXPECT_EQ(CONTENT_SETTING_ALLOW, 569 EXPECT_EQ(CONTENT_SETTING_ALLOW,
599 host_content_settings_map->GetContentSetting( 570 host_content_settings_map->GetContentSetting(
600 host_ending_with_dot, host_ending_with_dot, 571 host_ending_with_dot, host_ending_with_dot,
601 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); 572 CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string()));
602 host_content_settings_map->SetContentSettingDefaultScope( 573 host_content_settings_map->SetContentSettingDefaultScope(
603 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY, 574 host_ending_with_dot, GURL(), CONTENT_SETTINGS_TYPE_AUTOPLAY,
604 std::string(), CONTENT_SETTING_BLOCK); 575 std::string(), CONTENT_SETTING_BLOCK);
605 EXPECT_EQ(CONTENT_SETTING_BLOCK, 576 EXPECT_EQ(CONTENT_SETTING_BLOCK,
606 host_content_settings_map->GetContentSetting( 577 host_content_settings_map->GetContentSetting(
607 host_ending_with_dot, host_ending_with_dot, 578 host_ending_with_dot, host_ending_with_dot,
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 EXPECT_EQ(CONTENT_SETTING_BLOCK, 1062 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1092 host_content_settings_map->GetDefaultContentSetting( 1063 host_content_settings_map->GetDefaultContentSetting(
1093 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 1064 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
1094 1065
1095 // Remove the preference to manage the default-content-setting for Plugins. 1066 // Remove the preference to manage the default-content-setting for Plugins.
1096 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting); 1067 prefs->RemoveManagedPref(prefs::kManagedDefaultPluginsSetting);
1097 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT, 1068 EXPECT_EQ(CONTENT_SETTING_DETECT_IMPORTANT_CONTENT,
1098 host_content_settings_map->GetDefaultContentSetting( 1069 host_content_settings_map->GetDefaultContentSetting(
1099 CONTENT_SETTINGS_TYPE_PLUGINS, NULL)); 1070 CONTENT_SETTINGS_TYPE_PLUGINS, NULL));
1100 #endif 1071 #endif
1101
1102 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1103 host_content_settings_map->GetDefaultContentSetting(
1104 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
1105
1106 // Set managed-default content setting through the coresponding preferences.
1107 prefs->SetManagedPref(prefs::kManagedDefaultKeygenSetting,
1108 new base::FundamentalValue(CONTENT_SETTING_ALLOW));
1109 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1110 host_content_settings_map->GetDefaultContentSetting(
1111 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
1112
1113 // Remove managed-default content settings preferences.
1114 prefs->RemoveManagedPref(prefs::kManagedDefaultKeygenSetting);
1115 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1116 host_content_settings_map->GetDefaultContentSetting(
1117 CONTENT_SETTINGS_TYPE_KEYGEN, NULL));
1118 } 1072 }
1119 1073
1120 TEST_F(HostContentSettingsMapTest, 1074 TEST_F(HostContentSettingsMapTest,
1121 GetNonDefaultContentSettingsIfTypeManaged) { 1075 GetNonDefaultContentSettingsIfTypeManaged) {
1122 TestingProfile profile; 1076 TestingProfile profile;
1123 HostContentSettingsMap* host_content_settings_map = 1077 HostContentSettingsMap* host_content_settings_map =
1124 HostContentSettingsMapFactory::GetForProfile(&profile); 1078 HostContentSettingsMapFactory::GetForProfile(&profile);
1125 sync_preferences::TestingPrefServiceSyncable* prefs = 1079 sync_preferences::TestingPrefServiceSyncable* prefs =
1126 profile.GetTestingPrefService(); 1080 profile.GetTestingPrefService();
1127 1081
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 1315
1362 // Test that during construction all the prefs get cleared. 1316 // Test that during construction all the prefs get cleared.
1363 HostContentSettingsMapFactory::GetForProfile(&profile); 1317 HostContentSettingsMapFactory::GetForProfile(&profile);
1364 1318
1365 const base::DictionaryValue* all_settings_dictionary = 1319 const base::DictionaryValue* all_settings_dictionary =
1366 profile.GetPrefs()->GetDictionary( 1320 profile.GetPrefs()->GetDictionary(
1367 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES)); 1321 GetPrefName(CONTENT_SETTINGS_TYPE_COOKIES));
1368 EXPECT_TRUE(all_settings_dictionary->empty()); 1322 EXPECT_TRUE(all_settings_dictionary->empty());
1369 } 1323 }
1370 1324
1371 TEST_F(HostContentSettingsMapTest, MigrateKeygenSettings) {
1372 TestingProfile profile;
1373 HostContentSettingsMap* host_content_settings_map =
1374 HostContentSettingsMapFactory::GetForProfile(&profile);
1375
1376 // Set old formatted settings.
1377 GURL host("http://example.com/");
1378 ContentSettingsPattern pattern =
1379 ContentSettingsPattern::FromURLNoWildcard(host);
1380
1381 // Default setting is BLOCK.
1382 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1383 host_content_settings_map->GetContentSetting(
1384 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
1385
1386 host_content_settings_map->SetContentSettingCustomScope(
1387 pattern, pattern, CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
1388 CONTENT_SETTING_ALLOW);
1389 // Because of the old formatted setting entry which has two same patterns,
1390 // SetContentSetting() to (host, GURL()) will be ignored.
1391 host_content_settings_map->SetContentSettingDefaultScope(
1392 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
1393 CONTENT_SETTING_BLOCK);
1394 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1395 host_content_settings_map->GetContentSetting(
1396 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
1397
1398 host_content_settings_map->MigrateKeygenSettings();
1399
1400 ContentSettingsForOneType settings;
1401 host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_KEYGEN,
1402 std::string(), &settings);
1403 for (const ContentSettingPatternSource& setting_entry : settings) {
1404 EXPECT_EQ(setting_entry.secondary_pattern,
1405 ContentSettingsPattern::Wildcard());
1406 }
1407
1408 EXPECT_EQ(CONTENT_SETTING_ALLOW,
1409 host_content_settings_map->GetContentSetting(
1410 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
1411
1412 // After migrating old settings, changes to the setting works.
1413 host_content_settings_map->SetContentSettingDefaultScope(
1414 host, GURL(), CONTENT_SETTINGS_TYPE_KEYGEN, std::string(),
1415 CONTENT_SETTING_BLOCK);
1416 EXPECT_EQ(CONTENT_SETTING_BLOCK,
1417 host_content_settings_map->GetContentSetting(
1418 host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string()));
1419 }
1420
1421 TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) { 1325 TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) {
1422 TestingProfile profile; 1326 TestingProfile profile;
1423 HostContentSettingsMap* host_content_settings_map = 1327 HostContentSettingsMap* host_content_settings_map =
1424 HostContentSettingsMapFactory::GetForProfile(&profile); 1328 HostContentSettingsMapFactory::GetForProfile(&profile);
1425 PrefService* prefs = profile.GetPrefs(); 1329 PrefService* prefs = profile.GetPrefs();
1426 // Set the pref to its initial state so that migration can be done later in 1330 // Set the pref to its initial state so that migration can be done later in
1427 // the test (normally it is done on construction of HostContentSettingsMap). 1331 // the test (normally it is done on construction of HostContentSettingsMap).
1428 int default_value; 1332 int default_value;
1429 prefs->GetDefaultPrefValue(prefs::kDomainToOriginMigrationStatus) 1333 prefs->GetDefaultPrefValue(prefs::kDomainToOriginMigrationStatus)
1430 ->GetAsInteger(&default_value); 1334 ->GetAsInteger(&default_value);
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 EXPECT_TRUE(map->CanSetNarrowestContentSetting( 1714 EXPECT_TRUE(map->CanSetNarrowestContentSetting(
1811 valid_url, valid_url, 1715 valid_url, valid_url,
1812 CONTENT_SETTINGS_TYPE_POPUPS)); 1716 CONTENT_SETTINGS_TYPE_POPUPS));
1813 1717
1814 GURL invalid_url("about:blank"); 1718 GURL invalid_url("about:blank");
1815 EXPECT_FALSE(map->CanSetNarrowestContentSetting( 1719 EXPECT_FALSE(map->CanSetNarrowestContentSetting(
1816 invalid_url, invalid_url, 1720 invalid_url, invalid_url,
1817 CONTENT_SETTINGS_TYPE_POPUPS)); 1721 CONTENT_SETTINGS_TYPE_POPUPS));
1818 } 1722 }
1819 1723
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/content_settings/tab_specific_content_settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698