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" | |
15 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 16 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
16 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 17 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
17 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 18 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
18 #include "chrome/browser/content_settings/mock_settings_observer.h" | 19 #include "chrome/browser/content_settings/mock_settings_observer.h" |
20 #include "chrome/common/chrome_features.h" | |
19 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
20 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
21 #include "components/content_settings/core/browser/content_settings_details.h" | 23 #include "components/content_settings/core/browser/content_settings_details.h" |
22 #include "components/content_settings/core/browser/cookie_settings.h" | 24 #include "components/content_settings/core/browser/cookie_settings.h" |
23 #include "components/content_settings/core/browser/host_content_settings_map.h" | 25 #include "components/content_settings/core/browser/host_content_settings_map.h" |
24 #include "components/content_settings/core/browser/website_settings_info.h" | 26 #include "components/content_settings/core/browser/website_settings_info.h" |
25 #include "components/content_settings/core/browser/website_settings_registry.h" | 27 #include "components/content_settings/core/browser/website_settings_registry.h" |
26 #include "components/content_settings/core/common/pref_names.h" | 28 #include "components/content_settings/core/common/pref_names.h" |
27 #include "components/prefs/pref_service.h" | 29 #include "components/prefs/pref_service.h" |
28 #include "components/prefs/scoped_user_pref_update.h" | 30 #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( | 1683 host_content_settings_map->SetContentSettingCustomScope( |
1682 pattern, ContentSettingsPattern::Wildcard(), | 1684 pattern, ContentSettingsPattern::Wildcard(), |
1683 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); | 1685 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), CONTENT_SETTING_BLOCK); |
1684 host_content_settings_map->SetWebsiteSettingCustomScope( | 1686 host_content_settings_map->SetWebsiteSettingCustomScope( |
1685 pattern2, ContentSettingsPattern::Wildcard(), | 1687 pattern2, ContentSettingsPattern::Wildcard(), |
1686 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), | 1688 CONTENT_SETTINGS_TYPE_APP_BANNER, std::string(), |
1687 base::WrapUnique(new base::DictionaryValue())); | 1689 base::WrapUnique(new base::DictionaryValue())); |
1688 | 1690 |
1689 // First, test that we clear only COOKIES (not APP_BANNER), and pattern2. | 1691 // First, test that we clear only COOKIES (not APP_BANNER), and pattern2. |
1690 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( | 1692 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
1691 CONTENT_SETTINGS_TYPE_COOKIES, | 1693 CONTENT_SETTINGS_TYPE_COOKIES, base::Time(), |
1692 base::Bind(&MatchPrimaryPattern, pattern2)); | 1694 base::Bind(&MatchPrimaryPattern, pattern2)); |
1693 host_content_settings_map->GetSettingsForOneType( | 1695 host_content_settings_map->GetSettingsForOneType( |
1694 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings); | 1696 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), &host_settings); |
1695 // |host_settings| contains default & block. | 1697 // |host_settings| contains default & block. |
1696 EXPECT_EQ(2U, host_settings.size()); | 1698 EXPECT_EQ(2U, host_settings.size()); |
1697 EXPECT_EQ(pattern, host_settings[0].primary_pattern); | 1699 EXPECT_EQ(pattern, host_settings[0].primary_pattern); |
1698 EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString()); | 1700 EXPECT_EQ("*", host_settings[0].secondary_pattern.ToString()); |
1699 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); | 1701 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); |
1700 EXPECT_EQ("*", host_settings[1].secondary_pattern.ToString()); | 1702 EXPECT_EQ("*", host_settings[1].secondary_pattern.ToString()); |
1701 | 1703 |
(...skipping 24 matching lines...) Expand all Loading... | |
1726 host_content_settings_map->GetSettingsForOneType( | 1728 host_content_settings_map->GetSettingsForOneType( |
1727 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | 1729 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
1728 EXPECT_EQ(2u, host_settings.size()); | 1730 EXPECT_EQ(2u, host_settings.size()); |
1729 | 1731 |
1730 // Clear the http one, which we should be able to do w/ the origin only, as | 1732 // 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 | 1733 // the scope of CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT is |
1732 // REQUESTING_ORIGIN_ONLY_SCOPE. | 1734 // REQUESTING_ORIGIN_ONLY_SCOPE. |
1733 ContentSettingsPattern http_pattern = | 1735 ContentSettingsPattern http_pattern = |
1734 ContentSettingsPattern::FromURLNoWildcard(url3_origin_only); | 1736 ContentSettingsPattern::FromURLNoWildcard(url3_origin_only); |
1735 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( | 1737 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( |
1736 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, | 1738 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, base::Time(), |
1737 base::Bind(&MatchPrimaryPattern, http_pattern)); | 1739 base::Bind(&MatchPrimaryPattern, http_pattern)); |
1738 // Verify we only have one, and it's url1. | 1740 // Verify we only have one, and it's url1. |
1739 host_content_settings_map->GetSettingsForOneType( | 1741 host_content_settings_map->GetSettingsForOneType( |
1740 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); | 1742 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings); |
1741 EXPECT_EQ(1u, host_settings.size()); | 1743 EXPECT_EQ(1u, host_settings.size()); |
1742 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), | 1744 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), |
1743 host_settings[0].primary_pattern); | 1745 host_settings[0].primary_pattern); |
1744 } | 1746 } |
1745 | 1747 |
1748 TEST_F(HostContentSettingsMapTest, ClearSettingsWithTimePredicate) { | |
1749 base::test::ScopedFeatureList feature_list; | |
1750 feature_list.InitAndEnableFeature(features::kTabsInCbd); | |
1751 | |
1752 TestingProfile profile; | |
1753 HostContentSettingsMap* host_content_settings_map = | |
1754 HostContentSettingsMapFactory::GetForProfile(&profile); | |
1755 ContentSettingsForOneType host_settings; | |
1756 | |
1757 GURL url1("https://www.google.com/"); | |
1758 GURL url2("https://maps.google.com/"); | |
1759 | |
1760 // Add setting for url1. | |
1761 host_content_settings_map->SetContentSettingDefaultScope( | |
1762 url1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), | |
1763 CONTENT_SETTING_BLOCK); | |
1764 | |
1765 base::Time t2 = base::Time::Now(); | |
raymes
2017/04/24 03:20:22
I'm not sure if this will be brittle since it reli
dullweber
2017/04/25 10:50:44
I added a Sleep(tiny_timeout) before t2, to make s
raymes
2017/04/26 01:54:17
Yep. I think that's what we had before (there used
| |
1766 // Add setting for url2. | |
1767 host_content_settings_map->SetContentSettingDefaultScope( | |
1768 url2, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), | |
1769 CONTENT_SETTING_BLOCK); | |
1770 | |
1771 // Verify we have two pattern and the default. | |
1772 host_content_settings_map->GetSettingsForOneType( | |
1773 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); | |
1774 EXPECT_EQ(3u, host_settings.size()); | |
1775 | |
1776 // Clear all settings since t2. | |
1777 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( | |
1778 CONTENT_SETTINGS_TYPE_POPUPS, t2, | |
1779 HostContentSettingsMap::PatternSourcePredicate()); | |
1780 | |
1781 // Verify we only have one pattern (url1) and the default. | |
1782 host_content_settings_map->GetSettingsForOneType( | |
1783 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); | |
1784 EXPECT_EQ(2u, host_settings.size()); | |
1785 EXPECT_EQ("https://www.google.com:443", | |
1786 host_settings[0].primary_pattern.ToString()); | |
1787 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); | |
1788 } | |
1789 | |
1746 TEST_F(HostContentSettingsMapTest, CanSetNarrowestSetting) { | 1790 TEST_F(HostContentSettingsMapTest, CanSetNarrowestSetting) { |
1747 TestingProfile profile; | 1791 TestingProfile profile; |
1748 const auto* map = HostContentSettingsMapFactory::GetForProfile(&profile); | 1792 const auto* map = HostContentSettingsMapFactory::GetForProfile(&profile); |
1749 | 1793 |
1750 GURL valid_url("http://google.com"); | 1794 GURL valid_url("http://google.com"); |
1751 EXPECT_TRUE(map->CanSetNarrowestContentSetting( | 1795 EXPECT_TRUE(map->CanSetNarrowestContentSetting( |
1752 valid_url, valid_url, | 1796 valid_url, valid_url, |
1753 CONTENT_SETTINGS_TYPE_POPUPS)); | 1797 CONTENT_SETTINGS_TYPE_POPUPS)); |
1754 | 1798 |
1755 GURL invalid_url("about:blank"); | 1799 GURL invalid_url("about:blank"); |
1756 EXPECT_FALSE(map->CanSetNarrowestContentSetting( | 1800 EXPECT_FALSE(map->CanSetNarrowestContentSetting( |
1757 invalid_url, invalid_url, | 1801 invalid_url, invalid_url, |
1758 CONTENT_SETTINGS_TYPE_POPUPS)); | 1802 CONTENT_SETTINGS_TYPE_POPUPS)); |
1759 } | 1803 } |
1760 | 1804 |
OLD | NEW |