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 "chrome/browser/browsing_data/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 } | 660 } |
661 | 661 |
662 class ClearDomainReliabilityTester { | 662 class ClearDomainReliabilityTester { |
663 public: | 663 public: |
664 explicit ClearDomainReliabilityTester(TestingProfile* profile) : | 664 explicit ClearDomainReliabilityTester(TestingProfile* profile) : |
665 profile_(profile), | 665 profile_(profile), |
666 mock_service_(new MockDomainReliabilityService()) { | 666 mock_service_(new MockDomainReliabilityService()) { |
667 AttachService(); | 667 AttachService(); |
668 } | 668 } |
669 | 669 |
670 unsigned clear_count() { return mock_service_->clear_count(); } | 670 unsigned clear_count() const { return mock_service_->clear_count(); } |
671 | 671 |
672 DomainReliabilityClearMode last_clear_mode() { | 672 DomainReliabilityClearMode last_clear_mode() const { |
673 return mock_service_->last_clear_mode(); | 673 return mock_service_->last_clear_mode(); |
674 } | 674 } |
675 | 675 |
676 private: | 676 private: |
677 void AttachService() { | 677 void AttachService() { |
678 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey; | 678 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey; |
679 | 679 |
680 // Attach kludgey UserData struct to profile. | 680 // Attach kludgey UserData struct to profile. |
681 TestingDomainReliabilityServiceFactoryUserData* data = | 681 TestingDomainReliabilityServiceFactoryUserData* data = |
682 new TestingDomainReliabilityServiceFactoryUserData(profile_, | 682 new TestingDomainReliabilityServiceFactoryUserData(profile_, |
(...skipping 13 matching lines...) Expand all Loading... | |
696 } | 696 } |
697 | 697 |
698 TestingProfile* profile_; | 698 TestingProfile* profile_; |
699 MockDomainReliabilityService* mock_service_; | 699 MockDomainReliabilityService* mock_service_; |
700 }; | 700 }; |
701 | 701 |
702 // Test Class ---------------------------------------------------------------- | 702 // Test Class ---------------------------------------------------------------- |
703 | 703 |
704 class BrowsingDataRemoverTest : public testing::Test { | 704 class BrowsingDataRemoverTest : public testing::Test { |
705 public: | 705 public: |
706 BrowsingDataRemoverTest() : profile_(new TestingProfile()) { | 706 BrowsingDataRemoverTest() |
707 : profile_(new TestingProfile()), | |
708 clear_domain_reliability_tester_(GetProfile()) { | |
707 callback_subscription_ = | 709 callback_subscription_ = |
708 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( | 710 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback( |
709 base::Bind(&BrowsingDataRemoverTest::NotifyWithDetails, | 711 base::Bind(&BrowsingDataRemoverTest::NotifyWithDetails, |
710 base::Unretained(this))); | 712 base::Unretained(this))); |
711 } | 713 } |
712 | 714 |
713 ~BrowsingDataRemoverTest() override {} | 715 ~BrowsingDataRemoverTest() override {} |
714 | 716 |
715 void TearDown() override { | 717 void TearDown() override { |
716 #if defined(ENABLE_EXTENSIONS) | 718 #if defined(ENABLE_EXTENSIONS) |
717 mock_policy_ = NULL; | 719 mock_policy_ = NULL; |
718 #endif | 720 #endif |
719 | 721 |
720 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor | 722 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor |
721 // posts a message to the WEBKIT thread to delete some of its member | 723 // posts a message to the WEBKIT thread to delete some of its member |
722 // variables. We need to ensure that the profile is destroyed, and that | 724 // variables. We need to ensure that the profile is destroyed, and that |
723 // the message loop is cleared out, before destroying the threads and loop. | 725 // the message loop is cleared out, before destroying the threads and loop. |
724 // Otherwise we leak memory. | 726 // Otherwise we leak memory. |
725 profile_.reset(); | 727 profile_.reset(); |
726 base::MessageLoop::current()->RunUntilIdle(); | 728 base::MessageLoop::current()->RunUntilIdle(); |
729 | |
730 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | |
727 } | 731 } |
728 | 732 |
729 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, | 733 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, |
730 int remove_mask, | 734 int remove_mask, |
731 bool include_protected_origins) { | 735 bool include_protected_origins) { |
732 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod( | 736 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod( |
733 profile_.get(), period); | 737 profile_.get(), period); |
734 | 738 |
735 TestStoragePartition storage_partition; | 739 TestStoragePartition storage_partition; |
736 remover->OverrideStoragePartitionForTesting(&storage_partition); | 740 remover->OverrideStoragePartitionForTesting(&storage_partition); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
824 // If |kOrigin1| is protected when extensions are enabled, the expected | 828 // If |kOrigin1| is protected when extensions are enabled, the expected |
825 // result for tests where the OriginMatcherFunction result is variable. | 829 // result for tests where the OriginMatcherFunction result is variable. |
826 bool ShouldRemoveForProtectedOriginOne() const { | 830 bool ShouldRemoveForProtectedOriginOne() const { |
827 #if defined(ENABLE_EXTENSIONS) | 831 #if defined(ENABLE_EXTENSIONS) |
828 return false; | 832 return false; |
829 #else | 833 #else |
830 return true; | 834 return true; |
831 #endif | 835 #endif |
832 } | 836 } |
833 | 837 |
838 const ClearDomainReliabilityTester& clear_domain_reliability_tester() { | |
839 return clear_domain_reliability_tester_; | |
840 } | |
841 | |
834 protected: | 842 protected: |
835 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; | 843 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; |
836 | 844 |
837 private: | 845 private: |
838 content::TestBrowserThreadBundle thread_bundle_; | 846 content::TestBrowserThreadBundle thread_bundle_; |
839 scoped_ptr<TestingProfile> profile_; | 847 scoped_ptr<TestingProfile> profile_; |
840 | 848 |
841 StoragePartitionRemovalData storage_partition_removal_data_; | 849 StoragePartitionRemovalData storage_partition_removal_data_; |
842 | 850 |
843 #if defined(ENABLE_EXTENSIONS) | 851 #if defined(ENABLE_EXTENSIONS) |
844 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_; | 852 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_; |
845 #endif | 853 #endif |
846 | 854 |
847 BrowsingDataRemover::CallbackSubscription callback_subscription_; | 855 BrowsingDataRemover::CallbackSubscription callback_subscription_; |
848 | 856 |
857 // Needed to mock out DomainReliabilityService, even for unrelated tests. | |
858 ClearDomainReliabilityTester clear_domain_reliability_tester_; | |
859 | |
849 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); | 860 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); |
850 }; | 861 }; |
851 | 862 |
852 // Tests --------------------------------------------------------------------- | 863 // Tests --------------------------------------------------------------------- |
853 | 864 |
854 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { | 865 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { |
855 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 866 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
856 BrowsingDataRemover::REMOVE_COOKIES, | 867 BrowsingDataRemover::REMOVE_COOKIES, |
857 false); | 868 false); |
858 | 869 |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1765 | 1776 |
1766 BlockUntilBrowsingDataRemoved( | 1777 BlockUntilBrowsingDataRemoved( |
1767 BrowsingDataRemover::EVERYTHING, | 1778 BrowsingDataRemover::EVERYTHING, |
1768 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false); | 1779 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false); |
1769 | 1780 |
1770 chromeos::DBusThreadManager::Shutdown(); | 1781 chromeos::DBusThreadManager::Shutdown(); |
1771 } | 1782 } |
1772 #endif | 1783 #endif |
1773 | 1784 |
1774 TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) { | 1785 TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) { |
1775 ClearDomainReliabilityTester tester(GetProfile()); | 1786 const ClearDomainReliabilityTester& tester = |
1787 clear_domain_reliability_tester(); | |
1776 | 1788 |
1777 EXPECT_EQ(0u, tester.clear_count()); | 1789 EXPECT_EQ(0u, tester.clear_count()); |
1778 } | 1790 } |
1779 | 1791 |
1780 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) { | 1792 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) { |
1781 ClearDomainReliabilityTester tester(GetProfile()); | 1793 const ClearDomainReliabilityTester& tester = |
1794 clear_domain_reliability_tester(); | |
1782 | 1795 |
1783 BlockUntilBrowsingDataRemoved( | 1796 BlockUntilBrowsingDataRemoved( |
1784 BrowsingDataRemover::EVERYTHING, | 1797 BrowsingDataRemover::EVERYTHING, |
1785 BrowsingDataRemover::REMOVE_HISTORY, false); | 1798 BrowsingDataRemover::REMOVE_HISTORY, false); |
1786 EXPECT_EQ(1u, tester.clear_count()); | 1799 EXPECT_EQ(1u, tester.clear_count()); |
1787 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode()); | 1800 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode()); |
1788 } | 1801 } |
1789 | 1802 |
1790 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) { | 1803 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) { |
1791 ClearDomainReliabilityTester tester(GetProfile()); | 1804 const ClearDomainReliabilityTester& tester = |
1805 clear_domain_reliability_tester(); | |
1792 | 1806 |
1793 BlockUntilBrowsingDataRemoved( | 1807 BlockUntilBrowsingDataRemoved( |
1794 BrowsingDataRemover::EVERYTHING, | 1808 BrowsingDataRemover::EVERYTHING, |
1795 BrowsingDataRemover::REMOVE_COOKIES, false); | 1809 BrowsingDataRemover::REMOVE_COOKIES, false); |
1796 EXPECT_EQ(1u, tester.clear_count()); | 1810 EXPECT_EQ(1u, tester.clear_count()); |
1797 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | 1811 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
1798 } | 1812 } |
1799 | 1813 |
1800 TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) { | 1814 TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) { |
1801 ClearDomainReliabilityTester tester(GetProfile()); | 1815 const ClearDomainReliabilityTester& tester = |
1816 clear_domain_reliability_tester(); | |
1802 | 1817 |
1803 BlockUntilBrowsingDataRemoved( | 1818 BlockUntilBrowsingDataRemoved( |
1804 BrowsingDataRemover::EVERYTHING, | 1819 BrowsingDataRemover::EVERYTHING, |
1805 BrowsingDataRemover::REMOVE_HISTORY | | 1820 BrowsingDataRemover::REMOVE_HISTORY | |
1806 BrowsingDataRemover::REMOVE_COOKIES, false); | 1821 BrowsingDataRemover::REMOVE_COOKIES, false); |
1807 EXPECT_EQ(1u, tester.clear_count()); | 1822 EXPECT_EQ(1u, tester.clear_count()); |
1808 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | 1823 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
1809 } | 1824 } |
1810 | 1825 |
1811 TEST_F(BrowsingDataRemoverTest, DomainReliability_ProtectedOrigins) { | 1826 TEST_F(BrowsingDataRemoverTest, DomainReliability_ProtectedOrigins) { |
1812 ClearDomainReliabilityTester tester(GetProfile()); | 1827 const ClearDomainReliabilityTester& tester = |
1828 clear_domain_reliability_tester(); | |
1813 | 1829 |
1814 BlockUntilBrowsingDataRemoved( | 1830 BlockUntilBrowsingDataRemoved( |
1815 BrowsingDataRemover::EVERYTHING, | 1831 BrowsingDataRemover::EVERYTHING, |
1816 BrowsingDataRemover::REMOVE_COOKIES, true); | 1832 BrowsingDataRemover::REMOVE_COOKIES, true); |
1817 EXPECT_EQ(1u, tester.clear_count()); | 1833 EXPECT_EQ(1u, tester.clear_count()); |
1818 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); | 1834 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode()); |
1819 } | 1835 } |
1820 | 1836 |
1821 TEST_F(BrowsingDataRemoverTest, DomainReliability_NoMonitor) { | 1837 // TODO(ttuttle): This isn't actually testing the no-monitor case, since |
Bernhard Bauer
2015/02/09 18:19:04
So, what's the TODO here?
Deprecated (see juliatuttle)
2015/02/09 18:35:11
Done.
| |
1838 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed | |
1839 // for some unrelated test cases. | |
1840 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { | |
1822 BlockUntilBrowsingDataRemoved( | 1841 BlockUntilBrowsingDataRemoved( |
1823 BrowsingDataRemover::EVERYTHING, | 1842 BrowsingDataRemover::EVERYTHING, |
1824 BrowsingDataRemover::REMOVE_HISTORY | | 1843 BrowsingDataRemover::REMOVE_HISTORY | |
1825 BrowsingDataRemover::REMOVE_COOKIES, false); | 1844 BrowsingDataRemover::REMOVE_COOKIES, false); |
1826 } | 1845 } |
OLD | NEW |