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

Side by Side Diff: content/browser/browsing_data/browsing_data_remover_impl_unittest.cc

Issue 2827523003: Move BrowsingDataRemover to content/ (Closed)
Patch Set: Rebase over codereview.chromium.org/2815913005 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <list> 8 #include <list>
9 #include <memory> 9 #include <memory>
10 #include <set> 10 #include <set>
(...skipping 10 matching lines...) Expand all
21 #include "base/macros.h" 21 #include "base/macros.h"
22 #include "base/memory/ptr_util.h" 22 #include "base/memory/ptr_util.h"
23 #include "base/message_loop/message_loop.h" 23 #include "base/message_loop/message_loop.h"
24 #include "base/run_loop.h" 24 #include "base/run_loop.h"
25 #include "base/single_thread_task_runner.h" 25 #include "base/single_thread_task_runner.h"
26 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "base/task/cancelable_task_tracker.h" 27 #include "base/task/cancelable_task_tracker.h"
28 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/thread_task_runner_handle.h"
29 #include "base/time/time.h" 29 #include "base/time/time.h"
30 #include "build/build_config.h" 30 #include "build/build_config.h"
31 #include "chrome/browser/browsing_data/browsing_data_helper.h" 31 #include "content/browser/browsing_data/browsing_data_remover_impl.h"
32 #include "chrome/browser/browsing_data/browsing_data_remover.h"
33 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
34 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h"
35 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
36 #include "chrome/test/base/testing_profile.h"
37 #include "content/public/browser/browser_context.h" 32 #include "content/public/browser/browser_context.h"
38 #include "content/public/browser/browsing_data_filter_builder.h" 33 #include "content/public/browser/browsing_data_filter_builder.h"
34 #include "content/public/browser/browsing_data_remover.h"
39 #include "content/public/browser/cookie_store_factory.h" 35 #include "content/public/browser/cookie_store_factory.h"
40 #include "content/public/browser/dom_storage_context.h" 36 #include "content/public/browser/dom_storage_context.h"
41 #include "content/public/browser/local_storage_usage_info.h" 37 #include "content/public/browser/local_storage_usage_info.h"
42 #include "content/public/browser/storage_partition.h" 38 #include "content/public/browser/storage_partition.h"
39 #include "content/public/test/browsing_data_remover_test_util.h"
43 #include "content/public/test/mock_download_manager.h" 40 #include "content/public/test/mock_download_manager.h"
41 #include "content/public/test/test_browser_context.h"
44 #include "content/public/test/test_browser_thread.h" 42 #include "content/public/test/test_browser_thread.h"
45 #include "content/public/test/test_browser_thread_bundle.h" 43 #include "content/public/test/test_browser_thread_bundle.h"
46 #include "content/public/test/test_utils.h" 44 #include "content/public/test/test_utils.h"
47 #include "extensions/features/features.h"
48 #include "net/cookies/cookie_store.h" 45 #include "net/cookies/cookie_store.h"
49 #include "net/http/http_network_session.h" 46 #include "net/http/http_network_session.h"
50 #include "net/http/http_transaction_factory.h" 47 #include "net/http/http_transaction_factory.h"
51 #include "net/ssl/channel_id_service.h" 48 #include "net/ssl/channel_id_service.h"
52 #include "net/ssl/channel_id_store.h" 49 #include "net/ssl/channel_id_store.h"
53 #include "net/ssl/ssl_client_cert_type.h" 50 #include "net/ssl/ssl_client_cert_type.h"
54 #include "net/url_request/url_request_context.h" 51 #include "net/url_request/url_request_context.h"
55 #include "net/url_request/url_request_context_getter.h" 52 #include "net/url_request/url_request_context_getter.h"
56 #include "ppapi/features/features.h" 53 #include "ppapi/features/features.h"
57 #include "storage/browser/test/mock_special_storage_policy.h" 54 #include "storage/browser/test/mock_special_storage_policy.h"
58 #include "testing/gmock/include/gmock/gmock.h" 55 #include "testing/gmock/include/gmock/gmock.h"
59 #include "testing/gtest/include/gtest/gtest.h" 56 #include "testing/gtest/include/gtest/gtest.h"
60 #include "url/origin.h" 57 #include "url/origin.h"
61 58
62 using content::BrowserThread;
63 using content::BrowserContext;
64 using content::BrowsingDataFilterBuilder;
65 using content::StoragePartition;
66 using testing::_; 59 using testing::_;
67 using testing::ByRef; 60 using testing::ByRef;
68 using testing::Eq; 61 using testing::Eq;
69 using testing::Invoke; 62 using testing::Invoke;
70 using testing::IsEmpty; 63 using testing::IsEmpty;
71 using testing::Matcher; 64 using testing::Matcher;
72 using testing::MakeMatcher; 65 using testing::MakeMatcher;
73 using testing::MatcherInterface; 66 using testing::MatcherInterface;
74 using testing::MatchResultListener; 67 using testing::MatchResultListener;
75 using testing::Not; 68 using testing::Not;
76 using testing::Return; 69 using testing::Return;
77 using testing::SizeIs; 70 using testing::SizeIs;
78 using testing::WithArgs; 71 using testing::WithArgs;
79 72
73 namespace content {
74
80 namespace { 75 namespace {
81 76
82 const char kTestOrigin1[] = "http://host1.com:1/"; 77 const char kTestOrigin1[] = "http://host1.com:1/";
83 const char kTestRegisterableDomain1[] = "host1.com"; 78 const char kTestRegisterableDomain1[] = "host1.com";
84 const char kTestOrigin2[] = "http://host2.com:1/"; 79 const char kTestOrigin2[] = "http://host2.com:1/";
85 const char kTestOrigin3[] = "http://host3.com:1/"; 80 const char kTestOrigin3[] = "http://host3.com:1/";
86 const char kTestRegisterableDomain3[] = "host3.com"; 81 const char kTestRegisterableDomain3[] = "host3.com";
87 const char kTestOrigin4[] = "https://host3.com:1/"; 82 const char kTestOrigin4[] = "https://host3.com:1/";
88 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; 83 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
89 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; 84 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 net::COOKIE_PRIORITY_MEDIUM)); 123 net::COOKIE_PRIORITY_MEDIUM));
129 EXPECT_TRUE(cookie); 124 EXPECT_TRUE(cookie);
130 return *cookie; 125 return *cookie;
131 } 126 }
132 127
133 class TestStoragePartition : public StoragePartition { 128 class TestStoragePartition : public StoragePartition {
134 public: 129 public:
135 TestStoragePartition() {} 130 TestStoragePartition() {}
136 ~TestStoragePartition() override {} 131 ~TestStoragePartition() override {}
137 132
138 // content::StoragePartition implementation. 133 // StoragePartition implementation.
139 base::FilePath GetPath() override { return base::FilePath(); } 134 base::FilePath GetPath() override { return base::FilePath(); }
140 net::URLRequestContextGetter* GetURLRequestContext() override { 135 net::URLRequestContextGetter* GetURLRequestContext() override {
141 return nullptr; 136 return nullptr;
142 } 137 }
143 net::URLRequestContextGetter* GetMediaURLRequestContext() override { 138 net::URLRequestContextGetter* GetMediaURLRequestContext() override {
144 return nullptr; 139 return nullptr;
145 } 140 }
146 storage::QuotaManager* GetQuotaManager() override { return nullptr; } 141 storage::QuotaManager* GetQuotaManager() override { return nullptr; }
147 content::AppCacheService* GetAppCacheService() override { return nullptr; } 142 AppCacheService* GetAppCacheService() override { return nullptr; }
148 storage::FileSystemContext* GetFileSystemContext() override { 143 storage::FileSystemContext* GetFileSystemContext() override {
149 return nullptr; 144 return nullptr;
150 } 145 }
151 storage::DatabaseTracker* GetDatabaseTracker() override { return nullptr; } 146 storage::DatabaseTracker* GetDatabaseTracker() override { return nullptr; }
152 content::DOMStorageContext* GetDOMStorageContext() override { 147 DOMStorageContext* GetDOMStorageContext() override { return nullptr; }
148 IndexedDBContext* GetIndexedDBContext() override { return nullptr; }
149 ServiceWorkerContext* GetServiceWorkerContext() override { return nullptr; }
150 CacheStorageContext* GetCacheStorageContext() override { return nullptr; }
151 PlatformNotificationContext* GetPlatformNotificationContext() override {
153 return nullptr; 152 return nullptr;
154 } 153 }
155 content::IndexedDBContext* GetIndexedDBContext() override { return nullptr; } 154 HostZoomMap* GetHostZoomMap() override { return nullptr; }
156 content::ServiceWorkerContext* GetServiceWorkerContext() override { 155 HostZoomLevelContext* GetHostZoomLevelContext() override { return nullptr; }
157 return nullptr; 156 ZoomLevelDelegate* GetZoomLevelDelegate() override { return nullptr; }
158 }
159 content::CacheStorageContext* GetCacheStorageContext() override {
160 return nullptr;
161 }
162 content::PlatformNotificationContext* GetPlatformNotificationContext()
163 override {
164 return nullptr;
165 }
166 content::HostZoomMap* GetHostZoomMap() override { return nullptr; }
167 content::HostZoomLevelContext* GetHostZoomLevelContext() override {
168 return nullptr;
169 }
170 content::ZoomLevelDelegate* GetZoomLevelDelegate() override {
171 return nullptr;
172 }
173 157
174 void ClearDataForOrigin(uint32_t remove_mask, 158 void ClearDataForOrigin(uint32_t remove_mask,
175 uint32_t quota_storage_remove_mask, 159 uint32_t quota_storage_remove_mask,
176 const GURL& storage_origin, 160 const GURL& storage_origin,
177 net::URLRequestContextGetter* rq_context, 161 net::URLRequestContextGetter* rq_context,
178 const base::Closure& callback) override { 162 const base::Closure& callback) override {
179 BrowserThread::PostTask( 163 BrowserThread::PostTask(
180 BrowserThread::UI, FROM_HERE, 164 BrowserThread::UI, FROM_HERE,
181 base::BindOnce(&TestStoragePartition::AsyncRunCallback, 165 base::BindOnce(&TestStoragePartition::AsyncRunCallback,
182 base::Unretained(this), callback)); 166 base::Unretained(this), callback));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 219
236 void Flush() override {} 220 void Flush() override {}
237 221
238 void ClearBluetoothAllowedDevicesMapForTesting() override {} 222 void ClearBluetoothAllowedDevicesMapForTesting() override {}
239 223
240 StoragePartitionRemovalData GetStoragePartitionRemovalData() { 224 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
241 return storage_partition_removal_data_; 225 return storage_partition_removal_data_;
242 } 226 }
243 227
244 private: 228 private:
245 void AsyncRunCallback(const base::Closure& callback) { 229 void AsyncRunCallback(const base::Closure& callback) { callback.Run(); }
246 callback.Run();
247 }
248 230
249 StoragePartitionRemovalData storage_partition_removal_data_; 231 StoragePartitionRemovalData storage_partition_removal_data_;
250 232
251 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); 233 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition);
252 }; 234 };
253 235
254 // Custom matcher to test the equivalence of two URL filters. Since those are 236 // Custom matcher to test the equivalence of two URL filters. Since those are
255 // blackbox predicates, we can only approximate the equivalence by testing 237 // blackbox predicates, we can only approximate the equivalence by testing
256 // whether the filter give the same answer for several URLs. This is currently 238 // whether the filter give the same answer for several URLs. This is currently
257 // good enough for our testing purposes, to distinguish whitelists 239 // good enough for our testing purposes, to distinguish whitelists
258 // and blacklists, empty and non-empty filters and such. 240 // and blacklists, empty and non-empty filters and such.
259 // TODO(msramek): BrowsingDataRemover and some of its backends support URL 241 // TODO(msramek): BrowsingDataRemover and some of its backends support URL
260 // filters, but its constructor currently only takes a single URL and constructs 242 // filters, but its constructor currently only takes a single URL and constructs
261 // its own url filter. If an url filter was directly passed to 243 // its own url filter. If an url filter was directly passed to
262 // BrowsingDataRemover (what should eventually be the case), we can use the same 244 // BrowsingDataRemover (what should eventually be the case), we can use the same
263 // instance in the test as well, and thus simply test base::Callback::Equals() 245 // instance in the test as well, and thus simply test base::Callback::Equals()
264 // in this matcher. 246 // in this matcher.
265 class ProbablySameFilterMatcher 247 class ProbablySameFilterMatcher
266 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> { 248 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> {
267 public: 249 public:
268 explicit ProbablySameFilterMatcher( 250 explicit ProbablySameFilterMatcher(
269 const base::Callback<bool(const GURL&)>& filter) 251 const base::Callback<bool(const GURL&)>& filter)
270 : to_match_(filter) { 252 : to_match_(filter) {}
271 }
272 253
273 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter, 254 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter,
274 MatchResultListener* listener) const { 255 MatchResultListener* listener) const {
275 if (filter.is_null() && to_match_.is_null()) 256 if (filter.is_null() && to_match_.is_null())
276 return true; 257 return true;
277 if (filter.is_null() != to_match_.is_null()) 258 if (filter.is_null() != to_match_.is_null())
278 return false; 259 return false;
279 260
280 const GURL urls_to_test_[] = 261 const GURL urls_to_test_[] = {kOrigin1, kOrigin2, kOrigin3,
281 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")}; 262 GURL("invalid spec")};
282 for (GURL url : urls_to_test_) { 263 for (GURL url : urls_to_test_) {
283 if (filter.Run(url) != to_match_.Run(url)) { 264 if (filter.Run(url) != to_match_.Run(url)) {
284 if (listener) 265 if (listener)
285 *listener << "The filters differ on the URL " << url; 266 *listener << "The filters differ on the URL " << url;
286 return false; 267 return false;
287 } 268 }
288 } 269 }
289 return true; 270 return true;
290 } 271 }
291 272
(...skipping 21 matching lines...) Expand all
313 } // namespace 294 } // namespace
314 295
315 // Testers ------------------------------------------------------------------- 296 // Testers -------------------------------------------------------------------
316 297
317 class RemoveCookieTester { 298 class RemoveCookieTester {
318 public: 299 public:
319 RemoveCookieTester() {} 300 RemoveCookieTester() {}
320 301
321 // Returns true, if the given cookie exists in the cookie store. 302 // Returns true, if the given cookie exists in the cookie store.
322 bool ContainsCookie() { 303 bool ContainsCookie() {
323 scoped_refptr<content::MessageLoopRunner> message_loop_runner = 304 scoped_refptr<MessageLoopRunner> message_loop_runner =
324 new content::MessageLoopRunner; 305 new MessageLoopRunner();
325 quit_closure_ = message_loop_runner->QuitClosure(); 306 quit_closure_ = message_loop_runner->QuitClosure();
326 get_cookie_success_ = false; 307 get_cookie_success_ = false;
327 cookie_store_->GetCookiesWithOptionsAsync( 308 cookie_store_->GetCookiesWithOptionsAsync(
328 kOrigin1, net::CookieOptions(), 309 kOrigin1, net::CookieOptions(),
329 base::Bind(&RemoveCookieTester::GetCookieCallback, 310 base::Bind(&RemoveCookieTester::GetCookieCallback,
330 base::Unretained(this))); 311 base::Unretained(this)));
331 message_loop_runner->Run(); 312 message_loop_runner->Run();
332 return get_cookie_success_; 313 return get_cookie_success_;
333 } 314 }
334 315
335 void AddCookie() { 316 void AddCookie() {
336 scoped_refptr<content::MessageLoopRunner> message_loop_runner = 317 scoped_refptr<MessageLoopRunner> message_loop_runner =
337 new content::MessageLoopRunner; 318 new MessageLoopRunner();
338 quit_closure_ = message_loop_runner->QuitClosure(); 319 quit_closure_ = message_loop_runner->QuitClosure();
339 cookie_store_->SetCookieWithOptionsAsync( 320 cookie_store_->SetCookieWithOptionsAsync(
340 kOrigin1, "A=1", net::CookieOptions(), 321 kOrigin1, "A=1", net::CookieOptions(),
341 base::Bind(&RemoveCookieTester::SetCookieCallback, 322 base::Bind(&RemoveCookieTester::SetCookieCallback,
342 base::Unretained(this))); 323 base::Unretained(this)));
343 message_loop_runner->Run(); 324 message_loop_runner->Run();
344 } 325 }
345 326
346 protected: 327 protected:
347 void SetCookieStore(net::CookieStore* cookie_store) { 328 void SetCookieStore(net::CookieStore* cookie_store) {
(...skipping 22 matching lines...) Expand all
370 // CookieStore must out live |this|. 351 // CookieStore must out live |this|.
371 net::CookieStore* cookie_store_ = nullptr; 352 net::CookieStore* cookie_store_ = nullptr;
372 353
373 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); 354 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
374 }; 355 };
375 356
376 class RemoveChannelIDTester : public net::SSLConfigService::Observer { 357 class RemoveChannelIDTester : public net::SSLConfigService::Observer {
377 public: 358 public:
378 explicit RemoveChannelIDTester(BrowserContext* browser_context) { 359 explicit RemoveChannelIDTester(BrowserContext* browser_context) {
379 net::URLRequestContext* url_request_context = 360 net::URLRequestContext* url_request_context =
380 content::BrowserContext::GetDefaultStoragePartition(browser_context) 361 BrowserContext::GetDefaultStoragePartition(browser_context)
381 ->GetURLRequestContext()->GetURLRequestContext(); 362 ->GetURLRequestContext()
382 channel_id_service_ = url_request_context-> channel_id_service(); 363 ->GetURLRequestContext();
364 channel_id_service_ = url_request_context->channel_id_service();
383 ssl_config_service_ = url_request_context->ssl_config_service(); 365 ssl_config_service_ = url_request_context->ssl_config_service();
384 ssl_config_service_->AddObserver(this); 366 ssl_config_service_->AddObserver(this);
385 } 367 }
386 368
387 ~RemoveChannelIDTester() override { 369 ~RemoveChannelIDTester() override {
388 ssl_config_service_->RemoveObserver(this); 370 ssl_config_service_->RemoveObserver(this);
389 } 371 }
390 372
391 int ChannelIDCount() { return channel_id_service_->channel_id_count(); } 373 int ChannelIDCount() { return channel_id_service_->channel_id_count(); }
392 374
393 // Add a server bound cert for |server| with specific creation and expiry 375 // Add a server bound cert for |server| with specific creation and expiry
394 // times. The cert and key data will be filled with dummy values. 376 // times. The cert and key data will be filled with dummy values.
395 void AddChannelIDWithTimes(const std::string& server_identifier, 377 void AddChannelIDWithTimes(const std::string& server_identifier,
396 base::Time creation_time) { 378 base::Time creation_time) {
397 GetChannelIDStore()->SetChannelID( 379 GetChannelIDStore()->SetChannelID(
398 base::MakeUnique<net::ChannelIDStore::ChannelID>( 380 base::MakeUnique<net::ChannelIDStore::ChannelID>(
399 server_identifier, creation_time, crypto::ECPrivateKey::Create())); 381 server_identifier, creation_time, crypto::ECPrivateKey::Create()));
400 } 382 }
401 383
402 // Add a server bound cert for |server|, with the current time as the 384 // Add a server bound cert for |server|, with the current time as the
403 // creation time. The cert and key data will be filled with dummy values. 385 // creation time. The cert and key data will be filled with dummy values.
404 void AddChannelID(const std::string& server_identifier) { 386 void AddChannelID(const std::string& server_identifier) {
405 base::Time now = base::Time::Now(); 387 base::Time now = base::Time::Now();
406 AddChannelIDWithTimes(server_identifier, now); 388 AddChannelIDWithTimes(server_identifier, now);
407 } 389 }
408 390
409 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) { 391 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) {
410 GetChannelIDStore()->GetAllChannelIDs( 392 GetChannelIDStore()->GetAllChannelIDs(base::Bind(
411 base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback, 393 &RemoveChannelIDTester::GetAllChannelIDsCallback, channel_ids));
412 channel_ids));
413 } 394 }
414 395
415 net::ChannelIDStore* GetChannelIDStore() { 396 net::ChannelIDStore* GetChannelIDStore() {
416 return channel_id_service_->GetChannelIDStore(); 397 return channel_id_service_->GetChannelIDStore();
417 } 398 }
418 399
419 int ssl_config_changed_count() const { 400 int ssl_config_changed_count() const { return ssl_config_changed_count_; }
420 return ssl_config_changed_count_;
421 }
422 401
423 // net::SSLConfigService::Observer implementation: 402 // net::SSLConfigService::Observer implementation:
424 void OnSSLConfigChanged() override { ssl_config_changed_count_++; } 403 void OnSSLConfigChanged() override { ssl_config_changed_count_++; }
425 404
426 private: 405 private:
427 static void GetAllChannelIDsCallback( 406 static void GetAllChannelIDsCallback(
428 net::ChannelIDStore::ChannelIDList* dest, 407 net::ChannelIDStore::ChannelIDList* dest,
429 const net::ChannelIDStore::ChannelIDList& result) { 408 const net::ChannelIDStore::ChannelIDList& result) {
430 *dest = result; 409 *dest = result;
431 } 410 }
432 411
433 net::ChannelIDService* channel_id_service_; 412 net::ChannelIDService* channel_id_service_;
434 scoped_refptr<net::SSLConfigService> ssl_config_service_; 413 scoped_refptr<net::SSLConfigService> ssl_config_service_;
435 int ssl_config_changed_count_ = 0; 414 int ssl_config_changed_count_ = 0;
436 415
437 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester); 416 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester);
438 }; 417 };
439 418
440 class RemoveLocalStorageTester { 419 class RemoveLocalStorageTester {
441 public: 420 public:
442 explicit RemoveLocalStorageTester(BrowserContext* browser_context) 421 explicit RemoveLocalStorageTester(BrowserContext* browser_context)
443 : browser_context_(browser_context) { 422 : browser_context_(browser_context) {
444 dom_storage_context_ = 423 dom_storage_context_ =
445 content::BrowserContext::GetDefaultStoragePartition(browser_context_)-> 424 BrowserContext::GetDefaultStoragePartition(browser_context_)
446 GetDOMStorageContext(); 425 ->GetDOMStorageContext();
447 } 426 }
448 427
449 // Returns true, if the given origin URL exists. 428 // Returns true, if the given origin URL exists.
450 bool DOMStorageExistsForOrigin(const GURL& origin) { 429 bool DOMStorageExistsForOrigin(const GURL& origin) {
451 scoped_refptr<content::MessageLoopRunner> message_loop_runner = 430 scoped_refptr<MessageLoopRunner> message_loop_runner =
452 new content::MessageLoopRunner; 431 new MessageLoopRunner();
453 quit_closure_ = message_loop_runner->QuitClosure(); 432 quit_closure_ = message_loop_runner->QuitClosure();
454 GetLocalStorageUsage(); 433 GetLocalStorageUsage();
455 message_loop_runner->Run(); 434 message_loop_runner->Run();
456 for (size_t i = 0; i < infos_.size(); ++i) { 435 for (size_t i = 0; i < infos_.size(); ++i) {
457 if (origin == infos_[i].origin) 436 if (origin == infos_[i].origin)
458 return true; 437 return true;
459 } 438 }
460 return false; 439 return false;
461 } 440 }
462 441
463 void AddDOMStorageTestData() { 442 void AddDOMStorageTestData() {
464 // Note: This test depends on details of how the dom_storage library 443 // Note: This test depends on details of how the dom_storage library
465 // stores data in the host file system. 444 // stores data in the host file system.
466 base::FilePath storage_path = 445 base::FilePath storage_path =
467 browser_context_->GetPath().AppendASCII("Local Storage"); 446 browser_context_->GetPath().AppendASCII("Local Storage");
468 base::CreateDirectory(storage_path); 447 base::CreateDirectory(storage_path);
469 448
470 // Write some files. 449 // Write some files.
471 base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0); 450 base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0);
472 base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0); 451 base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0);
473 base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0); 452 base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0);
474 base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0); 453 base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0);
475 454
476 // Tweak their dates. 455 // Tweak their dates.
477 base::Time now = base::Time::Now(); 456 base::Time now = base::Time::Now();
478 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now); 457 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
479 458
480 base::Time one_day_ago = now - base::TimeDelta::FromDays(1); 459 base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
481 base::TouchFile(storage_path.Append(kDomStorageOrigin2), 460 base::TouchFile(storage_path.Append(kDomStorageOrigin2), one_day_ago,
482 one_day_ago, one_day_ago); 461 one_day_ago);
483 462
484 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60); 463 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
485 base::TouchFile(storage_path.Append(kDomStorageOrigin3), 464 base::TouchFile(storage_path.Append(kDomStorageOrigin3), sixty_days_ago,
486 sixty_days_ago, sixty_days_ago); 465 sixty_days_ago);
487 466
488 base::TouchFile(storage_path.Append(kDomStorageExt), now, now); 467 base::TouchFile(storage_path.Append(kDomStorageExt), now, now);
489 } 468 }
490 469
491 private: 470 private:
492 void GetLocalStorageUsage() { 471 void GetLocalStorageUsage() {
493 dom_storage_context_->GetLocalStorageUsage( 472 dom_storage_context_->GetLocalStorageUsage(
494 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage, 473 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage,
495 base::Unretained(this))); 474 base::Unretained(this)));
496 } 475 }
497 void OnGotLocalStorageUsage( 476 void OnGotLocalStorageUsage(const std::vector<LocalStorageUsageInfo>& infos) {
498 const std::vector<content::LocalStorageUsageInfo>& infos) {
499 infos_ = infos; 477 infos_ = infos;
500 quit_closure_.Run(); 478 quit_closure_.Run();
501 } 479 }
502 480
503 // We don't own these pointers. 481 // We don't own these pointers.
504 BrowserContext* browser_context_; 482 BrowserContext* browser_context_;
505 content::DOMStorageContext* dom_storage_context_ = nullptr; 483 DOMStorageContext* dom_storage_context_ = nullptr;
506 484
507 std::vector<content::LocalStorageUsageInfo> infos_; 485 std::vector<LocalStorageUsageInfo> infos_;
508 base::Closure quit_closure_; 486 base::Closure quit_closure_;
509 487
510 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); 488 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
511 }; 489 };
512 490
513 class RemoveDownloadsTester { 491 class RemoveDownloadsTester {
514 public: 492 public:
515 explicit RemoveDownloadsTester(BrowserContext* browser_context) 493 explicit RemoveDownloadsTester(BrowserContext* browser_context)
516 : download_manager_(new content::MockDownloadManager()) { 494 : download_manager_(new MockDownloadManager()) {
517 content::BrowserContext::SetDownloadManagerForTesting( 495 BrowserContext::SetDownloadManagerForTesting(
518 browser_context, base::WrapUnique(download_manager_)); 496 browser_context, base::WrapUnique(download_manager_));
519 EXPECT_EQ(download_manager_, 497 EXPECT_EQ(download_manager_,
520 content::BrowserContext::GetDownloadManager(browser_context)); 498 BrowserContext::GetDownloadManager(browser_context));
521 EXPECT_CALL(*download_manager_, Shutdown()); 499 EXPECT_CALL(*download_manager_, Shutdown());
522 } 500 }
523 501
524 ~RemoveDownloadsTester() {} 502 ~RemoveDownloadsTester() {}
525 503
526 content::MockDownloadManager* download_manager() { return download_manager_; } 504 MockDownloadManager* download_manager() { return download_manager_; }
527 505
528 private: 506 private:
529 content::MockDownloadManager* download_manager_; // Owned by browser context. 507 MockDownloadManager* download_manager_; // Owned by browser context.
530 508
531 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester); 509 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester);
532 }; 510 };
533 511
534 // Test Class ---------------------------------------------------------------- 512 // Test Class ----------------------------------------------------------------
535 513
536 class BrowsingDataRemoverImplTest : public testing::Test { 514 class BrowsingDataRemoverImplTest : public testing::Test {
537 public: 515 public:
538 BrowsingDataRemoverImplTest() 516 BrowsingDataRemoverImplTest() : browser_context_(new TestBrowserContext()) {
539 : browser_context_(new TestingProfile()) {
540 // TODO(crbug.com/668114): To create a BrowsingDataRemoverImpl, we currently
541 // need a BrowsingDataRemoverFactory which only exists for a Profile.
542 // Therefore, this test must use a TestingProfile for now. Switch it to
543 // a BrowserContext or TestBrowserContext when BrowsingDataRemoverImpl
544 // moves to content/. Furthermore, when in content/, BrowsingDataRemoverImpl
545 // will have no delegate. For now, explicitly set it to nullptr.
546 remover_ = static_cast<BrowsingDataRemoverImpl*>( 517 remover_ = static_cast<BrowsingDataRemoverImpl*>(
547 BrowsingDataRemoverFactory::GetForBrowserContext( 518 BrowserContext::GetBrowsingDataRemover(browser_context_.get()));
548 browser_context_.get()));
549 remover_->SetEmbedderDelegate(nullptr);
550 } 519 }
551 520
552 ~BrowsingDataRemoverImplTest() override {} 521 ~BrowsingDataRemoverImplTest() override {}
553 522
554 void TearDown() override { 523 void TearDown() override {
555 mock_policy_ = nullptr; 524 mock_policy_ = nullptr;
556 525
557 // BrowserContext contains a DOMStorageContext. BrowserContext's 526 // BrowserContext contains a DOMStorageContext. BrowserContext's
558 // destructor posts a message to the WEBKIT thread to delete some of its 527 // destructor posts a message to the WEBKIT thread to delete some of its
559 // member variables. We need to ensure that the browser context is 528 // member variables. We need to ensure that the browser context is
560 // destroyed, and that the message loop is cleared out, before destroying 529 // destroyed, and that the message loop is cleared out, before destroying
561 // the threads and loop. Otherwise we leak memory. 530 // the threads and loop. Otherwise we leak memory.
562 browser_context_.reset(); 531 browser_context_.reset();
563 base::RunLoop().RunUntilIdle(); 532 base::RunLoop().RunUntilIdle();
564 } 533 }
565 534
566 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin, 535 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin,
567 const base::Time& delete_end, 536 const base::Time& delete_end,
568 int remove_mask, 537 int remove_mask,
569 bool include_protected_origins) { 538 bool include_protected_origins) {
570 TestStoragePartition storage_partition; 539 TestStoragePartition storage_partition;
571 remover_->OverrideStoragePartitionForTesting(&storage_partition); 540 remover_->OverrideStoragePartitionForTesting(&storage_partition);
572 541
573 int origin_type_mask = BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB; 542 int origin_type_mask = BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB;
574 if (include_protected_origins) 543 if (include_protected_origins)
575 origin_type_mask |= BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB; 544 origin_type_mask |= BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB;
576 545
577 BrowsingDataRemoverCompletionObserver completion_observer(remover_); 546 BrowsingDataRemoverCompletionObserver completion_observer(remover_);
578 remover_->RemoveAndReply( 547 remover_->RemoveAndReply(delete_begin, delete_end, remove_mask,
579 delete_begin, delete_end, remove_mask, origin_type_mask, 548 origin_type_mask, &completion_observer);
580 &completion_observer);
581 completion_observer.BlockUntilCompletion(); 549 completion_observer.BlockUntilCompletion();
582 550
583 // Save so we can verify later. 551 // Save so we can verify later.
584 storage_partition_removal_data_ = 552 storage_partition_removal_data_ =
585 storage_partition.GetStoragePartitionRemovalData(); 553 storage_partition.GetStoragePartitionRemovalData();
586 } 554 }
587 555
588 void BlockUntilOriginDataRemoved( 556 void BlockUntilOriginDataRemoved(
589 const base::Time& delete_begin, 557 const base::Time& delete_begin,
590 const base::Time& delete_end, 558 const base::Time& delete_end,
591 int remove_mask, 559 int remove_mask,
592 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) { 560 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder) {
593 TestStoragePartition storage_partition; 561 TestStoragePartition storage_partition;
594 remover_->OverrideStoragePartitionForTesting(&storage_partition); 562 remover_->OverrideStoragePartitionForTesting(&storage_partition);
595 563
596 BrowsingDataRemoverCompletionObserver completion_observer(remover_); 564 BrowsingDataRemoverCompletionObserver completion_observer(remover_);
597 remover_->RemoveWithFilterAndReply( 565 remover_->RemoveWithFilterAndReply(
598 delete_begin, delete_end, remove_mask, 566 delete_begin, delete_end, remove_mask,
599 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, 567 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
600 std::move(filter_builder), &completion_observer); 568 std::move(filter_builder), &completion_observer);
601 completion_observer.BlockUntilCompletion(); 569 completion_observer.BlockUntilCompletion();
602 570
603 // Save so we can verify later. 571 // Save so we can verify later.
604 storage_partition_removal_data_ = 572 storage_partition_removal_data_ =
605 storage_partition.GetStoragePartitionRemovalData(); 573 storage_partition.GetStoragePartitionRemovalData();
606 } 574 }
607 575
608 BrowserContext* GetBrowserContext() { 576 BrowserContext* GetBrowserContext() { return browser_context_.get(); }
609 return browser_context_.get();
610 }
611 577
612 void DestroyBrowserContext() { browser_context_.reset(); } 578 void DestroyBrowserContext() { browser_context_.reset(); }
613 579
614 const base::Time& GetBeginTime() { 580 const base::Time& GetBeginTime() { return remover_->GetLastUsedBeginTime(); }
615 return remover_->GetLastUsedBeginTime();
616 }
617 581
618 int GetRemovalMask() { 582 int GetRemovalMask() { return remover_->GetLastUsedRemovalMask(); }
619 return remover_->GetLastUsedRemovalMask();
620 }
621 583
622 int GetOriginTypeMask() { 584 int GetOriginTypeMask() { return remover_->GetLastUsedOriginTypeMask(); }
623 return remover_->GetLastUsedOriginTypeMask();
624 }
625 585
626 StoragePartitionRemovalData GetStoragePartitionRemovalData() { 586 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
627 return storage_partition_removal_data_; 587 return storage_partition_removal_data_;
628 } 588 }
629 589
630 content::MockSpecialStoragePolicy* CreateMockPolicy() { 590 MockSpecialStoragePolicy* CreateMockPolicy() {
631 mock_policy_ = new content::MockSpecialStoragePolicy(); 591 mock_policy_ = new MockSpecialStoragePolicy();
632 return mock_policy_.get(); 592 return mock_policy_.get();
633 } 593 }
634 594
635 content::MockSpecialStoragePolicy* mock_policy() { 595 MockSpecialStoragePolicy* mock_policy() { return mock_policy_.get(); }
636 return mock_policy_.get();
637 }
638 596
639 bool Match(const GURL& origin, 597 bool Match(const GURL& origin,
640 int mask, 598 int mask,
641 storage::SpecialStoragePolicy* policy) { 599 storage::SpecialStoragePolicy* policy) {
642 return remover_->DoesOriginMatchMask(mask, origin, policy); 600 return remover_->DoesOriginMatchMask(mask, origin, policy);
643 } 601 }
644 602
645 private: 603 private:
646 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods. 604 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods.
647 BrowsingDataRemoverImpl* remover_; 605 BrowsingDataRemoverImpl* remover_;
648 606
649 content::TestBrowserThreadBundle thread_bundle_; 607 TestBrowserThreadBundle thread_bundle_;
650 std::unique_ptr<BrowserContext> browser_context_; 608 std::unique_ptr<BrowserContext> browser_context_;
651 609
652 StoragePartitionRemovalData storage_partition_removal_data_; 610 StoragePartitionRemovalData storage_partition_removal_data_;
653 611
654 scoped_refptr<content::MockSpecialStoragePolicy> mock_policy_; 612 scoped_refptr<MockSpecialStoragePolicy> mock_policy_;
655 613
656 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImplTest); 614 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImplTest);
657 }; 615 };
658 616
659 // Tests --------------------------------------------------------------------- 617 // Tests ---------------------------------------------------------------------
660 618
661 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieForever) { 619 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieForever) {
662 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 620 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
663 BrowsingDataRemover::DATA_TYPE_COOKIES, false); 621 BrowsingDataRemover::DATA_TYPE_COOKIES, false);
664 622
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2))); 684 EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2)));
727 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin3))); 685 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin3)));
728 // This is false, because this is the same domain as 3, just with a different 686 // This is false, because this is the same domain as 3, just with a different
729 // scheme. 687 // scheme.
730 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4))); 688 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4)));
731 } 689 }
732 690
733 // Test that removing cookies clears HTTP auth data. 691 // Test that removing cookies clears HTTP auth data.
734 TEST_F(BrowsingDataRemoverImplTest, ClearHttpAuthCache_RemoveCookies) { 692 TEST_F(BrowsingDataRemoverImplTest, ClearHttpAuthCache_RemoveCookies) {
735 net::HttpNetworkSession* http_session = 693 net::HttpNetworkSession* http_session =
736 content::BrowserContext::GetDefaultStoragePartition(GetBrowserContext()) 694 BrowserContext::GetDefaultStoragePartition(GetBrowserContext())
737 ->GetURLRequestContext() 695 ->GetURLRequestContext()
738 ->GetURLRequestContext() 696 ->GetURLRequestContext()
739 ->http_transaction_factory() 697 ->http_transaction_factory()
740 ->GetSession(); 698 ->GetSession();
741 DCHECK(http_session); 699 DCHECK(http_session);
742 700
743 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache(); 701 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache();
744 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC, 702 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC,
745 "test challenge", 703 "test challenge",
746 net::AuthCredentials(base::ASCIIToUTF16("foo"), 704 net::AuthCredentials(base::ASCIIToUTF16("foo"),
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS, 772 BrowsingDataRemover::DATA_TYPE_CHANNEL_IDS,
815 std::move(filter_builder)); 773 std::move(filter_builder));
816 774
817 EXPECT_EQ(1, tester.ChannelIDCount()); 775 EXPECT_EQ(1, tester.ChannelIDCount());
818 net::ChannelIDStore::ChannelIDList channel_ids; 776 net::ChannelIDStore::ChannelIDList channel_ids;
819 tester.GetChannelIDList(&channel_ids); 777 tester.GetChannelIDList(&channel_ids);
820 EXPECT_EQ(kTestRegisterableDomain3, channel_ids.front().server_identifier()); 778 EXPECT_EQ(kTestRegisterableDomain3, channel_ids.front().server_identifier());
821 } 779 }
822 780
823 TEST_F(BrowsingDataRemoverImplTest, RemoveUnprotectedLocalStorageForever) { 781 TEST_F(BrowsingDataRemoverImplTest, RemoveUnprotectedLocalStorageForever) {
824 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); 782 MockSpecialStoragePolicy* policy = CreateMockPolicy();
825 // Protect kOrigin1. 783 // Protect kOrigin1.
826 policy->AddProtected(kOrigin1.GetOrigin()); 784 policy->AddProtected(kOrigin1.GetOrigin());
827 785
828 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 786 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
829 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, 787 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE,
830 false); 788 false);
831 789
832 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); 790 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask());
833 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, 791 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
834 GetOriginTypeMask()); 792 GetOriginTypeMask());
835 793
836 // Verify that storage partition was instructed to remove the data correctly. 794 // Verify that storage partition was instructed to remove the data correctly.
837 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 795 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
838 EXPECT_EQ(removal_data.remove_mask, 796 EXPECT_EQ(removal_data.remove_mask,
839 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); 797 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
840 EXPECT_EQ(removal_data.quota_storage_remove_mask, 798 EXPECT_EQ(removal_data.quota_storage_remove_mask,
841 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 799 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
842 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 800 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
843 801
844 // Check origin matcher. 802 // Check origin matcher.
845 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 803 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
846 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 804 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
847 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 805 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
848 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); 806 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
849 } 807 }
850 808
851 TEST_F(BrowsingDataRemoverImplTest, RemoveProtectedLocalStorageForever) { 809 TEST_F(BrowsingDataRemoverImplTest, RemoveProtectedLocalStorageForever) {
852 // Protect kOrigin1. 810 // Protect kOrigin1.
853 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); 811 MockSpecialStoragePolicy* policy = CreateMockPolicy();
854 policy->AddProtected(kOrigin1.GetOrigin()); 812 policy->AddProtected(kOrigin1.GetOrigin());
855 813
856 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 814 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
857 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, 815 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE,
858 true); 816 true);
859 817
860 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); 818 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask());
861 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | 819 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
862 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, 820 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB,
863 GetOriginTypeMask()); 821 GetOriginTypeMask());
864 822
865 // Verify that storage partition was instructed to remove the data correctly. 823 // Verify that storage partition was instructed to remove the data correctly.
866 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 824 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
867 EXPECT_EQ(removal_data.remove_mask, 825 EXPECT_EQ(removal_data.remove_mask,
868 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); 826 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
869 EXPECT_EQ(removal_data.quota_storage_remove_mask, 827 EXPECT_EQ(removal_data.quota_storage_remove_mask,
870 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 828 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
871 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 829 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
872 830
873 // Check origin matcher all http origin will match since we specified 831 // Check origin matcher all http origin will match since we specified
874 // both protected and unprotected. 832 // both protected and unprotected.
875 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 833 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
876 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 834 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
877 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 835 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
878 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); 836 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
879 } 837 }
880 838
881 TEST_F(BrowsingDataRemoverImplTest, RemoveLocalStorageForLastWeek) { 839 TEST_F(BrowsingDataRemoverImplTest, RemoveLocalStorageForLastWeek) {
882 #if BUILDFLAG(ENABLE_EXTENSIONS)
883 CreateMockPolicy(); 840 CreateMockPolicy();
884 #endif
885 841
886 BlockUntilBrowsingDataRemoved( 842 BlockUntilBrowsingDataRemoved(
887 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(), 843 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(),
888 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, false); 844 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, false);
889 845
890 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask()); 846 EXPECT_EQ(BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, GetRemovalMask());
891 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, 847 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
892 GetOriginTypeMask()); 848 GetOriginTypeMask());
893 849
894 // Verify that storage partition was instructed to remove the data correctly. 850 // Verify that storage partition was instructed to remove the data correctly.
(...skipping 15 matching lines...) Expand all
910 TEST_F(BrowsingDataRemoverImplTest, RemoveMultipleTypes) { 866 TEST_F(BrowsingDataRemoverImplTest, RemoveMultipleTypes) {
911 // Downloads should be deleted through the DownloadManager, assure it would 867 // Downloads should be deleted through the DownloadManager, assure it would
912 // be called. 868 // be called.
913 RemoveDownloadsTester downloads_tester(GetBrowserContext()); 869 RemoveDownloadsTester downloads_tester(GetBrowserContext());
914 EXPECT_CALL(*downloads_tester.download_manager(), 870 EXPECT_CALL(*downloads_tester.download_manager(),
915 RemoveDownloadsByURLAndTime(_, _, _)); 871 RemoveDownloadsByURLAndTime(_, _, _));
916 872
917 int removal_mask = BrowsingDataRemover::DATA_TYPE_DOWNLOADS | 873 int removal_mask = BrowsingDataRemover::DATA_TYPE_DOWNLOADS |
918 BrowsingDataRemover::DATA_TYPE_COOKIES; 874 BrowsingDataRemover::DATA_TYPE_COOKIES;
919 875
920 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 876 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), removal_mask,
921 removal_mask, false); 877 false);
922 878
923 EXPECT_EQ(removal_mask, GetRemovalMask()); 879 EXPECT_EQ(removal_mask, GetRemovalMask());
924 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, 880 EXPECT_EQ(BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB,
925 GetOriginTypeMask()); 881 GetOriginTypeMask());
926 882
927 // The cookie would be deleted throught the StorageParition, check if the 883 // The cookie would be deleted throught the StorageParition, check if the
928 // partition was requested to remove cookie. 884 // partition was requested to remove cookie.
929 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 885 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
930 EXPECT_EQ(removal_data.remove_mask, 886 EXPECT_EQ(removal_data.remove_mask,
931 StoragePartition::REMOVE_DATA_MASK_COOKIES); 887 StoragePartition::REMOVE_DATA_MASK_COOKIES);
(...skipping 30 matching lines...) Expand all
962 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 918 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
963 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | 919 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
964 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | 920 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
965 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); 921 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
966 EXPECT_EQ(removal_data.quota_storage_remove_mask, 922 EXPECT_EQ(removal_data.quota_storage_remove_mask,
967 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 923 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
968 } 924 }
969 925
970 TEST_F(BrowsingDataRemoverImplTest, 926 TEST_F(BrowsingDataRemoverImplTest,
971 RemoveQuotaManagedDataForeverOnlyTemporary) { 927 RemoveQuotaManagedDataForeverOnlyTemporary) {
972 #if BUILDFLAG(ENABLE_EXTENSIONS)
973 CreateMockPolicy(); 928 CreateMockPolicy();
974 #endif
975 929
976 BlockUntilBrowsingDataRemoved( 930 BlockUntilBrowsingDataRemoved(
977 base::Time(), base::Time::Max(), 931 base::Time(), base::Time::Max(),
978 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | 932 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS |
979 BrowsingDataRemover::DATA_TYPE_WEB_SQL | 933 BrowsingDataRemover::DATA_TYPE_WEB_SQL |
980 BrowsingDataRemover::DATA_TYPE_APP_CACHE | 934 BrowsingDataRemover::DATA_TYPE_APP_CACHE |
981 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | 935 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS |
982 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | 936 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE |
983 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, 937 BrowsingDataRemover::DATA_TYPE_INDEXED_DB,
984 false); 938 false);
(...skipping 23 matching lines...) Expand all
1008 962
1009 // Check that all related origin data would be removed, that is, origin 963 // Check that all related origin data would be removed, that is, origin
1010 // matcher would match these origin. 964 // matcher would match these origin.
1011 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 965 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1012 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 966 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1013 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 967 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1014 } 968 }
1015 969
1016 TEST_F(BrowsingDataRemoverImplTest, 970 TEST_F(BrowsingDataRemoverImplTest,
1017 RemoveQuotaManagedDataForeverOnlyPersistent) { 971 RemoveQuotaManagedDataForeverOnlyPersistent) {
1018 #if BUILDFLAG(ENABLE_EXTENSIONS)
1019 CreateMockPolicy(); 972 CreateMockPolicy();
1020 #endif
1021 973
1022 BlockUntilBrowsingDataRemoved( 974 BlockUntilBrowsingDataRemoved(
1023 base::Time(), base::Time::Max(), 975 base::Time(), base::Time::Max(),
1024 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | 976 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS |
1025 BrowsingDataRemover::DATA_TYPE_WEB_SQL | 977 BrowsingDataRemover::DATA_TYPE_WEB_SQL |
1026 BrowsingDataRemover::DATA_TYPE_APP_CACHE | 978 BrowsingDataRemover::DATA_TYPE_APP_CACHE |
1027 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | 979 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS |
1028 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | 980 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE |
1029 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, 981 BrowsingDataRemover::DATA_TYPE_INDEXED_DB,
1030 false); 982 false);
(...skipping 22 matching lines...) Expand all
1053 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 1005 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1054 1006
1055 // Check that all related origin data would be removed, that is, origin 1007 // Check that all related origin data would be removed, that is, origin
1056 // matcher would match these origin. 1008 // matcher would match these origin.
1057 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1009 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1058 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1010 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1059 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1011 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1060 } 1012 }
1061 1013
1062 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverNeither) { 1014 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverNeither) {
1063 #if BUILDFLAG(ENABLE_EXTENSIONS)
1064 CreateMockPolicy(); 1015 CreateMockPolicy();
1065 #endif
1066 1016
1067 BlockUntilBrowsingDataRemoved( 1017 BlockUntilBrowsingDataRemoved(
1068 base::Time(), base::Time::Max(), 1018 base::Time(), base::Time::Max(),
1069 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | 1019 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS |
1070 BrowsingDataRemover::DATA_TYPE_WEB_SQL | 1020 BrowsingDataRemover::DATA_TYPE_WEB_SQL |
1071 BrowsingDataRemover::DATA_TYPE_APP_CACHE | 1021 BrowsingDataRemover::DATA_TYPE_APP_CACHE |
1072 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | 1022 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS |
1073 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | 1023 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE |
1074 BrowsingDataRemover::DATA_TYPE_INDEXED_DB, 1024 BrowsingDataRemover::DATA_TYPE_INDEXED_DB,
1075 false); 1025 false);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1224 // Persistent data would be left out since we are not removing from 1174 // Persistent data would be left out since we are not removing from
1225 // beginning of time. 1175 // beginning of time.
1226 uint32_t expected_quota_mask = 1176 uint32_t expected_quota_mask =
1227 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 1177 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1228 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); 1178 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1229 // Check removal begin time. 1179 // Check removal begin time.
1230 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 1180 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1231 } 1181 }
1232 1182
1233 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedUnprotectedOrigins) { 1183 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedUnprotectedOrigins) {
1234 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); 1184 MockSpecialStoragePolicy* policy = CreateMockPolicy();
1235 // Protect kOrigin1. 1185 // Protect kOrigin1.
1236 policy->AddProtected(kOrigin1.GetOrigin()); 1186 policy->AddProtected(kOrigin1.GetOrigin());
1237 1187
1238 BlockUntilBrowsingDataRemoved( 1188 BlockUntilBrowsingDataRemoved(
1239 base::Time(), base::Time::Max(), 1189 base::Time(), base::Time::Max(),
1240 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | 1190 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS |
1241 BrowsingDataRemover::DATA_TYPE_WEB_SQL | 1191 BrowsingDataRemover::DATA_TYPE_WEB_SQL |
1242 BrowsingDataRemover::DATA_TYPE_APP_CACHE | 1192 BrowsingDataRemover::DATA_TYPE_APP_CACHE |
1243 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | 1193 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS |
1244 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | 1194 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE |
(...skipping 23 matching lines...) Expand all
1268 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1218 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1269 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 1219 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1270 1220
1271 // Check OriginMatcherFunction. 1221 // Check OriginMatcherFunction.
1272 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1222 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1273 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1223 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1274 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1224 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1275 } 1225 }
1276 1226
1277 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedSpecificOrigin) { 1227 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedSpecificOrigin) {
1278 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); 1228 MockSpecialStoragePolicy* policy = CreateMockPolicy();
1279 // Protect kOrigin1. 1229 // Protect kOrigin1.
1280 policy->AddProtected(kOrigin1.GetOrigin()); 1230 policy->AddProtected(kOrigin1.GetOrigin());
1281 1231
1282 std::unique_ptr<BrowsingDataFilterBuilder> builder( 1232 std::unique_ptr<BrowsingDataFilterBuilder> builder(
1283 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); 1233 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST));
1284 builder->AddRegisterableDomain(kTestRegisterableDomain1); 1234 builder->AddRegisterableDomain(kTestRegisterableDomain1);
1285 1235
1286 // Try to remove kOrigin1. Expect failure. 1236 // Try to remove kOrigin1. Expect failure.
1287 BlockUntilOriginDataRemoved( 1237 BlockUntilOriginDataRemoved(
1288 base::Time(), base::Time::Max(), 1238 base::Time(), base::Time::Max(),
(...skipping 30 matching lines...) Expand all
1319 1269
1320 // Check OriginMatcherFunction. 1270 // Check OriginMatcherFunction.
1321 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1271 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1322 // Since we use the matcher function to validate origins now, this should 1272 // Since we use the matcher function to validate origins now, this should
1323 // return false for the origins we're not trying to clear. 1273 // return false for the origins we're not trying to clear.
1324 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1274 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1325 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1275 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1326 } 1276 }
1327 1277
1328 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedOrigins) { 1278 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedOrigins) {
1329 content::MockSpecialStoragePolicy* policy = CreateMockPolicy(); 1279 MockSpecialStoragePolicy* policy = CreateMockPolicy();
1330 // Protect kOrigin1. 1280 // Protect kOrigin1.
1331 policy->AddProtected(kOrigin1.GetOrigin()); 1281 policy->AddProtected(kOrigin1.GetOrigin());
1332 1282
1333 // Try to remove kOrigin1. Expect success. 1283 // Try to remove kOrigin1. Expect success.
1334 BlockUntilBrowsingDataRemoved( 1284 BlockUntilBrowsingDataRemoved(
1335 base::Time(), base::Time::Max(), 1285 base::Time(), base::Time::Max(),
1336 BrowsingDataRemover::DATA_TYPE_APP_CACHE | 1286 BrowsingDataRemover::DATA_TYPE_APP_CACHE |
1337 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | 1287 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS |
1338 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | 1288 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE |
1339 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | 1289 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS |
(...skipping 27 matching lines...) Expand all
1367 1317
1368 // Check OriginMatcherFunction, |kOrigin1| would match mask since we 1318 // Check OriginMatcherFunction, |kOrigin1| would match mask since we
1369 // would have 'protected' specified in origin_type_mask. 1319 // would have 'protected' specified in origin_type_mask.
1370 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1320 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1371 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1321 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1372 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1322 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1373 } 1323 }
1374 1324
1375 TEST_F(BrowsingDataRemoverImplTest, 1325 TEST_F(BrowsingDataRemoverImplTest,
1376 RemoveQuotaManagedIgnoreExtensionsAndDevTools) { 1326 RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
1377 #if BUILDFLAG(ENABLE_EXTENSIONS)
1378 CreateMockPolicy(); 1327 CreateMockPolicy();
1379 #endif
1380 1328
1381 BlockUntilBrowsingDataRemoved( 1329 BlockUntilBrowsingDataRemoved(
1382 base::Time(), base::Time::Max(), 1330 base::Time(), base::Time::Max(),
1383 BrowsingDataRemover::DATA_TYPE_APP_CACHE | 1331 BrowsingDataRemover::DATA_TYPE_APP_CACHE |
1384 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS | 1332 BrowsingDataRemover::DATA_TYPE_SERVICE_WORKERS |
1385 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE | 1333 BrowsingDataRemover::DATA_TYPE_CACHE_STORAGE |
1386 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS | 1334 BrowsingDataRemover::DATA_TYPE_FILE_SYSTEMS |
1387 BrowsingDataRemover::DATA_TYPE_INDEXED_DB | 1335 BrowsingDataRemover::DATA_TYPE_INDEXED_DB |
1388 BrowsingDataRemover::DATA_TYPE_WEB_SQL, 1336 BrowsingDataRemover::DATA_TYPE_WEB_SQL,
1389 false); 1337 false);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone(); 1379 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone();
1432 called_ = true; 1380 called_ = true;
1433 } 1381 }
1434 1382
1435 private: 1383 private:
1436 bool called_ = false; 1384 bool called_ = false;
1437 }; 1385 };
1438 1386
1439 TEST_F(BrowsingDataRemoverImplTest, CompletionInhibition) { 1387 TEST_F(BrowsingDataRemoverImplTest, CompletionInhibition) {
1440 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( 1388 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
1441 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); 1389 BrowserContext::GetBrowsingDataRemover(GetBrowserContext()));
1442 1390
1443 // The |completion_inhibitor| on the stack should prevent removal sessions 1391 // The |completion_inhibitor| on the stack should prevent removal sessions
1444 // from completing until after ContinueToCompletion() is called. 1392 // from completing until after ContinueToCompletion() is called.
1445 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); 1393 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover);
1446 InspectableCompletionObserver completion_observer(remover); 1394 InspectableCompletionObserver completion_observer(remover);
1447 remover->RemoveAndReply( 1395 remover->RemoveAndReply(
1448 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, 1396 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES,
1449 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); 1397 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer);
1450 1398
1451 // Process messages until the inhibitor is notified, and then some, to make 1399 // Process messages until the inhibitor is notified, and then some, to make
(...skipping 11 matching lines...) Expand all
1463 // now notified, and the notifications is sent out. 1411 // now notified, and the notifications is sent out.
1464 completion_inhibitor.ContinueToCompletion(); 1412 completion_inhibitor.ContinueToCompletion();
1465 completion_observer.BlockUntilCompletion(); 1413 completion_observer.BlockUntilCompletion();
1466 1414
1467 EXPECT_FALSE(remover->is_removing()); 1415 EXPECT_FALSE(remover->is_removing());
1468 EXPECT_TRUE(completion_observer.called()); 1416 EXPECT_TRUE(completion_observer.called());
1469 } 1417 }
1470 1418
1471 TEST_F(BrowsingDataRemoverImplTest, EarlyShutdown) { 1419 TEST_F(BrowsingDataRemoverImplTest, EarlyShutdown) {
1472 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( 1420 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
1473 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); 1421 BrowserContext::GetBrowsingDataRemover(GetBrowserContext()));
1474 InspectableCompletionObserver completion_observer(remover); 1422 InspectableCompletionObserver completion_observer(remover);
1475 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); 1423 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover);
1476 remover->RemoveAndReply( 1424 remover->RemoveAndReply(
1477 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, 1425 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES,
1478 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer); 1426 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB, &completion_observer);
1479 1427
1480 completion_inhibitor.BlockUntilNearCompletion(); 1428 completion_inhibitor.BlockUntilNearCompletion();
1481 completion_inhibitor.Reset(); 1429 completion_inhibitor.Reset();
1482 1430
1483 // Verify that the deletion has not yet been completed and the observer has 1431 // Verify that the deletion has not yet been completed and the observer has
1484 // not been called. 1432 // not been called.
1485 EXPECT_TRUE(remover->is_removing()); 1433 EXPECT_TRUE(remover->is_removing());
1486 EXPECT_FALSE(completion_observer.called()); 1434 EXPECT_FALSE(completion_observer.called());
1487 1435
1488 // Destroying the profile should trigger the notification. 1436 // Destroying the profile should trigger the notification.
1489 DestroyBrowserContext(); 1437 DestroyBrowserContext();
1490 1438
1491 EXPECT_TRUE(completion_observer.called()); 1439 EXPECT_TRUE(completion_observer.called());
1492 1440
1493 // Finishing after shutdown shouldn't break anything. 1441 // Finishing after shutdown shouldn't break anything.
1494 completion_inhibitor.ContinueToCompletion(); 1442 completion_inhibitor.ContinueToCompletion();
1495 completion_observer.BlockUntilCompletion(); 1443 completion_observer.BlockUntilCompletion();
1496 } 1444 }
1497 1445
1498 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByTimeOnly) { 1446 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByTimeOnly) {
1499 RemoveDownloadsTester tester(GetBrowserContext()); 1447 RemoveDownloadsTester tester(GetBrowserContext());
1500 base::Callback<bool(const GURL&)> filter = 1448 base::Callback<bool(const GURL&)> filter =
1501 BrowsingDataFilterBuilder::BuildNoopFilter(); 1449 BrowsingDataFilterBuilder::BuildNoopFilter();
1502 1450
1503 EXPECT_CALL( 1451 EXPECT_CALL(*tester.download_manager(),
1504 *tester.download_manager(), 1452 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
1505 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
1506 1453
1507 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 1454 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1508 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, 1455 BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
1509 false); 1456 false);
1510 } 1457 }
1511 1458
1512 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByOrigin) { 1459 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByOrigin) {
1513 RemoveDownloadsTester tester(GetBrowserContext()); 1460 RemoveDownloadsTester tester(GetBrowserContext());
1514 std::unique_ptr<BrowsingDataFilterBuilder> builder( 1461 std::unique_ptr<BrowsingDataFilterBuilder> builder(
1515 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); 1462 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST));
1516 builder->AddRegisterableDomain(kTestRegisterableDomain1); 1463 builder->AddRegisterableDomain(kTestRegisterableDomain1);
1517 base::Callback<bool(const GURL&)> filter = builder->BuildGeneralFilter(); 1464 base::Callback<bool(const GURL&)> filter = builder->BuildGeneralFilter();
1518 1465
1519 EXPECT_CALL( 1466 EXPECT_CALL(*tester.download_manager(),
1520 *tester.download_manager(), 1467 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
1521 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
1522 1468
1523 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), 1469 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1524 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, 1470 BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
1525 std::move(builder)); 1471 std::move(builder));
1526 } 1472 }
1527 1473
1528 class MultipleTasksObserver { 1474 class MultipleTasksObserver {
1529 public: 1475 public:
1530 // A simple implementation of BrowsingDataRemover::Observer. 1476 // A simple implementation of BrowsingDataRemover::Observer.
1531 // MultipleTasksObserver will use several instances of Target to test 1477 // MultipleTasksObserver will use several instances of Target to test
1532 // that completion callbacks are returned to the correct one. 1478 // that completion callbacks are returned to the correct one.
1533 class Target : public BrowsingDataRemover::Observer { 1479 class Target : public BrowsingDataRemover::Observer {
1534 public: 1480 public:
1535 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover) 1481 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover)
1536 : parent_(parent), 1482 : parent_(parent), observer_(this) {
1537 observer_(this) {
1538 observer_.Add(remover); 1483 observer_.Add(remover);
1539 } 1484 }
1540 ~Target() override {} 1485 ~Target() override {}
1541 1486
1542 void OnBrowsingDataRemoverDone() override { 1487 void OnBrowsingDataRemoverDone() override {
1543 parent_->SetLastCalledTarget(this); 1488 parent_->SetLastCalledTarget(this);
1544 } 1489 }
1545 1490
1546 private: 1491 private:
1547 MultipleTasksObserver* parent_; 1492 MultipleTasksObserver* parent_;
1548 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer> 1493 ScopedObserver<BrowsingDataRemover, BrowsingDataRemover::Observer>
1549 observer_; 1494 observer_;
1550 }; 1495 };
1551 1496
1552 explicit MultipleTasksObserver(BrowsingDataRemover* remover) 1497 explicit MultipleTasksObserver(BrowsingDataRemover* remover)
1553 : target_a_(this, remover), 1498 : target_a_(this, remover),
1554 target_b_(this, remover), 1499 target_b_(this, remover),
1555 last_called_target_(nullptr) {} 1500 last_called_target_(nullptr) {}
1556 ~MultipleTasksObserver() {} 1501 ~MultipleTasksObserver() {}
1557 1502
1558 void ClearLastCalledTarget() { 1503 void ClearLastCalledTarget() { last_called_target_ = nullptr; }
1559 last_called_target_ = nullptr;
1560 }
1561 1504
1562 Target* GetLastCalledTarget() { 1505 Target* GetLastCalledTarget() { return last_called_target_; }
1563 return last_called_target_;
1564 }
1565 1506
1566 Target* target_a() { return &target_a_; } 1507 Target* target_a() { return &target_a_; }
1567 Target* target_b() { return &target_b_; } 1508 Target* target_b() { return &target_b_; }
1568 1509
1569 private: 1510 private:
1570 void SetLastCalledTarget(Target* target) { 1511 void SetLastCalledTarget(Target* target) {
1571 DCHECK(!last_called_target_) 1512 DCHECK(!last_called_target_)
1572 << "Call ClearLastCalledTarget() before every removal task."; 1513 << "Call ClearLastCalledTarget() before every removal task.";
1573 last_called_target_ = target; 1514 last_called_target_ = target;
1574 } 1515 }
1575 1516
1576 Target target_a_; 1517 Target target_a_;
1577 Target target_b_; 1518 Target target_b_;
1578 Target* last_called_target_; 1519 Target* last_called_target_;
1579 }; 1520 };
1580 1521
1581 TEST_F(BrowsingDataRemoverImplTest, MultipleTasks) { 1522 TEST_F(BrowsingDataRemoverImplTest, MultipleTasks) {
1582 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( 1523 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
1583 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); 1524 BrowserContext::GetBrowsingDataRemover(GetBrowserContext()));
1584 EXPECT_FALSE(remover->is_removing()); 1525 EXPECT_FALSE(remover->is_removing());
1585 1526
1586 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_1( 1527 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_1(
1587 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST)); 1528 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::WHITELIST));
1588 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_2( 1529 std::unique_ptr<BrowsingDataFilterBuilder> filter_builder_2(
1589 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST)); 1530 BrowsingDataFilterBuilder::Create(BrowsingDataFilterBuilder::BLACKLIST));
1590 filter_builder_2->AddRegisterableDomain("example.com"); 1531 filter_builder_2->AddRegisterableDomain("example.com");
1591 1532
1592 MultipleTasksObserver observer(remover); 1533 MultipleTasksObserver observer(remover);
1593 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover); 1534 BrowsingDataRemoverCompletionInhibitor completion_inhibitor(remover);
(...skipping 27 matching lines...) Expand all
1621 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB | 1562 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB |
1622 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB, 1563 BrowsingDataRemover::ORIGIN_TYPE_PROTECTED_WEB,
1623 std::move(filter_builder_2), nullptr); 1564 std::move(filter_builder_2), nullptr);
1624 1565
1625 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { 1566 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) {
1626 // All tasks can be directly translated to a RemoveInternal() call. Since 1567 // All tasks can be directly translated to a RemoveInternal() call. Since
1627 // that is a private method, we must call the four public versions of 1568 // that is a private method, we must call the four public versions of
1628 // Remove.* instead. This also serves as a test that those methods are all 1569 // Remove.* instead. This also serves as a test that those methods are all
1629 // correctly reduced to RemoveInternal(). 1570 // correctly reduced to RemoveInternal().
1630 if (!task.observer && task.filter_builder->IsEmptyBlacklist()) { 1571 if (!task.observer && task.filter_builder->IsEmptyBlacklist()) {
1631 remover->Remove(task.delete_begin, task.delete_end, 1572 remover->Remove(task.delete_begin, task.delete_end, task.remove_mask,
1632 task.remove_mask, task.origin_type_mask); 1573 task.origin_type_mask);
1633 } else if (task.filter_builder->IsEmptyBlacklist()) { 1574 } else if (task.filter_builder->IsEmptyBlacklist()) {
1634 remover->RemoveAndReply(task.delete_begin, task.delete_end, 1575 remover->RemoveAndReply(task.delete_begin, task.delete_end,
1635 task.remove_mask, task.origin_type_mask, 1576 task.remove_mask, task.origin_type_mask,
1636 task.observer); 1577 task.observer);
1637 } else if (!task.observer) { 1578 } else if (!task.observer) {
1638 remover->RemoveWithFilter(task.delete_begin, task.delete_end, 1579 remover->RemoveWithFilter(task.delete_begin, task.delete_end,
1639 task.remove_mask, task.origin_type_mask, 1580 task.remove_mask, task.origin_type_mask,
1640 std::move(task.filter_builder)); 1581 std::move(task.filter_builder));
1641 } else { 1582 } else {
1642 remover->RemoveWithFilterAndReply(task.delete_begin, task.delete_end, 1583 remover->RemoveWithFilterAndReply(
1643 task.remove_mask, task.origin_type_mask, 1584 task.delete_begin, task.delete_end, task.remove_mask,
1644 std::move(task.filter_builder), 1585 task.origin_type_mask, std::move(task.filter_builder), task.observer);
1645 task.observer);
1646 } 1586 }
1647 } 1587 }
1648 1588
1649 // Use the inhibitor to stop after every task and check the results. 1589 // Use the inhibitor to stop after every task and check the results.
1650 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) { 1590 for (BrowsingDataRemoverImpl::RemovalTask& task : tasks) {
1651 EXPECT_TRUE(remover->is_removing()); 1591 EXPECT_TRUE(remover->is_removing());
1652 observer.ClearLastCalledTarget(); 1592 observer.ClearLastCalledTarget();
1653 1593
1654 // Finish the task execution synchronously. 1594 // Finish the task execution synchronously.
1655 completion_inhibitor.BlockUntilNearCompletion(); 1595 completion_inhibitor.BlockUntilNearCompletion();
(...skipping 13 matching lines...) Expand all
1669 EXPECT_FALSE(remover->is_removing()); 1609 EXPECT_FALSE(remover->is_removing());
1670 } 1610 }
1671 1611
1672 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the 1612 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the
1673 // tasks are not mixed up and they are executed in a correct order. However, 1613 // tasks are not mixed up and they are executed in a correct order. However,
1674 // the completion inhibitor kept synchronizing the execution in order to verify 1614 // the completion inhibitor kept synchronizing the execution in order to verify
1675 // the parameters. This test demonstrates that even running the tasks without 1615 // the parameters. This test demonstrates that even running the tasks without
1676 // inhibition is executed correctly and doesn't crash. 1616 // inhibition is executed correctly and doesn't crash.
1677 TEST_F(BrowsingDataRemoverImplTest, MultipleTasksInQuickSuccession) { 1617 TEST_F(BrowsingDataRemoverImplTest, MultipleTasksInQuickSuccession) {
1678 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( 1618 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
1679 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext())); 1619 BrowserContext::GetBrowsingDataRemover(GetBrowserContext()));
1680 EXPECT_FALSE(remover->is_removing()); 1620 EXPECT_FALSE(remover->is_removing());
1681 1621
1682 int test_removal_masks[] = { 1622 int test_removal_masks[] = {
1683 BrowsingDataRemover::DATA_TYPE_COOKIES, 1623 BrowsingDataRemover::DATA_TYPE_COOKIES,
1684 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE, 1624 BrowsingDataRemover::DATA_TYPE_LOCAL_STORAGE,
1685 BrowsingDataRemover::DATA_TYPE_COOKIES, 1625 BrowsingDataRemover::DATA_TYPE_COOKIES,
1686 BrowsingDataRemover::DATA_TYPE_COOKIES, 1626 BrowsingDataRemover::DATA_TYPE_COOKIES,
1687 BrowsingDataRemover::DATA_TYPE_COOKIES, 1627 BrowsingDataRemover::DATA_TYPE_COOKIES,
1688 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, 1628 BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
1689 BrowsingDataRemover::DATA_TYPE_DOWNLOADS, 1629 BrowsingDataRemover::DATA_TYPE_DOWNLOADS,
(...skipping 16 matching lines...) Expand all
1706 1646
1707 EXPECT_TRUE(remover->is_removing()); 1647 EXPECT_TRUE(remover->is_removing());
1708 1648
1709 // Add one more deletion and wait for it. 1649 // Add one more deletion and wait for it.
1710 BlockUntilBrowsingDataRemoved( 1650 BlockUntilBrowsingDataRemoved(
1711 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES, 1651 base::Time(), base::Time::Max(), BrowsingDataRemover::DATA_TYPE_COOKIES,
1712 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB); 1652 BrowsingDataRemover::ORIGIN_TYPE_UNPROTECTED_WEB);
1713 1653
1714 EXPECT_FALSE(remover->is_removing()); 1654 EXPECT_FALSE(remover->is_removing());
1715 } 1655 }
1656
1657 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/browsing_data/browsing_data_remover_impl.cc ('k') | content/public/browser/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698