Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map_unittest.cc

Issue 2816723002: Add "Site Settings" option to Clear Browsing Data on Android (Closed)
Patch Set: fix comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 EXPECT_EQ(1u, host_settings.size()); 1745 EXPECT_EQ(1u, host_settings.size());
1746 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1), 1746 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(url1),
1747 host_settings[0].primary_pattern); 1747 host_settings[0].primary_pattern);
1748 } 1748 }
1749 1749
1750 TEST_F(HostContentSettingsMapTest, ClearSettingsWithTimePredicate) { 1750 TEST_F(HostContentSettingsMapTest, ClearSettingsWithTimePredicate) {
1751 base::test::ScopedFeatureList feature_list; 1751 base::test::ScopedFeatureList feature_list;
1752 feature_list.InitAndEnableFeature(features::kTabsInCbd); 1752 feature_list.InitAndEnableFeature(features::kTabsInCbd);
1753 1753
1754 TestingProfile profile; 1754 TestingProfile profile;
1755 HostContentSettingsMap* host_content_settings_map = 1755 auto* map = HostContentSettingsMapFactory::GetForProfile(&profile);
1756 HostContentSettingsMapFactory::GetForProfile(&profile);
1757 ContentSettingsForOneType host_settings; 1756 ContentSettingsForOneType host_settings;
1758 1757
1759 GURL url1("https://www.google.com/"); 1758 GURL url1("https://www.google.com/");
1760 GURL url2("https://maps.google.com/"); 1759 GURL url2("https://maps.google.com/");
1761 1760
1762 // Add setting for url1. 1761 // Add setting for url1.
1763 host_content_settings_map->SetContentSettingDefaultScope( 1762 map->SetContentSettingDefaultScope(url1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS,
1764 url1, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), 1763 std::string(), CONTENT_SETTING_BLOCK);
1765 CONTENT_SETTING_BLOCK);
1766 1764
1767 // Make sure that the timestamp for url1 is different from |t|. 1765 // Make sure that the timestamp for url1 is different from |t|.
1768 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); 1766 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
1769 base::Time t = base::Time::Now(); 1767 base::Time t = base::Time::Now();
1770 1768
1771 // Add setting for url2. 1769 // Add setting for url2.
1772 host_content_settings_map->SetContentSettingDefaultScope( 1770 map->SetContentSettingDefaultScope(url2, GURL(), CONTENT_SETTINGS_TYPE_POPUPS,
1773 url2, GURL(), CONTENT_SETTINGS_TYPE_POPUPS, std::string(), 1771 std::string(), CONTENT_SETTING_BLOCK);
1774 CONTENT_SETTING_BLOCK);
1775 1772
1776 // Verify we have two pattern and the default. 1773 // Verify we have two pattern and the default.
1777 host_content_settings_map->GetSettingsForOneType( 1774 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, std::string(),
1778 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); 1775 &host_settings);
1779 EXPECT_EQ(3u, host_settings.size()); 1776 EXPECT_EQ(3u, host_settings.size());
1780 1777
1781 // Clear all settings since |t|. 1778 // Clear all settings since |t|.
1782 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( 1779 map->ClearSettingsForOneTypeWithPredicate(
1783 CONTENT_SETTINGS_TYPE_POPUPS, t, 1780 CONTENT_SETTINGS_TYPE_POPUPS, t,
1784 HostContentSettingsMap::PatternSourcePredicate()); 1781 HostContentSettingsMap::PatternSourcePredicate());
1785 1782
1786 // Verify we only have one pattern (url1) and the default. 1783 // Verify we only have one pattern (url1) and the default.
1787 host_content_settings_map->GetSettingsForOneType( 1784 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, std::string(),
1788 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); 1785 &host_settings);
1789 EXPECT_EQ(2u, host_settings.size()); 1786 EXPECT_EQ(2u, host_settings.size());
1790 EXPECT_EQ("https://www.google.com:443", 1787 EXPECT_EQ("https://www.google.com:443",
1791 host_settings[0].primary_pattern.ToString()); 1788 host_settings[0].primary_pattern.ToString());
1792 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString()); 1789 EXPECT_EQ("*", host_settings[1].primary_pattern.ToString());
1793 1790
1794 // Clear all settings since the beginning of time. 1791 // Clear all settings since the beginning of time.
1795 host_content_settings_map->ClearSettingsForOneTypeWithPredicate( 1792 map->ClearSettingsForOneTypeWithPredicate(
1796 CONTENT_SETTINGS_TYPE_POPUPS, base::Time(), 1793 CONTENT_SETTINGS_TYPE_POPUPS, base::Time(),
1797 HostContentSettingsMap::PatternSourcePredicate()); 1794 HostContentSettingsMap::PatternSourcePredicate());
1798 1795
1799 // Verify we only have the default setting. 1796 // Verify we only have the default setting.
1800 host_content_settings_map->GetSettingsForOneType( 1797 map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS, std::string(),
1801 CONTENT_SETTINGS_TYPE_POPUPS, std::string(), &host_settings); 1798 &host_settings);
1802 EXPECT_EQ(1u, host_settings.size()); 1799 EXPECT_EQ(1u, host_settings.size());
1803 EXPECT_EQ("*", host_settings[0].primary_pattern.ToString()); 1800 EXPECT_EQ("*", host_settings[0].primary_pattern.ToString());
1804 } 1801 }
1805 1802
1803 TEST_F(HostContentSettingsMapTest, GetSettingLastModified) {
1804 base::test::ScopedFeatureList feature_list;
1805 feature_list.InitAndEnableFeature(features::kTabsInCbd);
1806
1807 TestingProfile profile;
1808 auto* map = HostContentSettingsMapFactory::GetForProfile(&profile);
1809 ContentSettingsForOneType host_settings;
1810
1811 GURL url("https://www.google.com/");
1812 ContentSettingsPattern pattern =
1813 ContentSettingsPattern::FromURLNoWildcard(url);
1814
1815 {
1816 // Last modified date for non existant settings should be base::Time().
1817 base::Time t = map->GetSettingLastModifiedDate(
1818 pattern, ContentSettingsPattern::Wildcard(),
1819 CONTENT_SETTINGS_TYPE_POPUPS);
1820 EXPECT_EQ(base::Time(), t);
1821 }
1822
1823 base::Time t1 = base::Time::Now();
1824
1825 // Add setting for url.
1826 map->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS,
1827 std::string(), CONTENT_SETTING_BLOCK);
1828
1829 // Make sure that the timestamp for url is different from |t|.
1830 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout());
Bernhard Bauer 2017/05/03 14:29:21 Ugh, real-time timers. Can't we inject a timer for
dullweber 2017/05/03 15:59:13 I changed the PrefProvider to use a base::Clock. I
1831 base::Time t2 = base::Time::Now();
1832
1833 {
1834 // Last modified date for non existant settings should be base::Time().
1835 base::Time t = map->GetSettingLastModifiedDate(
1836 pattern, ContentSettingsPattern::Wildcard(),
1837 CONTENT_SETTINGS_TYPE_POPUPS);
1838 EXPECT_GE(t, t1);
1839 EXPECT_LT(t, t2);
1840 }
1841
1842 // Modify setting.
1843 map->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS,
1844 std::string(), CONTENT_SETTING_ALLOW);
1845
1846 {
1847 // Last modified date for non existant settings should be base::Time().
1848 base::Time t = map->GetSettingLastModifiedDate(
1849 pattern, ContentSettingsPattern::Wildcard(),
1850 CONTENT_SETTINGS_TYPE_POPUPS);
1851 EXPECT_GE(t, t2);
1852 }
1853 }
1854
1855 TEST_F(HostContentSettingsMapTest, LastModifiedIsNotRecordedWhenDisabled) {
1856 base::test::ScopedFeatureList feature_list;
1857 feature_list.InitAndDisableFeature(features::kTabsInCbd);
1858
1859 TestingProfile profile;
1860 auto* map = HostContentSettingsMapFactory::GetForProfile(&profile);
1861 ContentSettingsForOneType host_settings;
1862
1863 GURL url("https://www.google.com/");
1864 ContentSettingsPattern pattern =
1865 ContentSettingsPattern::FromURLNoWildcard(url);
1866
1867 // Add setting for url.
1868 map->SetContentSettingDefaultScope(url, GURL(), CONTENT_SETTINGS_TYPE_POPUPS,
1869 std::string(), CONTENT_SETTING_BLOCK);
1870
1871 base::Time t = map->GetSettingLastModifiedDate(
1872 pattern, ContentSettingsPattern::Wildcard(),
1873 CONTENT_SETTINGS_TYPE_POPUPS);
1874 EXPECT_EQ(base::Time(), t);
1875 }
1876
1806 TEST_F(HostContentSettingsMapTest, CanSetNarrowestSetting) { 1877 TEST_F(HostContentSettingsMapTest, CanSetNarrowestSetting) {
1807 TestingProfile profile; 1878 TestingProfile profile;
1808 const auto* map = HostContentSettingsMapFactory::GetForProfile(&profile); 1879 const auto* map = HostContentSettingsMapFactory::GetForProfile(&profile);
1809 1880
1810 GURL valid_url("http://google.com"); 1881 GURL valid_url("http://google.com");
1811 EXPECT_TRUE(map->CanSetNarrowestContentSetting( 1882 EXPECT_TRUE(map->CanSetNarrowestContentSetting(
1812 valid_url, valid_url, 1883 valid_url, valid_url,
1813 CONTENT_SETTINGS_TYPE_POPUPS)); 1884 CONTENT_SETTINGS_TYPE_POPUPS));
1814 1885
1815 GURL invalid_url("about:blank"); 1886 GURL invalid_url("about:blank");
1816 EXPECT_FALSE(map->CanSetNarrowestContentSetting( 1887 EXPECT_FALSE(map->CanSetNarrowestContentSetting(
1817 invalid_url, invalid_url, 1888 invalid_url, invalid_url,
1818 CONTENT_SETTINGS_TYPE_POPUPS)); 1889 CONTENT_SETTINGS_TYPE_POPUPS));
1819 } 1890 }
1820 1891
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698