Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_remover_unittest.cc
blob467596a967a7845d7776ba12c722688f8da70dd8
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/browsing_data/browsing_data_remover.h"
7 #include <set>
8 #include <string>
9 #include <vector>
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/memory/scoped_ptr.h"
17 #include "base/message_loop/message_loop.h"
18 #include "base/prefs/testing_pref_service.h"
19 #include "base/run_loop.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/task/cancelable_task_tracker.h"
22 #include "chrome/browser/autofill/personal_data_manager_factory.h"
23 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
24 #include "chrome/browser/browsing_data/browsing_data_helper.h"
25 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h"
26 #include "chrome/browser/domain_reliability/service_factory.h"
27 #include "chrome/browser/download/chrome_download_manager_delegate.h"
28 #include "chrome/browser/favicon/favicon_service_factory.h"
29 #include "chrome/browser/history/history_service_factory.h"
30 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
31 #include "chrome/common/pref_names.h"
32 #include "chrome/test/base/testing_browser_process.h"
33 #include "chrome/test/base/testing_profile.h"
34 #include "components/autofill/core/browser/autofill_profile.h"
35 #include "components/autofill/core/browser/autofill_test_utils.h"
36 #include "components/autofill/core/browser/credit_card.h"
37 #include "components/autofill/core/browser/personal_data_manager.h"
38 #include "components/autofill/core/browser/personal_data_manager_observer.h"
39 #include "components/bookmarks/browser/bookmark_model.h"
40 #include "components/bookmarks/test/bookmark_test_helpers.h"
41 #include "components/domain_reliability/clear_mode.h"
42 #include "components/domain_reliability/monitor.h"
43 #include "components/domain_reliability/service.h"
44 #include "components/favicon/core/favicon_service.h"
45 #include "components/history/core/browser/history_service.h"
46 #include "components/omnibox/browser/omnibox_pref_names.h"
47 #include "content/public/browser/browser_context.h"
48 #include "content/public/browser/cookie_store_factory.h"
49 #include "content/public/browser/dom_storage_context.h"
50 #include "content/public/browser/local_storage_usage_info.h"
51 #include "content/public/browser/storage_partition.h"
52 #include "content/public/test/mock_download_manager.h"
53 #include "content/public/test/test_browser_thread.h"
54 #include "content/public/test/test_browser_thread_bundle.h"
55 #include "content/public/test/test_utils.h"
56 #include "net/cookies/cookie_store.h"
57 #include "net/ssl/channel_id_service.h"
58 #include "net/ssl/channel_id_store.h"
59 #include "net/ssl/ssl_client_cert_type.h"
60 #include "net/url_request/url_request_context.h"
61 #include "net/url_request/url_request_context_getter.h"
62 #include "testing/gmock/include/gmock/gmock.h"
63 #include "testing/gtest/include/gtest/gtest.h"
64 #include "third_party/skia/include/core/SkBitmap.h"
65 #include "ui/gfx/favicon_size.h"
66 #include "url/origin.h"
68 #if defined(OS_CHROMEOS)
69 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
70 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
71 #include "chrome/browser/chromeos/settings/cros_settings.h"
72 #include "chrome/browser/chromeos/settings/device_settings_service.h"
73 #include "chromeos/dbus/dbus_thread_manager.h"
74 #include "chromeos/dbus/mock_cryptohome_client.h"
75 #endif
77 #if defined(ENABLE_EXTENSIONS)
78 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h"
79 #endif
81 class MockExtensionSpecialStoragePolicy;
83 using content::BrowserThread;
84 using content::StoragePartition;
85 using domain_reliability::CLEAR_BEACONS;
86 using domain_reliability::CLEAR_CONTEXTS;
87 using domain_reliability::DomainReliabilityClearMode;
88 using domain_reliability::DomainReliabilityMonitor;
89 using domain_reliability::DomainReliabilityService;
90 using domain_reliability::DomainReliabilityServiceFactory;
91 using testing::_;
92 using testing::ByRef;
93 using testing::Invoke;
94 using testing::Matcher;
95 using testing::MakeMatcher;
96 using testing::MatcherInterface;
97 using testing::MatchResultListener;
98 using testing::Return;
99 using testing::WithArgs;
101 namespace {
103 const char kTestOrigin1[] = "http://host1:1/";
104 const char kTestOrigin2[] = "http://host2:1/";
105 const char kTestOrigin3[] = "http://host3:1/";
106 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/";
107 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/";
109 // For Autofill.
110 const char kChromeOrigin[] = "Chrome settings";
111 const char kWebOrigin[] = "https://www.example.com/";
113 const GURL kOrigin1(kTestOrigin1);
114 const GURL kOrigin2(kTestOrigin2);
115 const GURL kOrigin3(kTestOrigin3);
116 const GURL kOriginExt(kTestOriginExt);
117 const GURL kOriginDevTools(kTestOriginDevTools);
119 const base::FilePath::CharType kDomStorageOrigin1[] =
120 FILE_PATH_LITERAL("http_host1_1.localstorage");
122 const base::FilePath::CharType kDomStorageOrigin2[] =
123 FILE_PATH_LITERAL("http_host2_1.localstorage");
125 const base::FilePath::CharType kDomStorageOrigin3[] =
126 FILE_PATH_LITERAL("http_host3_1.localstorage");
128 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL(
129 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage");
131 #if defined(OS_CHROMEOS)
132 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) {
133 base::MessageLoop::current()->PostTask(
134 FROM_HERE,
135 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true));
137 #endif
139 struct StoragePartitionRemovalData {
140 uint32 remove_mask = 0;
141 uint32 quota_storage_remove_mask = 0;
142 GURL remove_origin;
143 base::Time remove_begin;
144 base::Time remove_end;
145 StoragePartition::OriginMatcherFunction origin_matcher;
147 StoragePartitionRemovalData() {}
150 class TestStoragePartition : public StoragePartition {
151 public:
152 TestStoragePartition() {}
153 ~TestStoragePartition() override {}
155 // content::StoragePartition implementation.
156 base::FilePath GetPath() override { return base::FilePath(); }
157 net::URLRequestContextGetter* GetURLRequestContext() override {
158 return nullptr;
160 net::URLRequestContextGetter* GetMediaURLRequestContext() override {
161 return nullptr;
163 storage::QuotaManager* GetQuotaManager() override { return nullptr; }
164 content::AppCacheService* GetAppCacheService() override { return nullptr; }
165 storage::FileSystemContext* GetFileSystemContext() override {
166 return nullptr;
168 storage::DatabaseTracker* GetDatabaseTracker() override { return nullptr; }
169 content::DOMStorageContext* GetDOMStorageContext() override {
170 return nullptr;
172 content::IndexedDBContext* GetIndexedDBContext() override { return nullptr; }
173 content::ServiceWorkerContext* GetServiceWorkerContext() override {
174 return nullptr;
176 content::CacheStorageContext* GetCacheStorageContext() override {
177 return nullptr;
179 content::GeofencingManager* GetGeofencingManager() override {
180 return nullptr;
182 content::NavigatorConnectContext* GetNavigatorConnectContext() override {
183 return nullptr;
185 content::PlatformNotificationContext* GetPlatformNotificationContext()
186 override {
187 return nullptr;
189 content::BackgroundSyncContext* GetBackgroundSyncContext() override {
190 return nullptr;
192 content::HostZoomMap* GetHostZoomMap() override { return nullptr; }
193 content::HostZoomLevelContext* GetHostZoomLevelContext() override {
194 return nullptr;
196 content::ZoomLevelDelegate* GetZoomLevelDelegate() override {
197 return nullptr;
200 void ClearDataForOrigin(uint32 remove_mask,
201 uint32 quota_storage_remove_mask,
202 const GURL& storage_origin,
203 net::URLRequestContextGetter* rq_context,
204 const base::Closure& callback) override {
205 BrowserThread::PostTask(BrowserThread::UI,
206 FROM_HERE,
207 base::Bind(&TestStoragePartition::AsyncRunCallback,
208 base::Unretained(this),
209 callback));
212 void ClearData(uint32 remove_mask,
213 uint32 quota_storage_remove_mask,
214 const GURL& storage_origin,
215 const OriginMatcherFunction& origin_matcher,
216 const base::Time begin,
217 const base::Time end,
218 const base::Closure& callback) override {
219 // Store stuff to verify parameters' correctness later.
220 storage_partition_removal_data_.remove_mask = remove_mask;
221 storage_partition_removal_data_.quota_storage_remove_mask =
222 quota_storage_remove_mask;
223 storage_partition_removal_data_.remove_origin = storage_origin;
224 storage_partition_removal_data_.remove_begin = begin;
225 storage_partition_removal_data_.remove_end = end;
226 storage_partition_removal_data_.origin_matcher = origin_matcher;
228 BrowserThread::PostTask(
229 BrowserThread::UI,
230 FROM_HERE,
231 base::Bind(&TestStoragePartition::AsyncRunCallback,
232 base::Unretained(this), callback));
235 void Flush() override {}
237 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
238 return storage_partition_removal_data_;
241 private:
242 void AsyncRunCallback(const base::Closure& callback) {
243 callback.Run();
246 StoragePartitionRemovalData storage_partition_removal_data_;
248 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition);
251 // Custom matcher to verify is-same-origin relationship to given reference
252 // origin.
253 // (We cannot use equality-based matching because operator== is not defined for
254 // Origin, and we in fact want to rely on IsSameOrigin for matching purposes.)
255 class SameOriginMatcher : public MatcherInterface<const url::Origin&> {
256 public:
257 explicit SameOriginMatcher(const url::Origin& reference)
258 : reference_(reference) {}
260 virtual bool MatchAndExplain(const url::Origin& origin,
261 MatchResultListener* listener) const {
262 return reference_.IsSameOriginWith(origin);
265 virtual void DescribeTo(::std::ostream* os) const {
266 *os << "is same origin with " << reference_;
269 virtual void DescribeNegationTo(::std::ostream* os) const {
270 *os << "is not same origin with " << reference_;
273 private:
274 const url::Origin& reference_;
277 inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) {
278 return MakeMatcher(new SameOriginMatcher(reference));
281 } // namespace
283 // Testers -------------------------------------------------------------------
285 class RemoveCookieTester {
286 public:
287 RemoveCookieTester() {}
289 // Returns true, if the given cookie exists in the cookie store.
290 bool ContainsCookie() {
291 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
292 new content::MessageLoopRunner;
293 quit_closure_ = message_loop_runner->QuitClosure();
294 get_cookie_success_ = false;
295 cookie_store_->GetCookiesWithOptionsAsync(
296 kOrigin1, net::CookieOptions(),
297 base::Bind(&RemoveCookieTester::GetCookieCallback,
298 base::Unretained(this)));
299 message_loop_runner->Run();
300 return get_cookie_success_;
303 void AddCookie() {
304 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
305 new content::MessageLoopRunner;
306 quit_closure_ = message_loop_runner->QuitClosure();
307 cookie_store_->SetCookieWithOptionsAsync(
308 kOrigin1, "A=1", net::CookieOptions(),
309 base::Bind(&RemoveCookieTester::SetCookieCallback,
310 base::Unretained(this)));
311 message_loop_runner->Run();
314 protected:
315 void SetMonster(net::CookieStore* monster) {
316 cookie_store_ = monster;
319 private:
320 void GetCookieCallback(const std::string& cookies) {
321 if (cookies == "A=1") {
322 get_cookie_success_ = true;
323 } else {
324 EXPECT_EQ("", cookies);
325 get_cookie_success_ = false;
327 quit_closure_.Run();
330 void SetCookieCallback(bool result) {
331 ASSERT_TRUE(result);
332 quit_closure_.Run();
335 bool get_cookie_success_ = false;
336 base::Closure quit_closure_;
337 net::CookieStore* cookie_store_ = nullptr;
339 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
342 #if defined(SAFE_BROWSING_SERVICE)
343 class RemoveSafeBrowsingCookieTester : public RemoveCookieTester {
344 public:
345 RemoveSafeBrowsingCookieTester()
346 : browser_process_(TestingBrowserProcess::GetGlobal()) {
347 scoped_refptr<SafeBrowsingService> sb_service =
348 SafeBrowsingService::CreateSafeBrowsingService();
349 browser_process_->SetSafeBrowsingService(sb_service.get());
350 sb_service->Initialize();
351 base::MessageLoop::current()->RunUntilIdle();
353 // Create a cookiemonster that does not have persistant storage, and replace
354 // the SafeBrowsingService created one with it.
355 net::CookieStore* monster =
356 content::CreateCookieStore(content::CookieStoreConfig());
357 sb_service->url_request_context()->GetURLRequestContext()->
358 set_cookie_store(monster);
359 SetMonster(monster);
362 virtual ~RemoveSafeBrowsingCookieTester() {
363 browser_process_->safe_browsing_service()->ShutDown();
364 base::MessageLoop::current()->RunUntilIdle();
365 browser_process_->SetSafeBrowsingService(nullptr);
368 private:
369 TestingBrowserProcess* browser_process_;
371 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
373 #endif
375 class RemoveChannelIDTester : public net::SSLConfigService::Observer {
376 public:
377 explicit RemoveChannelIDTester(TestingProfile* profile) {
378 channel_id_service_ = profile->GetRequestContext()->
379 GetURLRequestContext()->channel_id_service();
380 ssl_config_service_ = profile->GetSSLConfigService();
381 ssl_config_service_->AddObserver(this);
384 ~RemoveChannelIDTester() override {
385 ssl_config_service_->RemoveObserver(this);
388 int ChannelIDCount() { return channel_id_service_->channel_id_count(); }
390 // Add a server bound cert for |server| with specific creation and expiry
391 // times. The cert and key data will be filled with dummy values.
392 void AddChannelIDWithTimes(const std::string& server_identifier,
393 base::Time creation_time) {
394 GetChannelIDStore()->SetChannelID(
395 make_scoped_ptr(new net::ChannelIDStore::ChannelID(
396 server_identifier, creation_time,
397 make_scoped_ptr(crypto::ECPrivateKey::Create()))));
400 // Add a server bound cert for |server|, with the current time as the
401 // creation time. The cert and key data will be filled with dummy values.
402 void AddChannelID(const std::string& server_identifier) {
403 base::Time now = base::Time::Now();
404 AddChannelIDWithTimes(server_identifier, now);
407 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) {
408 GetChannelIDStore()->GetAllChannelIDs(
409 base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback,
410 channel_ids));
413 net::ChannelIDStore* GetChannelIDStore() {
414 return channel_id_service_->GetChannelIDStore();
417 int ssl_config_changed_count() const {
418 return ssl_config_changed_count_;
421 // net::SSLConfigService::Observer implementation:
422 void OnSSLConfigChanged() override { ssl_config_changed_count_++; }
424 private:
425 static void GetAllChannelIDsCallback(
426 net::ChannelIDStore::ChannelIDList* dest,
427 const net::ChannelIDStore::ChannelIDList& result) {
428 *dest = result;
431 net::ChannelIDService* channel_id_service_;
432 scoped_refptr<net::SSLConfigService> ssl_config_service_;
433 int ssl_config_changed_count_ = 0;
435 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester);
438 class RemoveHistoryTester {
439 public:
440 RemoveHistoryTester() {}
442 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
443 if (!profile->CreateHistoryService(true, false))
444 return false;
445 history_service_ = HistoryServiceFactory::GetForProfile(
446 profile, ServiceAccessType::EXPLICIT_ACCESS);
447 return true;
450 // Returns true, if the given URL exists in the history service.
451 bool HistoryContainsURL(const GURL& url) {
452 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
453 new content::MessageLoopRunner;
454 quit_closure_ = message_loop_runner->QuitClosure();
455 history_service_->QueryURL(
456 url,
457 true,
458 base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
459 base::Unretained(this)),
460 &tracker_);
461 message_loop_runner->Run();
462 return query_url_success_;
465 void AddHistory(const GURL& url, base::Time time) {
466 history_service_->AddPage(url, time, nullptr, 0, GURL(),
467 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
468 history::SOURCE_BROWSED, false);
471 private:
472 // Callback for HistoryService::QueryURL.
473 void SaveResultAndQuit(bool success,
474 const history::URLRow&,
475 const history::VisitVector&) {
476 query_url_success_ = success;
477 quit_closure_.Run();
480 // For History requests.
481 base::CancelableTaskTracker tracker_;
482 bool query_url_success_ = false;
483 base::Closure quit_closure_;
485 // TestingProfile owns the history service; we shouldn't delete it.
486 history::HistoryService* history_service_ = nullptr;
488 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
491 class RemoveFaviconTester {
492 public:
493 RemoveFaviconTester() {}
495 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
496 // Create the history service if it has not been created yet.
497 history_service_ = HistoryServiceFactory::GetForProfile(
498 profile, ServiceAccessType::EXPLICIT_ACCESS);
499 if (!history_service_) {
500 if (!profile->CreateHistoryService(true, false))
501 return false;
502 history_service_ = HistoryServiceFactory::GetForProfile(
503 profile, ServiceAccessType::EXPLICIT_ACCESS);
506 profile->CreateFaviconService();
507 favicon_service_ = FaviconServiceFactory::GetForProfile(
508 profile, ServiceAccessType::EXPLICIT_ACCESS);
509 return true;
512 // Returns true if there is a favicon stored for |page_url| in the favicon
513 // database.
514 bool HasFaviconForPageURL(const GURL& page_url) {
515 RequestFaviconSyncForPageURL(page_url);
516 return got_favicon_;
519 // Returns true if:
520 // - There is a favicon stored for |page_url| in the favicon database.
521 // - The stored favicon is expired.
522 bool HasExpiredFaviconForPageURL(const GURL& page_url) {
523 RequestFaviconSyncForPageURL(page_url);
524 return got_expired_favicon_;
527 // Adds a visit to history and stores an arbitrary favicon bitmap for
528 // |page_url|.
529 void VisitAndAddFavicon(const GURL& page_url) {
530 history_service_->AddPage(page_url, base::Time::Now(), nullptr, 0, GURL(),
531 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
532 history::SOURCE_BROWSED, false);
534 SkBitmap bitmap;
535 bitmap.allocN32Pixels(gfx::kFaviconSize, gfx::kFaviconSize);
536 bitmap.eraseColor(SK_ColorBLUE);
537 favicon_service_->SetFavicons(page_url, page_url, favicon_base::FAVICON,
538 gfx::Image::CreateFrom1xBitmap(bitmap));
541 private:
542 // Synchronously requests the favicon for |page_url| from the favicon
543 // database.
544 void RequestFaviconSyncForPageURL(const GURL& page_url) {
545 base::RunLoop run_loop;
546 quit_closure_ = run_loop.QuitClosure();
547 favicon_service_->GetRawFaviconForPageURL(
548 page_url,
549 favicon_base::FAVICON,
550 gfx::kFaviconSize,
551 base::Bind(&RemoveFaviconTester::SaveResultAndQuit,
552 base::Unretained(this)),
553 &tracker_);
554 run_loop.Run();
557 // Callback for HistoryService::QueryURL.
558 void SaveResultAndQuit(const favicon_base::FaviconRawBitmapResult& result) {
559 got_favicon_ = result.is_valid();
560 got_expired_favicon_ = result.is_valid() && result.expired;
561 quit_closure_.Run();
564 // For favicon requests.
565 base::CancelableTaskTracker tracker_;
566 bool got_favicon_ = false;
567 bool got_expired_favicon_ = false;
568 base::Closure quit_closure_;
570 // Owned by TestingProfile.
571 history::HistoryService* history_service_ = nullptr;
572 favicon::FaviconService* favicon_service_ = nullptr;
574 DISALLOW_COPY_AND_ASSIGN(RemoveFaviconTester);
577 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
578 public:
579 explicit RemoveAutofillTester(TestingProfile* profile)
580 : personal_data_manager_(
581 autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
582 autofill::test::DisableSystemServices(profile->GetPrefs());
583 personal_data_manager_->AddObserver(this);
586 ~RemoveAutofillTester() override {
587 personal_data_manager_->RemoveObserver(this);
590 // Returns true if there are autofill profiles.
591 bool HasProfile() {
592 return !personal_data_manager_->GetProfiles().empty() &&
593 !personal_data_manager_->GetCreditCards().empty();
596 bool HasOrigin(const std::string& origin) {
597 const std::vector<autofill::AutofillProfile*>& profiles =
598 personal_data_manager_->GetProfiles();
599 for (const autofill::AutofillProfile* profile : profiles) {
600 if (profile->origin() == origin)
601 return true;
604 const std::vector<autofill::CreditCard*>& credit_cards =
605 personal_data_manager_->GetCreditCards();
606 for (const autofill::CreditCard* credit_card : credit_cards) {
607 if (credit_card->origin() == origin)
608 return true;
611 return false;
614 // Add two profiles and two credit cards to the database. In each pair, one
615 // entry has a web origin and the other has a Chrome origin.
616 void AddProfilesAndCards() {
617 std::vector<autofill::AutofillProfile> profiles;
618 autofill::AutofillProfile profile;
619 profile.set_guid(base::GenerateGUID());
620 profile.set_origin(kWebOrigin);
621 profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
622 profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
623 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
624 profile.SetRawInfo(autofill::EMAIL_ADDRESS,
625 base::ASCIIToUTF16("sue@example.com"));
626 profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
627 profiles.push_back(profile);
629 profile.set_guid(base::GenerateGUID());
630 profile.set_origin(kChromeOrigin);
631 profiles.push_back(profile);
633 personal_data_manager_->SetProfiles(&profiles);
634 base::MessageLoop::current()->Run();
636 std::vector<autofill::CreditCard> cards;
637 autofill::CreditCard card;
638 card.set_guid(base::GenerateGUID());
639 card.set_origin(kWebOrigin);
640 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
641 base::ASCIIToUTF16("1234-5678-9012-3456"));
642 cards.push_back(card);
644 card.set_guid(base::GenerateGUID());
645 card.set_origin(kChromeOrigin);
646 cards.push_back(card);
648 personal_data_manager_->SetCreditCards(&cards);
649 base::MessageLoop::current()->Run();
652 private:
653 void OnPersonalDataChanged() override {
654 base::MessageLoop::current()->Quit();
657 autofill::PersonalDataManager* personal_data_manager_;
658 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
661 class RemoveLocalStorageTester {
662 public:
663 explicit RemoveLocalStorageTester(TestingProfile* profile)
664 : profile_(profile) {
665 dom_storage_context_ =
666 content::BrowserContext::GetDefaultStoragePartition(profile)->
667 GetDOMStorageContext();
670 // Returns true, if the given origin URL exists.
671 bool DOMStorageExistsForOrigin(const GURL& origin) {
672 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
673 new content::MessageLoopRunner;
674 quit_closure_ = message_loop_runner->QuitClosure();
675 GetLocalStorageUsage();
676 message_loop_runner->Run();
677 for (size_t i = 0; i < infos_.size(); ++i) {
678 if (origin == infos_[i].origin)
679 return true;
681 return false;
684 void AddDOMStorageTestData() {
685 // Note: This test depends on details of how the dom_storage library
686 // stores data in the host file system.
687 base::FilePath storage_path =
688 profile_->GetPath().AppendASCII("Local Storage");
689 base::CreateDirectory(storage_path);
691 // Write some files.
692 base::WriteFile(storage_path.Append(kDomStorageOrigin1), nullptr, 0);
693 base::WriteFile(storage_path.Append(kDomStorageOrigin2), nullptr, 0);
694 base::WriteFile(storage_path.Append(kDomStorageOrigin3), nullptr, 0);
695 base::WriteFile(storage_path.Append(kDomStorageExt), nullptr, 0);
697 // Tweak their dates.
698 base::Time now = base::Time::Now();
699 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
701 base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
702 base::TouchFile(storage_path.Append(kDomStorageOrigin2),
703 one_day_ago, one_day_ago);
705 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
706 base::TouchFile(storage_path.Append(kDomStorageOrigin3),
707 sixty_days_ago, sixty_days_ago);
709 base::TouchFile(storage_path.Append(kDomStorageExt), now, now);
712 private:
713 void GetLocalStorageUsage() {
714 dom_storage_context_->GetLocalStorageUsage(
715 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage,
716 base::Unretained(this)));
718 void OnGotLocalStorageUsage(
719 const std::vector<content::LocalStorageUsageInfo>& infos) {
720 infos_ = infos;
721 quit_closure_.Run();
724 // We don't own these pointers.
725 TestingProfile* profile_;
726 content::DOMStorageContext* dom_storage_context_ = nullptr;
728 std::vector<content::LocalStorageUsageInfo> infos_;
729 base::Closure quit_closure_;
731 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
734 class MockDomainReliabilityService : public DomainReliabilityService {
735 public:
736 MockDomainReliabilityService() {}
738 ~MockDomainReliabilityService() override {}
740 scoped_ptr<DomainReliabilityMonitor> CreateMonitor(
741 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
742 override {
743 NOTREACHED();
744 return scoped_ptr<DomainReliabilityMonitor>();
747 void ClearBrowsingData(DomainReliabilityClearMode clear_mode,
748 const base::Closure& callback) override {
749 clear_count_++;
750 last_clear_mode_ = clear_mode;
751 callback.Run();
754 void GetWebUIData(const base::Callback<void(scoped_ptr<base::Value>)>&
755 callback) const override {
756 NOTREACHED();
759 int clear_count() const { return clear_count_; }
761 DomainReliabilityClearMode last_clear_mode() const {
762 return last_clear_mode_;
765 private:
766 unsigned clear_count_ = 0;
767 DomainReliabilityClearMode last_clear_mode_;
770 struct TestingDomainReliabilityServiceFactoryUserData
771 : public base::SupportsUserData::Data {
772 TestingDomainReliabilityServiceFactoryUserData(
773 content::BrowserContext* context,
774 MockDomainReliabilityService* service)
775 : context(context),
776 service(service),
777 attached(false) {}
778 ~TestingDomainReliabilityServiceFactoryUserData() override {}
780 content::BrowserContext* const context;
781 MockDomainReliabilityService* const service;
782 bool attached;
784 static const void* kKey;
787 // static
788 const void* TestingDomainReliabilityServiceFactoryUserData::kKey =
789 &TestingDomainReliabilityServiceFactoryUserData::kKey;
791 scoped_ptr<KeyedService> TestingDomainReliabilityServiceFactoryFunction(
792 content::BrowserContext* context) {
793 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
795 TestingDomainReliabilityServiceFactoryUserData* data =
796 static_cast<TestingDomainReliabilityServiceFactoryUserData*>(
797 context->GetUserData(kKey));
798 EXPECT_TRUE(data);
799 EXPECT_EQ(data->context, context);
800 EXPECT_FALSE(data->attached);
802 data->attached = true;
803 return make_scoped_ptr(data->service);
806 class ClearDomainReliabilityTester {
807 public:
808 explicit ClearDomainReliabilityTester(TestingProfile* profile) :
809 profile_(profile),
810 mock_service_(new MockDomainReliabilityService()) {
811 AttachService();
814 unsigned clear_count() const { return mock_service_->clear_count(); }
816 DomainReliabilityClearMode last_clear_mode() const {
817 return mock_service_->last_clear_mode();
820 private:
821 void AttachService() {
822 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
824 // Attach kludgey UserData struct to profile.
825 TestingDomainReliabilityServiceFactoryUserData* data =
826 new TestingDomainReliabilityServiceFactoryUserData(profile_,
827 mock_service_);
828 EXPECT_FALSE(profile_->GetUserData(kKey));
829 profile_->SetUserData(kKey, data);
831 // Set and use factory that will attach service stuffed in kludgey struct.
832 DomainReliabilityServiceFactory::GetInstance()->SetTestingFactoryAndUse(
833 profile_,
834 &TestingDomainReliabilityServiceFactoryFunction);
836 // Verify and detach kludgey struct.
837 EXPECT_EQ(data, profile_->GetUserData(kKey));
838 EXPECT_TRUE(data->attached);
839 profile_->RemoveUserData(kKey);
842 TestingProfile* profile_;
843 MockDomainReliabilityService* mock_service_;
846 class RemoveDownloadsTester {
847 public:
848 explicit RemoveDownloadsTester(TestingProfile* testing_profile)
849 : download_manager_(new content::MockDownloadManager()),
850 chrome_download_manager_delegate_(testing_profile) {
851 content::BrowserContext::SetDownloadManagerForTesting(testing_profile,
852 download_manager_);
853 EXPECT_EQ(download_manager_,
854 content::BrowserContext::GetDownloadManager(testing_profile));
856 EXPECT_CALL(*download_manager_, GetDelegate())
857 .WillOnce(Return(&chrome_download_manager_delegate_));
858 EXPECT_CALL(*download_manager_, Shutdown());
861 ~RemoveDownloadsTester() { chrome_download_manager_delegate_.Shutdown(); }
863 content::MockDownloadManager* download_manager() { return download_manager_; }
865 private:
866 content::MockDownloadManager* download_manager_;
867 ChromeDownloadManagerDelegate chrome_download_manager_delegate_;
869 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester);
872 // Test Class ----------------------------------------------------------------
874 class BrowsingDataRemoverTest : public testing::Test {
875 public:
876 BrowsingDataRemoverTest()
877 : profile_(new TestingProfile()),
878 clear_domain_reliability_tester_(GetProfile()) {
879 callback_subscription_ =
880 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
881 base::Bind(&BrowsingDataRemoverTest::NotifyWithDetails,
882 base::Unretained(this)));
885 ~BrowsingDataRemoverTest() override {}
887 void TearDown() override {
888 #if defined(ENABLE_EXTENSIONS)
889 mock_policy_ = nullptr;
890 #endif
892 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
893 // posts a message to the WEBKIT thread to delete some of its member
894 // variables. We need to ensure that the profile is destroyed, and that
895 // the message loop is cleared out, before destroying the threads and loop.
896 // Otherwise we leak memory.
897 profile_.reset();
898 base::MessageLoop::current()->RunUntilIdle();
900 TestingBrowserProcess::GetGlobal()->SetLocalState(nullptr);
903 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period,
904 int remove_mask,
905 bool include_protected_origins) {
906 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
907 profile_.get(), period);
909 TestStoragePartition storage_partition;
910 remover->OverrideStoragePartitionForTesting(&storage_partition);
912 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
914 // BrowsingDataRemover deletes itself when it completes.
915 int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB;
916 if (include_protected_origins)
917 origin_type_mask |= BrowsingDataHelper::PROTECTED_WEB;
919 BrowsingDataRemoverCompletionObserver completion_observer(remover);
920 remover->Remove(remove_mask, origin_type_mask);
921 completion_observer.BlockUntilCompletion();
923 // Save so we can verify later.
924 storage_partition_removal_data_ =
925 storage_partition.GetStoragePartitionRemovalData();
928 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period,
929 int remove_mask,
930 const GURL& remove_origin) {
931 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
932 profile_.get(), period);
933 TestStoragePartition storage_partition;
934 remover->OverrideStoragePartitionForTesting(&storage_partition);
936 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
938 // BrowsingDataRemover deletes itself when it completes.
939 BrowsingDataRemoverCompletionObserver completion_observer(remover);
940 remover->RemoveImpl(remove_mask, remove_origin,
941 BrowsingDataHelper::UNPROTECTED_WEB);
942 completion_observer.BlockUntilCompletion();
944 // Save so we can verify later.
945 storage_partition_removal_data_ =
946 storage_partition.GetStoragePartitionRemovalData();
949 TestingProfile* GetProfile() {
950 return profile_.get();
953 base::Time GetBeginTime() {
954 return called_with_details_->removal_begin;
957 int GetRemovalMask() {
958 return called_with_details_->removal_mask;
961 int GetOriginTypeMask() {
962 return called_with_details_->origin_type_mask;
965 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
966 return storage_partition_removal_data_;
969 // Callback for browsing data removal events.
970 void NotifyWithDetails(
971 const BrowsingDataRemover::NotificationDetails& details) {
972 // We're not taking ownership of the details object, but storing a copy of
973 // it locally.
974 called_with_details_.reset(
975 new BrowsingDataRemover::NotificationDetails(details));
977 callback_subscription_.reset();
980 MockExtensionSpecialStoragePolicy* CreateMockPolicy() {
981 #if defined(ENABLE_EXTENSIONS)
982 mock_policy_ = new MockExtensionSpecialStoragePolicy;
983 return mock_policy_.get();
984 #else
985 NOTREACHED();
986 return nullptr;
987 #endif
990 storage::SpecialStoragePolicy* mock_policy() {
991 #if defined(ENABLE_EXTENSIONS)
992 return mock_policy_.get();
993 #else
994 return nullptr;
995 #endif
998 // If |kOrigin1| is protected when extensions are enabled, the expected
999 // result for tests where the OriginMatcherFunction result is variable.
1000 bool ShouldRemoveForProtectedOriginOne() const {
1001 #if defined(ENABLE_EXTENSIONS)
1002 return false;
1003 #else
1004 return true;
1005 #endif
1008 const ClearDomainReliabilityTester& clear_domain_reliability_tester() {
1009 return clear_domain_reliability_tester_;
1012 protected:
1013 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
1015 private:
1016 content::TestBrowserThreadBundle thread_bundle_;
1017 scoped_ptr<TestingProfile> profile_;
1019 StoragePartitionRemovalData storage_partition_removal_data_;
1021 #if defined(ENABLE_EXTENSIONS)
1022 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_;
1023 #endif
1025 BrowsingDataRemover::CallbackSubscription callback_subscription_;
1027 // Needed to mock out DomainReliabilityService, even for unrelated tests.
1028 ClearDomainReliabilityTester clear_domain_reliability_tester_;
1030 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
1033 // Tests ---------------------------------------------------------------------
1035 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
1036 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1037 BrowsingDataRemover::REMOVE_COOKIES,
1038 false);
1040 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1041 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1043 // Verify that storage partition was instructed to remove the cookies.
1044 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1045 EXPECT_EQ(removal_data.remove_mask,
1046 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1047 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1048 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1049 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1050 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1053 TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) {
1054 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1055 BrowsingDataRemover::REMOVE_COOKIES,
1056 false);
1058 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1059 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1061 // Verify that storage partition was instructed to remove the cookies.
1062 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1063 EXPECT_EQ(removal_data.remove_mask,
1064 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1065 // Removing with time period other than EVERYTHING should not clear
1066 // persistent storage data.
1067 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1068 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1069 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1070 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1073 #if defined(SAFE_BROWSING_SERVICE)
1074 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) {
1075 RemoveSafeBrowsingCookieTester tester;
1077 tester.AddCookie();
1078 ASSERT_TRUE(tester.ContainsCookie());
1080 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1081 BrowsingDataRemover::REMOVE_COOKIES, false);
1083 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1084 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1085 EXPECT_FALSE(tester.ContainsCookie());
1088 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) {
1089 RemoveSafeBrowsingCookieTester tester;
1091 tester.AddCookie();
1092 ASSERT_TRUE(tester.ContainsCookie());
1094 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1095 BrowsingDataRemover::REMOVE_COOKIES, false);
1097 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1098 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1099 // Removing with time period other than EVERYTHING should not clear safe
1100 // browsing cookies.
1101 EXPECT_TRUE(tester.ContainsCookie());
1103 #endif
1105 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) {
1106 RemoveChannelIDTester tester(GetProfile());
1108 tester.AddChannelID(kTestOrigin1);
1109 EXPECT_EQ(0, tester.ssl_config_changed_count());
1110 EXPECT_EQ(1, tester.ChannelIDCount());
1112 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1113 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
1115 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
1116 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1117 EXPECT_EQ(1, tester.ssl_config_changed_count());
1118 EXPECT_EQ(0, tester.ChannelIDCount());
1121 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDLastHour) {
1122 RemoveChannelIDTester tester(GetProfile());
1124 base::Time now = base::Time::Now();
1125 tester.AddChannelID(kTestOrigin1);
1126 tester.AddChannelIDWithTimes(kTestOrigin2,
1127 now - base::TimeDelta::FromHours(2));
1128 EXPECT_EQ(0, tester.ssl_config_changed_count());
1129 EXPECT_EQ(2, tester.ChannelIDCount());
1131 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1132 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
1134 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
1135 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1136 EXPECT_EQ(1, tester.ssl_config_changed_count());
1137 ASSERT_EQ(1, tester.ChannelIDCount());
1138 net::ChannelIDStore::ChannelIDList channel_ids;
1139 tester.GetChannelIDList(&channel_ids);
1140 ASSERT_EQ(1U, channel_ids.size());
1141 EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier());
1144 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) {
1145 #if defined(ENABLE_EXTENSIONS)
1146 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1147 // Protect kOrigin1.
1148 policy->AddProtected(kOrigin1.GetOrigin());
1149 #endif
1151 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1152 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1153 false);
1155 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1156 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1158 // Verify that storage partition was instructed to remove the data correctly.
1159 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1160 EXPECT_EQ(removal_data.remove_mask,
1161 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1162 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1163 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1164 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1165 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1167 // Check origin matcher.
1168 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1169 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1170 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1171 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1172 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1175 TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) {
1176 #if defined(ENABLE_EXTENSIONS)
1177 // Protect kOrigin1.
1178 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1179 policy->AddProtected(kOrigin1.GetOrigin());
1180 #endif
1182 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1183 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1184 true);
1186 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1187 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB |
1188 BrowsingDataHelper::PROTECTED_WEB, GetOriginTypeMask());
1190 // Verify that storage partition was instructed to remove the data correctly.
1191 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1192 EXPECT_EQ(removal_data.remove_mask,
1193 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1194 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1195 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1196 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1197 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1199 // Check origin matcher all http origin will match since we specified
1200 // both protected and unprotected.
1201 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1202 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1203 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1204 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1207 TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) {
1208 #if defined(ENABLE_EXTENSIONS)
1209 CreateMockPolicy();
1210 #endif
1212 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
1213 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1214 false);
1216 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1217 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1219 // Verify that storage partition was instructed to remove the data correctly.
1220 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1221 EXPECT_EQ(removal_data.remove_mask,
1222 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1223 // Persistent storage won't be deleted.
1224 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1225 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1226 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1227 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1229 // Check origin matcher.
1230 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1231 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1232 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1233 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1236 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
1237 RemoveHistoryTester tester;
1238 ASSERT_TRUE(tester.Init(GetProfile()));
1240 tester.AddHistory(kOrigin1, base::Time::Now());
1241 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1243 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1244 BrowsingDataRemover::REMOVE_HISTORY, false);
1246 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1247 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1248 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
1251 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
1252 RemoveHistoryTester tester;
1253 ASSERT_TRUE(tester.Init(GetProfile()));
1255 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1257 tester.AddHistory(kOrigin1, base::Time::Now());
1258 tester.AddHistory(kOrigin2, two_hours_ago);
1259 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1260 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1262 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1263 BrowsingDataRemover::REMOVE_HISTORY, false);
1265 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1266 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1267 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
1268 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1271 // This should crash (DCHECK) in Debug, but death tests don't work properly
1272 // here.
1273 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1274 TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
1275 RemoveHistoryTester tester;
1276 ASSERT_TRUE(tester.Init(GetProfile()));
1277 PrefService* prefs = GetProfile()->GetPrefs();
1278 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1280 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1282 tester.AddHistory(kOrigin1, base::Time::Now());
1283 tester.AddHistory(kOrigin2, two_hours_ago);
1284 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1285 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1287 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1288 BrowsingDataRemover::REMOVE_HISTORY, false);
1289 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1290 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1292 // Nothing should have been deleted.
1293 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1294 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1296 #endif
1298 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) {
1299 // Add some history.
1300 RemoveHistoryTester history_tester;
1301 ASSERT_TRUE(history_tester.Init(GetProfile()));
1302 history_tester.AddHistory(kOrigin1, base::Time::Now());
1303 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1305 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1306 BrowsingDataRemover::REMOVE_COOKIES;
1308 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1309 removal_mask, false);
1311 EXPECT_EQ(removal_mask, GetRemovalMask());
1312 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1313 EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1));
1315 // The cookie would be deleted throught the StorageParition, check if the
1316 // partition was requested to remove cookie.
1317 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1318 EXPECT_EQ(removal_data.remove_mask,
1319 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1320 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1321 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1324 // This should crash (DCHECK) in Debug, but death tests don't work properly
1325 // here.
1326 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1327 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
1328 PrefService* prefs = GetProfile()->GetPrefs();
1329 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1331 // Add some history.
1332 RemoveHistoryTester history_tester;
1333 ASSERT_TRUE(history_tester.Init(GetProfile()));
1334 history_tester.AddHistory(kOrigin1, base::Time::Now());
1335 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1337 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1338 BrowsingDataRemover::REMOVE_COOKIES;
1340 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1341 removal_mask, false);
1342 EXPECT_EQ(removal_mask, GetRemovalMask());
1343 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1345 // 1/2. History should remain.
1346 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1348 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if
1349 // the partition was requested to remove cookie.
1350 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1351 EXPECT_EQ(removal_data.remove_mask,
1352 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1353 // Persistent storage won't be deleted, since EVERYTHING was not specified.
1354 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1355 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1357 #endif
1359 // Test that clearing history deletes favicons not associated with bookmarks.
1360 TEST_F(BrowsingDataRemoverTest, RemoveFaviconsForever) {
1361 GURL page_url("http://a");
1363 RemoveFaviconTester favicon_tester;
1364 ASSERT_TRUE(favicon_tester.Init(GetProfile()));
1365 favicon_tester.VisitAndAddFavicon(page_url);
1366 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(page_url));
1368 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1369 BrowsingDataRemover::REMOVE_HISTORY, false);
1370 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1371 EXPECT_FALSE(favicon_tester.HasFaviconForPageURL(page_url));
1374 // Test that a bookmark's favicon is expired and not deleted when clearing
1375 // history. Expiring the favicon causes the bookmark's favicon to be updated
1376 // when the user next visits the bookmarked page. Expiring the bookmark's
1377 // favicon is useful when the bookmark's favicon becomes incorrect (See
1378 // crbug.com/474421 for a sample bug which causes this).
1379 TEST_F(BrowsingDataRemoverTest, ExpireBookmarkFavicons) {
1380 GURL bookmarked_page("http://a");
1382 TestingProfile* profile = GetProfile();
1383 profile->CreateBookmarkModel(true);
1384 bookmarks::BookmarkModel* bookmark_model =
1385 BookmarkModelFactory::GetForProfile(profile);
1386 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
1387 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
1388 base::ASCIIToUTF16("a"), bookmarked_page);
1390 RemoveFaviconTester favicon_tester;
1391 ASSERT_TRUE(favicon_tester.Init(GetProfile()));
1392 favicon_tester.VisitAndAddFavicon(bookmarked_page);
1393 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(bookmarked_page));
1395 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1396 BrowsingDataRemover::REMOVE_HISTORY, false);
1397 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1398 EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page));
1401 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
1402 BlockUntilBrowsingDataRemoved(
1403 BrowsingDataRemover::EVERYTHING,
1404 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1405 BrowsingDataRemover::REMOVE_WEBSQL |
1406 BrowsingDataRemover::REMOVE_APPCACHE |
1407 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1408 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1409 BrowsingDataRemover::REMOVE_INDEXEDDB,
1410 false);
1412 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1413 BrowsingDataRemover::REMOVE_WEBSQL |
1414 BrowsingDataRemover::REMOVE_APPCACHE |
1415 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1416 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1417 BrowsingDataRemover::REMOVE_INDEXEDDB,
1418 GetRemovalMask());
1419 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1421 // Verify storage partition related stuffs.
1422 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1423 EXPECT_EQ(removal_data.remove_mask,
1424 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1425 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1426 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1427 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1428 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1429 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1430 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1431 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1432 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1435 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
1436 #if defined(ENABLE_EXTENSIONS)
1437 CreateMockPolicy();
1438 #endif
1440 BlockUntilBrowsingDataRemoved(
1441 BrowsingDataRemover::EVERYTHING,
1442 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1443 BrowsingDataRemover::REMOVE_WEBSQL |
1444 BrowsingDataRemover::REMOVE_APPCACHE |
1445 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1446 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1447 BrowsingDataRemover::REMOVE_INDEXEDDB,
1448 false);
1450 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1451 BrowsingDataRemover::REMOVE_WEBSQL |
1452 BrowsingDataRemover::REMOVE_APPCACHE |
1453 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1454 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1455 BrowsingDataRemover::REMOVE_INDEXEDDB,
1456 GetRemovalMask());
1457 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1459 // Verify storage partition related stuffs.
1460 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1462 EXPECT_EQ(removal_data.remove_mask,
1463 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1464 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1465 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1466 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1467 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1468 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1469 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1470 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1471 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1473 // Check that all related origin data would be removed, that is, origin
1474 // matcher would match these origin.
1475 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1476 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1477 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1480 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
1481 #if defined(ENABLE_EXTENSIONS)
1482 CreateMockPolicy();
1483 #endif
1485 BlockUntilBrowsingDataRemoved(
1486 BrowsingDataRemover::EVERYTHING,
1487 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1488 BrowsingDataRemover::REMOVE_WEBSQL |
1489 BrowsingDataRemover::REMOVE_APPCACHE |
1490 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1491 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1492 BrowsingDataRemover::REMOVE_INDEXEDDB,
1493 false);
1495 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1496 BrowsingDataRemover::REMOVE_WEBSQL |
1497 BrowsingDataRemover::REMOVE_APPCACHE |
1498 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1499 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1500 BrowsingDataRemover::REMOVE_INDEXEDDB,
1501 GetRemovalMask());
1502 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1504 // Verify storage partition related stuffs.
1505 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1507 EXPECT_EQ(removal_data.remove_mask,
1508 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1509 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1510 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1511 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1512 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1513 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1514 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1515 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1516 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1518 // Check that all related origin data would be removed, that is, origin
1519 // matcher would match these origin.
1520 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1521 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1522 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1525 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
1526 #if defined(ENABLE_EXTENSIONS)
1527 CreateMockPolicy();
1528 #endif
1530 BlockUntilBrowsingDataRemoved(
1531 BrowsingDataRemover::EVERYTHING,
1532 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1533 BrowsingDataRemover::REMOVE_WEBSQL |
1534 BrowsingDataRemover::REMOVE_APPCACHE |
1535 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1536 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1537 BrowsingDataRemover::REMOVE_INDEXEDDB,
1538 false);
1540 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1541 BrowsingDataRemover::REMOVE_WEBSQL |
1542 BrowsingDataRemover::REMOVE_APPCACHE |
1543 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1544 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1545 BrowsingDataRemover::REMOVE_INDEXEDDB,
1546 GetRemovalMask());
1547 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1549 // Verify storage partition related stuffs.
1550 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1552 EXPECT_EQ(removal_data.remove_mask,
1553 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1554 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1555 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1556 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1557 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1558 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1559 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1560 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1561 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1563 // Check that all related origin data would be removed, that is, origin
1564 // matcher would match these origin.
1565 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1566 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1567 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1570 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
1571 // Remove Origin 1.
1572 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1573 BrowsingDataRemover::REMOVE_APPCACHE |
1574 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1575 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1576 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1577 BrowsingDataRemover::REMOVE_INDEXEDDB |
1578 BrowsingDataRemover::REMOVE_WEBSQL,
1579 kOrigin1);
1581 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1582 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1583 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1584 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1585 BrowsingDataRemover::REMOVE_INDEXEDDB |
1586 BrowsingDataRemover::REMOVE_WEBSQL,
1587 GetRemovalMask());
1588 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1590 // Verify storage partition related stuffs.
1591 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1593 EXPECT_EQ(removal_data.remove_mask,
1594 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1595 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1596 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1597 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1598 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1599 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1600 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1601 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1602 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1605 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
1606 BlockUntilBrowsingDataRemoved(
1607 BrowsingDataRemover::LAST_HOUR,
1608 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1609 BrowsingDataRemover::REMOVE_WEBSQL |
1610 BrowsingDataRemover::REMOVE_APPCACHE |
1611 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1612 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1613 BrowsingDataRemover::REMOVE_INDEXEDDB,
1614 false);
1616 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1617 BrowsingDataRemover::REMOVE_WEBSQL |
1618 BrowsingDataRemover::REMOVE_APPCACHE |
1619 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1620 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1621 BrowsingDataRemover::REMOVE_INDEXEDDB,
1622 GetRemovalMask());
1623 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1625 // Verify storage partition related stuffs.
1626 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1628 EXPECT_EQ(removal_data.remove_mask,
1629 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1630 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1631 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1632 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1633 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1634 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1636 // Persistent data would be left out since we are not removing from
1637 // beginning of time.
1638 uint32 expected_quota_mask =
1639 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1640 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1641 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1642 // Check removal begin time.
1643 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1646 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
1647 BlockUntilBrowsingDataRemoved(
1648 BrowsingDataRemover::LAST_WEEK,
1649 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1650 BrowsingDataRemover::REMOVE_WEBSQL |
1651 BrowsingDataRemover::REMOVE_APPCACHE |
1652 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1653 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1654 BrowsingDataRemover::REMOVE_INDEXEDDB,
1655 false);
1657 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1658 BrowsingDataRemover::REMOVE_WEBSQL |
1659 BrowsingDataRemover::REMOVE_APPCACHE |
1660 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1661 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1662 BrowsingDataRemover::REMOVE_INDEXEDDB,
1663 GetRemovalMask());
1664 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1666 // Verify storage partition related stuffs.
1667 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1669 EXPECT_EQ(removal_data.remove_mask,
1670 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1671 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1672 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1673 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1674 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1675 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1677 // Persistent data would be left out since we are not removing from
1678 // beginning of time.
1679 uint32 expected_quota_mask =
1680 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1681 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1682 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1683 // Check removal begin time.
1684 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1687 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
1688 #if defined(ENABLE_EXTENSIONS)
1689 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1690 // Protect kOrigin1.
1691 policy->AddProtected(kOrigin1.GetOrigin());
1692 #endif
1694 BlockUntilBrowsingDataRemoved(
1695 BrowsingDataRemover::EVERYTHING,
1696 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1697 BrowsingDataRemover::REMOVE_WEBSQL |
1698 BrowsingDataRemover::REMOVE_APPCACHE |
1699 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1700 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1701 BrowsingDataRemover::REMOVE_INDEXEDDB,
1702 false);
1704 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1705 BrowsingDataRemover::REMOVE_WEBSQL |
1706 BrowsingDataRemover::REMOVE_APPCACHE |
1707 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1708 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1709 BrowsingDataRemover::REMOVE_INDEXEDDB,
1710 GetRemovalMask());
1711 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1713 // Verify storage partition related stuffs.
1714 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1716 EXPECT_EQ(removal_data.remove_mask,
1717 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1718 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1719 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1720 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1721 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1722 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1723 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1724 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1725 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1727 // Check OriginMatcherFunction.
1728 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1729 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1730 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1731 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1734 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) {
1735 #if defined(ENABLE_EXTENSIONS)
1736 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1737 // Protect kOrigin1.
1738 policy->AddProtected(kOrigin1.GetOrigin());
1739 #endif
1741 // Try to remove kOrigin1. Expect failure.
1742 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1743 BrowsingDataRemover::REMOVE_APPCACHE |
1744 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1745 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1746 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1747 BrowsingDataRemover::REMOVE_INDEXEDDB |
1748 BrowsingDataRemover::REMOVE_WEBSQL,
1749 kOrigin1);
1751 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1752 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1753 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1754 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1755 BrowsingDataRemover::REMOVE_INDEXEDDB |
1756 BrowsingDataRemover::REMOVE_WEBSQL,
1757 GetRemovalMask());
1758 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1760 // Verify storage partition related stuffs.
1761 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1763 EXPECT_EQ(removal_data.remove_mask,
1764 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1765 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1766 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1767 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1768 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1769 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1770 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1771 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1772 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1774 // Check OriginMatcherFunction.
1775 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1776 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1777 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1778 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1781 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) {
1782 #if defined(ENABLE_EXTENSIONS)
1783 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1784 // Protect kOrigin1.
1785 policy->AddProtected(kOrigin1.GetOrigin());
1786 #endif
1788 // Try to remove kOrigin1. Expect success.
1789 BlockUntilBrowsingDataRemoved(
1790 BrowsingDataRemover::EVERYTHING,
1791 BrowsingDataRemover::REMOVE_APPCACHE |
1792 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1793 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1794 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1795 BrowsingDataRemover::REMOVE_INDEXEDDB |
1796 BrowsingDataRemover::REMOVE_WEBSQL,
1797 true);
1799 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1800 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1801 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1802 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1803 BrowsingDataRemover::REMOVE_INDEXEDDB |
1804 BrowsingDataRemover::REMOVE_WEBSQL,
1805 GetRemovalMask());
1806 EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB |
1807 BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1809 // Verify storage partition related stuffs.
1810 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1812 EXPECT_EQ(removal_data.remove_mask,
1813 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1814 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1815 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1816 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1817 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1818 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1819 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1820 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1821 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1823 // Check OriginMatcherFunction, |kOrigin1| would match mask since we
1824 // would have 'protected' specified in origin_type_mask.
1825 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1826 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1827 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1830 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
1831 #if defined(ENABLE_EXTENSIONS)
1832 CreateMockPolicy();
1833 #endif
1835 BlockUntilBrowsingDataRemoved(
1836 BrowsingDataRemover::EVERYTHING,
1837 BrowsingDataRemover::REMOVE_APPCACHE |
1838 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1839 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1840 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1841 BrowsingDataRemover::REMOVE_INDEXEDDB |
1842 BrowsingDataRemover::REMOVE_WEBSQL,
1843 false);
1845 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1846 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1847 BrowsingDataRemover::REMOVE_CACHE_STORAGE |
1848 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1849 BrowsingDataRemover::REMOVE_INDEXEDDB |
1850 BrowsingDataRemover::REMOVE_WEBSQL,
1851 GetRemovalMask());
1852 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1854 // Verify storage partition related stuffs.
1855 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1857 EXPECT_EQ(removal_data.remove_mask,
1858 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1859 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1860 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1861 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1862 StoragePartition::REMOVE_DATA_MASK_CACHE_STORAGE |
1863 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1864 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1865 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1866 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1868 // Check that extension and devtools data wouldn't be removed, that is,
1869 // origin matcher would not match these origin.
1870 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1871 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy()));
1874 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) {
1875 RemoveHistoryTester tester;
1876 ASSERT_TRUE(tester.Init(GetProfile()));
1878 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1880 tester.AddHistory(kOrigin1, base::Time::Now());
1881 tester.AddHistory(kOrigin2, two_hours_ago);
1882 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1883 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1885 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1886 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1888 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1889 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1891 // Nothing should have been deleted.
1892 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1893 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2));
1896 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
1897 RemoveHistoryTester tester;
1898 ASSERT_TRUE(tester.Init(GetProfile()));
1900 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1902 tester.AddHistory(kOrigin1, base::Time::Now());
1903 tester.AddHistory(kOrigin2, two_hours_ago);
1904 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1905 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1907 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
1908 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1910 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1911 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1912 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1913 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1916 // Verify that clearing autofill form data works.
1917 TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) {
1918 GetProfile()->CreateWebDataService();
1919 RemoveAutofillTester tester(GetProfile());
1921 ASSERT_FALSE(tester.HasProfile());
1922 tester.AddProfilesAndCards();
1923 ASSERT_TRUE(tester.HasProfile());
1925 BlockUntilBrowsingDataRemoved(
1926 BrowsingDataRemover::LAST_HOUR,
1927 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1929 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1930 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1931 ASSERT_FALSE(tester.HasProfile());
1934 TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) {
1935 GetProfile()->CreateWebDataService();
1936 RemoveAutofillTester tester(GetProfile());
1938 ASSERT_FALSE(tester.HasProfile());
1939 tester.AddProfilesAndCards();
1940 ASSERT_TRUE(tester.HasProfile());
1942 BlockUntilBrowsingDataRemoved(
1943 BrowsingDataRemover::EVERYTHING,
1944 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1946 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1947 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1948 ASSERT_FALSE(tester.HasProfile());
1951 // Verify that clearing autofill form data works.
1952 TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) {
1953 GetProfile()->CreateWebDataService();
1954 RemoveAutofillTester tester(GetProfile());
1956 tester.AddProfilesAndCards();
1957 EXPECT_FALSE(tester.HasOrigin(std::string()));
1958 EXPECT_TRUE(tester.HasOrigin(kWebOrigin));
1959 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1961 BlockUntilBrowsingDataRemoved(
1962 BrowsingDataRemover::LAST_HOUR,
1963 BrowsingDataRemover::REMOVE_HISTORY, false);
1965 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1966 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1967 EXPECT_TRUE(tester.HasOrigin(std::string()));
1968 EXPECT_FALSE(tester.HasOrigin(kWebOrigin));
1969 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1972 TEST_F(BrowsingDataRemoverTest, CompletionInhibition) {
1973 // The |completion_inhibitor| on the stack should prevent removal sessions
1974 // from completing until after ContinueToCompletion() is called.
1975 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
1977 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
1979 // BrowsingDataRemover deletes itself when it completes.
1980 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
1981 GetProfile(), BrowsingDataRemover::EVERYTHING);
1982 remover->Remove(BrowsingDataRemover::REMOVE_HISTORY,
1983 BrowsingDataHelper::UNPROTECTED_WEB);
1985 // Process messages until the inhibitor is notified, and then some, to make
1986 // sure we do not complete asynchronously before ContinueToCompletion() is
1987 // called.
1988 completion_inhibitor.BlockUntilNearCompletion();
1989 base::RunLoop().RunUntilIdle();
1991 // Verify that the completion notification has not yet been broadcasted.
1992 EXPECT_EQ(-1, GetRemovalMask());
1993 EXPECT_EQ(-1, GetOriginTypeMask());
1995 // Now run the removal process until completion, and verify that observers are
1996 // now notified, and the notifications is sent out.
1997 BrowsingDataRemoverCompletionObserver completion_observer(remover);
1998 completion_inhibitor.ContinueToCompletion();
1999 completion_observer.BlockUntilCompletion();
2001 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
2002 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
2005 TEST_F(BrowsingDataRemoverTest, ZeroSuggestCacheClear) {
2006 PrefService* prefs = GetProfile()->GetPrefs();
2007 prefs->SetString(omnibox::kZeroSuggestCachedResults,
2008 "[\"\", [\"foo\", \"bar\"]]");
2009 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
2010 BrowsingDataRemover::REMOVE_COOKIES,
2011 false);
2013 // Expect the prefs to be cleared when cookies are removed.
2014 EXPECT_TRUE(prefs->GetString(omnibox::kZeroSuggestCachedResults).empty());
2015 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
2016 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
2019 #if defined(OS_CHROMEOS)
2020 TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) {
2021 chromeos::ScopedTestDeviceSettingsService test_device_settings_service;
2022 chromeos::ScopedTestCrosSettings test_cros_settings;
2023 chromeos::MockUserManager* mock_user_manager =
2024 new testing::NiceMock<chromeos::MockUserManager>();
2025 mock_user_manager->SetActiveUser("test@example.com");
2026 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager);
2028 scoped_ptr<chromeos::DBusThreadManagerSetter> dbus_setter =
2029 chromeos::DBusThreadManager::GetSetterForTesting();
2030 chromeos::MockCryptohomeClient* cryptohome_client =
2031 new chromeos::MockCryptohomeClient;
2032 dbus_setter->SetCryptohomeClient(
2033 scoped_ptr<chromeos::CryptohomeClient>(cryptohome_client));
2035 // Expect exactly one call. No calls means no attempt to delete keys and more
2036 // than one call means a significant performance problem.
2037 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
2038 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
2040 BlockUntilBrowsingDataRemoved(
2041 BrowsingDataRemover::EVERYTHING,
2042 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false);
2044 chromeos::DBusThreadManager::Shutdown();
2046 #endif
2048 TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) {
2049 const ClearDomainReliabilityTester& tester =
2050 clear_domain_reliability_tester();
2052 EXPECT_EQ(0u, tester.clear_count());
2055 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) {
2056 const ClearDomainReliabilityTester& tester =
2057 clear_domain_reliability_tester();
2059 BlockUntilBrowsingDataRemoved(
2060 BrowsingDataRemover::EVERYTHING,
2061 BrowsingDataRemover::REMOVE_HISTORY, false);
2062 EXPECT_EQ(1u, tester.clear_count());
2063 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode());
2066 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) {
2067 const ClearDomainReliabilityTester& tester =
2068 clear_domain_reliability_tester();
2070 BlockUntilBrowsingDataRemoved(
2071 BrowsingDataRemover::EVERYTHING,
2072 BrowsingDataRemover::REMOVE_COOKIES, false);
2073 EXPECT_EQ(1u, tester.clear_count());
2074 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2077 TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) {
2078 const ClearDomainReliabilityTester& tester =
2079 clear_domain_reliability_tester();
2081 BlockUntilBrowsingDataRemoved(
2082 BrowsingDataRemover::EVERYTHING,
2083 BrowsingDataRemover::REMOVE_HISTORY |
2084 BrowsingDataRemover::REMOVE_COOKIES, false);
2085 EXPECT_EQ(1u, tester.clear_count());
2086 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2089 TEST_F(BrowsingDataRemoverTest, DomainReliability_ProtectedOrigins) {
2090 const ClearDomainReliabilityTester& tester =
2091 clear_domain_reliability_tester();
2093 BlockUntilBrowsingDataRemoved(
2094 BrowsingDataRemover::EVERYTHING,
2095 BrowsingDataRemover::REMOVE_COOKIES, true);
2096 EXPECT_EQ(1u, tester.clear_count());
2097 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2100 // TODO(ttuttle): This isn't actually testing the no-monitor case, since
2101 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed
2102 // for some unrelated test cases. This should be fixed so it tests the no-
2103 // monitor case again.
2104 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) {
2105 BlockUntilBrowsingDataRemoved(
2106 BrowsingDataRemover::EVERYTHING,
2107 BrowsingDataRemover::REMOVE_HISTORY |
2108 BrowsingDataRemover::REMOVE_COOKIES, false);
2111 TEST_F(BrowsingDataRemoverTest, RemoveSameOriginDownloads) {
2112 RemoveDownloadsTester tester(GetProfile());
2113 const url::Origin expectedOrigin(kOrigin1);
2115 EXPECT_CALL(*tester.download_manager(),
2116 RemoveDownloadsByOriginAndTime(SameOrigin(expectedOrigin), _, _));
2118 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
2119 BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1);