Chromium Code Reviews| Index: chrome/browser/content_settings/host_content_settings_map_unittest.cc |
| diff --git a/chrome/browser/content_settings/host_content_settings_map_unittest.cc b/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
| index 04eac30aaa1dbde21d758886ecdcd97193367931..a9444a3e999a98a3f0a826ded66077b53211f29a 100644 |
| --- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
| +++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
| @@ -678,11 +678,11 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) { |
| TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
| TestingProfile profile; |
| + Profile* otr_profile = profile.GetOffTheRecordProfile(); |
| HostContentSettingsMap* host_content_settings_map = |
| HostContentSettingsMapFactory::GetForProfile(&profile); |
| - scoped_refptr<HostContentSettingsMap> otr_map( |
| - new HostContentSettingsMap(profile.GetPrefs(), |
| - true)); |
| + HostContentSettingsMap* otr_map = |
| + HostContentSettingsMapFactory::GetForProfile(otr_profile); |
| GURL host("http://example.com/"); |
| ContentSettingsPattern pattern = |
| @@ -723,8 +723,120 @@ TEST_F(HostContentSettingsMapTest, OffTheRecord) { |
| EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| otr_map->GetContentSetting( |
| host, host, CONTENT_SETTINGS_TYPE_IMAGES, std::string())); |
| +} |
| + |
| +TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritPref) { |
| + // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in |
| + // ContentSettingsRegistry (e.g. push & notifications) only inherit blocks |
|
msramek
2015/12/01 13:41:43
nit: s/blocks/BLOCK/g
johnme
2015/12/02 15:13:16
Done.
|
| + // from the regular to incognito pref provider. |
|
msramek
2015/12/01 13:41:43
nit: it might be better to just talk about default
johnme
2015/12/02 15:13:16
Done.
|
| + TestingProfile profile; |
| + Profile* otr_profile = profile.GetOffTheRecordProfile(); |
| + HostContentSettingsMap* host_content_settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(&profile); |
| + HostContentSettingsMap* otr_map = |
| + HostContentSettingsMapFactory::GetForProfile(otr_profile); |
| + |
| + GURL host("http://example.com/"); |
| + ContentSettingsPattern pattern = |
| + ContentSettingsPattern::FromString("[*.]example.com"); |
|
msramek
2015/12/01 13:41:43
nit: indentation
johnme
2015/12/02 15:13:16
Done. I also fixed it in the 13 other places in th
|
| + |
| + EXPECT_EQ(CONTENT_SETTING_ASK, host_content_settings_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ASK, otr_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| + |
| + // BLOCK should be inherited from the main map to the incognito map. |
| + host_content_settings_map->SetContentSetting( |
| + pattern, |
| + ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string(), |
| + CONTENT_SETTING_BLOCK); |
| + EXPECT_EQ(CONTENT_SETTING_BLOCK, host_content_settings_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_BLOCK, otr_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| - otr_map->ShutdownOnUIThread(); |
| + // ALLOW should not be inherited from the main map to the incognito map (but |
| + // it still overwrites the BLOCK, hence incognito reverts to ASK). |
| + host_content_settings_map->SetContentSetting( |
| + pattern, |
| + ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string(), |
| + CONTENT_SETTING_ALLOW); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, host_content_settings_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ASK, otr_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| +} |
| + |
| +TEST_F(HostContentSettingsMapTest, OffTheRecordPartialInheritDefault) { |
| + // Permissions marked INHERIT_IN_INCOGNITO_EXCEPT_ALLOW in |
| + // ContentSettingsRegistry (e.g. push & notifications) only inherit blocks |
| + // from the regular to incognito default provider. |
| + TestingProfile profile; |
| + Profile* otr_profile = profile.GetOffTheRecordProfile(); |
| + HostContentSettingsMap* host_content_settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(&profile); |
| + HostContentSettingsMap* otr_map = |
| + HostContentSettingsMapFactory::GetForProfile(otr_profile); |
| + |
| + GURL host("http://example.com/"); |
| + |
| + EXPECT_EQ(CONTENT_SETTING_ASK, |
| + host_content_settings_map->GetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| + EXPECT_EQ(CONTENT_SETTING_ASK, |
| + host_content_settings_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ASK, |
| + otr_map->GetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| + EXPECT_EQ(CONTENT_SETTING_ASK, |
| + otr_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string())); |
| + |
| + // BLOCK should be inherited from the main map to the incognito map. |
| + host_content_settings_map->SetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + CONTENT_SETTING_BLOCK); |
| + EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| + host_content_settings_map->GetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| + EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| + host_content_settings_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| + otr_map->GetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| + EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| + otr_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string())); |
| + |
| + // ALLOW should not be inherited from the main map to the incognito map (but |
| + // it still overwrites the BLOCK, hence incognito reverts to ASK). |
| + host_content_settings_map->SetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + CONTENT_SETTING_ALLOW); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ASK, |
| + otr_map->GetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, NULL)); |
| + EXPECT_EQ(CONTENT_SETTING_ASK, |
| + otr_map->GetContentSetting( |
| + host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + std::string())); |
| } |
| // For a single Unicode encoded pattern, check if it gets converted to punycode |