[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_remover_unittest.cc
blob59e73b3f9e070e20cc76c3d862cf472880c1afc5
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;
141 uint32 quota_storage_remove_mask;
142 GURL remove_origin;
143 base::Time remove_begin;
144 base::Time remove_end;
145 StoragePartition::OriginMatcherFunction origin_matcher;
147 StoragePartitionRemovalData() : remove_mask(0),
148 quota_storage_remove_mask(0) {}
151 class TestStoragePartition : public StoragePartition {
152 public:
153 TestStoragePartition() {}
154 ~TestStoragePartition() override {}
156 // content::StoragePartition implementation.
157 base::FilePath GetPath() override { return base::FilePath(); }
158 net::URLRequestContextGetter* GetURLRequestContext() override { return NULL; }
159 net::URLRequestContextGetter* GetMediaURLRequestContext() override {
160 return NULL;
162 storage::QuotaManager* GetQuotaManager() override { return NULL; }
163 content::AppCacheService* GetAppCacheService() override { return NULL; }
164 storage::FileSystemContext* GetFileSystemContext() override { return NULL; }
165 storage::DatabaseTracker* GetDatabaseTracker() override { return NULL; }
166 content::DOMStorageContext* GetDOMStorageContext() override { return NULL; }
167 content::IndexedDBContext* GetIndexedDBContext() override { return NULL; }
168 content::ServiceWorkerContext* GetServiceWorkerContext() override {
169 return NULL;
171 content::GeofencingManager* GetGeofencingManager() override { return NULL; }
172 content::NavigatorConnectContext* GetNavigatorConnectContext() override {
173 return nullptr;
176 content::PlatformNotificationContext* GetPlatformNotificationContext()
177 override {
178 return nullptr;
181 content::BackgroundSyncContext* GetBackgroundSyncContext() override {
182 return nullptr;
185 content::HostZoomMap* GetHostZoomMap() override { return NULL; }
186 content::HostZoomLevelContext* GetHostZoomLevelContext() override {
187 return NULL;
189 content::ZoomLevelDelegate* GetZoomLevelDelegate() override { return NULL; }
191 void ClearDataForOrigin(uint32 remove_mask,
192 uint32 quota_storage_remove_mask,
193 const GURL& storage_origin,
194 net::URLRequestContextGetter* rq_context,
195 const base::Closure& callback) override {
196 BrowserThread::PostTask(BrowserThread::UI,
197 FROM_HERE,
198 base::Bind(&TestStoragePartition::AsyncRunCallback,
199 base::Unretained(this),
200 callback));
203 void ClearData(uint32 remove_mask,
204 uint32 quota_storage_remove_mask,
205 const GURL& storage_origin,
206 const OriginMatcherFunction& origin_matcher,
207 const base::Time begin,
208 const base::Time end,
209 const base::Closure& callback) override {
210 // Store stuff to verify parameters' correctness later.
211 storage_partition_removal_data_.remove_mask = remove_mask;
212 storage_partition_removal_data_.quota_storage_remove_mask =
213 quota_storage_remove_mask;
214 storage_partition_removal_data_.remove_origin = storage_origin;
215 storage_partition_removal_data_.remove_begin = begin;
216 storage_partition_removal_data_.remove_end = end;
217 storage_partition_removal_data_.origin_matcher = origin_matcher;
219 BrowserThread::PostTask(
220 BrowserThread::UI,
221 FROM_HERE,
222 base::Bind(&TestStoragePartition::AsyncRunCallback,
223 base::Unretained(this), callback));
226 void Flush() override {}
228 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
229 return storage_partition_removal_data_;
232 private:
233 void AsyncRunCallback(const base::Closure& callback) {
234 callback.Run();
237 StoragePartitionRemovalData storage_partition_removal_data_;
239 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition);
242 // Custom matcher to verify is-same-origin relationship to given reference
243 // origin.
244 // (We cannot use equality-based matching because operator== is not defined for
245 // Origin, and we in fact want to rely on IsSameOrigin for matching purposes.)
246 class SameOriginMatcher : public MatcherInterface<const url::Origin&> {
247 public:
248 explicit SameOriginMatcher(const url::Origin& reference)
249 : reference_(reference) {}
251 virtual bool MatchAndExplain(const url::Origin& origin,
252 MatchResultListener* listener) const {
253 return reference_.IsSameOriginWith(origin);
256 virtual void DescribeTo(::std::ostream* os) const {
257 *os << "is same origin with " << reference_;
260 virtual void DescribeNegationTo(::std::ostream* os) const {
261 *os << "is not same origin with " << reference_;
264 private:
265 const url::Origin& reference_;
268 inline Matcher<const url::Origin&> SameOrigin(const url::Origin& reference) {
269 return MakeMatcher(new SameOriginMatcher(reference));
272 } // namespace
274 // Testers -------------------------------------------------------------------
276 class RemoveCookieTester {
277 public:
278 RemoveCookieTester() : get_cookie_success_(false), cookie_store_(NULL) {
281 // Returns true, if the given cookie exists in the cookie store.
282 bool ContainsCookie() {
283 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
284 new content::MessageLoopRunner;
285 quit_closure_ = message_loop_runner->QuitClosure();
286 get_cookie_success_ = false;
287 cookie_store_->GetCookiesWithOptionsAsync(
288 kOrigin1, net::CookieOptions(),
289 base::Bind(&RemoveCookieTester::GetCookieCallback,
290 base::Unretained(this)));
291 message_loop_runner->Run();
292 return get_cookie_success_;
295 void AddCookie() {
296 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
297 new content::MessageLoopRunner;
298 quit_closure_ = message_loop_runner->QuitClosure();
299 cookie_store_->SetCookieWithOptionsAsync(
300 kOrigin1, "A=1", net::CookieOptions(),
301 base::Bind(&RemoveCookieTester::SetCookieCallback,
302 base::Unretained(this)));
303 message_loop_runner->Run();
306 protected:
307 void SetMonster(net::CookieStore* monster) {
308 cookie_store_ = monster;
311 private:
312 void GetCookieCallback(const std::string& cookies) {
313 if (cookies == "A=1") {
314 get_cookie_success_ = true;
315 } else {
316 EXPECT_EQ("", cookies);
317 get_cookie_success_ = false;
319 quit_closure_.Run();
322 void SetCookieCallback(bool result) {
323 ASSERT_TRUE(result);
324 quit_closure_.Run();
327 bool get_cookie_success_;
328 base::Closure quit_closure_;
329 net::CookieStore* cookie_store_;
331 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester);
334 #if defined(SAFE_BROWSING_SERVICE)
335 class RemoveSafeBrowsingCookieTester : public RemoveCookieTester {
336 public:
337 RemoveSafeBrowsingCookieTester()
338 : browser_process_(TestingBrowserProcess::GetGlobal()) {
339 scoped_refptr<SafeBrowsingService> sb_service =
340 SafeBrowsingService::CreateSafeBrowsingService();
341 browser_process_->SetSafeBrowsingService(sb_service.get());
342 sb_service->Initialize();
343 base::MessageLoop::current()->RunUntilIdle();
345 // Create a cookiemonster that does not have persistant storage, and replace
346 // the SafeBrowsingService created one with it.
347 net::CookieStore* monster =
348 content::CreateCookieStore(content::CookieStoreConfig());
349 sb_service->url_request_context()->GetURLRequestContext()->
350 set_cookie_store(monster);
351 SetMonster(monster);
354 virtual ~RemoveSafeBrowsingCookieTester() {
355 browser_process_->safe_browsing_service()->ShutDown();
356 base::MessageLoop::current()->RunUntilIdle();
357 browser_process_->SetSafeBrowsingService(NULL);
360 private:
361 TestingBrowserProcess* browser_process_;
363 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester);
365 #endif
367 class RemoveChannelIDTester : public net::SSLConfigService::Observer {
368 public:
369 explicit RemoveChannelIDTester(TestingProfile* profile)
370 : ssl_config_changed_count_(0) {
371 channel_id_service_ = profile->GetRequestContext()->
372 GetURLRequestContext()->channel_id_service();
373 ssl_config_service_ = profile->GetSSLConfigService();
374 ssl_config_service_->AddObserver(this);
377 ~RemoveChannelIDTester() override {
378 ssl_config_service_->RemoveObserver(this);
381 int ChannelIDCount() { return channel_id_service_->channel_id_count(); }
383 // Add a server bound cert for |server| with specific creation and expiry
384 // times. The cert and key data will be filled with dummy values.
385 void AddChannelIDWithTimes(const std::string& server_identifier,
386 base::Time creation_time) {
387 GetChannelIDStore()->SetChannelID(
388 make_scoped_ptr(new net::ChannelIDStore::ChannelID(
389 server_identifier, creation_time,
390 make_scoped_ptr(crypto::ECPrivateKey::Create()))));
393 // Add a server bound cert for |server|, with the current time as the
394 // creation time. The cert and key data will be filled with dummy values.
395 void AddChannelID(const std::string& server_identifier) {
396 base::Time now = base::Time::Now();
397 AddChannelIDWithTimes(server_identifier, now);
400 void GetChannelIDList(net::ChannelIDStore::ChannelIDList* channel_ids) {
401 GetChannelIDStore()->GetAllChannelIDs(
402 base::Bind(&RemoveChannelIDTester::GetAllChannelIDsCallback,
403 channel_ids));
406 net::ChannelIDStore* GetChannelIDStore() {
407 return channel_id_service_->GetChannelIDStore();
410 int ssl_config_changed_count() const {
411 return ssl_config_changed_count_;
414 // net::SSLConfigService::Observer implementation:
415 void OnSSLConfigChanged() override { ssl_config_changed_count_++; }
417 private:
418 static void GetAllChannelIDsCallback(
419 net::ChannelIDStore::ChannelIDList* dest,
420 const net::ChannelIDStore::ChannelIDList& result) {
421 *dest = result;
424 net::ChannelIDService* channel_id_service_;
425 scoped_refptr<net::SSLConfigService> ssl_config_service_;
426 int ssl_config_changed_count_;
428 DISALLOW_COPY_AND_ASSIGN(RemoveChannelIDTester);
431 class RemoveHistoryTester {
432 public:
433 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {}
435 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
436 if (!profile->CreateHistoryService(true, false))
437 return false;
438 history_service_ = HistoryServiceFactory::GetForProfile(
439 profile, ServiceAccessType::EXPLICIT_ACCESS);
440 return true;
443 // Returns true, if the given URL exists in the history service.
444 bool HistoryContainsURL(const GURL& url) {
445 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
446 new content::MessageLoopRunner;
447 quit_closure_ = message_loop_runner->QuitClosure();
448 history_service_->QueryURL(
449 url,
450 true,
451 base::Bind(&RemoveHistoryTester::SaveResultAndQuit,
452 base::Unretained(this)),
453 &tracker_);
454 message_loop_runner->Run();
455 return query_url_success_;
458 void AddHistory(const GURL& url, base::Time time) {
459 history_service_->AddPage(url, time, NULL, 0, GURL(),
460 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
461 history::SOURCE_BROWSED, false);
464 private:
465 // Callback for HistoryService::QueryURL.
466 void SaveResultAndQuit(bool success,
467 const history::URLRow&,
468 const history::VisitVector&) {
469 query_url_success_ = success;
470 quit_closure_.Run();
473 // For History requests.
474 base::CancelableTaskTracker tracker_;
475 bool query_url_success_;
476 base::Closure quit_closure_;
478 // TestingProfile owns the history service; we shouldn't delete it.
479 history::HistoryService* history_service_;
481 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester);
484 class RemoveFaviconTester {
485 public:
486 RemoveFaviconTester()
487 : got_favicon_(false),
488 got_expired_favicon_(false),
489 history_service_(nullptr),
490 favicon_service_(nullptr) {}
492 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT {
493 // Create the history service if it has not been created yet.
494 history_service_ = HistoryServiceFactory::GetForProfile(
495 profile, ServiceAccessType::EXPLICIT_ACCESS);
496 if (!history_service_) {
497 if (!profile->CreateHistoryService(true, false))
498 return false;
499 history_service_ = HistoryServiceFactory::GetForProfile(
500 profile, ServiceAccessType::EXPLICIT_ACCESS);
503 profile->CreateFaviconService();
504 favicon_service_ = FaviconServiceFactory::GetForProfile(
505 profile, ServiceAccessType::EXPLICIT_ACCESS);
506 return true;
509 // Returns true if there is a favicon stored for |page_url| in the favicon
510 // database.
511 bool HasFaviconForPageURL(const GURL& page_url) {
512 RequestFaviconSyncForPageURL(page_url);
513 return got_favicon_;
516 // Returns true if:
517 // - There is a favicon stored for |page_url| in the favicon database.
518 // - The stored favicon is expired.
519 bool HasExpiredFaviconForPageURL(const GURL& page_url) {
520 RequestFaviconSyncForPageURL(page_url);
521 return got_expired_favicon_;
524 // Adds a visit to history and stores an arbitrary favicon bitmap for
525 // |page_url|.
526 void VisitAndAddFavicon(const GURL& page_url) {
527 history_service_->AddPage(page_url, base::Time::Now(), nullptr, 0, GURL(),
528 history::RedirectList(), ui::PAGE_TRANSITION_LINK,
529 history::SOURCE_BROWSED, false);
531 SkBitmap bitmap;
532 bitmap.allocN32Pixels(gfx::kFaviconSize, gfx::kFaviconSize);
533 bitmap.eraseColor(SK_ColorBLUE);
534 favicon_service_->SetFavicons(page_url, page_url, favicon_base::FAVICON,
535 gfx::Image::CreateFrom1xBitmap(bitmap));
538 private:
539 // Synchronously requests the favicon for |page_url| from the favicon
540 // database.
541 void RequestFaviconSyncForPageURL(const GURL& page_url) {
542 base::RunLoop run_loop;
543 quit_closure_ = run_loop.QuitClosure();
544 favicon_service_->GetRawFaviconForPageURL(
545 page_url,
546 favicon_base::FAVICON,
547 gfx::kFaviconSize,
548 base::Bind(&RemoveFaviconTester::SaveResultAndQuit,
549 base::Unretained(this)),
550 &tracker_);
551 run_loop.Run();
554 // Callback for HistoryService::QueryURL.
555 void SaveResultAndQuit(const favicon_base::FaviconRawBitmapResult& result) {
556 got_favicon_ = result.is_valid();
557 got_expired_favicon_ = result.is_valid() && result.expired;
558 quit_closure_.Run();
561 // For favicon requests.
562 base::CancelableTaskTracker tracker_;
563 bool got_favicon_;
564 bool got_expired_favicon_;
565 base::Closure quit_closure_;
567 // Owned by TestingProfile.
568 history::HistoryService* history_service_;
569 favicon::FaviconService* favicon_service_;
571 DISALLOW_COPY_AND_ASSIGN(RemoveFaviconTester);
574 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver {
575 public:
576 explicit RemoveAutofillTester(TestingProfile* profile)
577 : personal_data_manager_(
578 autofill::PersonalDataManagerFactory::GetForProfile(profile)) {
579 autofill::test::DisableSystemServices(profile->GetPrefs());
580 personal_data_manager_->AddObserver(this);
583 ~RemoveAutofillTester() override {
584 personal_data_manager_->RemoveObserver(this);
587 // Returns true if there are autofill profiles.
588 bool HasProfile() {
589 return !personal_data_manager_->GetProfiles().empty() &&
590 !personal_data_manager_->GetCreditCards().empty();
593 bool HasOrigin(const std::string& origin) {
594 const std::vector<autofill::AutofillProfile*>& profiles =
595 personal_data_manager_->GetProfiles();
596 for (std::vector<autofill::AutofillProfile*>::const_iterator it =
597 profiles.begin();
598 it != profiles.end(); ++it) {
599 if ((*it)->origin() == origin)
600 return true;
603 const std::vector<autofill::CreditCard*>& credit_cards =
604 personal_data_manager_->GetCreditCards();
605 for (std::vector<autofill::CreditCard*>::const_iterator it =
606 credit_cards.begin();
607 it != credit_cards.end(); ++it) {
608 if ((*it)->origin() == origin)
609 return true;
612 return false;
615 // Add two profiles and two credit cards to the database. In each pair, one
616 // entry has a web origin and the other has a Chrome origin.
617 void AddProfilesAndCards() {
618 std::vector<autofill::AutofillProfile> profiles;
619 autofill::AutofillProfile profile;
620 profile.set_guid(base::GenerateGUID());
621 profile.set_origin(kWebOrigin);
622 profile.SetRawInfo(autofill::NAME_FIRST, base::ASCIIToUTF16("Bob"));
623 profile.SetRawInfo(autofill::NAME_LAST, base::ASCIIToUTF16("Smith"));
624 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, base::ASCIIToUTF16("94043"));
625 profile.SetRawInfo(autofill::EMAIL_ADDRESS,
626 base::ASCIIToUTF16("sue@example.com"));
627 profile.SetRawInfo(autofill::COMPANY_NAME, base::ASCIIToUTF16("Company X"));
628 profiles.push_back(profile);
630 profile.set_guid(base::GenerateGUID());
631 profile.set_origin(kChromeOrigin);
632 profiles.push_back(profile);
634 personal_data_manager_->SetProfiles(&profiles);
635 base::MessageLoop::current()->Run();
637 std::vector<autofill::CreditCard> cards;
638 autofill::CreditCard card;
639 card.set_guid(base::GenerateGUID());
640 card.set_origin(kWebOrigin);
641 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER,
642 base::ASCIIToUTF16("1234-5678-9012-3456"));
643 cards.push_back(card);
645 card.set_guid(base::GenerateGUID());
646 card.set_origin(kChromeOrigin);
647 cards.push_back(card);
649 personal_data_manager_->SetCreditCards(&cards);
650 base::MessageLoop::current()->Run();
653 private:
654 void OnPersonalDataChanged() override {
655 base::MessageLoop::current()->Quit();
658 autofill::PersonalDataManager* personal_data_manager_;
659 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester);
662 class RemoveLocalStorageTester {
663 public:
664 explicit RemoveLocalStorageTester(TestingProfile* profile)
665 : profile_(profile), dom_storage_context_(NULL) {
666 dom_storage_context_ =
667 content::BrowserContext::GetDefaultStoragePartition(profile)->
668 GetDOMStorageContext();
671 // Returns true, if the given origin URL exists.
672 bool DOMStorageExistsForOrigin(const GURL& origin) {
673 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
674 new content::MessageLoopRunner;
675 quit_closure_ = message_loop_runner->QuitClosure();
676 GetLocalStorageUsage();
677 message_loop_runner->Run();
678 for (size_t i = 0; i < infos_.size(); ++i) {
679 if (origin == infos_[i].origin)
680 return true;
682 return false;
685 void AddDOMStorageTestData() {
686 // Note: This test depends on details of how the dom_storage library
687 // stores data in the host file system.
688 base::FilePath storage_path =
689 profile_->GetPath().AppendASCII("Local Storage");
690 base::CreateDirectory(storage_path);
692 // Write some files.
693 base::WriteFile(storage_path.Append(kDomStorageOrigin1), NULL, 0);
694 base::WriteFile(storage_path.Append(kDomStorageOrigin2), NULL, 0);
695 base::WriteFile(storage_path.Append(kDomStorageOrigin3), NULL, 0);
696 base::WriteFile(storage_path.Append(kDomStorageExt), NULL, 0);
698 // Tweak their dates.
699 base::Time now = base::Time::Now();
700 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now);
702 base::Time one_day_ago = now - base::TimeDelta::FromDays(1);
703 base::TouchFile(storage_path.Append(kDomStorageOrigin2),
704 one_day_ago, one_day_ago);
706 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60);
707 base::TouchFile(storage_path.Append(kDomStorageOrigin3),
708 sixty_days_ago, sixty_days_ago);
710 base::TouchFile(storage_path.Append(kDomStorageExt), now, now);
713 private:
714 void GetLocalStorageUsage() {
715 dom_storage_context_->GetLocalStorageUsage(
716 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage,
717 base::Unretained(this)));
719 void OnGotLocalStorageUsage(
720 const std::vector<content::LocalStorageUsageInfo>& infos) {
721 infos_ = infos;
722 quit_closure_.Run();
725 // We don't own these pointers.
726 TestingProfile* profile_;
727 content::DOMStorageContext* dom_storage_context_;
729 std::vector<content::LocalStorageUsageInfo> infos_;
730 base::Closure quit_closure_;
732 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester);
735 class MockDomainReliabilityService : public DomainReliabilityService {
736 public:
737 MockDomainReliabilityService() : clear_count_(0) {}
739 ~MockDomainReliabilityService() override {}
741 scoped_ptr<DomainReliabilityMonitor> CreateMonitor(
742 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner)
743 override {
744 NOTREACHED();
745 return scoped_ptr<DomainReliabilityMonitor>();
748 void ClearBrowsingData(DomainReliabilityClearMode clear_mode,
749 const base::Closure& callback) override {
750 clear_count_++;
751 last_clear_mode_ = clear_mode;
752 callback.Run();
755 void GetWebUIData(const base::Callback<void(scoped_ptr<base::Value>)>&
756 callback) const override {
757 NOTREACHED();
760 int clear_count() const { return clear_count_; }
762 DomainReliabilityClearMode last_clear_mode() const {
763 return last_clear_mode_;
766 private:
767 unsigned clear_count_;
768 DomainReliabilityClearMode last_clear_mode_;
771 struct TestingDomainReliabilityServiceFactoryUserData
772 : public base::SupportsUserData::Data {
773 TestingDomainReliabilityServiceFactoryUserData(
774 content::BrowserContext* context,
775 MockDomainReliabilityService* service)
776 : context(context),
777 service(service),
778 attached(false) {}
779 ~TestingDomainReliabilityServiceFactoryUserData() override {}
781 content::BrowserContext* const context;
782 MockDomainReliabilityService* const service;
783 bool attached;
785 static const void* kKey;
788 // static
789 const void* TestingDomainReliabilityServiceFactoryUserData::kKey =
790 &TestingDomainReliabilityServiceFactoryUserData::kKey;
792 scoped_ptr<KeyedService> TestingDomainReliabilityServiceFactoryFunction(
793 content::BrowserContext* context) {
794 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
796 TestingDomainReliabilityServiceFactoryUserData* data =
797 static_cast<TestingDomainReliabilityServiceFactoryUserData*>(
798 context->GetUserData(kKey));
799 EXPECT_TRUE(data);
800 EXPECT_EQ(data->context, context);
801 EXPECT_FALSE(data->attached);
803 data->attached = true;
804 return make_scoped_ptr(data->service);
807 class ClearDomainReliabilityTester {
808 public:
809 explicit ClearDomainReliabilityTester(TestingProfile* profile) :
810 profile_(profile),
811 mock_service_(new MockDomainReliabilityService()) {
812 AttachService();
815 unsigned clear_count() const { return mock_service_->clear_count(); }
817 DomainReliabilityClearMode last_clear_mode() const {
818 return mock_service_->last_clear_mode();
821 private:
822 void AttachService() {
823 const void* kKey = TestingDomainReliabilityServiceFactoryUserData::kKey;
825 // Attach kludgey UserData struct to profile.
826 TestingDomainReliabilityServiceFactoryUserData* data =
827 new TestingDomainReliabilityServiceFactoryUserData(profile_,
828 mock_service_);
829 EXPECT_FALSE(profile_->GetUserData(kKey));
830 profile_->SetUserData(kKey, data);
832 // Set and use factory that will attach service stuffed in kludgey struct.
833 DomainReliabilityServiceFactory::GetInstance()->SetTestingFactoryAndUse(
834 profile_,
835 &TestingDomainReliabilityServiceFactoryFunction);
837 // Verify and detach kludgey struct.
838 EXPECT_EQ(data, profile_->GetUserData(kKey));
839 EXPECT_TRUE(data->attached);
840 profile_->RemoveUserData(kKey);
843 TestingProfile* profile_;
844 MockDomainReliabilityService* mock_service_;
847 class RemoveDownloadsTester {
848 public:
849 explicit RemoveDownloadsTester(TestingProfile* testing_profile)
850 : download_manager_(new content::MockDownloadManager()),
851 chrome_download_manager_delegate_(testing_profile) {
852 content::BrowserContext::SetDownloadManagerForTesting(testing_profile,
853 download_manager_);
854 EXPECT_EQ(download_manager_,
855 content::BrowserContext::GetDownloadManager(testing_profile));
857 EXPECT_CALL(*download_manager_, GetDelegate())
858 .WillOnce(Return(&chrome_download_manager_delegate_));
859 EXPECT_CALL(*download_manager_, Shutdown());
862 ~RemoveDownloadsTester() { chrome_download_manager_delegate_.Shutdown(); }
864 content::MockDownloadManager* download_manager() { return download_manager_; }
866 private:
867 content::MockDownloadManager* download_manager_;
868 ChromeDownloadManagerDelegate chrome_download_manager_delegate_;
870 DISALLOW_COPY_AND_ASSIGN(RemoveDownloadsTester);
873 // Test Class ----------------------------------------------------------------
875 class BrowsingDataRemoverTest : public testing::Test {
876 public:
877 BrowsingDataRemoverTest()
878 : profile_(new TestingProfile()),
879 clear_domain_reliability_tester_(GetProfile()) {
880 callback_subscription_ =
881 BrowsingDataRemover::RegisterOnBrowsingDataRemovedCallback(
882 base::Bind(&BrowsingDataRemoverTest::NotifyWithDetails,
883 base::Unretained(this)));
886 ~BrowsingDataRemoverTest() override {}
888 void TearDown() override {
889 #if defined(ENABLE_EXTENSIONS)
890 mock_policy_ = NULL;
891 #endif
893 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor
894 // posts a message to the WEBKIT thread to delete some of its member
895 // variables. We need to ensure that the profile is destroyed, and that
896 // the message loop is cleared out, before destroying the threads and loop.
897 // Otherwise we leak memory.
898 profile_.reset();
899 base::MessageLoop::current()->RunUntilIdle();
901 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL);
904 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period,
905 int remove_mask,
906 bool include_protected_origins) {
907 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
908 profile_.get(), period);
910 TestStoragePartition storage_partition;
911 remover->OverrideStoragePartitionForTesting(&storage_partition);
913 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
915 // BrowsingDataRemover deletes itself when it completes.
916 int origin_type_mask = BrowsingDataHelper::UNPROTECTED_WEB;
917 if (include_protected_origins)
918 origin_type_mask |= BrowsingDataHelper::PROTECTED_WEB;
920 BrowsingDataRemoverCompletionObserver completion_observer(remover);
921 remover->Remove(remove_mask, origin_type_mask);
922 completion_observer.BlockUntilCompletion();
924 // Save so we can verify later.
925 storage_partition_removal_data_ =
926 storage_partition.GetStoragePartitionRemovalData();
929 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period,
930 int remove_mask,
931 const GURL& remove_origin) {
932 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
933 profile_.get(), period);
934 TestStoragePartition storage_partition;
935 remover->OverrideStoragePartitionForTesting(&storage_partition);
937 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
939 // BrowsingDataRemover deletes itself when it completes.
940 BrowsingDataRemoverCompletionObserver completion_observer(remover);
941 remover->RemoveImpl(remove_mask, remove_origin,
942 BrowsingDataHelper::UNPROTECTED_WEB);
943 completion_observer.BlockUntilCompletion();
945 // Save so we can verify later.
946 storage_partition_removal_data_ =
947 storage_partition.GetStoragePartitionRemovalData();
950 TestingProfile* GetProfile() {
951 return profile_.get();
954 base::Time GetBeginTime() {
955 return called_with_details_->removal_begin;
958 int GetRemovalMask() {
959 return called_with_details_->removal_mask;
962 int GetOriginTypeMask() {
963 return called_with_details_->origin_type_mask;
966 StoragePartitionRemovalData GetStoragePartitionRemovalData() {
967 return storage_partition_removal_data_;
970 // Callback for browsing data removal events.
971 void NotifyWithDetails(
972 const BrowsingDataRemover::NotificationDetails& details) {
973 // We're not taking ownership of the details object, but storing a copy of
974 // it locally.
975 called_with_details_.reset(
976 new BrowsingDataRemover::NotificationDetails(details));
978 callback_subscription_.reset();
981 MockExtensionSpecialStoragePolicy* CreateMockPolicy() {
982 #if defined(ENABLE_EXTENSIONS)
983 mock_policy_ = new MockExtensionSpecialStoragePolicy;
984 return mock_policy_.get();
985 #else
986 NOTREACHED();
987 return NULL;
988 #endif
991 storage::SpecialStoragePolicy* mock_policy() {
992 #if defined(ENABLE_EXTENSIONS)
993 return mock_policy_.get();
994 #else
995 return NULL;
996 #endif
999 // If |kOrigin1| is protected when extensions are enabled, the expected
1000 // result for tests where the OriginMatcherFunction result is variable.
1001 bool ShouldRemoveForProtectedOriginOne() const {
1002 #if defined(ENABLE_EXTENSIONS)
1003 return false;
1004 #else
1005 return true;
1006 #endif
1009 const ClearDomainReliabilityTester& clear_domain_reliability_tester() {
1010 return clear_domain_reliability_tester_;
1013 protected:
1014 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_;
1016 private:
1017 content::TestBrowserThreadBundle thread_bundle_;
1018 scoped_ptr<TestingProfile> profile_;
1020 StoragePartitionRemovalData storage_partition_removal_data_;
1022 #if defined(ENABLE_EXTENSIONS)
1023 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy_;
1024 #endif
1026 BrowsingDataRemover::CallbackSubscription callback_subscription_;
1028 // Needed to mock out DomainReliabilityService, even for unrelated tests.
1029 ClearDomainReliabilityTester clear_domain_reliability_tester_;
1031 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest);
1034 // Tests ---------------------------------------------------------------------
1036 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) {
1037 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1038 BrowsingDataRemover::REMOVE_COOKIES,
1039 false);
1041 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1042 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1044 // Verify that storage partition was instructed to remove the cookies.
1045 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1046 EXPECT_EQ(removal_data.remove_mask,
1047 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1048 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1049 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1050 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1051 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1054 TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) {
1055 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1056 BrowsingDataRemover::REMOVE_COOKIES,
1057 false);
1059 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1060 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1062 // Verify that storage partition was instructed to remove the cookies.
1063 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1064 EXPECT_EQ(removal_data.remove_mask,
1065 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1066 // Removing with time period other than EVERYTHING should not clear
1067 // persistent storage data.
1068 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1069 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1070 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1071 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1074 #if defined(SAFE_BROWSING_SERVICE)
1075 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) {
1076 RemoveSafeBrowsingCookieTester tester;
1078 tester.AddCookie();
1079 ASSERT_TRUE(tester.ContainsCookie());
1081 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1082 BrowsingDataRemover::REMOVE_COOKIES, false);
1084 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1085 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1086 EXPECT_FALSE(tester.ContainsCookie());
1089 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) {
1090 RemoveSafeBrowsingCookieTester tester;
1092 tester.AddCookie();
1093 ASSERT_TRUE(tester.ContainsCookie());
1095 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1096 BrowsingDataRemover::REMOVE_COOKIES, false);
1098 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1099 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1100 // Removing with time period other than EVERYTHING should not clear safe
1101 // browsing cookies.
1102 EXPECT_TRUE(tester.ContainsCookie());
1104 #endif
1106 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDForever) {
1107 RemoveChannelIDTester tester(GetProfile());
1109 tester.AddChannelID(kTestOrigin1);
1110 EXPECT_EQ(0, tester.ssl_config_changed_count());
1111 EXPECT_EQ(1, tester.ChannelIDCount());
1113 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1114 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
1116 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
1117 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1118 EXPECT_EQ(1, tester.ssl_config_changed_count());
1119 EXPECT_EQ(0, tester.ChannelIDCount());
1122 TEST_F(BrowsingDataRemoverTest, RemoveChannelIDLastHour) {
1123 RemoveChannelIDTester tester(GetProfile());
1125 base::Time now = base::Time::Now();
1126 tester.AddChannelID(kTestOrigin1);
1127 tester.AddChannelIDWithTimes(kTestOrigin2,
1128 now - base::TimeDelta::FromHours(2));
1129 EXPECT_EQ(0, tester.ssl_config_changed_count());
1130 EXPECT_EQ(2, tester.ChannelIDCount());
1132 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1133 BrowsingDataRemover::REMOVE_CHANNEL_IDS, false);
1135 EXPECT_EQ(BrowsingDataRemover::REMOVE_CHANNEL_IDS, GetRemovalMask());
1136 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1137 EXPECT_EQ(1, tester.ssl_config_changed_count());
1138 ASSERT_EQ(1, tester.ChannelIDCount());
1139 net::ChannelIDStore::ChannelIDList channel_ids;
1140 tester.GetChannelIDList(&channel_ids);
1141 ASSERT_EQ(1U, channel_ids.size());
1142 EXPECT_EQ(kTestOrigin2, channel_ids.front().server_identifier());
1145 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) {
1146 #if defined(ENABLE_EXTENSIONS)
1147 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1148 // Protect kOrigin1.
1149 policy->AddProtected(kOrigin1.GetOrigin());
1150 #endif
1152 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1153 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1154 false);
1156 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1157 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1159 // Verify that storage partition was instructed to remove the data correctly.
1160 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1161 EXPECT_EQ(removal_data.remove_mask,
1162 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1163 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1164 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1165 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1166 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1168 // Check origin matcher.
1169 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1170 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1171 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1172 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1173 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1176 TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) {
1177 #if defined(ENABLE_EXTENSIONS)
1178 // Protect kOrigin1.
1179 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1180 policy->AddProtected(kOrigin1.GetOrigin());
1181 #endif
1183 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1184 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1185 true);
1187 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1188 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB |
1189 BrowsingDataHelper::PROTECTED_WEB, GetOriginTypeMask());
1191 // Verify that storage partition was instructed to remove the data correctly.
1192 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1193 EXPECT_EQ(removal_data.remove_mask,
1194 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1195 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1196 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1197 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1198 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1200 // Check origin matcher all http origin will match since we specified
1201 // both protected and unprotected.
1202 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1203 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1204 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1205 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1208 TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) {
1209 #if defined(ENABLE_EXTENSIONS)
1210 CreateMockPolicy();
1211 #endif
1213 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
1214 BrowsingDataRemover::REMOVE_LOCAL_STORAGE,
1215 false);
1217 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask());
1218 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1220 // Verify that storage partition was instructed to remove the data correctly.
1221 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1222 EXPECT_EQ(removal_data.remove_mask,
1223 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE);
1224 // Persistent storage won't be deleted.
1225 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1226 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1227 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1228 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1230 // Check origin matcher.
1231 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1232 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1233 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1234 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1237 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) {
1238 RemoveHistoryTester tester;
1239 ASSERT_TRUE(tester.Init(GetProfile()));
1241 tester.AddHistory(kOrigin1, base::Time::Now());
1242 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1244 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1245 BrowsingDataRemover::REMOVE_HISTORY, false);
1247 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1248 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1249 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
1252 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) {
1253 RemoveHistoryTester tester;
1254 ASSERT_TRUE(tester.Init(GetProfile()));
1256 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1258 tester.AddHistory(kOrigin1, base::Time::Now());
1259 tester.AddHistory(kOrigin2, two_hours_ago);
1260 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1261 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1263 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1264 BrowsingDataRemover::REMOVE_HISTORY, false);
1266 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1267 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1268 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1));
1269 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1272 // This should crash (DCHECK) in Debug, but death tests don't work properly
1273 // here.
1274 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1275 TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) {
1276 RemoveHistoryTester tester;
1277 ASSERT_TRUE(tester.Init(GetProfile()));
1278 PrefService* prefs = GetProfile()->GetPrefs();
1279 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1281 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1283 tester.AddHistory(kOrigin1, base::Time::Now());
1284 tester.AddHistory(kOrigin2, two_hours_ago);
1285 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1286 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1288 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1289 BrowsingDataRemover::REMOVE_HISTORY, false);
1290 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1291 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1293 // Nothing should have been deleted.
1294 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1295 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1297 #endif
1299 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) {
1300 // Add some history.
1301 RemoveHistoryTester history_tester;
1302 ASSERT_TRUE(history_tester.Init(GetProfile()));
1303 history_tester.AddHistory(kOrigin1, base::Time::Now());
1304 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1306 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1307 BrowsingDataRemover::REMOVE_COOKIES;
1309 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1310 removal_mask, false);
1312 EXPECT_EQ(removal_mask, GetRemovalMask());
1313 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1314 EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1));
1316 // The cookie would be deleted throught the StorageParition, check if the
1317 // partition was requested to remove cookie.
1318 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1319 EXPECT_EQ(removal_data.remove_mask,
1320 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1321 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1322 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1325 // This should crash (DCHECK) in Debug, but death tests don't work properly
1326 // here.
1327 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON)
1328 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) {
1329 PrefService* prefs = GetProfile()->GetPrefs();
1330 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false);
1332 // Add some history.
1333 RemoveHistoryTester history_tester;
1334 ASSERT_TRUE(history_tester.Init(GetProfile()));
1335 history_tester.AddHistory(kOrigin1, base::Time::Now());
1336 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1338 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY |
1339 BrowsingDataRemover::REMOVE_COOKIES;
1341 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1342 removal_mask, false);
1343 EXPECT_EQ(removal_mask, GetRemovalMask());
1344 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1346 // 1/2. History should remain.
1347 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1));
1349 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if
1350 // the partition was requested to remove cookie.
1351 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1352 EXPECT_EQ(removal_data.remove_mask,
1353 StoragePartition::REMOVE_DATA_MASK_COOKIES);
1354 // Persistent storage won't be deleted, since EVERYTHING was not specified.
1355 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1356 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT);
1358 #endif
1360 // Test that clearing history deletes favicons not associated with bookmarks.
1361 TEST_F(BrowsingDataRemoverTest, RemoveFaviconsForever) {
1362 GURL page_url("http://a");
1364 RemoveFaviconTester favicon_tester;
1365 ASSERT_TRUE(favicon_tester.Init(GetProfile()));
1366 favicon_tester.VisitAndAddFavicon(page_url);
1367 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(page_url));
1369 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1370 BrowsingDataRemover::REMOVE_HISTORY, false);
1371 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1372 EXPECT_FALSE(favicon_tester.HasFaviconForPageURL(page_url));
1375 // Test that a bookmark's favicon is expired and not deleted when clearing
1376 // history. Expiring the favicon causes the bookmark's favicon to be updated
1377 // when the user next visits the bookmarked page. Expiring the bookmark's
1378 // favicon is useful when the bookmark's favicon becomes incorrect (See
1379 // crbug.com/474421 for a sample bug which causes this).
1380 TEST_F(BrowsingDataRemoverTest, ExpireBookmarkFavicons) {
1381 GURL bookmarked_page("http://a");
1383 TestingProfile* profile = GetProfile();
1384 profile->CreateBookmarkModel(true);
1385 bookmarks::BookmarkModel* bookmark_model =
1386 BookmarkModelFactory::GetForProfile(profile);
1387 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
1388 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
1389 base::ASCIIToUTF16("a"), bookmarked_page);
1391 RemoveFaviconTester favicon_tester;
1392 ASSERT_TRUE(favicon_tester.Init(GetProfile()));
1393 favicon_tester.VisitAndAddFavicon(bookmarked_page);
1394 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(bookmarked_page));
1396 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1397 BrowsingDataRemover::REMOVE_HISTORY, false);
1398 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1399 EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page));
1402 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) {
1403 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1404 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1405 BrowsingDataRemover::REMOVE_WEBSQL |
1406 BrowsingDataRemover::REMOVE_APPCACHE |
1407 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1408 BrowsingDataRemover::REMOVE_INDEXEDDB,
1409 false);
1411 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1412 BrowsingDataRemover::REMOVE_WEBSQL |
1413 BrowsingDataRemover::REMOVE_APPCACHE |
1414 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1415 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1416 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1418 // Verify storage partition related stuffs.
1419 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1420 EXPECT_EQ(removal_data.remove_mask,
1421 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1422 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1423 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1424 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1425 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1426 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1427 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1428 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1431 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) {
1432 #if defined(ENABLE_EXTENSIONS)
1433 CreateMockPolicy();
1434 #endif
1436 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1437 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1438 BrowsingDataRemover::REMOVE_WEBSQL |
1439 BrowsingDataRemover::REMOVE_APPCACHE |
1440 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1441 BrowsingDataRemover::REMOVE_INDEXEDDB,
1442 false);
1444 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1445 BrowsingDataRemover::REMOVE_WEBSQL |
1446 BrowsingDataRemover::REMOVE_APPCACHE |
1447 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1448 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1449 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1451 // Verify storage partition related stuffs.
1452 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1454 EXPECT_EQ(removal_data.remove_mask,
1455 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1456 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1457 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1458 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1459 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1460 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1461 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1462 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1464 // Check that all related origin data would be removed, that is, origin
1465 // matcher would match these origin.
1466 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1467 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1468 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1471 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) {
1472 #if defined(ENABLE_EXTENSIONS)
1473 CreateMockPolicy();
1474 #endif
1476 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1477 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1478 BrowsingDataRemover::REMOVE_WEBSQL |
1479 BrowsingDataRemover::REMOVE_APPCACHE |
1480 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1481 BrowsingDataRemover::REMOVE_INDEXEDDB,
1482 false);
1484 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1485 BrowsingDataRemover::REMOVE_WEBSQL |
1486 BrowsingDataRemover::REMOVE_APPCACHE |
1487 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1488 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1489 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1491 // Verify storage partition related stuffs.
1492 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1494 EXPECT_EQ(removal_data.remove_mask,
1495 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1496 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1497 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1498 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1499 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1500 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1501 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1502 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1504 // Check that all related origin data would be removed, that is, origin
1505 // matcher would match these origin.
1506 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1507 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1508 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1511 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) {
1512 #if defined(ENABLE_EXTENSIONS)
1513 CreateMockPolicy();
1514 #endif
1517 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1518 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1519 BrowsingDataRemover::REMOVE_WEBSQL |
1520 BrowsingDataRemover::REMOVE_APPCACHE |
1521 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1522 BrowsingDataRemover::REMOVE_INDEXEDDB,
1523 false);
1525 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1526 BrowsingDataRemover::REMOVE_WEBSQL |
1527 BrowsingDataRemover::REMOVE_APPCACHE |
1528 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1529 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1530 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1532 // Verify storage partition related stuffs.
1533 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1535 EXPECT_EQ(removal_data.remove_mask,
1536 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1537 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1538 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1539 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1540 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1541 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1542 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1543 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1545 // Check that all related origin data would be removed, that is, origin
1546 // matcher would match these origin.
1547 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1548 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1549 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1552 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) {
1553 // Remove Origin 1.
1554 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1555 BrowsingDataRemover::REMOVE_APPCACHE |
1556 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1557 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1558 BrowsingDataRemover::REMOVE_INDEXEDDB |
1559 BrowsingDataRemover::REMOVE_WEBSQL,
1560 kOrigin1);
1562 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1563 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1564 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1565 BrowsingDataRemover::REMOVE_INDEXEDDB |
1566 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1567 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1569 // Verify storage partition related stuffs.
1570 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1572 EXPECT_EQ(removal_data.remove_mask,
1573 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1574 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1575 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1576 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1577 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1578 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1579 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1580 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1583 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) {
1584 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR,
1585 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1586 BrowsingDataRemover::REMOVE_WEBSQL |
1587 BrowsingDataRemover::REMOVE_APPCACHE |
1588 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1589 BrowsingDataRemover::REMOVE_INDEXEDDB,
1590 false);
1592 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1593 BrowsingDataRemover::REMOVE_WEBSQL |
1594 BrowsingDataRemover::REMOVE_APPCACHE |
1595 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1596 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1597 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1599 // Verify storage partition related stuffs.
1600 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1602 EXPECT_EQ(removal_data.remove_mask,
1603 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1604 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1605 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1606 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1607 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1609 // Persistent data would be left out since we are not removing from
1610 // beginning of time.
1611 uint32 expected_quota_mask =
1612 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1613 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1614 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1615 // Check removal begin time.
1616 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1619 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) {
1620 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK,
1621 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1622 BrowsingDataRemover::REMOVE_WEBSQL |
1623 BrowsingDataRemover::REMOVE_APPCACHE |
1624 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1625 BrowsingDataRemover::REMOVE_INDEXEDDB,
1626 false);
1628 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1629 BrowsingDataRemover::REMOVE_WEBSQL |
1630 BrowsingDataRemover::REMOVE_APPCACHE |
1631 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1632 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1633 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1635 // Verify storage partition related stuffs.
1636 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1638 EXPECT_EQ(removal_data.remove_mask,
1639 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1640 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1641 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1642 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1643 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1645 // Persistent data would be left out since we are not removing from
1646 // beginning of time.
1647 uint32 expected_quota_mask =
1648 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT;
1649 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask);
1650 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1651 // Check removal begin time.
1652 EXPECT_EQ(removal_data.remove_begin, GetBeginTime());
1655 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) {
1656 #if defined(ENABLE_EXTENSIONS)
1657 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1658 // Protect kOrigin1.
1659 policy->AddProtected(kOrigin1.GetOrigin());
1660 #endif
1662 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1663 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1664 BrowsingDataRemover::REMOVE_WEBSQL |
1665 BrowsingDataRemover::REMOVE_APPCACHE |
1666 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1667 BrowsingDataRemover::REMOVE_INDEXEDDB,
1668 false);
1670 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1671 BrowsingDataRemover::REMOVE_WEBSQL |
1672 BrowsingDataRemover::REMOVE_APPCACHE |
1673 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1674 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask());
1675 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1677 // Verify storage partition related stuffs.
1678 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1680 EXPECT_EQ(removal_data.remove_mask,
1681 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1682 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1683 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1684 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1685 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1686 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1687 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1688 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1690 // Check OriginMatcherFunction.
1691 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1692 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1693 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1694 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1697 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) {
1698 #if defined(ENABLE_EXTENSIONS)
1699 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1700 // Protect kOrigin1.
1701 policy->AddProtected(kOrigin1.GetOrigin());
1702 #endif
1704 // Try to remove kOrigin1. Expect failure.
1705 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1706 BrowsingDataRemover::REMOVE_APPCACHE |
1707 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1708 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1709 BrowsingDataRemover::REMOVE_INDEXEDDB |
1710 BrowsingDataRemover::REMOVE_WEBSQL,
1711 kOrigin1);
1713 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1714 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1715 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1716 BrowsingDataRemover::REMOVE_INDEXEDDB |
1717 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1718 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1720 // Verify storage partition related stuffs.
1721 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1723 EXPECT_EQ(removal_data.remove_mask,
1724 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1725 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1726 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1727 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1728 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1729 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1730 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1731 EXPECT_EQ(removal_data.remove_origin, kOrigin1);
1733 // Check OriginMatcherFunction.
1734 EXPECT_EQ(ShouldRemoveForProtectedOriginOne(),
1735 removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1736 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1737 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1740 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) {
1741 #if defined(ENABLE_EXTENSIONS)
1742 MockExtensionSpecialStoragePolicy* policy = CreateMockPolicy();
1743 // Protect kOrigin1.
1744 policy->AddProtected(kOrigin1.GetOrigin());
1745 #endif
1747 // Try to remove kOrigin1. Expect success.
1748 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1749 BrowsingDataRemover::REMOVE_APPCACHE |
1750 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1751 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1752 BrowsingDataRemover::REMOVE_INDEXEDDB |
1753 BrowsingDataRemover::REMOVE_WEBSQL,
1754 true);
1756 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1757 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1758 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1759 BrowsingDataRemover::REMOVE_INDEXEDDB |
1760 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1761 EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB |
1762 BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1764 // Verify storage partition related stuffs.
1765 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1767 EXPECT_EQ(removal_data.remove_mask,
1768 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1769 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1770 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1771 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1772 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1773 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1774 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1775 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1777 // Check OriginMatcherFunction, |kOrigin1| would match mask since we
1778 // would have 'protected' specified in origin_type_mask.
1779 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy()));
1780 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy()));
1781 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy()));
1784 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) {
1785 #if defined(ENABLE_EXTENSIONS)
1786 CreateMockPolicy();
1787 #endif
1789 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1790 BrowsingDataRemover::REMOVE_APPCACHE |
1791 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1792 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1793 BrowsingDataRemover::REMOVE_INDEXEDDB |
1794 BrowsingDataRemover::REMOVE_WEBSQL,
1795 false);
1797 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE |
1798 BrowsingDataRemover::REMOVE_SERVICE_WORKERS |
1799 BrowsingDataRemover::REMOVE_FILE_SYSTEMS |
1800 BrowsingDataRemover::REMOVE_INDEXEDDB |
1801 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask());
1802 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1804 // Verify storage partition related stuffs.
1805 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData();
1807 EXPECT_EQ(removal_data.remove_mask,
1808 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS |
1809 StoragePartition::REMOVE_DATA_MASK_WEBSQL |
1810 StoragePartition::REMOVE_DATA_MASK_APPCACHE |
1811 StoragePartition::REMOVE_DATA_MASK_SERVICE_WORKERS |
1812 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB);
1813 EXPECT_EQ(removal_data.quota_storage_remove_mask,
1814 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL);
1815 EXPECT_TRUE(removal_data.remove_origin.is_empty());
1817 // Check that extension and devtools data wouldn't be removed, that is,
1818 // origin matcher would not match these origin.
1819 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy()));
1820 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy()));
1823 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) {
1824 RemoveHistoryTester tester;
1825 ASSERT_TRUE(tester.Init(GetProfile()));
1827 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1829 tester.AddHistory(kOrigin1, base::Time::Now());
1830 tester.AddHistory(kOrigin2, two_hours_ago);
1831 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1832 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1834 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
1835 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1837 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1838 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1840 // Nothing should have been deleted.
1841 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1842 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2));
1845 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) {
1846 RemoveHistoryTester tester;
1847 ASSERT_TRUE(tester.Init(GetProfile()));
1849 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2);
1851 tester.AddHistory(kOrigin1, base::Time::Now());
1852 tester.AddHistory(kOrigin2, two_hours_ago);
1853 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1));
1854 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2));
1856 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR,
1857 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2);
1859 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1860 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1861 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1));
1862 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2));
1865 // Verify that clearing autofill form data works.
1866 TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) {
1867 GetProfile()->CreateWebDataService();
1868 RemoveAutofillTester tester(GetProfile());
1870 ASSERT_FALSE(tester.HasProfile());
1871 tester.AddProfilesAndCards();
1872 ASSERT_TRUE(tester.HasProfile());
1874 BlockUntilBrowsingDataRemoved(
1875 BrowsingDataRemover::LAST_HOUR,
1876 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1878 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1879 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1880 ASSERT_FALSE(tester.HasProfile());
1883 TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) {
1884 GetProfile()->CreateWebDataService();
1885 RemoveAutofillTester tester(GetProfile());
1887 ASSERT_FALSE(tester.HasProfile());
1888 tester.AddProfilesAndCards();
1889 ASSERT_TRUE(tester.HasProfile());
1891 BlockUntilBrowsingDataRemoved(
1892 BrowsingDataRemover::EVERYTHING,
1893 BrowsingDataRemover::REMOVE_FORM_DATA, false);
1895 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask());
1896 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1897 ASSERT_FALSE(tester.HasProfile());
1900 // Verify that clearing autofill form data works.
1901 TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) {
1902 GetProfile()->CreateWebDataService();
1903 RemoveAutofillTester tester(GetProfile());
1905 tester.AddProfilesAndCards();
1906 EXPECT_FALSE(tester.HasOrigin(std::string()));
1907 EXPECT_TRUE(tester.HasOrigin(kWebOrigin));
1908 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1910 BlockUntilBrowsingDataRemoved(
1911 BrowsingDataRemover::LAST_HOUR,
1912 BrowsingDataRemover::REMOVE_HISTORY, false);
1914 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1915 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1916 EXPECT_TRUE(tester.HasOrigin(std::string()));
1917 EXPECT_FALSE(tester.HasOrigin(kWebOrigin));
1918 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin));
1921 TEST_F(BrowsingDataRemoverTest, CompletionInhibition) {
1922 // The |completion_inhibitor| on the stack should prevent removal sessions
1923 // from completing until after ContinueToCompletion() is called.
1924 BrowsingDataRemoverCompletionInhibitor completion_inhibitor;
1926 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails());
1928 // BrowsingDataRemover deletes itself when it completes.
1929 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod(
1930 GetProfile(), BrowsingDataRemover::EVERYTHING);
1931 remover->Remove(BrowsingDataRemover::REMOVE_HISTORY,
1932 BrowsingDataHelper::UNPROTECTED_WEB);
1934 // Process messages until the inhibitor is notified, and then some, to make
1935 // sure we do not complete asynchronously before ContinueToCompletion() is
1936 // called.
1937 completion_inhibitor.BlockUntilNearCompletion();
1938 base::RunLoop().RunUntilIdle();
1940 // Verify that the completion notification has not yet been broadcasted.
1941 EXPECT_EQ(-1, GetRemovalMask());
1942 EXPECT_EQ(-1, GetOriginTypeMask());
1944 // Now run the removal process until completion, and verify that observers are
1945 // now notified, and the notifications is sent out.
1946 BrowsingDataRemoverCompletionObserver completion_observer(remover);
1947 completion_inhibitor.ContinueToCompletion();
1948 completion_observer.BlockUntilCompletion();
1950 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask());
1951 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1954 TEST_F(BrowsingDataRemoverTest, ZeroSuggestCacheClear) {
1955 PrefService* prefs = GetProfile()->GetPrefs();
1956 prefs->SetString(omnibox::kZeroSuggestCachedResults,
1957 "[\"\", [\"foo\", \"bar\"]]");
1958 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING,
1959 BrowsingDataRemover::REMOVE_COOKIES,
1960 false);
1962 // Expect the prefs to be cleared when cookies are removed.
1963 EXPECT_TRUE(prefs->GetString(omnibox::kZeroSuggestCachedResults).empty());
1964 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask());
1965 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginTypeMask());
1968 #if defined(OS_CHROMEOS)
1969 TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) {
1970 chromeos::ScopedTestDeviceSettingsService test_device_settings_service;
1971 chromeos::ScopedTestCrosSettings test_cros_settings;
1972 chromeos::MockUserManager* mock_user_manager =
1973 new testing::NiceMock<chromeos::MockUserManager>();
1974 mock_user_manager->SetActiveUser("test@example.com");
1975 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager);
1977 scoped_ptr<chromeos::DBusThreadManagerSetter> dbus_setter =
1978 chromeos::DBusThreadManager::GetSetterForTesting();
1979 chromeos::MockCryptohomeClient* cryptohome_client =
1980 new chromeos::MockCryptohomeClient;
1981 dbus_setter->SetCryptohomeClient(
1982 scoped_ptr<chromeos::CryptohomeClient>(cryptohome_client));
1984 // Expect exactly one call. No calls means no attempt to delete keys and more
1985 // than one call means a significant performance problem.
1986 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _))
1987 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall)));
1989 BlockUntilBrowsingDataRemoved(
1990 BrowsingDataRemover::EVERYTHING,
1991 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false);
1993 chromeos::DBusThreadManager::Shutdown();
1995 #endif
1997 TEST_F(BrowsingDataRemoverTest, DomainReliability_Null) {
1998 const ClearDomainReliabilityTester& tester =
1999 clear_domain_reliability_tester();
2001 EXPECT_EQ(0u, tester.clear_count());
2004 TEST_F(BrowsingDataRemoverTest, DomainReliability_Beacons) {
2005 const ClearDomainReliabilityTester& tester =
2006 clear_domain_reliability_tester();
2008 BlockUntilBrowsingDataRemoved(
2009 BrowsingDataRemover::EVERYTHING,
2010 BrowsingDataRemover::REMOVE_HISTORY, false);
2011 EXPECT_EQ(1u, tester.clear_count());
2012 EXPECT_EQ(CLEAR_BEACONS, tester.last_clear_mode());
2015 TEST_F(BrowsingDataRemoverTest, DomainReliability_Contexts) {
2016 const ClearDomainReliabilityTester& tester =
2017 clear_domain_reliability_tester();
2019 BlockUntilBrowsingDataRemoved(
2020 BrowsingDataRemover::EVERYTHING,
2021 BrowsingDataRemover::REMOVE_COOKIES, false);
2022 EXPECT_EQ(1u, tester.clear_count());
2023 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2026 TEST_F(BrowsingDataRemoverTest, DomainReliability_ContextsWin) {
2027 const ClearDomainReliabilityTester& tester =
2028 clear_domain_reliability_tester();
2030 BlockUntilBrowsingDataRemoved(
2031 BrowsingDataRemover::EVERYTHING,
2032 BrowsingDataRemover::REMOVE_HISTORY |
2033 BrowsingDataRemover::REMOVE_COOKIES, false);
2034 EXPECT_EQ(1u, tester.clear_count());
2035 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2038 TEST_F(BrowsingDataRemoverTest, DomainReliability_ProtectedOrigins) {
2039 const ClearDomainReliabilityTester& tester =
2040 clear_domain_reliability_tester();
2042 BlockUntilBrowsingDataRemoved(
2043 BrowsingDataRemover::EVERYTHING,
2044 BrowsingDataRemover::REMOVE_COOKIES, true);
2045 EXPECT_EQ(1u, tester.clear_count());
2046 EXPECT_EQ(CLEAR_CONTEXTS, tester.last_clear_mode());
2049 // TODO(ttuttle): This isn't actually testing the no-monitor case, since
2050 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed
2051 // for some unrelated test cases. This should be fixed so it tests the no-
2052 // monitor case again.
2053 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) {
2054 BlockUntilBrowsingDataRemoved(
2055 BrowsingDataRemover::EVERYTHING,
2056 BrowsingDataRemover::REMOVE_HISTORY |
2057 BrowsingDataRemover::REMOVE_COOKIES, false);
2060 TEST_F(BrowsingDataRemoverTest, RemoveSameOriginDownloads) {
2061 RemoveDownloadsTester tester(GetProfile());
2062 const url::Origin expectedOrigin(kOrigin1);
2064 EXPECT_CALL(*tester.download_manager(),
2065 RemoveDownloadsByOriginAndTime(SameOrigin(expectedOrigin), _, _));
2067 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING,
2068 BrowsingDataRemover::REMOVE_DOWNLOADS, kOrigin1);