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

Unified Diff: chrome/browser/content_settings/content_settings_pref_provider_unittest.cc

Issue 2812113004: Write last_modified date to Content Settings in the PrefProvider (Closed)
Patch Set: fix comments Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
diff --git a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
index a59763fa7bc83107b88ab7ddd24bd217f7ed07a7..b91c7535e088671125abaaf5b288ef05da2bd995 100644
--- a/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
+++ b/chrome/browser/content_settings/content_settings_pref_provider_unittest.cc
@@ -114,7 +114,7 @@ class PrefProviderTest : public testing::Test {
TEST_F(PrefProviderTest, Observer) {
TestingProfile profile;
- PrefProvider pref_content_settings_provider(profile.GetPrefs(), false);
+ PrefProvider pref_content_settings_provider(profile.GetPrefs(), false, true);
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
@@ -162,7 +162,7 @@ TEST_F(PrefProviderTest, DiscardObsoleteFullscreenAndMouselockPreferences) {
// Instantiate a new PrefProvider here, because we want to test the
// constructor's behavior after setting the above.
- PrefProvider provider(prefs, false);
+ PrefProvider provider(prefs, false, true);
provider.ShutdownOnUIThread();
// Check that fullscreen and mouselock have been deleted.
@@ -220,7 +220,7 @@ TEST_F(PrefProviderTest, DiscardObsoleteLastUsagePreferences) {
// Instantiate a new PrefProvider here, because we want to test the
// constructor's behavior after setting the above.
- PrefProvider provider(prefs, false);
+ PrefProvider provider(prefs, false, true);
// Check that last_used data has been deleted.
EXPECT_TRUE(prefs->GetDictionary(kGeolocationPrefPath)->empty());
@@ -273,8 +273,8 @@ TEST_F(PrefProviderTest, Incognito) {
otr_profile_builder.SetPrefService(base::WrapUnique(otr_prefs));
otr_profile_builder.BuildIncognito(profile.get());
- PrefProvider pref_content_settings_provider(regular_prefs, false);
- PrefProvider pref_content_settings_provider_incognito(otr_prefs, true);
+ PrefProvider pref_content_settings_provider(regular_prefs, false, true);
+ PrefProvider pref_content_settings_provider_incognito(otr_prefs, true, true);
ContentSettingsPattern pattern =
ContentSettingsPattern::FromString("[*.]example.com");
pref_content_settings_provider.SetWebsiteSetting(
@@ -303,7 +303,7 @@ TEST_F(PrefProviderTest, Incognito) {
TEST_F(PrefProviderTest, GetContentSettingsValue) {
TestingProfile testing_profile;
- PrefProvider provider(testing_profile.GetPrefs(), false);
+ PrefProvider provider(testing_profile.GetPrefs(), false, true);
GURL primary_url("http://example.com/");
ContentSettingsPattern primary_pattern =
@@ -343,8 +343,8 @@ TEST_F(PrefProviderTest, GetContentSettingsValue) {
TEST_F(PrefProviderTest, Patterns) {
TestingProfile testing_profile;
- PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
- false);
+ PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), false,
+ true);
GURL host1("http://example.com/");
GURL host2("http://www.example.com/");
@@ -403,8 +403,8 @@ TEST_F(PrefProviderTest, Patterns) {
#if BUILDFLAG(ENABLE_PLUGINS)
TEST_F(PrefProviderTest, ResourceIdentifier) {
TestingProfile testing_profile;
- PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(),
- false);
+ PrefProvider pref_content_settings_provider(testing_profile.GetPrefs(), false,
+ true);
GURL host("http://example.com/");
ContentSettingsPattern pattern =
@@ -444,7 +444,7 @@ TEST_F(PrefProviderTest, Deadlock) {
const WebsiteSettingsInfo* info = WebsiteSettingsRegistry::GetInstance()->Get(
CONTENT_SETTINGS_TYPE_COOKIES);
- PrefProvider provider(&prefs, false);
+ PrefProvider provider(&prefs, false, true);
DeadlockCheckerObserver observer(&prefs, &provider);
{
DictionaryPrefUpdate update(&prefs, info->pref_name());
@@ -470,7 +470,7 @@ TEST_F(PrefProviderTest, IncognitoInheritsValueMap) {
std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
// Create a normal provider and set a setting.
- PrefProvider normal_provider(&prefs, false);
+ PrefProvider normal_provider(&prefs, false, true);
normal_provider.SetWebsiteSetting(pattern_1, wildcard,
CONTENT_SETTINGS_TYPE_COOKIES,
std::string(), value->DeepCopy());
@@ -492,7 +492,7 @@ TEST_F(PrefProviderTest, IncognitoInheritsValueMap) {
}
// Create an incognito provider and set a setting.
- PrefProvider incognito_provider(&prefs, true);
+ PrefProvider incognito_provider(&prefs, true, true);
incognito_provider.SetWebsiteSetting(pattern_2, wildcard,
CONTENT_SETTINGS_TYPE_COOKIES,
std::string(), value->DeepCopy());
@@ -530,7 +530,7 @@ TEST_F(PrefProviderTest, ClearAllContentSettingsRules) {
std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
ResourceIdentifier res_id("abcde");
- PrefProvider provider(&prefs, false);
+ PrefProvider provider(&prefs, false, true);
// Non-empty pattern, syncable, empty resource identifier.
provider.SetWebsiteSetting(pattern, wildcard,
@@ -596,4 +596,71 @@ TEST_F(PrefProviderTest, ClearAllContentSettingsRules) {
provider.ShutdownOnUIThread();
}
+TEST_F(PrefProviderTest, LastModified) {
+ sync_preferences::TestingPrefServiceSyncable prefs;
+ PrefProvider::RegisterProfilePrefs(prefs.registry());
+
+ ContentSettingsPattern pattern_1 =
+ ContentSettingsPattern::FromString("google.com");
+ ContentSettingsPattern pattern_2 =
+ ContentSettingsPattern::FromString("www.google.com");
+ std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW));
+
+ base::Time t1 = base::Time::Now();
+ // Create a provider and set a setting.
+ PrefProvider provider(&prefs, false, /*store_last_modified=*/true);
+ provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
+ value->DeepCopy());
+ provider.SetWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
+ value->DeepCopy());
+ base::Time t2 = base::Time::Now();
+
+ {
+ std::unique_ptr<RuleIterator> it(provider.GetRuleIterator(
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
+ EXPECT_TRUE(it->HasNext());
+ Rule rule = it->Next();
+ EXPECT_EQ(pattern_1, rule.primary_pattern);
+ EXPECT_LT(t1, rule.last_modified);
+ EXPECT_GT(t2, rule.last_modified);
+
+ EXPECT_TRUE(it->HasNext());
+ rule = it->Next();
+ EXPECT_EQ(pattern_2, rule.primary_pattern);
+ EXPECT_LT(t1, rule.last_modified);
+ EXPECT_GT(t2, rule.last_modified);
+
+ EXPECT_FALSE(it->HasNext());
+ }
+
+ // Update pattern_1 and check that the timestamp changes.
+ std::unique_ptr<base::Value> value2(new base::Value(CONTENT_SETTING_BLOCK));
+ provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
+ value2->DeepCopy());
+ base::Time t3 = base::Time::Now();
+
+ {
+ std::unique_ptr<RuleIterator> it(provider.GetRuleIterator(
+ CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false));
+ EXPECT_TRUE(it->HasNext());
+ Rule rule = it->Next();
+ EXPECT_EQ(pattern_1, rule.primary_pattern);
+ EXPECT_LT(t2, rule.last_modified);
+ EXPECT_GT(t3, rule.last_modified);
+
+ EXPECT_TRUE(it->HasNext());
+ rule = it->Next();
+ EXPECT_EQ(pattern_2, rule.primary_pattern);
+ EXPECT_LT(t1, rule.last_modified);
+ EXPECT_GT(t2, rule.last_modified);
+
+ EXPECT_FALSE(it->HasNext());
+ }
+
+ provider.ShutdownOnUIThread();
+}
+
} // namespace content_settings

Powered by Google App Engine
This is Rietveld 408576698