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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
15 #include "base/guid.h" | 15 #include "base/guid.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/prefs/testing_pref_service.h" | 17 #include "base/prefs/testing_pref_service.h" |
| 18 #include "base/run_loop.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/task/cancelable_task_tracker.h" | 20 #include "base/task/cancelable_task_tracker.h" |
20 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 21 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
21 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 23 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
22 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 24 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
23 #include "chrome/browser/domain_reliability/service_factory.h" | 25 #include "chrome/browser/domain_reliability/service_factory.h" |
| 26 #include "chrome/browser/favicon/favicon_service_factory.h" |
24 #include "chrome/browser/history/history_service_factory.h" | 27 #include "chrome/browser/history/history_service_factory.h" |
25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
26 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
27 #include "chrome/test/base/testing_browser_process.h" | 30 #include "chrome/test/base/testing_browser_process.h" |
28 #include "chrome/test/base/testing_profile.h" | 31 #include "chrome/test/base/testing_profile.h" |
29 #include "components/autofill/core/browser/autofill_profile.h" | 32 #include "components/autofill/core/browser/autofill_profile.h" |
30 #include "components/autofill/core/browser/autofill_test_utils.h" | 33 #include "components/autofill/core/browser/autofill_test_utils.h" |
31 #include "components/autofill/core/browser/credit_card.h" | 34 #include "components/autofill/core/browser/credit_card.h" |
32 #include "components/autofill/core/browser/personal_data_manager.h" | 35 #include "components/autofill/core/browser/personal_data_manager.h" |
33 #include "components/autofill/core/browser/personal_data_manager_observer.h" | 36 #include "components/autofill/core/browser/personal_data_manager_observer.h" |
| 37 #include "components/bookmarks/browser/bookmark_model.h" |
| 38 #include "components/bookmarks/test/bookmark_test_helpers.h" |
34 #include "components/domain_reliability/clear_mode.h" | 39 #include "components/domain_reliability/clear_mode.h" |
35 #include "components/domain_reliability/monitor.h" | 40 #include "components/domain_reliability/monitor.h" |
36 #include "components/domain_reliability/service.h" | 41 #include "components/domain_reliability/service.h" |
| 42 #include "components/favicon/core/favicon_service.h" |
37 #include "components/history/core/browser/history_service.h" | 43 #include "components/history/core/browser/history_service.h" |
38 #include "content/public/browser/cookie_store_factory.h" | 44 #include "content/public/browser/cookie_store_factory.h" |
39 #include "content/public/browser/dom_storage_context.h" | 45 #include "content/public/browser/dom_storage_context.h" |
40 #include "content/public/browser/local_storage_usage_info.h" | 46 #include "content/public/browser/local_storage_usage_info.h" |
41 #include "content/public/browser/storage_partition.h" | 47 #include "content/public/browser/storage_partition.h" |
42 #include "content/public/test/test_browser_thread.h" | 48 #include "content/public/test/test_browser_thread.h" |
43 #include "content/public/test/test_browser_thread_bundle.h" | 49 #include "content/public/test/test_browser_thread_bundle.h" |
44 #include "content/public/test/test_utils.h" | 50 #include "content/public/test/test_utils.h" |
45 #include "net/cookies/cookie_store.h" | 51 #include "net/cookies/cookie_store.h" |
46 #include "net/ssl/channel_id_service.h" | 52 #include "net/ssl/channel_id_service.h" |
47 #include "net/ssl/channel_id_store.h" | 53 #include "net/ssl/channel_id_store.h" |
48 #include "net/ssl/ssl_client_cert_type.h" | 54 #include "net/ssl/ssl_client_cert_type.h" |
49 #include "net/url_request/url_request_context.h" | 55 #include "net/url_request/url_request_context.h" |
50 #include "net/url_request/url_request_context_getter.h" | 56 #include "net/url_request/url_request_context_getter.h" |
51 #include "testing/gmock/include/gmock/gmock.h" | 57 #include "testing/gmock/include/gmock/gmock.h" |
52 #include "testing/gtest/include/gtest/gtest.h" | 58 #include "testing/gtest/include/gtest/gtest.h" |
| 59 #include "third_party/skia/include/core/SkBitmap.h" |
| 60 #include "ui/gfx/favicon_size.h" |
53 | 61 |
54 #if defined(OS_CHROMEOS) | 62 #if defined(OS_CHROMEOS) |
55 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 63 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
56 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | 64 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" |
57 #include "chrome/browser/chromeos/settings/cros_settings.h" | 65 #include "chrome/browser/chromeos/settings/cros_settings.h" |
58 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 66 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
59 #include "chromeos/dbus/dbus_thread_manager.h" | 67 #include "chromeos/dbus/dbus_thread_manager.h" |
60 #include "chromeos/dbus/mock_cryptohome_client.h" | 68 #include "chromeos/dbus/mock_cryptohome_client.h" |
61 #endif | 69 #endif |
62 | 70 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 base::CancelableTaskTracker tracker_; | 432 base::CancelableTaskTracker tracker_; |
425 bool query_url_success_; | 433 bool query_url_success_; |
426 base::Closure quit_closure_; | 434 base::Closure quit_closure_; |
427 | 435 |
428 // TestingProfile owns the history service; we shouldn't delete it. | 436 // TestingProfile owns the history service; we shouldn't delete it. |
429 history::HistoryService* history_service_; | 437 history::HistoryService* history_service_; |
430 | 438 |
431 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester); | 439 DISALLOW_COPY_AND_ASSIGN(RemoveHistoryTester); |
432 }; | 440 }; |
433 | 441 |
| 442 class RemoveFaviconTester { |
| 443 public: |
| 444 RemoveFaviconTester() |
| 445 : got_favicon_(false), |
| 446 got_expired_favicon_(false), |
| 447 history_service_(nullptr), |
| 448 favicon_service_(nullptr) {} |
| 449 |
| 450 bool Init(TestingProfile* profile) WARN_UNUSED_RESULT { |
| 451 // Create the history service if it has not been created yet. |
| 452 history_service_ = HistoryServiceFactory::GetForProfile( |
| 453 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 454 if (!history_service_) { |
| 455 if (!profile->CreateHistoryService(true, false)) |
| 456 return false; |
| 457 history_service_ = HistoryServiceFactory::GetForProfile( |
| 458 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 459 } |
| 460 |
| 461 profile->CreateFaviconService(); |
| 462 favicon_service_ = FaviconServiceFactory::GetForProfile( |
| 463 profile, ServiceAccessType::EXPLICIT_ACCESS); |
| 464 return true; |
| 465 } |
| 466 |
| 467 // Returns true if there is a favicon stored for |page_url| in the favicon |
| 468 // database. |
| 469 bool HasFaviconForPageURL(const GURL& page_url) { |
| 470 RequestFaviconSyncForPageURL(page_url); |
| 471 return got_favicon_; |
| 472 } |
| 473 |
| 474 // Returns true if: |
| 475 // - There is a favicon stored for |page_url| in the favicon database. |
| 476 // - The stored favicon is expired. |
| 477 bool HasExpiredFaviconForPageURL(const GURL& page_url) { |
| 478 RequestFaviconSyncForPageURL(page_url); |
| 479 return got_expired_favicon_; |
| 480 } |
| 481 |
| 482 // Adds a visit to history and stores an arbitrary favicon bitmap for |
| 483 // |page_url|. |
| 484 void VisitAndAddFavicon(const GURL& page_url) { |
| 485 history_service_->AddPage(page_url, base::Time::Now(), nullptr, 0, GURL(), |
| 486 history::RedirectList(), ui::PAGE_TRANSITION_LINK, |
| 487 history::SOURCE_BROWSED, false); |
| 488 |
| 489 SkBitmap bitmap; |
| 490 bitmap.allocN32Pixels(gfx::kFaviconSize, gfx::kFaviconSize); |
| 491 bitmap.eraseColor(SK_ColorBLUE); |
| 492 favicon_service_->SetFavicons(page_url, page_url, favicon_base::FAVICON, |
| 493 gfx::Image::CreateFrom1xBitmap(bitmap)); |
| 494 } |
| 495 |
| 496 private: |
| 497 // Synchronously requests the favicon for |page_url| from the favicon |
| 498 // database. |
| 499 void RequestFaviconSyncForPageURL(const GURL& page_url) { |
| 500 base::RunLoop run_loop; |
| 501 quit_closure_ = run_loop.QuitClosure(); |
| 502 favicon_service_->GetRawFaviconForPageURL( |
| 503 page_url, |
| 504 favicon_base::FAVICON, |
| 505 gfx::kFaviconSize, |
| 506 base::Bind(&RemoveFaviconTester::SaveResultAndQuit, |
| 507 base::Unretained(this)), |
| 508 &tracker_); |
| 509 run_loop.Run(); |
| 510 } |
| 511 |
| 512 // Callback for HistoryService::QueryURL. |
| 513 void SaveResultAndQuit(const favicon_base::FaviconRawBitmapResult& result) { |
| 514 got_favicon_ = result.is_valid(); |
| 515 got_expired_favicon_ = result.is_valid() && result.expired; |
| 516 quit_closure_.Run(); |
| 517 } |
| 518 |
| 519 // For favicon requests. |
| 520 base::CancelableTaskTracker tracker_; |
| 521 bool got_favicon_; |
| 522 bool got_expired_favicon_; |
| 523 base::Closure quit_closure_; |
| 524 |
| 525 // Owned by TestingProfile. |
| 526 history::HistoryService* history_service_; |
| 527 favicon::FaviconService* favicon_service_; |
| 528 |
| 529 DISALLOW_COPY_AND_ASSIGN(RemoveFaviconTester); |
| 530 }; |
| 531 |
434 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver { | 532 class RemoveAutofillTester : public autofill::PersonalDataManagerObserver { |
435 public: | 533 public: |
436 explicit RemoveAutofillTester(TestingProfile* profile) | 534 explicit RemoveAutofillTester(TestingProfile* profile) |
437 : personal_data_manager_( | 535 : personal_data_manager_( |
438 autofill::PersonalDataManagerFactory::GetForProfile(profile)) { | 536 autofill::PersonalDataManagerFactory::GetForProfile(profile)) { |
439 autofill::test::DisableSystemServices(profile->GetPrefs()); | 537 autofill::test::DisableSystemServices(profile->GetPrefs()); |
440 personal_data_manager_->AddObserver(this); | 538 personal_data_manager_->AddObserver(this); |
441 } | 539 } |
442 | 540 |
443 ~RemoveAutofillTester() override { | 541 ~RemoveAutofillTester() override { |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 // the partition was requested to remove cookie. | 1283 // the partition was requested to remove cookie. |
1186 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); | 1284 StoragePartitionRemovalData removal_data = GetStoragePartitionRemovalData(); |
1187 EXPECT_EQ(removal_data.remove_mask, | 1285 EXPECT_EQ(removal_data.remove_mask, |
1188 StoragePartition::REMOVE_DATA_MASK_COOKIES); | 1286 StoragePartition::REMOVE_DATA_MASK_COOKIES); |
1189 // Persistent storage won't be deleted, since EVERYTHING was not specified. | 1287 // Persistent storage won't be deleted, since EVERYTHING was not specified. |
1190 EXPECT_EQ(removal_data.quota_storage_remove_mask, | 1288 EXPECT_EQ(removal_data.quota_storage_remove_mask, |
1191 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); | 1289 ~StoragePartition::QUOTA_MANAGED_STORAGE_MASK_PERSISTENT); |
1192 } | 1290 } |
1193 #endif | 1291 #endif |
1194 | 1292 |
| 1293 // Test that clearing history deletes favicons not associated with bookmarks. |
| 1294 TEST_F(BrowsingDataRemoverTest, RemoveFaviconsForever) { |
| 1295 GURL page_url("http://a"); |
| 1296 |
| 1297 RemoveFaviconTester favicon_tester; |
| 1298 ASSERT_TRUE(favicon_tester.Init(GetProfile())); |
| 1299 favicon_tester.VisitAndAddFavicon(page_url); |
| 1300 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(page_url)); |
| 1301 |
| 1302 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 1303 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 1304 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 1305 EXPECT_FALSE(favicon_tester.HasFaviconForPageURL(page_url)); |
| 1306 } |
| 1307 |
| 1308 // Test that a bookmark's favicon is expired and not deleted when clearing |
| 1309 // history. Expiring the favicon causes the bookmark's favicon to be updated |
| 1310 // when the user next visits the bookmarked page. Expiring the bookmark's |
| 1311 // favicon is useful when the bookmark's favicon becomes incorrect (See |
| 1312 // crbug.com/474421 for a sample bug which causes this). |
| 1313 TEST_F(BrowsingDataRemoverTest, ExpireBookmarkFavicons) { |
| 1314 GURL bookmarked_page("http://a"); |
| 1315 |
| 1316 TestingProfile* profile = GetProfile(); |
| 1317 profile->CreateBookmarkModel(true); |
| 1318 bookmarks::BookmarkModel* bookmark_model = |
| 1319 BookmarkModelFactory::GetForProfile(profile); |
| 1320 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); |
| 1321 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0, |
| 1322 base::ASCIIToUTF16("a"), bookmarked_page); |
| 1323 |
| 1324 RemoveFaviconTester favicon_tester; |
| 1325 ASSERT_TRUE(favicon_tester.Init(GetProfile())); |
| 1326 favicon_tester.VisitAndAddFavicon(bookmarked_page); |
| 1327 ASSERT_TRUE(favicon_tester.HasFaviconForPageURL(bookmarked_page)); |
| 1328 |
| 1329 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
| 1330 BrowsingDataRemover::REMOVE_HISTORY, false); |
| 1331 EXPECT_EQ(BrowsingDataRemover::REMOVE_HISTORY, GetRemovalMask()); |
| 1332 EXPECT_TRUE(favicon_tester.HasExpiredFaviconForPageURL(bookmarked_page)); |
| 1333 } |
| 1334 |
1195 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) { | 1335 TEST_F(BrowsingDataRemoverTest, RemoveQuotaManagedDataForeverBoth) { |
1196 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, | 1336 BlockUntilBrowsingDataRemoved(BrowsingDataRemover::EVERYTHING, |
1197 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | 1337 BrowsingDataRemover::REMOVE_FILE_SYSTEMS | |
1198 BrowsingDataRemover::REMOVE_WEBSQL | | 1338 BrowsingDataRemover::REMOVE_WEBSQL | |
1199 BrowsingDataRemover::REMOVE_APPCACHE | | 1339 BrowsingDataRemover::REMOVE_APPCACHE | |
1200 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | | 1340 BrowsingDataRemover::REMOVE_SERVICE_WORKERS | |
1201 BrowsingDataRemover::REMOVE_INDEXEDDB, | 1341 BrowsingDataRemover::REMOVE_INDEXEDDB, |
1202 false); | 1342 false); |
1203 | 1343 |
1204 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | | 1344 EXPECT_EQ(BrowsingDataRemover::REMOVE_FILE_SYSTEMS | |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1842 // TODO(ttuttle): This isn't actually testing the no-monitor case, since | 1982 // TODO(ttuttle): This isn't actually testing the no-monitor case, since |
1843 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed | 1983 // BrowsingDataRemoverTest now creates one unconditionally, since it's needed |
1844 // for some unrelated test cases. This should be fixed so it tests the no- | 1984 // for some unrelated test cases. This should be fixed so it tests the no- |
1845 // monitor case again. | 1985 // monitor case again. |
1846 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { | 1986 TEST_F(BrowsingDataRemoverTest, DISABLED_DomainReliability_NoMonitor) { |
1847 BlockUntilBrowsingDataRemoved( | 1987 BlockUntilBrowsingDataRemoved( |
1848 BrowsingDataRemover::EVERYTHING, | 1988 BrowsingDataRemover::EVERYTHING, |
1849 BrowsingDataRemover::REMOVE_HISTORY | | 1989 BrowsingDataRemover::REMOVE_HISTORY | |
1850 BrowsingDataRemover::REMOVE_COOKIES, false); | 1990 BrowsingDataRemover::REMOVE_COOKIES, false); |
1851 } | 1991 } |
OLD | NEW |