Chromium Code Reviews| 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 "components/content_settings/core/browser/content_settings_pref_provide r.h" | 5 #include "components/content_settings/core/browser/content_settings_pref_provide r.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 589 | 589 |
| 590 for (const char* pref : nonempty_prefs) { | 590 for (const char* pref : nonempty_prefs) { |
| 591 DictionaryPrefUpdate update(&prefs, pref); | 591 DictionaryPrefUpdate update(&prefs, pref); |
| 592 const base::DictionaryValue* dictionary = update.Get(); | 592 const base::DictionaryValue* dictionary = update.Get(); |
| 593 EXPECT_EQ(1u, dictionary->size()); | 593 EXPECT_EQ(1u, dictionary->size()); |
| 594 } | 594 } |
| 595 | 595 |
| 596 provider.ShutdownOnUIThread(); | 596 provider.ShutdownOnUIThread(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 TEST_F(PrefProviderTest, LastModified) { | |
| 600 sync_preferences::TestingPrefServiceSyncable prefs; | |
| 601 PrefProvider::RegisterProfilePrefs(prefs.registry()); | |
| 602 | |
| 603 ContentSettingsPattern pattern_1 = | |
| 604 ContentSettingsPattern::FromString("google.com"); | |
| 605 ContentSettingsPattern pattern_2 = | |
| 606 ContentSettingsPattern::FromString("www.google.com"); | |
| 607 std::unique_ptr<base::Value> value(new base::Value(CONTENT_SETTING_ALLOW)); | |
| 608 | |
| 609 base::Time t1 = base::Time::Now(); | |
|
msramek
2017/04/19 10:49:15
optional: This might be a good place for SimpleTes
dullweber
2017/04/19 15:02:45
Thanks for pointing at this, it will probably be u
| |
| 610 // Create a provider and set a setting. | |
| 611 PrefProvider provider(&prefs, false, /*store_last_modified=*/true); | |
| 612 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(), | |
| 613 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | |
| 614 value->DeepCopy()); | |
| 615 provider.SetWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(), | |
| 616 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | |
| 617 value->DeepCopy()); | |
| 618 base::Time t2 = base::Time::Now(); | |
| 619 | |
| 620 { | |
| 621 std::unique_ptr<RuleIterator> it(provider.GetRuleIterator( | |
| 622 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); | |
| 623 EXPECT_TRUE(it->HasNext()); | |
| 624 Rule rule = it->Next(); | |
| 625 EXPECT_EQ(pattern_1, rule.primary_pattern); | |
| 626 EXPECT_LT(t1, rule.last_modified); | |
| 627 EXPECT_GT(t2, rule.last_modified); | |
| 628 | |
| 629 EXPECT_TRUE(it->HasNext()); | |
| 630 rule = it->Next(); | |
| 631 EXPECT_EQ(pattern_2, rule.primary_pattern); | |
| 632 EXPECT_LT(t1, rule.last_modified); | |
| 633 EXPECT_GT(t2, rule.last_modified); | |
| 634 | |
| 635 EXPECT_FALSE(it->HasNext()); | |
| 636 } | |
| 637 | |
| 638 // Update pattern_1 and check that the timestamp changes. | |
| 639 std::unique_ptr<base::Value> value2(new base::Value(CONTENT_SETTING_BLOCK)); | |
| 640 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(), | |
| 641 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | |
| 642 value2->DeepCopy()); | |
| 643 base::Time t3 = base::Time::Now(); | |
| 644 | |
| 645 { | |
| 646 std::unique_ptr<RuleIterator> it(provider.GetRuleIterator( | |
| 647 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), false)); | |
| 648 EXPECT_TRUE(it->HasNext()); | |
| 649 Rule rule = it->Next(); | |
| 650 EXPECT_EQ(pattern_1, rule.primary_pattern); | |
| 651 EXPECT_LT(t2, rule.last_modified); | |
| 652 EXPECT_GT(t3, rule.last_modified); | |
| 653 | |
| 654 EXPECT_TRUE(it->HasNext()); | |
| 655 rule = it->Next(); | |
| 656 EXPECT_EQ(pattern_2, rule.primary_pattern); | |
| 657 EXPECT_LT(t1, rule.last_modified); | |
| 658 EXPECT_GT(t2, rule.last_modified); | |
| 659 | |
| 660 EXPECT_FALSE(it->HasNext()); | |
| 661 } | |
| 662 | |
| 663 provider.ShutdownOnUIThread(); | |
| 664 } | |
| 665 | |
| 599 } // namespace content_settings | 666 } // namespace content_settings |
| OLD | NEW |