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

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

Issue 2651673002: Reland "Split BrowsingDataRemoverTest into two tests for Impl and Delegate." (Closed)
Patch Set: Fix. 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
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover_unittest.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
6
7 #include "base/guid.h"
8 #include "base/run_loop.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/autofill/personal_data_manager_factory.h"
12 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
13 #include "chrome/browser/browsing_data/browsing_data_helper.h"
14 #include "chrome/browser/browsing_data/browsing_data_remover.h"
15 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
16 #include "chrome/browser/browsing_data/browsing_data_remover_impl.h"
17 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
18 #include "chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h"
19 #include "chrome/browser/browsing_data/registrable_domain_filter_builder.h"
20 #include "chrome/browser/content_settings/host_content_settings_map_factory.h"
21 #include "chrome/browser/domain_reliability/service_factory.h"
22 #include "chrome/browser/download/chrome_download_manager_delegate.h"
23 #include "chrome/browser/favicon/favicon_service_factory.h"
24 #include "chrome/browser/history/history_service_factory.h"
25 #include "chrome/browser/password_manager/password_store_factory.h"
26 #include "chrome/browser/permissions/permission_decision_auto_blocker.h"
27 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
28 #include "chrome/browser/storage/durable_storage_permission_context.h"
29 #include "chrome/common/pref_names.h"
30 #include "chrome/test/base/testing_browser_process.h"
31 #include "chrome/test/base/testing_profile.h"
32 #include "components/autofill/core/browser/autofill_profile.h"
33 #include "components/autofill/core/browser/autofill_test_utils.h"
34 #include "components/autofill/core/browser/credit_card.h"
35 #include "components/autofill/core/browser/personal_data_manager.h"
36 #include "components/autofill/core/browser/personal_data_manager_observer.h"
37 #include "components/autofill/core/common/autofill_constants.h"
38 #include "components/bookmarks/browser/bookmark_model.h"
39 #include "components/bookmarks/test/bookmark_test_helpers.h"
40 #include "components/browsing_data/core/browsing_data_utils.h"
41 #include "components/content_settings/core/browser/host_content_settings_map.h"
42 #include "components/content_settings/core/common/content_settings.h"
43 #include "components/content_settings/core/common/content_settings_pattern.h"
44 #include "components/domain_reliability/clear_mode.h"
45 #include "components/domain_reliability/monitor.h"
46 #include "components/domain_reliability/service.h"
47 #include "components/favicon/core/favicon_service.h"
48 #include "components/history/core/browser/history_service.h"
49 #include "components/ntp_snippets/bookmarks/bookmark_last_visit_utils.h"
50 #include "components/omnibox/browser/omnibox_pref_names.h"
51 #include "components/os_crypt/os_crypt_mocker.h"
52 #include "components/password_manager/core/browser/mock_password_store.h"
53 #include "components/password_manager/core/browser/password_manager_test_utils.h "
54 #include "components/password_manager/core/browser/password_store_consumer.h"
55 #include "components/prefs/testing_pref_service.h"
56 #include "content/public/test/mock_download_manager.h"
57 #include "content/public/test/test_browser_thread_bundle.h"
58 #include "content/public/test/test_utils.h"
59 #include "net/cookies/cookie_store.h"
60 #include "net/http/http_transaction_factory.h"
61 #include "net/url_request/url_request_context.h"
62 #include "net/url_request/url_request_context_getter.h"
63 #include "third_party/skia/include/core/SkBitmap.h"
64 #include "ui/gfx/favicon_size.h"
65
66 #if defined(OS_ANDROID)
67 #include "chrome/browser/android/webapps/webapp_registry.h"
68 #endif
69
70 #if defined(OS_CHROMEOS)
71 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
72 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
73 #include "chrome/browser/chromeos/settings/cros_settings.h"
74 #include "chrome/browser/chromeos/settings/device_settings_service.h"
75 #include "chromeos/dbus/dbus_thread_manager.h"
76 #include "chromeos/dbus/mock_cryptohome_client.h"
77 #include "components/signin/core/account_id/account_id.h"
78 #endif
79
80 #if BUILDFLAG(ENABLE_PLUGINS)
81 #include "chrome/browser/browsing_data/mock_browsing_data_flash_lso_helper.h"
82 #endif
83
84 using domain_reliability::CLEAR_BEACONS;
85 using domain_reliability::CLEAR_CONTEXTS;
86 using domain_reliability::DomainReliabilityClearMode;
87 using domain_reliability::DomainReliabilityMonitor;
88 using domain_reliability::DomainReliabilityService;
89 using domain_reliability::DomainReliabilityServiceFactory;
90 using testing::_;
91 using testing::ByRef;
92 using testing::Eq;
93 using testing::Invoke;
94 using testing::IsEmpty;
95 using testing::Matcher;
96 using testing::MakeMatcher;
97 using testing::MatcherInterface;
98 using testing::MatchResultListener;
99 using testing::Not;
100 using testing::Return;
101 using testing::SizeIs;
102 using testing::WithArgs;
103
104 namespace {
105
106 const char kTestOrigin1[] = "http://host1.com:1/";
107 const char kTestRegisterableDomain1[] = "host1.com";
108 const char kTestOrigin2[] = "http://host2.com:1/";
109 const char kTestOrigin3[] = "http://host3.com:1/";
110 const char kTestRegisterableDomain3[] = "host3.com";
111 const char kTestOrigin4[] = "https://host3.com:1/";
112
113 // For HTTP auth.
114 const char kTestRealm[] = "TestRealm";
115
116 // For Autofill.
117 const char kWebOrigin[] = "https://www.example.com/";
118
119 const GURL kOrigin1(kTestOrigin1);
120 const GURL kOrigin2(kTestOrigin2);
121 const GURL kOrigin3(kTestOrigin3);
122 const GURL kOrigin4(kTestOrigin4);
123
124 // Testers --------------------------------------------------------------------
125
126 #if defined(OS_ANDROID)
127 class TestWebappRegistry : public WebappRegistry {
128 public:
129 TestWebappRegistry() : WebappRegistry() { }
130
131 void UnregisterWebappsForUrls(
132 const base::Callback<bool(const GURL&)>& url_filter) override {
133 // Mocks out a JNI call.
134 }
135
136 void ClearWebappHistoryForUrls(
137 const base::Callback<bool(const GURL&)>& url_filter) override {
138 // Mocks out a JNI call.
139 }
140 };
141 #endif
142
143 #if defined(OS_CHROMEOS)
144 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
145 base::ThreadTaskRunnerHandle::Get()->PostTask(
146 FROM_HERE,
147 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true));
148 }
149 #endif
150
151 class RemoveCookieTester {
152 public:
153 RemoveCookieTester() {}
154
155 // Returns true, if the given cookie exists in the cookie store.
156 bool ContainsCookie() {
157 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
158 new content::MessageLoopRunner;
159 quit_closure_ = message_loop_runner->QuitClosure();
160 get_cookie_success_ = false;
161 cookie_store_->GetCookiesWithOptionsAsync(
162 kOrigin1, net::CookieOptions(),
163 base::Bind(&RemoveCookieTester::GetCookieCallback,
164 base::Unretained(this)));
165 message_loop_runner->Run();
166 return get_cookie_success_;
167 }
168
169 void AddCookie() {
170 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
171 new content::MessageLoopRunner;
172 quit_closure_ = message_loop_runner->QuitClosure();
173 cookie_store_->SetCookieWithOptionsAsync(
174 kOrigin1, "A=1", net::CookieOptions(),
175 base::Bind(&RemoveCookieTester::SetCookieCallback,
176 base::Unretained(this)));
177 message_loop_runner->Run();
178 }
179
180 protected:
181 void SetCookieStore(net::CookieStore* cookie_store) {
182 cookie_store_ = cookie_store;
183 }
184
185 private:
186 void GetCookieCallback(const std::string& cookies) {
187 if (cookies == "A=1") {
188 get_cookie_success_ = true;
189 } else {
190 EXPECT_EQ("", cookies);
191 get_cookie_success_ = false;
192 }
193 quit_closure_.Run();
194 }
195
196 void SetCookieCallback(bool result) {
197 ASSERT_TRUE(result);
198 quit_closure_.Run();
199 }
200
201 bool get_cookie_success_ = false;
202 base::Closure quit_closure_;
203
204 // CookieStore must out live |this|.
205 net::CookieStore* cookie_store_ = nullptr;
206
207 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
208 };
209
210 void RunClosureAfterCookiesCleared(const base::Closure& task,
211 int cookies_deleted) {
212 task.Run();
213 }
214
215 class RemoveSafeBrowsingCookieTester : public RemoveCookieTester {
216 public:
217 RemoveSafeBrowsingCookieTester()
218 : browser_process_(TestingBrowserProcess::GetGlobal()) {
219 scoped_refptr<safe_browsing::SafeBrowsingService> sb_service =
220 safe_browsing::SafeBrowsingService::CreateSafeBrowsingService();
221 browser_process_->SetSafeBrowsingService(sb_service.get());
222 sb_service->Initialize();
223 base::RunLoop().RunUntilIdle();
224
225 // Make sure the safe browsing cookie store has no cookies.
226 // TODO(mmenke): Is this really needed?
227 base::RunLoop run_loop;
228 net::URLRequestContext* request_context =
229 sb_service->url_request_context()->GetURLRequestContext();
230 request_context->cookie_store()->DeleteAllAsync(
231 base::Bind(&RunClosureAfterCookiesCleared, run_loop.QuitClosure()));
232 run_loop.Run();
233
234 SetCookieStore(request_context->cookie_store());
235 }
236
237 virtual ~RemoveSafeBrowsingCookieTester() {
238 browser_process_->safe_browsing_service()->ShutDown();
239 base::RunLoop().RunUntilIdle();
240 browser_process_->SetSafeBrowsingService(nullptr);
241 }
242
243 private:
244 TestingBrowserProcess* browser_process_;
245
246 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
247 };
248
249 class RemoveHistoryTester {
250 public:
251 RemoveHistoryTester() {}
252
253 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
254 if (!profile->CreateHistoryService(true, false))
255 return false;
256 history_service_ = HistoryServiceFactory::GetForProfile(
257 profile, ServiceAccessType::EXPLICIT_ACCESS);
258 return true;
259 }
260
261 // Returns true, if the given URL exists in the history service.
262 bool HistoryContainsURL(const GURL& url) {
263 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
264 new content::MessageLoopRunner;
265 quit_closure_ = message_loop_runner->QuitClosure();
266 history_service_->QueryURL(
267 url,
268 true,
269 base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
270 base::Unretained(this)),
271 &tracker_);
272 message_loop_runner->Run();
273 return query_url_success_;
274 }
275
276 void AddHistory(const GURL& url, base::Time time) {
277 history_service_->AddPage(url, time, nullptr, 0, GURL(),
278 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
279 history::SOURCE_BROWSED, false);
280 }
281
282 private:
283 // Callback for HistoryService::QueryURL.
284 void SaveResultAndQuit(bool success,
285 const history::URLRow&,
286 const history::VisitVector&) {
287 query_url_success_ = success;
288 quit_closure_.Run();
289 }
290
291 // For History requests.
292 base::CancelableTaskTracker tracker_;
293 bool query_url_success_ = false;
294 base::Closure quit_closure_;
295
296 // TestingProfile owns the history service; we shouldn't delete it.
297 history::HistoryService* history_service_ = nullptr;
298
299 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
300 };
301
302 class RemoveFaviconTester {
303 public:
304 RemoveFaviconTester() {}
305
306 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
307 // Create the history service if it has not been created yet.
308 history_service_ = HistoryServiceFactory::GetForProfile(
309 profile, ServiceAccessType::EXPLICIT_ACCESS);
310 if (!history_service_) {
311 if (!profile->CreateHistoryService(true, false))
312 return false;
313 history_service_ = HistoryServiceFactory::GetForProfile(
314 profile, ServiceAccessType::EXPLICIT_ACCESS);
315 }
316
317 profile->CreateFaviconService();
318 favicon_service_ = FaviconServiceFactory::GetForProfile(
319 profile, ServiceAccessType::EXPLICIT_ACCESS);
320 return true;
321 }
322
323 // Returns true if there is a favicon stored for |page_url| in the favicon
324 // database.
325 bool HasFaviconForPageURL(const GURL& page_url) {
326 RequestFaviconSyncForPageURL(page_url);
327 return got_favicon_;
328 }
329
330 // Returns true if:
331 // - There is a favicon stored for |page_url| in the favicon database.
332 // - The stored favicon is expired.
333 bool HasExpiredFaviconForPageURL(const GURL& page_url) {
334 RequestFaviconSyncForPageURL(page_url);
335 return got_expired_favicon_;
336 }
337
338 // Adds a visit to history and stores an arbitrary favicon bitmap for
339 // |page_url|.
340 void VisitAndAddFavicon(const GURL& page_url) {
341 history_service_->AddPage(page_url, base::Time::Now(), nullptr, 0, GURL(),
342 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
343 history::SOURCE_BROWSED, false);
344
345 SkBitmap bitmap;
346 bitmap.allocN32Pixels(gfx::kFaviconSize, gfx::kFaviconSize);
347 bitmap.eraseColor(SK_ColorBLUE);
348 favicon_service_->SetFavicons(page_url, page_url, favicon_base::FAVICON,
349 gfx::Image::CreateFrom1xBitmap(bitmap));
350 }
351
352 private:
353 // Synchronously requests the favicon for |page_url| from the favicon
354 // database.
355 void RequestFaviconSyncForPageURL(const GURL& page_url) {
356 base::RunLoop run_loop;
357 quit_closure_ = run_loop.QuitClosure();
358 favicon_service_->GetRawFaviconForPageURL(
359 page_url,
360 favicon_base::FAVICON,
361 gfx::kFaviconSize,
362 base::Bind(&RemoveFaviconTester::SaveResultAndQuit,
363 base::Unretained(this)),
364 &tracker_);
365 run_loop.Run();
366 }
367
368 // Callback for HistoryService::QueryURL.
369 void SaveResultAndQuit(const favicon_base::FaviconRawBitmapResult& result) {
370 got_favicon_ = result.is_valid();
371 got_expired_favicon_ = result.is_valid() && result.expired;
372 quit_closure_.Run();
373 }
374
375 // For favicon requests.
376 base::CancelableTaskTracker tracker_;
377 bool got_favicon_ = false;
378 bool got_expired_favicon_ = false;
379 base::Closure quit_closure_;
380
381 // Owned by TestingProfile.
382 history::HistoryService* history_service_ = nullptr;
383 favicon::FaviconService* favicon_service_ = nullptr;
384
385 DISALLOW_COPY_AND_ASSIGN(RemoveFaviconTester);
386 };
387
388 class MockDomainReliabilityService : public DomainReliabilityService {
389 public:
390 MockDomainReliabilityService() {}
391
392 ~MockDomainReliabilityService() override {}
393
394 std::unique_ptr<DomainReliabilityMonitor> CreateMonitor(
395 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
396 override {
397 NOTREACHED();
398 return std::unique_ptr<DomainReliabilityMonitor>();
399 }
400
401 void ClearBrowsingData(
402 DomainReliabilityClearMode clear_mode,
403 const base::Callback<bool(const GURL&)>& origin_filter,
404 const base::Closure& callback) override {
405 clear_count_++;
406 last_clear_mode_ = clear_mode;
407 last_filter_ = origin_filter;
408 callback.Run();
409 }
410
411 void GetWebUIData(const base::Callback<void(std::unique_ptr<base::Value>)>&
412 callback) const override {
413 NOTREACHED();
414 }
415
416 void SetDiscardUploadsForTesting(bool discard_uploads) override {
417 NOTREACHED();
418 }
419
420 void AddContextForTesting(
421 std::unique_ptr<const domain_reliability::DomainReliabilityConfig> config)
422 override {
423 NOTREACHED();
424 }
425
426 void ForceUploadsForTesting() override { NOTREACHED(); }
427
428 int clear_count() const { return clear_count_; }
429
430 DomainReliabilityClearMode last_clear_mode() const {
431 return last_clear_mode_;
432 }
433
434 const base::Callback<bool(const GURL&)>& last_filter() const {
435 return last_filter_;
436 }
437
438 private:
439 unsigned clear_count_ = 0;
440 DomainReliabilityClearMode last_clear_mode_;
441 base::Callback<bool(const GURL&)> last_filter_;
442 };
443
444 struct TestingDomainReliabilityServiceFactoryUserData
445 : public base::SupportsUserData::Data {
446 TestingDomainReliabilityServiceFactoryUserData(
447 content::BrowserContext* context,
448 MockDomainReliabilityService* service)
449 : context(context),
450 service(service),
451 attached(false) {}
452 ~TestingDomainReliabilityServiceFactoryUserData() override {}
453
454 content::BrowserContext* const context;
455 MockDomainReliabilityService* const service;
456 bool attached;
457
458 static const void* kKey;
459 };
460
461 // static
462 const void* TestingDomainReliabilityServiceFactoryUserData::kKey =
463 &TestingDomainReliabilityServiceFactoryUserData::kKey;
464
465 std::unique_ptr<KeyedService> TestingDomainReliabilityServiceFactoryFunction(
466 content::BrowserContext* context) {
467 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
468
469 TestingDomainReliabilityServiceFactoryUserData* data =
470 static_cast<TestingDomainReliabilityServiceFactoryUserData*>(
471 context->GetUserData(kKey));
472 EXPECT_TRUE(data);
473 EXPECT_EQ(data->context, context);
474 EXPECT_FALSE(data->attached);
475
476 data->attached = true;
477 return base::WrapUnique(data->service);
478 }
479
480 class ClearDomainReliabilityTester {
481 public:
482 explicit ClearDomainReliabilityTester(TestingProfile* profile) :
483 profile_(profile),
484 mock_service_(new MockDomainReliabilityService()) {
485 AttachService();
486 }
487
488 unsigned clear_count() const { return mock_service_->clear_count(); }
489
490 DomainReliabilityClearMode last_clear_mode() const {
491 return mock_service_->last_clear_mode();
492 }
493
494 const base::Callback<bool(const GURL&)>& last_filter() const {
495 return mock_service_->last_filter();
496 }
497
498 private:
499 void AttachService() {
500 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
501
502 // Attach kludgey UserData struct to profile.
503 TestingDomainReliabilityServiceFactoryUserData* data =
504 new TestingDomainReliabilityServiceFactoryUserData(profile_,
505 mock_service_);
506 EXPECT_FALSE(profile_->GetUserData(kKey));
507 profile_->SetUserData(kKey, data);
508
509 // Set and use factory that will attach service stuffed in kludgey struct.
510 DomainReliabilityServiceFactory::GetInstance()->SetTestingFactoryAndUse(
511 profile_,
512 &TestingDomainReliabilityServiceFactoryFunction);
513
514 // Verify and detach kludgey struct.
515 EXPECT_EQ(data, profile_->GetUserData(kKey));
516 EXPECT_TRUE(data->attached);
517 profile_->RemoveUserData(kKey);
518 }
519
520 TestingProfile* profile_;
521 MockDomainReliabilityService* mock_service_;
522 };
523
524 class RemovePasswordsTester {
525 public:
526 explicit RemovePasswordsTester(TestingProfile* testing_profile) {
527 PasswordStoreFactory::GetInstance()->SetTestingFactoryAndUse(
528 testing_profile,
529 password_manager::BuildPasswordStore<
530 content::BrowserContext,
531 testing::NiceMock<password_manager::MockPasswordStore>>);
532
533 store_ = static_cast<password_manager::MockPasswordStore*>(
534 PasswordStoreFactory::GetInstance()
535 ->GetForProfile(testing_profile, ServiceAccessType::EXPLICIT_ACCESS)
536 .get());
537
538 OSCryptMocker::SetUpWithSingleton();
539 }
540
541 ~RemovePasswordsTester() { OSCryptMocker::TearDown(); }
542
543 password_manager::MockPasswordStore* store() { return store_; }
544
545 private:
546 password_manager::MockPasswordStore* store_;
547
548 DISALLOW_COPY_AND_ASSIGN(RemovePasswordsTester);
549 };
550
551 class RemovePermissionPromptCountsTest {
552 public:
553 explicit RemovePermissionPromptCountsTest(TestingProfile* profile)
554 : profile_(profile) {}
555
556 int GetDismissCount(const GURL& url, content::PermissionType permission) {
557 return PermissionDecisionAutoBlocker::GetDismissCount(
558 url, permission, profile_);
559 }
560
561 int GetIgnoreCount(const GURL& url, content::PermissionType permission) {
562 return PermissionDecisionAutoBlocker::GetIgnoreCount(
563 url, permission, profile_);
564 }
565
566 int RecordIgnore(const GURL& url, content::PermissionType permission) {
567 return PermissionDecisionAutoBlocker::RecordIgnore(url, permission,
568 profile_);
569 }
570
571 bool ShouldChangeDismissalToBlock(const GURL& url,
572 content::PermissionType permission) {
573 return PermissionDecisionAutoBlocker::ShouldChangeDismissalToBlock(
574 url, permission, profile_);
575 }
576
577 private:
578 TestingProfile* profile_;
579
580 DISALLOW_COPY_AND_ASSIGN(RemovePermissionPromptCountsTest);
581 };
582
583 #if BUILDFLAG(ENABLE_PLUGINS)
584 // A small modification to MockBrowsingDataFlashLSOHelper so that it responds
585 // immediately and does not wait for the Notify() call. Otherwise it would
586 // deadlock BrowsingDataRemoverImpl::RemoveImpl.
587 class TestBrowsingDataFlashLSOHelper : public MockBrowsingDataFlashLSOHelper {
588 public:
589 explicit TestBrowsingDataFlashLSOHelper(TestingProfile* profile)
590 : MockBrowsingDataFlashLSOHelper(profile) {}
591
592 void StartFetching(const GetSitesWithFlashDataCallback& callback) override {
593 MockBrowsingDataFlashLSOHelper::StartFetching(callback);
594 Notify();
595 }
596
597 private:
598 ~TestBrowsingDataFlashLSOHelper() override {}
599
600 DISALLOW_COPY_AND_ASSIGN(TestBrowsingDataFlashLSOHelper);
601 };
602
603 class RemovePluginDataTester {
604 public:
605 explicit RemovePluginDataTester(TestingProfile* profile)
606 : helper_(new TestBrowsingDataFlashLSOHelper(profile)) {
607 static_cast<ChromeBrowsingDataRemoverDelegate*>(
608 BrowsingDataRemoverFactory::GetForBrowserContext(profile)
609 ->GetEmbedderDelegate())->OverrideFlashLSOHelperForTesting(helper_);
610 }
611
612 void AddDomain(const std::string& domain) {
613 helper_->AddFlashLSODomain(domain);
614 }
615
616 const std::vector<std::string>& GetDomains() {
617 // TestBrowsingDataFlashLSOHelper is synchronous, so we can immediately
618 // return the fetched domains.
619 helper_->StartFetching(
620 base::Bind(&RemovePluginDataTester::OnSitesWithFlashDataFetched,
621 base::Unretained(this)));
622 return domains_;
623 }
624
625 private:
626 void OnSitesWithFlashDataFetched(const std::vector<std::string>& sites) {
627 domains_ = sites;
628 }
629
630 std::vector<std::string> domains_;
631 scoped_refptr<TestBrowsingDataFlashLSOHelper> helper_;
632
633 DISALLOW_COPY_AND_ASSIGN(RemovePluginDataTester);
634 };
635 #endif
636
637 // Custom matcher to test the equivalence of two URL filters. Since those are
638 // blackbox predicates, we can only approximate the equivalence by testing
639 // whether the filter give the same answer for several URLs. This is currently
640 // good enough for our testing purposes, to distinguish whitelists
641 // and blacklists, empty and non-empty filters and such.
642 // TODO(msramek): BrowsingDataRemover and some of its backends support URL
643 // filters, but its constructor currently only takes a single URL and constructs
644 // its own url filter. If an url filter was directly passed to
645 // BrowsingDataRemover (what should eventually be the case), we can use the same
646 // instance in the test as well, and thus simply test base::Callback::Equals()
647 // in this matcher.
648 class ProbablySameFilterMatcher
649 : public MatcherInterface<const base::Callback<bool(const GURL&)>&> {
650 public:
651 explicit ProbablySameFilterMatcher(
652 const base::Callback<bool(const GURL&)>& filter)
653 : to_match_(filter) {
654 }
655
656 virtual bool MatchAndExplain(const base::Callback<bool(const GURL&)>& filter,
657 MatchResultListener* listener) const {
658 if (filter.is_null() && to_match_.is_null())
659 return true;
660 if (filter.is_null() != to_match_.is_null())
661 return false;
662
663 const GURL urls_to_test_[] =
664 {kOrigin1, kOrigin2, kOrigin3, GURL("invalid spec")};
665 for (GURL url : urls_to_test_) {
666 if (filter.Run(url) != to_match_.Run(url)) {
667 if (listener)
668 *listener << "The filters differ on the URL " << url;
669 return false;
670 }
671 }
672 return true;
673 }
674
675 virtual void DescribeTo(::std::ostream* os) const {
676 *os << "is probably the same url filter as " << &to_match_;
677 }
678
679 virtual void DescribeNegationTo(::std::ostream* os) const {
680 *os << "is definitely NOT the same url filter as " << &to_match_;
681 }
682
683 private:
684 const base::Callback<bool(const GURL&)>& to_match_;
685 };
686
687 inline Matcher<const base::Callback<bool(const GURL&)>&> ProbablySameFilter(
688 const base::Callback<bool(const GURL&)>& filter) {
689 return MakeMatcher(new ProbablySameFilterMatcher(filter));
690 }
691
692 bool ProbablySameFilters(
693 const base::Callback<bool(const GURL&)>& filter1,
694 const base::Callback<bool(const GURL&)>& filter2) {
695 return ProbablySameFilter(filter1).MatchAndExplain(filter2, nullptr);
696 }
697
698 base::Time AnHourAgo() {
699 return base::Time::Now() - base::TimeDelta::FromHours(1);
700 }
701
702 class RemoveDownloadsTester {
703 public:
704 explicit RemoveDownloadsTester(TestingProfile* testing_profile)
705 : download_manager_(new content::MockDownloadManager()),
706 chrome_download_manager_delegate_(testing_profile) {
707 content::BrowserContext::SetDownloadManagerForTesting(testing_profile,
708 download_manager_);
709 EXPECT_EQ(download_manager_,
710 content::BrowserContext::GetDownloadManager(testing_profile));
711
712 EXPECT_CALL(*download_manager_, GetDelegate())
713 .WillOnce(Return(&chrome_download_manager_delegate_));
714 EXPECT_CALL(*download_manager_, Shutdown());
715 }
716
717 ~RemoveDownloadsTester() { chrome_download_manager_delegate_.Shutdown(); }
718
719 content::MockDownloadManager* download_manager() { return download_manager_; }
720
721 private:
722 content::MockDownloadManager* download_manager_;
723 ChromeDownloadManagerDelegate chrome_download_manager_delegate_;
724
725 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester);
726 };
727
728 } // namespace
729
730 // RemoveAutofillTester is not a part of the anonymous namespace above, as
731 // PersonalDataManager declares it a friend in an empty namespace.
732 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
733 public:
734 explicit RemoveAutofillTester(TestingProfile* profile)
735 : personal_data_manager_(
736 autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
737 autofill::test::DisableSystemServices(profile->GetPrefs());
738 personal_data_manager_->AddObserver(this);
739 }
740
741 ~RemoveAutofillTester() override {
742 personal_data_manager_->RemoveObserver(this);
743 autofill::test::ReenableSystemServices();
744 }
745
746 // Returns true if there are autofill profiles.
747 bool HasProfile() {
748 return !personal_data_manager_->GetProfiles().empty() &&
749 !personal_data_manager_->GetCreditCards().empty();
750 }
751
752 bool HasOrigin(const std::string& origin) {
753 const std::vector<autofill::AutofillProfile*>& profiles =
754 personal_data_manager_->GetProfiles();
755 for (const autofill::AutofillProfile* profile : profiles) {
756 if (profile->origin() == origin)
757 return true;
758 }
759
760 const std::vector<autofill::CreditCard*>& credit_cards =
761 personal_data_manager_->GetCreditCards();
762 for (const autofill::CreditCard* credit_card : credit_cards) {
763 if (credit_card->origin() == origin)
764 return true;
765 }
766
767 return false;
768 }
769
770 // Add two profiles and two credit cards to the database. In each pair, one
771 // entry has a web origin and the other has a Chrome origin.
772 void AddProfilesAndCards() {
773 std::vector<autofill::AutofillProfile> profiles;
774 autofill::AutofillProfile profile;
775 profile.set_guid(base::GenerateGUID());
776 profile.set_origin(kWebOrigin);
777 profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
778 profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
779 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
780 profile.SetRawInfo(autofill::EMAIL_ADDRESS,
781 base::ASCIIToUTF16("sue@example.com"));
782 profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
783 profiles.push_back(profile);
784
785 profile.set_guid(base::GenerateGUID());
786 profile.set_origin(autofill::kSettingsOrigin);
787 profiles.push_back(profile);
788
789 personal_data_manager_->SetProfiles(&profiles);
790 base::RunLoop().Run();
791
792 std::vector<autofill::CreditCard> cards;
793 autofill::CreditCard card;
794 card.set_guid(base::GenerateGUID());
795 card.set_origin(kWebOrigin);
796 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
797 base::ASCIIToUTF16("1234-5678-9012-3456"));
798 cards.push_back(card);
799
800 card.set_guid(base::GenerateGUID());
801 card.set_origin(autofill::kSettingsOrigin);
802 cards.push_back(card);
803
804 personal_data_manager_->SetCreditCards(&cards);
805 base::RunLoop().Run();
806 }
807
808 private:
809 void OnPersonalDataChanged() override {
810 base::MessageLoop::current()->QuitWhenIdle();
811 }
812
813 autofill::PersonalDataManager* personal_data_manager_;
814 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
815 };
816
817 // Test Class -----------------------------------------------------------------
818
819 class ChromeBrowsingDataRemoverDelegateTest : public testing::Test {
820 public:
821 ChromeBrowsingDataRemoverDelegateTest()
822 : profile_(new TestingProfile()),
823 clear_domain_reliability_tester_(profile_.get()) {
824 remover_ = BrowsingDataRemoverFactory::GetForBrowserContext(profile_.get());
825
826 #if defined(OS_ANDROID)
827 static_cast<ChromeBrowsingDataRemoverDelegate*>(
828 remover_->GetEmbedderDelegate())->OverrideWebappRegistryForTesting(
829 base::WrapUnique<WebappRegistry>(new TestWebappRegistry()));
830 #endif
831 }
832
833 void TearDown() override {
834 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
835 // posts a message to the WEBKIT thread to delete some of its member
836 // variables. We need to ensure that the profile is destroyed, and that
837 // the message loop is cleared out, before destroying the threads and loop.
838 // Otherwise we leak memory.
839 profile_.reset();
840 base::RunLoop().RunUntilIdle();
841
842 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
843 }
844
845 ~ChromeBrowsingDataRemoverDelegateTest() override {}
846
847 void BlockUntilBrowsingDataRemoved(const base::Time& delete_begin,
848 const base::Time& delete_end,
849 int remove_mask,
850 bool include_protected_origins) {
851 int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB;
852 if (include_protected_origins)
853 origin_type_mask |= BrowsingDataHelper::PROTECTED_WEB;
854
855 BrowsingDataRemoverCompletionObserver completion_observer(remover_);
856 remover_->RemoveAndReply(
857 delete_begin, delete_end, remove_mask, origin_type_mask,
858 &completion_observer);
859 completion_observer.BlockUntilCompletion();
860 }
861
862 void BlockUntilOriginDataRemoved(
863 const base::Time& delete_begin,
864 const base::Time& delete_end,
865 int remove_mask,
866 const BrowsingDataFilterBuilder& filter_builder) {
867 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
868
869 // TODO(crbug.com/668114): ChromeBrowsingDataRemoverTest should not know
870 // about BrowsingDataRemoverImpl. We will be able to remove this cast once
871 // BrowsingDataFilterBuilder is copyable and comparable.
872 static_cast<BrowsingDataRemoverImpl*>(remover_)
873 ->RemoveImpl(delete_begin, delete_end, remove_mask, filter_builder,
874 BrowsingDataHelper::UNPROTECTED_WEB);
875 completion_inhibitor.BlockUntilNearCompletion();
876 completion_inhibitor.ContinueToCompletion();
877 }
878
879 const base::Time& GetBeginTime() {
880 return remover_->GetLastUsedBeginTime();
881 }
882
883 int GetRemovalMask() {
884 return remover_->GetLastUsedRemovalMask();
885 }
886
887 int GetOriginTypeMask() {
888 return remover_->GetLastUsedOriginTypeMask();
889 }
890
891 TestingProfile* GetProfile() {
892 return profile_.get();
893 }
894
895 const ClearDomainReliabilityTester& clear_domain_reliability_tester() {
896 return clear_domain_reliability_tester_;
897 }
898
899 private:
900 // Cached pointer to BrowsingDataRemoverImpl for access to testing methods.
901 BrowsingDataRemover* remover_;
902
903 content::TestBrowserThreadBundle thread_bundle_;
904 std::unique_ptr<TestingProfile> profile_;
905
906 // Needed to mock out DomainReliabilityService, even for unrelated tests.
907 ClearDomainReliabilityTester clear_domain_reliability_tester_;
908
909 DISALLOW_COPY_AND_ASSIGN(ChromeBrowsingDataRemoverDelegateTest);
910 };
911
912 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveSafeBrowsingCookieForever) {
913 RemoveSafeBrowsingCookieTester tester;
914
915 tester.AddCookie();
916 ASSERT_TRUE(tester.ContainsCookie());
917
918 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
919 BrowsingDataRemover::REMOVE_COOKIES, false);
920
921 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
922 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
923 EXPECT_FALSE(tester.ContainsCookie());
924 }
925
926 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
927 RemoveSafeBrowsingCookieLastHour) {
928 RemoveSafeBrowsingCookieTester tester;
929
930 tester.AddCookie();
931 ASSERT_TRUE(tester.ContainsCookie());
932
933 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
934 BrowsingDataRemover::REMOVE_COOKIES, false);
935
936 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
937 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
938 // Removing with time period other than all time should not clear safe
939 // browsing cookies.
940 EXPECT_TRUE(tester.ContainsCookie());
941 }
942
943 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
944 RemoveSafeBrowsingCookieForeverWithPredicate) {
945 RemoveSafeBrowsingCookieTester tester;
946
947 tester.AddCookie();
948 ASSERT_TRUE(tester.ContainsCookie());
949 RegistrableDomainFilterBuilder filter(
950 RegistrableDomainFilterBuilder::BLACKLIST);
951 filter.AddRegisterableDomain(kTestRegisterableDomain1);
952 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
953 BrowsingDataRemover::REMOVE_COOKIES, filter);
954
955 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
956 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
957 EXPECT_TRUE(tester.ContainsCookie());
958
959 RegistrableDomainFilterBuilder filter2(
960 RegistrableDomainFilterBuilder::WHITELIST);
961 filter2.AddRegisterableDomain(kTestRegisterableDomain1);
962 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
963 BrowsingDataRemover::REMOVE_COOKIES, filter2);
964 EXPECT_FALSE(tester.ContainsCookie());
965 }
966
967 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryForever) {
968 RemoveHistoryTester tester;
969 ASSERT_TRUE(tester.Init(GetProfile()));
970
971 tester.AddHistory(kOrigin1, base::Time::Now());
972 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
973
974 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
975 BrowsingDataRemover::REMOVE_HISTORY, false);
976
977 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
978 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
979 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
980 }
981
982 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryForLastHour) {
983 RemoveHistoryTester tester;
984 ASSERT_TRUE(tester.Init(GetProfile()));
985
986 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
987
988 tester.AddHistory(kOrigin1, base::Time::Now());
989 tester.AddHistory(kOrigin2, two_hours_ago);
990 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
991 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
992
993 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
994 BrowsingDataRemover::REMOVE_HISTORY, false);
995
996 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
997 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
998 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
999 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1000 }
1001
1002 // This should crash (DCHECK) in Debug, but death tests don't work properly
1003 // here.
Bernhard Bauer 2017/01/23 16:10:47 Yeah, um... If this is logic we want to test, it m
msramek 2017/01/23 16:43:31 Acknowledged. Added a TODO.
1004 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1005 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveHistoryProhibited) {
1006 RemoveHistoryTester tester;
1007 ASSERT_TRUE(tester.Init(GetProfile()));
1008 PrefService* prefs = GetProfile()->GetPrefs();
1009 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1010
1011 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1012
1013 tester.AddHistory(kOrigin1, base::Time::Now());
1014 tester.AddHistory(kOrigin2, two_hours_ago);
1015 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1016 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1017
1018 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1019 BrowsingDataRemover::REMOVE_HISTORY, false);
1020 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1021 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1022
1023 // Nothing should have been deleted.
1024 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1025 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1026 }
1027
1028 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1029 RemoveMultipleTypesHistoryProhibited) {
1030 PrefService* prefs = GetProfile()->GetPrefs();
1031 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1032
1033 // Add some history.
1034 RemoveHistoryTester history_tester;
1035 ASSERT_TRUE(history_tester.Init(GetProfile()));
1036 history_tester.AddHistory(kOrigin1, base::Time::Now());
1037 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1038
1039 // Expect that passwords will be deleted, as they do not depend
1040 // on |prefs::kAllowDeletingBrowserHistory|.
1041 RemovePasswordsTester tester(GetProfile());
1042 EXPECT_CALL(*tester.store(), RemoveLoginsByURLAndTimeImpl(_, _, _));
1043
1044 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1045 BrowsingDataRemover::REMOVE_PASSWORDS;
1046
1047 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1048 removal_mask, false);
1049 EXPECT_EQ(removal_mask, GetRemovalMask());
1050 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1051
1052 // Verify that history was not deleted.
1053 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1054 }
1055 #endif
1056
1057 // Test that clearing history deletes favicons not associated with bookmarks.
1058 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveFaviconsForever) {
1059 GURL page_url("http://a");
1060
1061 RemoveFaviconTester favicon_tester;
1062 ASSERT_TRUE(favicon_tester.Init(GetProfile()));
1063 favicon_tester.VisitAndAddFavicon(page_url);
1064 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(page_url));
1065
1066 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1067 BrowsingDataRemover::REMOVE_HISTORY, false);
1068 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1069 EXPECT_FALSE(favicon_tester.HasFaviconForPageURL(page_url));
1070 }
1071
1072 // Test that a bookmark's favicon is expired and not deleted when clearing
1073 // history. Expiring the favicon causes the bookmark's favicon to be updated
1074 // when the user next visits the bookmarked page. Expiring the bookmark's
1075 // favicon is useful when the bookmark's favicon becomes incorrect (See
1076 // crbug.com/474421 for a sample bug which causes this).
1077 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ExpireBookmarkFavicons) {
1078 GURL bookmarked_page("http://a");
1079
1080 TestingProfile* profile = GetProfile();
1081 profile->CreateBookmarkModel(true);
1082 bookmarks::BookmarkModel* bookmark_model =
1083 BookmarkModelFactory::GetForBrowserContext(profile);
1084 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
1085 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
1086 base::ASCIIToUTF16("a"), bookmarked_page);
1087
1088 RemoveFaviconTester favicon_tester;
1089 ASSERT_TRUE(favicon_tester.Init(GetProfile()));
1090 favicon_tester.VisitAndAddFavicon(bookmarked_page);
1091 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(bookmarked_page));
1092
1093 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1094 BrowsingDataRemover::REMOVE_HISTORY, false);
1095 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1096 EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page));
1097 }
1098
1099 TEST_F(ChromeBrowsingDataRemoverDelegateTest, TimeBasedHistoryRemoval) {
1100 RemoveHistoryTester tester;
1101 ASSERT_TRUE(tester.Init(GetProfile()));
1102
1103 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1104
1105 tester.AddHistory(kOrigin1, base::Time::Now());
1106 tester.AddHistory(kOrigin2, two_hours_ago);
1107 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1108 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1109
1110 RegistrableDomainFilterBuilder builder(
1111 RegistrableDomainFilterBuilder::BLACKLIST);
1112 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
1113 BrowsingDataRemover::REMOVE_HISTORY, builder);
1114
1115 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1116 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1117 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
1118 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1119 }
1120
1121 // Verify that clearing autofill form data works.
1122 TEST_F(ChromeBrowsingDataRemoverDelegateTest, AutofillRemovalLastHour) {
1123 GetProfile()->CreateWebDataService();
1124 RemoveAutofillTester tester(GetProfile());
1125
1126 ASSERT_FALSE(tester.HasProfile());
1127 tester.AddProfilesAndCards();
1128 ASSERT_TRUE(tester.HasProfile());
1129
1130 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1131 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1132
1133 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1134 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1135 ASSERT_FALSE(tester.HasProfile());
1136 }
1137
1138 TEST_F(ChromeBrowsingDataRemoverDelegateTest, AutofillRemovalEverything) {
1139 GetProfile()->CreateWebDataService();
1140 RemoveAutofillTester tester(GetProfile());
1141
1142 ASSERT_FALSE(tester.HasProfile());
1143 tester.AddProfilesAndCards();
1144 ASSERT_TRUE(tester.HasProfile());
1145
1146 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1147 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1148
1149 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1150 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1151 ASSERT_FALSE(tester.HasProfile());
1152 }
1153
1154 // Verify that clearing autofill form data works.
1155 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1156 AutofillOriginsRemovedWithHistory) {
1157 GetProfile()->CreateWebDataService();
1158 RemoveAutofillTester tester(GetProfile());
1159
1160 tester.AddProfilesAndCards();
1161 EXPECT_FALSE(tester.HasOrigin(std::string()));
1162 EXPECT_TRUE(tester.HasOrigin(kWebOrigin));
1163 EXPECT_TRUE(tester.HasOrigin(autofill::kSettingsOrigin));
1164
1165 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1166 BrowsingDataRemover::REMOVE_HISTORY, false);
1167
1168 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1169 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1170 EXPECT_TRUE(tester.HasOrigin(std::string()));
1171 EXPECT_FALSE(tester.HasOrigin(kWebOrigin));
1172 EXPECT_TRUE(tester.HasOrigin(autofill::kSettingsOrigin));
1173 }
1174
1175 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ZeroSuggestCacheClear) {
1176 PrefService* prefs = GetProfile()->GetPrefs();
1177 prefs->SetString(omnibox::kZeroSuggestCachedResults,
1178 "[\"\", [\"foo\", \"bar\"]]");
1179 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1180 BrowsingDataRemover::REMOVE_COOKIES, false);
1181
1182 // Expect the prefs to be cleared when cookies are removed.
1183 EXPECT_TRUE(prefs->GetString(omnibox::kZeroSuggestCachedResults).empty());
1184 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1185 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1186 }
1187
1188 #if defined(OS_CHROMEOS)
1189 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1190 ContentProtectionPlatformKeysRemoval) {
1191 chromeos::ScopedTestDeviceSettingsService test_device_settings_service;
1192 chromeos::ScopedTestCrosSettings test_cros_settings;
1193 chromeos::MockUserManager* mock_user_manager =
1194 new testing::NiceMock<chromeos::MockUserManager>();
1195 mock_user_manager->SetActiveUser(
1196 AccountId::FromUserEmail("test@example.com"));
1197 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager);
1198
1199 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter =
1200 chromeos::DBusThreadManager::GetSetterForTesting();
1201 chromeos::MockCryptohomeClient* cryptohome_client =
1202 new chromeos::MockCryptohomeClient;
1203 dbus_setter->SetCryptohomeClient(
1204 std::unique_ptr<chromeos::CryptohomeClient>(cryptohome_client));
1205
1206 // Expect exactly one call. No calls means no attempt to delete keys and more
1207 // than one call means a significant performance problem.
1208 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
1209 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
1210
1211 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1212 BrowsingDataRemover::REMOVE_MEDIA_LICENSES,
1213 false);
1214
1215 chromeos::DBusThreadManager::Shutdown();
1216 }
1217 #endif
1218
1219 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Null) {
1220 const ClearDomainReliabilityTester& tester =
1221 clear_domain_reliability_tester();
1222
1223 EXPECT_EQ(0u, tester.clear_count());
1224 }
1225
1226 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Beacons) {
1227 const ClearDomainReliabilityTester& tester =
1228 clear_domain_reliability_tester();
1229
1230 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1231 BrowsingDataRemover::REMOVE_HISTORY, false);
1232 EXPECT_EQ(1u, tester.clear_count());
1233 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode());
1234 EXPECT_TRUE(ProbablySameFilters(
1235 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter()));
1236 }
1237
1238 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1239 DomainReliability_Beacons_WithFilter) {
1240 const ClearDomainReliabilityTester& tester =
1241 clear_domain_reliability_tester();
1242
1243 RegistrableDomainFilterBuilder builder(
1244 RegistrableDomainFilterBuilder::WHITELIST);
1245 builder.AddRegisterableDomain(kTestRegisterableDomain1);
1246
1247 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1248 BrowsingDataRemover::REMOVE_HISTORY, builder);
1249 EXPECT_EQ(1u, tester.clear_count());
1250 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode());
1251 EXPECT_TRUE(ProbablySameFilters(
1252 builder.BuildGeneralFilter(), tester.last_filter()));
1253 }
1254
1255 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_Contexts) {
1256 const ClearDomainReliabilityTester& tester =
1257 clear_domain_reliability_tester();
1258
1259 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1260 BrowsingDataRemover::REMOVE_COOKIES, false);
1261 EXPECT_EQ(1u, tester.clear_count());
1262 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
1263 EXPECT_TRUE(ProbablySameFilters(
1264 BrowsingDataFilterBuilder::BuildNoopFilter(), tester.last_filter()));
1265 }
1266
1267 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1268 DomainReliability_Contexts_WithFilter) {
1269 const ClearDomainReliabilityTester& tester =
1270 clear_domain_reliability_tester();
1271
1272 RegistrableDomainFilterBuilder builder(
1273 RegistrableDomainFilterBuilder::WHITELIST);
1274 builder.AddRegisterableDomain(kTestRegisterableDomain1);
1275
1276 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1277 BrowsingDataRemover::REMOVE_COOKIES, builder);
1278 EXPECT_EQ(1u, tester.clear_count());
1279 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
1280 EXPECT_TRUE(ProbablySameFilters(
1281 builder.BuildGeneralFilter(), tester.last_filter()));
1282 }
1283
1284 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DomainReliability_ContextsWin) {
1285 const ClearDomainReliabilityTester& tester =
1286 clear_domain_reliability_tester();
1287
1288 BlockUntilBrowsingDataRemoved(
1289 base::Time(), base::Time::Max(),
1290 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES,
1291 false);
1292 EXPECT_EQ(1u, tester.clear_count());
1293 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
1294 }
1295
1296 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1297 DomainReliability_ProtectedOrigins) {
1298 const ClearDomainReliabilityTester& tester =
1299 clear_domain_reliability_tester();
1300
1301 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1302 BrowsingDataRemover::REMOVE_COOKIES, true);
1303 EXPECT_EQ(1u, tester.clear_count());
1304 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
1305 }
1306
1307 // TODO(juliatuttle): This isn't actually testing the no-monitor case, since
1308 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed
1309 // for some unrelated test cases. This should be fixed so it tests the no-
1310 // monitor case again.
1311 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1312 DISABLED_DomainReliability_NoMonitor) {
1313 BlockUntilBrowsingDataRemoved(
1314 base::Time(), base::Time::Max(),
1315 BrowsingDataRemover::REMOVE_HISTORY | BrowsingDataRemover::REMOVE_COOKIES,
1316 false);
1317 }
1318
1319 // Tests that the deletion of downloads completes successfully and that
1320 // ChromeDownloadManagerDelegate is correctly created and shut down.
1321 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveDownloads) {
1322 RemoveDownloadsTester tester(GetProfile());
1323
1324 EXPECT_CALL(
1325 *tester.download_manager(), RemoveDownloadsByURLAndTime(_, _, _));
1326
1327 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1328 BrowsingDataRemover::REMOVE_DOWNLOADS, false);
1329 }
1330
1331 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordStatistics) {
1332 RemovePasswordsTester tester(GetProfile());
1333 base::Callback<bool(const GURL&)> empty_filter;
1334
1335 EXPECT_CALL(*tester.store(), RemoveStatisticsByOriginAndTimeImpl(
1336 ProbablySameFilter(empty_filter),
1337 base::Time(), base::Time::Max()));
1338 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1339 BrowsingDataRemover::REMOVE_HISTORY, false);
1340 }
1341
1342 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1343 RemovePasswordStatisticsByOrigin) {
1344 RemovePasswordsTester tester(GetProfile());
1345
1346 RegistrableDomainFilterBuilder builder(
1347 RegistrableDomainFilterBuilder::WHITELIST);
1348 builder.AddRegisterableDomain(kTestRegisterableDomain1);
1349 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter();
1350
1351 EXPECT_CALL(*tester.store(),
1352 RemoveStatisticsByOriginAndTimeImpl(
1353 ProbablySameFilter(filter), base::Time(), base::Time::Max()));
1354 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1355 BrowsingDataRemover::REMOVE_HISTORY, builder);
1356 }
1357
1358 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordsByTimeOnly) {
1359 RemovePasswordsTester tester(GetProfile());
1360 base::Callback<bool(const GURL&)> filter =
1361 BrowsingDataFilterBuilder::BuildNoopFilter();
1362
1363 EXPECT_CALL(*tester.store(),
1364 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _))
1365 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
1366 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1367 BrowsingDataRemover::REMOVE_PASSWORDS, false);
1368 }
1369
1370 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePasswordsByOrigin) {
1371 RemovePasswordsTester tester(GetProfile());
1372 RegistrableDomainFilterBuilder builder(
1373 RegistrableDomainFilterBuilder::WHITELIST);
1374 builder.AddRegisterableDomain(kTestRegisterableDomain1);
1375 base::Callback<bool(const GURL&)> filter = builder.BuildGeneralFilter();
1376
1377 EXPECT_CALL(*tester.store(),
1378 RemoveLoginsByURLAndTimeImpl(ProbablySameFilter(filter), _, _))
1379 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
1380 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1381 BrowsingDataRemover::REMOVE_PASSWORDS, builder);
1382 }
1383
1384 TEST_F(ChromeBrowsingDataRemoverDelegateTest, DisableAutoSignIn) {
1385 RemovePasswordsTester tester(GetProfile());
1386 base::Callback<bool(const GURL&)> empty_filter =
1387 BrowsingDataFilterBuilder::BuildNoopFilter();
1388
1389 EXPECT_CALL(
1390 *tester.store(),
1391 DisableAutoSignInForOriginsImpl(ProbablySameFilter(empty_filter)))
1392 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
1393
1394 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1395 BrowsingDataRemover::REMOVE_COOKIES, false);
1396 }
1397
1398 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1399 DisableAutoSignInAfterRemovingPasswords) {
1400 RemovePasswordsTester tester(GetProfile());
1401 base::Callback<bool(const GURL&)> empty_filter =
1402 BrowsingDataFilterBuilder::BuildNoopFilter();
1403
1404 EXPECT_CALL(*tester.store(), RemoveLoginsByURLAndTimeImpl(_, _, _))
1405 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
1406 EXPECT_CALL(
1407 *tester.store(),
1408 DisableAutoSignInForOriginsImpl(ProbablySameFilter(empty_filter)))
1409 .WillOnce(Return(password_manager::PasswordStoreChangeList()));
1410
1411 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1412 BrowsingDataRemover::REMOVE_COOKIES |
1413 BrowsingDataRemover::REMOVE_PASSWORDS,
1414 false);
1415 }
1416
1417 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1418 RemoveContentSettingsWithBlacklist) {
1419 // Add our settings.
1420 HostContentSettingsMap* host_content_settings_map =
1421 HostContentSettingsMapFactory::GetForProfile(GetProfile());
1422 host_content_settings_map->SetWebsiteSettingDefaultScope(
1423 kOrigin1, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
1424 base::MakeUnique<base::DictionaryValue>());
1425 host_content_settings_map->SetWebsiteSettingDefaultScope(
1426 kOrigin2, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
1427 base::MakeUnique<base::DictionaryValue>());
1428 host_content_settings_map->SetWebsiteSettingDefaultScope(
1429 kOrigin3, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
1430 base::MakeUnique<base::DictionaryValue>());
1431 host_content_settings_map->SetWebsiteSettingDefaultScope(
1432 kOrigin4, GURL(), CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(),
1433 base::MakeUnique<base::DictionaryValue>());
1434
1435 // Clear all except for origin1 and origin3.
1436 RegistrableDomainFilterBuilder filter(
1437 RegistrableDomainFilterBuilder::BLACKLIST);
1438 filter.AddRegisterableDomain(kTestRegisterableDomain1);
1439 filter.AddRegisterableDomain(kTestRegisterableDomain3);
1440 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
1441 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
1442 filter);
1443
1444 EXPECT_EQ(BrowsingDataRemover::REMOVE_SITE_USAGE_DATA, GetRemovalMask());
1445 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1446
1447 // Verify we only have true, and they're origin1, origin3, and origin4.
1448 ContentSettingsForOneType host_settings;
1449 host_content_settings_map->GetSettingsForOneType(
1450 CONTENT_SETTINGS_TYPE_SITE_ENGAGEMENT, std::string(), &host_settings);
1451 EXPECT_EQ(3u, host_settings.size());
1452 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin1),
1453 host_settings[0].primary_pattern)
1454 << host_settings[0].primary_pattern.ToString();
1455 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin4),
1456 host_settings[1].primary_pattern)
1457 << host_settings[1].primary_pattern.ToString();
1458 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin3),
1459 host_settings[2].primary_pattern)
1460 << host_settings[2].primary_pattern.ToString();
1461 }
1462
1463 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemoveDurablePermission) {
1464 // Add our settings.
1465 HostContentSettingsMap* host_content_settings_map =
1466 HostContentSettingsMapFactory::GetForProfile(GetProfile());
1467
1468 DurableStoragePermissionContext durable_permission(GetProfile());
1469 durable_permission.UpdateContentSetting(kOrigin1, GURL(),
1470 CONTENT_SETTING_ALLOW);
1471 durable_permission.UpdateContentSetting(kOrigin2, GURL(),
1472 CONTENT_SETTING_ALLOW);
1473
1474 // Clear all except for origin1 and origin3.
1475 RegistrableDomainFilterBuilder filter(
1476 RegistrableDomainFilterBuilder::BLACKLIST);
1477 filter.AddRegisterableDomain(kTestRegisterableDomain1);
1478 filter.AddRegisterableDomain(kTestRegisterableDomain3);
1479 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
1480 BrowsingDataRemover::REMOVE_DURABLE_PERMISSION,
1481 filter);
1482
1483 EXPECT_EQ(BrowsingDataRemover::REMOVE_DURABLE_PERMISSION, GetRemovalMask());
1484 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1485
1486 // Verify we only have allow for the first origin.
1487 ContentSettingsForOneType host_settings;
1488 host_content_settings_map->GetSettingsForOneType(
1489 CONTENT_SETTINGS_TYPE_DURABLE_STORAGE, std::string(), &host_settings);
1490
1491 ASSERT_EQ(2u, host_settings.size());
1492 // Only the first should should have a setting.
1493 EXPECT_EQ(ContentSettingsPattern::FromURLNoWildcard(kOrigin1),
1494 host_settings[0].primary_pattern)
1495 << host_settings[0].primary_pattern.ToString();
1496 EXPECT_EQ(CONTENT_SETTING_ALLOW, host_settings[0].setting);
1497
1498 // And our wildcard.
1499 EXPECT_EQ(ContentSettingsPattern::Wildcard(),
1500 host_settings[1].primary_pattern)
1501 << host_settings[1].primary_pattern.ToString();
1502 EXPECT_EQ(CONTENT_SETTING_ASK, host_settings[1].setting);
1503 }
1504
1505 // Test that removing passwords clears HTTP auth data.
1506 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1507 ClearHttpAuthCache_RemovePasswords) {
1508 net::HttpNetworkSession* http_session = GetProfile()
1509 ->GetRequestContext()
1510 ->GetURLRequestContext()
1511 ->http_transaction_factory()
1512 ->GetSession();
1513 DCHECK(http_session);
1514
1515 net::HttpAuthCache* http_auth_cache = http_session->http_auth_cache();
1516 http_auth_cache->Add(kOrigin1, kTestRealm, net::HttpAuth::AUTH_SCHEME_BASIC,
1517 "test challenge",
1518 net::AuthCredentials(base::ASCIIToUTF16("foo"),
1519 base::ASCIIToUTF16("bar")),
1520 "/");
1521 CHECK(http_auth_cache->Lookup(kOrigin1, kTestRealm,
1522 net::HttpAuth::AUTH_SCHEME_BASIC));
1523
1524 BlockUntilBrowsingDataRemoved(base::Time(), base::Time::Max(),
1525 BrowsingDataRemover::REMOVE_PASSWORDS, false);
1526
1527 EXPECT_EQ(nullptr, http_auth_cache->Lookup(kOrigin1, kTestRealm,
1528 net::HttpAuth::AUTH_SCHEME_BASIC));
1529 }
1530
1531 TEST_F(ChromeBrowsingDataRemoverDelegateTest, ClearPermissionPromptCounts) {
1532 RemovePermissionPromptCountsTest tester(GetProfile());
1533
1534 RegistrableDomainFilterBuilder filter_builder_1(
1535 RegistrableDomainFilterBuilder::WHITELIST);
1536 filter_builder_1.AddRegisterableDomain(kTestRegisterableDomain1);
1537
1538 RegistrableDomainFilterBuilder filter_builder_2(
1539 RegistrableDomainFilterBuilder::BLACKLIST);
1540 filter_builder_2.AddRegisterableDomain(kTestRegisterableDomain1);
1541
1542 {
1543 // Test REMOVE_HISTORY.
1544 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
1545 content::PermissionType::GEOLOCATION));
1546 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1,
1547 content::PermissionType::GEOLOCATION));
1548 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
1549 content::PermissionType::NOTIFICATIONS));
1550 tester.ShouldChangeDismissalToBlock(kOrigin1,
1551 content::PermissionType::MIDI_SYSEX);
1552 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2,
1553 content::PermissionType::DURABLE_STORAGE));
1554 tester.ShouldChangeDismissalToBlock(kOrigin2,
1555 content::PermissionType::NOTIFICATIONS);
1556
1557 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
1558 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
1559 filter_builder_1);
1560
1561 // kOrigin1 should be gone, but kOrigin2 remains.
1562 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
1563 content::PermissionType::GEOLOCATION));
1564 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
1565 content::PermissionType::NOTIFICATIONS));
1566 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
1567 content::PermissionType::MIDI_SYSEX));
1568 EXPECT_EQ(1, tester.GetIgnoreCount(
1569 kOrigin2, content::PermissionType::DURABLE_STORAGE));
1570 EXPECT_EQ(1, tester.GetDismissCount(
1571 kOrigin2, content::PermissionType::NOTIFICATIONS));
1572
1573 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1574 BrowsingDataRemover::REMOVE_HISTORY, false);
1575
1576 // Everything should be gone.
1577 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
1578 content::PermissionType::GEOLOCATION));
1579 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
1580 content::PermissionType::NOTIFICATIONS));
1581 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
1582 content::PermissionType::MIDI_SYSEX));
1583 EXPECT_EQ(0, tester.GetIgnoreCount(
1584 kOrigin2, content::PermissionType::DURABLE_STORAGE));
1585 EXPECT_EQ(0, tester.GetDismissCount(
1586 kOrigin2, content::PermissionType::NOTIFICATIONS));
1587 }
1588 {
1589 // Test REMOVE_SITE_DATA.
1590 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
1591 content::PermissionType::GEOLOCATION));
1592 EXPECT_EQ(2, tester.RecordIgnore(kOrigin1,
1593 content::PermissionType::GEOLOCATION));
1594 EXPECT_EQ(1, tester.RecordIgnore(kOrigin1,
1595 content::PermissionType::NOTIFICATIONS));
1596 tester.ShouldChangeDismissalToBlock(kOrigin1,
1597 content::PermissionType::MIDI_SYSEX);
1598 EXPECT_EQ(1, tester.RecordIgnore(kOrigin2,
1599 content::PermissionType::DURABLE_STORAGE));
1600 tester.ShouldChangeDismissalToBlock(kOrigin2,
1601 content::PermissionType::NOTIFICATIONS);
1602
1603 BlockUntilOriginDataRemoved(AnHourAgo(), base::Time::Max(),
1604 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
1605 filter_builder_2);
1606
1607 // kOrigin2 should be gone, but kOrigin1 remains.
1608 EXPECT_EQ(2, tester.GetIgnoreCount(kOrigin1,
1609 content::PermissionType::GEOLOCATION));
1610 EXPECT_EQ(1, tester.GetIgnoreCount(kOrigin1,
1611 content::PermissionType::NOTIFICATIONS));
1612 EXPECT_EQ(1, tester.GetDismissCount(kOrigin1,
1613 content::PermissionType::MIDI_SYSEX));
1614 EXPECT_EQ(0, tester.GetIgnoreCount(
1615 kOrigin2, content::PermissionType::DURABLE_STORAGE));
1616 EXPECT_EQ(0, tester.GetDismissCount(
1617 kOrigin2, content::PermissionType::NOTIFICATIONS));
1618
1619 BlockUntilBrowsingDataRemoved(AnHourAgo(), base::Time::Max(),
1620 BrowsingDataRemover::REMOVE_SITE_USAGE_DATA,
1621 false);
1622
1623 // Everything should be gone.
1624 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
1625 content::PermissionType::GEOLOCATION));
1626 EXPECT_EQ(0, tester.GetIgnoreCount(kOrigin1,
1627 content::PermissionType::NOTIFICATIONS));
1628 EXPECT_EQ(0, tester.GetDismissCount(kOrigin1,
1629 content::PermissionType::MIDI_SYSEX));
1630 EXPECT_EQ(0, tester.GetIgnoreCount(
1631 kOrigin2, content::PermissionType::DURABLE_STORAGE));
1632 EXPECT_EQ(0, tester.GetDismissCount(
1633 kOrigin2, content::PermissionType::NOTIFICATIONS));
1634 }
1635 }
1636
1637 #if BUILDFLAG(ENABLE_PLUGINS)
1638 TEST_F(ChromeBrowsingDataRemoverDelegateTest, RemovePluginData) {
1639 RemovePluginDataTester tester(GetProfile());
1640
1641 tester.AddDomain(kOrigin1.host());
1642 tester.AddDomain(kOrigin2.host());
1643 tester.AddDomain(kOrigin3.host());
1644
1645 std::vector<std::string> expected = {
1646 kOrigin1.host(), kOrigin2.host(), kOrigin3.host() };
1647 EXPECT_EQ(expected, tester.GetDomains());
1648
1649 // Delete data with a filter for the registrable domain of |kOrigin3|.
1650 RegistrableDomainFilterBuilder filter_builder(
1651 RegistrableDomainFilterBuilder::WHITELIST);
1652 filter_builder.AddRegisterableDomain(kTestRegisterableDomain3);
1653 BlockUntilOriginDataRemoved(base::Time(), base::Time::Max(),
1654 BrowsingDataRemover::REMOVE_PLUGIN_DATA,
1655 filter_builder);
1656
1657 // Plugin data for |kOrigin3.host()| should have been removed.
1658 expected.pop_back();
1659 EXPECT_EQ(expected, tester.GetDomains());
1660
1661 // TODO(msramek): Mock PluginDataRemover and test the complete deletion
1662 // of plugin data as well.
1663 }
1664 #endif
1665
1666 // Test that the remover clears bookmark meta data (normally added in a tab
1667 // helper).
1668 TEST_F(ChromeBrowsingDataRemoverDelegateTest,
1669 BookmarkLastVisitDatesGetCleared) {
1670 TestingProfile profile;
1671 profile.CreateBookmarkModel(true);
1672
1673 bookmarks::BookmarkModel* bookmark_model =
1674 BookmarkModelFactory::GetForBrowserContext(&profile);
1675 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
1676
1677 const base::Time delete_begin =
1678 base::Time::Now() - base::TimeDelta::FromDays(1);
1679
1680 // Create a couple of bookmarks.
1681 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
1682 base::string16(),
1683 GURL("http://foo.org/desktop"));
1684 bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
1685 base::string16(),
1686 GURL("http://foo.org/mobile"));
1687
1688 // Simulate their visits (this is using Time::Now() as timestamps).
1689 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame(
1690 bookmark_model, GURL("http://foo.org/desktop"),
1691 /*is_mobile_platform=*/false);
1692 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame(
1693 bookmark_model, GURL("http://foo.org/mobile"),
1694 /*is_mobile_platform=*/true);
1695
1696 // Add a bookmark with a visited timestamp before the deletion interval.
1697 bookmarks::BookmarkNode::MetaInfoMap meta_info = {
1698 {"last_visited",
1699 base::Int64ToString((delete_begin - base::TimeDelta::FromSeconds(1))
1700 .ToInternalValue())}};
1701 bookmark_model->AddURLWithCreationTimeAndMetaInfo(
1702 bookmark_model->mobile_node(), 0, base::ASCIIToUTF16("my title"),
1703 GURL("http://foo-2.org/"), delete_begin - base::TimeDelta::FromDays(1),
1704 &meta_info);
1705
1706 // There should be some recently visited bookmarks.
1707 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks(
1708 bookmark_model, 2, base::Time::UnixEpoch(),
1709 /*consider_visits_from_desktop=*/false),
1710 Not(IsEmpty()));
1711
1712 // Inject the bookmark model into the remover.
1713 BrowsingDataRemover* remover =
1714 BrowsingDataRemoverFactory::GetForBrowserContext(&profile);
1715
1716 BrowsingDataRemoverCompletionObserver completion_observer(remover);
1717 remover->RemoveAndReply(delete_begin, base::Time::Max(),
1718 BrowsingDataRemover::REMOVE_HISTORY,
1719 BrowsingDataHelper::ALL, &completion_observer);
1720 completion_observer.BlockUntilCompletion();
1721
1722 // There should be only 1 recently visited bookmarks.
1723 std::vector<const bookmarks::BookmarkNode*> remaining_nodes =
1724 ntp_snippets::GetRecentlyVisitedBookmarks(
1725 bookmark_model, 3, base::Time::UnixEpoch(),
1726 /*consider_visits_from_desktop=*/true);
1727 EXPECT_THAT(remaining_nodes, SizeIs(1));
1728 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/"));
1729 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/browsing_data_remover_unittest.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698