EME test page application.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_remover_unittest.cc
blob349ae04b1bda62422d0a3c60c66d8ee5394520a7
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/prefs/testing_pref_service.h"
17 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/browser/autofill/personal_data_manager_factory.h"
19 #include "chrome/browser/browsing_data/browsing_data_helper.h"
20 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
21 #include "chrome/browser/chrome_notification_types.h"
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
24 #include "chrome/browser/chromeos/login/users/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 "components/domain_reliability/clear_mode.h"
46 #include "components/domain_reliability/monitor.h"
47 #include "content/public/browser/cookie_store_factory.h"
48 #include "content/public/browser/dom_storage_context.h"
49 #include "content/public/browser/local_storage_usage_info.h"
50 #include "content/public/browser/notification_service.h"
51 #include "content/public/browser/storage_partition.h"
52 #include "content/public/test/test_browser_thread.h"
53 #include "content/public/test/test_browser_thread_bundle.h"
54 #include "content/public/test/test_utils.h"
55 #include "net/cookies/cookie_store.h"
56 #include "net/ssl/server_bound_cert_service.h"
57 #include "net/ssl/server_bound_cert_store.h"
58 #include "net/ssl/ssl_client_cert_type.h"
59 #include "net/url_request/url_request_context.h"
60 #include "net/url_request/url_request_context_getter.h"
61 #include "testing/gmock/include/gmock/gmock.h"
62 #include "testing/gtest/include/gtest/gtest.h"
64 using content::BrowserThread;
65 using content::StoragePartition;
66 using domain_reliability::CLEAR_BEACONS;
67 using domain_reliability::CLEAR_CONTEXTS;
68 using domain_reliability::DomainReliabilityClearMode;
69 using domain_reliability::DomainReliabilityMonitor;
70 using testing::_;
71 using testing::Invoke;
72 using testing::WithArgs;
74 namespace {
76 const char kTestOrigin1[] = "http://host1:1/";
77 const char kTestOrigin2[] = "http://host2:1/";
78 const char kTestOrigin3[] = "http://host3:1/";
79 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
80 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
82 // For Autofill.
83 const char kChromeOrigin[] = "Chrome settings";
84 const char kWebOrigin[] = "https://www.example.com/";
86 const GURL kOrigin1(kTestOrigin1);
87 const GURL kOrigin2(kTestOrigin2);
88 const GURL kOrigin3(kTestOrigin3);
89 const GURL kOriginExt(kTestOriginExt);
90 const GURL kOriginDevTools(kTestOriginDevTools);
92 const base::FilePath::CharType kDomStorageOrigin1[] =
93 FILE_PATH_LITERAL("http_host1_1.localstorage");
95 const base::FilePath::CharType kDomStorageOrigin2[] =
96 FILE_PATH_LITERAL("http_host2_1.localstorage");
98 const base::FilePath::CharType kDomStorageOrigin3[] =
99 FILE_PATH_LITERAL("http_host3_1.localstorage");
101 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL(
102 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
104 #if defined(OS_CHROMEOS)
105 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
106 base::MessageLoop::current()->PostTask(
107 FROM_HERE,
108 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true));
110 #endif
112 struct StoragePartitionRemovalData {
113 uint32 remove_mask;
114 uint32 quota_storage_remove_mask;
115 GURL remove_origin;
116 base::Time remove_begin;
117 base::Time remove_end;
118 StoragePartition::OriginMatcherFunction origin_matcher;
120 StoragePartitionRemovalData() : remove_mask(0),
121 quota_storage_remove_mask(0) {}
124 class TestStoragePartition : public StoragePartition {
125 public:
126 TestStoragePartition() {}
127 virtual ~TestStoragePartition() {}
129 // content::StoragePartition implementation.
130 virtual base::FilePath GetPath() OVERRIDE { return base::FilePath(); }
131 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE {
132 return NULL;
134 virtual net::URLRequestContextGetter* GetMediaURLRequestContext() OVERRIDE {
135 return NULL;
137 virtual quota::QuotaManager* GetQuotaManager() OVERRIDE {
138 return NULL;
140 virtual appcache::AppCacheService* GetAppCacheService() OVERRIDE {
141 return NULL;
143 virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE {
144 return NULL;
146 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE {
147 return NULL;
149 virtual content::DOMStorageContext* GetDOMStorageContext() OVERRIDE {
150 return NULL;
152 virtual content::IndexedDBContext* GetIndexedDBContext() OVERRIDE {
153 return NULL;
155 virtual content::ServiceWorkerContext* GetServiceWorkerContext() OVERRIDE {
156 return NULL;
159 virtual void ClearDataForOrigin(
160 uint32 remove_mask,
161 uint32 quota_storage_remove_mask,
162 const GURL& storage_origin,
163 net::URLRequestContextGetter* rq_context) OVERRIDE {}
165 virtual void ClearData(uint32 remove_mask,
166 uint32 quota_storage_remove_mask,
167 const GURL& storage_origin,
168 const OriginMatcherFunction& origin_matcher,
169 const base::Time begin,
170 const base::Time end,
171 const base::Closure& callback) OVERRIDE {
172 // Store stuff to verify parameters' correctness later.
173 storage_partition_removal_data_.remove_mask = remove_mask;
174 storage_partition_removal_data_.quota_storage_remove_mask =
175 quota_storage_remove_mask;
176 storage_partition_removal_data_.remove_origin = storage_origin;
177 storage_partition_removal_data_.remove_begin = begin;
178 storage_partition_removal_data_.remove_end = end;
179 storage_partition_removal_data_.origin_matcher = origin_matcher;
181 BrowserThread::PostTask(
182 BrowserThread::UI,
183 FROM_HERE,
184 base::Bind(&TestStoragePartition::AsyncRunCallback,
185 base::Unretained(this), callback));
188 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
189 return storage_partition_removal_data_;
191 private:
192 void AsyncRunCallback(const base::Closure& callback) {
193 callback.Run();
196 StoragePartitionRemovalData storage_partition_removal_data_;
198 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition);
201 } // namespace
203 // Testers -------------------------------------------------------------------
205 class RemoveCookieTester {
206 public:
207 RemoveCookieTester() : get_cookie_success_(false), cookie_store_(NULL) {
210 // Returns true, if the given cookie exists in the cookie store.
211 bool ContainsCookie() {
212 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
213 new content::MessageLoopRunner;
214 quit_closure_ = message_loop_runner->QuitClosure();
215 get_cookie_success_ = false;
216 cookie_store_->GetCookiesWithOptionsAsync(
217 kOrigin1, net::CookieOptions(),
218 base::Bind(&RemoveCookieTester::GetCookieCallback,
219 base::Unretained(this)));
220 message_loop_runner->Run();
221 return get_cookie_success_;
224 void AddCookie() {
225 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
226 new content::MessageLoopRunner;
227 quit_closure_ = message_loop_runner->QuitClosure();
228 cookie_store_->SetCookieWithOptionsAsync(
229 kOrigin1, "A=1", net::CookieOptions(),
230 base::Bind(&RemoveCookieTester::SetCookieCallback,
231 base::Unretained(this)));
232 message_loop_runner->Run();
235 protected:
236 void SetMonster(net::CookieStore* monster) {
237 cookie_store_ = monster;
240 private:
241 void GetCookieCallback(const std::string& cookies) {
242 if (cookies == "A=1") {
243 get_cookie_success_ = true;
244 } else {
245 EXPECT_EQ("", cookies);
246 get_cookie_success_ = false;
248 quit_closure_.Run();
251 void SetCookieCallback(bool result) {
252 ASSERT_TRUE(result);
253 quit_closure_.Run();
256 bool get_cookie_success_;
257 base::Closure quit_closure_;
258 net::CookieStore* cookie_store_;
260 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
263 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
264 class RemoveSafeBrowsingCookieTester : public RemoveCookieTester {
265 public:
266 RemoveSafeBrowsingCookieTester()
267 : browser_process_(TestingBrowserProcess::GetGlobal()) {
268 scoped_refptr<SafeBrowsingService> sb_service =
269 SafeBrowsingService::CreateSafeBrowsingService();
270 browser_process_->SetSafeBrowsingService(sb_service.get());
271 sb_service->Initialize();
272 base::MessageLoop::current()->RunUntilIdle();
274 // Create a cookiemonster that does not have persistant storage, and replace
275 // the SafeBrowsingService created one with it.
276 net::CookieStore* monster =
277 content::CreateCookieStore(content::CookieStoreConfig());
278 sb_service->url_request_context()->GetURLRequestContext()->
279 set_cookie_store(monster);
280 SetMonster(monster);
283 virtual ~RemoveSafeBrowsingCookieTester() {
284 browser_process_->safe_browsing_service()->ShutDown();
285 base::MessageLoop::current()->RunUntilIdle();
286 browser_process_->SetSafeBrowsingService(NULL);
289 private:
290 TestingBrowserProcess* browser_process_;
292 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
294 #endif
296 class RemoveServerBoundCertTester : public net::SSLConfigService::Observer {
297 public:
298 explicit RemoveServerBoundCertTester(TestingProfile* profile)
299 : ssl_config_changed_count_(0) {
300 server_bound_cert_service_ = profile->GetRequestContext()->
301 GetURLRequestContext()->server_bound_cert_service();
302 ssl_config_service_ = profile->GetSSLConfigService();
303 ssl_config_service_->AddObserver(this);
306 virtual ~RemoveServerBoundCertTester() {
307 ssl_config_service_->RemoveObserver(this);
310 int ServerBoundCertCount() {
311 return server_bound_cert_service_->cert_count();
314 // Add a server bound cert for |server| with specific creation and expiry
315 // times. The cert and key data will be filled with dummy values.
316 void AddServerBoundCertWithTimes(const std::string& server_identifier,
317 base::Time creation_time,
318 base::Time expiration_time) {
319 GetCertStore()->SetServerBoundCert(server_identifier,
320 creation_time,
321 expiration_time,
322 "a",
323 "b");
326 // Add a server bound cert for |server|, with the current time as the
327 // creation time. The cert and key data will be filled with dummy values.
328 void AddServerBoundCert(const std::string& server_identifier) {
329 base::Time now = base::Time::Now();
330 AddServerBoundCertWithTimes(server_identifier,
331 now,
332 now + base::TimeDelta::FromDays(1));
335 void GetCertList(net::ServerBoundCertStore::ServerBoundCertList* certs) {
336 GetCertStore()->GetAllServerBoundCerts(
337 base::Bind(&RemoveServerBoundCertTester::GetAllCertsCallback, certs));
340 net::ServerBoundCertStore* GetCertStore() {
341 return server_bound_cert_service_->GetCertStore();
344 int ssl_config_changed_count() const {
345 return ssl_config_changed_count_;
348 // net::SSLConfigService::Observer implementation:
349 virtual void OnSSLConfigChanged() OVERRIDE {
350 ssl_config_changed_count_++;
353 private:
354 static void GetAllCertsCallback(
355 net::ServerBoundCertStore::ServerBoundCertList* dest,
356 const net::ServerBoundCertStore::ServerBoundCertList& result) {
357 *dest = result;
360 net::ServerBoundCertService* server_bound_cert_service_;
361 scoped_refptr<net::SSLConfigService> ssl_config_service_;
362 int ssl_config_changed_count_;
364 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester);
367 class RemoveHistoryTester {
368 public:
369 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {}
371 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
372 if (!profile->CreateHistoryService(true, false))
373 return false;
374 history_service_ = HistoryServiceFactory::GetForProfile(
375 profile, Profile::EXPLICIT_ACCESS);
376 return true;
379 // Returns true, if the given URL exists in the history service.
380 bool HistoryContainsURL(const GURL& url) {
381 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
382 new content::MessageLoopRunner;
383 quit_closure_ = message_loop_runner->QuitClosure();
384 history_service_->QueryURL(
385 url,
386 true,
387 &consumer_,
388 base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
389 base::Unretained(this)));
390 message_loop_runner->Run();
391 return query_url_success_;
394 void AddHistory(const GURL& url, base::Time time) {
395 history_service_->AddPage(url, time, NULL, 0, GURL(),
396 history::RedirectList(), content::PAGE_TRANSITION_LINK,
397 history::SOURCE_BROWSED, false);
400 private:
401 // Callback for HistoryService::QueryURL.
402 void SaveResultAndQuit(HistoryService::Handle,
403 bool success,
404 const history::URLRow*,
405 history::VisitVector*) {
406 query_url_success_ = success;
407 quit_closure_.Run();
410 // For History requests.
411 CancelableRequestConsumer consumer_;
412 bool query_url_success_;
413 base::Closure quit_closure_;
415 // TestingProfile owns the history service; we shouldn't delete it.
416 HistoryService* history_service_;
418 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
421 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
422 public:
423 explicit RemoveAutofillTester(TestingProfile* profile)
424 : personal_data_manager_(
425 autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
426 autofill::test::DisableSystemServices(profile->GetPrefs());
427 personal_data_manager_->AddObserver(this);
430 virtual ~RemoveAutofillTester() {
431 personal_data_manager_->RemoveObserver(this);
434 // Returns true if there are autofill profiles.
435 bool HasProfile() {
436 return !personal_data_manager_->GetProfiles().empty() &&
437 !personal_data_manager_->GetCreditCards().empty();
440 bool HasOrigin(const std::string& origin) {
441 const std::vector<autofill::AutofillProfile*>& profiles =
442 personal_data_manager_->GetProfiles();
443 for (std::vector<autofill::AutofillProfile*>::const_iterator it =
444 profiles.begin();
445 it != profiles.end(); ++it) {
446 if ((*it)->origin() == origin)
447 return true;
450 const std::vector<autofill::CreditCard*>& credit_cards =
451 personal_data_manager_->GetCreditCards();
452 for (std::vector<autofill::CreditCard*>::const_iterator it =
453 credit_cards.begin();
454 it != credit_cards.end(); ++it) {
455 if ((*it)->origin() == origin)
456 return true;
459 return false;
462 // Add two profiles and two credit cards to the database. In each pair, one
463 // entry has a web origin and the other has a Chrome origin.
464 void AddProfilesAndCards() {
465 std::vector<autofill::AutofillProfile> profiles;
466 autofill::AutofillProfile profile;
467 profile.set_guid(base::GenerateGUID());
468 profile.set_origin(kWebOrigin);
469 profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
470 profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
471 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
472 profile.SetRawInfo(autofill::EMAIL_ADDRESS,
473 base::ASCIIToUTF16("sue@example.com"));
474 profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
475 profiles.push_back(profile);
477 profile.set_guid(base::GenerateGUID());
478 profile.set_origin(kChromeOrigin);
479 profiles.push_back(profile);
481 personal_data_manager_->SetProfiles(&profiles);
482 base::MessageLoop::current()->Run();
484 std::vector<autofill::CreditCard> cards;
485 autofill::CreditCard card;
486 card.set_guid(base::GenerateGUID());
487 card.set_origin(kWebOrigin);
488 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
489 base::ASCIIToUTF16("1234-5678-9012-3456"));
490 cards.push_back(card);
492 card.set_guid(base::GenerateGUID());
493 card.set_origin(kChromeOrigin);
494 cards.push_back(card);
496 personal_data_manager_->SetCreditCards(&cards);
497 base::MessageLoop::current()->Run();
500 private:
501 virtual void OnPersonalDataChanged() OVERRIDE {
502 base::MessageLoop::current()->Quit();
505 autofill::PersonalDataManager* personal_data_manager_;
506 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
509 class RemoveLocalStorageTester {
510 public:
511 explicit RemoveLocalStorageTester(TestingProfile* profile)
512 : profile_(profile), dom_storage_context_(NULL) {
513 dom_storage_context_ =
514 content::BrowserContext::GetDefaultStoragePartition(profile)->
515 GetDOMStorageContext();
518 // Returns true, if the given origin URL exists.
519 bool DOMStorageExistsForOrigin(const GURL& origin) {
520 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
521 new content::MessageLoopRunner;
522 quit_closure_ = message_loop_runner->QuitClosure();
523 GetLocalStorageUsage();
524 message_loop_runner->Run();
525 for (size_t i = 0; i < infos_.size(); ++i) {
526 if (origin == infos_[i].origin)
527 return true;
529 return false;
532 void AddDOMStorageTestData() {
533 // Note: This test depends on details of how the dom_storage library
534 // stores data in the host file system.
535 base::FilePath storage_path =
536 profile_->GetPath().AppendASCII("Local Storage");
537 base::CreateDirectory(storage_path);
539 // Write some files.
540 base::WriteFile(storage_path.Append(kDomStorageOrigin1), NULL, 0);
541 base::WriteFile(storage_path.Append(kDomStorageOrigin2), NULL, 0);
542 base::WriteFile(storage_path.Append(kDomStorageOrigin3), NULL, 0);
543 base::WriteFile(storage_path.Append(kDomStorageExt), NULL, 0);
545 // Tweak their dates.
546 base::Time now = base::Time::Now();
547 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
549 base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
550 base::TouchFile(storage_path.Append(kDomStorageOrigin2),
551 one_day_ago, one_day_ago);
553 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
554 base::TouchFile(storage_path.Append(kDomStorageOrigin3),
555 sixty_days_ago, sixty_days_ago);
557 base::TouchFile(storage_path.Append(kDomStorageExt), now, now);
560 private:
561 void GetLocalStorageUsage() {
562 dom_storage_context_->GetLocalStorageUsage(
563 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage,
564 base::Unretained(this)));
566 void OnGotLocalStorageUsage(
567 const std::vector<content::LocalStorageUsageInfo>& infos) {
568 infos_ = infos;
569 quit_closure_.Run();
572 // We don't own these pointers.
573 TestingProfile* profile_;
574 content::DOMStorageContext* dom_storage_context_;
576 std::vector<content::LocalStorageUsageInfo> infos_;
577 base::Closure quit_closure_;
579 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
582 class TestingProfileWithDomainReliabilityMonitor : public TestingProfile {
583 public:
584 TestingProfileWithDomainReliabilityMonitor() :
585 TestingProfile(),
586 upload_reporter_string_("test-reporter"),
587 monitor_(GetRequestContext()->GetURLRequestContext(),
588 upload_reporter_string_) {}
590 virtual void ClearDomainReliabilityMonitor(
591 DomainReliabilityClearMode mode,
592 const base::Closure& completion) OVERRIDE {
593 monitor_.ClearBrowsingData(mode);
594 completion.Run();
597 DomainReliabilityMonitor* monitor() { return &monitor_; }
599 private:
600 std::string upload_reporter_string_;
601 DomainReliabilityMonitor monitor_;
604 // Test Class ----------------------------------------------------------------
606 class BrowsingDataRemoverTest : public testing::Test,
607 public content::NotificationObserver {
608 public:
609 BrowsingDataRemoverTest()
610 : profile_(new TestingProfile()) {
611 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
612 content::Source<Profile>(profile_.get()));
615 virtual ~BrowsingDataRemoverTest() {
618 virtual void TearDown() {
619 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
620 // posts a message to the WEBKIT thread to delete some of its member
621 // variables. We need to ensure that the profile is destroyed, and that
622 // the message loop is cleared out, before destroying the threads and loop.
623 // Otherwise we leak memory.
624 profile_.reset();
625 base::MessageLoop::current()->RunUntilIdle();
628 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period,
629 int remove_mask,
630 bool include_protected_origins) {
631 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
632 profile_.get(), period);
634 TestStoragePartition storage_partition;
635 remover->OverrideStoragePartitionForTesting(&storage_partition);
637 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
639 // BrowsingDataRemover deletes itself when it completes.
640 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB;
641 if (include_protected_origins)
642 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB;
644 BrowsingDataRemoverCompletionObserver completion_observer(remover);
645 remover->Remove(remove_mask, origin_set_mask);
646 completion_observer.BlockUntilCompletion();
648 // Save so we can verify later.
649 storage_partition_removal_data_ =
650 storage_partition.GetStoragePartitionRemovalData();
653 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period,
654 int remove_mask,
655 const GURL& remove_origin) {
656 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
657 profile_.get(), period);
658 TestStoragePartition storage_partition;
659 remover->OverrideStoragePartitionForTesting(&storage_partition);
661 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
663 // BrowsingDataRemover deletes itself when it completes.
664 BrowsingDataRemoverCompletionObserver completion_observer(remover);
665 remover->RemoveImpl(remove_mask, remove_origin,
666 BrowsingDataHelper::UNPROTECTED_WEB);
667 completion_observer.BlockUntilCompletion();
669 // Save so we can verify later.
670 storage_partition_removal_data_ =
671 storage_partition.GetStoragePartitionRemovalData();
674 TestingProfile* GetProfile() {
675 return profile_.get();
678 base::Time GetBeginTime() {
679 return called_with_details_->removal_begin;
682 int GetRemovalMask() {
683 return called_with_details_->removal_mask;
686 int GetOriginSetMask() {
687 return called_with_details_->origin_set_mask;
690 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
691 return storage_partition_removal_data_;
694 // content::NotificationObserver implementation.
695 virtual void Observe(int type,
696 const content::NotificationSource& source,
697 const content::NotificationDetails& details) OVERRIDE {
698 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED);
700 // We're not taking ownership of the details object, but storing a copy of
701 // it locally.
702 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails(
703 *content::Details<BrowsingDataRemover::NotificationDetails>(
704 details).ptr()));
706 registrar_.RemoveAll();
709 DomainReliabilityMonitor *UseProfileWithDomainReliabilityMonitor() {
710 TestingProfileWithDomainReliabilityMonitor* new_profile =
711 new TestingProfileWithDomainReliabilityMonitor();
712 DomainReliabilityMonitor* monitor = new_profile->monitor();
713 profile_.reset(new_profile);
714 return monitor;
717 protected:
718 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
720 private:
721 content::NotificationRegistrar registrar_;
723 content::TestBrowserThreadBundle thread_bundle_;
724 scoped_ptr<TestingProfile> profile_;
726 StoragePartitionRemovalData storage_partition_removal_data_;
728 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
731 // Tests ---------------------------------------------------------------------
733 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
734 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
735 BrowsingDataRemover::REMOVE_COOKIES,
736 false);
738 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
739 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
741 // Verify that storage partition was instructed to remove the cookies.
742 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
743 EXPECT_EQ(removal_data.remove_mask,
744 static_cast<uint32>(
745 StoragePartition::REMOVE_DATA_MASK_COOKIES));
746 EXPECT_EQ(removal_data.quota_storage_remove_mask,
747 static_cast<uint32>(
748 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
749 EXPECT_TRUE(removal_data.remove_origin.is_empty());
750 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
753 TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) {
754 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
755 BrowsingDataRemover::REMOVE_COOKIES,
756 false);
758 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
759 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
761 // Verify that storage partition was instructed to remove the cookies.
762 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
763 EXPECT_EQ(removal_data.remove_mask,
764 static_cast<uint32>(
765 StoragePartition::REMOVE_DATA_MASK_COOKIES));
766 // Removing with time period other than EVERYTHING should not clear
767 // persistent storage data.
768 EXPECT_EQ(removal_data.quota_storage_remove_mask,
769 static_cast<uint32>(
770 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL &
771 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT));
772 EXPECT_TRUE(removal_data.remove_origin.is_empty());
773 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
776 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
777 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) {
778 RemoveSafeBrowsingCookieTester tester;
780 tester.AddCookie();
781 ASSERT_TRUE(tester.ContainsCookie());
783 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
784 BrowsingDataRemover::REMOVE_COOKIES, false);
786 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
787 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
788 EXPECT_FALSE(tester.ContainsCookie());
791 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) {
792 RemoveSafeBrowsingCookieTester tester;
794 tester.AddCookie();
795 ASSERT_TRUE(tester.ContainsCookie());
797 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
798 BrowsingDataRemover::REMOVE_COOKIES, false);
800 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
801 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
802 // Removing with time period other than EVERYTHING should not clear safe
803 // browsing cookies.
804 EXPECT_TRUE(tester.ContainsCookie());
806 #endif
808 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertForever) {
809 RemoveServerBoundCertTester tester(GetProfile());
811 tester.AddServerBoundCert(kTestOrigin1);
812 EXPECT_EQ(0, tester.ssl_config_changed_count());
813 EXPECT_EQ(1, tester.ServerBoundCertCount());
815 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
816 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false);
818 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask());
819 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
820 EXPECT_EQ(1, tester.ssl_config_changed_count());
821 EXPECT_EQ(0, tester.ServerBoundCertCount());
824 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertLastHour) {
825 RemoveServerBoundCertTester tester(GetProfile());
827 base::Time now = base::Time::Now();
828 tester.AddServerBoundCert(kTestOrigin1);
829 tester.AddServerBoundCertWithTimes(kTestOrigin2,
830 now - base::TimeDelta::FromHours(2),
831 now);
832 EXPECT_EQ(0, tester.ssl_config_changed_count());
833 EXPECT_EQ(2, tester.ServerBoundCertCount());
835 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
836 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false);
838 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask());
839 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
840 EXPECT_EQ(1, tester.ssl_config_changed_count());
841 ASSERT_EQ(1, tester.ServerBoundCertCount());
842 net::ServerBoundCertStore::ServerBoundCertList certs;
843 tester.GetCertList(&certs);
844 ASSERT_EQ(1U, certs.size());
845 EXPECT_EQ(kTestOrigin2, certs.front().server_identifier());
848 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) {
849 // Protect kOrigin1.
850 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
851 new MockExtensionSpecialStoragePolicy;
852 mock_policy->AddProtected(kOrigin1.GetOrigin());
853 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
855 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
856 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
857 false);
859 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
860 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
862 // Verify that storage partition was instructed to remove the data correctly.
863 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
864 EXPECT_EQ(removal_data.remove_mask,
865 static_cast<uint32>(
866 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE));
867 EXPECT_EQ(removal_data.quota_storage_remove_mask,
868 static_cast<uint32>(
869 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
870 EXPECT_TRUE(removal_data.remove_origin.is_empty());
871 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
873 // Check origin matcher.
874 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
875 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
876 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
877 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy));
880 TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) {
881 // Protect kOrigin1.
882 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
883 new MockExtensionSpecialStoragePolicy;
884 mock_policy->AddProtected(kOrigin1.GetOrigin());
885 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
887 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
888 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
889 true);
891 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
892 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB |
893 BrowsingDataHelper::PROTECTED_WEB, GetOriginSetMask());
895 // Verify that storage partition was instructed to remove the data correctly.
896 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
897 EXPECT_EQ(removal_data.remove_mask,
898 static_cast<uint32>(
899 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE));
900 EXPECT_EQ(removal_data.quota_storage_remove_mask,
901 static_cast<uint32>(
902 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
903 EXPECT_TRUE(removal_data.remove_origin.is_empty());
904 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
906 // Check origin matcher all http origin will match since we specified
907 // both protected and unprotected.
908 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
909 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
910 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
911 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy));
914 TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) {
915 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
916 new MockExtensionSpecialStoragePolicy;
917 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
919 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
920 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
921 false);
923 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
924 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
926 // Verify that storage partition was instructed to remove the data correctly.
927 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
928 EXPECT_EQ(removal_data.remove_mask,
929 static_cast<uint32>(
930 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE));
931 // Persistent storage won't be deleted.
932 EXPECT_EQ(removal_data.quota_storage_remove_mask,
933 static_cast<uint32>(
934 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL &
935 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT));
936 EXPECT_TRUE(removal_data.remove_origin.is_empty());
937 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
939 // Check origin matcher.
940 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
941 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
942 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
943 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy));
946 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
947 RemoveHistoryTester tester;
948 ASSERT_TRUE(tester.Init(GetProfile()));
950 tester.AddHistory(kOrigin1, base::Time::Now());
951 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
953 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
954 BrowsingDataRemover::REMOVE_HISTORY, false);
956 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
957 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
958 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
961 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
962 RemoveHistoryTester tester;
963 ASSERT_TRUE(tester.Init(GetProfile()));
965 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
967 tester.AddHistory(kOrigin1, base::Time::Now());
968 tester.AddHistory(kOrigin2, two_hours_ago);
969 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
970 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
972 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
973 BrowsingDataRemover::REMOVE_HISTORY, false);
975 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
976 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
977 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
978 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
981 // This should crash (DCHECK) in Debug, but death tests don't work properly
982 // here.
983 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
984 TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
985 RemoveHistoryTester tester;
986 ASSERT_TRUE(tester.Init(GetProfile()));
987 PrefService* prefs = GetProfile()->GetPrefs();
988 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
990 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
992 tester.AddHistory(kOrigin1, base::Time::Now());
993 tester.AddHistory(kOrigin2, two_hours_ago);
994 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
995 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
997 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
998 BrowsingDataRemover::REMOVE_HISTORY, false);
999 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1000 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1002 // Nothing should have been deleted.
1003 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1004 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1006 #endif
1008 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) {
1009 // Add some history.
1010 RemoveHistoryTester history_tester;
1011 ASSERT_TRUE(history_tester.Init(GetProfile()));
1012 history_tester.AddHistory(kOrigin1, base::Time::Now());
1013 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1015 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1016 BrowsingDataRemover::REMOVE_COOKIES;
1018 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1019 removal_mask, false);
1021 EXPECT_EQ(removal_mask, GetRemovalMask());
1022 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1023 EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1));
1025 // The cookie would be deleted throught the StorageParition, check if the
1026 // partition was requested to remove cookie.
1027 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1028 EXPECT_EQ(removal_data.remove_mask,
1029 static_cast<uint32>(
1030 StoragePartition::REMOVE_DATA_MASK_COOKIES));
1031 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1032 static_cast<uint32>(
1033 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1036 // This should crash (DCHECK) in Debug, but death tests don't work properly
1037 // here.
1038 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1039 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
1040 PrefService* prefs = GetProfile()->GetPrefs();
1041 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1043 // Add some history.
1044 RemoveHistoryTester history_tester;
1045 ASSERT_TRUE(history_tester.Init(GetProfile()));
1046 history_tester.AddHistory(kOrigin1, base::Time::Now());
1047 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1049 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1050 BrowsingDataRemover::REMOVE_COOKIES;
1052 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1053 removal_mask, false);
1054 EXPECT_EQ(removal_mask, GetRemovalMask());
1055 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1057 // 1/2. History should remain.
1058 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1060 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if
1061 // the partition was requested to remove cookie.
1062 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1063 EXPECT_EQ(removal_data.remove_mask,
1064 static_cast<uint32>(
1065 StoragePartition::REMOVE_DATA_MASK_COOKIES));
1066 // Persistent storage won't be deleted, since EVERYTHING was not specified.
1067 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1068 static_cast<uint32>(
1069 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL &
1070 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT));
1072 #endif
1074 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
1075 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1076 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1077 BrowsingDataRemover::REMOVE_WEBSQL |
1078 BrowsingDataRemover::REMOVE_APPCACHE |
1079 BrowsingDataRemover::REMOVE_INDEXEDDB,
1080 false);
1082 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1083 BrowsingDataRemover::REMOVE_WEBSQL |
1084 BrowsingDataRemover::REMOVE_APPCACHE |
1085 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1086 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1088 // Verify storage partition related stuffs.
1089 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1090 EXPECT_EQ(removal_data.remove_mask,
1091 static_cast<uint32>(
1092 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1093 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1094 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1095 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1096 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1097 static_cast<uint32>(
1098 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1099 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1102 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
1103 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1104 new MockExtensionSpecialStoragePolicy;
1105 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1107 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1108 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1109 BrowsingDataRemover::REMOVE_WEBSQL |
1110 BrowsingDataRemover::REMOVE_APPCACHE |
1111 BrowsingDataRemover::REMOVE_INDEXEDDB,
1112 false);
1114 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1115 BrowsingDataRemover::REMOVE_WEBSQL |
1116 BrowsingDataRemover::REMOVE_APPCACHE |
1117 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1118 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1120 // Verify storage partition related stuffs.
1121 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1123 EXPECT_EQ(removal_data.remove_mask,
1124 static_cast<uint32>(
1125 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1126 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1127 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1128 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1129 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1130 static_cast<uint32>(
1131 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1132 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1134 // Check that all related origin data would be removed, that is, origin
1135 // matcher would match these origin.
1136 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1137 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1138 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1141 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
1142 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1143 new MockExtensionSpecialStoragePolicy;
1144 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1146 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1147 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1148 BrowsingDataRemover::REMOVE_WEBSQL |
1149 BrowsingDataRemover::REMOVE_APPCACHE |
1150 BrowsingDataRemover::REMOVE_INDEXEDDB,
1151 false);
1153 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1154 BrowsingDataRemover::REMOVE_WEBSQL |
1155 BrowsingDataRemover::REMOVE_APPCACHE |
1156 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1157 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1159 // Verify storage partition related stuffs.
1160 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1162 EXPECT_EQ(removal_data.remove_mask,
1163 static_cast<uint32>(
1164 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1165 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1166 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1167 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1168 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1169 static_cast<uint32>(
1170 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1171 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1173 // Check that all related origin data would be removed, that is, origin
1174 // matcher would match these origin.
1175 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1176 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1177 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1180 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
1181 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1182 new MockExtensionSpecialStoragePolicy;
1183 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1186 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1187 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1188 BrowsingDataRemover::REMOVE_WEBSQL |
1189 BrowsingDataRemover::REMOVE_APPCACHE |
1190 BrowsingDataRemover::REMOVE_INDEXEDDB,
1191 false);
1193 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1194 BrowsingDataRemover::REMOVE_WEBSQL |
1195 BrowsingDataRemover::REMOVE_APPCACHE |
1196 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1197 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1199 // Verify storage partition related stuffs.
1200 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1202 EXPECT_EQ(removal_data.remove_mask,
1203 static_cast<uint32>(
1204 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1205 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1206 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1207 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1208 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1209 static_cast<uint32>(
1210 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1211 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1213 // Check that all related origin data would be removed, that is, origin
1214 // matcher would match these origin.
1215 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1216 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1217 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1220 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
1221 // Remove Origin 1.
1222 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1223 BrowsingDataRemover::REMOVE_APPCACHE |
1224 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1225 BrowsingDataRemover::REMOVE_INDEXEDDB |
1226 BrowsingDataRemover::REMOVE_WEBSQL,
1227 kOrigin1);
1229 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1230 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1231 BrowsingDataRemover::REMOVE_INDEXEDDB |
1232 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1233 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1235 // Verify storage partition related stuffs.
1236 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1238 EXPECT_EQ(removal_data.remove_mask,
1239 static_cast<uint32>(
1240 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1241 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1242 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1243 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1244 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1245 static_cast<uint32>(
1246 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1247 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1250 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
1251 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1252 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1253 BrowsingDataRemover::REMOVE_WEBSQL |
1254 BrowsingDataRemover::REMOVE_APPCACHE |
1255 BrowsingDataRemover::REMOVE_INDEXEDDB,
1256 false);
1258 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1259 BrowsingDataRemover::REMOVE_WEBSQL |
1260 BrowsingDataRemover::REMOVE_APPCACHE |
1261 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1262 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1264 // Verify storage partition related stuffs.
1265 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1267 EXPECT_EQ(removal_data.remove_mask,
1268 static_cast<uint32>(
1269 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1270 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1271 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1272 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1274 // Persistent data would be left out since we are not removing from
1275 // beginning of time.
1276 uint32 expected_quota_mask =
1277 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1278 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1279 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1280 // Check removal begin time.
1281 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1284 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
1285 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
1286 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1287 BrowsingDataRemover::REMOVE_WEBSQL |
1288 BrowsingDataRemover::REMOVE_APPCACHE |
1289 BrowsingDataRemover::REMOVE_INDEXEDDB,
1290 false);
1292 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1293 BrowsingDataRemover::REMOVE_WEBSQL |
1294 BrowsingDataRemover::REMOVE_APPCACHE |
1295 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1296 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1298 // Verify storage partition related stuffs.
1299 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1301 EXPECT_EQ(removal_data.remove_mask,
1302 static_cast<uint32>(
1303 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1304 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1305 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1306 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1308 // Persistent data would be left out since we are not removing from
1309 // beginning of time.
1310 uint32 expected_quota_mask =
1311 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1312 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1313 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1314 // Check removal begin time.
1315 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1318 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
1319 // Protect kOrigin1.
1320 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1321 new MockExtensionSpecialStoragePolicy;
1322 mock_policy->AddProtected(kOrigin1.GetOrigin());
1323 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1325 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1326 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1327 BrowsingDataRemover::REMOVE_WEBSQL |
1328 BrowsingDataRemover::REMOVE_APPCACHE |
1329 BrowsingDataRemover::REMOVE_INDEXEDDB,
1330 false);
1332 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1333 BrowsingDataRemover::REMOVE_WEBSQL |
1334 BrowsingDataRemover::REMOVE_APPCACHE |
1335 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1336 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1338 // Verify storage partition related stuffs.
1339 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1341 EXPECT_EQ(removal_data.remove_mask,
1342 static_cast<uint32>(
1343 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1344 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1345 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1346 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1347 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1348 static_cast<uint32>(
1349 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1350 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1352 // Check OriginMatcherFunction, |kOrigin1| would not match mask since it
1353 // is protected.
1354 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1355 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1356 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1359 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) {
1360 // Protect kOrigin1.
1361 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1362 new MockExtensionSpecialStoragePolicy;
1363 mock_policy->AddProtected(kOrigin1.GetOrigin());
1364 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1366 // Try to remove kOrigin1. Expect failure.
1367 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1368 BrowsingDataRemover::REMOVE_APPCACHE |
1369 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1370 BrowsingDataRemover::REMOVE_INDEXEDDB |
1371 BrowsingDataRemover::REMOVE_WEBSQL,
1372 kOrigin1);
1374 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1375 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1376 BrowsingDataRemover::REMOVE_INDEXEDDB |
1377 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1378 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1380 // Verify storage partition related stuffs.
1381 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1383 EXPECT_EQ(removal_data.remove_mask,
1384 static_cast<uint32>(
1385 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1386 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1387 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1388 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1389 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1390 static_cast<uint32>(
1391 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1392 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1394 // Check OriginMatcherFunction, |kOrigin1| would not match mask since it
1395 // is protected.
1396 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1397 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1398 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1401 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) {
1402 // Protect kOrigin1.
1403 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1404 new MockExtensionSpecialStoragePolicy;
1405 mock_policy->AddProtected(kOrigin1.GetOrigin());
1406 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1408 // Try to remove kOrigin1. Expect success.
1409 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1410 BrowsingDataRemover::REMOVE_APPCACHE |
1411 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1412 BrowsingDataRemover::REMOVE_INDEXEDDB |
1413 BrowsingDataRemover::REMOVE_WEBSQL,
1414 true);
1416 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1417 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1418 BrowsingDataRemover::REMOVE_INDEXEDDB |
1419 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1420 EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB |
1421 BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1423 // Verify storage partition related stuffs.
1424 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1426 EXPECT_EQ(removal_data.remove_mask,
1427 static_cast<uint32>(
1428 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1429 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1430 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1431 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1432 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1433 static_cast<uint32>(
1434 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1435 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1437 // Check OriginMatcherFunction, |kOrigin1| would match mask since we
1438 // would have 'protected' specified in origin_set_mask.
1439 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy));
1440 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy));
1441 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy));
1444 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
1445 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy =
1446 new MockExtensionSpecialStoragePolicy;
1447 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get());
1449 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1450 BrowsingDataRemover::REMOVE_APPCACHE |
1451 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1452 BrowsingDataRemover::REMOVE_INDEXEDDB |
1453 BrowsingDataRemover::REMOVE_WEBSQL,
1454 false);
1456 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1457 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1458 BrowsingDataRemover::REMOVE_INDEXEDDB |
1459 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1460 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1462 // Verify storage partition related stuffs.
1463 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1465 EXPECT_EQ(removal_data.remove_mask,
1466 static_cast<uint32>(
1467 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1468 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1469 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1470 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB));
1471 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1472 static_cast<uint32>(
1473 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL));
1474 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1476 // Check that extension and devtools data wouldn't be removed, that is,
1477 // origin matcher would not match these origin.
1478 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy));
1479 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy));
1482 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) {
1483 RemoveHistoryTester tester;
1484 ASSERT_TRUE(tester.Init(GetProfile()));
1486 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1488 tester.AddHistory(kOrigin1, base::Time::Now());
1489 tester.AddHistory(kOrigin2, two_hours_ago);
1490 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1491 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1493 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1494 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1496 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1497 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1499 // Nothing should have been deleted.
1500 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1501 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2));
1504 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
1505 RemoveHistoryTester tester;
1506 ASSERT_TRUE(tester.Init(GetProfile()));
1508 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1510 tester.AddHistory(kOrigin1, base::Time::Now());
1511 tester.AddHistory(kOrigin2, two_hours_ago);
1512 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1513 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1515 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
1516 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1518 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1519 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1520 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1521 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1524 // Verify that clearing autofill form data works.
1525 TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) {
1526 GetProfile()->CreateWebDataService();
1527 RemoveAutofillTester tester(GetProfile());
1529 ASSERT_FALSE(tester.HasProfile());
1530 tester.AddProfilesAndCards();
1531 ASSERT_TRUE(tester.HasProfile());
1533 BlockUntilBrowsingDataRemoved(
1534 BrowsingDataRemover::LAST_HOUR,
1535 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1537 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1538 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1539 ASSERT_FALSE(tester.HasProfile());
1542 TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) {
1543 GetProfile()->CreateWebDataService();
1544 RemoveAutofillTester tester(GetProfile());
1546 ASSERT_FALSE(tester.HasProfile());
1547 tester.AddProfilesAndCards();
1548 ASSERT_TRUE(tester.HasProfile());
1550 BlockUntilBrowsingDataRemoved(
1551 BrowsingDataRemover::EVERYTHING,
1552 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1554 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1555 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1556 ASSERT_FALSE(tester.HasProfile());
1559 // Verify that clearing autofill form data works.
1560 TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) {
1561 GetProfile()->CreateWebDataService();
1562 RemoveAutofillTester tester(GetProfile());
1564 tester.AddProfilesAndCards();
1565 EXPECT_FALSE(tester.HasOrigin(std::string()));
1566 EXPECT_TRUE(tester.HasOrigin(kWebOrigin));
1567 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1569 BlockUntilBrowsingDataRemoved(
1570 BrowsingDataRemover::LAST_HOUR,
1571 BrowsingDataRemover::REMOVE_HISTORY, false);
1573 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1574 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1575 EXPECT_TRUE(tester.HasOrigin(std::string()));
1576 EXPECT_FALSE(tester.HasOrigin(kWebOrigin));
1577 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1580 TEST_F(BrowsingDataRemoverTest, CompletionInhibition) {
1581 // The |completion_inhibitor| on the stack should prevent removal sessions
1582 // from completing until after ContinueToCompletion() is called.
1583 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
1585 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
1587 // BrowsingDataRemover deletes itself when it completes.
1588 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
1589 GetProfile(), BrowsingDataRemover::EVERYTHING);
1590 remover->Remove(BrowsingDataRemover::REMOVE_HISTORY,
1591 BrowsingDataHelper::UNPROTECTED_WEB);
1593 // Process messages until the inhibitor is notified, and then some, to make
1594 // sure we do not complete asynchronously before ContinueToCompletion() is
1595 // called.
1596 completion_inhibitor.BlockUntilNearCompletion();
1597 base::RunLoop().RunUntilIdle();
1599 // Verify that the completion notification has not yet been broadcasted.
1600 EXPECT_EQ(-1, GetRemovalMask());
1601 EXPECT_EQ(-1, GetOriginSetMask());
1603 // Now run the removal process until completion, and verify that observers are
1604 // now notified, and the notifications is sent out.
1605 BrowsingDataRemoverCompletionObserver completion_observer(remover);
1606 completion_inhibitor.ContinueToCompletion();
1607 completion_observer.BlockUntilCompletion();
1609 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1610 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1613 TEST_F(BrowsingDataRemoverTest, ZeroSuggestCacheClear) {
1614 PrefService* prefs = GetProfile()->GetPrefs();
1615 prefs->SetString(prefs::kZeroSuggestCachedResults,
1616 "[\"\", [\"foo\", \"bar\"]]");
1617 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1618 BrowsingDataRemover::REMOVE_COOKIES,
1619 false);
1621 // Expect the prefs to be cleared when cookies are removed.
1622 EXPECT_TRUE(prefs->GetString(prefs::kZeroSuggestCachedResults).empty());
1623 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1624 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1627 #if defined(OS_CHROMEOS)
1628 TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) {
1629 chromeos::ScopedTestDeviceSettingsService test_device_settings_service;
1630 chromeos::ScopedTestCrosSettings test_cros_settings;
1631 chromeos::MockUserManager* mock_user_manager =
1632 new testing::NiceMock<chromeos::MockUserManager>();
1633 mock_user_manager->SetActiveUser("test@example.com");
1634 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager);
1636 chromeos::FakeDBusThreadManager* fake_dbus_manager =
1637 new chromeos::FakeDBusThreadManager;
1638 chromeos::MockCryptohomeClient* cryptohome_client =
1639 new chromeos::MockCryptohomeClient;
1640 fake_dbus_manager->SetCryptohomeClient(
1641 scoped_ptr<chromeos::CryptohomeClient>(cryptohome_client));
1642 chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_manager);
1644 // Expect exactly one call. No calls means no attempt to delete keys and more
1645 // than one call means a significant performance problem.
1646 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
1647 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
1649 BlockUntilBrowsingDataRemoved(
1650 BrowsingDataRemover::EVERYTHING,
1651 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false);
1653 chromeos::DBusThreadManager::Shutdown();
1655 #endif
1657 TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) {
1658 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1659 EXPECT_FALSE(monitor->was_cleared_for_testing());
1662 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) {
1663 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1664 BlockUntilBrowsingDataRemoved(
1665 BrowsingDataRemover::EVERYTHING,
1666 BrowsingDataRemover::REMOVE_HISTORY, false);
1667 EXPECT_TRUE(monitor->was_cleared_for_testing());
1668 EXPECT_EQ(CLEAR_BEACONS, monitor->cleared_mode_for_testing());
1671 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons_ProtectedOrigins) {
1672 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1673 BlockUntilBrowsingDataRemoved(
1674 BrowsingDataRemover::EVERYTHING,
1675 BrowsingDataRemover::REMOVE_HISTORY, true);
1676 EXPECT_TRUE(monitor->was_cleared_for_testing());
1677 EXPECT_EQ(CLEAR_BEACONS, monitor->cleared_mode_for_testing());
1680 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) {
1681 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1682 BlockUntilBrowsingDataRemoved(
1683 BrowsingDataRemover::EVERYTHING,
1684 BrowsingDataRemover::REMOVE_COOKIES, false);
1685 EXPECT_TRUE(monitor->was_cleared_for_testing());
1686 EXPECT_EQ(CLEAR_CONTEXTS, monitor->cleared_mode_for_testing());
1689 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts_ProtectedOrigins) {
1690 DomainReliabilityMonitor* monitor = UseProfileWithDomainReliabilityMonitor();
1691 BlockUntilBrowsingDataRemoved(
1692 BrowsingDataRemover::EVERYTHING,
1693 BrowsingDataRemover::REMOVE_COOKIES, true);
1694 EXPECT_TRUE(monitor->was_cleared_for_testing());
1695 EXPECT_EQ(CLEAR_CONTEXTS, monitor->cleared_mode_for_testing());