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

Side by Side Diff: chrome/browser/browsing_data/chrome_browsing_data_remover_delegate_unittest.cc

Issue 2829683004: Reporting: Plumb from //chrome/browser/browsing_data. (Closed)
Patch Set: Fix. 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 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/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 #include "components/prefs/testing_pref_service.h" 55 #include "components/prefs/testing_pref_service.h"
56 #include "components/translate/core/browser/language_model.h" 56 #include "components/translate/core/browser/language_model.h"
57 #include "content/public/browser/browsing_data_filter_builder.h" 57 #include "content/public/browser/browsing_data_filter_builder.h"
58 #include "content/public/browser/browsing_data_remover.h" 58 #include "content/public/browser/browsing_data_remover.h"
59 #include "content/public/test/browsing_data_remover_test_util.h" 59 #include "content/public/test/browsing_data_remover_test_util.h"
60 #include "content/public/test/mock_download_manager.h" 60 #include "content/public/test/mock_download_manager.h"
61 #include "content/public/test/test_browser_thread_bundle.h" 61 #include "content/public/test/test_browser_thread_bundle.h"
62 #include "content/public/test/test_utils.h" 62 #include "content/public/test/test_utils.h"
63 #include "net/cookies/cookie_store.h" 63 #include "net/cookies/cookie_store.h"
64 #include "net/http/http_transaction_factory.h" 64 #include "net/http/http_transaction_factory.h"
65 #include "net/reporting/reporting_browsing_data_remover.h"
66 #include "net/reporting/reporting_service.h"
65 #include "net/url_request/url_request_context.h" 67 #include "net/url_request/url_request_context.h"
66 #include "net/url_request/url_request_context_getter.h" 68 #include "net/url_request/url_request_context_getter.h"
67 #include "third_party/skia/include/core/SkBitmap.h" 69 #include "third_party/skia/include/core/SkBitmap.h"
68 #include "ui/gfx/favicon_size.h" 70 #include "ui/gfx/favicon_size.h"
69 71
70 #if defined(OS_ANDROID) 72 #if defined(OS_ANDROID)
71 #include "chrome/browser/android/webapps/webapp_registry.h" 73 #include "chrome/browser/android/webapps/webapp_registry.h"
72 #endif 74 #endif
73 75
74 #if defined(OS_CHROMEOS) 76 #if defined(OS_CHROMEOS)
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 850
849 private: 851 private:
850 void OnPersonalDataChanged() override { 852 void OnPersonalDataChanged() override {
851 base::MessageLoop::current()->QuitWhenIdle(); 853 base::MessageLoop::current()->QuitWhenIdle();
852 } 854 }
853 855
854 autofill::PersonalDataManager* personal_data_manager_; 856 autofill::PersonalDataManager* personal_data_manager_;
855 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester); 857 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
856 }; 858 };
857 859
860 class MockReportingService : public net::ReportingService {
861 public:
862 MockReportingService() {}
863
864 // net::ReportingService implementation:
865
866 ~MockReportingService() override {}
867
868 void QueueReport(const GURL& url,
869 const std::string& group,
870 const std::string& type,
871 std::unique_ptr<const base::Value> body) override {
872 NOTREACHED();
873 }
874
875 void ProcessHeader(const GURL& url,
876 const std::string& header_value) override {
877 NOTREACHED();
878 }
879
880 void RemoveBrowsingData(
881 int data_type_mask,
882 base::Callback<bool(const GURL&)> origin_filter) override {
883 ++remove_calls_;
884 last_data_type_mask_ = data_type_mask;
885 last_origin_filter_ = origin_filter;
886 }
887
888 int remove_calls() const { return remove_calls_; }
889 int last_data_type_mask() const { return last_data_type_mask_; }
890 base::Callback<bool(const GURL&)> last_origin_filter() const {
891 return last_origin_filter_;
892 }
893
894 private:
895 int remove_calls_ = 0;
896 int last_data_type_mask_ = 0;
897 base::Callback<bool(const GURL&)> last_origin_filter_;
898
899 DISALLOW_COPY_AND_ASSIGN(MockReportingService);
900 };
901
902 class ClearReportingCacheTester {
903 public:
904 ClearReportingCacheTester(TestingProfile* profile, bool create_service)
905 : profile_(profile) {
906 if (create_service)
907 service_ = base::MakeUnique<MockReportingService>();
908
909 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
910
911 net::URLRequestContext* request_context =
912 profile_->GetRequestContext()->GetURLRequestContext();
913 old_service_ = request_context->reporting_service();
914 request_context->set_reporting_service(service_.get());
915 }
916
917 ~ClearReportingCacheTester() {
918 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
919
920 net::URLRequestContext* request_context =
921 profile_->GetRequestContext()->GetURLRequestContext();
922 DCHECK_EQ(service_.get(), request_context->reporting_service());
923 request_context->set_reporting_service(old_service_);
924 }
925
926 void GetMockInfo(int* remove_calls_out,
927 int* last_data_type_mask_out,
928 base::Callback<bool(const GURL&)>* last_origin_filter_out) {
929 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
930 DCHECK_NE(nullptr, service_.get());
931
932 *remove_calls_out = service_->remove_calls();
933 *last_data_type_mask_out = service_->last_data_type_mask();
934 *last_origin_filter_out = service_->last_origin_filter();
935 }
936
937 private:
938 TestingProfile* profile_;
939 std::unique_ptr<MockReportingService> service_;
940 net::ReportingService* old_service_;
941 };
942
858 // Test Class ----------------------------------------------------------------- 943 // Test Class -----------------------------------------------------------------
859 944
860 class ChromeBrowsingDataRemoverDelegateTest : public testing::Test { 945 class ChromeBrowsingDataRemoverDelegateTest : public testing::Test {
861 public: 946 public:
862 ChromeBrowsingDataRemoverDelegateTest() 947 ChromeBrowsingDataRemoverDelegateTest()
863 : profile_(new TestingProfileWithDelegate()), 948 : profile_(new TestingProfileWithDelegate()),
864 clear_domain_reliability_tester_(profile_.get()) { 949 clear_domain_reliability_tester_(profile_.get()) {
865 remover_ = content::BrowserContext::GetBrowsingDataRemover(profile_.get()); 950 remover_ = content::BrowserContext::GetBrowsingDataRemover(profile_.get());
866 951
867 #if defined(OS_ANDROID) 952 #if defined(OS_ANDROID)
(...skipping 1145 matching lines...) Expand 10 before | Expand all | Expand 10 after
2013 EXPECT_FALSE(Match(kOrigin1, kProtected, nullptr)); 2098 EXPECT_FALSE(Match(kOrigin1, kProtected, nullptr));
2014 EXPECT_FALSE(Match(kOriginExt, kProtected, nullptr)); 2099 EXPECT_FALSE(Match(kOriginExt, kProtected, nullptr));
2015 EXPECT_FALSE(Match(kOriginDevTools, kProtected, nullptr)); 2100 EXPECT_FALSE(Match(kOriginDevTools, kProtected, nullptr));
2016 2101
2017 #if BUILDFLAG(ENABLE_EXTENSIONS) 2102 #if BUILDFLAG(ENABLE_EXTENSIONS)
2018 EXPECT_FALSE(Match(kOrigin1, kExtension, nullptr)); 2103 EXPECT_FALSE(Match(kOrigin1, kExtension, nullptr));
2019 EXPECT_TRUE(Match(kOriginExt, kExtension, nullptr)); 2104 EXPECT_TRUE(Match(kOriginExt, kExtension, nullptr));
2020 EXPECT_FALSE(Match(kOriginDevTools, kExtension, nullptr)); 2105 EXPECT_FALSE(Match(kOriginDevTools, kExtension, nullptr));
2021 #endif 2106 #endif
2022 } 2107 }
2108
2109 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ReportingCache_NoService) {
2110 ClearReportingCacheTester tester(GetProfile(), false);
2111
2112 BlockUntilBrowsingDataRemoved(
2113 base::Time(), base::Time::Max(),
2114 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
2115 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY,
2116 true);
2117
2118 // Nothing to check, since there's no mock service; we're just making sure
2119 // nothing crashes without a service.
2120 }
2121
2122 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ReportingCache_Cookies) {
2123 ClearReportingCacheTester tester(GetProfile(), true);
2124
2125 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2126 content::BrowsingDataRemover::DATA_TYPE_COOKIES,
2127 true);
2128
2129 int remove_count;
2130 int data_type_mask;
2131 base::Callback<bool(const GURL&)> origin_filter;
2132 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter);
2133
2134 EXPECT_EQ(1, remove_count);
2135 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_CLIENTS,
2136 data_type_mask);
2137 EXPECT_TRUE(ProbablySameFilters(BrowsingDataFilterBuilder::BuildNoopFilter(),
2138 origin_filter));
2139 }
2140
2141 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
2142 ReportingCache_Cookies_WithFilter) {
2143 ClearReportingCacheTester tester(GetProfile(), true);
2144
2145 std::unique_ptr<BrowsingDataFilterBuilder> builder(
2146 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST));
2147 builder->AddRegisterableDomain(kTestRegisterableDomain1);
2148
2149 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
2150 content::BrowsingDataRemover::DATA_TYPE_COOKIES,
2151 builder->Copy());
2152
2153 int remove_count;
2154 int data_type_mask;
2155 base::Callback<bool(const GURL&)> origin_filter;
2156 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter);
2157
2158 EXPECT_EQ(1, remove_count);
2159 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_CLIENTS,
2160 data_type_mask);
2161 EXPECT_TRUE(
2162 ProbablySameFilters(builder->BuildGeneralFilter(), origin_filter));
2163 }
2164
2165 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ReportingCache_History) {
2166 ClearReportingCacheTester tester(GetProfile(), true);
2167
2168 BlockUntilBrowsingDataRemoved(
2169 base::Time(), base::Time::Max(),
2170 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY, true);
2171
2172 int remove_count;
2173 int data_type_mask;
2174 base::Callback<bool(const GURL&)> origin_filter;
2175 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter);
2176
2177 EXPECT_EQ(1, remove_count);
2178 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_REPORTS,
2179 data_type_mask);
2180 EXPECT_TRUE(ProbablySameFilters(BrowsingDataFilterBuilder::BuildNoopFilter(),
2181 origin_filter));
2182 }
2183
2184 // TODO(crbug.com/589586): Disabled, since history is not yet marked as
2185 // a filterable datatype.
2186 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
2187 DISABLED_ReportingCache_History_WithFilter) {
2188 ClearReportingCacheTester tester(GetProfile(), true);
2189
2190 std::unique_ptr<BrowsingDataFilterBuilder> builder(
2191 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST));
2192 builder->AddRegisterableDomain(kTestRegisterableDomain1);
2193
2194 BlockUntilOriginDataRemoved(
2195 base::Time(), base::Time::Max(),
2196 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY, builder->Copy());
2197
2198 int remove_count;
2199 int data_type_mask;
2200 base::Callback<bool(const GURL&)> origin_filter;
2201 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter);
2202
2203 EXPECT_EQ(1, remove_count);
2204 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_REPORTS,
2205 data_type_mask);
2206 EXPECT_TRUE(
2207 ProbablySameFilters(builder->BuildGeneralFilter(), origin_filter));
2208 }
2209
2210 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
2211 ReportingCache_CookiesAndHistory) {
2212 ClearReportingCacheTester tester(GetProfile(), true);
2213
2214 BlockUntilBrowsingDataRemoved(
2215 base::Time(), base::Time::Max(),
2216 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
2217 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY,
2218 true);
2219
2220 int remove_count;
2221 int data_type_mask;
2222 base::Callback<bool(const GURL&)> origin_filter;
2223 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter);
2224
2225 EXPECT_EQ(1, remove_count);
2226 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_REPORTS |
2227 net::ReportingBrowsingDataRemover::DATA_TYPE_CLIENTS,
2228 data_type_mask);
2229 EXPECT_TRUE(ProbablySameFilters(BrowsingDataFilterBuilder::BuildNoopFilter(),
2230 origin_filter));
2231 }
2232
2233 // TODO(crbug.com/589586): Disabled, since history is not yet marked as
2234 // a filterable datatype.
2235 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
2236 DISABLED_ReportingCache_CookiesAndHistory_WithFilter) {
2237 ClearReportingCacheTester tester(GetProfile(), true);
2238
2239 std::unique_ptr<BrowsingDataFilterBuilder> builder(
2240 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST));
2241 builder->AddRegisterableDomain(kTestRegisterableDomain1);
2242
2243 BlockUntilOriginDataRemoved(
2244 base::Time(), base::Time::Max(),
2245 content::BrowsingDataRemover::DATA_TYPE_COOKIES |
2246 ChromeBrowsingDataRemoverDelegate::DATA_TYPE_HISTORY,
2247 builder->Copy());
2248
2249 int remove_count;
2250 int data_type_mask;
2251 base::Callback<bool(const GURL&)> origin_filter;
2252 tester.GetMockInfo(&remove_count, &data_type_mask, &origin_filter);
2253
2254 EXPECT_EQ(1, remove_count);
2255 EXPECT_EQ(net::ReportingBrowsingDataRemover::DATA_TYPE_REPORTS |
2256 net::ReportingBrowsingDataRemover::DATA_TYPE_CLIENTS,
2257 data_type_mask);
2258 EXPECT_TRUE(
2259 ProbablySameFilters(builder->BuildGeneralFilter(), origin_filter));
2260 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.cc ('k') | net/reporting/reporting_browsing_data_remover.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698