Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: chrome/browser/browsing_data/browsing_data_remover_unittest.cc

Issue 2616633002: Respect time range in browsing data removal for last-visited data. (Closed)
Patch Set: rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 2922 matching lines...) Expand 10 before | Expand all | Expand 10 after
3076 // Test that the remover clears bookmark meta data (normally added in a tab 3080 // Test that the remover clears bookmark meta data (normally added in a tab
3077 // helper). 3081 // helper).
3078 TEST_F(BrowsingDataRemoverTest, BookmarkLastVisitDatesGetCleared) { 3082 TEST_F(BrowsingDataRemoverTest, BookmarkLastVisitDatesGetCleared) {
3079 TestingProfile profile; 3083 TestingProfile profile;
3080 profile.CreateBookmarkModel(true); 3084 profile.CreateBookmarkModel(true);
3081 3085
3082 bookmarks::BookmarkModel* bookmark_model = 3086 bookmarks::BookmarkModel* bookmark_model =
3083 BookmarkModelFactory::GetForBrowserContext(&profile); 3087 BookmarkModelFactory::GetForBrowserContext(&profile);
3084 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); 3088 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
3085 3089
3090 const base::Time delete_begin =
3091 base::Time::Now() - base::TimeDelta::FromDays(1);
3092
3086 // Create a couple of bookmarks. 3093 // Create a couple of bookmarks.
3087 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0, 3094 bookmark_model->AddURL(bookmark_model->bookmark_bar_node(), 0,
3088 base::string16(), 3095 base::string16(),
3089 GURL("http://foo.org/desktop")); 3096 GURL("http://foo.org/desktop"));
3090 bookmark_model->AddURL(bookmark_model->mobile_node(), 0, 3097 bookmark_model->AddURL(bookmark_model->mobile_node(), 0,
3091 base::string16(), 3098 base::string16(),
3092 GURL("http://foo.org/mobile")); 3099 GURL("http://foo.org/mobile"));
3093 3100
3094 // Simulate their visits. 3101 // Simulate their visits (this is using Time::Now() as timestamps).
3095 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( 3102 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame(
3096 bookmark_model, GURL("http://foo.org/desktop"), 3103 bookmark_model, GURL("http://foo.org/desktop"),
3097 /*is_mobile_platform=*/false); 3104 /*is_mobile_platform=*/false);
3098 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame( 3105 ntp_snippets::UpdateBookmarkOnURLVisitedInMainFrame(
3099 bookmark_model, GURL("http://foo.org/mobile"), 3106 bookmark_model, GURL("http://foo.org/mobile"),
3100 /*is_mobile_platform=*/true); 3107 /*is_mobile_platform=*/true);
3101 3108
3109 // Add a bookmark with a visited timestamp before the deletion interval.
3110 bookmarks::BookmarkNode::MetaInfoMap meta_info = {
3111 {"last_visited",
3112 base::Int64ToString((delete_begin - base::TimeDelta::FromSeconds(1))
3113 .ToInternalValue())}};
3114 bookmark_model->AddURLWithCreationTimeAndMetaInfo(
3115 bookmark_model->mobile_node(), 0, base::ASCIIToUTF16("my title"),
3116 GURL("http://foo-2.org/"), delete_begin - base::TimeDelta::FromDays(1),
3117 &meta_info);
3118
3102 // There should be some recently visited bookmarks. 3119 // There should be some recently visited bookmarks.
3103 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks( 3120 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks(
3104 bookmark_model, 2, base::Time::UnixEpoch(), 3121 bookmark_model, 2, base::Time::UnixEpoch(),
3105 /*consider_visits_from_desktop=*/false), 3122 /*consider_visits_from_desktop=*/false),
3106 Not(IsEmpty())); 3123 Not(IsEmpty()));
3107 3124
3108 // Inject the bookmark model into the remover. 3125 // Inject the bookmark model into the remover.
3109 BrowsingDataRemover* remover = 3126 BrowsingDataRemover* remover =
3110 BrowsingDataRemoverFactory::GetForBrowserContext(&profile); 3127 BrowsingDataRemoverFactory::GetForBrowserContext(&profile);
3111 3128
3112 BrowsingDataRemoverCompletionObserver completion_observer(remover); 3129 BrowsingDataRemoverCompletionObserver completion_observer(remover);
3113 remover->RemoveAndReply(base::Time(), base::Time::Max(), 3130 remover->RemoveAndReply(delete_begin, base::Time::Max(),
3114 BrowsingDataRemover::REMOVE_HISTORY, 3131 BrowsingDataRemover::REMOVE_HISTORY,
3115 BrowsingDataHelper::ALL, &completion_observer); 3132 BrowsingDataHelper::ALL, &completion_observer);
3116 completion_observer.BlockUntilCompletion(); 3133 completion_observer.BlockUntilCompletion();
3117 3134
3118 // There should be no recently visited bookmarks. 3135 // There should be only 1 recently visited bookmarks.
3119 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks( 3136 std::vector<const bookmarks::BookmarkNode*> remaining_nodes =
3120 bookmark_model, 2, base::Time::UnixEpoch(), 3137 ntp_snippets::GetRecentlyVisitedBookmarks(
3121 /*consider_visits_from_desktop=*/false), 3138 bookmark_model, 3, base::Time::UnixEpoch(),
3122 IsEmpty()); 3139 /*consider_visits_from_desktop=*/true);
3123 EXPECT_THAT(ntp_snippets::GetRecentlyVisitedBookmarks( 3140 EXPECT_THAT(remaining_nodes, SizeIs(1));
3124 bookmark_model, 2, base::Time::UnixEpoch(), 3141 EXPECT_THAT(remaining_nodes[0]->url().spec(), Eq("http://foo-2.org/"));
3125 /*consider_visits_from_desktop=*/true),
3126 IsEmpty());
3127 } 3142 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/browsing_data/chrome_browsing_data_remover_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698