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

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

Issue 2651673002: Reland "Split BrowsingDataRemoverTest into two tests for Impl and Delegate." (Closed)
Patch Set: Added a TODO. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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>
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/bind_helpers.h" 16 #include "base/bind_helpers.h"
17 #include "base/files/file_path.h" 17 #include "base/files/file_path.h"
18 #include "base/files/file_util.h" 18 #include "base/files/file_util.h"
19 #include "base/guid.h"
20 #include "base/location.h" 19 #include "base/location.h"
21 #include "base/logging.h" 20 #include "base/logging.h"
22 #include "base/macros.h" 21 #include "base/macros.h"
23 #include "base/memory/ptr_util.h" 22 #include "base/memory/ptr_util.h"
24 #include "base/message_loop/message_loop.h" 23 #include "base/message_loop/message_loop.h"
25 #include "base/run_loop.h" 24 #include "base/run_loop.h"
26 #include "base/single_thread_task_runner.h" 25 #include "base/single_thread_task_runner.h"
27 #include "base/strings/string_number_conversions.h"
28 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
29 #include "base/task/cancelable_task_tracker.h" 27 #include "base/task/cancelable_task_tracker.h"
30 #include "base/threading/thread_task_runner_handle.h" 28 #include "base/threading/thread_task_runner_handle.h"
31 #include "build/build_config.h" 29 #include "build/build_config.h"
32 #include "chrome/browser/autofill/personal_data_manager_factory.h"
33 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
34 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" 30 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
35 #include "chrome/browser/browsing_data/browsing_data_helper.h" 31 #include "chrome/browser/browsing_data/browsing_data_helper.h"
36 #include "chrome/browser/browsing_data/browsing_data_remover.h" 32 #include "chrome/browser/browsing_data/browsing_data_remover.h"
37 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 33 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
38 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h" 34 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h"
39 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" 35 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
40 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
41 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h" 36 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
42 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
43 #include "chrome/browser/domain_reliability/service_factory.h"
44 #include "chrome/browser/download/chrome_download_manager_delegate.h"
45 #include "chrome/browser/favicon/favicon_service_factory.h"
46 #include "chrome/browser/history/history_service_factory.h"
47 #include "chrome/browser/password_manager/password_store_factory.h"
48 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
49 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
50 #include "chrome/browser/storage/durable_storage_permission_context.h"
51 #include "chrome/common/pref_names.h"
52 #include "chrome/test/base/testing_browser_process.h"
53 #include "chrome/test/base/testing_profile.h" 37 #include "chrome/test/base/testing_profile.h"
54 #include "components/autofill/core/browser/autofill_profile.h"
55 #include "components/autofill/core/browser/autofill_test_utils.h"
56 #include "components/autofill/core/browser/credit_card.h"
57 #include "components/autofill/core/browser/personal_data_manager.h"
58 #include "components/autofill/core/browser/personal_data_manager_observer.h"
59 #include "components/autofill/core/common/autofill_constants.h"
60 #include "components/bookmarks/browser/bookmark_model.h"
61 #include "components/bookmarks/test/bookmark_test_helpers.h"
62 #include "components/browsing_data/core/browsing_data_utils.h"
63 #include "components/content_settings/core/browser/host_content_settings_map.h"
64 #include "components/content_settings/core/common/content_settings.h"
65 #include "components/content_settings/core/common/content_settings_pattern.h"
66 #include "components/domain_reliability/clear_mode.h"
67 #include "components/domain_reliability/monitor.h"
68 #include "components/domain_reliability/service.h"
69 #include "components/favicon/core/favicon_service.h"
70 #include "components/history/core/browser/history_service.h"
71 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h"
72 #include "components/omnibox/browser/omnibox_pref_names.h"
73 #include "components/os_crypt/os_crypt_mocker.h"
74 #include "components/password_manager/core/browser/mock_password_store.h"
75 #include "components/password_manager/core/browser/password_manager_test_utils.h "
76 #include "components/password_manager/core/browser/password_store_consumer.h"
77 #include "components/prefs/testing_pref_service.h"
78 #include "content/public/browser/browser_context.h" 38 #include "content/public/browser/browser_context.h"
79 #include "content/public/browser/cookie_store_factory.h" 39 #include "content/public/browser/cookie_store_factory.h"
80 #include "content/public/browser/dom_storage_context.h" 40 #include "content/public/browser/dom_storage_context.h"
81 #include "content/public/browser/local_storage_usage_info.h" 41 #include "content/public/browser/local_storage_usage_info.h"
82 #include "content/public/browser/permission_type.h" 42 #include "content/public/browser/permission_type.h"
83 #include "content/public/browser/storage_partition.h" 43 #include "content/public/browser/storage_partition.h"
84 #include "content/public/test/mock_download_manager.h" 44 #include "content/public/test/mock_download_manager.h"
85 #include "content/public/test/test_browser_thread.h" 45 #include "content/public/test/test_browser_thread.h"
86 #include "content/public/test/test_browser_thread_bundle.h" 46 #include "content/public/test/test_browser_thread_bundle.h"
87 #include "content/public/test/test_utils.h" 47 #include "content/public/test/test_utils.h"
88 #include "extensions/features/features.h" 48 #include "extensions/features/features.h"
89 #include "net/cookies/cookie_store.h" 49 #include "net/cookies/cookie_store.h"
90 #include "net/http/http_network_session.h" 50 #include "net/http/http_network_session.h"
91 #include "net/http/http_transaction_factory.h" 51 #include "net/http/http_transaction_factory.h"
92 #include "net/ssl/channel_id_service.h" 52 #include "net/ssl/channel_id_service.h"
93 #include "net/ssl/channel_id_store.h" 53 #include "net/ssl/channel_id_store.h"
94 #include "net/ssl/ssl_client_cert_type.h" 54 #include "net/ssl/ssl_client_cert_type.h"
95 #include "net/url_request/url_request_context.h" 55 #include "net/url_request/url_request_context.h"
96 #include "net/url_request/url_request_context_getter.h" 56 #include "net/url_request/url_request_context_getter.h"
97 #include "ppapi/features/features.h" 57 #include "ppapi/features/features.h"
98 #include "testing/gmock/include/gmock/gmock.h" 58 #include "testing/gmock/include/gmock/gmock.h"
99 #include "testing/gtest/include/gtest/gtest.h" 59 #include "testing/gtest/include/gtest/gtest.h"
100 #include "third_party/skia/include/core/SkBitmap.h"
101 #include "ui/gfx/favicon_size.h"
102 #include "url/origin.h" 60 #include "url/origin.h"
103 61
104 #if defined(OS_ANDROID)
105 #include "chrome/browser/android/webapps/webapp_registry.h"
106 #endif
107
108 #if defined(OS_CHROMEOS)
109 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
110 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
111 #include "chrome/browser/chromeos/settings/cros_settings.h"
112 #include "chrome/browser/chromeos/settings/device_settings_service.h"
113 #include "chromeos/dbus/dbus_thread_manager.h"
114 #include "chromeos/dbus/mock_cryptohome_client.h"
115 #include "components/signin/core/account_id/account_id.h"
116 #endif
117
118 #if BUILDFLAG(ENABLE_EXTENSIONS) 62 #if BUILDFLAG(ENABLE_EXTENSIONS)
119 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" 63 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
120 #endif 64 #endif
121 65
122 #if BUILDFLAG(ENABLE_PLUGINS)
123 #include "chrome/browser/browsing_data/mock_browsing_data_flash_lso_helper.h"
124 #endif
125
126 class MockExtensionSpecialStoragePolicy; 66 class MockExtensionSpecialStoragePolicy;
127 67
128 using content::BrowserThread; 68 using content::BrowserThread;
69 using content::BrowserContext;
129 using content::StoragePartition; 70 using content::StoragePartition;
130 using domain_reliability::CLEAR_BEACONS;
131 using domain_reliability::CLEAR_CONTEXTS;
132 using domain_reliability::DomainReliabilityClearMode;
133 using domain_reliability::DomainReliabilityMonitor;
134 using domain_reliability::DomainReliabilityService;
135 using domain_reliability::DomainReliabilityServiceFactory;
136 using testing::_; 71 using testing::_;
137 using testing::ByRef; 72 using testing::ByRef;
138 using testing::Eq; 73 using testing::Eq;
139 using testing::Invoke; 74 using testing::Invoke;
140 using testing::IsEmpty; 75 using testing::IsEmpty;
141 using testing::Matcher; 76 using testing::Matcher;
142 using testing::MakeMatcher; 77 using testing::MakeMatcher;
143 using testing::MatcherInterface; 78 using testing::MatcherInterface;
144 using testing::MatchResultListener; 79 using testing::MatchResultListener;
145 using testing::Not; 80 using testing::Not;
146 using testing::Return; 81 using testing::Return;
147 using testing::SizeIs; 82 using testing::SizeIs;
148 using testing::WithArgs; 83 using testing::WithArgs;
149 84
150 namespace { 85 namespace {
151 86
152 const char kTestOrigin1[] = "http://host1.com:1/"; 87 const char kTestOrigin1[] = "http://host1.com:1/";
153 const char kTestRegisterableDomain1[] = "host1.com"; 88 const char kTestRegisterableDomain1[] = "host1.com";
154 const char kTestOrigin2[] = "http://host2.com:1/"; 89 const char kTestOrigin2[] = "http://host2.com:1/";
155 const char kTestOrigin3[] = "http://host3.com:1/"; 90 const char kTestOrigin3[] = "http://host3.com:1/";
156 const char kTestRegisterableDomain3[] = "host3.com"; 91 const char kTestRegisterableDomain3[] = "host3.com";
157 const char kTestOrigin4[] = "https://host3.com:1/"; 92 const char kTestOrigin4[] = "https://host3.com:1/";
158 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; 93 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
159 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; 94 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
160 95
161 // For Autofill.
162 const char kWebOrigin[] = "https://www.example.com/";
163
164 // For HTTP auth. 96 // For HTTP auth.
165 const char kTestRealm[] = "TestRealm"; 97 const char kTestRealm[] = "TestRealm";
166 98
167 const GURL kOrigin1(kTestOrigin1); 99 const GURL kOrigin1(kTestOrigin1);
168 const GURL kOrigin2(kTestOrigin2); 100 const GURL kOrigin2(kTestOrigin2);
169 const GURL kOrigin3(kTestOrigin3); 101 const GURL kOrigin3(kTestOrigin3);
170 const GURL kOrigin4(kTestOrigin4); 102 const GURL kOrigin4(kTestOrigin4);
171 const GURL kOriginExt(kTestOriginExt); 103 const GURL kOriginExt(kTestOriginExt);
172 const GURL kOriginDevTools(kTestOriginDevTools); 104 const GURL kOriginDevTools(kTestOriginDevTools);
173 105
174 const base::FilePath::CharType kDomStorageOrigin1[] = 106 const base::FilePath::CharType kDomStorageOrigin1[] =
175 FILE_PATH_LITERAL("http_host1_1.localstorage"); 107 FILE_PATH_LITERAL("http_host1_1.localstorage");
176 108
177 const base::FilePath::CharType kDomStorageOrigin2[] = 109 const base::FilePath::CharType kDomStorageOrigin2[] =
178 FILE_PATH_LITERAL("http_host2_1.localstorage"); 110 FILE_PATH_LITERAL("http_host2_1.localstorage");
179 111
180 const base::FilePath::CharType kDomStorageOrigin3[] = 112 const base::FilePath::CharType kDomStorageOrigin3[] =
181 FILE_PATH_LITERAL("http_host3_1.localstorage"); 113 FILE_PATH_LITERAL("http_host3_1.localstorage");
182 114
183 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL( 115 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL(
184 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage"); 116 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
185 117
186 #if defined(OS_CHROMEOS)
187 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
188 base::ThreadTaskRunnerHandle::Get()->PostTask(
189 FROM_HERE,
190 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true));
191 }
192 #endif
193
194 struct StoragePartitionRemovalData { 118 struct StoragePartitionRemovalData {
195 uint32_t remove_mask = 0; 119 uint32_t remove_mask = 0;
196 uint32_t quota_storage_remove_mask = 0; 120 uint32_t quota_storage_remove_mask = 0;
197 base::Time remove_begin; 121 base::Time remove_begin;
198 base::Time remove_end; 122 base::Time remove_end;
199 StoragePartition::OriginMatcherFunction origin_matcher; 123 StoragePartition::OriginMatcherFunction origin_matcher;
200 StoragePartition::CookieMatcherFunction cookie_matcher; 124 StoragePartition::CookieMatcherFunction cookie_matcher;
201 125
202 StoragePartitionRemovalData() {} 126 StoragePartitionRemovalData() {}
203 }; 127 };
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 private: 240 private:
317 void AsyncRunCallback(const base::Closure& callback) { 241 void AsyncRunCallback(const base::Closure& callback) {
318 callback.Run(); 242 callback.Run();
319 } 243 }
320 244
321 StoragePartitionRemovalData storage_partition_removal_data_; 245 StoragePartitionRemovalData storage_partition_removal_data_;
322 246
323 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); 247 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition);
324 }; 248 };
325 249
326 #if defined(OS_ANDROID)
327 class TestWebappRegistry : public WebappRegistry {
328 public:
329 TestWebappRegistry() : WebappRegistry() { }
330
331 void UnregisterWebappsForUrls(
332 const base::Callback<bool(const GURL&)>& url_filter) override {
333 // Mocks out a JNI call.
334 }
335
336 void ClearWebappHistoryForUrls(
337 const base::Callback<bool(const GURL&)>& url_filter) override {
338 // Mocks out a JNI call.
339 }
340 };
341 #endif
342
343 // Custom matcher to test the equivalence of two URL filters. Since those are 250 // Custom matcher to test the equivalence of two URL filters. Since those are
344 // blackbox predicates, we can only approximate the equivalence by testing 251 // blackbox predicates, we can only approximate the equivalence by testing
345 // whether the filter give the same answer for several URLs. This is currently 252 // whether the filter give the same answer for several URLs. This is currently
346 // good enough for our testing purposes, to distinguish whitelists 253 // good enough for our testing purposes, to distinguish whitelists
347 // and blacklists, empty and non-empty filters and such. 254 // and blacklists, empty and non-empty filters and such.
348 // TODO(msramek): BrowsingDataRemover and some of its backends support URL 255 // TODO(msramek): BrowsingDataRemover and some of its backends support URL
349 // filters, but its constructor currently only takes a single URL and constructs 256 // filters, but its constructor currently only takes a single URL and constructs
350 // its own url filter. If an url filter was directly passed to 257 // its own url filter. If an url filter was directly passed to
351 // BrowsingDataRemover (what should eventually be the case), we can use the same 258 // BrowsingDataRemover (what should eventually be the case), we can use the same
352 // instance in the test as well, and thus simply test base::Callback::Equals() 259 // instance in the test as well, and thus simply test base::Callback::Equals()
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 295
389 private: 296 private:
390 const base::Callback<bool(const GURL&)>& to_match_; 297 const base::Callback<bool(const GURL&)>& to_match_;
391 }; 298 };
392 299
393 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter( 300 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter(
394 const base::Callback<bool(const GURL&)>& filter) { 301 const base::Callback<bool(const GURL&)>& filter) {
395 return MakeMatcher(new ProbablySameFilterMatcher(filter)); 302 return MakeMatcher(new ProbablySameFilterMatcher(filter));
396 } 303 }
397 304
398 bool ProbablySameFilters(
399 const base::Callback<bool(const GURL&)>& filter1,
400 const base::Callback<bool(const GURL&)>& filter2) {
401 return ProbablySameFilter(filter1).MatchAndExplain(filter2, nullptr);
402 }
403
404 base::Time AnHourAgo() { 305 base::Time AnHourAgo() {
405 return base::Time::Now() - base::TimeDelta::FromHours(1); 306 return base::Time::Now() - base::TimeDelta::FromHours(1);
406 } 307 }
407 308
408 } // namespace 309 } // namespace
409 310
410 // Testers ------------------------------------------------------------------- 311 // Testers -------------------------------------------------------------------
411 312
412 class RemoveCookieTester { 313 class RemoveCookieTester {
413 public: 314 public:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 362
462 bool get_cookie_success_ = false; 363 bool get_cookie_success_ = false;
463 base::Closure quit_closure_; 364 base::Closure quit_closure_;
464 365
465 // CookieStore must out live |this|. 366 // CookieStore must out live |this|.
466 net::CookieStore* cookie_store_ = nullptr; 367 net::CookieStore* cookie_store_ = nullptr;
467 368
468 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); 369 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
469 }; 370 };
470 371
471 void RunClosureAfterCookiesCleared(const base::Closure& task,
472 int cookies_deleted) {
473 task.Run();
474 }
475
476 class RemoveSafeBrowsingCookieTester : public RemoveCookieTester {
477 public:
478 RemoveSafeBrowsingCookieTester()
479 : browser_process_(TestingBrowserProcess::GetGlobal()) {
480 scoped_refptr<safe_browsing::SafeBrowsingService> sb_service =
481 safe_browsing::SafeBrowsingService::CreateSafeBrowsingService();
482 browser_process_->SetSafeBrowsingService(sb_service.get());
483 sb_service->Initialize();
484 base::RunLoop().RunUntilIdle();
485
486 // Make sure the safe browsing cookie store has no cookies.
487 // TODO(mmenke): Is this really needed?
488 base::RunLoop run_loop;
489 net::URLRequestContext* request_context =
490 sb_service->url_request_context()->GetURLRequestContext();
491 request_context->cookie_store()->DeleteAllAsync(
492 base::Bind(&RunClosureAfterCookiesCleared, run_loop.QuitClosure()));
493 run_loop.Run();
494
495 SetCookieStore(request_context->cookie_store());
496 }
497
498 virtual ~RemoveSafeBrowsingCookieTester() {
499 browser_process_->safe_browsing_service()->ShutDown();
500 base::RunLoop().RunUntilIdle();
501 browser_process_->SetSafeBrowsingService(nullptr);
502 }
503
504 private:
505 TestingBrowserProcess* browser_process_;
506
507 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
508 };
509
510 class RemoveChannelIDTester : public net::SSLConfigService::Observer { 372 class RemoveChannelIDTester : public net::SSLConfigService::Observer {
511 public: 373 public:
512 explicit RemoveChannelIDTester(TestingProfile* profile) { 374 explicit RemoveChannelIDTester(BrowserContext* browser_context) {
513 channel_id_service_ = profile->GetRequestContext()-> 375 net::URLRequestContext* url_request_context =
514 GetURLRequestContext()->channel_id_service(); 376 content::BrowserContext::GetDefaultStoragePartition(browser_context)
515 ssl_config_service_ = profile->GetSSLConfigService(); 377 ->GetURLRequestContext()->GetURLRequestContext();
378 channel_id_service_ = url_request_context-> channel_id_service();
379 ssl_config_service_ = url_request_context->ssl_config_service();
516 ssl_config_service_->AddObserver(this); 380 ssl_config_service_->AddObserver(this);
517 } 381 }
518 382
519 ~RemoveChannelIDTester() override { 383 ~RemoveChannelIDTester() override {
520 ssl_config_service_->RemoveObserver(this); 384 ssl_config_service_->RemoveObserver(this);
521 } 385 }
522 386
523 int ChannelIDCount() { return channel_id_service_->channel_id_count(); } 387 int ChannelIDCount() { return channel_id_service_->channel_id_count(); }
524 388
525 // Add a server bound cert for |server| with specific creation and expiry 389 // Add a server bound cert for |server| with specific creation and expiry
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 *dest = result; 426 *dest = result;
563 } 427 }
564 428
565 net::ChannelIDService* channel_id_service_; 429 net::ChannelIDService* channel_id_service_;
566 scoped_refptr<net::SSLConfigService> ssl_config_service_; 430 scoped_refptr<net::SSLConfigService> ssl_config_service_;
567 int ssl_config_changed_count_ = 0; 431 int ssl_config_changed_count_ = 0;
568 432
569 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester); 433 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester);
570 }; 434 };
571 435
572 class RemoveHistoryTester {
573 public:
574 RemoveHistoryTester() {}
575
576 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
577 if (!profile->CreateHistoryService(true, false))
578 return false;
579 history_service_ = HistoryServiceFactory::GetForProfile(
580 profile, ServiceAccessType::EXPLICIT_ACCESS);
581 return true;
582 }
583
584 // Returns true, if the given URL exists in the history service.
585 bool HistoryContainsURL(const GURL& url) {
586 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
587 new content::MessageLoopRunner;
588 quit_closure_ = message_loop_runner->QuitClosure();
589 history_service_->QueryURL(
590 url,
591 true,
592 base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
593 base::Unretained(this)),
594 &tracker_);
595 message_loop_runner->Run();
596 return query_url_success_;
597 }
598
599 void AddHistory(const GURL& url, base::Time time) {
600 history_service_->AddPage(url, time, nullptr, 0, GURL(),
601 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
602 history::SOURCE_BROWSED, false);
603 }
604
605 private:
606 // Callback for HistoryService::QueryURL.
607 void SaveResultAndQuit(bool success,
608 const history::URLRow&,
609 const history::VisitVector&) {
610 query_url_success_ = success;
611 quit_closure_.Run();
612 }
613
614 // For History requests.
615 base::CancelableTaskTracker tracker_;
616 bool query_url_success_ = false;
617 base::Closure quit_closure_;
618
619 // TestingProfile owns the history service; we shouldn't delete it.
620 history::HistoryService* history_service_ = nullptr;
621
622 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
623 };
624
625 class RemoveFaviconTester {
626 public:
627 RemoveFaviconTester() {}
628
629 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
630 // Create the history service if it has not been created yet.
631 history_service_ = HistoryServiceFactory::GetForProfile(
632 profile, ServiceAccessType::EXPLICIT_ACCESS);
633 if (!history_service_) {
634 if (!profile->CreateHistoryService(true, false))
635 return false;
636 history_service_ = HistoryServiceFactory::GetForProfile(
637 profile, ServiceAccessType::EXPLICIT_ACCESS);
638 }
639
640 profile->CreateFaviconService();
641 favicon_service_ = FaviconServiceFactory::GetForProfile(
642 profile, ServiceAccessType::EXPLICIT_ACCESS);
643 return true;
644 }
645
646 // Returns true if there is a favicon stored for |page_url| in the favicon
647 // database.
648 bool HasFaviconForPageURL(const GURL& page_url) {
649 RequestFaviconSyncForPageURL(page_url);
650 return got_favicon_;
651 }
652
653 // Returns true if:
654 // - There is a favicon stored for |page_url| in the favicon database.
655 // - The stored favicon is expired.
656 bool HasExpiredFaviconForPageURL(const GURL& page_url) {
657 RequestFaviconSyncForPageURL(page_url);
658 return got_expired_favicon_;
659 }
660
661 // Adds a visit to history and stores an arbitrary favicon bitmap for
662 // |page_url|.
663 void VisitAndAddFavicon(const GURL& page_url) {
664 history_service_->AddPage(page_url, base::Time::Now(), nullptr, 0, GURL(),
665 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
666 history::SOURCE_BROWSED, false);
667
668 SkBitmap bitmap;
669 bitmap.allocN32Pixels(gfx::kFaviconSize, gfx::kFaviconSize);
670 bitmap.eraseColor(SK_ColorBLUE);
671 favicon_service_->SetFavicons(page_url, page_url, favicon_base::FAVICON,
672 gfx::Image::CreateFrom1xBitmap(bitmap));
673 }
674
675 private:
676 // Synchronously requests the favicon for |page_url| from the favicon
677 // database.
678 void RequestFaviconSyncForPageURL(const GURL& page_url) {
679 base::RunLoop run_loop;
680 quit_closure_ = run_loop.QuitClosure();
681 favicon_service_->GetRawFaviconForPageURL(
682 page_url,
683 favicon_base::FAVICON,
684 gfx::kFaviconSize,
685 base::Bind(&RemoveFaviconTester::SaveResultAndQuit,
686 base::Unretained(this)),
687 &tracker_);
688 run_loop.Run();
689 }
690
691 // Callback for HistoryService::QueryURL.
692 void SaveResultAndQuit(const favicon_base::FaviconRawBitmapResult& result) {
693 got_favicon_ = result.is_valid();
694 got_expired_favicon_ = result.is_valid() && result.expired;
695 quit_closure_.Run();
696 }
697
698 // For favicon requests.
699 base::CancelableTaskTracker tracker_;
700 bool got_favicon_ = false;
701 bool got_expired_favicon_ = false;
702 base::Closure quit_closure_;
703
704 // Owned by TestingProfile.
705 history::HistoryService* history_service_ = nullptr;
706 favicon::FaviconService* favicon_service_ = nullptr;
707
708 DISALLOW_COPY_AND_ASSIGN(RemoveFaviconTester);
709 };
710
711 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
712 public:
713 explicit RemoveAutofillTester(TestingProfile* profile)
714 : personal_data_manager_(
715 autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
716 autofill::test::DisableSystemServices(profile->GetPrefs());
717 personal_data_manager_->AddObserver(this);
718 }
719
720 ~RemoveAutofillTester() override {
721 personal_data_manager_->RemoveObserver(this);
722 autofill::test::ReenableSystemServices();
723 }
724
725 // Returns true if there are autofill profiles.
726 bool HasProfile() {
727 return !personal_data_manager_->GetProfiles().empty() &&
728 !personal_data_manager_->GetCreditCards().empty();
729 }
730
731 bool HasOrigin(const std::string& origin) {
732 const std::vector<autofill::AutofillProfile*>& profiles =
733 personal_data_manager_->GetProfiles();
734 for (const autofill::AutofillProfile* profile : profiles) {
735 if (profile->origin() == origin)
736 return true;
737 }
738
739 const std::vector<autofill::CreditCard*>& credit_cards =
740 personal_data_manager_->GetCreditCards();
741 for (const autofill::CreditCard* credit_card : credit_cards) {
742 if (credit_card->origin() == origin)
743 return true;
744 }
745
746 return false;
747 }
748
749 // Add two profiles and two credit cards to the database. In each pair, one
750 // entry has a web origin and the other has a Chrome origin.
751 void AddProfilesAndCards() {
752 std::vector<autofill::AutofillProfile> profiles;
753 autofill::AutofillProfile profile;
754 profile.set_guid(base::GenerateGUID());
755 profile.set_origin(kWebOrigin);
756 profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
757 profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
758 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
759 profile.SetRawInfo(autofill::EMAIL_ADDRESS,
760 base::ASCIIToUTF16("sue@example.com"));
761 profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
762 profiles.push_back(profile);
763
764 profile.set_guid(base::GenerateGUID());
765 profile.set_origin(autofill::kSettingsOrigin);
766 profiles.push_back(profile);
767
768 personal_data_manager_->SetProfiles(&profiles);
769 base::RunLoop().Run();
770
771 std::vector<autofill::CreditCard> cards;
772 autofill::CreditCard card;
773 card.set_guid(base::GenerateGUID());
774 card.set_origin(kWebOrigin);
775 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
776 base::ASCIIToUTF16("1234-5678-9012-3456"));
777 cards.push_back(card);
778
779 card.set_guid(base::GenerateGUID());
780 card.set_origin(autofill::kSettingsOrigin);
781 cards.push_back(card);
782
783 personal_data_manager_->SetCreditCards(&cards);
784 base::RunLoop().Run();
785 }
786
787 private:
788 void OnPersonalDataChanged() override {
789 base::MessageLoop::current()->QuitWhenIdle();
790 }
791
792 autofill::PersonalDataManager* personal_data_manager_;
793 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
794 };
795
796 class RemoveLocalStorageTester { 436 class RemoveLocalStorageTester {
797 public: 437 public:
798 explicit RemoveLocalStorageTester(TestingProfile* profile) 438 explicit RemoveLocalStorageTester(BrowserContext* browser_context)
799 : profile_(profile) { 439 : browser_context_(browser_context) {
800 dom_storage_context_ = 440 dom_storage_context_ =
801 content::BrowserContext::GetDefaultStoragePartition(profile)-> 441 content::BrowserContext::GetDefaultStoragePartition(browser_context_)->
802 GetDOMStorageContext(); 442 GetDOMStorageContext();
803 } 443 }
804 444
805 // Returns true, if the given origin URL exists. 445 // Returns true, if the given origin URL exists.
806 bool DOMStorageExistsForOrigin(const GURL& origin) { 446 bool DOMStorageExistsForOrigin(const GURL& origin) {
807 scoped_refptr<content::MessageLoopRunner> message_loop_runner = 447 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
808 new content::MessageLoopRunner; 448 new content::MessageLoopRunner;
809 quit_closure_ = message_loop_runner->QuitClosure(); 449 quit_closure_ = message_loop_runner->QuitClosure();
810 GetLocalStorageUsage(); 450 GetLocalStorageUsage();
811 message_loop_runner->Run(); 451 message_loop_runner->Run();
812 for (size_t i = 0; i < infos_.size(); ++i) { 452 for (size_t i = 0; i < infos_.size(); ++i) {
813 if (origin == infos_[i].origin) 453 if (origin == infos_[i].origin)
814 return true; 454 return true;
815 } 455 }
816 return false; 456 return false;
817 } 457 }
818 458
819 void AddDOMStorageTestData() { 459 void AddDOMStorageTestData() {
820 // Note: This test depends on details of how the dom_storage library 460 // Note: This test depends on details of how the dom_storage library
821 // stores data in the host file system. 461 // stores data in the host file system.
822 base::FilePath storage_path = 462 base::FilePath storage_path =
823 profile_->GetPath().AppendASCII("Local Storage"); 463 browser_context_->GetPath().AppendASCII("Local Storage");
824 base::CreateDirectory(storage_path); 464 base::CreateDirectory(storage_path);
825 465
826 // Write some files. 466 // Write some files.
827 base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0); 467 base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0);
828 base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0); 468 base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0);
829 base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0); 469 base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0);
830 base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0); 470 base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0);
831 471
832 // Tweak their dates. 472 // Tweak their dates.
833 base::Time now = base::Time::Now(); 473 base::Time now = base::Time::Now();
(...skipping 16 matching lines...) Expand all
850 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage, 490 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage,
851 base::Unretained(this))); 491 base::Unretained(this)));
852 } 492 }
853 void OnGotLocalStorageUsage( 493 void OnGotLocalStorageUsage(
854 const std::vector<content::LocalStorageUsageInfo>& infos) { 494 const std::vector<content::LocalStorageUsageInfo>& infos) {
855 infos_ = infos; 495 infos_ = infos;
856 quit_closure_.Run(); 496 quit_closure_.Run();
857 } 497 }
858 498
859 // We don't own these pointers. 499 // We don't own these pointers.
860 TestingProfile* profile_; 500 BrowserContext* browser_context_;
861 content::DOMStorageContext* dom_storage_context_ = nullptr; 501 content::DOMStorageContext* dom_storage_context_ = nullptr;
862 502
863 std::vector<content::LocalStorageUsageInfo> infos_; 503 std::vector<content::LocalStorageUsageInfo> infos_;
864 base::Closure quit_closure_; 504 base::Closure quit_closure_;
865 505
866 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); 506 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
867 }; 507 };
868 508
869 class MockDomainReliabilityService : public DomainReliabilityService {
870 public:
871 MockDomainReliabilityService() {}
872
873 ~MockDomainReliabilityService() override {}
874
875 std::unique_ptr<DomainReliabilityMonitor> CreateMonitor(
876 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
877 override {
878 NOTREACHED();
879 return std::unique_ptr<DomainReliabilityMonitor>();
880 }
881
882 void ClearBrowsingData(
883 DomainReliabilityClearMode clear_mode,
884 const base::Callback<bool(const GURL&)>& origin_filter,
885 const base::Closure& callback) override {
886 clear_count_++;
887 last_clear_mode_ = clear_mode;
888 last_filter_ = origin_filter;
889 callback.Run();
890 }
891
892 void GetWebUIData(const base::Callback<void(std::unique_ptr<base::Value>)>&
893 callback) const override {
894 NOTREACHED();
895 }
896
897 void SetDiscardUploadsForTesting(bool discard_uploads) override {
898 NOTREACHED();
899 }
900
901 void AddContextForTesting(
902 std::unique_ptr<const domain_reliability::DomainReliabilityConfig> config)
903 override {
904 NOTREACHED();
905 }
906
907 void ForceUploadsForTesting() override { NOTREACHED(); }
908
909 int clear_count() const { return clear_count_; }
910
911 DomainReliabilityClearMode last_clear_mode() const {
912 return last_clear_mode_;
913 }
914
915 const base::Callback<bool(const GURL&)>& last_filter() const {
916 return last_filter_;
917 }
918
919 private:
920 unsigned clear_count_ = 0;
921 DomainReliabilityClearMode last_clear_mode_;
922 base::Callback<bool(const GURL&)> last_filter_;
923 };
924
925 struct TestingDomainReliabilityServiceFactoryUserData
926 : public base::SupportsUserData::Data {
927 TestingDomainReliabilityServiceFactoryUserData(
928 content::BrowserContext* context,
929 MockDomainReliabilityService* service)
930 : context(context),
931 service(service),
932 attached(false) {}
933 ~TestingDomainReliabilityServiceFactoryUserData() override {}
934
935 content::BrowserContext* const context;
936 MockDomainReliabilityService* const service;
937 bool attached;
938
939 static const void* kKey;
940 };
941
942 // static
943 const void* TestingDomainReliabilityServiceFactoryUserData::kKey =
944 &TestingDomainReliabilityServiceFactoryUserData::kKey;
945
946 std::unique_ptr<KeyedService> TestingDomainReliabilityServiceFactoryFunction(
947 content::BrowserContext* context) {
948 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
949
950 TestingDomainReliabilityServiceFactoryUserData* data =
951 static_cast<TestingDomainReliabilityServiceFactoryUserData*>(
952 context->GetUserData(kKey));
953 EXPECT_TRUE(data);
954 EXPECT_EQ(data->context, context);
955 EXPECT_FALSE(data->attached);
956
957 data->attached = true;
958 return base::WrapUnique(data->service);
959 }
960
961 class ClearDomainReliabilityTester {
962 public:
963 explicit ClearDomainReliabilityTester(TestingProfile* profile) :
964 profile_(profile),
965 mock_service_(new MockDomainReliabilityService()) {
966 AttachService();
967 }
968
969 unsigned clear_count() const { return mock_service_->clear_count(); }
970
971 DomainReliabilityClearMode last_clear_mode() const {
972 return mock_service_->last_clear_mode();
973 }
974
975 const base::Callback<bool(const GURL&)>& last_filter() const {
976 return mock_service_->last_filter();
977 }
978
979 private:
980 void AttachService() {
981 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
982
983 // Attach kludgey UserData struct to profile.
984 TestingDomainReliabilityServiceFactoryUserData* data =
985 new TestingDomainReliabilityServiceFactoryUserData(profile_,
986 mock_service_);
987 EXPECT_FALSE(profile_->GetUserData(kKey));
988 profile_->SetUserData(kKey, data);
989
990 // Set and use factory that will attach service stuffed in kludgey struct.
991 DomainReliabilityServiceFactory::GetInstance()->SetTestingFactoryAndUse(
992 profile_,
993 &TestingDomainReliabilityServiceFactoryFunction);
994
995 // Verify and detach kludgey struct.
996 EXPECT_EQ(data, profile_->GetUserData(kKey));
997 EXPECT_TRUE(data->attached);
998 profile_->RemoveUserData(kKey);
999 }
1000
1001 TestingProfile* profile_;
1002 MockDomainReliabilityService* mock_service_;
1003 };
1004
1005 class RemoveDownloadsTester { 509 class RemoveDownloadsTester {
1006 public: 510 public:
1007 explicit RemoveDownloadsTester(TestingProfile* testing_profile) 511 explicit RemoveDownloadsTester(BrowserContext* browser_context)
1008 : download_manager_(new content::MockDownloadManager()), 512 : download_manager_(new content::MockDownloadManager()) {
1009 chrome_download_manager_delegate_(testing_profile) { 513 content::BrowserContext::SetDownloadManagerForTesting(browser_context,
1010 content::BrowserContext::SetDownloadManagerForTesting(testing_profile,
1011 download_manager_); 514 download_manager_);
1012 EXPECT_EQ(download_manager_, 515 EXPECT_EQ(download_manager_,
1013 content::BrowserContext::GetDownloadManager(testing_profile)); 516 content::BrowserContext::GetDownloadManager(browser_context));
1014
1015 EXPECT_CALL(*download_manager_, GetDelegate())
1016 .WillOnce(Return(&chrome_download_manager_delegate_));
1017 EXPECT_CALL(*download_manager_, Shutdown()); 517 EXPECT_CALL(*download_manager_, Shutdown());
1018 } 518 }
1019 519
1020 ~RemoveDownloadsTester() { chrome_download_manager_delegate_.Shutdown(); } 520 ~RemoveDownloadsTester() {}
1021 521
1022 content::MockDownloadManager* download_manager() { return download_manager_; } 522 content::MockDownloadManager* download_manager() { return download_manager_; }
1023 523
1024 private: 524 private:
1025 content::MockDownloadManager* download_manager_; 525 content::MockDownloadManager* download_manager_;
1026 ChromeDownloadManagerDelegate chrome_download_manager_delegate_;
1027 526
1028 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester); 527 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester);
1029 }; 528 };
1030 529
1031 class RemovePasswordsTester { 530 // Test Class ----------------------------------------------------------------
531
532 class BrowsingDataRemoverImplTest : public testing::Test {
1032 public: 533 public:
1033 explicit RemovePasswordsTester(TestingProfile* testing_profile) { 534 BrowsingDataRemoverImplTest()
1034 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse( 535 : browser_context_(new TestingProfile()) {
1035 testing_profile, 536 // TODO(crbug.com/668114): To create a BrowsingDataRemoverImpl, we currently
1036 password_manager::BuildPasswordStore< 537 // need a BrowsingDataRemoverFactory which only exists for a Profile.
1037 content::BrowserContext, 538 // Therefore, this test must use a TestingProfile for now. Switch it to
1038 testing::NiceMock<password_manager::MockPasswordStore>>); 539 // a BrowserContext or TestBrowserContext when BrowsingDataRemoverImpl
1039 540 // moves to content/. Furthermore, when in content/, BrowsingDataRemoverImpl
1040 store_ = static_cast<password_manager::MockPasswordStore*>( 541 // will have no delegate. For now, explicitly set it to nullptr.
1041 PasswordStoreFactory::GetInstance() 542 remover_ = static_cast<BrowsingDataRemoverImpl*>(
1042 ->GetForProfile(testing_profile, ServiceAccessType::EXPLICIT_ACCESS) 543 BrowsingDataRemoverFactory::GetForBrowserContext(
1043 .get()); 544 browser_context_.get()));
1044 545 remover_->SetEmbedderDelegate(nullptr);
1045 OSCryptMocker::SetUpWithSingleton();
1046 } 546 }
1047 547
1048 ~RemovePasswordsTester() { OSCryptMocker::TearDown(); } 548 ~BrowsingDataRemoverImplTest() override {}
1049
1050 password_manager::MockPasswordStore* store() { return store_; }
1051
1052 private:
1053 password_manager::MockPasswordStore* store_;
1054
1055 DISALLOW_COPY_AND_ASSIGN(RemovePasswordsTester);
1056 };
1057
1058 class RemovePermissionPromptCountsTest {
1059 public:
1060 explicit RemovePermissionPromptCountsTest(TestingProfile* profile)
1061 : profile_(profile) {}
1062
1063 int GetDismissCount(const GURL& url, content::PermissionType permission) {
1064 return PermissionDecisionAutoBlocker::GetDismissCount(
1065 url, permission, profile_);
1066 }
1067
1068 int GetIgnoreCount(const GURL& url, content::PermissionType permission) {
1069 return PermissionDecisionAutoBlocker::GetIgnoreCount(
1070 url, permission, profile_);
1071 }
1072
1073 int RecordIgnore(const GURL& url, content::PermissionType permission) {
1074 return PermissionDecisionAutoBlocker::RecordIgnore(url, permission,
1075 profile_);
1076 }
1077
1078 bool ShouldChangeDismissalToBlock(const GURL& url,
1079 content::PermissionType permission) {
1080 return PermissionDecisionAutoBlocker::ShouldChangeDismissalToBlock(
1081 url, permission, profile_);
1082 }
1083
1084 private:
1085 TestingProfile* profile_;
1086
1087 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest);
1088 };
1089
1090 #if BUILDFLAG(ENABLE_PLUGINS)
1091 // A small modification to MockBrowsingDataFlashLSOHelper so that it responds
1092 // immediately and does not wait for the Notify() call. Otherwise it would
1093 // deadlock BrowsingDataRemoverImpl::RemoveImpl.
1094 class TestBrowsingDataFlashLSOHelper : public MockBrowsingDataFlashLSOHelper {
1095 public:
1096 explicit TestBrowsingDataFlashLSOHelper(TestingProfile* profile)
1097 : MockBrowsingDataFlashLSOHelper(profile) {}
1098
1099 void StartFetching(const GetSitesWithFlashDataCallback& callback) override {
1100 MockBrowsingDataFlashLSOHelper::StartFetching(callback);
1101 Notify();
1102 }
1103
1104 private:
1105 ~TestBrowsingDataFlashLSOHelper() override {}
1106
1107 DISALLOW_COPY_AND_ASSIGN(TestBrowsingDataFlashLSOHelper);
1108 };
1109
1110 class RemovePluginDataTester {
1111 public:
1112 explicit RemovePluginDataTester(TestingProfile* profile)
1113 : helper_(new TestBrowsingDataFlashLSOHelper(profile)) {
1114 static_cast<ChromeBrowsingDataRemoverDelegate*>(
1115 BrowsingDataRemoverFactory::GetForBrowserContext(profile)
1116 ->GetEmbedderDelegate())->OverrideFlashLSOHelperForTesting(helper_);
1117 }
1118
1119 void AddDomain(const std::string& domain) {
1120 helper_->AddFlashLSODomain(domain);
1121 }
1122
1123 const std::vector<std::string>& GetDomains() {
1124 // TestBrowsingDataFlashLSOHelper is synchronous, so we can immediately
1125 // return the fetched domains.
1126 helper_->StartFetching(
1127 base::Bind(&RemovePluginDataTester::OnSitesWithFlashDataFetched,
1128 base::Unretained(this)));
1129 return domains_;
1130 }
1131
1132 private:
1133 void OnSitesWithFlashDataFetched(const std::vector<std::string>& sites) {
1134 domains_ = sites;
1135 }
1136
1137 std::vector<std::string> domains_;
1138 scoped_refptr<TestBrowsingDataFlashLSOHelper> helper_;
1139
1140 DISALLOW_COPY_AND_ASSIGN(RemovePluginDataTester);
1141 };
1142 #endif
1143
1144 // Test Class ----------------------------------------------------------------
1145
1146 class BrowsingDataRemoverTest : public testing::Test {
1147 public:
1148 BrowsingDataRemoverTest()
1149 : profile_(new TestingProfile()),
1150 clear_domain_reliability_tester_(GetProfile()) {
1151 remover_ = static_cast<BrowsingDataRemoverImpl*>(
1152 BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get()));
1153
1154 #if defined(OS_ANDROID)
1155 static_cast<ChromeBrowsingDataRemoverDelegate*>(
1156 remover_->GetEmbedderDelegate())->OverrideWebappRegistryForTesting(
1157 base::WrapUnique<WebappRegistry>(new TestWebappRegistry()));
1158 #endif
1159 }
1160
1161 ~BrowsingDataRemoverTest() override {}
1162 549
1163 void TearDown() override { 550 void TearDown() override {
1164 #if BUILDFLAG(ENABLE_EXTENSIONS) 551 #if BUILDFLAG(ENABLE_EXTENSIONS)
1165 mock_policy_ = nullptr; 552 mock_policy_ = nullptr;
1166 #endif 553 #endif
1167 554
1168 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor 555 // BrowserContext contains a DOMStorageContext. BrowserContext's
1169 // posts a message to the WEBKIT thread to delete some of its member 556 // destructor posts a message to the WEBKIT thread to delete some of its
1170 // variables. We need to ensure that the profile is destroyed, and that 557 // member variables. We need to ensure that the browser context is
1171 // the message loop is cleared out, before destroying the threads and loop. 558 // destroyed, and that the message loop is cleared out, before destroying
1172 // Otherwise we leak memory. 559 // the threads and loop. Otherwise we leak memory.
1173 profile_.reset(); 560 browser_context_.reset();
1174 base::RunLoop().RunUntilIdle(); 561 base::RunLoop().RunUntilIdle();
1175
1176 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
1177 } 562 }
1178 563
1179 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin, 564 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin,
1180 const base::Time& delete_end, 565 const base::Time& delete_end,
1181 int remove_mask, 566 int remove_mask,
1182 bool include_protected_origins) { 567 bool include_protected_origins) {
1183 TestStoragePartition storage_partition; 568 TestStoragePartition storage_partition;
1184 remover_->OverrideStoragePartitionForTesting(&storage_partition); 569 remover_->OverrideStoragePartitionForTesting(&storage_partition);
1185 570
1186 int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB; 571 int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB;
(...skipping 23 matching lines...) Expand all
1210 remover_->RemoveImpl(delete_begin, delete_end, remove_mask, filter_builder, 595 remover_->RemoveImpl(delete_begin, delete_end, remove_mask, filter_builder,
1211 BrowsingDataHelper::UNPROTECTED_WEB); 596 BrowsingDataHelper::UNPROTECTED_WEB);
1212 completion_inhibitor.BlockUntilNearCompletion(); 597 completion_inhibitor.BlockUntilNearCompletion();
1213 completion_inhibitor.ContinueToCompletion(); 598 completion_inhibitor.ContinueToCompletion();
1214 599
1215 // Save so we can verify later. 600 // Save so we can verify later.
1216 storage_partition_removal_data_ = 601 storage_partition_removal_data_ =
1217 storage_partition.GetStoragePartitionRemovalData(); 602 storage_partition.GetStoragePartitionRemovalData();
1218 } 603 }
1219 604
1220 TestingProfile* GetProfile() { 605 BrowserContext* GetBrowserContext() {
1221 return profile_.get(); 606 return browser_context_.get();
1222 } 607 }
1223 608
1224 void DestroyProfile() { profile_.reset(); } 609 void DestroyBrowserContext() { browser_context_.reset(); }
1225 610
1226 const base::Time& GetBeginTime() { 611 const base::Time& GetBeginTime() {
1227 return remover_->GetLastUsedBeginTime(); 612 return remover_->GetLastUsedBeginTime();
1228 } 613 }
1229 614
1230 int GetRemovalMask() { 615 int GetRemovalMask() {
1231 return remover_->GetLastUsedRemovalMask(); 616 return remover_->GetLastUsedRemovalMask();
1232 } 617 }
1233 618
1234 int GetOriginTypeMask() { 619 int GetOriginTypeMask() {
(...skipping 25 matching lines...) Expand all
1260 // If |kOrigin1| is protected when extensions are enabled, the expected 645 // If |kOrigin1| is protected when extensions are enabled, the expected
1261 // result for tests where the OriginMatcherFunction result is variable. 646 // result for tests where the OriginMatcherFunction result is variable.
1262 bool ShouldRemoveForProtectedOriginOne() const { 647 bool ShouldRemoveForProtectedOriginOne() const {
1263 #if BUILDFLAG(ENABLE_EXTENSIONS) 648 #if BUILDFLAG(ENABLE_EXTENSIONS)
1264 return false; 649 return false;
1265 #else 650 #else
1266 return true; 651 return true;
1267 #endif 652 #endif
1268 } 653 }
1269 654
1270 const ClearDomainReliabilityTester& clear_domain_reliability_tester() {
1271 return clear_domain_reliability_tester_;
1272 }
1273
1274 private: 655 private:
1275 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods. 656 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods.
1276 BrowsingDataRemoverImpl* remover_; 657 BrowsingDataRemoverImpl* remover_;
1277 658
1278 content::TestBrowserThreadBundle thread_bundle_; 659 content::TestBrowserThreadBundle thread_bundle_;
1279 std::unique_ptr<TestingProfile> profile_; 660 std::unique_ptr<BrowserContext> browser_context_;
1280 661
1281 StoragePartitionRemovalData storage_partition_removal_data_; 662 StoragePartitionRemovalData storage_partition_removal_data_;
1282 663
1283 #if BUILDFLAG(ENABLE_EXTENSIONS) 664 #if BUILDFLAG(ENABLE_EXTENSIONS)
1284 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_; 665 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_;
1285 #endif 666 #endif
1286 667
1287 // Needed to mock out DomainReliabilityService, even for unrelated tests. 668 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverImplTest);
1288 ClearDomainReliabilityTester clear_domain_reliability_tester_;
1289
1290 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
1291 }; 669 };
1292 670
1293 // Tests --------------------------------------------------------------------- 671 // Tests ---------------------------------------------------------------------
1294 672
1295 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { 673 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieForever) {
1296 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 674 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1297 BrowsingDataRemover::REMOVE_COOKIES, false); 675 BrowsingDataRemover::REMOVE_COOKIES, false);
1298 676
1299 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 677 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1300 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); 678 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1301 679
1302 // Verify that storage partition was instructed to remove the cookies. 680 // Verify that storage partition was instructed to remove the cookies.
1303 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 681 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1304 EXPECT_EQ(removal_data.remove_mask, 682 EXPECT_EQ(removal_data.remove_mask,
1305 StoragePartition::REMOVE_DATA_MASK_COOKIES); 683 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1306 EXPECT_EQ(removal_data.quota_storage_remove_mask, 684 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1307 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 685 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1308 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 686 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1309 } 687 }
1310 688
1311 TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) { 689 TEST_F(BrowsingDataRemoverImplTest, RemoveCookieLastHour) {
1312 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), 690 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1313 BrowsingDataRemover::REMOVE_COOKIES, false); 691 BrowsingDataRemover::REMOVE_COOKIES, false);
1314 692
1315 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 693 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1316 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); 694 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1317 695
1318 // Verify that storage partition was instructed to remove the cookies. 696 // Verify that storage partition was instructed to remove the cookies.
1319 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 697 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1320 EXPECT_EQ(removal_data.remove_mask, 698 EXPECT_EQ(removal_data.remove_mask,
1321 StoragePartition::REMOVE_DATA_MASK_COOKIES); 699 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1322 // Removing with time period other than all time should not clear 700 // Removing with time period other than all time should not clear
1323 // persistent storage data. 701 // persistent storage data.
1324 EXPECT_EQ(removal_data.quota_storage_remove_mask, 702 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1325 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); 703 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1326 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 704 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1327 } 705 }
1328 706
1329 TEST_F(BrowsingDataRemoverTest, RemoveCookiesDomainBlacklist) { 707 TEST_F(BrowsingDataRemoverImplTest, RemoveCookiesDomainBlacklist) {
1330 RegistrableDomainFilterBuilder filter( 708 RegistrableDomainFilterBuilder filter(
1331 RegistrableDomainFilterBuilder::BLACKLIST); 709 RegistrableDomainFilterBuilder::BLACKLIST);
1332 filter.AddRegisterableDomain(kTestRegisterableDomain1); 710 filter.AddRegisterableDomain(kTestRegisterableDomain1);
1333 filter.AddRegisterableDomain(kTestRegisterableDomain3); 711 filter.AddRegisterableDomain(kTestRegisterableDomain3);
1334 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(), 712 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
1335 BrowsingDataRemover::REMOVE_COOKIES, filter); 713 BrowsingDataRemover::REMOVE_COOKIES, filter);
1336 714
1337 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 715 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1338 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); 716 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1339 717
(...skipping 13 matching lines...) Expand all
1353 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy())); 731 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy()));
1354 732
1355 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin1))); 733 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin1)));
1356 EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2))); 734 EXPECT_TRUE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin2)));
1357 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin3))); 735 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin3)));
1358 // This is false, because this is the same domain as 3, just with a different 736 // This is false, because this is the same domain as 3, just with a different
1359 // scheme. 737 // scheme.
1360 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4))); 738 EXPECT_FALSE(removal_data.cookie_matcher.Run(CreateCookieWithHost(kOrigin4)));
1361 } 739 }
1362 740
1363 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) { 741 // Test that removing cookies clears HTTP auth data.
1364 RemoveSafeBrowsingCookieTester tester; 742 TEST_F(BrowsingDataRemoverImplTest, ClearHttpAuthCache_RemoveCookies) {
743 net::HttpNetworkSession* http_session =
744 content::BrowserContext::GetDefaultStoragePartition(GetBrowserContext())
745 ->GetURLRequestContext()
746 ->GetURLRequestContext()
747 ->http_transaction_factory()
748 ->GetSession();
749 DCHECK(http_session);
1365 750
1366 tester.AddCookie(); 751 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache();
1367 ASSERT_TRUE(tester.ContainsCookie()); 752 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC,
753 "test challenge",
754 net::AuthCredentials(base::ASCIIToUTF16("foo"),
755 base::ASCIIToUTF16("bar")),
756 "/");
757 CHECK(http_auth_cache->Lookup(kOrigin1, kTestRealm,
758 net::HttpAuth::AUTH_SCHEME_BASIC));
1368 759
1369 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 760 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1370 BrowsingDataRemover::REMOVE_COOKIES, false); 761 BrowsingDataRemover::REMOVE_COOKIES, false);
1371 762
1372 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 763 EXPECT_EQ(nullptr, http_auth_cache->Lookup(kOrigin1, kTestRealm,
1373 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); 764 net::HttpAuth::AUTH_SCHEME_BASIC));
1374 EXPECT_FALSE(tester.ContainsCookie());
1375 } 765 }
1376 766
1377 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) { 767 TEST_F(BrowsingDataRemoverImplTest, RemoveChannelIDForever) {
1378 RemoveSafeBrowsingCookieTester tester; 768 RemoveChannelIDTester tester(GetBrowserContext());
1379
1380 tester.AddCookie();
1381 ASSERT_TRUE(tester.ContainsCookie());
1382
1383 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1384 BrowsingDataRemover::REMOVE_COOKIES, false);
1385
1386 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1387 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1388 // Removing with time period other than all time should not clear safe
1389 // browsing cookies.
1390 EXPECT_TRUE(tester.ContainsCookie());
1391 }
1392
1393 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForeverWithPredicate) {
1394 RemoveSafeBrowsingCookieTester tester;
1395
1396 tester.AddCookie();
1397 ASSERT_TRUE(tester.ContainsCookie());
1398 RegistrableDomainFilterBuilder filter(
1399 RegistrableDomainFilterBuilder::BLACKLIST);
1400 filter.AddRegisterableDomain(kTestRegisterableDomain1);
1401 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1402 BrowsingDataRemover::REMOVE_COOKIES, filter);
1403
1404 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1405 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1406 EXPECT_TRUE(tester.ContainsCookie());
1407
1408 RegistrableDomainFilterBuilder filter2(
1409 RegistrableDomainFilterBuilder::WHITELIST);
1410 filter2.AddRegisterableDomain(kTestRegisterableDomain1);
1411 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1412 BrowsingDataRemover::REMOVE_COOKIES, filter2);
1413 EXPECT_FALSE(tester.ContainsCookie());
1414 }
1415
1416 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) {
1417 RemoveChannelIDTester tester(GetProfile());
1418 769
1419 tester.AddChannelID(kTestOrigin1); 770 tester.AddChannelID(kTestOrigin1);
1420 EXPECT_EQ(0, tester.ssl_config_changed_count()); 771 EXPECT_EQ(0, tester.ssl_config_changed_count());
1421 EXPECT_EQ(1, tester.ChannelIDCount()); 772 EXPECT_EQ(1, tester.ChannelIDCount());
1422 773
1423 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 774 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1424 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false); 775 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
1425 776
1426 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask()); 777 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
1427 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); 778 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1428 EXPECT_EQ(1, tester.ssl_config_changed_count()); 779 EXPECT_EQ(1, tester.ssl_config_changed_count());
1429 EXPECT_EQ(0, tester.ChannelIDCount()); 780 EXPECT_EQ(0, tester.ChannelIDCount());
1430 } 781 }
1431 782
1432 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDLastHour) { 783 TEST_F(BrowsingDataRemoverImplTest, RemoveChannelIDLastHour) {
1433 RemoveChannelIDTester tester(GetProfile()); 784 RemoveChannelIDTester tester(GetBrowserContext());
1434 785
1435 base::Time now = base::Time::Now(); 786 base::Time now = base::Time::Now();
1436 tester.AddChannelID(kTestOrigin1); 787 tester.AddChannelID(kTestOrigin1);
1437 tester.AddChannelIDWithTimes(kTestOrigin2, 788 tester.AddChannelIDWithTimes(kTestOrigin2,
1438 now - base::TimeDelta::FromHours(2)); 789 now - base::TimeDelta::FromHours(2));
1439 EXPECT_EQ(0, tester.ssl_config_changed_count()); 790 EXPECT_EQ(0, tester.ssl_config_changed_count());
1440 EXPECT_EQ(2, tester.ChannelIDCount()); 791 EXPECT_EQ(2, tester.ChannelIDCount());
1441 792
1442 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(), 793 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1443 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false); 794 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
1444 795
1445 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask()); 796 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
1446 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); 797 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1447 EXPECT_EQ(1, tester.ssl_config_changed_count()); 798 EXPECT_EQ(1, tester.ssl_config_changed_count());
1448 ASSERT_EQ(1, tester.ChannelIDCount()); 799 ASSERT_EQ(1, tester.ChannelIDCount());
1449 net::ChannelIDStore::ChannelIDList channel_ids; 800 net::ChannelIDStore::ChannelIDList channel_ids;
1450 tester.GetChannelIDList(&channel_ids); 801 tester.GetChannelIDList(&channel_ids);
1451 ASSERT_EQ(1U, channel_ids.size()); 802 ASSERT_EQ(1U, channel_ids.size());
1452 EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier()); 803 EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier());
1453 } 804 }
1454 805
1455 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDsForServerIdentifiers) { 806 TEST_F(BrowsingDataRemoverImplTest, RemoveChannelIDsForServerIdentifiers) {
1456 RemoveChannelIDTester tester(GetProfile()); 807 RemoveChannelIDTester tester(GetBrowserContext());
1457 808
1458 tester.AddChannelID(kTestRegisterableDomain1); 809 tester.AddChannelID(kTestRegisterableDomain1);
1459 tester.AddChannelID(kTestRegisterableDomain3); 810 tester.AddChannelID(kTestRegisterableDomain3);
1460 EXPECT_EQ(2, tester.ChannelIDCount()); 811 EXPECT_EQ(2, tester.ChannelIDCount());
1461 812
1462 RegistrableDomainFilterBuilder filter_builder( 813 RegistrableDomainFilterBuilder filter_builder(
1463 RegistrableDomainFilterBuilder::WHITELIST); 814 RegistrableDomainFilterBuilder::WHITELIST);
1464 filter_builder.AddRegisterableDomain(kTestRegisterableDomain1); 815 filter_builder.AddRegisterableDomain(kTestRegisterableDomain1);
1465 816
1466 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), 817 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1467 BrowsingDataRemover::REMOVE_CHANNEL_IDS, 818 BrowsingDataRemover::REMOVE_CHANNEL_IDS,
1468 filter_builder); 819 filter_builder);
1469 820
1470 EXPECT_EQ(1, tester.ChannelIDCount()); 821 EXPECT_EQ(1, tester.ChannelIDCount());
1471 net::ChannelIDStore::ChannelIDList channel_ids; 822 net::ChannelIDStore::ChannelIDList channel_ids;
1472 tester.GetChannelIDList(&channel_ids); 823 tester.GetChannelIDList(&channel_ids);
1473 EXPECT_EQ(kTestRegisterableDomain3, channel_ids.front().server_identifier()); 824 EXPECT_EQ(kTestRegisterableDomain3, channel_ids.front().server_identifier());
1474 } 825 }
1475 826
1476 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) { 827 TEST_F(BrowsingDataRemoverImplTest, RemoveUnprotectedLocalStorageForever) {
1477 #if BUILDFLAG(ENABLE_EXTENSIONS) 828 #if BUILDFLAG(ENABLE_EXTENSIONS)
1478 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); 829 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1479 // Protect kOrigin1. 830 // Protect kOrigin1.
1480 policy->AddProtected(kOrigin1.GetOrigin()); 831 policy->AddProtected(kOrigin1.GetOrigin());
1481 #endif 832 #endif
1482 833
1483 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 834 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1484 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, 835 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1485 false); 836 false);
1486 837
1487 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); 838 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1488 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); 839 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1489 840
1490 // Verify that storage partition was instructed to remove the data correctly. 841 // Verify that storage partition was instructed to remove the data correctly.
1491 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 842 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1492 EXPECT_EQ(removal_data.remove_mask, 843 EXPECT_EQ(removal_data.remove_mask,
1493 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); 844 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1494 EXPECT_EQ(removal_data.quota_storage_remove_mask, 845 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1495 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 846 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1496 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 847 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1497 848
1498 // Check origin matcher. 849 // Check origin matcher.
1499 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(), 850 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1500 removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 851 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1501 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 852 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1502 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 853 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1503 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); 854 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1504 } 855 }
1505 856
1506 TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) { 857 TEST_F(BrowsingDataRemoverImplTest, RemoveProtectedLocalStorageForever) {
1507 #if BUILDFLAG(ENABLE_EXTENSIONS) 858 #if BUILDFLAG(ENABLE_EXTENSIONS)
1508 // Protect kOrigin1. 859 // Protect kOrigin1.
1509 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); 860 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1510 policy->AddProtected(kOrigin1.GetOrigin()); 861 policy->AddProtected(kOrigin1.GetOrigin());
1511 #endif 862 #endif
1512 863
1513 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 864 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1514 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, 865 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1515 true); 866 true);
1516 867
(...skipping 10 matching lines...) Expand all
1527 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 878 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1528 879
1529 // Check origin matcher all http origin will match since we specified 880 // Check origin matcher all http origin will match since we specified
1530 // both protected and unprotected. 881 // both protected and unprotected.
1531 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 882 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1532 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 883 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1533 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 884 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1534 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); 885 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1535 } 886 }
1536 887
1537 TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) { 888 TEST_F(BrowsingDataRemoverImplTest, RemoveLocalStorageForLastWeek) {
1538 #if BUILDFLAG(ENABLE_EXTENSIONS) 889 #if BUILDFLAG(ENABLE_EXTENSIONS)
1539 CreateMockPolicy(); 890 CreateMockPolicy();
1540 #endif 891 #endif
1541 892
1542 BlockUntilBrowsingDataRemoved( 893 BlockUntilBrowsingDataRemoved(
1543 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(), 894 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(),
1544 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, false); 895 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, false);
1545 896
1546 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); 897 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1547 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); 898 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1548 899
1549 // Verify that storage partition was instructed to remove the data correctly. 900 // Verify that storage partition was instructed to remove the data correctly.
1550 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 901 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1551 EXPECT_EQ(removal_data.remove_mask, 902 EXPECT_EQ(removal_data.remove_mask,
1552 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE); 903 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1553 // Persistent storage won't be deleted. 904 // Persistent storage won't be deleted.
1554 EXPECT_EQ(removal_data.quota_storage_remove_mask, 905 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1555 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); 906 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1556 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 907 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1557 908
1558 // Check origin matcher. 909 // Check origin matcher.
1559 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 910 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1560 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 911 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1561 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 912 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1562 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); 913 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1563 } 914 }
1564 915
1565 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { 916 TEST_F(BrowsingDataRemoverImplTest, RemoveMultipleTypes) {
1566 RemoveHistoryTester tester; 917 // Downloads should be deleted through the DownloadManager, assure it would
1567 ASSERT_TRUE(tester.Init(GetProfile())); 918 // be called.
919 RemoveDownloadsTester downloads_tester(GetBrowserContext());
920 EXPECT_CALL(*downloads_tester.download_manager(),
921 RemoveDownloadsByURLAndTime(_, _, _));
1568 922
1569 tester.AddHistory(kOrigin1, base::Time::Now()); 923 int removal_mask = BrowsingDataRemover::REMOVE_DOWNLOADS |
1570 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1571
1572 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1573 BrowsingDataRemover::REMOVE_HISTORY, false);
1574
1575 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1576 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1577 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
1578 }
1579
1580 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
1581 RemoveHistoryTester tester;
1582 ASSERT_TRUE(tester.Init(GetProfile()));
1583
1584 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1585
1586 tester.AddHistory(kOrigin1, base::Time::Now());
1587 tester.AddHistory(kOrigin2, two_hours_ago);
1588 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1589 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1590
1591 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1592 BrowsingDataRemover::REMOVE_HISTORY, false);
1593
1594 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1595 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1596 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
1597 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1598 }
1599
1600 // This should crash (DCHECK) in Debug, but death tests don't work properly
1601 // here.
1602 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1603 TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
1604 RemoveHistoryTester tester;
1605 ASSERT_TRUE(tester.Init(GetProfile()));
1606 PrefService* prefs = GetProfile()->GetPrefs();
1607 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1608
1609 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1610
1611 tester.AddHistory(kOrigin1, base::Time::Now());
1612 tester.AddHistory(kOrigin2, two_hours_ago);
1613 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1614 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1615
1616 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1617 BrowsingDataRemover::REMOVE_HISTORY, false);
1618 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1619 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1620
1621 // Nothing should have been deleted.
1622 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1623 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1624 }
1625 #endif
1626
1627 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) {
1628 // Add some history.
1629 RemoveHistoryTester history_tester;
1630 ASSERT_TRUE(history_tester.Init(GetProfile()));
1631 history_tester.AddHistory(kOrigin1, base::Time::Now());
1632 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1633
1634 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1635 BrowsingDataRemover::REMOVE_COOKIES; 924 BrowsingDataRemover::REMOVE_COOKIES;
1636 925
1637 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 926 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1638 removal_mask, false); 927 removal_mask, false);
1639 928
1640 EXPECT_EQ(removal_mask, GetRemovalMask()); 929 EXPECT_EQ(removal_mask, GetRemovalMask());
1641 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask()); 930 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1642 EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1));
1643 931
1644 // The cookie would be deleted throught the StorageParition, check if the 932 // The cookie would be deleted throught the StorageParition, check if the
1645 // partition was requested to remove cookie. 933 // partition was requested to remove cookie.
1646 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 934 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1647 EXPECT_EQ(removal_data.remove_mask, 935 EXPECT_EQ(removal_data.remove_mask,
1648 StoragePartition::REMOVE_DATA_MASK_COOKIES); 936 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1649 EXPECT_EQ(removal_data.quota_storage_remove_mask, 937 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1650 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 938 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1651 } 939 }
1652 940
1653 // This should crash (DCHECK) in Debug, but death tests don't work properly 941 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverBoth) {
1654 // here.
1655 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1656 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
1657 PrefService* prefs = GetProfile()->GetPrefs();
1658 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1659
1660 // Add some history.
1661 RemoveHistoryTester history_tester;
1662 ASSERT_TRUE(history_tester.Init(GetProfile()));
1663 history_tester.AddHistory(kOrigin1, base::Time::Now());
1664 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1665
1666 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1667 BrowsingDataRemover::REMOVE_COOKIES;
1668
1669 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1670 removal_mask, false);
1671 EXPECT_EQ(removal_mask, GetRemovalMask());
1672 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1673
1674 // 1/2. History should remain.
1675 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1676
1677 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if
1678 // the partition was requested to remove cookie.
1679 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1680 EXPECT_EQ(removal_data.remove_mask,
1681 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1682 // Persistent storage won't be deleted, since the time period is not all time.
1683 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1684 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1685 }
1686 #endif
1687
1688 // Test that clearing history deletes favicons not associated with bookmarks.
1689 TEST_F(BrowsingDataRemoverTest, RemoveFaviconsForever) {
1690 GURL page_url("http://a");
1691
1692 RemoveFaviconTester favicon_tester;
1693 ASSERT_TRUE(favicon_tester.Init(GetProfile()));
1694 favicon_tester.VisitAndAddFavicon(page_url);
1695 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(page_url));
1696
1697 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1698 BrowsingDataRemover::REMOVE_HISTORY, false);
1699 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1700 EXPECT_FALSE(favicon_tester.HasFaviconForPageURL(page_url));
1701 }
1702
1703 // Test that a bookmark's favicon is expired and not deleted when clearing
1704 // history. Expiring the favicon causes the bookmark's favicon to be updated
1705 // when the user next visits the bookmarked page. Expiring the bookmark's
1706 // favicon is useful when the bookmark's favicon becomes incorrect (See
1707 // crbug.com/474421 for a sample bug which causes this).
1708 TEST_F(BrowsingDataRemoverTest, ExpireBookmarkFavicons) {
1709 GURL bookmarked_page("http://a");
1710
1711 TestingProfile* profile = GetProfile();
1712 profile->CreateBookmarkModel(true);
1713 bookmarks::BookmarkModel* bookmark_model =
1714 BookmarkModelFactory::GetForBrowserContext(profile);
1715 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
1716 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
1717 base::ASCIIToUTF16("a"), bookmarked_page);
1718
1719 RemoveFaviconTester favicon_tester;
1720 ASSERT_TRUE(favicon_tester.Init(GetProfile()));
1721 favicon_tester.VisitAndAddFavicon(bookmarked_page);
1722 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(bookmarked_page));
1723
1724 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1725 BrowsingDataRemover::REMOVE_HISTORY, false);
1726 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1727 EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page));
1728 }
1729
1730 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
1731 BlockUntilBrowsingDataRemoved( 942 BlockUntilBrowsingDataRemoved(
1732 base::Time(), base::Time::Max(), 943 base::Time(), base::Time::Max(),
1733 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 944 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1734 BrowsingDataRemover::REMOVE_WEBSQL | 945 BrowsingDataRemover::REMOVE_WEBSQL |
1735 BrowsingDataRemover::REMOVE_APPCACHE | 946 BrowsingDataRemover::REMOVE_APPCACHE |
1736 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | 947 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1737 BrowsingDataRemover::REMOVE_CACHE_STORAGE | 948 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1738 BrowsingDataRemover::REMOVE_INDEXEDDB, 949 BrowsingDataRemover::REMOVE_INDEXEDDB,
1739 false); 950 false);
1740 951
(...skipping 12 matching lines...) Expand all
1753 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 964 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1754 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 965 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1755 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 966 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1756 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS | 967 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1757 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | 968 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1758 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); 969 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1759 EXPECT_EQ(removal_data.quota_storage_remove_mask, 970 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1760 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 971 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1761 } 972 }
1762 973
1763 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) { 974 TEST_F(BrowsingDataRemoverImplTest,
975 RemoveQuotaManagedDataForeverOnlyTemporary) {
1764 #if BUILDFLAG(ENABLE_EXTENSIONS) 976 #if BUILDFLAG(ENABLE_EXTENSIONS)
1765 CreateMockPolicy(); 977 CreateMockPolicy();
1766 #endif 978 #endif
1767 979
1768 BlockUntilBrowsingDataRemoved( 980 BlockUntilBrowsingDataRemoved(
1769 base::Time(), base::Time::Max(), 981 base::Time(), base::Time::Max(),
1770 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 982 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1771 BrowsingDataRemover::REMOVE_WEBSQL | 983 BrowsingDataRemover::REMOVE_WEBSQL |
1772 BrowsingDataRemover::REMOVE_APPCACHE | 984 BrowsingDataRemover::REMOVE_APPCACHE |
1773 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | 985 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
(...skipping 23 matching lines...) Expand all
1797 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1009 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1798 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 1010 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1799 1011
1800 // Check that all related origin data would be removed, that is, origin 1012 // Check that all related origin data would be removed, that is, origin
1801 // matcher would match these origin. 1013 // matcher would match these origin.
1802 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1014 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1803 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1015 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1804 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1016 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1805 } 1017 }
1806 1018
1807 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) { 1019 TEST_F(BrowsingDataRemoverImplTest,
1020 RemoveQuotaManagedDataForeverOnlyPersistent) {
1808 #if BUILDFLAG(ENABLE_EXTENSIONS) 1021 #if BUILDFLAG(ENABLE_EXTENSIONS)
1809 CreateMockPolicy(); 1022 CreateMockPolicy();
1810 #endif 1023 #endif
1811 1024
1812 BlockUntilBrowsingDataRemoved( 1025 BlockUntilBrowsingDataRemoved(
1813 base::Time(), base::Time::Max(), 1026 base::Time(), base::Time::Max(),
1814 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1027 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1815 BrowsingDataRemover::REMOVE_WEBSQL | 1028 BrowsingDataRemover::REMOVE_WEBSQL |
1816 BrowsingDataRemover::REMOVE_APPCACHE | 1029 BrowsingDataRemover::REMOVE_APPCACHE |
1817 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | 1030 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
(...skipping 23 matching lines...) Expand all
1841 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1054 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1842 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 1055 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1843 1056
1844 // Check that all related origin data would be removed, that is, origin 1057 // Check that all related origin data would be removed, that is, origin
1845 // matcher would match these origin. 1058 // matcher would match these origin.
1846 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1059 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1847 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1060 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1848 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1061 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1849 } 1062 }
1850 1063
1851 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) { 1064 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForeverNeither) {
1852 #if BUILDFLAG(ENABLE_EXTENSIONS) 1065 #if BUILDFLAG(ENABLE_EXTENSIONS)
1853 CreateMockPolicy(); 1066 CreateMockPolicy();
1854 #endif 1067 #endif
1855 1068
1856 BlockUntilBrowsingDataRemoved( 1069 BlockUntilBrowsingDataRemoved(
1857 base::Time(), base::Time::Max(), 1070 base::Time(), base::Time::Max(),
1858 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1071 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1859 BrowsingDataRemover::REMOVE_WEBSQL | 1072 BrowsingDataRemover::REMOVE_WEBSQL |
1860 BrowsingDataRemover::REMOVE_APPCACHE | 1073 BrowsingDataRemover::REMOVE_APPCACHE |
1861 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | 1074 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
(...skipping 23 matching lines...) Expand all
1885 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1098 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1886 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 1099 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1887 1100
1888 // Check that all related origin data would be removed, that is, origin 1101 // Check that all related origin data would be removed, that is, origin
1889 // matcher would match these origin. 1102 // matcher would match these origin.
1890 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1103 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1891 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1104 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1892 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1105 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1893 } 1106 }
1894 1107
1895 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) { 1108 TEST_F(BrowsingDataRemoverImplTest,
1109 RemoveQuotaManagedDataForeverSpecificOrigin) {
1896 RegistrableDomainFilterBuilder builder( 1110 RegistrableDomainFilterBuilder builder(
1897 RegistrableDomainFilterBuilder::WHITELIST); 1111 RegistrableDomainFilterBuilder::WHITELIST);
1898 builder.AddRegisterableDomain(kTestRegisterableDomain1); 1112 builder.AddRegisterableDomain(kTestRegisterableDomain1);
1899 // Remove Origin 1. 1113 // Remove Origin 1.
1900 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), 1114 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1901 BrowsingDataRemover::REMOVE_APPCACHE | 1115 BrowsingDataRemover::REMOVE_APPCACHE |
1902 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | 1116 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1903 BrowsingDataRemover::REMOVE_CACHE_STORAGE | 1117 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1904 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1118 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1905 BrowsingDataRemover::REMOVE_INDEXEDDB | 1119 BrowsingDataRemover::REMOVE_INDEXEDDB |
(...skipping 20 matching lines...) Expand all
1926 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE | 1140 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1927 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); 1141 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1928 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1142 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1929 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 1143 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1930 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1144 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1931 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1145 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1932 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1146 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1933 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy())); 1147 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin4, mock_policy()));
1934 } 1148 }
1935 1149
1936 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) { 1150 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForLastHour) {
1937 BlockUntilBrowsingDataRemoved( 1151 BlockUntilBrowsingDataRemoved(
1938 AnHourAgo(), base::Time::Max(), 1152 AnHourAgo(), base::Time::Max(),
1939 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1153 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1940 BrowsingDataRemover::REMOVE_WEBSQL | 1154 BrowsingDataRemover::REMOVE_WEBSQL |
1941 BrowsingDataRemover::REMOVE_APPCACHE | 1155 BrowsingDataRemover::REMOVE_APPCACHE |
1942 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | 1156 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1943 BrowsingDataRemover::REMOVE_CACHE_STORAGE | 1157 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1944 BrowsingDataRemover::REMOVE_INDEXEDDB, 1158 BrowsingDataRemover::REMOVE_INDEXEDDB,
1945 false); 1159 false);
1946 1160
(...skipping 19 matching lines...) Expand all
1966 1180
1967 // Persistent data would be left out since we are not removing from 1181 // Persistent data would be left out since we are not removing from
1968 // beginning of time. 1182 // beginning of time.
1969 uint32_t expected_quota_mask = 1183 uint32_t expected_quota_mask =
1970 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 1184 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1971 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); 1185 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1972 // Check removal begin time. 1186 // Check removal begin time.
1973 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 1187 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1974 } 1188 }
1975 1189
1976 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) { 1190 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedDataForLastWeek) {
1977 BlockUntilBrowsingDataRemoved( 1191 BlockUntilBrowsingDataRemoved(
1978 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(), 1192 base::Time::Now() - base::TimeDelta::FromDays(7), base::Time::Max(),
1979 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1193 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1980 BrowsingDataRemover::REMOVE_WEBSQL | 1194 BrowsingDataRemover::REMOVE_WEBSQL |
1981 BrowsingDataRemover::REMOVE_APPCACHE | 1195 BrowsingDataRemover::REMOVE_APPCACHE |
1982 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | 1196 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1983 BrowsingDataRemover::REMOVE_CACHE_STORAGE | 1197 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1984 BrowsingDataRemover::REMOVE_INDEXEDDB, 1198 BrowsingDataRemover::REMOVE_INDEXEDDB,
1985 false); 1199 false);
1986 1200
(...skipping 19 matching lines...) Expand all
2006 1220
2007 // Persistent data would be left out since we are not removing from 1221 // Persistent data would be left out since we are not removing from
2008 // beginning of time. 1222 // beginning of time.
2009 uint32_t expected_quota_mask = 1223 uint32_t expected_quota_mask =
2010 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 1224 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
2011 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); 1225 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
2012 // Check removal begin time. 1226 // Check removal begin time.
2013 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 1227 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
2014 } 1228 }
2015 1229
2016 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) { 1230 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedUnprotectedOrigins) {
2017 #if BUILDFLAG(ENABLE_EXTENSIONS) 1231 #if BUILDFLAG(ENABLE_EXTENSIONS)
2018 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); 1232 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
2019 // Protect kOrigin1. 1233 // Protect kOrigin1.
2020 policy->AddProtected(kOrigin1.GetOrigin()); 1234 policy->AddProtected(kOrigin1.GetOrigin());
2021 #endif 1235 #endif
2022 1236
2023 BlockUntilBrowsingDataRemoved( 1237 BlockUntilBrowsingDataRemoved(
2024 base::Time(), base::Time::Max(), 1238 base::Time(), base::Time::Max(),
2025 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1239 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
2026 BrowsingDataRemover::REMOVE_WEBSQL | 1240 BrowsingDataRemover::REMOVE_WEBSQL |
(...skipping 25 matching lines...) Expand all
2052 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1266 EXPECT_EQ(removal_data.quota_storage_remove_mask,
2053 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 1267 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
2054 1268
2055 // Check OriginMatcherFunction. 1269 // Check OriginMatcherFunction.
2056 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(), 1270 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
2057 removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1271 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
2058 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1272 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
2059 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1273 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
2060 } 1274 }
2061 1275
2062 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) { 1276 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedSpecificOrigin) {
2063 #if BUILDFLAG(ENABLE_EXTENSIONS) 1277 #if BUILDFLAG(ENABLE_EXTENSIONS)
2064 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); 1278 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
2065 // Protect kOrigin1. 1279 // Protect kOrigin1.
2066 policy->AddProtected(kOrigin1.GetOrigin()); 1280 policy->AddProtected(kOrigin1.GetOrigin());
2067 #endif 1281 #endif
2068 1282
2069 RegistrableDomainFilterBuilder builder( 1283 RegistrableDomainFilterBuilder builder(
2070 RegistrableDomainFilterBuilder::WHITELIST); 1284 RegistrableDomainFilterBuilder::WHITELIST);
2071 builder.AddRegisterableDomain(kTestRegisterableDomain1); 1285 builder.AddRegisterableDomain(kTestRegisterableDomain1);
2072 1286
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 1318
2105 // Check OriginMatcherFunction. 1319 // Check OriginMatcherFunction.
2106 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(), 1320 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
2107 removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1321 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
2108 // Since we use the matcher function to validate origins now, this should 1322 // Since we use the matcher function to validate origins now, this should
2109 // return false for the origins we're not trying to clear. 1323 // return false for the origins we're not trying to clear.
2110 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1324 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
2111 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1325 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
2112 } 1326 }
2113 1327
2114 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) { 1328 TEST_F(BrowsingDataRemoverImplTest, RemoveQuotaManagedProtectedOrigins) {
2115 #if BUILDFLAG(ENABLE_EXTENSIONS) 1329 #if BUILDFLAG(ENABLE_EXTENSIONS)
2116 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy(); 1330 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
2117 // Protect kOrigin1. 1331 // Protect kOrigin1.
2118 policy->AddProtected(kOrigin1.GetOrigin()); 1332 policy->AddProtected(kOrigin1.GetOrigin());
2119 #endif 1333 #endif
2120 1334
2121 // Try to remove kOrigin1. Expect success. 1335 // Try to remove kOrigin1. Expect success.
2122 BlockUntilBrowsingDataRemoved( 1336 BlockUntilBrowsingDataRemoved(
2123 base::Time(), base::Time::Max(), 1337 base::Time(), base::Time::Max(),
2124 BrowsingDataRemover::REMOVE_APPCACHE | 1338 BrowsingDataRemover::REMOVE_APPCACHE |
(...skipping 27 matching lines...) Expand all
2152 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1366 EXPECT_EQ(removal_data.quota_storage_remove_mask,
2153 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 1367 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
2154 1368
2155 // Check OriginMatcherFunction, |kOrigin1| would match mask since we 1369 // Check OriginMatcherFunction, |kOrigin1| would match mask since we
2156 // would have 'protected' specified in origin_type_mask. 1370 // would have 'protected' specified in origin_type_mask.
2157 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy())); 1371 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
2158 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy())); 1372 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
2159 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy())); 1373 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
2160 } 1374 }
2161 1375
2162 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) { 1376 TEST_F(BrowsingDataRemoverImplTest,
1377 RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
2163 #if BUILDFLAG(ENABLE_EXTENSIONS) 1378 #if BUILDFLAG(ENABLE_EXTENSIONS)
2164 CreateMockPolicy(); 1379 CreateMockPolicy();
2165 #endif 1380 #endif
2166 1381
2167 BlockUntilBrowsingDataRemoved( 1382 BlockUntilBrowsingDataRemoved(
2168 base::Time(), base::Time::Max(), 1383 base::Time(), base::Time::Max(),
2169 BrowsingDataRemover::REMOVE_APPCACHE | 1384 BrowsingDataRemover::REMOVE_APPCACHE |
2170 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | 1385 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
2171 BrowsingDataRemover::REMOVE_CACHE_STORAGE | 1386 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
2172 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1387 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
(...skipping 22 matching lines...) Expand all
2195 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB); 1410 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
2196 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1411 EXPECT_EQ(removal_data.quota_storage_remove_mask,
2197 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL); 1412 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
2198 1413
2199 // Check that extension and devtools data wouldn't be removed, that is, 1414 // Check that extension and devtools data wouldn't be removed, that is,
2200 // origin matcher would not match these origin. 1415 // origin matcher would not match these origin.
2201 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy())); 1416 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
2202 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy())); 1417 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy()));
2203 } 1418 }
2204 1419
2205 TEST_F(BrowsingDataRemoverTest, TimeBasedHistoryRemoval) {
2206 RemoveHistoryTester tester;
2207 ASSERT_TRUE(tester.Init(GetProfile()));
2208
2209 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
2210
2211 tester.AddHistory(kOrigin1, base::Time::Now());
2212 tester.AddHistory(kOrigin2, two_hours_ago);
2213 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
2214 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
2215
2216 RegistrableDomainFilterBuilder builder(
2217 RegistrableDomainFilterBuilder::BLACKLIST);
2218 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
2219 BrowsingDataRemover::REMOVE_HISTORY, builder);
2220
2221 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
2222 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
2223 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
2224 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
2225 }
2226
2227 // Verify that clearing autofill form data works.
2228 TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) {
2229 GetProfile()->CreateWebDataService();
2230 RemoveAutofillTester tester(GetProfile());
2231
2232 ASSERT_FALSE(tester.HasProfile());
2233 tester.AddProfilesAndCards();
2234 ASSERT_TRUE(tester.HasProfile());
2235
2236 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
2237 BrowsingDataRemover::REMOVE_FORM_DATA, false);
2238
2239 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
2240 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
2241 ASSERT_FALSE(tester.HasProfile());
2242 }
2243
2244 TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) {
2245 GetProfile()->CreateWebDataService();
2246 RemoveAutofillTester tester(GetProfile());
2247
2248 ASSERT_FALSE(tester.HasProfile());
2249 tester.AddProfilesAndCards();
2250 ASSERT_TRUE(tester.HasProfile());
2251
2252 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2253 BrowsingDataRemover::REMOVE_FORM_DATA, false);
2254
2255 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
2256 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
2257 ASSERT_FALSE(tester.HasProfile());
2258 }
2259
2260 // Verify that clearing autofill form data works.
2261 TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) {
2262 GetProfile()->CreateWebDataService();
2263 RemoveAutofillTester tester(GetProfile());
2264
2265 tester.AddProfilesAndCards();
2266 EXPECT_FALSE(tester.HasOrigin(std::string()));
2267 EXPECT_TRUE(tester.HasOrigin(kWebOrigin));
2268 EXPECT_TRUE(tester.HasOrigin(autofill::kSettingsOrigin));
2269
2270 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
2271 BrowsingDataRemover::REMOVE_HISTORY, false);
2272
2273 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
2274 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
2275 EXPECT_TRUE(tester.HasOrigin(std::string()));
2276 EXPECT_FALSE(tester.HasOrigin(kWebOrigin));
2277 EXPECT_TRUE(tester.HasOrigin(autofill::kSettingsOrigin));
2278 }
2279
2280 class InspectableCompletionObserver 1420 class InspectableCompletionObserver
2281 : public BrowsingDataRemoverCompletionObserver { 1421 : public BrowsingDataRemoverCompletionObserver {
2282 public: 1422 public:
2283 explicit InspectableCompletionObserver(BrowsingDataRemover* remover) 1423 explicit InspectableCompletionObserver(BrowsingDataRemover* remover)
2284 : BrowsingDataRemoverCompletionObserver(remover) {} 1424 : BrowsingDataRemoverCompletionObserver(remover) {}
2285 ~InspectableCompletionObserver() override {} 1425 ~InspectableCompletionObserver() override {}
2286 1426
2287 bool called() { return called_; } 1427 bool called() { return called_; }
2288 1428
2289 protected: 1429 protected:
2290 void OnBrowsingDataRemoverDone() override { 1430 void OnBrowsingDataRemoverDone() override {
2291 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone(); 1431 BrowsingDataRemoverCompletionObserver::OnBrowsingDataRemoverDone();
2292 called_ = true; 1432 called_ = true;
2293 } 1433 }
2294 1434
2295 private: 1435 private:
2296 bool called_ = false; 1436 bool called_ = false;
2297 }; 1437 };
2298 1438
2299 TEST_F(BrowsingDataRemoverTest, CompletionInhibition) { 1439 TEST_F(BrowsingDataRemoverImplTest, CompletionInhibition) {
2300 // The |completion_inhibitor| on the stack should prevent removal sessions 1440 // The |completion_inhibitor| on the stack should prevent removal sessions
2301 // from completing until after ContinueToCompletion() is called. 1441 // from completing until after ContinueToCompletion() is called.
2302 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 1442 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
2303 1443
2304 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( 1444 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
2305 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile())); 1445 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext()));
2306 InspectableCompletionObserver completion_observer(remover); 1446 InspectableCompletionObserver completion_observer(remover);
2307 remover->RemoveAndReply(base::Time(), base::Time::Max(), 1447 remover->RemoveAndReply(base::Time(), base::Time::Max(),
2308 BrowsingDataRemover::REMOVE_HISTORY, 1448 BrowsingDataRemover::REMOVE_HISTORY,
2309 BrowsingDataHelper::UNPROTECTED_WEB, 1449 BrowsingDataHelper::UNPROTECTED_WEB,
2310 &completion_observer); 1450 &completion_observer);
2311 1451
2312 // Process messages until the inhibitor is notified, and then some, to make 1452 // Process messages until the inhibitor is notified, and then some, to make
2313 // sure we do not complete asynchronously before ContinueToCompletion() is 1453 // sure we do not complete asynchronously before ContinueToCompletion() is
2314 // called. 1454 // called.
2315 completion_inhibitor.BlockUntilNearCompletion(); 1455 completion_inhibitor.BlockUntilNearCompletion();
2316 base::RunLoop().RunUntilIdle(); 1456 base::RunLoop().RunUntilIdle();
2317 1457
2318 // Verify that the removal has not yet been completed and the observer has 1458 // Verify that the removal has not yet been completed and the observer has
2319 // not been called. 1459 // not been called.
2320 EXPECT_TRUE(remover->is_removing()); 1460 EXPECT_TRUE(remover->is_removing());
2321 EXPECT_FALSE(completion_observer.called()); 1461 EXPECT_FALSE(completion_observer.called());
2322 1462
2323 // Now run the removal process until completion, and verify that observers are 1463 // Now run the removal process until completion, and verify that observers are
2324 // now notified, and the notifications is sent out. 1464 // now notified, and the notifications is sent out.
2325 completion_inhibitor.ContinueToCompletion(); 1465 completion_inhibitor.ContinueToCompletion();
2326 completion_observer.BlockUntilCompletion(); 1466 completion_observer.BlockUntilCompletion();
2327 1467
2328 EXPECT_FALSE(remover->is_removing()); 1468 EXPECT_FALSE(remover->is_removing());
2329 EXPECT_TRUE(completion_observer.called()); 1469 EXPECT_TRUE(completion_observer.called());
2330 } 1470 }
2331 1471
2332 TEST_F(BrowsingDataRemoverTest, EarlyShutdown) { 1472 TEST_F(BrowsingDataRemoverImplTest, EarlyShutdown) {
2333 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( 1473 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
2334 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile())); 1474 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext()));
2335 InspectableCompletionObserver completion_observer(remover); 1475 InspectableCompletionObserver completion_observer(remover);
2336 BrowsingDataRemoverCompletionInhibitor completion_inhibitor; 1476 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
2337 remover->RemoveAndReply(base::Time(), base::Time::Max(), 1477 remover->RemoveAndReply(base::Time(), base::Time::Max(),
2338 BrowsingDataRemover::REMOVE_HISTORY, 1478 BrowsingDataRemover::REMOVE_HISTORY,
2339 BrowsingDataHelper::UNPROTECTED_WEB, 1479 BrowsingDataHelper::UNPROTECTED_WEB,
2340 &completion_observer); 1480 &completion_observer);
2341 1481
2342 completion_inhibitor.BlockUntilNearCompletion(); 1482 completion_inhibitor.BlockUntilNearCompletion();
2343 1483
2344 // Verify that the deletion has not yet been completed and the observer has 1484 // Verify that the deletion has not yet been completed and the observer has
2345 // not been called. 1485 // not been called.
2346 EXPECT_TRUE(remover->is_removing()); 1486 EXPECT_TRUE(remover->is_removing());
2347 EXPECT_FALSE(completion_observer.called()); 1487 EXPECT_FALSE(completion_observer.called());
2348 1488
2349 // Destroying the profile should trigger the notification. 1489 // Destroying the profile should trigger the notification.
2350 DestroyProfile(); 1490 DestroyBrowserContext();
2351 1491
2352 EXPECT_TRUE(completion_observer.called()); 1492 EXPECT_TRUE(completion_observer.called());
2353 1493
2354 // Finishing after shutdown shouldn't break anything. 1494 // Finishing after shutdown shouldn't break anything.
2355 completion_inhibitor.ContinueToCompletion(); 1495 completion_inhibitor.ContinueToCompletion();
2356 completion_observer.BlockUntilCompletion(); 1496 completion_observer.BlockUntilCompletion();
2357 } 1497 }
2358 1498
2359 TEST_F(BrowsingDataRemoverTest, ZeroSuggestCacheClear) { 1499 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByTimeOnly) {
2360 PrefService* prefs = GetProfile()->GetPrefs(); 1500 RemoveDownloadsTester tester(GetBrowserContext());
2361 prefs->SetString(omnibox::kZeroSuggestCachedResults,
2362 "[\"\", [\"foo\", \"bar\"]]");
2363 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2364 BrowsingDataRemover::REMOVE_COOKIES, false);
2365
2366 // Expect the prefs to be cleared when cookies are removed.
2367 EXPECT_TRUE(prefs->GetString(omnibox::kZeroSuggestCachedResults).empty());
2368 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
2369 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
2370 }
2371
2372 #if defined(OS_CHROMEOS)
2373 TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) {
2374 chromeos::ScopedTestDeviceSettingsService test_device_settings_service;
2375 chromeos::ScopedTestCrosSettings test_cros_settings;
2376 chromeos::MockUserManager* mock_user_manager =
2377 new testing::NiceMock<chromeos::MockUserManager>();
2378 mock_user_manager->SetActiveUser(
2379 AccountId::FromUserEmail("test@example.com"));
2380 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager);
2381
2382 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter =
2383 chromeos::DBusThreadManager::GetSetterForTesting();
2384 chromeos::MockCryptohomeClient* cryptohome_client =
2385 new chromeos::MockCryptohomeClient;
2386 dbus_setter->SetCryptohomeClient(
2387 std::unique_ptr<chromeos::CryptohomeClient>(cryptohome_client));
2388
2389 // Expect exactly one call. No calls means no attempt to delete keys and more
2390 // than one call means a significant performance problem.
2391 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
2392 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
2393
2394 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2395 BrowsingDataRemover::REMOVE_MEDIA_LICENSES,
2396 false);
2397
2398 chromeos::DBusThreadManager::Shutdown();
2399 }
2400 #endif
2401
2402 TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) {
2403 const ClearDomainReliabilityTester& tester =
2404 clear_domain_reliability_tester();
2405
2406 EXPECT_EQ(0u, tester.clear_count());
2407 }
2408
2409 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) {
2410 const ClearDomainReliabilityTester& tester =
2411 clear_domain_reliability_tester();
2412
2413 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2414 BrowsingDataRemover::REMOVE_HISTORY, false);
2415 EXPECT_EQ(1u, tester.clear_count());
2416 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode());
2417 EXPECT_TRUE(ProbablySameFilters(
2418 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter()));
2419 }
2420
2421 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons_WithFilter) {
2422 const ClearDomainReliabilityTester& tester =
2423 clear_domain_reliability_tester();
2424
2425 RegistrableDomainFilterBuilder builder(
2426 RegistrableDomainFilterBuilder::WHITELIST);
2427 builder.AddRegisterableDomain(kTestRegisterableDomain1);
2428
2429 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
2430 BrowsingDataRemover::REMOVE_HISTORY, builder);
2431 EXPECT_EQ(1u, tester.clear_count());
2432 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode());
2433 EXPECT_TRUE(ProbablySameFilters(
2434 builder.BuildGeneralFilter(), tester.last_filter()));
2435 }
2436
2437 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) {
2438 const ClearDomainReliabilityTester& tester =
2439 clear_domain_reliability_tester();
2440
2441 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2442 BrowsingDataRemover::REMOVE_COOKIES, false);
2443 EXPECT_EQ(1u, tester.clear_count());
2444 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2445 EXPECT_TRUE(ProbablySameFilters(
2446 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter()));
2447 }
2448
2449 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts_WithFilter) {
2450 const ClearDomainReliabilityTester& tester =
2451 clear_domain_reliability_tester();
2452
2453 RegistrableDomainFilterBuilder builder(
2454 RegistrableDomainFilterBuilder::WHITELIST);
2455 builder.AddRegisterableDomain(kTestRegisterableDomain1);
2456
2457 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
2458 BrowsingDataRemover::REMOVE_COOKIES, builder);
2459 EXPECT_EQ(1u, tester.clear_count());
2460 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2461 EXPECT_TRUE(ProbablySameFilters(
2462 builder.BuildGeneralFilter(), tester.last_filter()));
2463 }
2464
2465 TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) {
2466 const ClearDomainReliabilityTester& tester =
2467 clear_domain_reliability_tester();
2468
2469 BlockUntilBrowsingDataRemoved(
2470 base::Time(), base::Time::Max(),
2471 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES,
2472 false);
2473 EXPECT_EQ(1u, tester.clear_count());
2474 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2475 }
2476
2477 TEST_F(BrowsingDataRemoverTest, DomainReliability_ProtectedOrigins) {
2478 const ClearDomainReliabilityTester& tester =
2479 clear_domain_reliability_tester();
2480
2481 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2482 BrowsingDataRemover::REMOVE_COOKIES, true);
2483 EXPECT_EQ(1u, tester.clear_count());
2484 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2485 }
2486
2487 // TODO(juliatuttle): This isn't actually testing the no-monitor case, since
2488 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed
2489 // for some unrelated test cases. This should be fixed so it tests the no-
2490 // monitor case again.
2491 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) {
2492 BlockUntilBrowsingDataRemoved(
2493 base::Time(), base::Time::Max(),
2494 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES,
2495 false);
2496 }
2497
2498 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByTimeOnly) {
2499 RemoveDownloadsTester tester(GetProfile());
2500 base::Callback<bool(const GURL&)> filter = 1501 base::Callback<bool(const GURL&)> filter =
2501 BrowsingDataFilterBuilder::BuildNoopFilter(); 1502 BrowsingDataFilterBuilder::BuildNoopFilter();
2502 1503
2503 EXPECT_CALL( 1504 EXPECT_CALL(
2504 *tester.download_manager(), 1505 *tester.download_manager(),
2505 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); 1506 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
2506 1507
2507 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(), 1508 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2508 BrowsingDataRemover::REMOVE_DOWNLOADS, false); 1509 BrowsingDataRemover::REMOVE_DOWNLOADS, false);
2509 } 1510 }
2510 1511
2511 TEST_F(BrowsingDataRemoverTest, RemoveDownloadsByOrigin) { 1512 TEST_F(BrowsingDataRemoverImplTest, RemoveDownloadsByOrigin) {
2512 RemoveDownloadsTester tester(GetProfile()); 1513 RemoveDownloadsTester tester(GetBrowserContext());
2513 RegistrableDomainFilterBuilder builder( 1514 RegistrableDomainFilterBuilder builder(
2514 RegistrableDomainFilterBuilder::WHITELIST); 1515 RegistrableDomainFilterBuilder::WHITELIST);
2515 builder.AddRegisterableDomain(kTestRegisterableDomain1); 1516 builder.AddRegisterableDomain(kTestRegisterableDomain1);
2516 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter(); 1517 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter();
2517 1518
2518 EXPECT_CALL( 1519 EXPECT_CALL(
2519 *tester.download_manager(), 1520 *tester.download_manager(),
2520 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _)); 1521 RemoveDownloadsByURLAndTime(ProbablySameFilter(filter), _, _));
2521 1522
2522 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(), 1523 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
2523 BrowsingDataRemover::REMOVE_DOWNLOADS, builder); 1524 BrowsingDataRemover::REMOVE_DOWNLOADS, builder);
2524 } 1525 }
2525 1526
2526 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatistics) {
2527 RemovePasswordsTester tester(GetProfile());
2528 base::Callback<bool(const GURL&)> empty_filter;
2529
2530 EXPECT_CALL(*tester.store(), RemoveStatisticsByOriginAndTimeImpl(
2531 ProbablySameFilter(empty_filter),
2532 base::Time(), base::Time::Max()));
2533 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2534 BrowsingDataRemover::REMOVE_HISTORY, false);
2535 }
2536
2537 TEST_F(BrowsingDataRemoverTest, RemovePasswordStatisticsByOrigin) {
2538 RemovePasswordsTester tester(GetProfile());
2539
2540 RegistrableDomainFilterBuilder builder(
2541 RegistrableDomainFilterBuilder::WHITELIST);
2542 builder.AddRegisterableDomain(kTestRegisterableDomain1);
2543 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter();
2544
2545 EXPECT_CALL(*tester.store(),
2546 RemoveStatisticsByOriginAndTimeImpl(
2547 ProbablySameFilter(filter), base::Time(), base::Time::Max()));
2548 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
2549 BrowsingDataRemover::REMOVE_HISTORY, builder);
2550 }
2551
2552 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByTimeOnly) {
2553 RemovePasswordsTester tester(GetProfile());
2554 base::Callback<bool(const GURL&)> filter =
2555 BrowsingDataFilterBuilder::BuildNoopFilter();
2556
2557 EXPECT_CALL(*tester.store(),
2558 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _))
2559 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
2560 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2561 BrowsingDataRemover::REMOVE_PASSWORDS, false);
2562 }
2563
2564 TEST_F(BrowsingDataRemoverTest, RemovePasswordsByOrigin) {
2565 RemovePasswordsTester tester(GetProfile());
2566 RegistrableDomainFilterBuilder builder(
2567 RegistrableDomainFilterBuilder::WHITELIST);
2568 builder.AddRegisterableDomain(kTestRegisterableDomain1);
2569 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter();
2570
2571 EXPECT_CALL(*tester.store(),
2572 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _))
2573 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
2574 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
2575 BrowsingDataRemover::REMOVE_PASSWORDS, builder);
2576 }
2577
2578 TEST_F(BrowsingDataRemoverTest, DisableAutoSignIn) {
2579 RemovePasswordsTester tester(GetProfile());
2580 base::Callback<bool(const GURL&)> empty_filter =
2581 BrowsingDataFilterBuilder::BuildNoopFilter();
2582
2583 EXPECT_CALL(
2584 *tester.store(),
2585 DisableAutoSignInForOriginsImpl(ProbablySameFilter(empty_filter)))
2586 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
2587
2588 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2589 BrowsingDataRemover::REMOVE_COOKIES, false);
2590 }
2591
2592 TEST_F(BrowsingDataRemoverTest, DisableAutoSignInAfterRemovingPasswords) {
2593 RemovePasswordsTester tester(GetProfile());
2594 base::Callback<bool(const GURL&)> empty_filter =
2595 BrowsingDataFilterBuilder::BuildNoopFilter();
2596
2597 EXPECT_CALL(*tester.store(), RemoveLoginsByURLAndTimeImpl(_, _, _))
2598 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
2599 EXPECT_CALL(
2600 *tester.store(),
2601 DisableAutoSignInForOriginsImpl(ProbablySameFilter(empty_filter)))
2602 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
2603
2604 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2605 BrowsingDataRemover::REMOVE_COOKIES |
2606 BrowsingDataRemover::REMOVE_PASSWORDS,
2607 false);
2608 }
2609
2610 TEST_F(BrowsingDataRemoverTest, RemoveContentSettingsWithBlacklist) {
2611 // Add our settings.
2612 HostContentSettingsMap* host_content_settings_map =
2613 HostContentSettingsMapFactory::GetForProfile(GetProfile());
2614 host_content_settings_map->SetWebsiteSettingDefaultScope(
2615 kOrigin1, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
2616 base::MakeUnique<base::DictionaryValue>());
2617 host_content_settings_map->SetWebsiteSettingDefaultScope(
2618 kOrigin2, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
2619 base::MakeUnique<base::DictionaryValue>());
2620 host_content_settings_map->SetWebsiteSettingDefaultScope(
2621 kOrigin3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
2622 base::MakeUnique<base::DictionaryValue>());
2623 host_content_settings_map->SetWebsiteSettingDefaultScope(
2624 kOrigin4, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
2625 base::MakeUnique<base::DictionaryValue>());
2626
2627 // Clear all except for origin1 and origin3.
2628 RegistrableDomainFilterBuilder filter(
2629 RegistrableDomainFilterBuilder::BLACKLIST);
2630 filter.AddRegisterableDomain(kTestRegisterableDomain1);
2631 filter.AddRegisterableDomain(kTestRegisterableDomain3);
2632 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
2633 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
2634 filter);
2635
2636 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, GetRemovalMask());
2637 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
2638
2639 // Verify we only have true, and they're origin1, origin3, and origin4.
2640 ContentSettingsForOneType host_settings;
2641 host_content_settings_map->GetSettingsForOneType(
2642 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings);
2643 EXPECT_EQ(3u, host_settings.size());
2644 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin1),
2645 host_settings[0].primary_pattern)
2646 << host_settings[0].primary_pattern.ToString();
2647 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin4),
2648 host_settings[1].primary_pattern)
2649 << host_settings[1].primary_pattern.ToString();
2650 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin3),
2651 host_settings[2].primary_pattern)
2652 << host_settings[2].primary_pattern.ToString();
2653 }
2654
2655 TEST_F(BrowsingDataRemoverTest, RemoveDurablePermission) {
2656 // Add our settings.
2657 HostContentSettingsMap* host_content_settings_map =
2658 HostContentSettingsMapFactory::GetForProfile(GetProfile());
2659
2660 DurableStoragePermissionContext durable_permission(GetProfile());
2661 durable_permission.UpdateContentSetting(kOrigin1, GURL(),
2662 CONTENT_SETTING_ALLOW);
2663 durable_permission.UpdateContentSetting(kOrigin2, GURL(),
2664 CONTENT_SETTING_ALLOW);
2665
2666 // Clear all except for origin1 and origin3.
2667 RegistrableDomainFilterBuilder filter(
2668 RegistrableDomainFilterBuilder::BLACKLIST);
2669 filter.AddRegisterableDomain(kTestRegisterableDomain1);
2670 filter.AddRegisterableDomain(kTestRegisterableDomain3);
2671 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
2672 BrowsingDataRemover::REMOVE_DURABLE_PERMISSION,
2673 filter);
2674
2675 EXPECT_EQ(BrowsingDataRemover::REMOVE_DURABLE_PERMISSION, GetRemovalMask());
2676 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
2677
2678 // Verify we only have allow for the first origin.
2679 ContentSettingsForOneType host_settings;
2680 host_content_settings_map->GetSettingsForOneType(
2681 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string(), &host_settings);
2682
2683 ASSERT_EQ(2u, host_settings.size());
2684 // Only the first should should have a setting.
2685 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin1),
2686 host_settings[0].primary_pattern)
2687 << host_settings[0].primary_pattern.ToString();
2688 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_settings[0].setting);
2689
2690 // And our wildcard.
2691 EXPECT_EQ(ContentSettingsPattern::Wildcard(),
2692 host_settings[1].primary_pattern)
2693 << host_settings[1].primary_pattern.ToString();
2694 EXPECT_EQ(CONTENT_SETTING_ASK, host_settings[1].setting);
2695 }
2696
2697 // Test that removing cookies clears HTTP auth data.
2698 TEST_F(BrowsingDataRemoverTest, ClearHttpAuthCache_RemoveCookies) {
2699 net::HttpNetworkSession* http_session = GetProfile()
2700 ->GetRequestContext()
2701 ->GetURLRequestContext()
2702 ->http_transaction_factory()
2703 ->GetSession();
2704 DCHECK(http_session);
2705
2706 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache();
2707 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC,
2708 "test challenge",
2709 net::AuthCredentials(base::ASCIIToUTF16("foo"),
2710 base::ASCIIToUTF16("bar")),
2711 "/");
2712 CHECK(http_auth_cache->Lookup(kOrigin1, kTestRealm,
2713 net::HttpAuth::AUTH_SCHEME_BASIC));
2714
2715 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2716 BrowsingDataRemover::REMOVE_COOKIES, false);
2717
2718 EXPECT_EQ(nullptr, http_auth_cache->Lookup(kOrigin1, kTestRealm,
2719 net::HttpAuth::AUTH_SCHEME_BASIC));
2720 }
2721
2722 // Test that removing passwords clears HTTP auth data.
2723 TEST_F(BrowsingDataRemoverTest, ClearHttpAuthCache_RemovePasswords) {
2724 net::HttpNetworkSession* http_session = GetProfile()
2725 ->GetRequestContext()
2726 ->GetURLRequestContext()
2727 ->http_transaction_factory()
2728 ->GetSession();
2729 DCHECK(http_session);
2730
2731 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache();
2732 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC,
2733 "test challenge",
2734 net::AuthCredentials(base::ASCIIToUTF16("foo"),
2735 base::ASCIIToUTF16("bar")),
2736 "/");
2737 CHECK(http_auth_cache->Lookup(kOrigin1, kTestRealm,
2738 net::HttpAuth::AUTH_SCHEME_BASIC));
2739
2740 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
2741 BrowsingDataRemover::REMOVE_PASSWORDS, false);
2742
2743 EXPECT_EQ(nullptr, http_auth_cache->Lookup(kOrigin1, kTestRealm,
2744 net::HttpAuth::AUTH_SCHEME_BASIC));
2745 }
2746
2747 TEST_F(BrowsingDataRemoverTest, ClearPermissionPromptCounts) {
2748 RemovePermissionPromptCountsTest tester(GetProfile());
2749
2750 RegistrableDomainFilterBuilder filter_builder_1(
2751 RegistrableDomainFilterBuilder::WHITELIST);
2752 filter_builder_1.AddRegisterableDomain(kTestRegisterableDomain1);
2753
2754 RegistrableDomainFilterBuilder filter_builder_2(
2755 RegistrableDomainFilterBuilder::BLACKLIST);
2756 filter_builder_2.AddRegisterableDomain(kTestRegisterableDomain1);
2757
2758 {
2759 // Test REMOVE_HISTORY.
2760 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2761 content::PermissionType::GEOLOCATION));
2762 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1,
2763 content::PermissionType::GEOLOCATION));
2764 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2765 content::PermissionType::NOTIFICATIONS));
2766 tester.ShouldChangeDismissalToBlock(kOrigin1,
2767 content::PermissionType::MIDI_SYSEX);
2768 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2,
2769 content::PermissionType::DURABLE_STORAGE));
2770 tester.ShouldChangeDismissalToBlock(kOrigin2,
2771 content::PermissionType::NOTIFICATIONS);
2772
2773 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
2774 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
2775 filter_builder_1);
2776
2777 // kOrigin1 should be gone, but kOrigin2 remains.
2778 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2779 content::PermissionType::GEOLOCATION));
2780 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2781 content::PermissionType::NOTIFICATIONS));
2782 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
2783 content::PermissionType::MIDI_SYSEX));
2784 EXPECT_EQ(1, tester.GetIgnoreCount(
2785 kOrigin2, content::PermissionType::DURABLE_STORAGE));
2786 EXPECT_EQ(1, tester.GetDismissCount(
2787 kOrigin2, content::PermissionType::NOTIFICATIONS));
2788
2789 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
2790 BrowsingDataRemover::REMOVE_HISTORY, false);
2791
2792 // Everything should be gone.
2793 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2794 content::PermissionType::GEOLOCATION));
2795 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2796 content::PermissionType::NOTIFICATIONS));
2797 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
2798 content::PermissionType::MIDI_SYSEX));
2799 EXPECT_EQ(0, tester.GetIgnoreCount(
2800 kOrigin2, content::PermissionType::DURABLE_STORAGE));
2801 EXPECT_EQ(0, tester.GetDismissCount(
2802 kOrigin2, content::PermissionType::NOTIFICATIONS));
2803 }
2804 {
2805 // Test REMOVE_SITE_DATA.
2806 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2807 content::PermissionType::GEOLOCATION));
2808 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1,
2809 content::PermissionType::GEOLOCATION));
2810 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
2811 content::PermissionType::NOTIFICATIONS));
2812 tester.ShouldChangeDismissalToBlock(kOrigin1,
2813 content::PermissionType::MIDI_SYSEX);
2814 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2,
2815 content::PermissionType::DURABLE_STORAGE));
2816 tester.ShouldChangeDismissalToBlock(kOrigin2,
2817 content::PermissionType::NOTIFICATIONS);
2818
2819 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
2820 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
2821 filter_builder_2);
2822
2823 // kOrigin2 should be gone, but kOrigin1 remains.
2824 EXPECT_EQ(2, tester.GetIgnoreCount(kOrigin1,
2825 content::PermissionType::GEOLOCATION));
2826 EXPECT_EQ(1, tester.GetIgnoreCount(kOrigin1,
2827 content::PermissionType::NOTIFICATIONS));
2828 EXPECT_EQ(1, tester.GetDismissCount(kOrigin1,
2829 content::PermissionType::MIDI_SYSEX));
2830 EXPECT_EQ(0, tester.GetIgnoreCount(
2831 kOrigin2, content::PermissionType::DURABLE_STORAGE));
2832 EXPECT_EQ(0, tester.GetDismissCount(
2833 kOrigin2, content::PermissionType::NOTIFICATIONS));
2834
2835 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
2836 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
2837 false);
2838
2839 // Everything should be gone.
2840 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2841 content::PermissionType::GEOLOCATION));
2842 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
2843 content::PermissionType::NOTIFICATIONS));
2844 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
2845 content::PermissionType::MIDI_SYSEX));
2846 EXPECT_EQ(0, tester.GetIgnoreCount(
2847 kOrigin2, content::PermissionType::DURABLE_STORAGE));
2848 EXPECT_EQ(0, tester.GetDismissCount(
2849 kOrigin2, content::PermissionType::NOTIFICATIONS));
2850 }
2851 }
2852
2853 #if BUILDFLAG(ENABLE_PLUGINS)
2854 TEST_F(BrowsingDataRemoverTest, RemovePluginData) {
2855 RemovePluginDataTester tester(GetProfile());
2856
2857 tester.AddDomain(kOrigin1.host());
2858 tester.AddDomain(kOrigin2.host());
2859 tester.AddDomain(kOrigin3.host());
2860
2861 std::vector<std::string> expected = {
2862 kOrigin1.host(), kOrigin2.host(), kOrigin3.host() };
2863 EXPECT_EQ(expected, tester.GetDomains());
2864
2865 // Delete data with a filter for the registrable domain of |kOrigin3|.
2866 RegistrableDomainFilterBuilder filter_builder(
2867 RegistrableDomainFilterBuilder::WHITELIST);
2868 filter_builder.AddRegisterableDomain(kTestRegisterableDomain3);
2869 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
2870 BrowsingDataRemover::REMOVE_PLUGIN_DATA,
2871 filter_builder);
2872
2873 // Plugin data for |kOrigin3.host()| should have been removed.
2874 expected.pop_back();
2875 EXPECT_EQ(expected, tester.GetDomains());
2876
2877 // TODO(msramek): Mock PluginDataRemover and test the complete deletion
2878 // of plugin data as well.
2879 }
2880 #endif
2881
2882 class MultipleTasksObserver { 1527 class MultipleTasksObserver {
2883 public: 1528 public:
2884 // A simple implementation of BrowsingDataRemover::Observer. 1529 // A simple implementation of BrowsingDataRemover::Observer.
2885 // MultipleTasksObserver will use several instances of Target to test 1530 // MultipleTasksObserver will use several instances of Target to test
2886 // that completion callbacks are returned to the correct one. 1531 // that completion callbacks are returned to the correct one.
2887 class Target : public BrowsingDataRemover::Observer { 1532 class Target : public BrowsingDataRemover::Observer {
2888 public: 1533 public:
2889 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover) 1534 Target(MultipleTasksObserver* parent, BrowsingDataRemover* remover)
2890 : parent_(parent), 1535 : parent_(parent),
2891 observer_(this) { 1536 observer_(this) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2925 DCHECK(!last_called_target_) 1570 DCHECK(!last_called_target_)
2926 << "Call ClearLastCalledTarget() before every removal task."; 1571 << "Call ClearLastCalledTarget() before every removal task.";
2927 last_called_target_ = target; 1572 last_called_target_ = target;
2928 } 1573 }
2929 1574
2930 Target target_a_; 1575 Target target_a_;
2931 Target target_b_; 1576 Target target_b_;
2932 Target* last_called_target_; 1577 Target* last_called_target_;
2933 }; 1578 };
2934 1579
2935 TEST_F(BrowsingDataRemoverTest, MultipleTasks) { 1580 TEST_F(BrowsingDataRemoverImplTest, MultipleTasks) {
2936 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( 1581 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
2937 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile())); 1582 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext()));
2938 EXPECT_FALSE(remover->is_removing()); 1583 EXPECT_FALSE(remover->is_removing());
2939 1584
2940 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_1( 1585 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_1(
2941 new RegistrableDomainFilterBuilder( 1586 new RegistrableDomainFilterBuilder(
2942 RegistrableDomainFilterBuilder::WHITELIST)); 1587 RegistrableDomainFilterBuilder::WHITELIST));
2943 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_2( 1588 std::unique_ptr<RegistrableDomainFilterBuilder> filter_builder_2(
2944 new RegistrableDomainFilterBuilder( 1589 new RegistrableDomainFilterBuilder(
2945 RegistrableDomainFilterBuilder::BLACKLIST)); 1590 RegistrableDomainFilterBuilder::BLACKLIST));
2946 filter_builder_2->AddRegisterableDomain("example.com"); 1591 filter_builder_2->AddRegisterableDomain("example.com");
2947 1592
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3027 } 1672 }
3028 1673
3029 EXPECT_FALSE(remover->is_removing()); 1674 EXPECT_FALSE(remover->is_removing());
3030 } 1675 }
3031 1676
3032 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the 1677 // The previous test, BrowsingDataRemoverTest.MultipleTasks, tests that the
3033 // tasks are not mixed up and they are executed in a correct order. However, 1678 // tasks are not mixed up and they are executed in a correct order. However,
3034 // the completion inhibitor kept synchronizing the execution in order to verify 1679 // the completion inhibitor kept synchronizing the execution in order to verify
3035 // the parameters. This test demonstrates that even running the tasks without 1680 // the parameters. This test demonstrates that even running the tasks without
3036 // inhibition is executed correctly and doesn't crash. 1681 // inhibition is executed correctly and doesn't crash.
3037 TEST_F(BrowsingDataRemoverTest, MultipleTasksInQuickSuccession) { 1682 TEST_F(BrowsingDataRemoverImplTest, MultipleTasksInQuickSuccession) {
3038 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>( 1683 BrowsingDataRemoverImpl* remover = static_cast<BrowsingDataRemoverImpl*>(
3039 BrowsingDataRemoverFactory::GetForBrowserContext(GetProfile())); 1684 BrowsingDataRemoverFactory::GetForBrowserContext(GetBrowserContext()));
3040 EXPECT_FALSE(remover->is_removing()); 1685 EXPECT_FALSE(remover->is_removing());
3041 1686
3042 int test_removal_masks[] = { 1687 int test_removal_masks[] = {
3043 BrowsingDataRemover::REMOVE_COOKIES, 1688 BrowsingDataRemover::REMOVE_COOKIES,
3044 BrowsingDataRemover::REMOVE_PASSWORDS, 1689 BrowsingDataRemover::REMOVE_PASSWORDS,
3045 BrowsingDataRemover::REMOVE_COOKIES, 1690 BrowsingDataRemover::REMOVE_COOKIES,
3046 BrowsingDataRemover::REMOVE_COOKIES, 1691 BrowsingDataRemover::REMOVE_COOKIES,
3047 BrowsingDataRemover::REMOVE_COOKIES, 1692 BrowsingDataRemover::REMOVE_COOKIES,
3048 BrowsingDataRemover::REMOVE_HISTORY, 1693 BrowsingDataRemover::REMOVE_HISTORY,
3049 BrowsingDataRemover::REMOVE_HISTORY, 1694 BrowsingDataRemover::REMOVE_HISTORY,
(...skipping 15 matching lines...) Expand all
3065 EXPECT_TRUE(remover->is_removing()); 1710 EXPECT_TRUE(remover->is_removing());
3066 1711
3067 // Add one more deletion and wait for it. 1712 // Add one more deletion and wait for it.
3068 BlockUntilBrowsingDataRemoved( 1713 BlockUntilBrowsingDataRemoved(
3069 base::Time(), base::Time::Max(), 1714 base::Time(), base::Time::Max(),
3070 BrowsingDataRemover::REMOVE_COOKIES, 1715 BrowsingDataRemover::REMOVE_COOKIES,
3071 BrowsingDataHelper::UNPROTECTED_WEB); 1716 BrowsingDataHelper::UNPROTECTED_WEB);
3072 1717
3073 EXPECT_FALSE(remover->is_removing()); 1718 EXPECT_FALSE(remover->is_removing());
3074 } 1719 }
3075
3076 // Test that the remover clears bookmark meta data (normally added in a tab
3077 // helper).
3078 TEST_F(BrowsingDataRemoverTest, BookmarkLastVisitDatesGetCleared) {
3079 TestingProfile profile;
3080 profile.CreateBookmarkModel(true);
3081
3082 bookmarks::BookmarkModel* bookmark_model =
3083 BookmarkModelFactory::GetForBrowserContext(&profile);
3084 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
3085
3086 const base::Time delete_begin =
3087 base::Time::Now() - base::TimeDelta::FromDays(1);
3088
3089 // Create a couple of bookmarks.
3090 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
3091 base::string16(),
3092 GURL("http://foo.org/desktop"));
3093 bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
3094 base::string16(),
3095 GURL("http://foo.org/mobile"));
3096
3097 // Simulate their visits (this is using Time::Now() as timestamps).
3098 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame(
3099 bookmark_model, GURL("http://foo.org/desktop"),
3100 /*is_mobile_platform=*/false);
3101 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame(
3102 bookmark_model, GURL("http://foo.org/mobile"),
3103 /*is_mobile_platform=*/true);
3104
3105 // Add a bookmark with a visited timestamp before the deletion interval.
3106 bookmarks::BookmarkNode::MetaInfoMap meta_info = {
3107 {"last_visited",
3108 base::Int64ToString((delete_begin - base::TimeDelta::FromSeconds(1))
3109 .ToInternalValue())}};
3110 bookmark_model->AddURLWithCreationTimeAndMetaInfo(
3111 bookmark_model->mobile_node(), 0, base::ASCIIToUTF16("my title"),
3112 GURL("http://foo-2.org/"), delete_begin - base::TimeDelta::FromDays(1),
3113 &meta_info);
3114
3115 // There should be some recently visited bookmarks.
3116 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks(
3117 bookmark_model, 2, base::Time::UnixEpoch(),
3118 /*consider_visits_from_desktop=*/false),
3119 Not(IsEmpty()));
3120
3121 // Inject the bookmark model into the remover.
3122 BrowsingDataRemover* remover =
3123 BrowsingDataRemoverFactory::GetForBrowserContext(&profile);
3124
3125 BrowsingDataRemoverCompletionObserver completion_observer(remover);
3126 remover->RemoveAndReply(delete_begin, base::Time::Max(),
3127 BrowsingDataRemover::REMOVE_HISTORY,
3128 BrowsingDataHelper::ALL, &completion_observer);
3129 completion_observer.BlockUntilCompletion();
3130
3131 // There should be only 1 recently visited bookmarks.
3132 std::vector<const bookmarks::BookmarkNode*> remaining_nodes =
3133 ntp_snippets::GetRecentlyVisitedBookmarks(
3134 bookmark_model, 3, base::Time::UnixEpoch(),
3135 /*consider_visits_from_desktop=*/true);
3136 EXPECT_THAT(remaining_nodes, SizeIs(1));
3137 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/"));
3138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698