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 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "url/gurl.h" | 34 #include "url/gurl.h" |
35 | 35 |
36 using content::BrowserThread; | 36 using content::BrowserThread; |
37 | 37 |
38 using ::testing::_; | 38 using ::testing::_; |
39 | 39 |
40 namespace { | 40 namespace { |
41 | 41 |
42 bool MatchPrimaryPattern(const ContentSettingsPattern& expected_primary, | 42 bool MatchPrimaryPattern(const ContentSettingsPattern& expected_primary, |
43 const ContentSettingsPattern& primary_pattern, | 43 const ContentSettingsPattern& primary_pattern, |
44 const ContentSettingsPattern& secondary_pattern) { | 44 const ContentSettingsPattern& secondary_pattern, |
45 base::Time last_modified) { | |
45 return expected_primary == primary_pattern; | 46 return expected_primary == primary_pattern; |
46 } | 47 } |
47 | 48 |
49 bool MatchLastModified(base::Time begin_time, | |
50 const ContentSettingsPattern& primary_pattern, | |
51 const ContentSettingsPattern& secondary_pattern, | |
52 base::Time last_modified) { | |
53 return last_modified >= begin_time; | |
54 } | |
55 | |
48 } // namespace | 56 } // namespace |
49 | 57 |
50 class HostContentSettingsMapTest : public testing::Test { | 58 class HostContentSettingsMapTest : public testing::Test { |
51 public: | 59 public: |
52 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) { | 60 HostContentSettingsMapTest() : ui_thread_(BrowserThread::UI, &message_loop_) { |
53 } | 61 } |
54 | 62 |
55 protected: | 63 protected: |
56 const std::string& GetPrefName(ContentSettingsType type) { | 64 const std::string& GetPrefName(ContentSettingsType type) { |
57 return content_settings::WebsiteSettingsRegistry::GetInstance() | 65 return content_settings::WebsiteSettingsRegistry::GetInstance() |
(...skipping 1678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1736 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | 1744 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, |
1737 base::Bind(&MatchPrimaryPattern, http_pattern)); | 1745 base::Bind(&MatchPrimaryPattern, http_pattern)); |
1738 // Verify we only have one, and it's url1. | 1746 // Verify we only have one, and it's url1. |
1739 host_content_settings_map->GetSettingsForOneType( | 1747 host_content_settings_map->GetSettingsForOneType( |
1740 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | 1748 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
1741 EXPECT_EQ(1u, host_settings.size()); | 1749 EXPECT_EQ(1u, host_settings.size()); |
1742 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), | 1750 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), |
1743 host_settings[0].primary_pattern); | 1751 host_settings[0].primary_pattern); |
1744 } | 1752 } |
1745 | 1753 |
1754 TEST_F(HostContentSettingsMapTest, ClearSettingsForOneTypeWithPredicateTime) { | |
1755 if (!HostContentSettingsMap::kStoreLastModified) { | |
1756 return; | |
1757 } | |
1758 TestingProfile profile; | |
1759 HostContentSettingsMap* host_content_settings_map = | |
1760 HostContentSettingsMapFactory::GetForProfile(&profile); | |
1761 ContentSettingsForOneType host_settings; | |
1762 | |
1763 GURL url1("https://www.google.com/"); | |
1764 GURL url2("https://maps.google.com/"); | |
1765 | |
1766 // Add setting for url1. | |
1767 host_content_settings_map->SetContentSettingDefaultScope( | |
1768 url1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), | |
1769 CONTENT_SETTING_BLOCK); | |
1770 | |
1771 base::Time t2 = base::Time::Now(); | |
1772 // Add setting for url2. | |
1773 host_content_settings_map->SetContentSettingDefaultScope( | |
1774 url2, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), | |
1775 CONTENT_SETTING_BLOCK); | |
1776 | |
1777 // Verify we have two pattern and the default. | |
1778 host_content_settings_map->GetSettingsForOneType( | |
1779 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); | |
1780 EXPECT_EQ(3u, host_settings.size()); | |
1781 | |
1782 // Clear all settings since t2. | |
1783 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( | |
1784 CONTENT_SETTINGS_TYPE_POPUPS, base::Bind(&MatchLastModified, t2)); | |
1785 | |
1786 // Verify we only have one pattern (url1) and the default. | |
1787 host_content_settings_map->GetSettingsForOneType( | |
1788 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); | |
1789 EXPECT_EQ(2u, host_settings.size()); | |
1790 EXPECT_EQ("https://www.google.com:443", | |
1791 host_settings[0].primary_pattern.ToString()); | |
1792 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); | |
1793 } | |
msramek
2017/04/19 10:49:16
Please also add a test with resource identifiers.
dullweber
2017/04/19 15:02:45
I added a test and discovered that ClearSettingsFo
| |
1794 | |
1746 TEST_F(HostContentSettingsMapTest, CanSetNarrowestSetting) { | 1795 TEST_F(HostContentSettingsMapTest, CanSetNarrowestSetting) { |
1747 TestingProfile profile; | 1796 TestingProfile profile; |
1748 const auto* map = HostContentSettingsMapFactory::GetForProfile(&profile); | 1797 const auto* map = HostContentSettingsMapFactory::GetForProfile(&profile); |
1749 | 1798 |
1750 GURL valid_url("http://google.com"); | 1799 GURL valid_url("http://google.com"); |
1751 EXPECT_TRUE(map->CanSetNarrowestContentSetting( | 1800 EXPECT_TRUE(map->CanSetNarrowestContentSetting( |
1752 valid_url, valid_url, | 1801 valid_url, valid_url, |
1753 CONTENT_SETTINGS_TYPE_POPUPS)); | 1802 CONTENT_SETTINGS_TYPE_POPUPS)); |
1754 | 1803 |
1755 GURL invalid_url("about:blank"); | 1804 GURL invalid_url("about:blank"); |
1756 EXPECT_FALSE(map->CanSetNarrowestContentSetting( | 1805 EXPECT_FALSE(map->CanSetNarrowestContentSetting( |
1757 invalid_url, invalid_url, | 1806 invalid_url, invalid_url, |
1758 CONTENT_SETTINGS_TYPE_POPUPS)); | 1807 CONTENT_SETTINGS_TYPE_POPUPS)); |
1759 } | 1808 } |
1760 | 1809 |
OLD | NEW |