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" |
11 #include "base/json/json_reader.h" | 11 #include "base/json/json_reader.h" |
12 #include "base/json/json_writer.h" | 12 #include "base/json/json_writer.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/test/scoped_feature_list.h" |
| 16 #include "base/test/test_timeouts.h" |
| 17 #include "base/threading/platform_thread.h" |
15 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 18 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
16 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 19 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 20 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
18 #include "chrome/browser/content_settings/mock_settings_observer.h" | 21 #include "chrome/browser/content_settings/mock_settings_observer.h" |
| 22 #include "chrome/common/chrome_features.h" |
19 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
20 #include "chrome/test/base/testing_profile.h" | 24 #include "chrome/test/base/testing_profile.h" |
21 #include "components/content_settings/core/browser/content_settings_details.h" | 25 #include "components/content_settings/core/browser/content_settings_details.h" |
22 #include "components/content_settings/core/browser/cookie_settings.h" | 26 #include "components/content_settings/core/browser/cookie_settings.h" |
23 #include "components/content_settings/core/browser/host_content_settings_map.h" | 27 #include "components/content_settings/core/browser/host_content_settings_map.h" |
24 #include "components/content_settings/core/browser/website_settings_info.h" | 28 #include "components/content_settings/core/browser/website_settings_info.h" |
25 #include "components/content_settings/core/browser/website_settings_registry.h" | 29 #include "components/content_settings/core/browser/website_settings_registry.h" |
26 #include "components/content_settings/core/common/pref_names.h" | 30 #include "components/content_settings/core/common/pref_names.h" |
27 #include "components/prefs/pref_service.h" | 31 #include "components/prefs/pref_service.h" |
28 #include "components/prefs/scoped_user_pref_update.h" | 32 #include "components/prefs/scoped_user_pref_update.h" |
(...skipping 1652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1681 host_content_settings_map->SetContentSettingCustomScope( | 1685 host_content_settings_map->SetContentSettingCustomScope( |
1682 pattern, ContentSettingsPattern::Wildcard(), | 1686 pattern, ContentSettingsPattern::Wildcard(), |
1683 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | 1687 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
1684 host_content_settings_map->SetWebsiteSettingCustomScope( | 1688 host_content_settings_map->SetWebsiteSettingCustomScope( |
1685 pattern2, ContentSettingsPattern::Wildcard(), | 1689 pattern2, ContentSettingsPattern::Wildcard(), |
1686 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 1690 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), |
1687 base::WrapUnique(new base::DictionaryValue())); | 1691 base::WrapUnique(new base::DictionaryValue())); |
1688 | 1692 |
1689 // First, test that we clear only COOKIES (not APP_BANNER), and pattern2. | 1693 // First, test that we clear only COOKIES (not APP_BANNER), and pattern2. |
1690 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( | 1694 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
1691 CONTENT_SETTINGS_TYPE_COOKIES, | 1695 CONTENT_SETTINGS_TYPE_COOKIES, base::Time(), |
1692 base::Bind(&MatchPrimaryPattern, pattern2)); | 1696 base::Bind(&MatchPrimaryPattern, pattern2)); |
1693 host_content_settings_map->GetSettingsForOneType( | 1697 host_content_settings_map->GetSettingsForOneType( |
1694 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings); | 1698 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings); |
1695 // |host_settings| contains default & block. | 1699 // |host_settings| contains default & block. |
1696 EXPECT_EQ(2U, host_settings.size()); | 1700 EXPECT_EQ(2U, host_settings.size()); |
1697 EXPECT_EQ(pattern, host_settings[0].primary_pattern); | 1701 EXPECT_EQ(pattern, host_settings[0].primary_pattern); |
1698 EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString()); | 1702 EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString()); |
1699 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); | 1703 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); |
1700 EXPECT_EQ("*", host_settings[1].secondary_pattern.ToString()); | 1704 EXPECT_EQ("*", host_settings[1].secondary_pattern.ToString()); |
1701 | 1705 |
(...skipping 24 matching lines...) Expand all Loading... |
1726 host_content_settings_map->GetSettingsForOneType( | 1730 host_content_settings_map->GetSettingsForOneType( |
1727 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | 1731 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
1728 EXPECT_EQ(2u, host_settings.size()); | 1732 EXPECT_EQ(2u, host_settings.size()); |
1729 | 1733 |
1730 // Clear the http one, which we should be able to do w/ the origin only, as | 1734 // Clear the http one, which we should be able to do w/ the origin only, as |
1731 // the scope of CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT is | 1735 // the scope of CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT is |
1732 // REQUESTING_ORIGIN_ONLY_SCOPE. | 1736 // REQUESTING_ORIGIN_ONLY_SCOPE. |
1733 ContentSettingsPattern http_pattern = | 1737 ContentSettingsPattern http_pattern = |
1734 ContentSettingsPattern::FromURLNoWildcard(url3_origin_only); | 1738 ContentSettingsPattern::FromURLNoWildcard(url3_origin_only); |
1735 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( | 1739 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
1736 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | 1740 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, base::Time(), |
1737 base::Bind(&MatchPrimaryPattern, http_pattern)); | 1741 base::Bind(&MatchPrimaryPattern, http_pattern)); |
1738 // Verify we only have one, and it's url1. | 1742 // Verify we only have one, and it's url1. |
1739 host_content_settings_map->GetSettingsForOneType( | 1743 host_content_settings_map->GetSettingsForOneType( |
1740 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | 1744 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
1741 EXPECT_EQ(1u, host_settings.size()); | 1745 EXPECT_EQ(1u, host_settings.size()); |
1742 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), | 1746 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), |
1743 host_settings[0].primary_pattern); | 1747 host_settings[0].primary_pattern); |
1744 } | 1748 } |
1745 | 1749 |
| 1750 TEST_F(HostContentSettingsMapTest, ClearSettingsWithTimePredicate) { |
| 1751 base::test::ScopedFeatureList feature_list; |
| 1752 feature_list.InitAndEnableFeature(features::kTabsInCbd); |
| 1753 |
| 1754 TestingProfile profile; |
| 1755 HostContentSettingsMap* host_content_settings_map = |
| 1756 HostContentSettingsMapFactory::GetForProfile(&profile); |
| 1757 ContentSettingsForOneType host_settings; |
| 1758 |
| 1759 GURL url1("https://www.google.com/"); |
| 1760 GURL url2("https://maps.google.com/"); |
| 1761 |
| 1762 // Add setting for url1. |
| 1763 host_content_settings_map->SetContentSettingDefaultScope( |
| 1764 url1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), |
| 1765 CONTENT_SETTING_BLOCK); |
| 1766 |
| 1767 // Make sure that the timestamp for url1 is different from |t|. |
| 1768 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); |
| 1769 base::Time t = base::Time::Now(); |
| 1770 |
| 1771 // Add setting for url2. |
| 1772 host_content_settings_map->SetContentSettingDefaultScope( |
| 1773 url2, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), |
| 1774 CONTENT_SETTING_BLOCK); |
| 1775 |
| 1776 // Verify we have two pattern and the default. |
| 1777 host_content_settings_map->GetSettingsForOneType( |
| 1778 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); |
| 1779 EXPECT_EQ(3u, host_settings.size()); |
| 1780 |
| 1781 // Clear all settings since |t|. |
| 1782 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
| 1783 CONTENT_SETTINGS_TYPE_POPUPS, t, |
| 1784 HostContentSettingsMap::PatternSourcePredicate()); |
| 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 } |
| 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 |