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"
11 #include "base/bind.h"
12 #include "base/bind_helpers.h"
13 #include "base/files/file_path.h"
14 #include "base/files/file_util.h"
15 #include "base/guid.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/prefs/testing_pref_service.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "base/task/cancelable_task_tracker.h"
20 #include "chrome/browser/autofill/personal_data_manager_factory.h"
21 #include "chrome/browser/browsing_data/browsing_data_helper.h"
22 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
23 #include "chrome/browser/chrome_notification_types.h"
24 #include "chrome/browser/domain_reliability/service_factory.h"
25 #include "chrome/browser/history/history_service.h"
26 #include "chrome/browser/history/history_service_factory.h"
27 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
28 #include "chrome/common/pref_names.h"
29 #include "chrome/test/base/testing_browser_process.h"
30 #include "chrome/test/base/testing_profile.h"
31 #include "components/autofill/core/browser/autofill_profile.h"
32 #include "components/autofill/core/browser/autofill_test_utils.h"
33 #include "components/autofill/core/browser/credit_card.h"
34 #include "components/autofill/core/browser/personal_data_manager.h"
35 #include "components/autofill/core/browser/personal_data_manager_observer.h"
36 #include "components/domain_reliability/clear_mode.h"
37 #include "components/domain_reliability/monitor.h"
38 #include "components/domain_reliability/service.h"
39 #include "content/public/browser/cookie_store_factory.h"
40 #include "content/public/browser/dom_storage_context.h"
41 #include "content/public/browser/local_storage_usage_info.h"
42 #include "content/public/browser/notification_service.h"
43 #include "content/public/browser/storage_partition.h"
44 #include "content/public/test/test_browser_thread.h"
45 #include "content/public/test/test_browser_thread_bundle.h"
46 #include "content/public/test/test_utils.h"
47 #include "net/cookies/cookie_store.h"
48 #include "net/ssl/channel_id_service.h"
49 #include "net/ssl/channel_id_store.h"
50 #include "net/ssl/ssl_client_cert_type.h"
51 #include "net/url_request/url_request_context.h"
52 #include "net/url_request/url_request_context_getter.h"
53 #include "testing/gmock/include/gmock/gmock.h"
54 #include "testing/gtest/include/gtest/gtest.h"
56 #if defined(OS_CHROMEOS)
57 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
58 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
59 #include "chrome/browser/chromeos/settings/cros_settings.h"
60 #include "chrome/browser/chromeos/settings/device_settings_service.h"
61 #include "chromeos/dbus/dbus_thread_manager.h"
62 #include "chromeos/dbus/mock_cryptohome_client.h"
65 #if defined(ENABLE_EXTENSIONS)
66 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
69 class MockExtensionSpecialStoragePolicy;
71 using content::BrowserThread;
72 using content::StoragePartition;
73 using domain_reliability::CLEAR_BEACONS;
74 using domain_reliability::CLEAR_CONTEXTS;
75 using domain_reliability::DomainReliabilityClearMode;
76 using domain_reliability::DomainReliabilityMonitor;
77 using domain_reliability::DomainReliabilityService;
78 using domain_reliability::DomainReliabilityServiceFactory;
80 using testing::Invoke;
81 using testing::WithArgs;
85 const char kTestOrigin1[] = "http://host1:1/";
86 const char kTestOrigin2[] = "http://host2:1/";
87 const char kTestOrigin3[] = "http://host3:1/";
88 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
89 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
92 const char kChromeOrigin[] = "Chrome settings";
93 const char kWebOrigin[] = "https://www.example.com/";
95 const GURL kOrigin1(kTestOrigin1);
96 const GURL kOrigin2(kTestOrigin2);
97 const GURL kOrigin3(kTestOrigin3);
98 const GURL kOriginExt(kTestOriginExt);
99 const GURL kOriginDevTools(kTestOriginDevTools);
101 const base::FilePath::CharType kDomStorageOrigin1[] =
102 FILE_PATH_LITERAL("http_host1_1.localstorage");
104 const base::FilePath::CharType kDomStorageOrigin2[] =
105 FILE_PATH_LITERAL("http_host2_1.localstorage");
107 const base::FilePath::CharType kDomStorageOrigin3[] =
108 FILE_PATH_LITERAL("http_host3_1.localstorage");
110 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL(
111 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
113 #if defined(OS_CHROMEOS)
114 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
115 base::MessageLoop::current()->PostTask(
117 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true));
121 struct StoragePartitionRemovalData {
123 uint32 quota_storage_remove_mask;
125 base::Time remove_begin;
126 base::Time remove_end;
127 StoragePartition::OriginMatcherFunction origin_matcher;
129 StoragePartitionRemovalData() : remove_mask(0),
130 quota_storage_remove_mask(0) {}
133 class TestStoragePartition : public StoragePartition {
135 TestStoragePartition() {}
136 virtual ~TestStoragePartition() {}
138 // content::StoragePartition implementation.
139 virtual base::FilePath GetPath() OVERRIDE { return base::FilePath(); }
140 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE {
143 virtual net::URLRequestContextGetter* GetMediaURLRequestContext() OVERRIDE {
146 virtual storage::QuotaManager* GetQuotaManager() OVERRIDE { return NULL; }
147 virtual content::AppCacheService* GetAppCacheService() OVERRIDE {
150 virtual storage::FileSystemContext* GetFileSystemContext() OVERRIDE {
153 virtual storage::DatabaseTracker* GetDatabaseTracker() OVERRIDE {
156 virtual content::DOMStorageContext* GetDOMStorageContext() OVERRIDE {
159 virtual content::IndexedDBContext* GetIndexedDBContext() OVERRIDE {
162 virtual content::ServiceWorkerContext* GetServiceWorkerContext() OVERRIDE {
166 virtual void ClearDataForOrigin(uint32 remove_mask,
167 uint32 quota_storage_remove_mask,
168 const GURL& storage_origin,
169 net::URLRequestContextGetter* rq_context,
170 const base::Closure& callback) OVERRIDE {
171 BrowserThread::PostTask(BrowserThread::UI,
173 base::Bind(&TestStoragePartition::AsyncRunCallback,
174 base::Unretained(this),
178 virtual void ClearData(uint32 remove_mask,
179 uint32 quota_storage_remove_mask,
180 const GURL& storage_origin,
181 const OriginMatcherFunction& origin_matcher,
182 const base::Time begin,
183 const base::Time end,
184 const base::Closure& callback) OVERRIDE {
185 // Store stuff to verify parameters' correctness later.
186 storage_partition_removal_data_.remove_mask = remove_mask;
187 storage_partition_removal_data_.quota_storage_remove_mask =
188 quota_storage_remove_mask;
189 storage_partition_removal_data_.remove_origin = storage_origin;
190 storage_partition_removal_data_.remove_begin = begin;
191 storage_partition_removal_data_.remove_end = end;
192 storage_partition_removal_data_.origin_matcher = origin_matcher;
194 BrowserThread::PostTask(
197 base::Bind(&TestStoragePartition::AsyncRunCallback,
198 base::Unretained(this), callback));
201 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
202 return storage_partition_removal_data_;
206 void AsyncRunCallback(const base::Closure& callback) {
210 StoragePartitionRemovalData storage_partition_removal_data_;
212 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition);
217 // Testers -------------------------------------------------------------------
219 class RemoveCookieTester {
221 RemoveCookieTester() : get_cookie_success_(false), cookie_store_(NULL) {
224 // Returns true, if the given cookie exists in the cookie store.
225 bool ContainsCookie() {
226 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
227 new content::MessageLoopRunner;
228 quit_closure_ = message_loop_runner->QuitClosure();
229 get_cookie_success_ = false;
230 cookie_store_->GetCookiesWithOptionsAsync(
231 kOrigin1, net::CookieOptions(),
232 base::Bind(&RemoveCookieTester::GetCookieCallback,
233 base::Unretained(this)));
234 message_loop_runner->Run();
235 return get_cookie_success_;
239 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
240 new content::MessageLoopRunner;
241 quit_closure_ = message_loop_runner->QuitClosure();
242 cookie_store_->SetCookieWithOptionsAsync(
243 kOrigin1, "A=1", net::CookieOptions(),
244 base::Bind(&RemoveCookieTester::SetCookieCallback,
245 base::Unretained(this)));
246 message_loop_runner->Run();
250 void SetMonster(net::CookieStore* monster) {
251 cookie_store_ = monster;
255 void GetCookieCallback(const std::string& cookies) {
256 if (cookies == "A=1") {
257 get_cookie_success_ = true;
259 EXPECT_EQ("", cookies);
260 get_cookie_success_ = false;
265 void SetCookieCallback(bool result) {
270 bool get_cookie_success_;
271 base::Closure quit_closure_;
272 net::CookieStore* cookie_store_;
274 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
277 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
278 class RemoveSafeBrowsingCookieTester : public RemoveCookieTester {
280 RemoveSafeBrowsingCookieTester()
281 : browser_process_(TestingBrowserProcess::GetGlobal()) {
282 scoped_refptr<SafeBrowsingService> sb_service =
283 SafeBrowsingService::CreateSafeBrowsingService();
284 browser_process_->SetSafeBrowsingService(sb_service.get());
285 sb_service->Initialize();
286 base::MessageLoop::current()->RunUntilIdle();
288 // Create a cookiemonster that does not have persistant storage, and replace
289 // the SafeBrowsingService created one with it.
290 net::CookieStore* monster =
291 content::CreateCookieStore(content::CookieStoreConfig());
292 sb_service->url_request_context()->GetURLRequestContext()->
293 set_cookie_store(monster);
297 virtual ~RemoveSafeBrowsingCookieTester() {
298 browser_process_->safe_browsing_service()->ShutDown();
299 base::MessageLoop::current()->RunUntilIdle();
300 browser_process_->SetSafeBrowsingService(NULL);
304 TestingBrowserProcess* browser_process_;
306 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
310 class RemoveChannelIDTester : public net::SSLConfigService::Observer {
312 explicit RemoveChannelIDTester(TestingProfile* profile)
313 : ssl_config_changed_count_(0) {
314 channel_id_service_ = profile->GetRequestContext()->
315 GetURLRequestContext()->channel_id_service();
316 ssl_config_service_ = profile->GetSSLConfigService();
317 ssl_config_service_->AddObserver(this);
320 virtual ~RemoveChannelIDTester() {
321 ssl_config_service_->RemoveObserver(this);
324 int ChannelIDCount() {
325 return channel_id_service_->cert_count();
328 // Add a server bound cert for |server| with specific creation and expiry
329 // times. The cert and key data will be filled with dummy values.
330 void AddChannelIDWithTimes(const std::string& server_identifier,
331 base::Time creation_time,
332 base::Time expiration_time) {
333 GetChannelIDStore()->SetChannelID(server_identifier,
340 // Add a server bound cert for |server|, with the current time as the
341 // creation time. The cert and key data will be filled with dummy values.
342 void AddChannelID(const std::string& server_identifier) {
343 base::Time now = base::Time::Now();
344 AddChannelIDWithTimes(server_identifier,
346 now + base::TimeDelta::FromDays(1));
349 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) {
350 GetChannelIDStore()->GetAllChannelIDs(
351 base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback,
355 net::ChannelIDStore* GetChannelIDStore() {
356 return channel_id_service_->GetChannelIDStore();
359 int ssl_config_changed_count() const {
360 return ssl_config_changed_count_;
363 // net::SSLConfigService::Observer implementation:
364 virtual void OnSSLConfigChanged() OVERRIDE {
365 ssl_config_changed_count_++;
369 static void GetAllChannelIDsCallback(
370 net::ChannelIDStore::ChannelIDList* dest,
371 const net::ChannelIDStore::ChannelIDList& result) {
375 net::ChannelIDService* channel_id_service_;
376 scoped_refptr<net::SSLConfigService> ssl_config_service_;
377 int ssl_config_changed_count_;
379 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester);
382 class RemoveHistoryTester {
384 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {}
386 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
387 if (!profile->CreateHistoryService(true, false))
389 history_service_ = HistoryServiceFactory::GetForProfile(
390 profile, Profile::EXPLICIT_ACCESS);
394 // Returns true, if the given URL exists in the history service.
395 bool HistoryContainsURL(const GURL& url) {
396 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
397 new content::MessageLoopRunner;
398 quit_closure_ = message_loop_runner->QuitClosure();
399 history_service_->QueryURL(
402 base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
403 base::Unretained(this)),
405 message_loop_runner->Run();
406 return query_url_success_;
409 void AddHistory(const GURL& url, base::Time time) {
410 history_service_->AddPage(url, time, NULL, 0, GURL(),
411 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
412 history::SOURCE_BROWSED, false);
416 // Callback for HistoryService::QueryURL.
417 void SaveResultAndQuit(bool success,
418 const history::URLRow&,
419 const history::VisitVector&) {
420 query_url_success_ = success;
424 // For History requests.
425 base::CancelableTaskTracker tracker_;
426 bool query_url_success_;
427 base::Closure quit_closure_;
429 // TestingProfile owns the history service; we shouldn't delete it.
430 HistoryService* history_service_;
432 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
435 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
437 explicit RemoveAutofillTester(TestingProfile* profile)
438 : personal_data_manager_(
439 autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
440 autofill::test::DisableSystemServices(profile->GetPrefs());
441 personal_data_manager_->AddObserver(this);
444 virtual ~RemoveAutofillTester() {
445 personal_data_manager_->RemoveObserver(this);
448 // Returns true if there are autofill profiles.
450 return !personal_data_manager_->GetProfiles().empty() &&
451 !personal_data_manager_->GetCreditCards().empty();
454 bool HasOrigin(const std::string& origin) {
455 const std::vector<autofill::AutofillProfile*>& profiles =
456 personal_data_manager_->GetProfiles();
457 for (std::vector<autofill::AutofillProfile*>::const_iterator it =
459 it != profiles.end(); ++it) {
460 if ((*it)->origin() == origin)
464 const std::vector<autofill::CreditCard*>& credit_cards =
465 personal_data_manager_->GetCreditCards();
466 for (std::vector<autofill::CreditCard*>::const_iterator it =
467 credit_cards.begin();
468 it != credit_cards.end(); ++it) {
469 if ((*it)->origin() == origin)
476 // Add two profiles and two credit cards to the database. In each pair, one
477 // entry has a web origin and the other has a Chrome origin.
478 void AddProfilesAndCards() {
479 std::vector<autofill::AutofillProfile> profiles;
480 autofill::AutofillProfile profile;
481 profile.set_guid(base::GenerateGUID());
482 profile.set_origin(kWebOrigin);
483 profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
484 profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
485 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
486 profile.SetRawInfo(autofill::EMAIL_ADDRESS,
487 base::ASCIIToUTF16("sue@example.com"));
488 profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
489 profiles.push_back(profile);
491 profile.set_guid(base::GenerateGUID());
492 profile.set_origin(kChromeOrigin);
493 profiles.push_back(profile);
495 personal_data_manager_->SetProfiles(&profiles);
496 base::MessageLoop::current()->Run();
498 std::vector<autofill::CreditCard> cards;
499 autofill::CreditCard card;
500 card.set_guid(base::GenerateGUID());
501 card.set_origin(kWebOrigin);
502 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
503 base::ASCIIToUTF16("1234-5678-9012-3456"));
504 cards.push_back(card);
506 card.set_guid(base::GenerateGUID());
507 card.set_origin(kChromeOrigin);
508 cards.push_back(card);
510 personal_data_manager_->SetCreditCards(&cards);
511 base::MessageLoop::current()->Run();
515 virtual void OnPersonalDataChanged() OVERRIDE {
516 base::MessageLoop::current()->Quit();
519 autofill::PersonalDataManager* personal_data_manager_;
520 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
523 class RemoveLocalStorageTester {
525 explicit RemoveLocalStorageTester(TestingProfile* profile)
526 : profile_(profile), dom_storage_context_(NULL) {
527 dom_storage_context_ =
528 content::BrowserContext::GetDefaultStoragePartition(profile)->
529 GetDOMStorageContext();
532 // Returns true, if the given origin URL exists.
533 bool DOMStorageExistsForOrigin(const GURL& origin) {
534 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
535 new content::MessageLoopRunner;
536 quit_closure_ = message_loop_runner->QuitClosure();
537 GetLocalStorageUsage();
538 message_loop_runner->Run();
539 for (size_t i = 0; i < infos_.size(); ++i) {
540 if (origin == infos_[i].origin)
546 void AddDOMStorageTestData() {
547 // Note: This test depends on details of how the dom_storage library
548 // stores data in the host file system.
549 base::FilePath storage_path =
550 profile_->GetPath().AppendASCII("Local Storage");
551 base::CreateDirectory(storage_path);
554 base::WriteFile(storage_path.Append(kDomStorageOrigin1), NULL, 0);
555 base::WriteFile(storage_path.Append(kDomStorageOrigin2), NULL, 0);
556 base::WriteFile(storage_path.Append(kDomStorageOrigin3), NULL, 0);
557 base::WriteFile(storage_path.Append(kDomStorageExt), NULL, 0);
559 // Tweak their dates.
560 base::Time now = base::Time::Now();
561 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
563 base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
564 base::TouchFile(storage_path.Append(kDomStorageOrigin2),
565 one_day_ago, one_day_ago);
567 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
568 base::TouchFile(storage_path.Append(kDomStorageOrigin3),
569 sixty_days_ago, sixty_days_ago);
571 base::TouchFile(storage_path.Append(kDomStorageExt), now, now);
575 void GetLocalStorageUsage() {
576 dom_storage_context_->GetLocalStorageUsage(
577 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage,
578 base::Unretained(this)));
580 void OnGotLocalStorageUsage(
581 const std::vector<content::LocalStorageUsageInfo>& infos) {
586 // We don't own these pointers.
587 TestingProfile* profile_;
588 content::DOMStorageContext* dom_storage_context_;
590 std::vector<content::LocalStorageUsageInfo> infos_;
591 base::Closure quit_closure_;
593 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
596 class MockDomainReliabilityService : public DomainReliabilityService {
598 MockDomainReliabilityService() : clear_count_(0) {}
600 virtual ~MockDomainReliabilityService() {}
602 virtual scoped_ptr<DomainReliabilityMonitor> CreateMonitor(
603 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner,
604 PrefService* local_state_pref_service,
605 const char* reporting_pref_name) OVERRIDE {
607 return scoped_ptr<DomainReliabilityMonitor>();
610 virtual void ClearBrowsingData(DomainReliabilityClearMode clear_mode,
611 const base::Closure& callback) OVERRIDE {
613 last_clear_mode_ = clear_mode;
617 virtual void GetWebUIData(
618 const base::Callback<void(scoped_ptr<base::Value>)>& callback)
623 int clear_count() const { return clear_count_; }
625 DomainReliabilityClearMode last_clear_mode() const {
626 return last_clear_mode_;
630 unsigned clear_count_;
631 DomainReliabilityClearMode last_clear_mode_;
634 struct TestingDomainReliabilityServiceFactoryUserData
635 : public base::SupportsUserData::Data {
636 TestingDomainReliabilityServiceFactoryUserData(
637 content::BrowserContext* context,
638 MockDomainReliabilityService* service)
642 virtual ~TestingDomainReliabilityServiceFactoryUserData() {}
644 content::BrowserContext* const context;
645 MockDomainReliabilityService* const service;
648 static const void* kKey;
652 const void* TestingDomainReliabilityServiceFactoryUserData::kKey =
653 &TestingDomainReliabilityServiceFactoryUserData::kKey;
655 KeyedService* TestingDomainReliabilityServiceFactoryFunction(
656 content::BrowserContext* context) {
657 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
659 TestingDomainReliabilityServiceFactoryUserData* data =
660 static_cast<TestingDomainReliabilityServiceFactoryUserData*>(
661 context->GetUserData(kKey));
663 EXPECT_EQ(data->context, context);
664 EXPECT_FALSE(data->attached);
666 data->attached = true;
667 return data->service;
670 class ClearDomainReliabilityTester {
672 explicit ClearDomainReliabilityTester(TestingProfile* profile) :
674 mock_service_(new MockDomainReliabilityService()) {
678 unsigned clear_count() { return mock_service_->clear_count(); }
680 DomainReliabilityClearMode last_clear_mode() {
681 return mock_service_->last_clear_mode();
685 void AttachService() {
686 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
688 // Attach kludgey UserData struct to profile.
689 TestingDomainReliabilityServiceFactoryUserData* data =
690 new TestingDomainReliabilityServiceFactoryUserData(profile_,
692 EXPECT_FALSE(profile_->GetUserData(kKey));
693 profile_->SetUserData(kKey, data);
695 // Set and use factory that will attach service stuffed in kludgey struct.
696 DomainReliabilityServiceFactory::GetInstance()->SetTestingFactoryAndUse(
698 &TestingDomainReliabilityServiceFactoryFunction);
700 // Verify and detach kludgey struct.
701 EXPECT_EQ(data, profile_->GetUserData(kKey));
702 EXPECT_TRUE(data->attached);
703 profile_->RemoveUserData(kKey);
706 TestingProfile* profile_;
707 MockDomainReliabilityService* mock_service_;
710 // Test Class ----------------------------------------------------------------
712 class BrowsingDataRemoverTest : public testing::Test,
713 public content::NotificationObserver {
715 BrowsingDataRemoverTest()
716 : profile_(new TestingProfile()) {
717 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED,
718 content::Source<Profile>(profile_.get()));
721 virtual ~BrowsingDataRemoverTest() {
724 virtual void TearDown() {
725 #if defined(ENABLE_EXTENSIONS)
729 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
730 // posts a message to the WEBKIT thread to delete some of its member
731 // variables. We need to ensure that the profile is destroyed, and that
732 // the message loop is cleared out, before destroying the threads and loop.
733 // Otherwise we leak memory.
735 base::MessageLoop::current()->RunUntilIdle();
738 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period,
740 bool include_protected_origins) {
741 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
742 profile_.get(), period);
744 TestStoragePartition storage_partition;
745 remover->OverrideStoragePartitionForTesting(&storage_partition);
747 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
749 // BrowsingDataRemover deletes itself when it completes.
750 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB;
751 if (include_protected_origins)
752 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB;
754 BrowsingDataRemoverCompletionObserver completion_observer(remover);
755 remover->Remove(remove_mask, origin_set_mask);
756 completion_observer.BlockUntilCompletion();
758 // Save so we can verify later.
759 storage_partition_removal_data_ =
760 storage_partition.GetStoragePartitionRemovalData();
763 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period,
765 const GURL& remove_origin) {
766 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
767 profile_.get(), period);
768 TestStoragePartition storage_partition;
769 remover->OverrideStoragePartitionForTesting(&storage_partition);
771 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
773 // BrowsingDataRemover deletes itself when it completes.
774 BrowsingDataRemoverCompletionObserver completion_observer(remover);
775 remover->RemoveImpl(remove_mask, remove_origin,
776 BrowsingDataHelper::UNPROTECTED_WEB);
777 completion_observer.BlockUntilCompletion();
779 // Save so we can verify later.
780 storage_partition_removal_data_ =
781 storage_partition.GetStoragePartitionRemovalData();
784 TestingProfile* GetProfile() {
785 return profile_.get();
788 base::Time GetBeginTime() {
789 return called_with_details_->removal_begin;
792 int GetRemovalMask() {
793 return called_with_details_->removal_mask;
796 int GetOriginSetMask() {
797 return called_with_details_->origin_set_mask;
800 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
801 return storage_partition_removal_data_;
804 // content::NotificationObserver implementation.
805 virtual void Observe(int type,
806 const content::NotificationSource& source,
807 const content::NotificationDetails& details) OVERRIDE {
808 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED);
810 // We're not taking ownership of the details object, but storing a copy of
812 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails(
813 *content::Details<BrowsingDataRemover::NotificationDetails>(
816 registrar_.RemoveAll();
819 MockExtensionSpecialStoragePolicy* CreateMockPolicy() {
820 #if defined(ENABLE_EXTENSIONS)
821 mock_policy_ = new MockExtensionSpecialStoragePolicy;
822 return mock_policy_.get();
829 storage::SpecialStoragePolicy* mock_policy() {
830 #if defined(ENABLE_EXTENSIONS)
831 return mock_policy_.get();
837 // If |kOrigin1| is protected when extensions are enabled, the expected
838 // result for tests where the OriginMatcherFunction result is variable.
839 bool ShouldRemoveForProtectedOriginOne() const {
840 #if defined(ENABLE_EXTENSIONS)
848 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
851 content::NotificationRegistrar registrar_;
853 content::TestBrowserThreadBundle thread_bundle_;
854 scoped_ptr<TestingProfile> profile_;
856 StoragePartitionRemovalData storage_partition_removal_data_;
858 #if defined(ENABLE_EXTENSIONS)
859 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_;
862 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
865 // Tests ---------------------------------------------------------------------
867 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
868 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
869 BrowsingDataRemover::REMOVE_COOKIES,
872 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
873 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
875 // Verify that storage partition was instructed to remove the cookies.
876 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
877 EXPECT_EQ(removal_data.remove_mask,
878 StoragePartition::REMOVE_DATA_MASK_COOKIES);
879 EXPECT_EQ(removal_data.quota_storage_remove_mask,
880 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
881 EXPECT_TRUE(removal_data.remove_origin.is_empty());
882 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
885 TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) {
886 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
887 BrowsingDataRemover::REMOVE_COOKIES,
890 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
891 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
893 // Verify that storage partition was instructed to remove the cookies.
894 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
895 EXPECT_EQ(removal_data.remove_mask,
896 StoragePartition::REMOVE_DATA_MASK_COOKIES);
897 // Removing with time period other than EVERYTHING should not clear
898 // persistent storage data.
899 EXPECT_EQ(removal_data.quota_storage_remove_mask,
900 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
901 EXPECT_TRUE(removal_data.remove_origin.is_empty());
902 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
905 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
906 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) {
907 RemoveSafeBrowsingCookieTester tester;
910 ASSERT_TRUE(tester.ContainsCookie());
912 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
913 BrowsingDataRemover::REMOVE_COOKIES, false);
915 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
916 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
917 EXPECT_FALSE(tester.ContainsCookie());
920 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) {
921 RemoveSafeBrowsingCookieTester tester;
924 ASSERT_TRUE(tester.ContainsCookie());
926 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
927 BrowsingDataRemover::REMOVE_COOKIES, false);
929 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
930 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
931 // Removing with time period other than EVERYTHING should not clear safe
933 EXPECT_TRUE(tester.ContainsCookie());
937 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) {
938 RemoveChannelIDTester tester(GetProfile());
940 tester.AddChannelID(kTestOrigin1);
941 EXPECT_EQ(0, tester.ssl_config_changed_count());
942 EXPECT_EQ(1, tester.ChannelIDCount());
944 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
945 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
947 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
948 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
949 EXPECT_EQ(1, tester.ssl_config_changed_count());
950 EXPECT_EQ(0, tester.ChannelIDCount());
953 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDLastHour) {
954 RemoveChannelIDTester tester(GetProfile());
956 base::Time now = base::Time::Now();
957 tester.AddChannelID(kTestOrigin1);
958 tester.AddChannelIDWithTimes(kTestOrigin2,
959 now - base::TimeDelta::FromHours(2),
961 EXPECT_EQ(0, tester.ssl_config_changed_count());
962 EXPECT_EQ(2, tester.ChannelIDCount());
964 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
965 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
967 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
968 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
969 EXPECT_EQ(1, tester.ssl_config_changed_count());
970 ASSERT_EQ(1, tester.ChannelIDCount());
971 net::ChannelIDStore::ChannelIDList channel_ids;
972 tester.GetChannelIDList(&channel_ids);
973 ASSERT_EQ(1U, channel_ids.size());
974 EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier());
977 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) {
978 #if defined(ENABLE_EXTENSIONS)
979 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
981 policy->AddProtected(kOrigin1.GetOrigin());
984 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
985 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
988 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
989 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
991 // Verify that storage partition was instructed to remove the data correctly.
992 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
993 EXPECT_EQ(removal_data.remove_mask,
994 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
995 EXPECT_EQ(removal_data.quota_storage_remove_mask,
996 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
997 EXPECT_TRUE(removal_data.remove_origin.is_empty());
998 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1000 // Check origin matcher.
1001 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1002 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1003 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1004 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1005 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1008 TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) {
1009 #if defined(ENABLE_EXTENSIONS)
1010 // Protect kOrigin1.
1011 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1012 policy->AddProtected(kOrigin1.GetOrigin());
1015 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1016 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1019 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1020 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB |
1021 BrowsingDataHelper::PROTECTED_WEB, GetOriginSetMask());
1023 // Verify that storage partition was instructed to remove the data correctly.
1024 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1025 EXPECT_EQ(removal_data.remove_mask,
1026 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1027 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1028 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1029 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1030 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1032 // Check origin matcher all http origin will match since we specified
1033 // both protected and unprotected.
1034 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1035 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1036 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1037 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1040 TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) {
1041 #if defined(ENABLE_EXTENSIONS)
1045 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
1046 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1049 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1050 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1052 // Verify that storage partition was instructed to remove the data correctly.
1053 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1054 EXPECT_EQ(removal_data.remove_mask,
1055 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1056 // Persistent storage won't be deleted.
1057 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1058 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1059 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1060 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1062 // Check origin matcher.
1063 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1064 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1065 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1066 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1069 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
1070 RemoveHistoryTester tester;
1071 ASSERT_TRUE(tester.Init(GetProfile()));
1073 tester.AddHistory(kOrigin1, base::Time::Now());
1074 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1076 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1077 BrowsingDataRemover::REMOVE_HISTORY, false);
1079 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1080 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1081 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
1084 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
1085 RemoveHistoryTester tester;
1086 ASSERT_TRUE(tester.Init(GetProfile()));
1088 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1090 tester.AddHistory(kOrigin1, base::Time::Now());
1091 tester.AddHistory(kOrigin2, two_hours_ago);
1092 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1093 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1095 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1096 BrowsingDataRemover::REMOVE_HISTORY, false);
1098 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1099 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1100 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
1101 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1104 // This should crash (DCHECK) in Debug, but death tests don't work properly
1106 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1107 TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
1108 RemoveHistoryTester tester;
1109 ASSERT_TRUE(tester.Init(GetProfile()));
1110 PrefService* prefs = GetProfile()->GetPrefs();
1111 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1113 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1115 tester.AddHistory(kOrigin1, base::Time::Now());
1116 tester.AddHistory(kOrigin2, two_hours_ago);
1117 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1118 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1120 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1121 BrowsingDataRemover::REMOVE_HISTORY, false);
1122 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1123 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1125 // Nothing should have been deleted.
1126 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1127 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1131 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) {
1132 // Add some history.
1133 RemoveHistoryTester history_tester;
1134 ASSERT_TRUE(history_tester.Init(GetProfile()));
1135 history_tester.AddHistory(kOrigin1, base::Time::Now());
1136 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1138 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1139 BrowsingDataRemover::REMOVE_COOKIES;
1141 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1142 removal_mask, false);
1144 EXPECT_EQ(removal_mask, GetRemovalMask());
1145 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1146 EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1));
1148 // The cookie would be deleted throught the StorageParition, check if the
1149 // partition was requested to remove cookie.
1150 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1151 EXPECT_EQ(removal_data.remove_mask,
1152 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1153 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1154 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1157 // This should crash (DCHECK) in Debug, but death tests don't work properly
1159 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1160 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
1161 PrefService* prefs = GetProfile()->GetPrefs();
1162 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1164 // Add some history.
1165 RemoveHistoryTester history_tester;
1166 ASSERT_TRUE(history_tester.Init(GetProfile()));
1167 history_tester.AddHistory(kOrigin1, base::Time::Now());
1168 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1170 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1171 BrowsingDataRemover::REMOVE_COOKIES;
1173 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1174 removal_mask, false);
1175 EXPECT_EQ(removal_mask, GetRemovalMask());
1176 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1178 // 1/2. History should remain.
1179 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1181 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if
1182 // the partition was requested to remove cookie.
1183 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1184 EXPECT_EQ(removal_data.remove_mask,
1185 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1186 // Persistent storage won't be deleted, since EVERYTHING was not specified.
1187 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1188 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1192 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
1193 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1194 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1195 BrowsingDataRemover::REMOVE_WEBSQL |
1196 BrowsingDataRemover::REMOVE_APPCACHE |
1197 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1198 BrowsingDataRemover::REMOVE_INDEXEDDB,
1201 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1202 BrowsingDataRemover::REMOVE_WEBSQL |
1203 BrowsingDataRemover::REMOVE_APPCACHE |
1204 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1205 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1206 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1208 // Verify storage partition related stuffs.
1209 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1210 EXPECT_EQ(removal_data.remove_mask,
1211 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1212 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1213 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1214 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1215 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1216 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1217 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1218 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1221 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
1222 #if defined(ENABLE_EXTENSIONS)
1226 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1227 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1228 BrowsingDataRemover::REMOVE_WEBSQL |
1229 BrowsingDataRemover::REMOVE_APPCACHE |
1230 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1231 BrowsingDataRemover::REMOVE_INDEXEDDB,
1234 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1235 BrowsingDataRemover::REMOVE_WEBSQL |
1236 BrowsingDataRemover::REMOVE_APPCACHE |
1237 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1238 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1239 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1241 // Verify storage partition related stuffs.
1242 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1244 EXPECT_EQ(removal_data.remove_mask,
1245 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1246 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1247 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1248 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1249 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1250 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1251 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1252 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1254 // Check that all related origin data would be removed, that is, origin
1255 // matcher would match these origin.
1256 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1257 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1258 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1261 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
1262 #if defined(ENABLE_EXTENSIONS)
1266 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1267 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1268 BrowsingDataRemover::REMOVE_WEBSQL |
1269 BrowsingDataRemover::REMOVE_APPCACHE |
1270 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1271 BrowsingDataRemover::REMOVE_INDEXEDDB,
1274 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1275 BrowsingDataRemover::REMOVE_WEBSQL |
1276 BrowsingDataRemover::REMOVE_APPCACHE |
1277 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1278 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1279 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1281 // Verify storage partition related stuffs.
1282 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1284 EXPECT_EQ(removal_data.remove_mask,
1285 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1286 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1287 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1288 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1289 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1290 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1291 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1292 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1294 // Check that all related origin data would be removed, that is, origin
1295 // matcher would match these origin.
1296 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1297 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1298 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1301 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
1302 #if defined(ENABLE_EXTENSIONS)
1307 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1308 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1309 BrowsingDataRemover::REMOVE_WEBSQL |
1310 BrowsingDataRemover::REMOVE_APPCACHE |
1311 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1312 BrowsingDataRemover::REMOVE_INDEXEDDB,
1315 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1316 BrowsingDataRemover::REMOVE_WEBSQL |
1317 BrowsingDataRemover::REMOVE_APPCACHE |
1318 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1319 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1320 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1322 // Verify storage partition related stuffs.
1323 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1325 EXPECT_EQ(removal_data.remove_mask,
1326 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1327 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1328 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1329 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1330 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1331 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1332 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1333 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1335 // Check that all related origin data would be removed, that is, origin
1336 // matcher would match these origin.
1337 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1338 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1339 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1342 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
1344 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1345 BrowsingDataRemover::REMOVE_APPCACHE |
1346 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1347 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1348 BrowsingDataRemover::REMOVE_INDEXEDDB |
1349 BrowsingDataRemover::REMOVE_WEBSQL,
1352 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1353 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1354 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1355 BrowsingDataRemover::REMOVE_INDEXEDDB |
1356 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1357 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1359 // Verify storage partition related stuffs.
1360 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1362 EXPECT_EQ(removal_data.remove_mask,
1363 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1364 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1365 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1366 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1367 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1368 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1369 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1370 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1373 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
1374 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1375 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1376 BrowsingDataRemover::REMOVE_WEBSQL |
1377 BrowsingDataRemover::REMOVE_APPCACHE |
1378 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1379 BrowsingDataRemover::REMOVE_INDEXEDDB,
1382 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1383 BrowsingDataRemover::REMOVE_WEBSQL |
1384 BrowsingDataRemover::REMOVE_APPCACHE |
1385 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1386 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1387 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1389 // Verify storage partition related stuffs.
1390 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1392 EXPECT_EQ(removal_data.remove_mask,
1393 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1394 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1395 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1396 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1397 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1399 // Persistent data would be left out since we are not removing from
1400 // beginning of time.
1401 uint32 expected_quota_mask =
1402 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1403 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1404 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1405 // Check removal begin time.
1406 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1409 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
1410 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
1411 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1412 BrowsingDataRemover::REMOVE_WEBSQL |
1413 BrowsingDataRemover::REMOVE_APPCACHE |
1414 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1415 BrowsingDataRemover::REMOVE_INDEXEDDB,
1418 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1419 BrowsingDataRemover::REMOVE_WEBSQL |
1420 BrowsingDataRemover::REMOVE_APPCACHE |
1421 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1422 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1423 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1425 // Verify storage partition related stuffs.
1426 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1428 EXPECT_EQ(removal_data.remove_mask,
1429 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1430 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1431 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1432 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1433 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1435 // Persistent data would be left out since we are not removing from
1436 // beginning of time.
1437 uint32 expected_quota_mask =
1438 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1439 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1440 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1441 // Check removal begin time.
1442 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1445 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
1446 #if defined(ENABLE_EXTENSIONS)
1447 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1448 // Protect kOrigin1.
1449 policy->AddProtected(kOrigin1.GetOrigin());
1452 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1453 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1454 BrowsingDataRemover::REMOVE_WEBSQL |
1455 BrowsingDataRemover::REMOVE_APPCACHE |
1456 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1457 BrowsingDataRemover::REMOVE_INDEXEDDB,
1460 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1461 BrowsingDataRemover::REMOVE_WEBSQL |
1462 BrowsingDataRemover::REMOVE_APPCACHE |
1463 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1464 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1465 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1467 // Verify storage partition related stuffs.
1468 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1470 EXPECT_EQ(removal_data.remove_mask,
1471 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1472 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1473 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1474 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1475 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1476 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1477 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1478 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1480 // Check OriginMatcherFunction.
1481 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1482 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1483 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1484 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1487 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) {
1488 #if defined(ENABLE_EXTENSIONS)
1489 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1490 // Protect kOrigin1.
1491 policy->AddProtected(kOrigin1.GetOrigin());
1494 // Try to remove kOrigin1. Expect failure.
1495 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1496 BrowsingDataRemover::REMOVE_APPCACHE |
1497 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1498 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1499 BrowsingDataRemover::REMOVE_INDEXEDDB |
1500 BrowsingDataRemover::REMOVE_WEBSQL,
1503 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1504 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1505 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1506 BrowsingDataRemover::REMOVE_INDEXEDDB |
1507 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1508 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1510 // Verify storage partition related stuffs.
1511 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1513 EXPECT_EQ(removal_data.remove_mask,
1514 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1515 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1516 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1517 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1518 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1519 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1520 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1521 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1523 // Check OriginMatcherFunction.
1524 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1525 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1526 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1527 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1530 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) {
1531 #if defined(ENABLE_EXTENSIONS)
1532 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1533 // Protect kOrigin1.
1534 policy->AddProtected(kOrigin1.GetOrigin());
1537 // Try to remove kOrigin1. Expect success.
1538 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1539 BrowsingDataRemover::REMOVE_APPCACHE |
1540 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1541 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1542 BrowsingDataRemover::REMOVE_INDEXEDDB |
1543 BrowsingDataRemover::REMOVE_WEBSQL,
1546 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1547 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1548 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1549 BrowsingDataRemover::REMOVE_INDEXEDDB |
1550 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1551 EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB |
1552 BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1554 // Verify storage partition related stuffs.
1555 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1557 EXPECT_EQ(removal_data.remove_mask,
1558 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1559 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1560 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1561 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1562 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1563 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1564 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1565 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1567 // Check OriginMatcherFunction, |kOrigin1| would match mask since we
1568 // would have 'protected' specified in origin_set_mask.
1569 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1570 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1571 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1574 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
1575 #if defined(ENABLE_EXTENSIONS)
1579 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1580 BrowsingDataRemover::REMOVE_APPCACHE |
1581 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1582 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1583 BrowsingDataRemover::REMOVE_INDEXEDDB |
1584 BrowsingDataRemover::REMOVE_WEBSQL,
1587 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1588 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1589 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1590 BrowsingDataRemover::REMOVE_INDEXEDDB |
1591 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1592 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1594 // Verify storage partition related stuffs.
1595 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1597 EXPECT_EQ(removal_data.remove_mask,
1598 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1599 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1600 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1601 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1602 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1603 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1604 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1605 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1607 // Check that extension and devtools data wouldn't be removed, that is,
1608 // origin matcher would not match these origin.
1609 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1610 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy()));
1613 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) {
1614 RemoveHistoryTester tester;
1615 ASSERT_TRUE(tester.Init(GetProfile()));
1617 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1619 tester.AddHistory(kOrigin1, base::Time::Now());
1620 tester.AddHistory(kOrigin2, two_hours_ago);
1621 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1622 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1624 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1625 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1627 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1628 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1630 // Nothing should have been deleted.
1631 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1632 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2));
1635 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
1636 RemoveHistoryTester tester;
1637 ASSERT_TRUE(tester.Init(GetProfile()));
1639 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1641 tester.AddHistory(kOrigin1, base::Time::Now());
1642 tester.AddHistory(kOrigin2, two_hours_ago);
1643 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1644 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1646 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
1647 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1649 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1650 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1651 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1652 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1655 // Verify that clearing autofill form data works.
1656 TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) {
1657 GetProfile()->CreateWebDataService();
1658 RemoveAutofillTester tester(GetProfile());
1660 ASSERT_FALSE(tester.HasProfile());
1661 tester.AddProfilesAndCards();
1662 ASSERT_TRUE(tester.HasProfile());
1664 BlockUntilBrowsingDataRemoved(
1665 BrowsingDataRemover::LAST_HOUR,
1666 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1668 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1669 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1670 ASSERT_FALSE(tester.HasProfile());
1673 TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) {
1674 GetProfile()->CreateWebDataService();
1675 RemoveAutofillTester tester(GetProfile());
1677 ASSERT_FALSE(tester.HasProfile());
1678 tester.AddProfilesAndCards();
1679 ASSERT_TRUE(tester.HasProfile());
1681 BlockUntilBrowsingDataRemoved(
1682 BrowsingDataRemover::EVERYTHING,
1683 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1685 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1686 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1687 ASSERT_FALSE(tester.HasProfile());
1690 // Verify that clearing autofill form data works.
1691 TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) {
1692 GetProfile()->CreateWebDataService();
1693 RemoveAutofillTester tester(GetProfile());
1695 tester.AddProfilesAndCards();
1696 EXPECT_FALSE(tester.HasOrigin(std::string()));
1697 EXPECT_TRUE(tester.HasOrigin(kWebOrigin));
1698 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1700 BlockUntilBrowsingDataRemoved(
1701 BrowsingDataRemover::LAST_HOUR,
1702 BrowsingDataRemover::REMOVE_HISTORY, false);
1704 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1705 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1706 EXPECT_TRUE(tester.HasOrigin(std::string()));
1707 EXPECT_FALSE(tester.HasOrigin(kWebOrigin));
1708 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1711 TEST_F(BrowsingDataRemoverTest, CompletionInhibition) {
1712 // The |completion_inhibitor| on the stack should prevent removal sessions
1713 // from completing until after ContinueToCompletion() is called.
1714 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
1716 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
1718 // BrowsingDataRemover deletes itself when it completes.
1719 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
1720 GetProfile(), BrowsingDataRemover::EVERYTHING);
1721 remover->Remove(BrowsingDataRemover::REMOVE_HISTORY,
1722 BrowsingDataHelper::UNPROTECTED_WEB);
1724 // Process messages until the inhibitor is notified, and then some, to make
1725 // sure we do not complete asynchronously before ContinueToCompletion() is
1727 completion_inhibitor.BlockUntilNearCompletion();
1728 base::RunLoop().RunUntilIdle();
1730 // Verify that the completion notification has not yet been broadcasted.
1731 EXPECT_EQ(-1, GetRemovalMask());
1732 EXPECT_EQ(-1, GetOriginSetMask());
1734 // Now run the removal process until completion, and verify that observers are
1735 // now notified, and the notifications is sent out.
1736 BrowsingDataRemoverCompletionObserver completion_observer(remover);
1737 completion_inhibitor.ContinueToCompletion();
1738 completion_observer.BlockUntilCompletion();
1740 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1741 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1744 TEST_F(BrowsingDataRemoverTest, ZeroSuggestCacheClear) {
1745 PrefService* prefs = GetProfile()->GetPrefs();
1746 prefs->SetString(prefs::kZeroSuggestCachedResults,
1747 "[\"\", [\"foo\", \"bar\"]]");
1748 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1749 BrowsingDataRemover::REMOVE_COOKIES,
1752 // Expect the prefs to be cleared when cookies are removed.
1753 EXPECT_TRUE(prefs->GetString(prefs::kZeroSuggestCachedResults).empty());
1754 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1755 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask());
1758 #if defined(OS_CHROMEOS)
1759 TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) {
1760 chromeos::ScopedTestDeviceSettingsService test_device_settings_service;
1761 chromeos::ScopedTestCrosSettings test_cros_settings;
1762 chromeos::MockUserManager* mock_user_manager =
1763 new testing::NiceMock<chromeos::MockUserManager>();
1764 mock_user_manager->SetActiveUser("test@example.com");
1765 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager);
1767 scoped_ptr<chromeos::DBusThreadManagerSetter> dbus_setter =
1768 chromeos::DBusThreadManager::GetSetterForTesting();
1769 chromeos::MockCryptohomeClient* cryptohome_client =
1770 new chromeos::MockCryptohomeClient;
1771 dbus_setter->SetCryptohomeClient(
1772 scoped_ptr<chromeos::CryptohomeClient>(cryptohome_client));
1774 // Expect exactly one call. No calls means no attempt to delete keys and more
1775 // than one call means a significant performance problem.
1776 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
1777 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
1779 BlockUntilBrowsingDataRemoved(
1780 BrowsingDataRemover::EVERYTHING,
1781 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false);
1783 chromeos::DBusThreadManager::Shutdown();
1787 TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) {
1788 ClearDomainReliabilityTester tester(GetProfile());
1790 EXPECT_EQ(0u, tester.clear_count());
1793 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) {
1794 ClearDomainReliabilityTester tester(GetProfile());
1796 BlockUntilBrowsingDataRemoved(
1797 BrowsingDataRemover::EVERYTHING,
1798 BrowsingDataRemover::REMOVE_HISTORY, false);
1799 EXPECT_EQ(1u, tester.clear_count());
1800 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode());
1803 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) {
1804 ClearDomainReliabilityTester tester(GetProfile());
1806 BlockUntilBrowsingDataRemoved(
1807 BrowsingDataRemover::EVERYTHING,
1808 BrowsingDataRemover::REMOVE_COOKIES, false);
1809 EXPECT_EQ(1u, tester.clear_count());
1810 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
1813 TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) {
1814 ClearDomainReliabilityTester tester(GetProfile());
1816 BlockUntilBrowsingDataRemoved(
1817 BrowsingDataRemover::EVERYTHING,
1818 BrowsingDataRemover::REMOVE_HISTORY |
1819 BrowsingDataRemover::REMOVE_COOKIES, false);
1820 EXPECT_EQ(1u, tester.clear_count());
1821 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
1824 TEST_F(BrowsingDataRemoverTest, DomainReliability_ProtectedOrigins) {
1825 ClearDomainReliabilityTester tester(GetProfile());
1827 BlockUntilBrowsingDataRemoved(
1828 BrowsingDataRemover::EVERYTHING,
1829 BrowsingDataRemover::REMOVE_COOKIES, true);
1830 EXPECT_EQ(1u, tester.clear_count());
1831 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
1834 TEST_F(BrowsingDataRemoverTest, DomainReliability_NoMonitor) {
1835 BlockUntilBrowsingDataRemoved(
1836 BrowsingDataRemover::EVERYTHING,
1837 BrowsingDataRemover::REMOVE_HISTORY |
1838 BrowsingDataRemover::REMOVE_COOKIES, false);