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

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

Issue 2816723002: Add "Site Settings" option to Clear Browsing Data on Android (Closed)
Patch Set: inject Clock into HostContentSettingsMap for testing 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 "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
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* clock = new base::SimpleTestClock();
Bernhard Bauer 2017/05/03 16:05:39 Could you create this in a std::unique_ptr with ba
dullweber 2017/05/03 16:23:00 Done.
626 clock->SetNow(base::Time::Now());
627 provider.SetClockForTesting(base::WrapUnique(clock));
628
629 base::Time t1 = clock->Now();
630
628 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(), 631 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
629 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 632 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
630 value->DeepCopy()); 633 value->DeepCopy());
631 provider.SetWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(), 634 provider.SetWebsiteSetting(pattern_2, ContentSettingsPattern::Wildcard(),
632 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 635 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
633 value->DeepCopy()); 636 value->DeepCopy());
634 // Make sure that the timestamps for pattern_1 and patter_2 are before |t2|. 637 // Make sure that the timestamps for pattern_1 and patter_2 are before |t2|.
635 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout()); 638 clock->Advance(base::TimeDelta::FromSeconds(1));
636 base::Time t2 = base::Time::Now(); 639 base::Time t2 = clock->Now();
637 640
638 base::Time last_modified = provider.GetWebsiteSettingLastModified( 641 base::Time last_modified = provider.GetWebsiteSettingLastModified(
639 pattern_1, ContentSettingsPattern::Wildcard(), 642 pattern_1, ContentSettingsPattern::Wildcard(),
640 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 643 CONTENT_SETTINGS_TYPE_COOKIES, std::string());
641 EXPECT_GE(last_modified, t1); 644 EXPECT_EQ(last_modified, t1);
642 EXPECT_LT(last_modified, t2);
643 last_modified = provider.GetWebsiteSettingLastModified( 645 last_modified = provider.GetWebsiteSettingLastModified(
644 pattern_2, ContentSettingsPattern::Wildcard(), 646 pattern_2, ContentSettingsPattern::Wildcard(),
645 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 647 CONTENT_SETTINGS_TYPE_COOKIES, std::string());
646 EXPECT_GE(last_modified, t1); 648 EXPECT_EQ(last_modified, t1);
647 EXPECT_LT(last_modified, t2);
648 649
649 // A change for pattern_1, which will update the last_modified timestamp. 650 // A change for pattern_1, which will update the last_modified timestamp.
650 auto value2 = base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK); 651 auto value2 = base::MakeUnique<base::Value>(CONTENT_SETTING_BLOCK);
651 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(), 652 provider.SetWebsiteSetting(pattern_1, ContentSettingsPattern::Wildcard(),
652 CONTENT_SETTINGS_TYPE_COOKIES, std::string(), 653 CONTENT_SETTINGS_TYPE_COOKIES, std::string(),
653 value2->DeepCopy()); 654 value2->DeepCopy());
654 655
655 last_modified = provider.GetWebsiteSettingLastModified( 656 last_modified = provider.GetWebsiteSettingLastModified(
656 pattern_1, ContentSettingsPattern::Wildcard(), 657 pattern_1, ContentSettingsPattern::Wildcard(),
657 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 658 CONTENT_SETTINGS_TYPE_COOKIES, std::string());
658 EXPECT_GE(last_modified, t2); 659 EXPECT_EQ(last_modified, t2);
659 660
660 // The timestamp of pattern_2 shouldn't change. 661 // The timestamp of pattern_2 shouldn't change.
661 last_modified = provider.GetWebsiteSettingLastModified( 662 last_modified = provider.GetWebsiteSettingLastModified(
662 pattern_2, ContentSettingsPattern::Wildcard(), 663 pattern_2, ContentSettingsPattern::Wildcard(),
663 CONTENT_SETTINGS_TYPE_COOKIES, std::string()); 664 CONTENT_SETTINGS_TYPE_COOKIES, std::string());
664 EXPECT_GE(last_modified, t1); 665 EXPECT_EQ(last_modified, t1);
665 EXPECT_LT(last_modified, t2);
666 666
667 provider.ShutdownOnUIThread(); 667 provider.ShutdownOnUIThread();
668 } 668 }
669 669
670 } // namespace content_settings 670 } // namespace content_settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698