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"
10 #include "base/bind.h"
11 #include "base/bind_helpers.h"
12 #include "base/file_util.h"
13 #include "base/files/file_path.h"
14 #include "base/guid.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/platform_file.h"
17 #include "base/prefs/testing_pref_service.h"
18 #include "base/strings/utf_string_conversions.h"
19 #include "chrome/browser/autofill/personal_data_manager_factory.h"
20 #include "chrome/browser/browsing_data/browsing_data_helper.h"
21 #include "chrome/browser/chrome_notification_types.h"
22 #if defined(OS_CHROMEOS)
23 #include "chrome/browser/chromeos/login/mock_user_manager.h"
24 #include "chrome/browser/chromeos/login/user_manager.h"
25 #include "chrome/browser/chromeos/settings/cros_settings.h"
26 #include "chrome/browser/chromeos/settings/device_settings_service.h"
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"
40 #include "components/autofill/core/browser/autofill_profile.h"
41 #include "components/autofill/core/browser/autofill_test_utils.h"
42 #include "components/autofill/core/browser/credit_card.h"
43 #include "components/autofill/core/browser/personal_data_manager.h"
44 #include "components/autofill/core/browser/personal_data_manager_observer.h"
45 #include "content/public/browser/dom_storage_context.h"
46 #include "content/public/browser/local_storage_usage_info.h"
47 #include "content/public/browser/notification_service.h"
48 #include "content/public/browser/storage_partition.h"
49 #include "content/public/test/test_browser_thread.h"
50 #include "content/public/test/test_browser_thread_bundle.h"
51 #include "net/cookies/cookie_monster.h"
52 #include "net/ssl/server_bound_cert_service.h"
53 #include "net/ssl/server_bound_cert_store.h"
54 #include "net/ssl/ssl_client_cert_type.h"
55 #include "net/url_request/url_request_context.h"
56 #include "net/url_request/url_request_context_getter.h"
57 #include "testing/gmock/include/gmock/gmock.h"
58 #include "testing/gtest/include/gtest/gtest.h"
60 using content::BrowserThread
;
61 using content::StoragePartition
;
63 using testing::Invoke
;
64 using testing::WithArgs
;
68 const char kTestOrigin1
[] = "http://host1:1/";
69 const char kTestOrigin2
[] = "http://host2:1/";
70 const char kTestOrigin3
[] = "http://host3:1/";
71 const char kTestOriginExt
[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
72 const char kTestOriginDevTools
[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
75 const char kChromeOrigin
[] = "Chrome settings";
76 const char kWebOrigin
[] = "https://www.example.com/";
78 const GURL
kOrigin1(kTestOrigin1
);
79 const GURL
kOrigin2(kTestOrigin2
);
80 const GURL
kOrigin3(kTestOrigin3
);
81 const GURL
kOriginExt(kTestOriginExt
);
82 const GURL
kOriginDevTools(kTestOriginDevTools
);
84 const base::FilePath::CharType kDomStorageOrigin1
[] =
85 FILE_PATH_LITERAL("http_host1_1.localstorage");
87 const base::FilePath::CharType kDomStorageOrigin2
[] =
88 FILE_PATH_LITERAL("http_host2_1.localstorage");
90 const base::FilePath::CharType kDomStorageOrigin3
[] =
91 FILE_PATH_LITERAL("http_host3_1.localstorage");
93 const base::FilePath::CharType kDomStorageExt
[] = FILE_PATH_LITERAL(
94 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
96 class AwaitCompletionHelper
: public BrowsingDataRemover::Observer
{
98 AwaitCompletionHelper() : start_(false), already_quit_(false) {}
99 virtual ~AwaitCompletionHelper() {}
101 void BlockUntilNotified() {
102 if (!already_quit_
) {
105 base::MessageLoop::current()->Run();
108 already_quit_
= false;
114 DCHECK(!already_quit_
);
115 base::MessageLoop::current()->Quit();
118 DCHECK(!already_quit_
);
119 already_quit_
= true;
124 // BrowsingDataRemover::Observer implementation.
125 virtual void OnBrowsingDataRemoverDone() OVERRIDE
{
130 // Helps prevent from running message_loop, if the callback invoked
135 DISALLOW_COPY_AND_ASSIGN(AwaitCompletionHelper
);
138 #if defined(OS_CHROMEOS)
139 void FakeDBusCall(const chromeos::BoolDBusMethodCallback
& callback
) {
140 base::MessageLoop::current()->PostTask(
142 base::Bind(callback
, chromeos::DBUS_METHOD_CALL_SUCCESS
, true));
146 struct StoragePartitionRemovalData
{
148 uint32 quota_storage_remove_mask
;
150 base::Time remove_begin
;
151 base::Time remove_end
;
152 StoragePartition::OriginMatcherFunction origin_matcher
;
154 StoragePartitionRemovalData() : remove_mask(0),
155 quota_storage_remove_mask(0) {}
158 class TestStoragePartition
: public StoragePartition
{
160 TestStoragePartition() {}
161 virtual ~TestStoragePartition() {}
163 // content::StoragePartition implementation.
164 virtual base::FilePath
GetPath() OVERRIDE
{ return base::FilePath(); }
165 virtual net::URLRequestContextGetter
* GetURLRequestContext() OVERRIDE
{
168 virtual net::URLRequestContextGetter
* GetMediaURLRequestContext() OVERRIDE
{
171 virtual quota::QuotaManager
* GetQuotaManager() OVERRIDE
{
174 virtual appcache::AppCacheService
* GetAppCacheService() OVERRIDE
{
177 virtual fileapi::FileSystemContext
* GetFileSystemContext() OVERRIDE
{
180 virtual webkit_database::DatabaseTracker
* GetDatabaseTracker() OVERRIDE
{
183 virtual content::DOMStorageContext
* GetDOMStorageContext() OVERRIDE
{
186 virtual content::IndexedDBContext
* GetIndexedDBContext() OVERRIDE
{
190 virtual void ClearDataForOrigin(
192 uint32 quota_storage_remove_mask
,
193 const GURL
& storage_origin
,
194 net::URLRequestContextGetter
* rq_context
) OVERRIDE
{}
196 virtual void ClearData(uint32 remove_mask
,
197 uint32 quota_storage_remove_mask
,
198 const GURL
* storage_origin
,
199 const OriginMatcherFunction
& origin_matcher
,
200 const base::Time begin
,
201 const base::Time end
,
202 const base::Closure
& callback
) OVERRIDE
{
203 // Store stuff to verify parameters' correctness later.
204 storage_partition_removal_data_
.remove_mask
= remove_mask
;
205 storage_partition_removal_data_
.quota_storage_remove_mask
=
206 quota_storage_remove_mask
;
207 storage_partition_removal_data_
.remove_origin
=
208 storage_origin
? *storage_origin
: GURL();
209 storage_partition_removal_data_
.remove_begin
= begin
;
210 storage_partition_removal_data_
.remove_end
= end
;
211 storage_partition_removal_data_
.origin_matcher
= origin_matcher
;
213 BrowserThread::PostTask(
216 base::Bind(&TestStoragePartition::AsyncRunCallback
,
217 base::Unretained(this), callback
));
220 StoragePartitionRemovalData
GetStoragePartitionRemovalData() {
221 return storage_partition_removal_data_
;
224 void AsyncRunCallback(const base::Closure
& callback
) {
228 StoragePartitionRemovalData storage_partition_removal_data_
;
230 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition
);
235 // Testers -------------------------------------------------------------------
237 class RemoveCookieTester
{
239 RemoveCookieTester() : get_cookie_success_(false), monster_(NULL
) {
242 // Returns true, if the given cookie exists in the cookie store.
243 bool ContainsCookie() {
244 get_cookie_success_
= false;
245 monster_
->GetCookiesWithOptionsAsync(
246 kOrigin1
, net::CookieOptions(),
247 base::Bind(&RemoveCookieTester::GetCookieCallback
,
248 base::Unretained(this)));
249 await_completion_
.BlockUntilNotified();
250 return get_cookie_success_
;
254 monster_
->SetCookieWithOptionsAsync(
255 kOrigin1
, "A=1", net::CookieOptions(),
256 base::Bind(&RemoveCookieTester::SetCookieCallback
,
257 base::Unretained(this)));
258 await_completion_
.BlockUntilNotified();
262 void SetMonster(net::CookieStore
* monster
) {
267 void GetCookieCallback(const std::string
& cookies
) {
268 if (cookies
== "A=1") {
269 get_cookie_success_
= true;
271 EXPECT_EQ("", cookies
);
272 get_cookie_success_
= false;
274 await_completion_
.Notify();
277 void SetCookieCallback(bool result
) {
279 await_completion_
.Notify();
282 bool get_cookie_success_
;
283 AwaitCompletionHelper await_completion_
;
284 net::CookieStore
* monster_
;
286 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester
);
289 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
290 class RemoveSafeBrowsingCookieTester
: public RemoveCookieTester
{
292 RemoveSafeBrowsingCookieTester()
293 : browser_process_(TestingBrowserProcess::GetGlobal()) {
294 scoped_refptr
<SafeBrowsingService
> sb_service
=
295 SafeBrowsingService::CreateSafeBrowsingService();
296 browser_process_
->SetSafeBrowsingService(sb_service
.get());
297 sb_service
->Initialize();
298 base::MessageLoop::current()->RunUntilIdle();
300 // Create a cookiemonster that does not have persistant storage, and replace
301 // the SafeBrowsingService created one with it.
302 net::CookieStore
* monster
= new net::CookieMonster(NULL
, NULL
);
303 sb_service
->url_request_context()->GetURLRequestContext()->
304 set_cookie_store(monster
);
308 virtual ~RemoveSafeBrowsingCookieTester() {
309 browser_process_
->safe_browsing_service()->ShutDown();
310 base::MessageLoop::current()->RunUntilIdle();
311 browser_process_
->SetSafeBrowsingService(NULL
);
315 TestingBrowserProcess
* browser_process_
;
317 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester
);
321 class RemoveServerBoundCertTester
: public net::SSLConfigService::Observer
{
323 explicit RemoveServerBoundCertTester(TestingProfile
* profile
)
324 : ssl_config_changed_count_(0) {
325 server_bound_cert_service_
= profile
->GetRequestContext()->
326 GetURLRequestContext()->server_bound_cert_service();
327 ssl_config_service_
= profile
->GetSSLConfigService();
328 ssl_config_service_
->AddObserver(this);
331 virtual ~RemoveServerBoundCertTester() {
332 ssl_config_service_
->RemoveObserver(this);
335 int ServerBoundCertCount() {
336 return server_bound_cert_service_
->cert_count();
339 // Add a server bound cert for |server| with specific creation and expiry
340 // times. The cert and key data will be filled with dummy values.
341 void AddServerBoundCertWithTimes(const std::string
& server_identifier
,
342 base::Time creation_time
,
343 base::Time expiration_time
) {
344 GetCertStore()->SetServerBoundCert(server_identifier
,
351 // Add a server bound cert for |server|, with the current time as the
352 // creation time. The cert and key data will be filled with dummy values.
353 void AddServerBoundCert(const std::string
& server_identifier
) {
354 base::Time now
= base::Time::Now();
355 AddServerBoundCertWithTimes(server_identifier
,
357 now
+ base::TimeDelta::FromDays(1));
360 void GetCertList(net::ServerBoundCertStore::ServerBoundCertList
* certs
) {
361 GetCertStore()->GetAllServerBoundCerts(
362 base::Bind(&RemoveServerBoundCertTester::GetAllCertsCallback
, certs
));
365 net::ServerBoundCertStore
* GetCertStore() {
366 return server_bound_cert_service_
->GetCertStore();
369 int ssl_config_changed_count() const {
370 return ssl_config_changed_count_
;
373 // net::SSLConfigService::Observer implementation:
374 virtual void OnSSLConfigChanged() OVERRIDE
{
375 ssl_config_changed_count_
++;
379 static void GetAllCertsCallback(
380 net::ServerBoundCertStore::ServerBoundCertList
* dest
,
381 const net::ServerBoundCertStore::ServerBoundCertList
& result
) {
385 net::ServerBoundCertService
* server_bound_cert_service_
;
386 scoped_refptr
<net::SSLConfigService
> ssl_config_service_
;
387 int ssl_config_changed_count_
;
389 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester
);
392 class RemoveHistoryTester
{
394 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL
) {}
396 bool Init(TestingProfile
* profile
) WARN_UNUSED_RESULT
{
397 if (!profile
->CreateHistoryService(true, false))
399 history_service_
= HistoryServiceFactory::GetForProfile(
400 profile
, Profile::EXPLICIT_ACCESS
);
404 // Returns true, if the given URL exists in the history service.
405 bool HistoryContainsURL(const GURL
& url
) {
406 history_service_
->QueryURL(
410 base::Bind(&RemoveHistoryTester::SaveResultAndQuit
,
411 base::Unretained(this)));
412 await_completion_
.BlockUntilNotified();
413 return query_url_success_
;
416 void AddHistory(const GURL
& url
, base::Time time
) {
417 history_service_
->AddPage(url
, time
, NULL
, 0, GURL(),
418 history::RedirectList(), content::PAGE_TRANSITION_LINK
,
419 history::SOURCE_BROWSED
, false);
423 // Callback for HistoryService::QueryURL.
424 void SaveResultAndQuit(HistoryService::Handle
,
426 const history::URLRow
*,
427 history::VisitVector
*) {
428 query_url_success_
= success
;
429 await_completion_
.Notify();
432 // For History requests.
433 CancelableRequestConsumer consumer_
;
434 bool query_url_success_
;
436 // TestingProfile owns the history service; we shouldn't delete it.
437 HistoryService
* history_service_
;
439 AwaitCompletionHelper await_completion_
;
441 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester
);
444 class RemoveAutofillTester
: public autofill::PersonalDataManagerObserver
{
446 explicit RemoveAutofillTester(TestingProfile
* profile
)
447 : personal_data_manager_(
448 autofill::PersonalDataManagerFactory::GetForProfile(profile
)) {
449 autofill::test::DisableSystemServices(profile
);
450 personal_data_manager_
->AddObserver(this);
453 virtual ~RemoveAutofillTester() {
454 personal_data_manager_
->RemoveObserver(this);
457 // Returns true if there are autofill profiles.
459 return !personal_data_manager_
->GetProfiles().empty() &&
460 !personal_data_manager_
->GetCreditCards().empty();
463 bool HasOrigin(const std::string
& origin
) {
464 const std::vector
<autofill::AutofillProfile
*>& profiles
=
465 personal_data_manager_
->GetProfiles();
466 for (std::vector
<autofill::AutofillProfile
*>::const_iterator it
=
468 it
!= profiles
.end(); ++it
) {
469 if ((*it
)->origin() == origin
)
473 const std::vector
<autofill::CreditCard
*>& credit_cards
=
474 personal_data_manager_
->GetCreditCards();
475 for (std::vector
<autofill::CreditCard
*>::const_iterator it
=
476 credit_cards
.begin();
477 it
!= credit_cards
.end(); ++it
) {
478 if ((*it
)->origin() == origin
)
485 // Add two profiles and two credit cards to the database. In each pair, one
486 // entry has a web origin and the other has a Chrome origin.
487 void AddProfilesAndCards() {
488 std::vector
<autofill::AutofillProfile
> profiles
;
489 autofill::AutofillProfile profile
;
490 profile
.set_guid(base::GenerateGUID());
491 profile
.set_origin(kWebOrigin
);
492 profile
.SetRawInfo(autofill::NAME_FIRST
, ASCIIToUTF16("Bob"));
493 profile
.SetRawInfo(autofill::NAME_LAST
, ASCIIToUTF16("Smith"));
494 profile
.SetRawInfo(autofill::ADDRESS_HOME_ZIP
, ASCIIToUTF16("94043"));
495 profile
.SetRawInfo(autofill::EMAIL_ADDRESS
,
496 ASCIIToUTF16("sue@example.com"));
497 profile
.SetRawInfo(autofill::COMPANY_NAME
, ASCIIToUTF16("Company X"));
498 profiles
.push_back(profile
);
500 profile
.set_guid(base::GenerateGUID());
501 profile
.set_origin(kChromeOrigin
);
502 profiles
.push_back(profile
);
504 personal_data_manager_
->SetProfiles(&profiles
);
505 base::MessageLoop::current()->Run();
507 std::vector
<autofill::CreditCard
> cards
;
508 autofill::CreditCard card
;
509 card
.set_guid(base::GenerateGUID());
510 card
.set_origin(kWebOrigin
);
511 card
.SetRawInfo(autofill::CREDIT_CARD_NUMBER
,
512 ASCIIToUTF16("1234-5678-9012-3456"));
513 cards
.push_back(card
);
515 card
.set_guid(base::GenerateGUID());
516 card
.set_origin(kChromeOrigin
);
517 cards
.push_back(card
);
519 personal_data_manager_
->SetCreditCards(&cards
);
520 base::MessageLoop::current()->Run();
524 virtual void OnPersonalDataChanged() OVERRIDE
{
525 base::MessageLoop::current()->Quit();
528 autofill::PersonalDataManager
* personal_data_manager_
;
529 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester
);
532 class RemoveLocalStorageTester
{
534 explicit RemoveLocalStorageTester(TestingProfile
* profile
)
535 : profile_(profile
), dom_storage_context_(NULL
) {
536 dom_storage_context_
=
537 content::BrowserContext::GetDefaultStoragePartition(profile
)->
538 GetDOMStorageContext();
541 // Returns true, if the given origin URL exists.
542 bool DOMStorageExistsForOrigin(const GURL
& origin
) {
543 GetLocalStorageUsage();
544 await_completion_
.BlockUntilNotified();
545 for (size_t i
= 0; i
< infos_
.size(); ++i
) {
546 if (origin
== infos_
[i
].origin
)
552 void AddDOMStorageTestData() {
553 // Note: This test depends on details of how the dom_storage library
554 // stores data in the host file system.
555 base::FilePath storage_path
=
556 profile_
->GetPath().AppendASCII("Local Storage");
557 base::CreateDirectory(storage_path
);
560 file_util::WriteFile(storage_path
.Append(kDomStorageOrigin1
), NULL
, 0);
561 file_util::WriteFile(storage_path
.Append(kDomStorageOrigin2
), NULL
, 0);
562 file_util::WriteFile(storage_path
.Append(kDomStorageOrigin3
), NULL
, 0);
563 file_util::WriteFile(storage_path
.Append(kDomStorageExt
), NULL
, 0);
565 // Tweak their dates.
566 base::Time now
= base::Time::Now();
567 base::TouchFile(storage_path
.Append(kDomStorageOrigin1
), now
, now
);
569 base::Time one_day_ago
= now
- base::TimeDelta::FromDays(1);
570 base::TouchFile(storage_path
.Append(kDomStorageOrigin2
),
571 one_day_ago
, one_day_ago
);
573 base::Time sixty_days_ago
= now
- base::TimeDelta::FromDays(60);
574 base::TouchFile(storage_path
.Append(kDomStorageOrigin3
),
575 sixty_days_ago
, sixty_days_ago
);
577 base::TouchFile(storage_path
.Append(kDomStorageExt
), now
, now
);
581 void GetLocalStorageUsage() {
582 dom_storage_context_
->GetLocalStorageUsage(
583 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage
,
584 base::Unretained(this)));
586 void OnGotLocalStorageUsage(
587 const std::vector
<content::LocalStorageUsageInfo
>& infos
) {
589 await_completion_
.Notify();
592 // We don't own these pointers.
593 TestingProfile
* profile_
;
594 content::DOMStorageContext
* dom_storage_context_
;
596 std::vector
<content::LocalStorageUsageInfo
> infos_
;
598 AwaitCompletionHelper await_completion_
;
600 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester
);
603 // Test Class ----------------------------------------------------------------
605 class BrowsingDataRemoverTest
: public testing::Test
,
606 public content::NotificationObserver
{
608 BrowsingDataRemoverTest()
609 : profile_(new TestingProfile()) {
610 registrar_
.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED
,
611 content::Source
<Profile
>(profile_
.get()));
614 virtual ~BrowsingDataRemoverTest() {
617 virtual void TearDown() {
618 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
619 // posts a message to the WEBKIT thread to delete some of its member
620 // variables. We need to ensure that the profile is destroyed, and that
621 // the message loop is cleared out, before destroying the threads and loop.
622 // Otherwise we leak memory.
624 base::MessageLoop::current()->RunUntilIdle();
627 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period
,
629 bool include_protected_origins
) {
630 BrowsingDataRemover
* remover
= BrowsingDataRemover::CreateForPeriod(
631 profile_
.get(), period
);
633 TestStoragePartition storage_partition
;
634 remover
->OverrideStoragePartitionForTesting(&storage_partition
);
636 AwaitCompletionHelper await_completion
;
637 remover
->AddObserver(&await_completion
);
639 called_with_details_
.reset(new BrowsingDataRemover::NotificationDetails());
641 // BrowsingDataRemover deletes itself when it completes.
642 int origin_set_mask
= BrowsingDataHelper::UNPROTECTED_WEB
;
643 if (include_protected_origins
)
644 origin_set_mask
|= BrowsingDataHelper::PROTECTED_WEB
;
645 remover
->Remove(remove_mask
, origin_set_mask
);
646 await_completion
.BlockUntilNotified();
648 // Save so we can verify later.
649 storage_partition_removal_data_
=
650 storage_partition
.GetStoragePartitionRemovalData();
653 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period
,
655 const GURL
& remove_origin
) {
656 BrowsingDataRemover
* remover
= BrowsingDataRemover::CreateForPeriod(
657 profile_
.get(), period
);
658 TestStoragePartition storage_partition
;
659 remover
->OverrideStoragePartitionForTesting(&storage_partition
);
661 AwaitCompletionHelper await_completion
;
662 remover
->AddObserver(&await_completion
);
664 called_with_details_
.reset(new BrowsingDataRemover::NotificationDetails());
666 // BrowsingDataRemover deletes itself when it completes.
667 remover
->RemoveImpl(remove_mask
, remove_origin
,
668 BrowsingDataHelper::UNPROTECTED_WEB
);
669 await_completion
.BlockUntilNotified();
671 // Save so we can verify later.
672 storage_partition_removal_data_
=
673 storage_partition
.GetStoragePartitionRemovalData();
676 TestingProfile
* GetProfile() {
677 return profile_
.get();
680 base::Time
GetBeginTime() {
681 return called_with_details_
->removal_begin
;
684 int GetRemovalMask() {
685 return called_with_details_
->removal_mask
;
688 int GetOriginSetMask() {
689 return called_with_details_
->origin_set_mask
;
692 StoragePartitionRemovalData
GetStoragePartitionRemovalData() {
693 return storage_partition_removal_data_
;
696 // content::NotificationObserver implementation.
697 virtual void Observe(int type
,
698 const content::NotificationSource
& source
,
699 const content::NotificationDetails
& details
) OVERRIDE
{
700 DCHECK_EQ(type
, chrome::NOTIFICATION_BROWSING_DATA_REMOVED
);
702 // We're not taking ownership of the details object, but storing a copy of
704 called_with_details_
.reset(new BrowsingDataRemover::NotificationDetails(
705 *content::Details
<BrowsingDataRemover::NotificationDetails
>(
708 registrar_
.RemoveAll();
712 scoped_ptr
<BrowsingDataRemover::NotificationDetails
> called_with_details_
;
713 content::NotificationRegistrar registrar_
;
715 content::TestBrowserThreadBundle thread_bundle_
;
716 scoped_ptr
<TestingProfile
> profile_
;
718 StoragePartitionRemovalData storage_partition_removal_data_
;
720 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest
);
723 // Tests ---------------------------------------------------------------------
725 TEST_F(BrowsingDataRemoverTest
, RemoveCookieForever
) {
726 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
727 BrowsingDataRemover::REMOVE_COOKIES
,
730 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES
, GetRemovalMask());
731 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
733 // Verify that storage partition was instructed to remove the cookies.
734 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
735 EXPECT_EQ(removal_data
.remove_mask
,
737 StoragePartition::REMOVE_DATA_MASK_COOKIES
));
738 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
740 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
741 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
742 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
745 TEST_F(BrowsingDataRemoverTest
, RemoveCookieLastHour
) {
746 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
747 BrowsingDataRemover::REMOVE_COOKIES
,
750 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES
, GetRemovalMask());
751 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
753 // Verify that storage partition was instructed to remove the cookies.
754 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
755 EXPECT_EQ(removal_data
.remove_mask
,
757 StoragePartition::REMOVE_DATA_MASK_COOKIES
));
758 // Removing with time period other than EVERYTHING should not clear
759 // persistent storage data.
760 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
762 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
&
763 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
));
764 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
765 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
768 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
769 TEST_F(BrowsingDataRemoverTest
, RemoveSafeBrowsingCookieForever
) {
770 RemoveSafeBrowsingCookieTester tester
;
773 ASSERT_TRUE(tester
.ContainsCookie());
775 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
776 BrowsingDataRemover::REMOVE_COOKIES
, false);
778 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES
, GetRemovalMask());
779 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
780 EXPECT_FALSE(tester
.ContainsCookie());
783 TEST_F(BrowsingDataRemoverTest
, RemoveSafeBrowsingCookieLastHour
) {
784 RemoveSafeBrowsingCookieTester tester
;
787 ASSERT_TRUE(tester
.ContainsCookie());
789 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
790 BrowsingDataRemover::REMOVE_COOKIES
, false);
792 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES
, GetRemovalMask());
793 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
794 // Removing with time period other than EVERYTHING should not clear safe
796 EXPECT_TRUE(tester
.ContainsCookie());
800 TEST_F(BrowsingDataRemoverTest
, RemoveServerBoundCertForever
) {
801 RemoveServerBoundCertTester
tester(GetProfile());
803 tester
.AddServerBoundCert(kTestOrigin1
);
804 EXPECT_EQ(0, tester
.ssl_config_changed_count());
805 EXPECT_EQ(1, tester
.ServerBoundCertCount());
807 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
808 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS
, false);
810 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS
, GetRemovalMask());
811 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
812 EXPECT_EQ(1, tester
.ssl_config_changed_count());
813 EXPECT_EQ(0, tester
.ServerBoundCertCount());
816 TEST_F(BrowsingDataRemoverTest
, RemoveServerBoundCertLastHour
) {
817 RemoveServerBoundCertTester
tester(GetProfile());
819 base::Time now
= base::Time::Now();
820 tester
.AddServerBoundCert(kTestOrigin1
);
821 tester
.AddServerBoundCertWithTimes(kTestOrigin2
,
822 now
- base::TimeDelta::FromHours(2),
824 EXPECT_EQ(0, tester
.ssl_config_changed_count());
825 EXPECT_EQ(2, tester
.ServerBoundCertCount());
827 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
828 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS
, false);
830 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS
, GetRemovalMask());
831 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
832 EXPECT_EQ(1, tester
.ssl_config_changed_count());
833 ASSERT_EQ(1, tester
.ServerBoundCertCount());
834 net::ServerBoundCertStore::ServerBoundCertList certs
;
835 tester
.GetCertList(&certs
);
836 ASSERT_EQ(1U, certs
.size());
837 EXPECT_EQ(kTestOrigin2
, certs
.front().server_identifier());
840 TEST_F(BrowsingDataRemoverTest
, RemoveUnprotectedLocalStorageForever
) {
842 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
843 new MockExtensionSpecialStoragePolicy
;
844 mock_policy
->AddProtected(kOrigin1
.GetOrigin());
845 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
847 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
848 BrowsingDataRemover::REMOVE_LOCAL_STORAGE
,
851 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE
, GetRemovalMask());
852 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
854 // Verify that storage partition was instructed to remove the data correctly.
855 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
856 EXPECT_EQ(removal_data
.remove_mask
,
858 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
));
859 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
861 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
862 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
863 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
865 // Check origin matcher.
866 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy
));
867 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy
));
868 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy
));
869 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginExt
, mock_policy
));
872 TEST_F(BrowsingDataRemoverTest
, RemoveProtectedLocalStorageForever
) {
874 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
875 new MockExtensionSpecialStoragePolicy
;
876 mock_policy
->AddProtected(kOrigin1
.GetOrigin());
877 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
879 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
880 BrowsingDataRemover::REMOVE_LOCAL_STORAGE
,
883 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE
, GetRemovalMask());
884 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
|
885 BrowsingDataHelper::PROTECTED_WEB
, GetOriginSetMask());
887 // Verify that storage partition was instructed to remove the data correctly.
888 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
889 EXPECT_EQ(removal_data
.remove_mask
,
891 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
));
892 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
894 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
895 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
896 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
898 // Check origin matcher all http origin will match since we specified
899 // both protected and unprotected.
900 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy
));
901 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy
));
902 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy
));
903 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginExt
, mock_policy
));
906 TEST_F(BrowsingDataRemoverTest
, RemoveLocalStorageForLastWeek
) {
907 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
908 new MockExtensionSpecialStoragePolicy
;
909 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
911 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK
,
912 BrowsingDataRemover::REMOVE_LOCAL_STORAGE
,
915 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE
, GetRemovalMask());
916 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
918 // Verify that storage partition was instructed to remove the data correctly.
919 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
920 EXPECT_EQ(removal_data
.remove_mask
,
922 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
));
923 // Persistent storage won't be deleted.
924 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
926 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
&
927 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
));
928 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
929 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
931 // Check origin matcher.
932 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy
));
933 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy
));
934 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy
));
935 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginExt
, mock_policy
));
938 TEST_F(BrowsingDataRemoverTest
, RemoveHistoryForever
) {
939 RemoveHistoryTester tester
;
940 ASSERT_TRUE(tester
.Init(GetProfile()));
942 tester
.AddHistory(kOrigin1
, base::Time::Now());
943 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
945 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
946 BrowsingDataRemover::REMOVE_HISTORY
, false);
948 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
949 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
950 EXPECT_FALSE(tester
.HistoryContainsURL(kOrigin1
));
953 TEST_F(BrowsingDataRemoverTest
, RemoveHistoryForLastHour
) {
954 RemoveHistoryTester tester
;
955 ASSERT_TRUE(tester
.Init(GetProfile()));
957 base::Time two_hours_ago
= base::Time::Now() - base::TimeDelta::FromHours(2);
959 tester
.AddHistory(kOrigin1
, base::Time::Now());
960 tester
.AddHistory(kOrigin2
, two_hours_ago
);
961 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
962 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
964 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
965 BrowsingDataRemover::REMOVE_HISTORY
, false);
967 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
968 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
969 EXPECT_FALSE(tester
.HistoryContainsURL(kOrigin1
));
970 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
973 // This should crash (DCHECK) in Debug, but death tests don't work properly
975 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
976 TEST_F(BrowsingDataRemoverTest
, RemoveHistoryProhibited
) {
977 RemoveHistoryTester tester
;
978 ASSERT_TRUE(tester
.Init(GetProfile()));
979 PrefService
* prefs
= GetProfile()->GetPrefs();
980 prefs
->SetBoolean(prefs::kAllowDeletingBrowserHistory
, false);
982 base::Time two_hours_ago
= base::Time::Now() - base::TimeDelta::FromHours(2);
984 tester
.AddHistory(kOrigin1
, base::Time::Now());
985 tester
.AddHistory(kOrigin2
, two_hours_ago
);
986 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
987 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
989 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
990 BrowsingDataRemover::REMOVE_HISTORY
, false);
991 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
992 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
994 // Nothing should have been deleted.
995 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
996 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1000 TEST_F(BrowsingDataRemoverTest
, RemoveMultipleTypes
) {
1001 // Add some history.
1002 RemoveHistoryTester history_tester
;
1003 ASSERT_TRUE(history_tester
.Init(GetProfile()));
1004 history_tester
.AddHistory(kOrigin1
, base::Time::Now());
1005 ASSERT_TRUE(history_tester
.HistoryContainsURL(kOrigin1
));
1007 int removal_mask
= BrowsingDataRemover::REMOVE_HISTORY
|
1008 BrowsingDataRemover::REMOVE_COOKIES
;
1010 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1011 removal_mask
, false);
1013 EXPECT_EQ(removal_mask
, GetRemovalMask());
1014 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1015 EXPECT_FALSE(history_tester
.HistoryContainsURL(kOrigin1
));
1017 // The cookie would be deleted throught the StorageParition, check if the
1018 // partition was requested to remove cookie.
1019 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1020 EXPECT_EQ(removal_data
.remove_mask
,
1021 static_cast<uint32
>(
1022 StoragePartition::REMOVE_DATA_MASK_COOKIES
));
1023 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1024 static_cast<uint32
>(
1025 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1028 // This should crash (DCHECK) in Debug, but death tests don't work properly
1030 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1031 TEST_F(BrowsingDataRemoverTest
, RemoveMultipleTypesHistoryProhibited
) {
1032 PrefService
* prefs
= GetProfile()->GetPrefs();
1033 prefs
->SetBoolean(prefs::kAllowDeletingBrowserHistory
, false);
1035 // Add some history.
1036 RemoveHistoryTester history_tester
;
1037 ASSERT_TRUE(history_tester
.Init(GetProfile()));
1038 history_tester
.AddHistory(kOrigin1
, base::Time::Now());
1039 ASSERT_TRUE(history_tester
.HistoryContainsURL(kOrigin1
));
1041 int removal_mask
= BrowsingDataRemover::REMOVE_HISTORY
|
1042 BrowsingDataRemover::REMOVE_COOKIES
;
1044 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
1045 removal_mask
, false);
1046 EXPECT_EQ(removal_mask
, GetRemovalMask());
1047 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1049 // 1/2. History should remain.
1050 EXPECT_TRUE(history_tester
.HistoryContainsURL(kOrigin1
));
1052 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if
1053 // the partition was requested to remove cookie.
1054 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1055 EXPECT_EQ(removal_data
.remove_mask
,
1056 static_cast<uint32
>(
1057 StoragePartition::REMOVE_DATA_MASK_COOKIES
));
1058 // Persistent storage won't be deleted, since EVERYTHING was not specified.
1059 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1060 static_cast<uint32
>(
1061 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
&
1062 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
));
1066 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverBoth
) {
1067 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1068 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1069 BrowsingDataRemover::REMOVE_WEBSQL
|
1070 BrowsingDataRemover::REMOVE_APPCACHE
|
1071 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1074 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1075 BrowsingDataRemover::REMOVE_WEBSQL
|
1076 BrowsingDataRemover::REMOVE_APPCACHE
|
1077 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1078 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1080 // Verify storage partition related stuffs.
1081 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1082 EXPECT_EQ(removal_data
.remove_mask
,
1083 static_cast<uint32
>(
1084 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1085 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1086 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1087 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1088 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1089 static_cast<uint32
>(
1090 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1091 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1094 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverOnlyTemporary
) {
1095 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
1096 new MockExtensionSpecialStoragePolicy
;
1097 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
1099 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1100 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1101 BrowsingDataRemover::REMOVE_WEBSQL
|
1102 BrowsingDataRemover::REMOVE_APPCACHE
|
1103 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1106 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1107 BrowsingDataRemover::REMOVE_WEBSQL
|
1108 BrowsingDataRemover::REMOVE_APPCACHE
|
1109 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1110 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1112 // Verify storage partition related stuffs.
1113 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1115 EXPECT_EQ(removal_data
.remove_mask
,
1116 static_cast<uint32
>(
1117 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1118 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1119 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1120 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1121 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1122 static_cast<uint32
>(
1123 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1124 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1126 // Check that all related origin data would be removed, that is, origin
1127 // matcher would match these origin.
1128 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy
));
1129 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy
));
1130 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy
));
1133 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverOnlyPersistent
) {
1134 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
1135 new MockExtensionSpecialStoragePolicy
;
1136 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
1138 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1139 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1140 BrowsingDataRemover::REMOVE_WEBSQL
|
1141 BrowsingDataRemover::REMOVE_APPCACHE
|
1142 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1145 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1146 BrowsingDataRemover::REMOVE_WEBSQL
|
1147 BrowsingDataRemover::REMOVE_APPCACHE
|
1148 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1149 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1151 // Verify storage partition related stuffs.
1152 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1154 EXPECT_EQ(removal_data
.remove_mask
,
1155 static_cast<uint32
>(
1156 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1157 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1158 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1159 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1160 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1161 static_cast<uint32
>(
1162 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1163 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1165 // Check that all related origin data would be removed, that is, origin
1166 // matcher would match these origin.
1167 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy
));
1168 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy
));
1169 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy
));
1172 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverNeither
) {
1173 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
1174 new MockExtensionSpecialStoragePolicy
;
1175 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
1178 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1179 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1180 BrowsingDataRemover::REMOVE_WEBSQL
|
1181 BrowsingDataRemover::REMOVE_APPCACHE
|
1182 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1185 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1186 BrowsingDataRemover::REMOVE_WEBSQL
|
1187 BrowsingDataRemover::REMOVE_APPCACHE
|
1188 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1189 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1191 // Verify storage partition related stuffs.
1192 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1194 EXPECT_EQ(removal_data
.remove_mask
,
1195 static_cast<uint32
>(
1196 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1197 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1198 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1199 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1200 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1201 static_cast<uint32
>(
1202 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1203 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1205 // Check that all related origin data would be removed, that is, origin
1206 // matcher would match these origin.
1207 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy
));
1208 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy
));
1209 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy
));
1212 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverSpecificOrigin
) {
1214 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING
,
1215 BrowsingDataRemover::REMOVE_APPCACHE
|
1216 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1217 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1218 BrowsingDataRemover::REMOVE_WEBSQL
,
1221 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE
|
1222 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1223 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1224 BrowsingDataRemover::REMOVE_WEBSQL
, GetRemovalMask());
1225 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1227 // Verify storage partition related stuffs.
1228 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1230 EXPECT_EQ(removal_data
.remove_mask
,
1231 static_cast<uint32
>(
1232 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1233 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1234 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1235 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1236 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1237 static_cast<uint32
>(
1238 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1239 EXPECT_EQ(removal_data
.remove_origin
, kOrigin1
);
1242 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForLastHour
) {
1243 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
1244 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1245 BrowsingDataRemover::REMOVE_WEBSQL
|
1246 BrowsingDataRemover::REMOVE_APPCACHE
|
1247 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1250 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1251 BrowsingDataRemover::REMOVE_WEBSQL
|
1252 BrowsingDataRemover::REMOVE_APPCACHE
|
1253 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1254 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1256 // Verify storage partition related stuffs.
1257 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1259 EXPECT_EQ(removal_data
.remove_mask
,
1260 static_cast<uint32
>(
1261 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1262 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1263 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1264 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1266 // Persistent data would be left out since we are not removing from
1267 // beginning of time.
1268 uint32 expected_quota_mask
=
1269 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
;
1270 EXPECT_EQ(removal_data
.quota_storage_remove_mask
, expected_quota_mask
);
1271 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1272 // Check removal begin time.
1273 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
1276 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForLastWeek
) {
1277 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK
,
1278 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1279 BrowsingDataRemover::REMOVE_WEBSQL
|
1280 BrowsingDataRemover::REMOVE_APPCACHE
|
1281 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1284 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1285 BrowsingDataRemover::REMOVE_WEBSQL
|
1286 BrowsingDataRemover::REMOVE_APPCACHE
|
1287 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1288 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1290 // Verify storage partition related stuffs.
1291 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1293 EXPECT_EQ(removal_data
.remove_mask
,
1294 static_cast<uint32
>(
1295 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1296 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1297 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1298 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1300 // Persistent data would be left out since we are not removing from
1301 // beginning of time.
1302 uint32 expected_quota_mask
=
1303 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
;
1304 EXPECT_EQ(removal_data
.quota_storage_remove_mask
, expected_quota_mask
);
1305 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1306 // Check removal begin time.
1307 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
1310 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedUnprotectedOrigins
) {
1311 // Protect kOrigin1.
1312 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
1313 new MockExtensionSpecialStoragePolicy
;
1314 mock_policy
->AddProtected(kOrigin1
.GetOrigin());
1315 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
1317 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1318 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1319 BrowsingDataRemover::REMOVE_WEBSQL
|
1320 BrowsingDataRemover::REMOVE_APPCACHE
|
1321 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1324 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1325 BrowsingDataRemover::REMOVE_WEBSQL
|
1326 BrowsingDataRemover::REMOVE_APPCACHE
|
1327 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1328 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1330 // Verify storage partition related stuffs.
1331 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1333 EXPECT_EQ(removal_data
.remove_mask
,
1334 static_cast<uint32
>(
1335 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1336 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1337 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1338 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1339 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1340 static_cast<uint32
>(
1341 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1342 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1344 // Check OriginMatcherFunction, |kOrigin1| would not match mask since it
1346 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy
));
1347 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy
));
1348 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy
));
1351 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedProtectedSpecificOrigin
) {
1352 // Protect kOrigin1.
1353 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
1354 new MockExtensionSpecialStoragePolicy
;
1355 mock_policy
->AddProtected(kOrigin1
.GetOrigin());
1356 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
1358 // Try to remove kOrigin1. Expect failure.
1359 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING
,
1360 BrowsingDataRemover::REMOVE_APPCACHE
|
1361 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1362 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1363 BrowsingDataRemover::REMOVE_WEBSQL
,
1366 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE
|
1367 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1368 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1369 BrowsingDataRemover::REMOVE_WEBSQL
, GetRemovalMask());
1370 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1372 // Verify storage partition related stuffs.
1373 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1375 EXPECT_EQ(removal_data
.remove_mask
,
1376 static_cast<uint32
>(
1377 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1378 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1379 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1380 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1381 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1382 static_cast<uint32
>(
1383 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1384 EXPECT_EQ(removal_data
.remove_origin
, kOrigin1
);
1386 // Check OriginMatcherFunction, |kOrigin1| would not match mask since it
1388 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy
));
1389 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy
));
1390 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy
));
1393 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedProtectedOrigins
) {
1394 // Protect kOrigin1.
1395 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
1396 new MockExtensionSpecialStoragePolicy
;
1397 mock_policy
->AddProtected(kOrigin1
.GetOrigin());
1398 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
1400 // Try to remove kOrigin1. Expect success.
1401 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1402 BrowsingDataRemover::REMOVE_APPCACHE
|
1403 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1404 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1405 BrowsingDataRemover::REMOVE_WEBSQL
,
1408 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE
|
1409 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1410 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1411 BrowsingDataRemover::REMOVE_WEBSQL
, GetRemovalMask());
1412 EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB
|
1413 BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1415 // Verify storage partition related stuffs.
1416 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1418 EXPECT_EQ(removal_data
.remove_mask
,
1419 static_cast<uint32
>(
1420 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1421 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1422 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1423 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1424 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1425 static_cast<uint32
>(
1426 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1427 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1429 // Check OriginMatcherFunction, |kOrigin1| would match mask since we
1430 // would have 'protected' specified in origin_set_mask.
1431 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy
));
1432 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy
));
1433 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy
));
1436 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedIgnoreExtensionsAndDevTools
) {
1437 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy
=
1438 new MockExtensionSpecialStoragePolicy
;
1439 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy
.get());
1441 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1442 BrowsingDataRemover::REMOVE_APPCACHE
|
1443 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1444 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1445 BrowsingDataRemover::REMOVE_WEBSQL
,
1448 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE
|
1449 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1450 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1451 BrowsingDataRemover::REMOVE_WEBSQL
, GetRemovalMask());
1452 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1454 // Verify storage partition related stuffs.
1455 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1457 EXPECT_EQ(removal_data
.remove_mask
,
1458 static_cast<uint32
>(
1459 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1460 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1461 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1462 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
));
1463 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1464 static_cast<uint32
>(
1465 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
));
1466 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1468 // Check that extension and devtools data wouldn't be removed, that is,
1469 // origin matcher would not match these origin.
1470 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginExt
, mock_policy
));
1471 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginDevTools
, mock_policy
));
1474 TEST_F(BrowsingDataRemoverTest
, OriginBasedHistoryRemoval
) {
1475 RemoveHistoryTester tester
;
1476 ASSERT_TRUE(tester
.Init(GetProfile()));
1478 base::Time two_hours_ago
= base::Time::Now() - base::TimeDelta::FromHours(2);
1480 tester
.AddHistory(kOrigin1
, base::Time::Now());
1481 tester
.AddHistory(kOrigin2
, two_hours_ago
);
1482 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1483 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1485 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING
,
1486 BrowsingDataRemover::REMOVE_HISTORY
, kOrigin2
);
1488 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1489 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1491 // Nothing should have been deleted.
1492 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1493 EXPECT_FALSE(tester
.HistoryContainsURL(kOrigin2
));
1496 TEST_F(BrowsingDataRemoverTest
, OriginAndTimeBasedHistoryRemoval
) {
1497 RemoveHistoryTester tester
;
1498 ASSERT_TRUE(tester
.Init(GetProfile()));
1500 base::Time two_hours_ago
= base::Time::Now() - base::TimeDelta::FromHours(2);
1502 tester
.AddHistory(kOrigin1
, base::Time::Now());
1503 tester
.AddHistory(kOrigin2
, two_hours_ago
);
1504 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1505 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1507 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR
,
1508 BrowsingDataRemover::REMOVE_HISTORY
, kOrigin2
);
1510 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1511 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1512 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1513 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1516 // Verify that clearing autofill form data works.
1517 TEST_F(BrowsingDataRemoverTest
, AutofillRemovalLastHour
) {
1518 GetProfile()->CreateWebDataService();
1519 RemoveAutofillTester
tester(GetProfile());
1521 ASSERT_FALSE(tester
.HasProfile());
1522 tester
.AddProfilesAndCards();
1523 ASSERT_TRUE(tester
.HasProfile());
1525 BlockUntilBrowsingDataRemoved(
1526 BrowsingDataRemover::LAST_HOUR
,
1527 BrowsingDataRemover::REMOVE_FORM_DATA
, false);
1529 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA
, GetRemovalMask());
1530 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1531 ASSERT_FALSE(tester
.HasProfile());
1534 TEST_F(BrowsingDataRemoverTest
, AutofillRemovalEverything
) {
1535 GetProfile()->CreateWebDataService();
1536 RemoveAutofillTester
tester(GetProfile());
1538 ASSERT_FALSE(tester
.HasProfile());
1539 tester
.AddProfilesAndCards();
1540 ASSERT_TRUE(tester
.HasProfile());
1542 BlockUntilBrowsingDataRemoved(
1543 BrowsingDataRemover::EVERYTHING
,
1544 BrowsingDataRemover::REMOVE_FORM_DATA
, false);
1546 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA
, GetRemovalMask());
1547 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1548 ASSERT_FALSE(tester
.HasProfile());
1551 // Verify that clearing autofill form data works.
1552 TEST_F(BrowsingDataRemoverTest
, AutofillOriginsRemovedWithHistory
) {
1553 GetProfile()->CreateWebDataService();
1554 RemoveAutofillTester
tester(GetProfile());
1556 tester
.AddProfilesAndCards();
1557 EXPECT_FALSE(tester
.HasOrigin(std::string()));
1558 EXPECT_TRUE(tester
.HasOrigin(kWebOrigin
));
1559 EXPECT_TRUE(tester
.HasOrigin(kChromeOrigin
));
1561 BlockUntilBrowsingDataRemoved(
1562 BrowsingDataRemover::LAST_HOUR
,
1563 BrowsingDataRemover::REMOVE_HISTORY
, false);
1565 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1566 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1567 EXPECT_TRUE(tester
.HasOrigin(std::string()));
1568 EXPECT_FALSE(tester
.HasOrigin(kWebOrigin
));
1569 EXPECT_TRUE(tester
.HasOrigin(kChromeOrigin
));
1572 #if defined(OS_CHROMEOS)
1573 TEST_F(BrowsingDataRemoverTest
, ContentProtectionPlatformKeysRemoval
) {
1574 chromeos::ScopedTestDeviceSettingsService test_device_settings_service
;
1575 chromeos::ScopedTestCrosSettings test_cros_settings
;
1576 chromeos::MockUserManager
* mock_user_manager
=
1577 new testing::NiceMock
<chromeos::MockUserManager
>();
1578 mock_user_manager
->SetActiveUser("test@example.com");
1579 chromeos::ScopedUserManagerEnabler
user_manager_enabler(mock_user_manager
);
1581 chromeos::FakeDBusThreadManager
* fake_dbus_manager
=
1582 new chromeos::FakeDBusThreadManager
;
1583 chromeos::MockCryptohomeClient
* cryptohome_client
=
1584 new chromeos::MockCryptohomeClient
;
1585 fake_dbus_manager
->SetCryptohomeClient(
1586 scoped_ptr
<chromeos::CryptohomeClient
>(cryptohome_client
));
1587 chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_manager
);
1589 // Expect exactly one call. No calls means no attempt to delete keys and more
1590 // than one call means a significant performance problem.
1591 EXPECT_CALL(*cryptohome_client
, TpmAttestationDeleteKeys(_
, _
, _
, _
))
1592 .WillOnce(WithArgs
<3>(Invoke(FakeDBusCall
)));
1594 BlockUntilBrowsingDataRemoved(
1595 BrowsingDataRemover::EVERYTHING
,
1596 BrowsingDataRemover::REMOVE_CONTENT_LICENSES
, false);
1598 chromeos::DBusThreadManager::Shutdown();