| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" | 5 #include "chrome/browser/browsing_data/browsing_data_remover.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/platform_file.h" | 15 #include "base/platform_file.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "chrome/browser/autofill/autofill_common_test.h" |
| 18 #include "chrome/browser/autofill/autofill_profile.h" |
| 19 #include "chrome/browser/autofill/credit_card.h" |
| 20 #include "chrome/browser/autofill/personal_data_manager.h" |
| 21 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 22 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
| 17 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 23 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 18 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" | 24 #include "chrome/browser/extensions/mock_extension_special_storage_policy.h" |
| 19 #include "chrome/browser/history/history.h" | 25 #include "chrome/browser/history/history.h" |
| 20 #include "chrome/browser/history/history_service_factory.h" | 26 #include "chrome/browser/history/history_service_factory.h" |
| 21 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 27 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/test/base/testing_browser_process.h" | 30 #include "chrome/test/base/testing_browser_process.h" |
| 25 #include "chrome/test/base/testing_pref_service.h" | 31 #include "chrome/test/base/testing_pref_service.h" |
| 26 #include "chrome/test/base/testing_profile.h" | 32 #include "chrome/test/base/testing_profile.h" |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 // For History requests. | 311 // For History requests. |
| 306 CancelableRequestConsumer consumer_; | 312 CancelableRequestConsumer consumer_; |
| 307 bool query_url_success_; | 313 bool query_url_success_; |
| 308 | 314 |
| 309 // TestingProfile owns the history service; we shouldn't delete it. | 315 // TestingProfile owns the history service; we shouldn't delete it. |
| 310 HistoryService* history_service_; | 316 HistoryService* history_service_; |
| 311 | 317 |
| 312 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester); | 318 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester); |
| 313 }; | 319 }; |
| 314 | 320 |
| 321 class RemoveAutofillTester : public BrowsingDataRemoverTester, |
| 322 public PersonalDataManagerObserver { |
| 323 public: |
| 324 explicit RemoveAutofillTester(TestingProfile* profile) |
| 325 : personal_data_manager_( |
| 326 PersonalDataManagerFactory::GetForProfile(profile)) { |
| 327 autofill_test::DisableSystemServices(profile); |
| 328 personal_data_manager_->SetObserver(this); |
| 329 } |
| 330 |
| 331 virtual ~RemoveAutofillTester() { |
| 332 personal_data_manager_->RemoveObserver(this); |
| 333 } |
| 334 |
| 335 // Returns true if there are autofill profiles. |
| 336 bool HasProfile() { |
| 337 return !personal_data_manager_->profiles().empty() && |
| 338 !personal_data_manager_->credit_cards().empty(); |
| 339 } |
| 340 |
| 341 void AddProfile() { |
| 342 AutofillProfile profile; |
| 343 profile.SetInfo(NAME_FIRST, ASCIIToUTF16("Bob")); |
| 344 profile.SetInfo(NAME_LAST, ASCIIToUTF16("Smith")); |
| 345 profile.SetInfo(ADDRESS_HOME_ZIP, ASCIIToUTF16("94043")); |
| 346 profile.SetInfo(EMAIL_ADDRESS, ASCIIToUTF16("sue@example.com")); |
| 347 profile.SetInfo(COMPANY_NAME, ASCIIToUTF16("Company X")); |
| 348 |
| 349 std::vector<AutofillProfile> profiles; |
| 350 profiles.push_back(profile); |
| 351 personal_data_manager_->SetProfiles(&profiles); |
| 352 MessageLoop::current()->Run(); |
| 353 |
| 354 CreditCard card; |
| 355 card.SetInfo(CREDIT_CARD_NUMBER, ASCIIToUTF16("1234-5678-9012-3456")); |
| 356 |
| 357 std::vector<CreditCard> cards; |
| 358 cards.push_back(card); |
| 359 personal_data_manager_->SetCreditCards(&cards); |
| 360 MessageLoop::current()->Run(); |
| 361 } |
| 362 |
| 363 private: |
| 364 virtual void OnPersonalDataChanged() OVERRIDE { |
| 365 MessageLoop::current()->Quit(); |
| 366 } |
| 367 |
| 368 PersonalDataManager* personal_data_manager_; |
| 369 DISALLOW_COPY_AND_ASSIGN(RemoveAutofillTester); |
| 370 }; |
| 371 |
| 315 class RemoveLocalStorageTester : public BrowsingDataRemoverTester { | 372 class RemoveLocalStorageTester : public BrowsingDataRemoverTester { |
| 316 public: | 373 public: |
| 317 explicit RemoveLocalStorageTester(TestingProfile* profile) | 374 explicit RemoveLocalStorageTester(TestingProfile* profile) |
| 318 : profile_(profile), dom_storage_context_(NULL) { | 375 : profile_(profile), dom_storage_context_(NULL) { |
| 319 dom_storage_context_ = | 376 dom_storage_context_ = |
| 320 content::BrowserContext::GetDefaultStoragePartition(profile)-> | 377 content::BrowserContext::GetDefaultStoragePartition(profile)-> |
| 321 GetDOMStorageContext(); | 378 GetDOMStorageContext(); |
| 322 } | 379 } |
| 323 | 380 |
| 324 // Returns true, if the given origin URL exists. | 381 // Returns true, if the given origin URL exists. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 profile_.reset(); | 509 profile_.reset(); |
| 453 message_loop_.RunAllPending(); | 510 message_loop_.RunAllPending(); |
| 454 } | 511 } |
| 455 | 512 |
| 456 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, | 513 void BlockUntilBrowsingDataRemoved(BrowsingDataRemover::TimePeriod period, |
| 457 int remove_mask, | 514 int remove_mask, |
| 458 bool include_protected_origins, | 515 bool include_protected_origins, |
| 459 BrowsingDataRemoverTester* tester) { | 516 BrowsingDataRemoverTester* tester) { |
| 460 BrowsingDataRemover* remover = new BrowsingDataRemover( | 517 BrowsingDataRemover* remover = new BrowsingDataRemover( |
| 461 profile_.get(), period, | 518 profile_.get(), period, |
| 462 base::Time::Now() + base::TimeDelta::FromMilliseconds(10)); | 519 // Pick a time that's a bit into the future, since there could be |
| 520 // pending writes. |
| 521 base::Time::Now() + base::TimeDelta::FromSeconds(10)); |
| 463 remover->OverrideQuotaManagerForTesting(GetMockManager()); | 522 remover->OverrideQuotaManagerForTesting(GetMockManager()); |
| 464 remover->AddObserver(tester); | 523 remover->AddObserver(tester); |
| 465 | 524 |
| 466 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); | 525 called_with_details_.reset(new BrowsingDataRemover::NotificationDetails()); |
| 467 | 526 |
| 468 // BrowsingDataRemover deletes itself when it completes. | 527 // BrowsingDataRemover deletes itself when it completes. |
| 469 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB; | 528 int origin_set_mask = BrowsingDataHelper::UNPROTECTED_WEB; |
| 470 if (include_protected_origins) | 529 if (include_protected_origins) |
| 471 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB; | 530 origin_set_mask |= BrowsingDataHelper::PROTECTED_WEB; |
| 472 remover->Remove(remove_mask, origin_set_mask); | 531 remover->Remove(remove_mask, origin_set_mask); |
| (...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); | 1208 ASSERT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
| 1150 | 1209 |
| 1151 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, | 1210 BlockUntilOriginDataRemoved(BrowsingDataRemover::LAST_HOUR, |
| 1152 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get()); | 1211 BrowsingDataRemover::REMOVE_HISTORY, kOrigin2, tester.get()); |
| 1153 | 1212 |
| 1154 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); | 1213 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 1155 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); | 1214 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
| 1156 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1)); | 1215 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin1)); |
| 1157 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); | 1216 EXPECT_TRUE(tester->HistoryContainsURL(kOrigin2)); |
| 1158 } | 1217 } |
| 1218 |
| 1219 // Verify that clearing autofill form data works. |
| 1220 TEST_F(BrowsingDataRemoverTest, AutofillRemoval) { |
| 1221 GetProfile()->CreateWebDataService(); |
| 1222 scoped_ptr<RemoveAutofillTester> tester( |
| 1223 new RemoveAutofillTester(GetProfile())); |
| 1224 |
| 1225 ASSERT_FALSE(tester->HasProfile()); |
| 1226 tester->AddProfile(); |
| 1227 ASSERT_TRUE(tester->HasProfile()); |
| 1228 |
| 1229 BlockUntilBrowsingDataRemoved( |
| 1230 BrowsingDataRemover::LAST_HOUR, |
| 1231 BrowsingDataRemover::REMOVE_FORM_DATA, false, tester.get()); |
| 1232 |
| 1233 EXPECT_EQ(BrowsingDataRemover::REMOVE_FORM_DATA, GetRemovalMask()); |
| 1234 EXPECT_EQ(BrowsingDataHelper::UNPROTECTED_WEB, GetOriginSetMask()); |
| 1235 ASSERT_FALSE(tester->HasProfile()); |
| 1236 } |
| OLD | NEW |