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 4573d3d95e49b64b4a43fbdf751c69ff77f3f5ba..cfb4b194f99e967f2345b8ad4ab2d601c1595529 100644 |
| --- a/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
| +++ b/chrome/browser/content_settings/host_content_settings_map_unittest.cc |
| @@ -301,12 +301,16 @@ TEST_F(HostContentSettingsMapTest, Patterns) { |
| GURL host1("http://example.com/"); |
| GURL host2("http://www.example.com/"); |
| GURL host3("http://example.org/"); |
| + ContentSettingsPattern pattern1 = |
| + ContentSettingsPattern::FromString("[*.]example.com"); |
| + ContentSettingsPattern pattern2 = |
| + ContentSettingsPattern::FromString("example.org"); |
|
msramek
2016/06/24 19:53:48
We should also have tests for crazier patterns suc
lshang
2016/06/27 00:31:00
Now I realized how we lack of full coverage of pat
|
| EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| host_content_settings_map->GetContentSetting( |
| host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| - host_content_settings_map->SetContentSettingDefaultScope( |
| - host1, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| - CONTENT_SETTING_BLOCK); |
| + host_content_settings_map->SetContentSettingCustomScope( |
| + pattern1, ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| @@ -316,14 +320,42 @@ TEST_F(HostContentSettingsMapTest, Patterns) { |
| EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| host_content_settings_map->GetContentSetting( |
| host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| - host_content_settings_map->SetContentSettingDefaultScope( |
| - host3, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| - CONTENT_SETTING_BLOCK); |
| + host_content_settings_map->SetContentSettingCustomScope( |
| + pattern2, ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| } |
| +// Changing a setting for one origin doesn't affect subdomains. |
| +TEST_F(HostContentSettingsMapTest, Origins) { |
| + TestingProfile profile; |
| + HostContentSettingsMap* host_content_settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(&profile); |
| + |
| + GURL host1("http://example.com/"); |
| + GURL host2("http://www.example.com/"); |
| + GURL host3("http://example.org/"); |
|
msramek
2016/06/24 19:53:48
Consider also adding a test for different port, e.
lshang
2016/06/27 00:31:00
Done.
|
| + ContentSettingsPattern pattern = |
| + ContentSettingsPattern::FromURLNoWildcard(host1); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + host_content_settings_map->SetContentSettingCustomScope( |
| + pattern, ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| + EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| + host_content_settings_map->GetContentSetting( |
| + host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| +} |
| + |
| TEST_F(HostContentSettingsMapTest, Observer) { |
| TestingProfile profile; |
| HostContentSettingsMap* host_content_settings_map = |
| @@ -576,58 +608,95 @@ TEST_F(HostContentSettingsMapTest, NestedSettings) { |
| HostContentSettingsMap* host_content_settings_map = |
| HostContentSettingsMapFactory::GetForProfile(&profile); |
| - GURL host("http://a.b.example.com/"); |
| GURL host1("http://example.com/"); |
| GURL host2("http://b.example.com/"); |
| + GURL host3("http://a.b.example.com/"); |
| + GURL host4("http://a.example.com/"); |
| + GURL host5("http://b.b.example.com/"); |
| + ContentSettingsPattern pattern1 = |
| + ContentSettingsPattern::FromString("[*.]example.com"); |
| + ContentSettingsPattern pattern2 = |
| + ContentSettingsPattern::FromString("[*.]b.example.com"); |
| + ContentSettingsPattern pattern3 = |
| + ContentSettingsPattern::FromString("a.b.example.com"); |
| - host_content_settings_map->SetContentSettingDefaultScope( |
| - host1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), |
| - CONTENT_SETTING_BLOCK); |
| - |
| - host_content_settings_map->SetContentSettingDefaultScope( |
| - host2, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| - CONTENT_SETTING_BLOCK); |
| - |
| - host_content_settings_map->SetContentSettingDefaultScope( |
| - host, GURL(), CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, std::string(), |
| - CONTENT_SETTING_BLOCK); |
| - host_content_settings_map->SetDefaultContentSetting( |
| - CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK); |
| - |
| + // Test nested patterns for one type. |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_COOKIES, nullptr)); |
| + host_content_settings_map->SetContentSettingCustomScope( |
| + pattern1, ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| + host_content_settings_map->SetContentSettingCustomScope( |
| + pattern2, ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_ALLOW); |
| + host_content_settings_map->SetContentSettingCustomScope( |
| + pattern3, ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + host1, host1, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_POPUPS, std::string())); |
| + host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string())); |
| + host4, host4, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetContentSetting( |
| + host5, host5, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + |
| + host_content_settings_map->ClearSettingsForOneType( |
| + CONTENT_SETTINGS_TYPE_COOKIES); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host_content_settings_map->GetDefaultContentSetting( |
| + CONTENT_SETTINGS_TYPE_COOKIES, nullptr)); |
| + |
| + GURL https_host2("https://b.example.com/"); |
|
msramek
2016/06/24 19:53:48
nit: 1,2 instead of 2,3
lshang
2016/06/27 00:31:00
Done.
|
| + GURL https_host3("https://a.b.example.com/"); |
| + ContentSettingsPattern pattern4 = |
| + ContentSettingsPattern::FromString("b.example.com"); |
| + |
| + host_content_settings_map->SetContentSettingCustomScope( |
| + pattern4, ContentSettingsPattern::Wildcard(), |
| + CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
| + // Pattern "b.example.com" will affect (http|https)://b.example.com |
| EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
| - std::string())); |
| - EXPECT_EQ(CONTENT_SETTING_ASK, |
| + host2, host2, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| - EXPECT_EQ( |
| - CONTENT_SETTING_ASK, |
| - host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string())); |
| - EXPECT_EQ(CONTENT_SETTING_ASK, |
| + https_host2, https_host2, CONTENT_SETTINGS_TYPE_COOKIES, |
| + std::string())); |
| + // Pattern "b.example.com" will not affect (http|https)://a.b.example.com |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_FULLSCREEN, std::string())); |
| -#if !defined(OS_ANDROID) |
| - EXPECT_EQ(CONTENT_SETTING_ASK, |
| + host3, host3, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_MOUSELOCK, std::string())); |
| -#endif |
| + https_host3, https_host3, CONTENT_SETTINGS_TYPE_COOKIES, |
| + std::string())); |
| +} |
| + |
| +TEST_F(HostContentSettingsMapTest, TypeIsolatedSettings) { |
| + TestingProfile profile; |
| + HostContentSettingsMap* host_content_settings_map = |
| + HostContentSettingsMapFactory::GetForProfile(&profile); |
| + |
| + GURL host("http://example.com/"); |
| + |
| + host_content_settings_map->SetContentSettingDefaultScope( |
| + host, GURL(), CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| + CONTENT_SETTING_BLOCK); |
| EXPECT_EQ(CONTENT_SETTING_BLOCK, |
| host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_KEYGEN, std::string())); |
| - EXPECT_EQ(CONTENT_SETTING_ALLOW, |
| + host, host, CONTENT_SETTINGS_TYPE_COOKIES, std::string())); |
| + EXPECT_EQ(CONTENT_SETTING_ASK, |
| host_content_settings_map->GetContentSetting( |
| - host, host, CONTENT_SETTINGS_TYPE_AUTOPLAY, std::string())); |
| + host, host, CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
| } |
| TEST_F(HostContentSettingsMapTest, OffTheRecord) { |