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/domain_reliability/service_factory.h"
24 #include "chrome/browser/history/history_service_factory.h"
25 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
26 #include "chrome/common/pref_names.h"
27 #include "chrome/test/base/testing_browser_process.h"
28 #include "chrome/test/base/testing_profile.h"
29 #include "components/autofill/core/browser/autofill_profile.h"
30 #include "components/autofill/core/browser/autofill_test_utils.h"
31 #include "components/autofill/core/browser/credit_card.h"
32 #include "components/autofill/core/browser/personal_data_manager.h"
33 #include "components/autofill/core/browser/personal_data_manager_observer.h"
34 #include "components/domain_reliability/clear_mode.h"
35 #include "components/domain_reliability/monitor.h"
36 #include "components/domain_reliability/service.h"
37 #include "components/history/core/browser/history_service.h"
38 #include "content/public/browser/cookie_store_factory.h"
39 #include "content/public/browser/dom_storage_context.h"
40 #include "content/public/browser/local_storage_usage_info.h"
41 #include "content/public/browser/storage_partition.h"
42 #include "content/public/test/test_browser_thread.h"
43 #include "content/public/test/test_browser_thread_bundle.h"
44 #include "content/public/test/test_utils.h"
45 #include "net/cookies/cookie_store.h"
46 #include "net/ssl/channel_id_service.h"
47 #include "net/ssl/channel_id_store.h"
48 #include "net/ssl/ssl_client_cert_type.h"
49 #include "net/url_request/url_request_context.h"
50 #include "net/url_request/url_request_context_getter.h"
51 #include "testing/gmock/include/gmock/gmock.h"
52 #include "testing/gtest/include/gtest/gtest.h"
54 #if defined(OS_CHROMEOS)
55 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
56 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
57 #include "chrome/browser/chromeos/settings/cros_settings.h"
58 #include "chrome/browser/chromeos/settings/device_settings_service.h"
59 #include "chromeos/dbus/dbus_thread_manager.h"
60 #include "chromeos/dbus/mock_cryptohome_client.h"
63 #if defined(ENABLE_EXTENSIONS)
64 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
67 class MockExtensionSpecialStoragePolicy
;
69 using content::BrowserThread
;
70 using content::StoragePartition
;
71 using domain_reliability::CLEAR_BEACONS
;
72 using domain_reliability::CLEAR_CONTEXTS
;
73 using domain_reliability::DomainReliabilityClearMode
;
74 using domain_reliability::DomainReliabilityMonitor
;
75 using domain_reliability::DomainReliabilityService
;
76 using domain_reliability::DomainReliabilityServiceFactory
;
78 using testing::Invoke
;
79 using testing::WithArgs
;
83 const char kTestOrigin1
[] = "http://host1:1/";
84 const char kTestOrigin2
[] = "http://host2:1/";
85 const char kTestOrigin3
[] = "http://host3:1/";
86 const char kTestOriginExt
[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
87 const char kTestOriginDevTools
[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
90 const char kChromeOrigin
[] = "Chrome settings";
91 const char kWebOrigin
[] = "https://www.example.com/";
93 const GURL
kOrigin1(kTestOrigin1
);
94 const GURL
kOrigin2(kTestOrigin2
);
95 const GURL
kOrigin3(kTestOrigin3
);
96 const GURL
kOriginExt(kTestOriginExt
);
97 const GURL
kOriginDevTools(kTestOriginDevTools
);
99 const base::FilePath::CharType kDomStorageOrigin1
[] =
100 FILE_PATH_LITERAL("http_host1_1.localstorage");
102 const base::FilePath::CharType kDomStorageOrigin2
[] =
103 FILE_PATH_LITERAL("http_host2_1.localstorage");
105 const base::FilePath::CharType kDomStorageOrigin3
[] =
106 FILE_PATH_LITERAL("http_host3_1.localstorage");
108 const base::FilePath::CharType kDomStorageExt
[] = FILE_PATH_LITERAL(
109 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
111 #if defined(OS_CHROMEOS)
112 void FakeDBusCall(const chromeos::BoolDBusMethodCallback
& callback
) {
113 base::MessageLoop::current()->PostTask(
115 base::Bind(callback
, chromeos::DBUS_METHOD_CALL_SUCCESS
, true));
119 struct StoragePartitionRemovalData
{
121 uint32 quota_storage_remove_mask
;
123 base::Time remove_begin
;
124 base::Time remove_end
;
125 StoragePartition::OriginMatcherFunction origin_matcher
;
127 StoragePartitionRemovalData() : remove_mask(0),
128 quota_storage_remove_mask(0) {}
131 class TestStoragePartition
: public StoragePartition
{
133 TestStoragePartition() {}
134 ~TestStoragePartition() override
{}
136 // content::StoragePartition implementation.
137 base::FilePath
GetPath() override
{ return base::FilePath(); }
138 net::URLRequestContextGetter
* GetURLRequestContext() override
{ return NULL
; }
139 net::URLRequestContextGetter
* GetMediaURLRequestContext() override
{
142 storage::QuotaManager
* GetQuotaManager() override
{ return NULL
; }
143 content::AppCacheService
* GetAppCacheService() override
{ return NULL
; }
144 storage::FileSystemContext
* GetFileSystemContext() override
{ return NULL
; }
145 storage::DatabaseTracker
* GetDatabaseTracker() override
{ return NULL
; }
146 content::DOMStorageContext
* GetDOMStorageContext() override
{ return NULL
; }
147 content::IndexedDBContext
* GetIndexedDBContext() override
{ return NULL
; }
148 content::ServiceWorkerContext
* GetServiceWorkerContext() override
{
151 content::GeofencingManager
* GetGeofencingManager() override
{ return NULL
; }
152 content::NavigatorConnectContext
* GetNavigatorConnectContext() override
{
156 content::PlatformNotificationContext
* GetPlatformNotificationContext()
161 content::HostZoomMap
* GetHostZoomMap() override
{ return NULL
; }
162 content::HostZoomLevelContext
* GetHostZoomLevelContext() override
{
165 content::ZoomLevelDelegate
* GetZoomLevelDelegate() override
{ return NULL
; }
167 void ClearDataForOrigin(uint32 remove_mask
,
168 uint32 quota_storage_remove_mask
,
169 const GURL
& storage_origin
,
170 net::URLRequestContextGetter
* rq_context
,
171 const base::Closure
& callback
) override
{
172 BrowserThread::PostTask(BrowserThread::UI
,
174 base::Bind(&TestStoragePartition::AsyncRunCallback
,
175 base::Unretained(this),
179 void ClearData(uint32 remove_mask
,
180 uint32 quota_storage_remove_mask
,
181 const GURL
& storage_origin
,
182 const OriginMatcherFunction
& origin_matcher
,
183 const base::Time begin
,
184 const base::Time end
,
185 const base::Closure
& callback
) override
{
186 // Store stuff to verify parameters' correctness later.
187 storage_partition_removal_data_
.remove_mask
= remove_mask
;
188 storage_partition_removal_data_
.quota_storage_remove_mask
=
189 quota_storage_remove_mask
;
190 storage_partition_removal_data_
.remove_origin
= storage_origin
;
191 storage_partition_removal_data_
.remove_begin
= begin
;
192 storage_partition_removal_data_
.remove_end
= end
;
193 storage_partition_removal_data_
.origin_matcher
= origin_matcher
;
195 BrowserThread::PostTask(
198 base::Bind(&TestStoragePartition::AsyncRunCallback
,
199 base::Unretained(this), callback
));
202 StoragePartitionRemovalData
GetStoragePartitionRemovalData() {
203 return storage_partition_removal_data_
;
207 void AsyncRunCallback(const base::Closure
& callback
) {
211 StoragePartitionRemovalData storage_partition_removal_data_
;
213 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition
);
218 // Testers -------------------------------------------------------------------
220 class RemoveCookieTester
{
222 RemoveCookieTester() : get_cookie_success_(false), cookie_store_(NULL
) {
225 // Returns true, if the given cookie exists in the cookie store.
226 bool ContainsCookie() {
227 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
228 new content::MessageLoopRunner
;
229 quit_closure_
= message_loop_runner
->QuitClosure();
230 get_cookie_success_
= false;
231 cookie_store_
->GetCookiesWithOptionsAsync(
232 kOrigin1
, net::CookieOptions(),
233 base::Bind(&RemoveCookieTester::GetCookieCallback
,
234 base::Unretained(this)));
235 message_loop_runner
->Run();
236 return get_cookie_success_
;
240 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
241 new content::MessageLoopRunner
;
242 quit_closure_
= message_loop_runner
->QuitClosure();
243 cookie_store_
->SetCookieWithOptionsAsync(
244 kOrigin1
, "A=1", net::CookieOptions(),
245 base::Bind(&RemoveCookieTester::SetCookieCallback
,
246 base::Unretained(this)));
247 message_loop_runner
->Run();
251 void SetMonster(net::CookieStore
* monster
) {
252 cookie_store_
= monster
;
256 void GetCookieCallback(const std::string
& cookies
) {
257 if (cookies
== "A=1") {
258 get_cookie_success_
= true;
260 EXPECT_EQ("", cookies
);
261 get_cookie_success_
= false;
266 void SetCookieCallback(bool result
) {
271 bool get_cookie_success_
;
272 base::Closure quit_closure_
;
273 net::CookieStore
* cookie_store_
;
275 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester
);
278 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
279 class RemoveSafeBrowsingCookieTester
: public RemoveCookieTester
{
281 RemoveSafeBrowsingCookieTester()
282 : browser_process_(TestingBrowserProcess::GetGlobal()) {
283 scoped_refptr
<SafeBrowsingService
> sb_service
=
284 SafeBrowsingService::CreateSafeBrowsingService();
285 browser_process_
->SetSafeBrowsingService(sb_service
.get());
286 sb_service
->Initialize();
287 base::MessageLoop::current()->RunUntilIdle();
289 // Create a cookiemonster that does not have persistant storage, and replace
290 // the SafeBrowsingService created one with it.
291 net::CookieStore
* monster
=
292 content::CreateCookieStore(content::CookieStoreConfig());
293 sb_service
->url_request_context()->GetURLRequestContext()->
294 set_cookie_store(monster
);
298 virtual ~RemoveSafeBrowsingCookieTester() {
299 browser_process_
->safe_browsing_service()->ShutDown();
300 base::MessageLoop::current()->RunUntilIdle();
301 browser_process_
->SetSafeBrowsingService(NULL
);
305 TestingBrowserProcess
* browser_process_
;
307 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester
);
311 class RemoveChannelIDTester
: public net::SSLConfigService::Observer
{
313 explicit RemoveChannelIDTester(TestingProfile
* profile
)
314 : ssl_config_changed_count_(0) {
315 channel_id_service_
= profile
->GetRequestContext()->
316 GetURLRequestContext()->channel_id_service();
317 ssl_config_service_
= profile
->GetSSLConfigService();
318 ssl_config_service_
->AddObserver(this);
321 ~RemoveChannelIDTester() override
{
322 ssl_config_service_
->RemoveObserver(this);
325 int ChannelIDCount() {
326 return channel_id_service_
->cert_count();
329 // Add a server bound cert for |server| with specific creation and expiry
330 // times. The cert and key data will be filled with dummy values.
331 void AddChannelIDWithTimes(const std::string
& server_identifier
,
332 base::Time creation_time
,
333 base::Time expiration_time
) {
334 GetChannelIDStore()->SetChannelID(server_identifier
,
341 // Add a server bound cert for |server|, with the current time as the
342 // creation time. The cert and key data will be filled with dummy values.
343 void AddChannelID(const std::string
& server_identifier
) {
344 base::Time now
= base::Time::Now();
345 AddChannelIDWithTimes(server_identifier
,
347 now
+ base::TimeDelta::FromDays(1));
350 void GetChannelIDList(net::ChannelIDStore::ChannelIDList
* channel_ids
) {
351 GetChannelIDStore()->GetAllChannelIDs(
352 base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback
,
356 net::ChannelIDStore
* GetChannelIDStore() {
357 return channel_id_service_
->GetChannelIDStore();
360 int ssl_config_changed_count() const {
361 return ssl_config_changed_count_
;
364 // net::SSLConfigService::Observer implementation:
365 void OnSSLConfigChanged() override
{ ssl_config_changed_count_
++; }
368 static void GetAllChannelIDsCallback(
369 net::ChannelIDStore::ChannelIDList
* dest
,
370 const net::ChannelIDStore::ChannelIDList
& result
) {
374 net::ChannelIDService
* channel_id_service_
;
375 scoped_refptr
<net::SSLConfigService
> ssl_config_service_
;
376 int ssl_config_changed_count_
;
378 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester
);
381 class RemoveHistoryTester
{
383 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL
) {}
385 bool Init(TestingProfile
* profile
) WARN_UNUSED_RESULT
{
386 if (!profile
->CreateHistoryService(true, false))
388 history_service_
= HistoryServiceFactory::GetForProfile(
389 profile
, ServiceAccessType::EXPLICIT_ACCESS
);
393 // Returns true, if the given URL exists in the history service.
394 bool HistoryContainsURL(const GURL
& url
) {
395 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
396 new content::MessageLoopRunner
;
397 quit_closure_
= message_loop_runner
->QuitClosure();
398 history_service_
->QueryURL(
401 base::Bind(&RemoveHistoryTester::SaveResultAndQuit
,
402 base::Unretained(this)),
404 message_loop_runner
->Run();
405 return query_url_success_
;
408 void AddHistory(const GURL
& url
, base::Time time
) {
409 history_service_
->AddPage(url
, time
, NULL
, 0, GURL(),
410 history::RedirectList(), ui::PAGE_TRANSITION_LINK
,
411 history::SOURCE_BROWSED
, false);
415 // Callback for HistoryService::QueryURL.
416 void SaveResultAndQuit(bool success
,
417 const history::URLRow
&,
418 const history::VisitVector
&) {
419 query_url_success_
= success
;
423 // For History requests.
424 base::CancelableTaskTracker tracker_
;
425 bool query_url_success_
;
426 base::Closure quit_closure_
;
428 // TestingProfile owns the history service; we shouldn't delete it.
429 history::HistoryService
* history_service_
;
431 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester
);
434 class RemoveAutofillTester
: public autofill::PersonalDataManagerObserver
{
436 explicit RemoveAutofillTester(TestingProfile
* profile
)
437 : personal_data_manager_(
438 autofill::PersonalDataManagerFactory::GetForProfile(profile
)) {
439 autofill::test::DisableSystemServices(profile
->GetPrefs());
440 personal_data_manager_
->AddObserver(this);
443 ~RemoveAutofillTester() override
{
444 personal_data_manager_
->RemoveObserver(this);
447 // Returns true if there are autofill profiles.
449 return !personal_data_manager_
->GetProfiles().empty() &&
450 !personal_data_manager_
->GetCreditCards().empty();
453 bool HasOrigin(const std::string
& origin
) {
454 const std::vector
<autofill::AutofillProfile
*>& profiles
=
455 personal_data_manager_
->GetProfiles();
456 for (std::vector
<autofill::AutofillProfile
*>::const_iterator it
=
458 it
!= profiles
.end(); ++it
) {
459 if ((*it
)->origin() == origin
)
463 const std::vector
<autofill::CreditCard
*>& credit_cards
=
464 personal_data_manager_
->GetCreditCards();
465 for (std::vector
<autofill::CreditCard
*>::const_iterator it
=
466 credit_cards
.begin();
467 it
!= credit_cards
.end(); ++it
) {
468 if ((*it
)->origin() == origin
)
475 // Add two profiles and two credit cards to the database. In each pair, one
476 // entry has a web origin and the other has a Chrome origin.
477 void AddProfilesAndCards() {
478 std::vector
<autofill::AutofillProfile
> profiles
;
479 autofill::AutofillProfile profile
;
480 profile
.set_guid(base::GenerateGUID());
481 profile
.set_origin(kWebOrigin
);
482 profile
.SetRawInfo(autofill::NAME_FIRST
, base::ASCIIToUTF16("Bob"));
483 profile
.SetRawInfo(autofill::NAME_LAST
, base::ASCIIToUTF16("Smith"));
484 profile
.SetRawInfo(autofill::ADDRESS_HOME_ZIP
, base::ASCIIToUTF16("94043"));
485 profile
.SetRawInfo(autofill::EMAIL_ADDRESS
,
486 base::ASCIIToUTF16("sue@example.com"));
487 profile
.SetRawInfo(autofill::COMPANY_NAME
, base::ASCIIToUTF16("Company X"));
488 profiles
.push_back(profile
);
490 profile
.set_guid(base::GenerateGUID());
491 profile
.set_origin(kChromeOrigin
);
492 profiles
.push_back(profile
);
494 personal_data_manager_
->SetProfiles(&profiles
);
495 base::MessageLoop::current()->Run();
497 std::vector
<autofill::CreditCard
> cards
;
498 autofill::CreditCard card
;
499 card
.set_guid(base::GenerateGUID());
500 card
.set_origin(kWebOrigin
);
501 card
.SetRawInfo(autofill::CREDIT_CARD_NUMBER
,
502 base::ASCIIToUTF16("1234-5678-9012-3456"));
503 cards
.push_back(card
);
505 card
.set_guid(base::GenerateGUID());
506 card
.set_origin(kChromeOrigin
);
507 cards
.push_back(card
);
509 personal_data_manager_
->SetCreditCards(&cards
);
510 base::MessageLoop::current()->Run();
514 void OnPersonalDataChanged() override
{
515 base::MessageLoop::current()->Quit();
518 autofill::PersonalDataManager
* personal_data_manager_
;
519 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester
);
522 class RemoveLocalStorageTester
{
524 explicit RemoveLocalStorageTester(TestingProfile
* profile
)
525 : profile_(profile
), dom_storage_context_(NULL
) {
526 dom_storage_context_
=
527 content::BrowserContext::GetDefaultStoragePartition(profile
)->
528 GetDOMStorageContext();
531 // Returns true, if the given origin URL exists.
532 bool DOMStorageExistsForOrigin(const GURL
& origin
) {
533 scoped_refptr
<content::MessageLoopRunner
> message_loop_runner
=
534 new content::MessageLoopRunner
;
535 quit_closure_
= message_loop_runner
->QuitClosure();
536 GetLocalStorageUsage();
537 message_loop_runner
->Run();
538 for (size_t i
= 0; i
< infos_
.size(); ++i
) {
539 if (origin
== infos_
[i
].origin
)
545 void AddDOMStorageTestData() {
546 // Note: This test depends on details of how the dom_storage library
547 // stores data in the host file system.
548 base::FilePath storage_path
=
549 profile_
->GetPath().AppendASCII("Local Storage");
550 base::CreateDirectory(storage_path
);
553 base::WriteFile(storage_path
.Append(kDomStorageOrigin1
), NULL
, 0);
554 base::WriteFile(storage_path
.Append(kDomStorageOrigin2
), NULL
, 0);
555 base::WriteFile(storage_path
.Append(kDomStorageOrigin3
), NULL
, 0);
556 base::WriteFile(storage_path
.Append(kDomStorageExt
), NULL
, 0);
558 // Tweak their dates.
559 base::Time now
= base::Time::Now();
560 base::TouchFile(storage_path
.Append(kDomStorageOrigin1
), now
, now
);
562 base::Time one_day_ago
= now
- base::TimeDelta::FromDays(1);
563 base::TouchFile(storage_path
.Append(kDomStorageOrigin2
),
564 one_day_ago
, one_day_ago
);
566 base::Time sixty_days_ago
= now
- base::TimeDelta::FromDays(60);
567 base::TouchFile(storage_path
.Append(kDomStorageOrigin3
),
568 sixty_days_ago
, sixty_days_ago
);
570 base::TouchFile(storage_path
.Append(kDomStorageExt
), now
, now
);
574 void GetLocalStorageUsage() {
575 dom_storage_context_
->GetLocalStorageUsage(
576 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage
,
577 base::Unretained(this)));
579 void OnGotLocalStorageUsage(
580 const std::vector
<content::LocalStorageUsageInfo
>& infos
) {
585 // We don't own these pointers.
586 TestingProfile
* profile_
;
587 content::DOMStorageContext
* dom_storage_context_
;
589 std::vector
<content::LocalStorageUsageInfo
> infos_
;
590 base::Closure quit_closure_
;
592 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester
);
595 class MockDomainReliabilityService
: public DomainReliabilityService
{
597 MockDomainReliabilityService() : clear_count_(0) {}
599 ~MockDomainReliabilityService() override
{}
601 scoped_ptr
<DomainReliabilityMonitor
> CreateMonitor(
602 scoped_refptr
<base::SingleThreadTaskRunner
> network_task_runner
)
605 return scoped_ptr
<DomainReliabilityMonitor
>();
608 void ClearBrowsingData(DomainReliabilityClearMode clear_mode
,
609 const base::Closure
& callback
) override
{
611 last_clear_mode_
= clear_mode
;
615 void GetWebUIData(const base::Callback
<void(scoped_ptr
<base::Value
>)>&
616 callback
) const override
{
620 int clear_count() const { return clear_count_
; }
622 DomainReliabilityClearMode
last_clear_mode() const {
623 return last_clear_mode_
;
627 unsigned clear_count_
;
628 DomainReliabilityClearMode last_clear_mode_
;
631 struct TestingDomainReliabilityServiceFactoryUserData
632 : public base::SupportsUserData::Data
{
633 TestingDomainReliabilityServiceFactoryUserData(
634 content::BrowserContext
* context
,
635 MockDomainReliabilityService
* service
)
639 ~TestingDomainReliabilityServiceFactoryUserData() override
{}
641 content::BrowserContext
* const context
;
642 MockDomainReliabilityService
* const service
;
645 static const void* kKey
;
649 const void* TestingDomainReliabilityServiceFactoryUserData::kKey
=
650 &TestingDomainReliabilityServiceFactoryUserData::kKey
;
652 KeyedService
* TestingDomainReliabilityServiceFactoryFunction(
653 content::BrowserContext
* context
) {
654 const void* kKey
= TestingDomainReliabilityServiceFactoryUserData::kKey
;
656 TestingDomainReliabilityServiceFactoryUserData
* data
=
657 static_cast<TestingDomainReliabilityServiceFactoryUserData
*>(
658 context
->GetUserData(kKey
));
660 EXPECT_EQ(data
->context
, context
);
661 EXPECT_FALSE(data
->attached
);
663 data
->attached
= true;
664 return data
->service
;
667 class ClearDomainReliabilityTester
{
669 explicit ClearDomainReliabilityTester(TestingProfile
* profile
) :
671 mock_service_(new MockDomainReliabilityService()) {
675 unsigned clear_count() const { return mock_service_
->clear_count(); }
677 DomainReliabilityClearMode
last_clear_mode() const {
678 return mock_service_
->last_clear_mode();
682 void AttachService() {
683 const void* kKey
= TestingDomainReliabilityServiceFactoryUserData::kKey
;
685 // Attach kludgey UserData struct to profile.
686 TestingDomainReliabilityServiceFactoryUserData
* data
=
687 new TestingDomainReliabilityServiceFactoryUserData(profile_
,
689 EXPECT_FALSE(profile_
->GetUserData(kKey
));
690 profile_
->SetUserData(kKey
, data
);
692 // Set and use factory that will attach service stuffed in kludgey struct.
693 DomainReliabilityServiceFactory::GetInstance()->SetTestingFactoryAndUse(
695 &TestingDomainReliabilityServiceFactoryFunction
);
697 // Verify and detach kludgey struct.
698 EXPECT_EQ(data
, profile_
->GetUserData(kKey
));
699 EXPECT_TRUE(data
->attached
);
700 profile_
->RemoveUserData(kKey
);
703 TestingProfile
* profile_
;
704 MockDomainReliabilityService
* mock_service_
;
707 // Test Class ----------------------------------------------------------------
709 class BrowsingDataRemoverTest
: public testing::Test
{
711 BrowsingDataRemoverTest()
712 : profile_(new TestingProfile()),
713 clear_domain_reliability_tester_(GetProfile()) {
714 callback_subscription_
=
715 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
716 base::Bind(&BrowsingDataRemoverTest::NotifyWithDetails
,
717 base::Unretained(this)));
720 ~BrowsingDataRemoverTest() override
{}
722 void TearDown() override
{
723 #if defined(ENABLE_EXTENSIONS)
727 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
728 // posts a message to the WEBKIT thread to delete some of its member
729 // variables. We need to ensure that the profile is destroyed, and that
730 // the message loop is cleared out, before destroying the threads and loop.
731 // Otherwise we leak memory.
733 base::MessageLoop::current()->RunUntilIdle();
735 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL
);
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 // Callback for browsing data removal events.
805 void NotifyWithDetails(
806 const BrowsingDataRemover::NotificationDetails
& details
) {
807 // We're not taking ownership of the details object, but storing a copy of
809 called_with_details_
.reset(
810 new BrowsingDataRemover::NotificationDetails(details
));
812 callback_subscription_
.reset();
815 MockExtensionSpecialStoragePolicy
* CreateMockPolicy() {
816 #if defined(ENABLE_EXTENSIONS)
817 mock_policy_
= new MockExtensionSpecialStoragePolicy
;
818 return mock_policy_
.get();
825 storage::SpecialStoragePolicy
* mock_policy() {
826 #if defined(ENABLE_EXTENSIONS)
827 return mock_policy_
.get();
833 // If |kOrigin1| is protected when extensions are enabled, the expected
834 // result for tests where the OriginMatcherFunction result is variable.
835 bool ShouldRemoveForProtectedOriginOne() const {
836 #if defined(ENABLE_EXTENSIONS)
843 const ClearDomainReliabilityTester
& clear_domain_reliability_tester() {
844 return clear_domain_reliability_tester_
;
848 scoped_ptr
<BrowsingDataRemover::NotificationDetails
> called_with_details_
;
851 content::TestBrowserThreadBundle thread_bundle_
;
852 scoped_ptr
<TestingProfile
> profile_
;
854 StoragePartitionRemovalData storage_partition_removal_data_
;
856 #if defined(ENABLE_EXTENSIONS)
857 scoped_refptr
<MockExtensionSpecialStoragePolicy
> mock_policy_
;
860 BrowsingDataRemover::CallbackSubscription callback_subscription_
;
862 // Needed to mock out DomainReliabilityService, even for unrelated tests.
863 ClearDomainReliabilityTester clear_domain_reliability_tester_
;
865 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest
);
868 // Tests ---------------------------------------------------------------------
870 TEST_F(BrowsingDataRemoverTest
, RemoveCookieForever
) {
871 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
872 BrowsingDataRemover::REMOVE_COOKIES
,
875 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES
, GetRemovalMask());
876 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
878 // Verify that storage partition was instructed to remove the cookies.
879 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
880 EXPECT_EQ(removal_data
.remove_mask
,
881 StoragePartition::REMOVE_DATA_MASK_COOKIES
);
882 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
883 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
884 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
885 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
888 TEST_F(BrowsingDataRemoverTest
, RemoveCookieLastHour
) {
889 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
890 BrowsingDataRemover::REMOVE_COOKIES
,
893 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES
, GetRemovalMask());
894 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
896 // Verify that storage partition was instructed to remove the cookies.
897 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
898 EXPECT_EQ(removal_data
.remove_mask
,
899 StoragePartition::REMOVE_DATA_MASK_COOKIES
);
900 // Removing with time period other than EVERYTHING should not clear
901 // persistent storage data.
902 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
903 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
);
904 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
905 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
908 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
909 TEST_F(BrowsingDataRemoverTest
, RemoveSafeBrowsingCookieForever
) {
910 RemoveSafeBrowsingCookieTester tester
;
913 ASSERT_TRUE(tester
.ContainsCookie());
915 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
916 BrowsingDataRemover::REMOVE_COOKIES
, false);
918 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES
, GetRemovalMask());
919 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
920 EXPECT_FALSE(tester
.ContainsCookie());
923 TEST_F(BrowsingDataRemoverTest
, RemoveSafeBrowsingCookieLastHour
) {
924 RemoveSafeBrowsingCookieTester tester
;
927 ASSERT_TRUE(tester
.ContainsCookie());
929 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
930 BrowsingDataRemover::REMOVE_COOKIES
, false);
932 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES
, GetRemovalMask());
933 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
934 // Removing with time period other than EVERYTHING should not clear safe
936 EXPECT_TRUE(tester
.ContainsCookie());
940 TEST_F(BrowsingDataRemoverTest
, RemoveChannelIDForever
) {
941 RemoveChannelIDTester
tester(GetProfile());
943 tester
.AddChannelID(kTestOrigin1
);
944 EXPECT_EQ(0, tester
.ssl_config_changed_count());
945 EXPECT_EQ(1, tester
.ChannelIDCount());
947 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
948 BrowsingDataRemover::REMOVE_CHANNEL_IDS
, false);
950 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS
, GetRemovalMask());
951 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
952 EXPECT_EQ(1, tester
.ssl_config_changed_count());
953 EXPECT_EQ(0, tester
.ChannelIDCount());
956 TEST_F(BrowsingDataRemoverTest
, RemoveChannelIDLastHour
) {
957 RemoveChannelIDTester
tester(GetProfile());
959 base::Time now
= base::Time::Now();
960 tester
.AddChannelID(kTestOrigin1
);
961 tester
.AddChannelIDWithTimes(kTestOrigin2
,
962 now
- base::TimeDelta::FromHours(2),
964 EXPECT_EQ(0, tester
.ssl_config_changed_count());
965 EXPECT_EQ(2, tester
.ChannelIDCount());
967 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
968 BrowsingDataRemover::REMOVE_CHANNEL_IDS
, false);
970 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS
, GetRemovalMask());
971 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
972 EXPECT_EQ(1, tester
.ssl_config_changed_count());
973 ASSERT_EQ(1, tester
.ChannelIDCount());
974 net::ChannelIDStore::ChannelIDList channel_ids
;
975 tester
.GetChannelIDList(&channel_ids
);
976 ASSERT_EQ(1U, channel_ids
.size());
977 EXPECT_EQ(kTestOrigin2
, channel_ids
.front().server_identifier());
980 TEST_F(BrowsingDataRemoverTest
, RemoveUnprotectedLocalStorageForever
) {
981 #if defined(ENABLE_EXTENSIONS)
982 MockExtensionSpecialStoragePolicy
* policy
= CreateMockPolicy();
984 policy
->AddProtected(kOrigin1
.GetOrigin());
987 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
988 BrowsingDataRemover::REMOVE_LOCAL_STORAGE
,
991 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE
, GetRemovalMask());
992 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
994 // Verify that storage partition was instructed to remove the data correctly.
995 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
996 EXPECT_EQ(removal_data
.remove_mask
,
997 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
);
998 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
999 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1000 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1001 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
1003 // Check origin matcher.
1004 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1005 removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy()));
1006 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy()));
1007 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy()));
1008 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginExt
, mock_policy()));
1011 TEST_F(BrowsingDataRemoverTest
, RemoveProtectedLocalStorageForever
) {
1012 #if defined(ENABLE_EXTENSIONS)
1013 // Protect kOrigin1.
1014 MockExtensionSpecialStoragePolicy
* policy
= CreateMockPolicy();
1015 policy
->AddProtected(kOrigin1
.GetOrigin());
1018 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1019 BrowsingDataRemover::REMOVE_LOCAL_STORAGE
,
1022 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE
, GetRemovalMask());
1023 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
|
1024 BrowsingDataHelper::PROTECTED_WEB
, GetOriginSetMask());
1026 // Verify that storage partition was instructed to remove the data correctly.
1027 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1028 EXPECT_EQ(removal_data
.remove_mask
,
1029 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
);
1030 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1031 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1032 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1033 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
1035 // Check origin matcher all http origin will match since we specified
1036 // both protected and unprotected.
1037 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy()));
1038 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy()));
1039 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy()));
1040 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginExt
, mock_policy()));
1043 TEST_F(BrowsingDataRemoverTest
, RemoveLocalStorageForLastWeek
) {
1044 #if defined(ENABLE_EXTENSIONS)
1048 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK
,
1049 BrowsingDataRemover::REMOVE_LOCAL_STORAGE
,
1052 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE
, GetRemovalMask());
1053 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1055 // Verify that storage partition was instructed to remove the data correctly.
1056 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1057 EXPECT_EQ(removal_data
.remove_mask
,
1058 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE
);
1059 // Persistent storage won't be deleted.
1060 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1061 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
);
1062 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1063 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
1065 // Check origin matcher.
1066 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy()));
1067 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy()));
1068 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy()));
1069 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginExt
, mock_policy()));
1072 TEST_F(BrowsingDataRemoverTest
, RemoveHistoryForever
) {
1073 RemoveHistoryTester tester
;
1074 ASSERT_TRUE(tester
.Init(GetProfile()));
1076 tester
.AddHistory(kOrigin1
, base::Time::Now());
1077 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1079 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1080 BrowsingDataRemover::REMOVE_HISTORY
, false);
1082 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1083 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1084 EXPECT_FALSE(tester
.HistoryContainsURL(kOrigin1
));
1087 TEST_F(BrowsingDataRemoverTest
, RemoveHistoryForLastHour
) {
1088 RemoveHistoryTester tester
;
1089 ASSERT_TRUE(tester
.Init(GetProfile()));
1091 base::Time two_hours_ago
= base::Time::Now() - base::TimeDelta::FromHours(2);
1093 tester
.AddHistory(kOrigin1
, base::Time::Now());
1094 tester
.AddHistory(kOrigin2
, two_hours_ago
);
1095 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1096 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1098 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
1099 BrowsingDataRemover::REMOVE_HISTORY
, false);
1101 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1102 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1103 EXPECT_FALSE(tester
.HistoryContainsURL(kOrigin1
));
1104 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1107 // This should crash (DCHECK) in Debug, but death tests don't work properly
1109 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1110 TEST_F(BrowsingDataRemoverTest
, RemoveHistoryProhibited
) {
1111 RemoveHistoryTester tester
;
1112 ASSERT_TRUE(tester
.Init(GetProfile()));
1113 PrefService
* prefs
= GetProfile()->GetPrefs();
1114 prefs
->SetBoolean(prefs::kAllowDeletingBrowserHistory
, false);
1116 base::Time two_hours_ago
= base::Time::Now() - base::TimeDelta::FromHours(2);
1118 tester
.AddHistory(kOrigin1
, base::Time::Now());
1119 tester
.AddHistory(kOrigin2
, two_hours_ago
);
1120 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1121 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1123 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
1124 BrowsingDataRemover::REMOVE_HISTORY
, false);
1125 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1126 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1128 // Nothing should have been deleted.
1129 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1130 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1134 TEST_F(BrowsingDataRemoverTest
, RemoveMultipleTypes
) {
1135 // Add some history.
1136 RemoveHistoryTester history_tester
;
1137 ASSERT_TRUE(history_tester
.Init(GetProfile()));
1138 history_tester
.AddHistory(kOrigin1
, base::Time::Now());
1139 ASSERT_TRUE(history_tester
.HistoryContainsURL(kOrigin1
));
1141 int removal_mask
= BrowsingDataRemover::REMOVE_HISTORY
|
1142 BrowsingDataRemover::REMOVE_COOKIES
;
1144 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1145 removal_mask
, false);
1147 EXPECT_EQ(removal_mask
, GetRemovalMask());
1148 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1149 EXPECT_FALSE(history_tester
.HistoryContainsURL(kOrigin1
));
1151 // The cookie would be deleted throught the StorageParition, check if the
1152 // partition was requested to remove cookie.
1153 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1154 EXPECT_EQ(removal_data
.remove_mask
,
1155 StoragePartition::REMOVE_DATA_MASK_COOKIES
);
1156 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1157 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1160 // This should crash (DCHECK) in Debug, but death tests don't work properly
1162 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1163 TEST_F(BrowsingDataRemoverTest
, RemoveMultipleTypesHistoryProhibited
) {
1164 PrefService
* prefs
= GetProfile()->GetPrefs();
1165 prefs
->SetBoolean(prefs::kAllowDeletingBrowserHistory
, false);
1167 // Add some history.
1168 RemoveHistoryTester history_tester
;
1169 ASSERT_TRUE(history_tester
.Init(GetProfile()));
1170 history_tester
.AddHistory(kOrigin1
, base::Time::Now());
1171 ASSERT_TRUE(history_tester
.HistoryContainsURL(kOrigin1
));
1173 int removal_mask
= BrowsingDataRemover::REMOVE_HISTORY
|
1174 BrowsingDataRemover::REMOVE_COOKIES
;
1176 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
1177 removal_mask
, false);
1178 EXPECT_EQ(removal_mask
, GetRemovalMask());
1179 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1181 // 1/2. History should remain.
1182 EXPECT_TRUE(history_tester
.HistoryContainsURL(kOrigin1
));
1184 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if
1185 // the partition was requested to remove cookie.
1186 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1187 EXPECT_EQ(removal_data
.remove_mask
,
1188 StoragePartition::REMOVE_DATA_MASK_COOKIES
);
1189 // Persistent storage won't be deleted, since EVERYTHING was not specified.
1190 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1191 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
);
1195 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverBoth
) {
1196 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1197 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1198 BrowsingDataRemover::REMOVE_WEBSQL
|
1199 BrowsingDataRemover::REMOVE_APPCACHE
|
1200 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1201 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1204 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1205 BrowsingDataRemover::REMOVE_WEBSQL
|
1206 BrowsingDataRemover::REMOVE_APPCACHE
|
1207 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1208 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1209 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1211 // Verify storage partition related stuffs.
1212 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1213 EXPECT_EQ(removal_data
.remove_mask
,
1214 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1215 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1216 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1217 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1218 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1219 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1220 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1221 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1224 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverOnlyTemporary
) {
1225 #if defined(ENABLE_EXTENSIONS)
1229 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1230 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1231 BrowsingDataRemover::REMOVE_WEBSQL
|
1232 BrowsingDataRemover::REMOVE_APPCACHE
|
1233 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1234 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1237 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1238 BrowsingDataRemover::REMOVE_WEBSQL
|
1239 BrowsingDataRemover::REMOVE_APPCACHE
|
1240 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1241 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1242 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1244 // Verify storage partition related stuffs.
1245 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1247 EXPECT_EQ(removal_data
.remove_mask
,
1248 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1249 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1250 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1251 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1252 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1253 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1254 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1255 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1257 // Check that all related origin data would be removed, that is, origin
1258 // matcher would match these origin.
1259 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy()));
1260 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy()));
1261 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy()));
1264 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverOnlyPersistent
) {
1265 #if defined(ENABLE_EXTENSIONS)
1269 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1270 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1271 BrowsingDataRemover::REMOVE_WEBSQL
|
1272 BrowsingDataRemover::REMOVE_APPCACHE
|
1273 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1274 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1277 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1278 BrowsingDataRemover::REMOVE_WEBSQL
|
1279 BrowsingDataRemover::REMOVE_APPCACHE
|
1280 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1281 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1282 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1284 // Verify storage partition related stuffs.
1285 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1287 EXPECT_EQ(removal_data
.remove_mask
,
1288 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1289 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1290 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1291 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1292 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1293 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1294 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1295 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1297 // Check that all related origin data would be removed, that is, origin
1298 // matcher would match these origin.
1299 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy()));
1300 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy()));
1301 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy()));
1304 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverNeither
) {
1305 #if defined(ENABLE_EXTENSIONS)
1310 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1311 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1312 BrowsingDataRemover::REMOVE_WEBSQL
|
1313 BrowsingDataRemover::REMOVE_APPCACHE
|
1314 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1315 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1318 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1319 BrowsingDataRemover::REMOVE_WEBSQL
|
1320 BrowsingDataRemover::REMOVE_APPCACHE
|
1321 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1322 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1323 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1325 // Verify storage partition related stuffs.
1326 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1328 EXPECT_EQ(removal_data
.remove_mask
,
1329 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1330 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1331 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1332 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1333 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1334 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1335 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1336 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1338 // Check that all related origin data would be removed, that is, origin
1339 // matcher would match these origin.
1340 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy()));
1341 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy()));
1342 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy()));
1345 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForeverSpecificOrigin
) {
1347 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING
,
1348 BrowsingDataRemover::REMOVE_APPCACHE
|
1349 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1350 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1351 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1352 BrowsingDataRemover::REMOVE_WEBSQL
,
1355 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE
|
1356 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1357 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1358 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1359 BrowsingDataRemover::REMOVE_WEBSQL
, GetRemovalMask());
1360 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1362 // Verify storage partition related stuffs.
1363 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1365 EXPECT_EQ(removal_data
.remove_mask
,
1366 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1367 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1368 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1369 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1370 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1371 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1372 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1373 EXPECT_EQ(removal_data
.remove_origin
, kOrigin1
);
1376 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForLastHour
) {
1377 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR
,
1378 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1379 BrowsingDataRemover::REMOVE_WEBSQL
|
1380 BrowsingDataRemover::REMOVE_APPCACHE
|
1381 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1382 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1385 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1386 BrowsingDataRemover::REMOVE_WEBSQL
|
1387 BrowsingDataRemover::REMOVE_APPCACHE
|
1388 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1389 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1390 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1392 // Verify storage partition related stuffs.
1393 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1395 EXPECT_EQ(removal_data
.remove_mask
,
1396 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1397 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1398 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1399 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1400 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1402 // Persistent data would be left out since we are not removing from
1403 // beginning of time.
1404 uint32 expected_quota_mask
=
1405 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
;
1406 EXPECT_EQ(removal_data
.quota_storage_remove_mask
, expected_quota_mask
);
1407 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1408 // Check removal begin time.
1409 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
1412 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedDataForLastWeek
) {
1413 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK
,
1414 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1415 BrowsingDataRemover::REMOVE_WEBSQL
|
1416 BrowsingDataRemover::REMOVE_APPCACHE
|
1417 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1418 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1421 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1422 BrowsingDataRemover::REMOVE_WEBSQL
|
1423 BrowsingDataRemover::REMOVE_APPCACHE
|
1424 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1425 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1426 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1428 // Verify storage partition related stuffs.
1429 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1431 EXPECT_EQ(removal_data
.remove_mask
,
1432 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1433 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1434 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1435 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1436 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1438 // Persistent data would be left out since we are not removing from
1439 // beginning of time.
1440 uint32 expected_quota_mask
=
1441 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT
;
1442 EXPECT_EQ(removal_data
.quota_storage_remove_mask
, expected_quota_mask
);
1443 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1444 // Check removal begin time.
1445 EXPECT_EQ(removal_data
.remove_begin
, GetBeginTime());
1448 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedUnprotectedOrigins
) {
1449 #if defined(ENABLE_EXTENSIONS)
1450 MockExtensionSpecialStoragePolicy
* policy
= CreateMockPolicy();
1451 // Protect kOrigin1.
1452 policy
->AddProtected(kOrigin1
.GetOrigin());
1455 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1456 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1457 BrowsingDataRemover::REMOVE_WEBSQL
|
1458 BrowsingDataRemover::REMOVE_APPCACHE
|
1459 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1460 BrowsingDataRemover::REMOVE_INDEXEDDB
,
1463 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1464 BrowsingDataRemover::REMOVE_WEBSQL
|
1465 BrowsingDataRemover::REMOVE_APPCACHE
|
1466 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1467 BrowsingDataRemover::REMOVE_INDEXEDDB
, GetRemovalMask());
1468 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1470 // Verify storage partition related stuffs.
1471 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1473 EXPECT_EQ(removal_data
.remove_mask
,
1474 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1475 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1476 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1477 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1478 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1479 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1480 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1481 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1483 // Check OriginMatcherFunction.
1484 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1485 removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy()));
1486 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy()));
1487 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy()));
1490 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedProtectedSpecificOrigin
) {
1491 #if defined(ENABLE_EXTENSIONS)
1492 MockExtensionSpecialStoragePolicy
* policy
= CreateMockPolicy();
1493 // Protect kOrigin1.
1494 policy
->AddProtected(kOrigin1
.GetOrigin());
1497 // Try to remove kOrigin1. Expect failure.
1498 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING
,
1499 BrowsingDataRemover::REMOVE_APPCACHE
|
1500 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1501 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1502 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1503 BrowsingDataRemover::REMOVE_WEBSQL
,
1506 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE
|
1507 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1508 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1509 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1510 BrowsingDataRemover::REMOVE_WEBSQL
, GetRemovalMask());
1511 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1513 // Verify storage partition related stuffs.
1514 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1516 EXPECT_EQ(removal_data
.remove_mask
,
1517 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1518 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1519 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1520 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1521 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1522 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1523 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1524 EXPECT_EQ(removal_data
.remove_origin
, kOrigin1
);
1526 // Check OriginMatcherFunction.
1527 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1528 removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy()));
1529 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy()));
1530 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy()));
1533 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedProtectedOrigins
) {
1534 #if defined(ENABLE_EXTENSIONS)
1535 MockExtensionSpecialStoragePolicy
* policy
= CreateMockPolicy();
1536 // Protect kOrigin1.
1537 policy
->AddProtected(kOrigin1
.GetOrigin());
1540 // Try to remove kOrigin1. Expect success.
1541 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1542 BrowsingDataRemover::REMOVE_APPCACHE
|
1543 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1544 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1545 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1546 BrowsingDataRemover::REMOVE_WEBSQL
,
1549 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE
|
1550 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1551 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1552 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1553 BrowsingDataRemover::REMOVE_WEBSQL
, GetRemovalMask());
1554 EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB
|
1555 BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1557 // Verify storage partition related stuffs.
1558 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1560 EXPECT_EQ(removal_data
.remove_mask
,
1561 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1562 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1563 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1564 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1565 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1566 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1567 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1568 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1570 // Check OriginMatcherFunction, |kOrigin1| would match mask since we
1571 // would have 'protected' specified in origin_set_mask.
1572 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin1
, mock_policy()));
1573 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin2
, mock_policy()));
1574 EXPECT_TRUE(removal_data
.origin_matcher
.Run(kOrigin3
, mock_policy()));
1577 TEST_F(BrowsingDataRemoverTest
, RemoveQuotaManagedIgnoreExtensionsAndDevTools
) {
1578 #if defined(ENABLE_EXTENSIONS)
1582 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1583 BrowsingDataRemover::REMOVE_APPCACHE
|
1584 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1585 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1586 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1587 BrowsingDataRemover::REMOVE_WEBSQL
,
1590 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE
|
1591 BrowsingDataRemover::REMOVE_SERVICE_WORKERS
|
1592 BrowsingDataRemover::REMOVE_FILE_SYSTEMS
|
1593 BrowsingDataRemover::REMOVE_INDEXEDDB
|
1594 BrowsingDataRemover::REMOVE_WEBSQL
, GetRemovalMask());
1595 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1597 // Verify storage partition related stuffs.
1598 StoragePartitionRemovalData removal_data
= GetStoragePartitionRemovalData();
1600 EXPECT_EQ(removal_data
.remove_mask
,
1601 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS
|
1602 StoragePartition::REMOVE_DATA_MASK_WEBSQL
|
1603 StoragePartition::REMOVE_DATA_MASK_APPCACHE
|
1604 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS
|
1605 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB
);
1606 EXPECT_EQ(removal_data
.quota_storage_remove_mask
,
1607 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL
);
1608 EXPECT_TRUE(removal_data
.remove_origin
.is_empty());
1610 // Check that extension and devtools data wouldn't be removed, that is,
1611 // origin matcher would not match these origin.
1612 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginExt
, mock_policy()));
1613 EXPECT_FALSE(removal_data
.origin_matcher
.Run(kOriginDevTools
, mock_policy()));
1616 TEST_F(BrowsingDataRemoverTest
, OriginBasedHistoryRemoval
) {
1617 RemoveHistoryTester tester
;
1618 ASSERT_TRUE(tester
.Init(GetProfile()));
1620 base::Time two_hours_ago
= base::Time::Now() - base::TimeDelta::FromHours(2);
1622 tester
.AddHistory(kOrigin1
, base::Time::Now());
1623 tester
.AddHistory(kOrigin2
, two_hours_ago
);
1624 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1625 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1627 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING
,
1628 BrowsingDataRemover::REMOVE_HISTORY
, kOrigin2
);
1630 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1631 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1633 // Nothing should have been deleted.
1634 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1635 EXPECT_FALSE(tester
.HistoryContainsURL(kOrigin2
));
1638 TEST_F(BrowsingDataRemoverTest
, OriginAndTimeBasedHistoryRemoval
) {
1639 RemoveHistoryTester tester
;
1640 ASSERT_TRUE(tester
.Init(GetProfile()));
1642 base::Time two_hours_ago
= base::Time::Now() - base::TimeDelta::FromHours(2);
1644 tester
.AddHistory(kOrigin1
, base::Time::Now());
1645 tester
.AddHistory(kOrigin2
, two_hours_ago
);
1646 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1647 ASSERT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1649 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR
,
1650 BrowsingDataRemover::REMOVE_HISTORY
, kOrigin2
);
1652 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1653 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1654 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin1
));
1655 EXPECT_TRUE(tester
.HistoryContainsURL(kOrigin2
));
1658 // Verify that clearing autofill form data works.
1659 TEST_F(BrowsingDataRemoverTest
, AutofillRemovalLastHour
) {
1660 GetProfile()->CreateWebDataService();
1661 RemoveAutofillTester
tester(GetProfile());
1663 ASSERT_FALSE(tester
.HasProfile());
1664 tester
.AddProfilesAndCards();
1665 ASSERT_TRUE(tester
.HasProfile());
1667 BlockUntilBrowsingDataRemoved(
1668 BrowsingDataRemover::LAST_HOUR
,
1669 BrowsingDataRemover::REMOVE_FORM_DATA
, false);
1671 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA
, GetRemovalMask());
1672 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1673 ASSERT_FALSE(tester
.HasProfile());
1676 TEST_F(BrowsingDataRemoverTest
, AutofillRemovalEverything
) {
1677 GetProfile()->CreateWebDataService();
1678 RemoveAutofillTester
tester(GetProfile());
1680 ASSERT_FALSE(tester
.HasProfile());
1681 tester
.AddProfilesAndCards();
1682 ASSERT_TRUE(tester
.HasProfile());
1684 BlockUntilBrowsingDataRemoved(
1685 BrowsingDataRemover::EVERYTHING
,
1686 BrowsingDataRemover::REMOVE_FORM_DATA
, false);
1688 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA
, GetRemovalMask());
1689 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1690 ASSERT_FALSE(tester
.HasProfile());
1693 // Verify that clearing autofill form data works.
1694 TEST_F(BrowsingDataRemoverTest
, AutofillOriginsRemovedWithHistory
) {
1695 GetProfile()->CreateWebDataService();
1696 RemoveAutofillTester
tester(GetProfile());
1698 tester
.AddProfilesAndCards();
1699 EXPECT_FALSE(tester
.HasOrigin(std::string()));
1700 EXPECT_TRUE(tester
.HasOrigin(kWebOrigin
));
1701 EXPECT_TRUE(tester
.HasOrigin(kChromeOrigin
));
1703 BlockUntilBrowsingDataRemoved(
1704 BrowsingDataRemover::LAST_HOUR
,
1705 BrowsingDataRemover::REMOVE_HISTORY
, false);
1707 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1708 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1709 EXPECT_TRUE(tester
.HasOrigin(std::string()));
1710 EXPECT_FALSE(tester
.HasOrigin(kWebOrigin
));
1711 EXPECT_TRUE(tester
.HasOrigin(kChromeOrigin
));
1714 TEST_F(BrowsingDataRemoverTest
, CompletionInhibition
) {
1715 // The |completion_inhibitor| on the stack should prevent removal sessions
1716 // from completing until after ContinueToCompletion() is called.
1717 BrowsingDataRemoverCompletionInhibitor completion_inhibitor
;
1719 called_with_details_
.reset(new BrowsingDataRemover::NotificationDetails());
1721 // BrowsingDataRemover deletes itself when it completes.
1722 BrowsingDataRemover
* remover
= BrowsingDataRemover::CreateForPeriod(
1723 GetProfile(), BrowsingDataRemover::EVERYTHING
);
1724 remover
->Remove(BrowsingDataRemover::REMOVE_HISTORY
,
1725 BrowsingDataHelper::UNPROTECTED_WEB
);
1727 // Process messages until the inhibitor is notified, and then some, to make
1728 // sure we do not complete asynchronously before ContinueToCompletion() is
1730 completion_inhibitor
.BlockUntilNearCompletion();
1731 base::RunLoop().RunUntilIdle();
1733 // Verify that the completion notification has not yet been broadcasted.
1734 EXPECT_EQ(-1, GetRemovalMask());
1735 EXPECT_EQ(-1, GetOriginSetMask());
1737 // Now run the removal process until completion, and verify that observers are
1738 // now notified, and the notifications is sent out.
1739 BrowsingDataRemoverCompletionObserver
completion_observer(remover
);
1740 completion_inhibitor
.ContinueToCompletion();
1741 completion_observer
.BlockUntilCompletion();
1743 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY
, GetRemovalMask());
1744 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1747 TEST_F(BrowsingDataRemoverTest
, ZeroSuggestCacheClear
) {
1748 PrefService
* prefs
= GetProfile()->GetPrefs();
1749 prefs
->SetString(prefs::kZeroSuggestCachedResults
,
1750 "[\"\", [\"foo\", \"bar\"]]");
1751 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING
,
1752 BrowsingDataRemover::REMOVE_COOKIES
,
1755 // Expect the prefs to be cleared when cookies are removed.
1756 EXPECT_TRUE(prefs
->GetString(prefs::kZeroSuggestCachedResults
).empty());
1757 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES
, GetRemovalMask());
1758 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB
, GetOriginSetMask());
1761 #if defined(OS_CHROMEOS)
1762 TEST_F(BrowsingDataRemoverTest
, ContentProtectionPlatformKeysRemoval
) {
1763 chromeos::ScopedTestDeviceSettingsService test_device_settings_service
;
1764 chromeos::ScopedTestCrosSettings test_cros_settings
;
1765 chromeos::MockUserManager
* mock_user_manager
=
1766 new testing::NiceMock
<chromeos::MockUserManager
>();
1767 mock_user_manager
->SetActiveUser("test@example.com");
1768 chromeos::ScopedUserManagerEnabler
user_manager_enabler(mock_user_manager
);
1770 scoped_ptr
<chromeos::DBusThreadManagerSetter
> dbus_setter
=
1771 chromeos::DBusThreadManager::GetSetterForTesting();
1772 chromeos::MockCryptohomeClient
* cryptohome_client
=
1773 new chromeos::MockCryptohomeClient
;
1774 dbus_setter
->SetCryptohomeClient(
1775 scoped_ptr
<chromeos::CryptohomeClient
>(cryptohome_client
));
1777 // Expect exactly one call. No calls means no attempt to delete keys and more
1778 // than one call means a significant performance problem.
1779 EXPECT_CALL(*cryptohome_client
, TpmAttestationDeleteKeys(_
, _
, _
, _
))
1780 .WillOnce(WithArgs
<3>(Invoke(FakeDBusCall
)));
1782 BlockUntilBrowsingDataRemoved(
1783 BrowsingDataRemover::EVERYTHING
,
1784 BrowsingDataRemover::REMOVE_CONTENT_LICENSES
, false);
1786 chromeos::DBusThreadManager::Shutdown();
1790 TEST_F(BrowsingDataRemoverTest
, DomainReliability_Null
) {
1791 const ClearDomainReliabilityTester
& tester
=
1792 clear_domain_reliability_tester();
1794 EXPECT_EQ(0u, tester
.clear_count());
1797 TEST_F(BrowsingDataRemoverTest
, DomainReliability_Beacons
) {
1798 const ClearDomainReliabilityTester
& tester
=
1799 clear_domain_reliability_tester();
1801 BlockUntilBrowsingDataRemoved(
1802 BrowsingDataRemover::EVERYTHING
,
1803 BrowsingDataRemover::REMOVE_HISTORY
, false);
1804 EXPECT_EQ(1u, tester
.clear_count());
1805 EXPECT_EQ(CLEAR_BEACONS
, tester
.last_clear_mode());
1808 TEST_F(BrowsingDataRemoverTest
, DomainReliability_Contexts
) {
1809 const ClearDomainReliabilityTester
& tester
=
1810 clear_domain_reliability_tester();
1812 BlockUntilBrowsingDataRemoved(
1813 BrowsingDataRemover::EVERYTHING
,
1814 BrowsingDataRemover::REMOVE_COOKIES
, false);
1815 EXPECT_EQ(1u, tester
.clear_count());
1816 EXPECT_EQ(CLEAR_CONTEXTS
, tester
.last_clear_mode());
1819 TEST_F(BrowsingDataRemoverTest
, DomainReliability_ContextsWin
) {
1820 const ClearDomainReliabilityTester
& tester
=
1821 clear_domain_reliability_tester();
1823 BlockUntilBrowsingDataRemoved(
1824 BrowsingDataRemover::EVERYTHING
,
1825 BrowsingDataRemover::REMOVE_HISTORY
|
1826 BrowsingDataRemover::REMOVE_COOKIES
, false);
1827 EXPECT_EQ(1u, tester
.clear_count());
1828 EXPECT_EQ(CLEAR_CONTEXTS
, tester
.last_clear_mode());
1831 TEST_F(BrowsingDataRemoverTest
, DomainReliability_ProtectedOrigins
) {
1832 const ClearDomainReliabilityTester
& tester
=
1833 clear_domain_reliability_tester();
1835 BlockUntilBrowsingDataRemoved(
1836 BrowsingDataRemover::EVERYTHING
,
1837 BrowsingDataRemover::REMOVE_COOKIES
, true);
1838 EXPECT_EQ(1u, tester
.clear_count());
1839 EXPECT_EQ(CLEAR_CONTEXTS
, tester
.last_clear_mode());
1842 // TODO(ttuttle): This isn't actually testing the no-monitor case, since
1843 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed
1844 // for some unrelated test cases. This should be fixed so it tests the no-
1845 // monitor case again.
1846 TEST_F(BrowsingDataRemoverTest
, DISABLED_DomainReliability_NoMonitor
) {
1847 BlockUntilBrowsingDataRemoved(
1848 BrowsingDataRemover::EVERYTHING
,
1849 BrowsingDataRemover::REMOVE_HISTORY
|
1850 BrowsingDataRemover::REMOVE_COOKIES
, false);