Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 #include <string> | 13 #include <string> |
| 14 #include <utility> | |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/bind.h" | 17 #include "base/bind.h" |
| 17 #include "base/bind_helpers.h" | 18 #include "base/bind_helpers.h" |
| 18 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 19 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
| 20 #include "base/guid.h" | 21 #include "base/guid.h" |
| 21 #include "base/location.h" | 22 #include "base/location.h" |
| 22 #include "base/logging.h" | 23 #include "base/logging.h" |
| 23 #include "base/macros.h" | 24 #include "base/macros.h" |
| 24 #include "base/memory/ptr_util.h" | 25 #include "base/memory/ptr_util.h" |
| 25 #include "base/message_loop/message_loop.h" | 26 #include "base/message_loop/message_loop.h" |
| 26 #include "base/run_loop.h" | 27 #include "base/run_loop.h" |
| 27 #include "base/single_thread_task_runner.h" | 28 #include "base/single_thread_task_runner.h" |
| 29 #include "base/strings/string_number_conversions.h" | |
| 28 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/task/cancelable_task_tracker.h" | 31 #include "base/task/cancelable_task_tracker.h" |
| 30 #include "base/threading/thread_task_runner_handle.h" | 32 #include "base/threading/thread_task_runner_handle.h" |
| 31 #include "build/build_config.h" | 33 #include "build/build_config.h" |
| 32 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 34 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 33 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 35 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 34 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" | 36 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" |
| 35 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 37 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 36 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" | 38 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" |
| 37 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" | 39 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 using content::BrowserThread; | 128 using content::BrowserThread; |
| 127 using content::StoragePartition; | 129 using content::StoragePartition; |
| 128 using domain_reliability::CLEAR_BEACONS; | 130 using domain_reliability::CLEAR_BEACONS; |
| 129 using domain_reliability::CLEAR_CONTEXTS; | 131 using domain_reliability::CLEAR_CONTEXTS; |
| 130 using domain_reliability::DomainReliabilityClearMode; | 132 using domain_reliability::DomainReliabilityClearMode; |
| 131 using domain_reliability::DomainReliabilityMonitor; | 133 using domain_reliability::DomainReliabilityMonitor; |
| 132 using domain_reliability::DomainReliabilityService; | 134 using domain_reliability::DomainReliabilityService; |
| 133 using domain_reliability::DomainReliabilityServiceFactory; | 135 using domain_reliability::DomainReliabilityServiceFactory; |
| 134 using testing::_; | 136 using testing::_; |
| 135 using testing::ByRef; | 137 using testing::ByRef; |
| 138 using testing::Eq; | |
| 136 using testing::Invoke; | 139 using testing::Invoke; |
| 137 using testing::IsEmpty; | 140 using testing::IsEmpty; |
| 138 using testing::Matcher; | 141 using testing::Matcher; |
| 139 using testing::MakeMatcher; | 142 using testing::MakeMatcher; |
| 140 using testing::MatcherInterface; | 143 using testing::MatcherInterface; |
| 141 using testing::MatchResultListener; | 144 using testing::MatchResultListener; |
| 142 using testing::Not; | 145 using testing::Not; |
| 143 using testing::Return; | 146 using testing::Return; |
| 147 using testing::SizeIs; | |
| 144 using testing::WithArgs; | 148 using testing::WithArgs; |
| 145 | 149 |
| 146 namespace { | 150 namespace { |
| 147 | 151 |
| 148 const char kTestOrigin1[] = "http://host1.com:1/"; | 152 const char kTestOrigin1[] = "http://host1.com:1/"; |
| 149 const char kTestRegisterableDomain1[] = "host1.com"; | 153 const char kTestRegisterableDomain1[] = "host1.com"; |
| 150 const char kTestOrigin2[] = "http://host2.com:1/"; | 154 const char kTestOrigin2[] = "http://host2.com:1/"; |
| 151 const char kTestOrigin3[] = "http://host3.com:1/"; | 155 const char kTestOrigin3[] = "http://host3.com:1/"; |
| 152 const char kTestRegisterableDomain3[] = "host3.com"; | 156 const char kTestRegisterableDomain3[] = "host3.com"; |
| 153 const char kTestOrigin4[] = "https://host3.com:1/"; | 157 const char kTestOrigin4[] = "https://host3.com:1/"; |
| (...skipping 2915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3069 // Test that the remover clears bookmark meta data (normally added in a tab | 3073 // Test that the remover clears bookmark meta data (normally added in a tab |
| 3070 // helper). | 3074 // helper). |
| 3071 TEST_F(BrowsingDataRemoverTest, BookmarkLastVisitDatesGetCleared) { | 3075 TEST_F(BrowsingDataRemoverTest, BookmarkLastVisitDatesGetCleared) { |
| 3072 TestingProfile profile; | 3076 TestingProfile profile; |
| 3073 profile.CreateBookmarkModel(true); | 3077 profile.CreateBookmarkModel(true); |
| 3074 | 3078 |
| 3075 bookmarks::BookmarkModel* bookmark_model = | 3079 bookmarks::BookmarkModel* bookmark_model = |
| 3076 BookmarkModelFactory::GetForBrowserContext(&profile); | 3080 BookmarkModelFactory::GetForBrowserContext(&profile); |
| 3077 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); | 3081 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); |
| 3078 | 3082 |
| 3083 const base::Time delete_begin = | |
| 3084 base::Time::Now() - base::TimeDelta::FromDays(1); | |
| 3085 | |
| 3079 // Create a couple of bookmarks. | 3086 // Create a couple of bookmarks. |
| 3080 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0, | 3087 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0, |
| 3081 base::string16(), | 3088 base::string16(), |
| 3082 GURL("http://foo.org/desktop")); | 3089 GURL("http://foo.org/desktop")); |
| 3083 bookmark_model->AddURL(bookmark_model->mobile_node(), 0, | 3090 bookmark_model->AddURL(bookmark_model->mobile_node(), 0, |
| 3084 base::string16(), | 3091 base::string16(), |
| 3085 GURL("http://foo.org/mobile")); | 3092 GURL("http://foo.org/mobile")); |
| 3086 | 3093 |
| 3087 // Simulate their visits. | 3094 // Simulate their visits (this is using Time::Now() as timestamps). |
| 3088 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( | 3095 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( |
| 3089 bookmark_model, GURL("http://foo.org/desktop"), | 3096 bookmark_model, GURL("http://foo.org/desktop"), |
| 3090 /*is_mobile_platform=*/false); | 3097 /*is_mobile_platform=*/false); |
| 3091 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( | 3098 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( |
| 3092 bookmark_model, GURL("http://foo.org/mobile"), | 3099 bookmark_model, GURL("http://foo.org/mobile"), |
| 3093 /*is_mobile_platform=*/true); | 3100 /*is_mobile_platform=*/true); |
| 3094 | 3101 |
| 3102 // Add a bookmark with a visited timestamp before the deletion interval. | |
| 3103 bookmarks::BookmarkNode::MetaInfoMap meta_info = { | |
| 3104 {"last_visited", | |
| 3105 base::Int64ToString((delete_begin - base::TimeDelta::FromSeconds(1)) | |
| 3106 .ToInternalValue())}}; | |
| 3107 bookmark_model->AddURLWithCreationTimeAndMetaInfo( | |
| 3108 bookmark_model->mobile_node(), 0, base::ASCIIToUTF16("my title"), | |
| 3109 GURL("http://foo-2.org/"), delete_begin - base::TimeDelta::FromDays(1), | |
| 3110 &meta_info); | |
| 3111 | |
| 3095 // There should be some recently visited bookmarks. | 3112 // There should be some recently visited bookmarks. |
| 3096 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks( | 3113 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks( |
| 3097 bookmark_model, 2, base::Time::UnixEpoch(), | 3114 bookmark_model, 2, base::Time::UnixEpoch(), |
| 3098 /*consider_visits_from_desktop=*/false), | 3115 /*consider_visits_from_desktop=*/false), |
| 3099 Not(IsEmpty())); | 3116 Not(IsEmpty())); |
| 3100 | 3117 |
| 3101 // Inject the bookmark model into the remover. | 3118 // Inject the bookmark model into the remover. |
| 3102 BrowsingDataRemover* remover = | 3119 BrowsingDataRemover* remover = |
| 3103 BrowsingDataRemoverFactory::GetForBrowserContext(&profile); | 3120 BrowsingDataRemoverFactory::GetForBrowserContext(&profile); |
| 3104 | 3121 |
| 3105 BrowsingDataRemoverCompletionObserver completion_observer(remover); | 3122 BrowsingDataRemoverCompletionObserver completion_observer(remover); |
| 3106 remover->RemoveAndReply(BrowsingDataRemover::Unbounded(), | 3123 remover->RemoveAndReply( |
| 3107 BrowsingDataRemover::REMOVE_HISTORY, | 3124 BrowsingDataRemover::TimeRange(delete_begin, base::Time::Max()), |
|
msramek
2017/01/04 20:27:20
FYI, I landed https://codereview.chromium.org/2578
| |
| 3108 BrowsingDataHelper::ALL, &completion_observer); | 3125 BrowsingDataRemover::REMOVE_HISTORY, BrowsingDataHelper::ALL, |
| 3126 &completion_observer); | |
| 3109 completion_observer.BlockUntilCompletion(); | 3127 completion_observer.BlockUntilCompletion(); |
| 3110 | 3128 |
| 3111 // There should be no recently visited bookmarks. | 3129 // There should be only 1 recently visited bookmarks. |
| 3112 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks( | 3130 std::vector<const bookmarks::BookmarkNode*> remaining_nodes = |
| 3113 bookmark_model, 2, base::Time::UnixEpoch(), | 3131 ntp_snippets::GetRecentlyVisitedBookmarks( |
| 3114 /*consider_visits_from_desktop=*/false), | 3132 bookmark_model, 3, base::Time::UnixEpoch(), |
| 3115 IsEmpty()); | 3133 /*consider_visits_from_desktop=*/true); |
| 3116 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks( | 3134 EXPECT_THAT(remaining_nodes, SizeIs(1)); |
| 3117 bookmark_model, 2, base::Time::UnixEpoch(), | 3135 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/")); |
| 3118 /*consider_visits_from_desktop=*/true), | |
| 3119 IsEmpty()); | |
| 3120 } | 3136 } |
| OLD | NEW |