Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_remover_unittest.cc
blob091989b024425e5ba26547837a36587e5fbb379d
1 // Copyright (c) 2012 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.
5 #include "chrome/browser/browsing_data/browsing_data_remover.h"
7 #include <set>
8 #include <vector>
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/file_util.h"
13 #include "base/files/file_path.h"
14 #include "base/guid.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/platform_file.h"
17 #include "base/prefs/testing_pref_service.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "chrome/browser/autofill/personal_data_manager_factory.h"
20 #include "chrome/browser/browsing_data/browsing_data_helper.h"
21 #include "chrome/browser/chrome_notification_types.h"
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/chromeos/login/mock_user_manager.h"
24 #include "chrome/browser/chromeos/login/user_manager.h"
25 #include "chrome/browser/chromeos/settings/cros_settings.h"
26 #include "chrome/browser/chromeos/settings/device_settings_service.h"
27 #endif
28 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
29 #include "chrome/browser/history/history_service.h"
30 #include "chrome/browser/history/history_service_factory.h"
31 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
32 #include "chrome/common/pref_names.h"
33 #include "chrome/test/base/testing_browser_process.h"
34 #include "chrome/test/base/testing_profile.h"
35 #if defined(OS_CHROMEOS)
36 #include "chromeos/dbus/dbus_thread_manager.h"
37 #include "chromeos/dbus/fake_dbus_thread_manager.h"
38 #include "chromeos/dbus/mock_cryptohome_client.h"
39 #endif
40 #include "components/autofill/core/browser/autofill_profile.h"
41 #include "components/autofill/core/browser/autofill_test_utils.h"
42 #include "components/autofill/core/browser/credit_card.h"
43 #include "components/autofill/core/browser/personal_data_manager.h"
44 #include "components/autofill/core/browser/personal_data_manager_observer.h"
45 #include "content/public/browser/cookie_store_factory.h"
46 #include "content/public/browser/dom_storage_context.h"
47 #include "content/public/browser/local_storage_usage_info.h"
48 #include "content/public/browser/notification_service.h"
49 #include "content/public/browser/storage_partition.h"
50 #include "content/public/test/test_browser_thread.h"
51 #include "content/public/test/test_browser_thread_bundle.h"
52 #include "net/cookies/cookie_store.h"
53 #include "net/ssl/server_bound_cert_service.h"
54 #include "net/ssl/server_bound_cert_store.h"
55 #include "net/ssl/ssl_client_cert_type.h"
56 #include "net/url_request/url_request_context.h"
57 #include "net/url_request/url_request_context_getter.h"
58 #include "testing/gmock/include/gmock/gmock.h"
59 #include "testing/gtest/include/gtest/gtest.h"
61 using content::BrowserThread;
62 using content::StoragePartition;
63 using testing::_;
64 using testing::Invoke;
65 using testing::WithArgs;
67 namespace {
69 const char kTestOrigin1[] = "http://host1:1/";
70 const char kTestOrigin2[] = "http://host2:1/";
71 const char kTestOrigin3[] = "http://host3:1/";
72 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
73 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
75 // For Autofill.
76 const char kChromeOrigin[] = "Chrome settings";
77 const char kWebOrigin[] = "https://www.example.com/";
79 const GURL kOrigin1(kTestOrigin1);
80 const GURL kOrigin2(kTestOrigin2);
81 const GURL kOrigin3(kTestOrigin3);
82 const GURL kOriginExt(kTestOriginExt);
83 const GURL kOriginDevTools(kTestOriginDevTools);
85 const base::FilePath::CharType kDomStorageOrigin1[] =
86 FILE_PATH_LITERAL("http_host1_1.localstorage");
88 const base::FilePath::CharType kDomStorageOrigin2[] =
89 FILE_PATH_LITERAL("http_host2_1.localstorage");
91 const base::FilePath::CharType kDomStorageOrigin3[] =
92 FILE_PATH_LITERAL("http_host3_1.localstorage");
94 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL(
95 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
97 class AwaitCompletionHelper : public BrowsingDataRemover::Observer {
98 public:
99 AwaitCompletionHelper() : start_(false), already_quit_(false) {}
100 virtual ~AwaitCompletionHelper() {}
102 void BlockUntilNotified() {
103 if (!already_quit_) {
104 DCHECK(!start_);
105 start_ = true;
106 base::MessageLoop::current()->Run();
107 } else {
108 DCHECK(!start_);
109 already_quit_ = false;
113 void Notify() {
114 if (start_) {
115 DCHECK(!already_quit_);
116 base::MessageLoop::current()->Quit();
117 start_ = false;
118 } else {
119 DCHECK(!already_quit_);
120 already_quit_ = true;
124 protected:
125 // BrowsingDataRemover::Observer implementation.
126 virtual void OnBrowsingDataRemoverDone() OVERRIDE {
127 Notify();
130 private:
131 // Helps prevent from running message_loop, if the callback invoked
132 // immediately.
133 bool start_;
134 bool already_quit_;
136 DISALLOW_COPY_AND_ASSIGN(AwaitCompletionHelper);
139 #if defined(OS_CHROMEOS)
140 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
141 base::MessageLoop::current()->PostTask(
142 FROM_HERE,
143 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true));
145 #endif
147 struct StoragePartitionRemovalData {
148 uint32 remove_mask;
149 uint32 quota_storage_remove_mask;
150 GURL remove_origin;
151 base::Time remove_begin;
152 base::Time remove_end;
153 StoragePartition::OriginMatcherFunction origin_matcher;
155 StoragePartitionRemovalData() : remove_mask(0),
156 quota_storage_remove_mask(0) {}
159 class TestStoragePartition : public StoragePartition {
160 public:
161 TestStoragePartition() {}
162 virtual ~TestStoragePartition() {}
164 // content::StoragePartition implementation.
165 virtual base::FilePath GetPath() OVERRIDE { return base::FilePath(); }
166 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE {
167 return NULL;
169 virtual net::URLRequestContextGetter* GetMediaURLRequestContext() OVERRIDE {
170 return NULL;
172 virtual quota::QuotaManager* GetQuotaManager() OVERRIDE {
173 return NULL;
175 virtual appcache::AppCacheService* GetAppCacheService() OVERRIDE {
176 return NULL;
178 virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE {
179 return NULL;
181 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE {
182 return NULL;
184 virtual content::DOMStorageContext* GetDOMStorageContext() OVERRIDE {
185 return NULL;
187 virtual content::IndexedDBContext* GetIndexedDBContext() OVERRIDE {
188 return NULL;
190 virtual content::ServiceWorkerContextWrapper*
191 GetServiceWorkerContext() OVERRIDE {
192 return NULL;
195 virtual void ClearDataForOrigin(
196 uint32 remove_mask,
197 uint32 quota_storage_remove_mask,
198 const GURL& storage_origin,
199 net::URLRequestContextGetter* rq_context) OVERRIDE {}
201 virtual void ClearData(uint32 remove_mask,
202 uint32 quota_storage_remove_mask,
203 const GURL& storage_origin,
204 const OriginMatcherFunction& origin_matcher,
205 const base::Time begin,
206 const base::Time end,
207 const base::Closure& callback) OVERRIDE {
208 // Store stuff to verify parameters' correctness later.
209 storage_partition_removal_data_.remove_mask = remove_mask;
210 storage_partition_removal_data_.quota_storage_remove_mask =
211 quota_storage_remove_mask;
212 storage_partition_removal_data_.remove_origin = storage_origin;
213 storage_partition_removal_data_.remove_begin = begin;
214 storage_partition_removal_data_.remove_end = end;
215 storage_partition_removal_data_.origin_matcher = origin_matcher;
217 BrowserThread::PostTask(
218 BrowserThread::UI,
219 FROM_HERE,
220 base::Bind(&TestStoragePartition::AsyncRunCallback,
221 base::Unretained(this), callback));
224 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
225 return storage_partition_removal_data_;
227 private:
228 void AsyncRunCallback(const base::Closure& callback) {
229 callback.Run();
232 StoragePartitionRemovalData storage_partition_removal_data_;
234 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition);
237 } // namespace
239 // Testers -------------------------------------------------------------------
241 class RemoveCookieTester {
242 public:
243 RemoveCookieTester() : get_cookie_success_(false), cookie_store_(NULL) {
246 // Returns true, if the given cookie exists in the cookie store.
247 bool ContainsCookie() {
248 get_cookie_success_ = false;
249 cookie_store_->GetCookiesWithOptionsAsync(
250 kOrigin1, net::CookieOptions(),
251 base::Bind(&RemoveCookieTester::GetCookieCallback,
252 base::Unretained(this)));
253 await_completion_.BlockUntilNotified();
254 return get_cookie_success_;
257 void AddCookie() {
258 cookie_store_->SetCookieWithOptionsAsync(
259 kOrigin1, "A=1", net::CookieOptions(),
260 base::Bind(&RemoveCookieTester::SetCookieCallback,
261 base::Unretained(this)));
262 await_completion_.BlockUntilNotified();
265 protected:
266 void SetMonster(net::CookieStore* monster) {
267 cookie_store_ = monster;
270 private:
271 void GetCookieCallback(const std::string& cookies) {
272 if (cookies == "A=1") {
273 get_cookie_success_ = true;
274 } else {
275 EXPECT_EQ("", cookies);
276 get_cookie_success_ = false;
278 await_completion_.Notify();
281 void SetCookieCallback(bool result) {
282 ASSERT_TRUE(result);
283 await_completion_.Notify();
286 bool get_cookie_success_;
287 AwaitCompletionHelper await_completion_;
288 net::CookieStore* cookie_store_;
290 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
293 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
294 class RemoveSafeBrowsingCookieTester : public RemoveCookieTester {
295 public:
296 RemoveSafeBrowsingCookieTester()
297 : browser_process_(TestingBrowserProcess::GetGlobal()) {
298 scoped_refptr<SafeBrowsingService> sb_service =
299 SafeBrowsingService::CreateSafeBrowsingService();
300 browser_process_->SetSafeBrowsingService(sb_service.get());
301 sb_service->Initialize();
302 base::MessageLoop::current()->RunUntilIdle();
304 // Create a cookiemonster that does not have persistant storage, and replace
305 // the SafeBrowsingService created one with it.
306 net::CookieStore* monster =
307 content::CreateCookieStore(content::CookieStoreConfig());
308 sb_service->url_request_context()->GetURLRequestContext()->
309 set_cookie_store(monster);
310 SetMonster(monster);
313 virtual ~RemoveSafeBrowsingCookieTester() {
314 browser_process_->safe_browsing_service()->ShutDown();
315 base::MessageLoop::current()->RunUntilIdle();
316 browser_process_->SetSafeBrowsingService(NULL);
319 private:
320 TestingBrowserProcess* browser_process_;
322 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
324 #endif
326 class RemoveServerBoundCertTester : public net::SSLConfigService::Observer {
327 public:
328 explicit RemoveServerBoundCertTester(TestingProfile* profile)
329 : ssl_config_changed_count_(0) {
330 server_bound_cert_service_ = profile->GetRequestContext()->
331 GetURLRequestContext()->server_bound_cert_service();
332 ssl_config_service_ = profile->GetSSLConfigService();
333 ssl_config_service_->AddObserver(this);
336 virtual ~RemoveServerBoundCertTester() {
337 ssl_config_service_->RemoveObserver(this);
340 int ServerBoundCertCount() {
341 return server_bound_cert_service_->cert_count();
344 // Add a server bound cert for |server| with specific creation and expiry
345 // times. The cert and key data will be filled with dummy values.
346 void AddServerBoundCertWithTimes(const std::string& server_identifier,
347 base::Time creation_time,
348 base::Time expiration_time) {
349 GetCertStore()->SetServerBoundCert(server_identifier,
350 creation_time,
351 expiration_time,
352 "a",
353 "b");
356 // Add a server bound cert for |server|, with the current time as the
357 // creation time. The cert and key data will be filled with dummy values.
358 void AddServerBoundCert(const std::string& server_identifier) {
359 base::Time now = base::Time::Now();
360 AddServerBoundCertWithTimes(server_identifier,
361 now,
362 now + base::TimeDelta::FromDays(1));
365 void GetCertList(net::ServerBoundCertStore::ServerBoundCertList* certs) {
366 GetCertStore()->GetAllServerBoundCerts(
367 base::Bind(&RemoveServerBoundCertTester::GetAllCertsCallback, certs));
370 net::ServerBoundCertStore* GetCertStore() {
371 return server_bound_cert_service_->GetCertStore();
374 int ssl_config_changed_count() const {
375 return ssl_config_changed_count_;
378 // net::SSLConfigService::Observer implementation:
379 virtual void OnSSLConfigChanged() OVERRIDE {
380 ssl_config_changed_count_++;
383 private:
384 static void GetAllCertsCallback(
385 net::ServerBoundCertStore::ServerBoundCertList* dest,
386 const net::ServerBoundCertStore::ServerBoundCertList& result) {
387 *dest = result;
390 net::ServerBoundCertService* server_bound_cert_service_;
391 scoped_refptr<net::SSLConfigService> ssl_config_service_;
392 int ssl_config_changed_count_;
394 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester);
397 class RemoveHistoryTester {
398 public:
399 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {}
401 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
402 if (!profile->CreateHistoryService(true, false))
403 return false;
404 history_service_ = HistoryServiceFactory::GetForProfile(
405 profile, Profile::EXPLICIT_ACCESS);
406 return true;
409 // Returns true, if the given URL exists in the history service.
410 bool HistoryContainsURL(const GURL& url) {
411 history_service_->QueryURL(
412 url,
413 true,
414 &consumer_,
415 base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
416 base::Unretained(this)));
417 await_completion_.BlockUntilNotified();
418 return query_url_success_;
421 void AddHistory(const GURL& url, base::Time time) {
422 history_service_->AddPage(url, time, NULL, 0, GURL(),
423 history::RedirectList(), content::PAGE_TRANSITION_LINK,
424 history::SOURCE_BROWSED, false);
427 private:
428 // Callback for HistoryService::QueryURL.
429 void SaveResultAndQuit(HistoryService::Handle,
430 bool success,
431 const history::URLRow*,
432 history::VisitVector*) {
433 query_url_success_ = success;
434 await_completion_.Notify();
437 // For History requests.
438 CancelableRequestConsumer consumer_;
439 bool query_url_success_;
441 // TestingProfile owns the history service; we shouldn't delete it.
442 HistoryService* history_service_;
444 AwaitCompletionHelper await_completion_;
446 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
449 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
450 public:
451 explicit RemoveAutofillTester(TestingProfile* profile)
452 : personal_data_manager_(
453 autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
454 autofill::test::DisableSystemServices(profile);
455 personal_data_manager_->AddObserver(this);
458 virtual ~RemoveAutofillTester() {
459 personal_data_manager_->RemoveObserver(this);
462 // Returns true if there are autofill profiles.
463 bool HasProfile() {
464 return !personal_data_manager_->GetProfiles().empty() &&
465 !personal_data_manager_->GetCreditCards().empty();
468 bool HasOrigin(const std::string& origin) {
469 const std::vector<autofill::AutofillProfile*>& profiles =
470 personal_data_manager_->GetProfiles();
471 for (std::vector<autofill::AutofillProfile*>::const_iterator it =
472 profiles.begin();
473 it != profiles.end(); ++it) {
474 if ((*it)->origin() == origin)
475 return true;
478 const std::vector<autofill::CreditCard*>& credit_cards =
479 personal_data_manager_->GetCreditCards();
480 for (std::vector<autofill::CreditCard*>::const_iterator it =
481 credit_cards.begin();
482 it != credit_cards.end(); ++it) {
483 if ((*it)->origin() == origin)
484 return true;
487 return false;
490 // Add two profiles and two credit cards to the database. In each pair, one
491 // entry has a web origin and the other has a Chrome origin.
492 void AddProfilesAndCards() {
493 std::vector<autofill::AutofillProfile> profiles;
494 autofill::AutofillProfile profile;
495 profile.set_guid(base::GenerateGUID());
496 profile.set_origin(kWebOrigin);
497 profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
498 profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
499 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
500 profile.SetRawInfo(autofill::EMAIL_ADDRESS,
501 base::ASCIIToUTF16("sue@example.com"));
502 profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
503 profiles.push_back(profile);
505 profile.set_guid(base::GenerateGUID());
506 profile.set_origin(kChromeOrigin);
507 profiles.push_back(profile);
509 personal_data_manager_->SetProfiles(&profiles);
510 base::MessageLoop::current()->Run();
512 std::vector<autofill::CreditCard> cards;
513 autofill::CreditCard card;
514 card.set_guid(base::GenerateGUID());
515 card.set_origin(kWebOrigin);
516 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
517 base::ASCIIToUTF16("1234-5678-9012-3456"));
518 cards.push_back(card);
520 card.set_guid(base::GenerateGUID());
521 card.set_origin(kChromeOrigin);
522 cards.push_back(card);
524 personal_data_manager_->SetCreditCards(&cards);
525 base::MessageLoop::current()->Run();
528 private:
529 virtual void OnPersonalDataChanged() OVERRIDE {
530 base::MessageLoop::current()->Quit();
533 autofill::PersonalDataManager* personal_data_manager_;
534 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
537 class RemoveLocalStorageTester {
538 public:
539 explicit RemoveLocalStorageTester(TestingProfile* profile)
540 : profile_(profile), dom_storage_context_(NULL) {
541 dom_storage_context_ =
542 content::BrowserContext::GetDefaultStoragePartition(profile)->
543 GetDOMStorageContext();
546 // Returns true, if the given origin URL exists.
547 bool DOMStorageExistsForOrigin(const GURL& origin) {
548 GetLocalStorageUsage();
549 await_completion_.BlockUntilNotified();
550 for (size_t i = 0; i < infos_.size(); ++i) {
551 if (origin == infos_[i].origin)
552 return true;
554 return false;
557 void AddDOMStorageTestData() {
558 // Note: This test depends on details of how the dom_storage library
559 // stores data in the host file system.
560 base::FilePath storage_path =
561 profile_->GetPath().AppendASCII("Local Storage");
562 base::CreateDirectory(storage_path);
564 // Write some files.
565 file_util::WriteFile(storage_path.Append(kDomStorageOrigin1), NULL, 0);
566 file_util::WriteFile(storage_path.Append(kDomStorageOrigin2), NULL, 0);
567 file_util::WriteFile(storage_path.Append(kDomStorageOrigin3), NULL, 0);
568 file_util::WriteFile(storage_path.Append(kDomStorageExt), NULL, 0);
570 // Tweak their dates.
571 base::Time now = base::Time::Now();
572 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
574 base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
575 base::TouchFile(storage_path.Append(kDomStorageOrigin2),
576 one_day_ago, one_day_ago);
578 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
579 base::TouchFile(storage_path.Append(kDomStorageOrigin3),
580 sixty_days_ago, sixty_days_ago);
582 base::TouchFile(storage_path.Append(kDomStorageExt), now, now);
585 private:
586 void GetLocalStorageUsage() {
587 dom_storage_context_->GetLocalStorageUsage(
588 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage,
589 base::Unretained(this)));
591 void OnGotLocalStorageUsage(
592 const std::vector<content::LocalStorageUsageInfo>& infos) {
593 infos_ = infos;
594 await_completion_.Notify();
597 // We don't own these pointers.
598 TestingProfile* profile_;
599 content::DOMStorageContext* dom_storage_context_;
601 std::vector<content::LocalStorageUsageInfo> infos_;
603 AwaitCompletionHelper await_completion_;
605 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
608 // Test Class ----------------------------------------------------------------
610 class BrowsingDataRemoverTest : public testing::Test,
611 public content::NotificationObserver {
612 public:
613 BrowsingDataRemoverTest()
614 : profile_(new TestingProfile()) {
615 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
616 content::Source<Profile>(profile_.get()));
619 virtual ~BrowsingDataRemoverTest() {
622 virtual void TearDown() {
623 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
624 // posts a message to the WEBKIT thread to delete some of its member
625 // variables. We need to ensure that the profile is destroyed, and that
626 // the message loop is cleared out, before destroying the threads and loop.
627 // Otherwise we leak memory.
628 profile_.reset();
629 base::MessageLoop::current()->RunUntilIdle();
632 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period,
633 int remove_mask,
634 bool include_protected_origins) {
635 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
636 profile_.get(), period);
638 TestStoragePartition storage_partition;
639 remover->OverrideStoragePartitionForTesting(&storage_partition);
641 AwaitCompletionHelper await_completion;
642 remover->AddObserver(&await_completion);
644 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
646 // BrowsingDataRemover deletes itself when it completes.
647 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB;
648 if (include_protected_origins)
649 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB;
650 remover->Remove(remove_mask, origin_set_mask);
651 await_completion.BlockUntilNotified();
653 // Save so we can verify later.
654 storage_partition_removal_data_ =
655 storage_partition.GetStoragePartitionRemovalData();
658 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period,
659 int remove_mask,
660 const GURL& remove_origin) {
661 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
662 profile_.get(), period);
663 TestStoragePartition storage_partition;
664 remover->OverrideStoragePartitionForTesting(&storage_partition);
666 AwaitCompletionHelper await_completion;
667 remover->AddObserver(&await_completion);
669 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
671 // BrowsingDataRemover deletes itself when it completes.
672 remover->RemoveImpl(remove_mask, remove_origin,
673 BrowsingDataHelper::UNPROTECTED_WEB);
674 await_completion.BlockUntilNotified();
676 // Save so we can verify later.
677 storage_partition_removal_data_ =
678 storage_partition.GetStoragePartitionRemovalData();
681 TestingProfile* GetProfile() {
682 return profile_.get();
685 base::Time GetBeginTime() {
686 return called_with_details_->removal_begin;
689 int GetRemovalMask() {
690 return called_with_details_->removal_mask;
693 int GetOriginSetMask() {
694 return called_with_details_->origin_set_mask;
697 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
698 return storage_partition_removal_data_;
701 // content::NotificationObserver implementation.
702 virtual void Observe(int type,
703 const content::NotificationSource& source,
704 const content::NotificationDetails& details) OVERRIDE {
705 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED);
707 // We're not taking ownership of the details object, but storing a copy of
708 // it locally.
709 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails(
710 *content::Details<BrowsingDataRemover::NotificationDetails>(
711 details).ptr()));
713 registrar_.RemoveAll();
716 private:
717 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
718 content::NotificationRegistrar registrar_;
720 content::TestBrowserThreadBundle thread_bundle_;
721 scoped_ptr<TestingProfile> profile_;
723 StoragePartitionRemovalData storage_partition_removal_data_;
725 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
728 // Tests ---------------------------------------------------------------------
730 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
731 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
732 BrowsingDataRemover::REMOVE_COOKIES,
733 false);
735 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
736 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
738 // Verify that storage partition was instructed to remove the cookies.
739 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
740 EXPECT_EQ(removal_data.remove_mask,
741 static_cast<uint32>(
742 StoragePartition::REMOVE_DATA_MASK_COOKIES));
743 EXPECT_EQ(removal_data.quota_storage_remove_mask,
744 static_cast<uint32>(
745 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
746 EXPECT_TRUE(removal_data.remove_origin.is_empty());
747 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
750 TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) {
751 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
752 BrowsingDataRemover::REMOVE_COOKIES,
753 false);
755 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
756 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
758 // Verify that storage partition was instructed to remove the cookies.
759 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
760 EXPECT_EQ(removal_data.remove_mask,
761 static_cast<uint32>(
762 StoragePartition::REMOVE_DATA_MASK_COOKIES));
763 // Removing with time period other than EVERYTHING should not clear
764 // persistent storage data.
765 EXPECT_EQ(removal_data.quota_storage_remove_mask,
766 static_cast<uint32>(
767 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL &
768 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT));
769 EXPECT_TRUE(removal_data.remove_origin.is_empty());
770 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
773 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
774 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) {
775 RemoveSafeBrowsingCookieTester tester;
777 tester.AddCookie();
778 ASSERT_TRUE(tester.ContainsCookie());
780 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
781 BrowsingDataRemover::REMOVE_COOKIES, false);
783 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
784 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
785 EXPECT_FALSE(tester.ContainsCookie());
788 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) {
789 RemoveSafeBrowsingCookieTester tester;
791 tester.AddCookie();
792 ASSERT_TRUE(tester.ContainsCookie());
794 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
795 BrowsingDataRemover::REMOVE_COOKIES, false);
797 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
798 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
799 // Removing with time period other than EVERYTHING should not clear safe
800 // browsing cookies.
801 EXPECT_TRUE(tester.ContainsCookie());
803 #endif
805 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertForever) {
806 RemoveServerBoundCertTester tester(GetProfile());
808 tester.AddServerBoundCert(kTestOrigin1);
809 EXPECT_EQ(0, tester.ssl_config_changed_count());
810 EXPECT_EQ(1, tester.ServerBoundCertCount());
812 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
813 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false);
815 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask());
816 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
817 EXPECT_EQ(1, tester.ssl_config_changed_count());
818 EXPECT_EQ(0, tester.ServerBoundCertCount());
821 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertLastHour) {
822 RemoveServerBoundCertTester tester(GetProfile());
824 base::Time now = base::Time::Now();
825 tester.AddServerBoundCert(kTestOrigin1);
826 tester.AddServerBoundCertWithTimes(kTestOrigin2,
827 now - base::TimeDelta::FromHours(2),
828 now);
829 EXPECT_EQ(0, tester.ssl_config_changed_count());
830 EXPECT_EQ(2, tester.ServerBoundCertCount());
832 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
833 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false);
835 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask());
836 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
837 EXPECT_EQ(1, tester.ssl_config_changed_count());
838 ASSERT_EQ(1, tester.ServerBoundCertCount());
839 net::ServerBoundCertStore::ServerBoundCertList certs;
840 tester.GetCertList(&certs);
841 ASSERT_EQ(1U, certs.size());
842 EXPECT_EQ(kTestOrigin2, certs.front().server_identifier());
845 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) {
846 // Protect kOrigin1.
847 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
848 new MockExtensionSpecialStoragePolicy;
849 mock_policy->AddProtected(kOrigin1.GetOrigin());
850 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
852 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
853 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
854 false);
856 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
857 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
859 // Verify that storage partition was instructed to remove the data correctly.
860 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
861 EXPECT_EQ(removal_data.remove_mask,
862 static_cast<uint32>(
863 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE));
864 EXPECT_EQ(removal_data.quota_storage_remove_mask,
865 static_cast<uint32>(
866 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
867 EXPECT_TRUE(removal_data.remove_origin.is_empty());
868 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
870 // Check origin matcher.
871 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
872 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
873 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
874 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy));
877 TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) {
878 // Protect kOrigin1.
879 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
880 new MockExtensionSpecialStoragePolicy;
881 mock_policy->AddProtected(kOrigin1.GetOrigin());
882 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
884 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
885 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
886 true);
888 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
889 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB |
890 BrowsingDataHelper::PROTECTED_WEB, GetOriginSetMask());
892 // Verify that storage partition was instructed to remove the data correctly.
893 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
894 EXPECT_EQ(removal_data.remove_mask,
895 static_cast<uint32>(
896 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE));
897 EXPECT_EQ(removal_data.quota_storage_remove_mask,
898 static_cast<uint32>(
899 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
900 EXPECT_TRUE(removal_data.remove_origin.is_empty());
901 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
903 // Check origin matcher all http origin will match since we specified
904 // both protected and unprotected.
905 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
906 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
907 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
908 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy));
911 TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) {
912 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
913 new MockExtensionSpecialStoragePolicy;
914 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
916 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
917 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
918 false);
920 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
921 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
923 // Verify that storage partition was instructed to remove the data correctly.
924 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
925 EXPECT_EQ(removal_data.remove_mask,
926 static_cast<uint32>(
927 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE));
928 // Persistent storage won't be deleted.
929 EXPECT_EQ(removal_data.quota_storage_remove_mask,
930 static_cast<uint32>(
931 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL &
932 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT));
933 EXPECT_TRUE(removal_data.remove_origin.is_empty());
934 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
936 // Check origin matcher.
937 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
938 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
939 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
940 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy));
943 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
944 RemoveHistoryTester tester;
945 ASSERT_TRUE(tester.Init(GetProfile()));
947 tester.AddHistory(kOrigin1, base::Time::Now());
948 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
950 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
951 BrowsingDataRemover::REMOVE_HISTORY, false);
953 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
954 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
955 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
958 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
959 RemoveHistoryTester tester;
960 ASSERT_TRUE(tester.Init(GetProfile()));
962 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
964 tester.AddHistory(kOrigin1, base::Time::Now());
965 tester.AddHistory(kOrigin2, two_hours_ago);
966 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
967 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
969 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
970 BrowsingDataRemover::REMOVE_HISTORY, false);
972 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
973 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
974 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
975 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
978 // This should crash (DCHECK) in Debug, but death tests don't work properly
979 // here.
980 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
981 TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
982 RemoveHistoryTester tester;
983 ASSERT_TRUE(tester.Init(GetProfile()));
984 PrefService* prefs = GetProfile()->GetPrefs();
985 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
987 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
989 tester.AddHistory(kOrigin1, base::Time::Now());
990 tester.AddHistory(kOrigin2, two_hours_ago);
991 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
992 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
994 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
995 BrowsingDataRemover::REMOVE_HISTORY, false);
996 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
997 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
999 // Nothing should have been deleted.
1000 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1001 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1003 #endif
1005 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) {
1006 // Add some history.
1007 RemoveHistoryTester history_tester;
1008 ASSERT_TRUE(history_tester.Init(GetProfile()));
1009 history_tester.AddHistory(kOrigin1, base::Time::Now());
1010 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1012 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1013 BrowsingDataRemover::REMOVE_COOKIES;
1015 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1016 removal_mask, false);
1018 EXPECT_EQ(removal_mask, GetRemovalMask());
1019 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1020 EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1));
1022 // The cookie would be deleted throught the StorageParition, check if the
1023 // partition was requested to remove cookie.
1024 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1025 EXPECT_EQ(removal_data.remove_mask,
1026 static_cast<uint32>(
1027 StoragePartition::REMOVE_DATA_MASK_COOKIES));
1028 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1029 static_cast<uint32>(
1030 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1033 // This should crash (DCHECK) in Debug, but death tests don't work properly
1034 // here.
1035 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1036 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
1037 PrefService* prefs = GetProfile()->GetPrefs();
1038 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1040 // Add some history.
1041 RemoveHistoryTester history_tester;
1042 ASSERT_TRUE(history_tester.Init(GetProfile()));
1043 history_tester.AddHistory(kOrigin1, base::Time::Now());
1044 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1046 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1047 BrowsingDataRemover::REMOVE_COOKIES;
1049 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1050 removal_mask, false);
1051 EXPECT_EQ(removal_mask, GetRemovalMask());
1052 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1054 // 1/2. History should remain.
1055 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1057 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if
1058 // the partition was requested to remove cookie.
1059 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1060 EXPECT_EQ(removal_data.remove_mask,
1061 static_cast<uint32>(
1062 StoragePartition::REMOVE_DATA_MASK_COOKIES));
1063 // Persistent storage won't be deleted, since EVERYTHING was not specified.
1064 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1065 static_cast<uint32>(
1066 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL &
1067 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT));
1069 #endif
1071 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
1072 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1073 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1074 BrowsingDataRemover::REMOVE_WEBSQL |
1075 BrowsingDataRemover::REMOVE_APPCACHE |
1076 BrowsingDataRemover::REMOVE_INDEXEDDB,
1077 false);
1079 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1080 BrowsingDataRemover::REMOVE_WEBSQL |
1081 BrowsingDataRemover::REMOVE_APPCACHE |
1082 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1083 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1085 // Verify storage partition related stuffs.
1086 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1087 EXPECT_EQ(removal_data.remove_mask,
1088 static_cast<uint32>(
1089 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1090 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1091 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1092 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1093 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1094 static_cast<uint32>(
1095 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1096 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1099 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
1100 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1101 new MockExtensionSpecialStoragePolicy;
1102 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1104 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1105 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1106 BrowsingDataRemover::REMOVE_WEBSQL |
1107 BrowsingDataRemover::REMOVE_APPCACHE |
1108 BrowsingDataRemover::REMOVE_INDEXEDDB,
1109 false);
1111 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1112 BrowsingDataRemover::REMOVE_WEBSQL |
1113 BrowsingDataRemover::REMOVE_APPCACHE |
1114 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1115 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1117 // Verify storage partition related stuffs.
1118 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1120 EXPECT_EQ(removal_data.remove_mask,
1121 static_cast<uint32>(
1122 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1123 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1124 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1125 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1126 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1127 static_cast<uint32>(
1128 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1129 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1131 // Check that all related origin data would be removed, that is, origin
1132 // matcher would match these origin.
1133 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1134 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1135 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1138 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
1139 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1140 new MockExtensionSpecialStoragePolicy;
1141 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1143 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1144 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1145 BrowsingDataRemover::REMOVE_WEBSQL |
1146 BrowsingDataRemover::REMOVE_APPCACHE |
1147 BrowsingDataRemover::REMOVE_INDEXEDDB,
1148 false);
1150 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1151 BrowsingDataRemover::REMOVE_WEBSQL |
1152 BrowsingDataRemover::REMOVE_APPCACHE |
1153 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1154 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1156 // Verify storage partition related stuffs.
1157 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1159 EXPECT_EQ(removal_data.remove_mask,
1160 static_cast<uint32>(
1161 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1162 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1163 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1164 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1165 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1166 static_cast<uint32>(
1167 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1168 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1170 // Check that all related origin data would be removed, that is, origin
1171 // matcher would match these origin.
1172 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1173 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1174 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1177 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
1178 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1179 new MockExtensionSpecialStoragePolicy;
1180 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1183 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1184 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1185 BrowsingDataRemover::REMOVE_WEBSQL |
1186 BrowsingDataRemover::REMOVE_APPCACHE |
1187 BrowsingDataRemover::REMOVE_INDEXEDDB,
1188 false);
1190 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1191 BrowsingDataRemover::REMOVE_WEBSQL |
1192 BrowsingDataRemover::REMOVE_APPCACHE |
1193 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1194 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1196 // Verify storage partition related stuffs.
1197 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1199 EXPECT_EQ(removal_data.remove_mask,
1200 static_cast<uint32>(
1201 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1202 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1203 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1204 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1205 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1206 static_cast<uint32>(
1207 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1208 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1210 // Check that all related origin data would be removed, that is, origin
1211 // matcher would match these origin.
1212 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1213 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1214 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1217 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
1218 // Remove Origin 1.
1219 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1220 BrowsingDataRemover::REMOVE_APPCACHE |
1221 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1222 BrowsingDataRemover::REMOVE_INDEXEDDB |
1223 BrowsingDataRemover::REMOVE_WEBSQL,
1224 kOrigin1);
1226 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1227 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1228 BrowsingDataRemover::REMOVE_INDEXEDDB |
1229 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1230 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1232 // Verify storage partition related stuffs.
1233 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1235 EXPECT_EQ(removal_data.remove_mask,
1236 static_cast<uint32>(
1237 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1238 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1239 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1240 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1241 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1242 static_cast<uint32>(
1243 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1244 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1247 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
1248 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1249 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1250 BrowsingDataRemover::REMOVE_WEBSQL |
1251 BrowsingDataRemover::REMOVE_APPCACHE |
1252 BrowsingDataRemover::REMOVE_INDEXEDDB,
1253 false);
1255 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1256 BrowsingDataRemover::REMOVE_WEBSQL |
1257 BrowsingDataRemover::REMOVE_APPCACHE |
1258 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1259 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1261 // Verify storage partition related stuffs.
1262 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1264 EXPECT_EQ(removal_data.remove_mask,
1265 static_cast<uint32>(
1266 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1267 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1268 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1269 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1271 // Persistent data would be left out since we are not removing from
1272 // beginning of time.
1273 uint32 expected_quota_mask =
1274 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1275 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1276 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1277 // Check removal begin time.
1278 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1281 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
1282 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
1283 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1284 BrowsingDataRemover::REMOVE_WEBSQL |
1285 BrowsingDataRemover::REMOVE_APPCACHE |
1286 BrowsingDataRemover::REMOVE_INDEXEDDB,
1287 false);
1289 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1290 BrowsingDataRemover::REMOVE_WEBSQL |
1291 BrowsingDataRemover::REMOVE_APPCACHE |
1292 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1293 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1295 // Verify storage partition related stuffs.
1296 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1298 EXPECT_EQ(removal_data.remove_mask,
1299 static_cast<uint32>(
1300 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1301 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1302 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1303 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1305 // Persistent data would be left out since we are not removing from
1306 // beginning of time.
1307 uint32 expected_quota_mask =
1308 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1309 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1310 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1311 // Check removal begin time.
1312 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1315 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
1316 // Protect kOrigin1.
1317 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1318 new MockExtensionSpecialStoragePolicy;
1319 mock_policy->AddProtected(kOrigin1.GetOrigin());
1320 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1322 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1323 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1324 BrowsingDataRemover::REMOVE_WEBSQL |
1325 BrowsingDataRemover::REMOVE_APPCACHE |
1326 BrowsingDataRemover::REMOVE_INDEXEDDB,
1327 false);
1329 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1330 BrowsingDataRemover::REMOVE_WEBSQL |
1331 BrowsingDataRemover::REMOVE_APPCACHE |
1332 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1333 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1335 // Verify storage partition related stuffs.
1336 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1338 EXPECT_EQ(removal_data.remove_mask,
1339 static_cast<uint32>(
1340 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1341 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1342 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1343 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1344 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1345 static_cast<uint32>(
1346 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1347 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1349 // Check OriginMatcherFunction, |kOrigin1| would not match mask since it
1350 // is protected.
1351 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1352 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1353 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1356 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) {
1357 // Protect kOrigin1.
1358 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1359 new MockExtensionSpecialStoragePolicy;
1360 mock_policy->AddProtected(kOrigin1.GetOrigin());
1361 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1363 // Try to remove kOrigin1. Expect failure.
1364 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1365 BrowsingDataRemover::REMOVE_APPCACHE |
1366 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1367 BrowsingDataRemover::REMOVE_INDEXEDDB |
1368 BrowsingDataRemover::REMOVE_WEBSQL,
1369 kOrigin1);
1371 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1372 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1373 BrowsingDataRemover::REMOVE_INDEXEDDB |
1374 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1375 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1377 // Verify storage partition related stuffs.
1378 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1380 EXPECT_EQ(removal_data.remove_mask,
1381 static_cast<uint32>(
1382 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1383 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1384 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1385 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1386 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1387 static_cast<uint32>(
1388 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1389 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1391 // Check OriginMatcherFunction, |kOrigin1| would not match mask since it
1392 // is protected.
1393 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1394 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1395 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1398 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) {
1399 // Protect kOrigin1.
1400 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1401 new MockExtensionSpecialStoragePolicy;
1402 mock_policy->AddProtected(kOrigin1.GetOrigin());
1403 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1405 // Try to remove kOrigin1. Expect success.
1406 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1407 BrowsingDataRemover::REMOVE_APPCACHE |
1408 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1409 BrowsingDataRemover::REMOVE_INDEXEDDB |
1410 BrowsingDataRemover::REMOVE_WEBSQL,
1411 true);
1413 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1414 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1415 BrowsingDataRemover::REMOVE_INDEXEDDB |
1416 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1417 EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB |
1418 BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1420 // Verify storage partition related stuffs.
1421 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1423 EXPECT_EQ(removal_data.remove_mask,
1424 static_cast<uint32>(
1425 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1426 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1427 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1428 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1429 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1430 static_cast<uint32>(
1431 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1432 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1434 // Check OriginMatcherFunction, |kOrigin1| would match mask since we
1435 // would have 'protected' specified in origin_set_mask.
1436 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1437 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1438 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1441 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
1442 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1443 new MockExtensionSpecialStoragePolicy;
1444 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1446 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1447 BrowsingDataRemover::REMOVE_APPCACHE |
1448 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1449 BrowsingDataRemover::REMOVE_INDEXEDDB |
1450 BrowsingDataRemover::REMOVE_WEBSQL,
1451 false);
1453 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1454 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1455 BrowsingDataRemover::REMOVE_INDEXEDDB |
1456 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1457 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1459 // Verify storage partition related stuffs.
1460 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1462 EXPECT_EQ(removal_data.remove_mask,
1463 static_cast<uint32>(
1464 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1465 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1466 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1467 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1468 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1469 static_cast<uint32>(
1470 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1471 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1473 // Check that extension and devtools data wouldn't be removed, that is,
1474 // origin matcher would not match these origin.
1475 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy));
1476 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy));
1479 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) {
1480 RemoveHistoryTester tester;
1481 ASSERT_TRUE(tester.Init(GetProfile()));
1483 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1485 tester.AddHistory(kOrigin1, base::Time::Now());
1486 tester.AddHistory(kOrigin2, two_hours_ago);
1487 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1488 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1490 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1491 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1493 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1494 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1496 // Nothing should have been deleted.
1497 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1498 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2));
1501 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
1502 RemoveHistoryTester tester;
1503 ASSERT_TRUE(tester.Init(GetProfile()));
1505 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1507 tester.AddHistory(kOrigin1, base::Time::Now());
1508 tester.AddHistory(kOrigin2, two_hours_ago);
1509 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1510 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1512 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
1513 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1515 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1516 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1517 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1518 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1521 // Verify that clearing autofill form data works.
1522 TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) {
1523 GetProfile()->CreateWebDataService();
1524 RemoveAutofillTester tester(GetProfile());
1526 ASSERT_FALSE(tester.HasProfile());
1527 tester.AddProfilesAndCards();
1528 ASSERT_TRUE(tester.HasProfile());
1530 BlockUntilBrowsingDataRemoved(
1531 BrowsingDataRemover::LAST_HOUR,
1532 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1534 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1535 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1536 ASSERT_FALSE(tester.HasProfile());
1539 TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) {
1540 GetProfile()->CreateWebDataService();
1541 RemoveAutofillTester tester(GetProfile());
1543 ASSERT_FALSE(tester.HasProfile());
1544 tester.AddProfilesAndCards();
1545 ASSERT_TRUE(tester.HasProfile());
1547 BlockUntilBrowsingDataRemoved(
1548 BrowsingDataRemover::EVERYTHING,
1549 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1551 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1552 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1553 ASSERT_FALSE(tester.HasProfile());
1556 // Verify that clearing autofill form data works.
1557 TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) {
1558 GetProfile()->CreateWebDataService();
1559 RemoveAutofillTester tester(GetProfile());
1561 tester.AddProfilesAndCards();
1562 EXPECT_FALSE(tester.HasOrigin(std::string()));
1563 EXPECT_TRUE(tester.HasOrigin(kWebOrigin));
1564 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1566 BlockUntilBrowsingDataRemoved(
1567 BrowsingDataRemover::LAST_HOUR,
1568 BrowsingDataRemover::REMOVE_HISTORY, false);
1570 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1571 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1572 EXPECT_TRUE(tester.HasOrigin(std::string()));
1573 EXPECT_FALSE(tester.HasOrigin(kWebOrigin));
1574 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1577 #if defined(OS_CHROMEOS)
1578 TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) {
1579 chromeos::ScopedTestDeviceSettingsService test_device_settings_service;
1580 chromeos::ScopedTestCrosSettings test_cros_settings;
1581 chromeos::MockUserManager* mock_user_manager =
1582 new testing::NiceMock<chromeos::MockUserManager>();
1583 mock_user_manager->SetActiveUser("test@example.com");
1584 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager);
1586 chromeos::FakeDBusThreadManager* fake_dbus_manager =
1587 new chromeos::FakeDBusThreadManager;
1588 chromeos::MockCryptohomeClient* cryptohome_client =
1589 new chromeos::MockCryptohomeClient;
1590 fake_dbus_manager->SetCryptohomeClient(
1591 scoped_ptr<chromeos::CryptohomeClient>(cryptohome_client));
1592 chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_manager);
1594 // Expect exactly one call. No calls means no attempt to delete keys and more
1595 // than one call means a significant performance problem.
1596 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
1597 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
1599 BlockUntilBrowsingDataRemoved(
1600 BrowsingDataRemover::EVERYTHING,
1601 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false);
1603 chromeos::DBusThreadManager::Shutdown();
1605 #endif