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. 4 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" 6 7 #include <set> 8 #include <vector> 9 10 #include "base/bind.h" 11 #include "base/bind_helpers.h" 12 #include "base/file_util.h" 13 #include "base/files/file_path.h" 14 #include "base/guid.h" 15 #include "base/message_loop/message_loop.h" 16 #include "base/platform_file.h" 17 #include "base/prefs/testing_pref_service.h" 18 #include "base/strings/utf_string_conversions.h" 19 #include "chrome/browser/autofill/personal_data_manager_factory.h" 20 #include "chrome/browser/browsing_data/browsing_data_helper.h" 21 #include "chrome/browser/chrome_notification_types.h" 22 #if defined(OS_CHROMEOS) 23 #include "chrome/browser/chromeos/login/mock_user_manager.h" 24 #include "chrome/browser/chromeos/login/user_manager.h" 25 #include "chrome/browser/chromeos/settings/cros_settings.h" 26 #include "chrome/browser/chromeos/settings/device_settings_service.h" 27 #endif 28 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" 29 #include "chrome/browser/history/history_service.h" 30 #include "chrome/browser/history/history_service_factory.h" 31 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 32 #include "chrome/common/pref_names.h" 33 #include "chrome/test/base/testing_browser_process.h" 34 #include "chrome/test/base/testing_profile.h" 35 #if defined(OS_CHROMEOS) 36 #include "chromeos/dbus/dbus_thread_manager.h" 37 #include "chromeos/dbus/fake_dbus_thread_manager.h" 38 #include "chromeos/dbus/mock_cryptohome_client.h" 39 #endif 40 #include "components/autofill/core/browser/autofill_profile.h" 41 #include "components/autofill/core/browser/autofill_test_utils.h" 42 #include "components/autofill/core/browser/credit_card.h" 43 #include "components/autofill/core/browser/personal_data_manager.h" 44 #include "components/autofill/core/browser/personal_data_manager_observer.h" 45 #include "content/public/browser/dom_storage_context.h" 46 #include "content/public/browser/local_storage_usage_info.h" 47 #include "content/public/browser/notification_service.h" 48 #include "content/public/browser/storage_partition.h" 49 #include "content/public/test/test_browser_thread.h" 50 #include "content/public/test/test_browser_thread_bundle.h" 51 #include "net/cookies/cookie_monster.h" 52 #include "net/ssl/server_bound_cert_service.h" 53 #include "net/ssl/server_bound_cert_store.h" 54 #include "net/ssl/ssl_client_cert_type.h" 55 #include "net/url_request/url_request_context.h" 56 #include "net/url_request/url_request_context_getter.h" 57 #include "testing/gmock/include/gmock/gmock.h" 58 #include "testing/gtest/include/gtest/gtest.h" 59 60 using content::BrowserThread; 61 using content::StoragePartition; 62 using testing::_; 63 using testing::Invoke; 64 using testing::WithArgs; 65 66 namespace { 67 68 const char kTestOrigin1[] = "http://host1:1/"; 69 const char kTestOrigin2[] = "http://host2:1/"; 70 const char kTestOrigin3[] = "http://host3:1/"; 71 const char kTestOriginExt[] = "chrome-extension://abcdefghijklmnopqrstuvwxyz/"; 72 const char kTestOriginDevTools[] = "chrome-devtools://abcdefghijklmnopqrstuvw/"; 73 74 // For Autofill. 75 const char kChromeOrigin[] = "Chrome settings"; 76 const char kWebOrigin[] = "https://www.example.com/"; 77 78 const GURL kOrigin1(kTestOrigin1); 79 const GURL kOrigin2(kTestOrigin2); 80 const GURL kOrigin3(kTestOrigin3); 81 const GURL kOriginExt(kTestOriginExt); 82 const GURL kOriginDevTools(kTestOriginDevTools); 83 84 const base::FilePath::CharType kDomStorageOrigin1[] = 85 FILE_PATH_LITERAL("http_host1_1.localstorage"); 86 87 const base::FilePath::CharType kDomStorageOrigin2[] = 88 FILE_PATH_LITERAL("http_host2_1.localstorage"); 89 90 const base::FilePath::CharType kDomStorageOrigin3[] = 91 FILE_PATH_LITERAL("http_host3_1.localstorage"); 92 93 const base::FilePath::CharType kDomStorageExt[] = FILE_PATH_LITERAL( 94 "chrome-extension_abcdefghijklmnopqrstuvwxyz_0.localstorage"); 95 96 class AwaitCompletionHelper : public BrowsingDataRemover::Observer { 97 public: 98 AwaitCompletionHelper() : start_(false), already_quit_(false) {} 99 virtual ~AwaitCompletionHelper() {} 100 101 void BlockUntilNotified() { 102 if (!already_quit_) { 103 DCHECK(!start_); 104 start_ = true; 105 base::MessageLoop::current()->Run(); 106 } else { 107 DCHECK(!start_); 108 already_quit_ = false; 109 } 110 } 111 112 void Notify() { 113 if (start_) { 114 DCHECK(!already_quit_); 115 base::MessageLoop::current()->Quit(); 116 start_ = false; 117 } else { 118 DCHECK(!already_quit_); 119 already_quit_ = true; 120 } 121 } 122 123 protected: 124 // BrowsingDataRemover::Observer implementation. 125 virtual void OnBrowsingDataRemoverDone() OVERRIDE { 126 Notify(); 127 } 128 129 private: 130 // Helps prevent from running message_loop, if the callback invoked 131 // immediately. 132 bool start_; 133 bool already_quit_; 134 135 DISALLOW_COPY_AND_ASSIGN(AwaitCompletionHelper); 136 }; 137 138 #if defined(OS_CHROMEOS) 139 void FakeDBusCall(const chromeos::BoolDBusMethodCallback& callback) { 140 base::MessageLoop::current()->PostTask( 141 FROM_HERE, 142 base::Bind(callback, chromeos::DBUS_METHOD_CALL_SUCCESS, true)); 143 } 144 #endif 145 146 struct StoragePartitionRemovalData { 147 uint32 remove_mask; 148 uint32 quota_storage_remove_mask; 149 GURL remove_origin; 150 base::Time remove_begin; 151 base::Time remove_end; 152 StoragePartition::OriginMatcherFunction origin_matcher; 153 154 StoragePartitionRemovalData() : remove_mask(0), 155 quota_storage_remove_mask(0) {} 156 }; 157 158 class TestStoragePartition : public StoragePartition { 159 public: 160 TestStoragePartition() {} 161 virtual ~TestStoragePartition() {} 162 163 // content::StoragePartition implementation. 164 virtual base::FilePath GetPath() OVERRIDE { return base::FilePath(); } 165 virtual net::URLRequestContextGetter* GetURLRequestContext() OVERRIDE { 166 return NULL; 167 } 168 virtual net::URLRequestContextGetter* GetMediaURLRequestContext() OVERRIDE { 169 return NULL; 170 } 171 virtual quota::QuotaManager* GetQuotaManager() OVERRIDE { 172 return NULL; 173 } 174 virtual appcache::AppCacheService* GetAppCacheService() OVERRIDE { 175 return NULL; 176 } 177 virtual fileapi::FileSystemContext* GetFileSystemContext() OVERRIDE { 178 return NULL; 179 } 180 virtual webkit_database::DatabaseTracker* GetDatabaseTracker() OVERRIDE { 181 return NULL; 182 } 183 virtual content::DOMStorageContext* GetDOMStorageContext() OVERRIDE { 184 return NULL; 185 } 186 virtual content::IndexedDBContext* GetIndexedDBContext() OVERRIDE { 187 return NULL; 188 } 189 190 virtual void ClearDataForOrigin( 191 uint32 remove_mask, 192 uint32 quota_storage_remove_mask, 193 const GURL& storage_origin, 194 net::URLRequestContextGetter* rq_context) OVERRIDE {} 195 196 virtual void ClearData(uint32 remove_mask, 197 uint32 quota_storage_remove_mask, 198 const GURL* storage_origin, 199 const OriginMatcherFunction& origin_matcher, 200 const base::Time begin, 201 const base::Time end, 202 const base::Closure& callback) OVERRIDE { 203 // Store stuff to verify parameters' correctness later. 204 storage_partition_removal_data_.remove_mask = remove_mask; 205 storage_partition_removal_data_.quota_storage_remove_mask = 206 quota_storage_remove_mask; 207 storage_partition_removal_data_.remove_origin = 208 storage_origin ? *storage_origin : GURL(); 209 storage_partition_removal_data_.remove_begin = begin; 210 storage_partition_removal_data_.remove_end = end; 211 storage_partition_removal_data_.origin_matcher = origin_matcher; 212 213 BrowserThread::PostTask( 214 BrowserThread::UI, 215 FROM_HERE, 216 base::Bind(&TestStoragePartition::AsyncRunCallback, 217 base::Unretained(this), callback)); 218 } 219 220 StoragePartitionRemovalData GetStoragePartitionRemovalData() { 221 return storage_partition_removal_data_; 222 } 223 private: 224 void AsyncRunCallback(const base::Closure& callback) { 225 callback.Run(); 226 } 227 228 StoragePartitionRemovalData storage_partition_removal_data_; 229 230 DISALLOW_COPY_AND_ASSIGN(TestStoragePartition); 231 }; 232 233 } // namespace 234 235 // Testers ------------------------------------------------------------------- 236 237 class RemoveCookieTester { 238 public: 239 RemoveCookieTester() : get_cookie_success_(false), monster_(NULL) { 240 } 241 242 // Returns true, if the given cookie exists in the cookie store. 243 bool ContainsCookie() { 244 get_cookie_success_ = false; 245 monster_->GetCookiesWithOptionsAsync( 246 kOrigin1, net::CookieOptions(), 247 base::Bind(&RemoveCookieTester::GetCookieCallback, 248 base::Unretained(this))); 249 await_completion_.BlockUntilNotified(); 250 return get_cookie_success_; 251 } 252 253 void AddCookie() { 254 monster_->SetCookieWithOptionsAsync( 255 kOrigin1, "A=1", net::CookieOptions(), 256 base::Bind(&RemoveCookieTester::SetCookieCallback, 257 base::Unretained(this))); 258 await_completion_.BlockUntilNotified(); 259 } 260 261 protected: 262 void SetMonster(net::CookieStore* monster) { 263 monster_ = monster; 264 } 265 266 private: 267 void GetCookieCallback(const std::string& cookies) { 268 if (cookies == "A=1") { 269 get_cookie_success_ = true; 270 } else { 271 EXPECT_EQ("", cookies); 272 get_cookie_success_ = false; 273 } 274 await_completion_.Notify(); 275 } 276 277 void SetCookieCallback(bool result) { 278 ASSERT_TRUE(result); 279 await_completion_.Notify(); 280 } 281 282 bool get_cookie_success_; 283 AwaitCompletionHelper await_completion_; 284 net::CookieStore* monster_; 285 286 DISALLOW_COPY_AND_ASSIGN(RemoveCookieTester); 287 }; 288 289 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) 290 class RemoveSafeBrowsingCookieTester : public RemoveCookieTester { 291 public: 292 RemoveSafeBrowsingCookieTester() 293 : browser_process_(TestingBrowserProcess::GetGlobal()) { 294 scoped_refptr<SafeBrowsingService> sb_service = 295 SafeBrowsingService::CreateSafeBrowsingService(); 296 browser_process_->SetSafeBrowsingService(sb_service.get()); 297 sb_service->Initialize(); 298 base::MessageLoop::current()->RunUntilIdle(); 299 300 // Create a cookiemonster that does not have persistant storage, and replace 301 // the SafeBrowsingService created one with it. 302 net::CookieStore* monster = new net::CookieMonster(NULL, NULL); 303 sb_service->url_request_context()->GetURLRequestContext()-> 304 set_cookie_store(monster); 305 SetMonster(monster); 306 } 307 308 virtual ~RemoveSafeBrowsingCookieTester() { 309 browser_process_->safe_browsing_service()->ShutDown(); 310 base::MessageLoop::current()->RunUntilIdle(); 311 browser_process_->SetSafeBrowsingService(NULL); 312 } 313 314 private: 315 TestingBrowserProcess* browser_process_; 316 317 DISALLOW_COPY_AND_ASSIGN(RemoveSafeBrowsingCookieTester); 318 }; 319 #endif 320 321 class RemoveServerBoundCertTester : public net::SSLConfigService::Observer { 322 public: 323 explicit RemoveServerBoundCertTester(TestingProfile* profile) 324 : ssl_config_changed_count_(0) { 325 server_bound_cert_service_ = profile->GetRequestContext()-> 326 GetURLRequestContext()->server_bound_cert_service(); 327 ssl_config_service_ = profile->GetSSLConfigService(); 328 ssl_config_service_->AddObserver(this); 329 } 330 331 virtual ~RemoveServerBoundCertTester() { 332 ssl_config_service_->RemoveObserver(this); 333 } 334 335 int ServerBoundCertCount() { 336 return server_bound_cert_service_->cert_count(); 337 } 338 339 // Add a server bound cert for |server| with specific creation and expiry 340 // times. The cert and key data will be filled with dummy values. 341 void AddServerBoundCertWithTimes(const std::string& server_identifier, 342 base::Time creation_time, 343 base::Time expiration_time) { 344 GetCertStore()->SetServerBoundCert(server_identifier, 345 creation_time, 346 expiration_time, 347 "a", 348 "b"); 349 } 350 351 // Add a server bound cert for |server|, with the current time as the 352 // creation time. The cert and key data will be filled with dummy values. 353 void AddServerBoundCert(const std::string& server_identifier) { 354 base::Time now = base::Time::Now(); 355 AddServerBoundCertWithTimes(server_identifier, 356 now, 357 now + base::TimeDelta::FromDays(1)); 358 } 359 360 void GetCertList(net::ServerBoundCertStore::ServerBoundCertList* certs) { 361 GetCertStore()->GetAllServerBoundCerts( 362 base::Bind(&RemoveServerBoundCertTester::GetAllCertsCallback, certs)); 363 } 364 365 net::ServerBoundCertStore* GetCertStore() { 366 return server_bound_cert_service_->GetCertStore(); 367 } 368 369 int ssl_config_changed_count() const { 370 return ssl_config_changed_count_; 371 } 372 373 // net::SSLConfigService::Observer implementation: 374 virtual void OnSSLConfigChanged() OVERRIDE { 375 ssl_config_changed_count_++; 376 } 377 378 private: 379 static void GetAllCertsCallback( 380 net::ServerBoundCertStore::ServerBoundCertList* dest, 381 const net::ServerBoundCertStore::ServerBoundCertList& result) { 382 *dest = result; 383 } 384 385 net::ServerBoundCertService* server_bound_cert_service_; 386 scoped_refptr<net::SSLConfigService> ssl_config_service_; 387 int ssl_config_changed_count_; 388 389 DISALLOW_COPY_AND_ASSIGN(RemoveServerBoundCertTester); 390 }; 391 392 class RemoveHistoryTester { 393 public: 394 RemoveHistoryTester() : query_url_success_(false), history_service_(NULL) {} 395 396 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT { 397 if (!profile->CreateHistoryService(true, false)) 398 return false; 399 history_service_ = HistoryServiceFactory::GetForProfile( 400 profile, Profile::EXPLICIT_ACCESS); 401 return true; 402 } 403 404 // Returns true, if the given URL exists in the history service. 405 bool HistoryContainsURL(const GURL& url) { 406 history_service_->QueryURL( 407 url, 408 true, 409 &consumer_, 410 base::Bind(&RemoveHistoryTester::SaveResultAndQuit, 411 base::Unretained(this))); 412 await_completion_.BlockUntilNotified(); 413 return query_url_success_; 414 } 415 416 void AddHistory(const GURL& url, base::Time time) { 417 history_service_->AddPage(url, time, NULL, 0, GURL(), 418 history::RedirectList(), content::PAGE_TRANSITION_LINK, 419 history::SOURCE_BROWSED, false); 420 } 421 422 private: 423 // Callback for HistoryService::QueryURL. 424 void SaveResultAndQuit(HistoryService::Handle, 425 bool success, 426 const history::URLRow*, 427 history::VisitVector*) { 428 query_url_success_ = success; 429 await_completion_.Notify(); 430 } 431 432 // For History requests. 433 CancelableRequestConsumer consumer_; 434 bool query_url_success_; 435 436 // TestingProfile owns the history service; we shouldn't delete it. 437 HistoryService* history_service_; 438 439 AwaitCompletionHelper await_completion_; 440 441 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester); 442 }; 443 444 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver { 445 public: 446 explicit RemoveAutofillTester(TestingProfile* profile) 447 : personal_data_manager_( 448 autofill::PersonalDataManagerFactory::GetForProfile(profile)) { 449 autofill::test::DisableSystemServices(profile); 450 personal_data_manager_->AddObserver(this); 451 } 452 453 virtual ~RemoveAutofillTester() { 454 personal_data_manager_->RemoveObserver(this); 455 } 456 457 // Returns true if there are autofill profiles. 458 bool HasProfile() { 459 return !personal_data_manager_->GetProfiles().empty() && 460 !personal_data_manager_->GetCreditCards().empty(); 461 } 462 463 bool HasOrigin(const std::string& origin) { 464 const std::vector<autofill::AutofillProfile*>& profiles = 465 personal_data_manager_->GetProfiles(); 466 for (std::vector<autofill::AutofillProfile*>::const_iterator it = 467 profiles.begin(); 468 it != profiles.end(); ++it) { 469 if ((*it)->origin() == origin) 470 return true; 471 } 472 473 const std::vector<autofill::CreditCard*>& credit_cards = 474 personal_data_manager_->GetCreditCards(); 475 for (std::vector<autofill::CreditCard*>::const_iterator it = 476 credit_cards.begin(); 477 it != credit_cards.end(); ++it) { 478 if ((*it)->origin() == origin) 479 return true; 480 } 481 482 return false; 483 } 484 485 // Add two profiles and two credit cards to the database. In each pair, one 486 // entry has a web origin and the other has a Chrome origin. 487 void AddProfilesAndCards() { 488 std::vector<autofill::AutofillProfile> profiles; 489 autofill::AutofillProfile profile; 490 profile.set_guid(base::GenerateGUID()); 491 profile.set_origin(kWebOrigin); 492 profile.SetRawInfo(autofill::NAME_FIRST, ASCIIToUTF16("Bob")); 493 profile.SetRawInfo(autofill::NAME_LAST, ASCIIToUTF16("Smith")); 494 profile.SetRawInfo(autofill::ADDRESS_HOME_ZIP, ASCIIToUTF16("94043")); 495 profile.SetRawInfo(autofill::EMAIL_ADDRESS, 496 ASCIIToUTF16("sue (at) example.com")); 497 profile.SetRawInfo(autofill::COMPANY_NAME, ASCIIToUTF16("Company X")); 498 profiles.push_back(profile); 499 500 profile.set_guid(base::GenerateGUID()); 501 profile.set_origin(kChromeOrigin); 502 profiles.push_back(profile); 503 504 personal_data_manager_->SetProfiles(&profiles); 505 base::MessageLoop::current()->Run(); 506 507 std::vector<autofill::CreditCard> cards; 508 autofill::CreditCard card; 509 card.set_guid(base::GenerateGUID()); 510 card.set_origin(kWebOrigin); 511 card.SetRawInfo(autofill::CREDIT_CARD_NUMBER, 512 ASCIIToUTF16("1234-5678-9012-3456")); 513 cards.push_back(card); 514 515 card.set_guid(base::GenerateGUID()); 516 card.set_origin(kChromeOrigin); 517 cards.push_back(card); 518 519 personal_data_manager_->SetCreditCards(&cards); 520 base::MessageLoop::current()->Run(); 521 } 522 523 private: 524 virtual void OnPersonalDataChanged() OVERRIDE { 525 base::MessageLoop::current()->Quit(); 526 } 527 528 autofill::PersonalDataManager* personal_data_manager_; 529 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester); 530 }; 531 532 class RemoveLocalStorageTester { 533 public: 534 explicit RemoveLocalStorageTester(TestingProfile* profile) 535 : profile_(profile), dom_storage_context_(NULL) { 536 dom_storage_context_ = 537 content::BrowserContext::GetDefaultStoragePartition(profile)-> 538 GetDOMStorageContext(); 539 } 540 541 // Returns true, if the given origin URL exists. 542 bool DOMStorageExistsForOrigin(const GURL& origin) { 543 GetLocalStorageUsage(); 544 await_completion_.BlockUntilNotified(); 545 for (size_t i = 0; i < infos_.size(); ++i) { 546 if (origin == infos_[i].origin) 547 return true; 548 } 549 return false; 550 } 551 552 void AddDOMStorageTestData() { 553 // Note: This test depends on details of how the dom_storage library 554 // stores data in the host file system. 555 base::FilePath storage_path = 556 profile_->GetPath().AppendASCII("Local Storage"); 557 base::CreateDirectory(storage_path); 558 559 // Write some files. 560 file_util::WriteFile(storage_path.Append(kDomStorageOrigin1), NULL, 0); 561 file_util::WriteFile(storage_path.Append(kDomStorageOrigin2), NULL, 0); 562 file_util::WriteFile(storage_path.Append(kDomStorageOrigin3), NULL, 0); 563 file_util::WriteFile(storage_path.Append(kDomStorageExt), NULL, 0); 564 565 // Tweak their dates. 566 base::Time now = base::Time::Now(); 567 base::TouchFile(storage_path.Append(kDomStorageOrigin1), now, now); 568 569 base::Time one_day_ago = now - base::TimeDelta::FromDays(1); 570 base::TouchFile(storage_path.Append(kDomStorageOrigin2), 571 one_day_ago, one_day_ago); 572 573 base::Time sixty_days_ago = now - base::TimeDelta::FromDays(60); 574 base::TouchFile(storage_path.Append(kDomStorageOrigin3), 575 sixty_days_ago, sixty_days_ago); 576 577 base::TouchFile(storage_path.Append(kDomStorageExt), now, now); 578 } 579 580 private: 581 void GetLocalStorageUsage() { 582 dom_storage_context_->GetLocalStorageUsage( 583 base::Bind(&RemoveLocalStorageTester::OnGotLocalStorageUsage, 584 base::Unretained(this))); 585 } 586 void OnGotLocalStorageUsage( 587 const std::vector<content::LocalStorageUsageInfo>& infos) { 588 infos_ = infos; 589 await_completion_.Notify(); 590 } 591 592 // We don't own these pointers. 593 TestingProfile* profile_; 594 content::DOMStorageContext* dom_storage_context_; 595 596 std::vector<content::LocalStorageUsageInfo> infos_; 597 598 AwaitCompletionHelper await_completion_; 599 600 DISALLOW_COPY_AND_ASSIGN(RemoveLocalStorageTester); 601 }; 602 603 // Test Class ---------------------------------------------------------------- 604 605 class BrowsingDataRemoverTest : public testing::Test, 606 public content::NotificationObserver { 607 public: 608 BrowsingDataRemoverTest() 609 : profile_(new TestingProfile()) { 610 registrar_.Add(this, chrome::NOTIFICATION_BROWSING_DATA_REMOVED, 611 content::Source<Profile>(profile_.get())); 612 } 613 614 virtual ~BrowsingDataRemoverTest() { 615 } 616 617 virtual void TearDown() { 618 // TestingProfile contains a DOMStorageContext. BrowserContext's destructor 619 // posts a message to the WEBKIT thread to delete some of its member 620 // variables. We need to ensure that the profile is destroyed, and that 621 // the message loop is cleared out, before destroying the threads and loop. 622 // Otherwise we leak memory. 623 profile_.reset(); 624 base::MessageLoop::current()->RunUntilIdle(); 625 } 626 627 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, 628 int remove_mask, 629 bool include_protected_origins) { 630 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod( 631 profile_.get(), period); 632 633 TestStoragePartition storage_partition; 634 remover->OverrideStoragePartitionForTesting(&storage_partition); 635 636 AwaitCompletionHelper await_completion; 637 remover->AddObserver(&await_completion); 638 639 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); 640 641 // BrowsingDataRemover deletes itself when it completes. 642 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB; 643 if (include_protected_origins) 644 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB; 645 remover->Remove(remove_mask, origin_set_mask); 646 await_completion.BlockUntilNotified(); 647 648 // Save so we can verify later. 649 storage_partition_removal_data_ = 650 storage_partition.GetStoragePartitionRemovalData(); 651 } 652 653 void BlockUntilOriginDataRemoved(BrowsingDataRemover::TimePeriod period, 654 int remove_mask, 655 const GURL& remove_origin) { 656 BrowsingDataRemover* remover = BrowsingDataRemover::CreateForPeriod( 657 profile_.get(), period); 658 TestStoragePartition storage_partition; 659 remover->OverrideStoragePartitionForTesting(&storage_partition); 660 661 AwaitCompletionHelper await_completion; 662 remover->AddObserver(&await_completion); 663 664 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); 665 666 // BrowsingDataRemover deletes itself when it completes. 667 remover->RemoveImpl(remove_mask, remove_origin, 668 BrowsingDataHelper::UNPROTECTED_WEB); 669 await_completion.BlockUntilNotified(); 670 671 // Save so we can verify later. 672 storage_partition_removal_data_ = 673 storage_partition.GetStoragePartitionRemovalData(); 674 } 675 676 TestingProfile* GetProfile() { 677 return profile_.get(); 678 } 679 680 base::Time GetBeginTime() { 681 return called_with_details_->removal_begin; 682 } 683 684 int GetRemovalMask() { 685 return called_with_details_->removal_mask; 686 } 687 688 int GetOriginSetMask() { 689 return called_with_details_->origin_set_mask; 690 } 691 692 StoragePartitionRemovalData GetStoragePartitionRemovalData() { 693 return storage_partition_removal_data_; 694 } 695 696 // content::NotificationObserver implementation. 697 virtual void Observe(int type, 698 const content::NotificationSource& source, 699 const content::NotificationDetails& details) OVERRIDE { 700 DCHECK_EQ(type, chrome::NOTIFICATION_BROWSING_DATA_REMOVED); 701 702 // We're not taking ownership of the details object, but storing a copy of 703 // it locally. 704 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails( 705 *content::Details<BrowsingDataRemover::NotificationDetails>( 706 details).ptr())); 707 708 registrar_.RemoveAll(); 709 } 710 711 private: 712 scoped_ptr<BrowsingDataRemover::NotificationDetails> called_with_details_; 713 content::NotificationRegistrar registrar_; 714 715 content::TestBrowserThreadBundle thread_bundle_; 716 scoped_ptr<TestingProfile> profile_; 717 718 StoragePartitionRemovalData storage_partition_removal_data_; 719 720 DISALLOW_COPY_AND_ASSIGN(BrowsingDataRemoverTest); 721 }; 722 723 // Tests --------------------------------------------------------------------- 724 725 TEST_F(BrowsingDataRemoverTest, RemoveCookieForever) { 726 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 727 BrowsingDataRemover::REMOVE_COOKIES, 728 false); 729 730 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 731 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 732 733 // Verify that storage partition was instructed to remove the cookies. 734 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 735 EXPECT_EQ(removal_data.remove_mask, 736 static_cast<uint32>( 737 StoragePartition::REMOVE_DATA_MASK_COOKIES)); 738 EXPECT_EQ(removal_data.quota_storage_remove_mask, 739 static_cast<uint32>( 740 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 741 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 742 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 743 } 744 745 TEST_F(BrowsingDataRemoverTest, RemoveCookieLastHour) { 746 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 747 BrowsingDataRemover::REMOVE_COOKIES, 748 false); 749 750 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 751 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 752 753 // Verify that storage partition was instructed to remove the cookies. 754 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 755 EXPECT_EQ(removal_data.remove_mask, 756 static_cast<uint32>( 757 StoragePartition::REMOVE_DATA_MASK_COOKIES)); 758 // Removing with time period other than EVERYTHING should not clear 759 // persistent storage data. 760 EXPECT_EQ(removal_data.quota_storage_remove_mask, 761 static_cast<uint32>( 762 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL & 763 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT)); 764 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 765 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 766 } 767 768 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) 769 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieForever) { 770 RemoveSafeBrowsingCookieTester tester; 771 772 tester.AddCookie(); 773 ASSERT_TRUE(tester.ContainsCookie()); 774 775 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 776 BrowsingDataRemover::REMOVE_COOKIES, false); 777 778 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 779 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 780 EXPECT_FALSE(tester.ContainsCookie()); 781 } 782 783 TEST_F(BrowsingDataRemoverTest, RemoveSafeBrowsingCookieLastHour) { 784 RemoveSafeBrowsingCookieTester tester; 785 786 tester.AddCookie(); 787 ASSERT_TRUE(tester.ContainsCookie()); 788 789 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 790 BrowsingDataRemover::REMOVE_COOKIES, false); 791 792 EXPECT_EQ(BrowsingDataRemover::REMOVE_COOKIES, GetRemovalMask()); 793 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 794 // Removing with time period other than EVERYTHING should not clear safe 795 // browsing cookies. 796 EXPECT_TRUE(tester.ContainsCookie()); 797 } 798 #endif 799 800 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertForever) { 801 RemoveServerBoundCertTester tester(GetProfile()); 802 803 tester.AddServerBoundCert(kTestOrigin1); 804 EXPECT_EQ(0, tester.ssl_config_changed_count()); 805 EXPECT_EQ(1, tester.ServerBoundCertCount()); 806 807 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 808 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false); 809 810 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); 811 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 812 EXPECT_EQ(1, tester.ssl_config_changed_count()); 813 EXPECT_EQ(0, tester.ServerBoundCertCount()); 814 } 815 816 TEST_F(BrowsingDataRemoverTest, RemoveServerBoundCertLastHour) { 817 RemoveServerBoundCertTester tester(GetProfile()); 818 819 base::Time now = base::Time::Now(); 820 tester.AddServerBoundCert(kTestOrigin1); 821 tester.AddServerBoundCertWithTimes(kTestOrigin2, 822 now - base::TimeDelta::FromHours(2), 823 now); 824 EXPECT_EQ(0, tester.ssl_config_changed_count()); 825 EXPECT_EQ(2, tester.ServerBoundCertCount()); 826 827 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 828 BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, false); 829 830 EXPECT_EQ(BrowsingDataRemover::REMOVE_SERVER_BOUND_CERTS, GetRemovalMask()); 831 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 832 EXPECT_EQ(1, tester.ssl_config_changed_count()); 833 ASSERT_EQ(1, tester.ServerBoundCertCount()); 834 net::ServerBoundCertStore::ServerBoundCertList certs; 835 tester.GetCertList(&certs); 836 ASSERT_EQ(1U, certs.size()); 837 EXPECT_EQ(kTestOrigin2, certs.front().server_identifier()); 838 } 839 840 TEST_F(BrowsingDataRemoverTest, RemoveUnprotectedLocalStorageForever) { 841 // Protect kOrigin1. 842 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 843 new MockExtensionSpecialStoragePolicy; 844 mock_policy->AddProtected(kOrigin1.GetOrigin()); 845 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 846 847 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 848 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, 849 false); 850 851 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); 852 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 853 854 // Verify that storage partition was instructed to remove the data correctly. 855 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 856 EXPECT_EQ(removal_data.remove_mask, 857 static_cast<uint32>( 858 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE)); 859 EXPECT_EQ(removal_data.quota_storage_remove_mask, 860 static_cast<uint32>( 861 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 862 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 863 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 864 865 // Check origin matcher. 866 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy)); 867 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy)); 868 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy)); 869 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy)); 870 } 871 872 TEST_F(BrowsingDataRemoverTest, RemoveProtectedLocalStorageForever) { 873 // Protect kOrigin1. 874 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 875 new MockExtensionSpecialStoragePolicy; 876 mock_policy->AddProtected(kOrigin1.GetOrigin()); 877 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 878 879 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 880 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, 881 true); 882 883 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); 884 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB | 885 BrowsingDataHelper::PROTECTED_WEB, GetOriginSetMask()); 886 887 // Verify that storage partition was instructed to remove the data correctly. 888 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 889 EXPECT_EQ(removal_data.remove_mask, 890 static_cast<uint32>( 891 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE)); 892 EXPECT_EQ(removal_data.quota_storage_remove_mask, 893 static_cast<uint32>( 894 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 895 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 896 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 897 898 // Check origin matcher all http origin will match since we specified 899 // both protected and unprotected. 900 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy)); 901 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy)); 902 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy)); 903 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy)); 904 } 905 906 TEST_F(BrowsingDataRemoverTest, RemoveLocalStorageForLastWeek) { 907 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 908 new MockExtensionSpecialStoragePolicy; 909 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 910 911 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK, 912 BrowsingDataRemover::REMOVE_LOCAL_STORAGE, 913 false); 914 915 EXPECT_EQ(BrowsingDataRemover::REMOVE_LOCAL_STORAGE, GetRemovalMask()); 916 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 917 918 // Verify that storage partition was instructed to remove the data correctly. 919 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 920 EXPECT_EQ(removal_data.remove_mask, 921 static_cast<uint32>( 922 StoragePartition::REMOVE_DATA_MASK_LOCAL_STORAGE)); 923 // Persistent storage won't be deleted. 924 EXPECT_EQ(removal_data.quota_storage_remove_mask, 925 static_cast<uint32>( 926 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL & 927 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT)); 928 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 929 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 930 931 // Check origin matcher. 932 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy)); 933 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy)); 934 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy)); 935 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy)); 936 } 937 938 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForever) { 939 RemoveHistoryTester tester; 940 ASSERT_TRUE(tester.Init(GetProfile())); 941 942 tester.AddHistory(kOrigin1, base::Time::Now()); 943 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 944 945 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 946 BrowsingDataRemover::REMOVE_HISTORY, false); 947 948 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 949 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 950 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); 951 } 952 953 TEST_F(BrowsingDataRemoverTest, RemoveHistoryForLastHour) { 954 RemoveHistoryTester tester; 955 ASSERT_TRUE(tester.Init(GetProfile())); 956 957 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); 958 959 tester.AddHistory(kOrigin1, base::Time::Now()); 960 tester.AddHistory(kOrigin2, two_hours_ago); 961 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 962 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); 963 964 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 965 BrowsingDataRemover::REMOVE_HISTORY, false); 966 967 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 968 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 969 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin1)); 970 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); 971 } 972 973 // This should crash (DCHECK) in Debug, but death tests don't work properly 974 // here. 975 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 976 TEST_F(BrowsingDataRemoverTest, RemoveHistoryProhibited) { 977 RemoveHistoryTester tester; 978 ASSERT_TRUE(tester.Init(GetProfile())); 979 PrefService* prefs = GetProfile()->GetPrefs(); 980 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); 981 982 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); 983 984 tester.AddHistory(kOrigin1, base::Time::Now()); 985 tester.AddHistory(kOrigin2, two_hours_ago); 986 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 987 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); 988 989 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 990 BrowsingDataRemover::REMOVE_HISTORY, false); 991 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 992 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 993 994 // Nothing should have been deleted. 995 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); 996 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); 997 } 998 #endif 999 1000 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypes) { 1001 // Add some history. 1002 RemoveHistoryTester history_tester; 1003 ASSERT_TRUE(history_tester.Init(GetProfile())); 1004 history_tester.AddHistory(kOrigin1, base::Time::Now()); 1005 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); 1006 1007 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY | 1008 BrowsingDataRemover::REMOVE_COOKIES; 1009 1010 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 1011 removal_mask, false); 1012 1013 EXPECT_EQ(removal_mask, GetRemovalMask()); 1014 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1015 EXPECT_FALSE(history_tester.HistoryContainsURL(kOrigin1)); 1016 1017 // The cookie would be deleted throught the StorageParition, check if the 1018 // partition was requested to remove cookie. 1019 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1020 EXPECT_EQ(removal_data.remove_mask, 1021 static_cast<uint32>( 1022 StoragePartition::REMOVE_DATA_MASK_COOKIES)); 1023 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1024 static_cast<uint32>( 1025 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1026 } 1027 1028 // This should crash (DCHECK) in Debug, but death tests don't work properly 1029 // here. 1030 #if defined(NDEBUG) && !defined(DCHECK_ALWAYS_ON) 1031 TEST_F(BrowsingDataRemoverTest, RemoveMultipleTypesHistoryProhibited) { 1032 PrefService* prefs = GetProfile()->GetPrefs(); 1033 prefs->SetBoolean(prefs::kAllowDeletingBrowserHistory, false); 1034 1035 // Add some history. 1036 RemoveHistoryTester history_tester; 1037 ASSERT_TRUE(history_tester.Init(GetProfile())); 1038 history_tester.AddHistory(kOrigin1, base::Time::Now()); 1039 ASSERT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); 1040 1041 int removal_mask = BrowsingDataRemover::REMOVE_HISTORY | 1042 BrowsingDataRemover::REMOVE_COOKIES; 1043 1044 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 1045 removal_mask, false); 1046 EXPECT_EQ(removal_mask, GetRemovalMask()); 1047 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1048 1049 // 1/2. History should remain. 1050 EXPECT_TRUE(history_tester.HistoryContainsURL(kOrigin1)); 1051 1052 // 2/2. The cookie(s) would be deleted throught the StorageParition, check if 1053 // the partition was requested to remove cookie. 1054 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1055 EXPECT_EQ(removal_data.remove_mask, 1056 static_cast<uint32>( 1057 StoragePartition::REMOVE_DATA_MASK_COOKIES)); 1058 // Persistent storage won't be deleted, since EVERYTHING was not specified. 1059 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1060 static_cast<uint32>( 1061 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL & 1062 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT)); 1063 } 1064 #endif 1065 1066 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) { 1067 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 1068 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1069 BrowsingDataRemover::REMOVE_WEBSQL | 1070 BrowsingDataRemover::REMOVE_APPCACHE | 1071 BrowsingDataRemover::REMOVE_INDEXEDDB, 1072 false); 1073 1074 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1075 BrowsingDataRemover::REMOVE_WEBSQL | 1076 BrowsingDataRemover::REMOVE_APPCACHE | 1077 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask()); 1078 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1079 1080 // Verify storage partition related stuffs. 1081 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1082 EXPECT_EQ(removal_data.remove_mask, 1083 static_cast<uint32>( 1084 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1085 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1086 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1087 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1088 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1089 static_cast<uint32>( 1090 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1091 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 1092 } 1093 1094 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyTemporary) { 1095 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 1096 new MockExtensionSpecialStoragePolicy; 1097 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 1098 1099 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 1100 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1101 BrowsingDataRemover::REMOVE_WEBSQL | 1102 BrowsingDataRemover::REMOVE_APPCACHE | 1103 BrowsingDataRemover::REMOVE_INDEXEDDB, 1104 false); 1105 1106 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1107 BrowsingDataRemover::REMOVE_WEBSQL | 1108 BrowsingDataRemover::REMOVE_APPCACHE | 1109 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask()); 1110 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1111 1112 // Verify storage partition related stuffs. 1113 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1114 1115 EXPECT_EQ(removal_data.remove_mask, 1116 static_cast<uint32>( 1117 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1118 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1119 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1120 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1121 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1122 static_cast<uint32>( 1123 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1124 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 1125 1126 // Check that all related origin data would be removed, that is, origin 1127 // matcher would match these origin. 1128 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy)); 1129 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy)); 1130 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy)); 1131 } 1132 1133 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverOnlyPersistent) { 1134 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 1135 new MockExtensionSpecialStoragePolicy; 1136 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 1137 1138 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 1139 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1140 BrowsingDataRemover::REMOVE_WEBSQL | 1141 BrowsingDataRemover::REMOVE_APPCACHE | 1142 BrowsingDataRemover::REMOVE_INDEXEDDB, 1143 false); 1144 1145 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1146 BrowsingDataRemover::REMOVE_WEBSQL | 1147 BrowsingDataRemover::REMOVE_APPCACHE | 1148 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask()); 1149 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1150 1151 // Verify storage partition related stuffs. 1152 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1153 1154 EXPECT_EQ(removal_data.remove_mask, 1155 static_cast<uint32>( 1156 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1157 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1158 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1159 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1160 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1161 static_cast<uint32>( 1162 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1163 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 1164 1165 // Check that all related origin data would be removed, that is, origin 1166 // matcher would match these origin. 1167 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy)); 1168 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy)); 1169 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy)); 1170 } 1171 1172 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverNeither) { 1173 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 1174 new MockExtensionSpecialStoragePolicy; 1175 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 1176 1177 1178 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 1179 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1180 BrowsingDataRemover::REMOVE_WEBSQL | 1181 BrowsingDataRemover::REMOVE_APPCACHE | 1182 BrowsingDataRemover::REMOVE_INDEXEDDB, 1183 false); 1184 1185 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1186 BrowsingDataRemover::REMOVE_WEBSQL | 1187 BrowsingDataRemover::REMOVE_APPCACHE | 1188 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask()); 1189 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1190 1191 // Verify storage partition related stuffs. 1192 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1193 1194 EXPECT_EQ(removal_data.remove_mask, 1195 static_cast<uint32>( 1196 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1197 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1198 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1199 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1200 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1201 static_cast<uint32>( 1202 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1203 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 1204 1205 // Check that all related origin data would be removed, that is, origin 1206 // matcher would match these origin. 1207 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy)); 1208 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy)); 1209 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy)); 1210 } 1211 1212 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverSpecificOrigin) { 1213 // Remove Origin 1. 1214 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, 1215 BrowsingDataRemover::REMOVE_APPCACHE | 1216 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1217 BrowsingDataRemover::REMOVE_INDEXEDDB | 1218 BrowsingDataRemover::REMOVE_WEBSQL, 1219 kOrigin1); 1220 1221 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | 1222 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1223 BrowsingDataRemover::REMOVE_INDEXEDDB | 1224 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask()); 1225 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1226 1227 // Verify storage partition related stuffs. 1228 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1229 1230 EXPECT_EQ(removal_data.remove_mask, 1231 static_cast<uint32>( 1232 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1233 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1234 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1235 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1236 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1237 static_cast<uint32>( 1238 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1239 EXPECT_EQ(removal_data.remove_origin, kOrigin1); 1240 } 1241 1242 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastHour) { 1243 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_HOUR, 1244 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1245 BrowsingDataRemover::REMOVE_WEBSQL | 1246 BrowsingDataRemover::REMOVE_APPCACHE | 1247 BrowsingDataRemover::REMOVE_INDEXEDDB, 1248 false); 1249 1250 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1251 BrowsingDataRemover::REMOVE_WEBSQL | 1252 BrowsingDataRemover::REMOVE_APPCACHE | 1253 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask()); 1254 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1255 1256 // Verify storage partition related stuffs. 1257 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1258 1259 EXPECT_EQ(removal_data.remove_mask, 1260 static_cast<uint32>( 1261 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1262 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1263 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1264 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1265 1266 // Persistent data would be left out since we are not removing from 1267 // beginning of time. 1268 uint32 expected_quota_mask = 1269 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 1270 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); 1271 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 1272 // Check removal begin time. 1273 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 1274 } 1275 1276 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForLastWeek) { 1277 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::LAST_WEEK, 1278 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1279 BrowsingDataRemover::REMOVE_WEBSQL | 1280 BrowsingDataRemover::REMOVE_APPCACHE | 1281 BrowsingDataRemover::REMOVE_INDEXEDDB, 1282 false); 1283 1284 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1285 BrowsingDataRemover::REMOVE_WEBSQL | 1286 BrowsingDataRemover::REMOVE_APPCACHE | 1287 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask()); 1288 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1289 1290 // Verify storage partition related stuffs. 1291 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1292 1293 EXPECT_EQ(removal_data.remove_mask, 1294 static_cast<uint32>( 1295 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1296 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1297 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1298 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1299 1300 // Persistent data would be left out since we are not removing from 1301 // beginning of time. 1302 uint32 expected_quota_mask = 1303 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT; 1304 EXPECT_EQ(removal_data.quota_storage_remove_mask, expected_quota_mask); 1305 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 1306 // Check removal begin time. 1307 EXPECT_EQ(removal_data.remove_begin, GetBeginTime()); 1308 } 1309 1310 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedUnprotectedOrigins) { 1311 // Protect kOrigin1. 1312 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 1313 new MockExtensionSpecialStoragePolicy; 1314 mock_policy->AddProtected(kOrigin1.GetOrigin()); 1315 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 1316 1317 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 1318 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1319 BrowsingDataRemover::REMOVE_WEBSQL | 1320 BrowsingDataRemover::REMOVE_APPCACHE | 1321 BrowsingDataRemover::REMOVE_INDEXEDDB, 1322 false); 1323 1324 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1325 BrowsingDataRemover::REMOVE_WEBSQL | 1326 BrowsingDataRemover::REMOVE_APPCACHE | 1327 BrowsingDataRemover::REMOVE_INDEXEDDB, GetRemovalMask()); 1328 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1329 1330 // Verify storage partition related stuffs. 1331 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1332 1333 EXPECT_EQ(removal_data.remove_mask, 1334 static_cast<uint32>( 1335 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1336 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1337 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1338 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1339 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1340 static_cast<uint32>( 1341 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1342 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 1343 1344 // Check OriginMatcherFunction, |kOrigin1| would not match mask since it 1345 // is protected. 1346 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy)); 1347 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy)); 1348 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy)); 1349 } 1350 1351 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedSpecificOrigin) { 1352 // Protect kOrigin1. 1353 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 1354 new MockExtensionSpecialStoragePolicy; 1355 mock_policy->AddProtected(kOrigin1.GetOrigin()); 1356 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 1357 1358 // Try to remove kOrigin1. Expect failure. 1359 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, 1360 BrowsingDataRemover::REMOVE_APPCACHE | 1361 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1362 BrowsingDataRemover::REMOVE_INDEXEDDB | 1363 BrowsingDataRemover::REMOVE_WEBSQL, 1364 kOrigin1); 1365 1366 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | 1367 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1368 BrowsingDataRemover::REMOVE_INDEXEDDB | 1369 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask()); 1370 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1371 1372 // Verify storage partition related stuffs. 1373 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1374 1375 EXPECT_EQ(removal_data.remove_mask, 1376 static_cast<uint32>( 1377 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1378 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1379 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1380 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1381 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1382 static_cast<uint32>( 1383 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1384 EXPECT_EQ(removal_data.remove_origin, kOrigin1); 1385 1386 // Check OriginMatcherFunction, |kOrigin1| would not match mask since it 1387 // is protected. 1388 EXPECT_FALSE(removal_data.origin_matcher.Run(kOrigin1, mock_policy)); 1389 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy)); 1390 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy)); 1391 } 1392 1393 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedProtectedOrigins) { 1394 // Protect kOrigin1. 1395 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 1396 new MockExtensionSpecialStoragePolicy; 1397 mock_policy->AddProtected(kOrigin1.GetOrigin()); 1398 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 1399 1400 // Try to remove kOrigin1. Expect success. 1401 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 1402 BrowsingDataRemover::REMOVE_APPCACHE | 1403 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1404 BrowsingDataRemover::REMOVE_INDEXEDDB | 1405 BrowsingDataRemover::REMOVE_WEBSQL, 1406 true); 1407 1408 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | 1409 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1410 BrowsingDataRemover::REMOVE_INDEXEDDB | 1411 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask()); 1412 EXPECT_EQ(BrowsingDataHelper::PROTECTED_WEB | 1413 BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1414 1415 // Verify storage partition related stuffs. 1416 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1417 1418 EXPECT_EQ(removal_data.remove_mask, 1419 static_cast<uint32>( 1420 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1421 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1422 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1423 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1424 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1425 static_cast<uint32>( 1426 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1427 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 1428 1429 // Check OriginMatcherFunction, |kOrigin1| would match mask since we 1430 // would have 'protected' specified in origin_set_mask. 1431 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin1, mock_policy)); 1432 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin2, mock_policy)); 1433 EXPECT_TRUE(removal_data.origin_matcher.Run(kOrigin3, mock_policy)); 1434 } 1435 1436 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedIgnoreExtensionsAndDevTools) { 1437 scoped_refptr<MockExtensionSpecialStoragePolicy> mock_policy = 1438 new MockExtensionSpecialStoragePolicy; 1439 GetProfile()->SetExtensionSpecialStoragePolicy(mock_policy.get()); 1440 1441 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, 1442 BrowsingDataRemover::REMOVE_APPCACHE | 1443 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1444 BrowsingDataRemover::REMOVE_INDEXEDDB | 1445 BrowsingDataRemover::REMOVE_WEBSQL, 1446 false); 1447 1448 EXPECT_EQ(BrowsingDataRemover::REMOVE_APPCACHE | 1449 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | 1450 BrowsingDataRemover::REMOVE_INDEXEDDB | 1451 BrowsingDataRemover::REMOVE_WEBSQL, GetRemovalMask()); 1452 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1453 1454 // Verify storage partition related stuffs. 1455 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); 1456 1457 EXPECT_EQ(removal_data.remove_mask, 1458 static_cast<uint32>( 1459 StoragePartition::REMOVE_DATA_MASK_FILE_SYSTEMS | 1460 StoragePartition::REMOVE_DATA_MASK_WEBSQL | 1461 StoragePartition::REMOVE_DATA_MASK_APPCACHE | 1462 StoragePartition::REMOVE_DATA_MASK_INDEXEDDB)); 1463 EXPECT_EQ(removal_data.quota_storage_remove_mask, 1464 static_cast<uint32>( 1465 StoragePartition::QUOTA_MANAGED_STORAGE_MASK_ALL)); 1466 EXPECT_TRUE(removal_data.remove_origin.is_empty()); 1467 1468 // Check that extension and devtools data wouldn't be removed, that is, 1469 // origin matcher would not match these origin. 1470 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginExt, mock_policy)); 1471 EXPECT_FALSE(removal_data.origin_matcher.Run(kOriginDevTools, mock_policy)); 1472 } 1473 1474 TEST_F(BrowsingDataRemoverTest, OriginBasedHistoryRemoval) { 1475 RemoveHistoryTester tester; 1476 ASSERT_TRUE(tester.Init(GetProfile())); 1477 1478 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); 1479 1480 tester.AddHistory(kOrigin1, base::Time::Now()); 1481 tester.AddHistory(kOrigin2, two_hours_ago); 1482 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 1483 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); 1484 1485 BlockUntilOriginDataRemoved(BrowsingDataRemover::EVERYTHING, 1486 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); 1487 1488 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 1489 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1490 1491 // Nothing should have been deleted. 1492 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); 1493 EXPECT_FALSE(tester.HistoryContainsURL(kOrigin2)); 1494 } 1495 1496 TEST_F(BrowsingDataRemoverTest, OriginAndTimeBasedHistoryRemoval) { 1497 RemoveHistoryTester tester; 1498 ASSERT_TRUE(tester.Init(GetProfile())); 1499 1500 base::Time two_hours_ago = base::Time::Now() - base::TimeDelta::FromHours(2); 1501 1502 tester.AddHistory(kOrigin1, base::Time::Now()); 1503 tester.AddHistory(kOrigin2, two_hours_ago); 1504 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin1)); 1505 ASSERT_TRUE(tester.HistoryContainsURL(kOrigin2)); 1506 1507 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, 1508 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2); 1509 1510 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 1511 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1512 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin1)); 1513 EXPECT_TRUE(tester.HistoryContainsURL(kOrigin2)); 1514 } 1515 1516 // Verify that clearing autofill form data works. 1517 TEST_F(BrowsingDataRemoverTest, AutofillRemovalLastHour) { 1518 GetProfile()->CreateWebDataService(); 1519 RemoveAutofillTester tester(GetProfile()); 1520 1521 ASSERT_FALSE(tester.HasProfile()); 1522 tester.AddProfilesAndCards(); 1523 ASSERT_TRUE(tester.HasProfile()); 1524 1525 BlockUntilBrowsingDataRemoved( 1526 BrowsingDataRemover::LAST_HOUR, 1527 BrowsingDataRemover::REMOVE_FORM_DATA, false); 1528 1529 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); 1530 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1531 ASSERT_FALSE(tester.HasProfile()); 1532 } 1533 1534 TEST_F(BrowsingDataRemoverTest, AutofillRemovalEverything) { 1535 GetProfile()->CreateWebDataService(); 1536 RemoveAutofillTester tester(GetProfile()); 1537 1538 ASSERT_FALSE(tester.HasProfile()); 1539 tester.AddProfilesAndCards(); 1540 ASSERT_TRUE(tester.HasProfile()); 1541 1542 BlockUntilBrowsingDataRemoved( 1543 BrowsingDataRemover::EVERYTHING, 1544 BrowsingDataRemover::REMOVE_FORM_DATA, false); 1545 1546 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); 1547 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1548 ASSERT_FALSE(tester.HasProfile()); 1549 } 1550 1551 // Verify that clearing autofill form data works. 1552 TEST_F(BrowsingDataRemoverTest, AutofillOriginsRemovedWithHistory) { 1553 GetProfile()->CreateWebDataService(); 1554 RemoveAutofillTester tester(GetProfile()); 1555 1556 tester.AddProfilesAndCards(); 1557 EXPECT_FALSE(tester.HasOrigin(std::string())); 1558 EXPECT_TRUE(tester.HasOrigin(kWebOrigin)); 1559 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin)); 1560 1561 BlockUntilBrowsingDataRemoved( 1562 BrowsingDataRemover::LAST_HOUR, 1563 BrowsingDataRemover::REMOVE_HISTORY, false); 1564 1565 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); 1566 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); 1567 EXPECT_TRUE(tester.HasOrigin(std::string())); 1568 EXPECT_FALSE(tester.HasOrigin(kWebOrigin)); 1569 EXPECT_TRUE(tester.HasOrigin(kChromeOrigin)); 1570 } 1571 1572 #if defined(OS_CHROMEOS) 1573 TEST_F(BrowsingDataRemoverTest, ContentProtectionPlatformKeysRemoval) { 1574 chromeos::ScopedTestDeviceSettingsService test_device_settings_service; 1575 chromeos::ScopedTestCrosSettings test_cros_settings; 1576 chromeos::MockUserManager* mock_user_manager = 1577 new testing::NiceMock<chromeos::MockUserManager>(); 1578 mock_user_manager->SetActiveUser("test (at) example.com"); 1579 chromeos::ScopedUserManagerEnabler user_manager_enabler(mock_user_manager); 1580 1581 chromeos::FakeDBusThreadManager* fake_dbus_manager = 1582 new chromeos::FakeDBusThreadManager; 1583 chromeos::MockCryptohomeClient* cryptohome_client = 1584 new chromeos::MockCryptohomeClient; 1585 fake_dbus_manager->SetCryptohomeClient( 1586 scoped_ptr<chromeos::CryptohomeClient>(cryptohome_client)); 1587 chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_manager); 1588 1589 // Expect exactly one call. No calls means no attempt to delete keys and more 1590 // than one call means a significant performance problem. 1591 EXPECT_CALL(*cryptohome_client, TpmAttestationDeleteKeys(_, _, _, _)) 1592 .WillOnce(WithArgs<3>(Invoke(FakeDBusCall))); 1593 1594 BlockUntilBrowsingDataRemoved( 1595 BrowsingDataRemover::EVERYTHING, 1596 BrowsingDataRemover::REMOVE_CONTENT_LICENSES, false); 1597 1598 chromeos::DBusThreadManager::Shutdown(); 1599 } 1600 #endif 1601