| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/test/test_timeouts.h" | 14 #include "base/test/simple_test_clock.h" |
| 15 #include "base/threading/platform_thread.h" | |
| 16 #include "base/values.h" | 15 #include "base/values.h" |
| 17 #include "chrome/browser/content_settings/content_settings_mock_observer.h" | 16 #include "chrome/browser/content_settings/content_settings_mock_observer.h" |
| 18 #include "chrome/browser/prefs/browser_prefs.h" | 17 #include "chrome/browser/prefs/browser_prefs.h" |
| 19 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 22 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
| 23 #include "components/content_settings/core/browser/content_settings_pref.h" | 22 #include "components/content_settings/core/browser/content_settings_pref.h" |
| 24 #include "components/content_settings/core/browser/content_settings_registry.h" | 23 #include "components/content_settings/core/browser/content_settings_registry.h" |
| 25 #include "components/content_settings/core/browser/content_settings_rule.h" | 24 #include "components/content_settings/core/browser/content_settings_rule.h" |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 TEST_F(PrefProviderTest, LastModified) { | 612 TEST_F(PrefProviderTest, LastModified) { |
| 614 sync_preferences::TestingPrefServiceSyncable prefs; | 613 sync_preferences::TestingPrefServiceSyncable prefs; |
| 615 PrefProvider::RegisterProfilePrefs(prefs.registry()); | 614 PrefProvider::RegisterProfilePrefs(prefs.registry()); |
| 616 | 615 |
| 617 ContentSettingsPattern pattern_1 = | 616 ContentSettingsPattern pattern_1 = |
| 618 ContentSettingsPattern::FromString("google.com"); | 617 ContentSettingsPattern::FromString("google.com"); |
| 619 ContentSettingsPattern pattern_2 = | 618 ContentSettingsPattern pattern_2 = |
| 620 ContentSettingsPattern::FromString("www.google.com"); | 619 ContentSettingsPattern::FromString("www.google.com"); |
| 621 auto value = base::MakeUnique<base::Value>(CONTENT_SETTING_ALLOW); | 620 auto value = base::MakeUnique<base::Value>(CONTENT_SETTING_ALLOW); |
| 622 | 621 |
| 623 base::Time t1 = base::Time::Now(); | |
| 624 | |
| 625 // Create a provider and set a few settings. | 622 // Create a provider and set a few settings. |
| 626 PrefProvider provider(&prefs, false /* incognito */, | 623 PrefProvider provider(&prefs, false /* incognito */, |
| 627 true /* store_last_modified */); | 624 true /* store_last_modified */); |
| 625 auto test_clock = base::MakeUnique<base::SimpleTestClock>(); |
| 626 test_clock->SetNow(base::Time::Now()); |
| 627 base::SimpleTestClock* clock = test_clock.get(); |
| 628 provider.SetClockForTesting(std::move(test_clock)); |
| 629 |
| 630 base::Time t1 = clock->Now(); |
| 631 |
| 628 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(), | 632 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(), |
| 629 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 633 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 630 value->DeepCopy()); | 634 value->DeepCopy()); |
| 631 provider.SetWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(), | 635 provider.SetWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(), |
| 632 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 636 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 633 value->DeepCopy()); | 637 value->DeepCopy()); |
| 634 // Make sure that the timestamps for pattern_1 and patter_2 are before |t2|. | 638 // Make sure that the timestamps for pattern_1 and patter_2 are before |t2|. |
| 635 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); | 639 clock->Advance(base::TimeDelta::FromSeconds(1)); |
| 636 base::Time t2 = base::Time::Now(); | 640 base::Time t2 = clock->Now(); |
| 637 | 641 |
| 638 base::Time last_modified = provider.GetWebsiteSettingLastModified( | 642 base::Time last_modified = provider.GetWebsiteSettingLastModified( |
| 639 pattern_1, ContentSettingsPattern::Wildcard(), | 643 pattern_1, ContentSettingsPattern::Wildcard(), |
| 640 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | 644 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
| 641 EXPECT_GE(last_modified, t1); | 645 EXPECT_EQ(last_modified, t1); |
| 642 EXPECT_LT(last_modified, t2); | |
| 643 last_modified = provider.GetWebsiteSettingLastModified( | 646 last_modified = provider.GetWebsiteSettingLastModified( |
| 644 pattern_2, ContentSettingsPattern::Wildcard(), | 647 pattern_2, ContentSettingsPattern::Wildcard(), |
| 645 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | 648 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
| 646 EXPECT_GE(last_modified, t1); | 649 EXPECT_EQ(last_modified, t1); |
| 647 EXPECT_LT(last_modified, t2); | |
| 648 | 650 |
| 649 // A change for pattern_1, which will update the last_modified timestamp. | 651 // A change for pattern_1, which will update the last_modified timestamp. |
| 650 auto value2 = base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK); | 652 auto value2 = base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK); |
| 651 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(), | 653 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(), |
| 652 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), | 654 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), |
| 653 value2->DeepCopy()); | 655 value2->DeepCopy()); |
| 654 | 656 |
| 655 last_modified = provider.GetWebsiteSettingLastModified( | 657 last_modified = provider.GetWebsiteSettingLastModified( |
| 656 pattern_1, ContentSettingsPattern::Wildcard(), | 658 pattern_1, ContentSettingsPattern::Wildcard(), |
| 657 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | 659 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
| 658 EXPECT_GE(last_modified, t2); | 660 EXPECT_EQ(last_modified, t2); |
| 659 | 661 |
| 660 // The timestamp of pattern_2 shouldn't change. | 662 // The timestamp of pattern_2 shouldn't change. |
| 661 last_modified = provider.GetWebsiteSettingLastModified( | 663 last_modified = provider.GetWebsiteSettingLastModified( |
| 662 pattern_2, ContentSettingsPattern::Wildcard(), | 664 pattern_2, ContentSettingsPattern::Wildcard(), |
| 663 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); | 665 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); |
| 664 EXPECT_GE(last_modified, t1); | 666 EXPECT_EQ(last_modified, t1); |
| 665 EXPECT_LT(last_modified, t2); | |
| 666 | 667 |
| 667 provider.ShutdownOnUIThread(); | 668 provider.ShutdownOnUIThread(); |
| 668 } | 669 } |
| 669 | 670 |
| 670 } // namespace content_settings | 671 } // namespace content_settings |
| OLD | NEW |