OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/chrome_browsing_data_remover_delegate.h" | 5 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h" |
6 | 6 |
7 #include "base/guid.h" | 7 #include "base/guid.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 #include "components/password_manager/core/browser/password_manager_test_utils.h " | 56 #include "components/password_manager/core/browser/password_manager_test_utils.h " |
57 #include "components/password_manager/core/browser/password_store_consumer.h" | 57 #include "components/password_manager/core/browser/password_store_consumer.h" |
58 #include "components/prefs/testing_pref_service.h" | 58 #include "components/prefs/testing_pref_service.h" |
59 #include "components/translate/core/browser/language_model.h" | 59 #include "components/translate/core/browser/language_model.h" |
60 #include "content/public/browser/browsing_data_filter_builder.h" | 60 #include "content/public/browser/browsing_data_filter_builder.h" |
61 #include "content/public/test/mock_download_manager.h" | 61 #include "content/public/test/mock_download_manager.h" |
62 #include "content/public/test/test_browser_thread_bundle.h" | 62 #include "content/public/test/test_browser_thread_bundle.h" |
63 #include "content/public/test/test_utils.h" | 63 #include "content/public/test/test_utils.h" |
64 #include "net/cookies/cookie_store.h" | 64 #include "net/cookies/cookie_store.h" |
65 #include "net/http/http_transaction_factory.h" | 65 #include "net/http/http_transaction_factory.h" |
66 #include "net/reporting/reporting_browsing_data_remover.h" | |
67 #include "net/reporting/reporting_service.h" | |
66 #include "net/url_request/url_request_context.h" | 68 #include "net/url_request/url_request_context.h" |
67 #include "net/url_request/url_request_context_getter.h" | 69 #include "net/url_request/url_request_context_getter.h" |
68 #include "third_party/skia/include/core/SkBitmap.h" | 70 #include "third_party/skia/include/core/SkBitmap.h" |
69 #include "ui/gfx/favicon_size.h" | 71 #include "ui/gfx/favicon_size.h" |
70 | 72 |
71 #if defined(OS_ANDROID) | 73 #if defined(OS_ANDROID) |
72 #include "chrome/browser/android/webapps/webapp_registry.h" | 74 #include "chrome/browser/android/webapps/webapp_registry.h" |
73 #endif | 75 #endif |
74 | 76 |
75 #if defined(OS_CHROMEOS) | 77 #if defined(OS_CHROMEOS) |
(...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
833 | 835 |
834 private: | 836 private: |
835 void OnPersonalDataChanged() override { | 837 void OnPersonalDataChanged() override { |
836 base::MessageLoop::current()->QuitWhenIdle(); | 838 base::MessageLoop::current()->QuitWhenIdle(); |
837 } | 839 } |
838 | 840 |
839 autofill::PersonalDataManager* personal_data_manager_; | 841 autofill::PersonalDataManager* personal_data_manager_; |
840 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester); | 842 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester); |
841 }; | 843 }; |
842 | 844 |
845 class MockReportingService : public net::ReportingService { | |
846 public: | |
847 MockReportingService() {} | |
848 | |
849 // net::ReportingService implementation: | |
850 | |
851 ~MockReportingService() override {} | |
852 | |
853 void QueueReport(const GURL& url, | |
854 const std::string& group, | |
855 const std::string& type, | |
856 std::unique_ptr<const base::Value> body) override { | |
857 NOTREACHED(); | |
858 } | |
859 | |
860 void ProcessHeader(const GURL& url, | |
861 const std::string& header_value) override { | |
862 NOTREACHED(); | |
863 } | |
864 | |
865 void RemoveBrowsingData( | |
866 int data_type_mask, | |
867 base::Callback<bool(const GURL&)> origin_filter) override { | |
868 ++remove_calls_; | |
869 last_data_type_mask_ = data_type_mask; | |
870 last_origin_filter_ = origin_filter; | |
871 } | |
872 | |
873 int remove_calls() const { return remove_calls_; } | |
874 int last_data_type_mask() const { return last_data_type_mask_; } | |
875 base::Callback<bool(const GURL&)> last_origin_filter() const { | |
876 return last_origin_filter_; | |
877 } | |
878 | |
879 private: | |
880 int remove_calls_ = 0; | |
881 int last_data_type_mask_ = 0; | |
882 base::Callback<bool(const GURL&)> last_origin_filter_; | |
883 | |
884 DISALLOW_COPY_AND_ASSIGN(MockReportingService); | |
885 }; | |
886 | |
887 class ClearReportingCacheTester { | |
888 public: | |
889 ClearReportingCacheTester(TestingProfile* profile, bool create_service) | |
890 : profile_(profile) { | |
891 if (create_service) | |
892 service_ = base::MakeUnique<MockReportingService>(); | |
893 | |
894 base::RunLoop run_loop; | |
895 content::BrowserThread::PostTaskAndReply( | |
896 content::BrowserThread::IO, FROM_HERE, | |
Bernhard Bauer
2017/04/21 16:49:26
I'm not sure this thread jumping is necessary -- t
Julia Tuttle
2017/04/21 18:25:11
I'll remove it and add a DCHECK.
| |
897 base::Bind(&ClearReportingCacheTester::SetUpOnIOThread, | |
898 base::Unretained(this)), | |
899 run_loop.QuitClosure()); | |
900 run_loop.Run(); | |
901 } | |
902 | |
903 void SetUpOnIOThread() { | |
904 net::URLRequestContext* request_context = | |
905 profile_->GetRequestContext()->GetURLRequestContext(); | |
906 old_service_ = request_context->reporting_service(); | |
907 request_context->set_reporting_service(service_.get()); | |
908 } | |
909 | |
910 ~ClearReportingCacheTester() { | |
911 base::RunLoop run_loop; | |
912 content::BrowserThread::PostTaskAndReply( | |
913 content::BrowserThread::IO, FROM_HERE, | |
914 base::Bind(&ClearReportingCacheTester::TearDownOnIOThread, | |
915 base::Unretained(this)), | |
916 run_loop.QuitClosure()); | |
917 run_loop.Run(); | |
918 } | |
919 | |
920 void TearDownOnIOThread() { | |
921 net::URLRequestContext* request_context = | |
922 profile_->GetRequestContext()->GetURLRequestContext(); | |
923 DCHECK_EQ(service_.get(), request_context->reporting_service()); | |
924 request_context->set_reporting_service(old_service_); | |
925 } | |
926 | |
927 void GetMockInfo(int* remove_calls_out, | |
928 int* last_data_type_mask_out, | |
929 base::Callback<bool(const GURL&)>* last_origin_filter_out) { | |
930 DCHECK_NE(nullptr, service_.get()); | |
931 | |
932 base::RunLoop run_loop; | |
933 content::BrowserThread::PostTaskAndReply( | |
934 content::BrowserThread::IO, FROM_HERE, | |
935 base::Bind(&ClearReportingCacheTester::GetMockInfoOnIOThread, | |
936 base::Unretained(this), remove_calls_out, | |
937 last_data_type_mask_out, last_origin_filter_out), | |
938 run_loop.QuitClosure()); | |
939 run_loop.Run(); | |
940 } | |
941 | |
942 void GetMockInfoOnIOThread( | |
943 int* remove_calls_out, | |
944 int* last_data_type_mask_out, | |
945 base::Callback<bool(const GURL&)>* last_origin_filter_out) { | |
946 *remove_calls_out = service_->remove_calls(); | |
947 *last_data_type_mask_out = service_->last_data_type_mask(); | |
948 *last_origin_filter_out = service_->last_origin_filter(); | |
949 } | |
950 | |
951 private: | |
952 TestingProfile* profile_; | |
953 std::unique_ptr<MockReportingService> service_; | |
954 net::ReportingService* old_service_; | |
955 }; | |
956 | |
843 // Test Class ----------------------------------------------------------------- | 957 // Test Class ----------------------------------------------------------------- |
844 | 958 |
845 class ChromeBrowsingDataRemoverDelegateTest : public testing::Test { | 959 class ChromeBrowsingDataRemoverDelegateTest : public testing::Test { |
846 public: | 960 public: |
847 ChromeBrowsingDataRemoverDelegateTest() | 961 ChromeBrowsingDataRemoverDelegateTest() |
848 : profile_(new TestingProfile()), | 962 : profile_(new TestingProfile()), |
849 clear_domain_reliability_tester_(profile_.get()) { | 963 clear_domain_reliability_tester_(profile_.get()) { |
850 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()); | 964 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()); |
851 | 965 |
852 #if defined(OS_ANDROID) | 966 #if defined(OS_ANDROID) |
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1988 EXPECT_FALSE(Match(kOrigin1, kProtected, nullptr)); | 2102 EXPECT_FALSE(Match(kOrigin1, kProtected, nullptr)); |
1989 EXPECT_FALSE(Match(kOriginExt, kProtected, nullptr)); | 2103 EXPECT_FALSE(Match(kOriginExt, kProtected, nullptr)); |
1990 EXPECT_FALSE(Match(kOriginDevTools, kProtected, nullptr)); | 2104 EXPECT_FALSE(Match(kOriginDevTools, kProtected, nullptr)); |
1991 | 2105 |
1992 #if BUILDFLAG(ENABLE_EXTENSIONS) | 2106 #if BUILDFLAG(ENABLE_EXTENSIONS) |
1993 EXPECT_FALSE(Match(kOrigin1, kExtension, nullptr)); | 2107 EXPECT_FALSE(Match(kOrigin1, kExtension, nullptr)); |
1994 EXPECT_TRUE(Match(kOriginExt, kExtension, nullptr)); | 2108 EXPECT_TRUE(Match(kOriginExt, kExtension, nullptr)); |
1995 EXPECT_FALSE(Match(kOriginDevTools, kExtension, nullptr)); | 2109 EXPECT_FALSE(Match(kOriginDevTools, kExtension, nullptr)); |
1996 #endif | 2110 #endif |
1997 } | 2111 } |
2112 | |
2113 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ReportingCache_NoService) { | |
2114 ClearReportingCacheTester tester(GetProfile(), false); | |
2115 | |
2116 BlockUntilBrowsingDataRemoved( | |
2117 base::Time(), base::Time::Max(), | |
2118 BrowsingDataRemover::DATA_TYPE_COOKIES | | |
2119 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY, | |
2120 true); | |
2121 | |
2122 // Nothing to check, since there's no mock service; we're just making sure | |
2123 // nothing crashes without a service. | |
2124 } | |
2125 | |
2126 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ReportingCache_Cookies) { | |
2127 ClearReportingCacheTester tester(GetProfile(), true); | |
2128 | |
2129 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), | |
2130 BrowsingDataRemover::DATA_TYPE_COOKIES, true); | |
2131 | |
2132 int remove_count; | |
2133 int data_type_mask; | |
2134 base::Callback<bool(const GURL&)> origin_filter; | |
2135 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter); | |
2136 | |
2137 EXPECT_EQ(1, remove_count); | |
2138 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_CLIENTS, | |
2139 data_type_mask); | |
2140 EXPECT_TRUE(ProbablySameFilters(BrowsingDataFilterBuilder::BuildNoopFilter(), | |
2141 origin_filter)); | |
2142 } | |
2143 | |
2144 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
2145 ReportingCache_Cookies_WithFilter) { | |
2146 ClearReportingCacheTester tester(GetProfile(), true); | |
2147 | |
2148 std::unique_ptr<BrowsingDataFilterBuilder> builder( | |
2149 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | |
2150 builder->AddRegisterableDomain(kTestRegisterableDomain1); | |
2151 | |
2152 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), | |
2153 BrowsingDataRemover::DATA_TYPE_COOKIES, | |
2154 builder->Copy()); | |
2155 | |
2156 int remove_count; | |
2157 int data_type_mask; | |
2158 base::Callback<bool(const GURL&)> origin_filter; | |
2159 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter); | |
2160 | |
2161 EXPECT_EQ(1, remove_count); | |
2162 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_CLIENTS, | |
2163 data_type_mask); | |
2164 EXPECT_TRUE( | |
2165 ProbablySameFilters(builder->BuildGeneralFilter(), origin_filter)); | |
2166 } | |
2167 | |
2168 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ReportingCache_History) { | |
2169 ClearReportingCacheTester tester(GetProfile(), true); | |
2170 | |
2171 BlockUntilBrowsingDataRemoved( | |
2172 base::Time(), base::Time::Max(), | |
2173 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY, true); | |
2174 | |
2175 int remove_count; | |
2176 int data_type_mask; | |
2177 base::Callback<bool(const GURL&)> origin_filter; | |
2178 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter); | |
2179 | |
2180 EXPECT_EQ(1, remove_count); | |
2181 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_REPORTS, | |
2182 data_type_mask); | |
2183 EXPECT_TRUE(ProbablySameFilters(BrowsingDataFilterBuilder::BuildNoopFilter(), | |
2184 origin_filter)); | |
2185 } | |
2186 | |
2187 // Disabled because history is not iterable yet. | |
2188 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
2189 DISABLED_ReportingCache_History_WithFilter) { | |
2190 ClearReportingCacheTester tester(GetProfile(), true); | |
2191 | |
2192 std::unique_ptr<BrowsingDataFilterBuilder> builder( | |
2193 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | |
2194 builder->AddRegisterableDomain(kTestRegisterableDomain1); | |
2195 | |
2196 BlockUntilOriginDataRemoved( | |
2197 base::Time(), base::Time::Max(), | |
2198 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY, builder->Copy()); | |
2199 | |
2200 int remove_count; | |
2201 int data_type_mask; | |
2202 base::Callback<bool(const GURL&)> origin_filter; | |
2203 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter); | |
2204 | |
2205 EXPECT_EQ(1, remove_count); | |
2206 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_REPORTS, | |
2207 data_type_mask); | |
2208 EXPECT_TRUE( | |
2209 ProbablySameFilters(builder->BuildGeneralFilter(), origin_filter)); | |
2210 } | |
2211 | |
2212 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
2213 ReportingCache_CookiesAndHistory) { | |
2214 ClearReportingCacheTester tester(GetProfile(), true); | |
2215 | |
2216 BlockUntilBrowsingDataRemoved( | |
2217 base::Time(), base::Time::Max(), | |
2218 BrowsingDataRemover::DATA_TYPE_COOKIES | | |
2219 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY, | |
2220 true); | |
2221 | |
2222 int remove_count; | |
2223 int data_type_mask; | |
2224 base::Callback<bool(const GURL&)> origin_filter; | |
2225 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter); | |
2226 | |
2227 EXPECT_EQ(1, remove_count); | |
2228 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_REPORTS | | |
2229 net::ReportingBrowsingDataRemover::DATA_TYPE_CLIENTS, | |
2230 data_type_mask); | |
2231 EXPECT_TRUE(ProbablySameFilters(BrowsingDataFilterBuilder::BuildNoopFilter(), | |
2232 origin_filter)); | |
2233 } | |
2234 | |
2235 // Disabled because history is not iterable yet. | |
2236 TEST_F(ChromeBrowsingDataRemoverDelegateTest, | |
2237 DISABLED_ReportingCache_CookiesAndHistory_WithFilter) { | |
2238 ClearReportingCacheTester tester(GetProfile(), true); | |
2239 | |
2240 std::unique_ptr<BrowsingDataFilterBuilder> builder( | |
2241 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); | |
2242 builder->AddRegisterableDomain(kTestRegisterableDomain1); | |
2243 | |
2244 BlockUntilOriginDataRemoved( | |
2245 base::Time(), base::Time::Max(), | |
2246 BrowsingDataRemover::DATA_TYPE_COOKIES | | |
2247 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY, | |
2248 builder->Copy()); | |
2249 | |
2250 int remove_count; | |
2251 int data_type_mask; | |
2252 base::Callback<bool(const GURL&)> origin_filter; | |
2253 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter); | |
2254 | |
2255 EXPECT_EQ(1, remove_count); | |
2256 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_REPORTS | | |
2257 net::ReportingBrowsingDataRemover::DATA_TYPE_CLIENTS, | |
2258 data_type_mask); | |
2259 EXPECT_TRUE( | |
2260 ProbablySameFilters(builder->BuildGeneralFilter(), origin_filter)); | |
2261 } | |
OLD | NEW |