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

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: updated browsing_data_remover_unittest and fixed lint warnings about missing includes 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 <vector> 14 #include <vector>
15 15
16 #include "base/bind.h" 16 #include "base/bind.h"
17 #include "base/bind_helpers.h" 17 #include "base/bind_helpers.h"
18 #include "base/files/file_path.h" 18 #include "base/files/file_path.h"
19 #include "base/files/file_util.h" 19 #include "base/files/file_util.h"
20 #include "base/guid.h" 20 #include "base/guid.h"
21 #include "base/location.h" 21 #include "base/location.h"
22 #include "base/logging.h" 22 #include "base/logging.h"
23 #include "base/macros.h" 23 #include "base/macros.h"
24 #include "base/memory/ptr_util.h" 24 #include "base/memory/ptr_util.h"
25 #include "base/message_loop/message_loop.h" 25 #include "base/message_loop/message_loop.h"
26 #include "base/run_loop.h" 26 #include "base/run_loop.h"
27 #include "base/single_thread_task_runner.h" 27 #include "base/single_thread_task_runner.h"
28 #include "base/strings/string_number_conversions.h"
28 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
29 #include "base/task/cancelable_task_tracker.h" 30 #include "base/task/cancelable_task_tracker.h"
30 #include "base/threading/thread_task_runner_handle.h" 31 #include "base/threading/thread_task_runner_handle.h"
31 #include "build/build_config.h" 32 #include "build/build_config.h"
32 #include "chrome/browser/autofill/personal_data_manager_factory.h" 33 #include "chrome/browser/autofill/personal_data_manager_factory.h"
33 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 34 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
34 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h" 35 #include "chrome/browser/browsing_data/browsing_data_filter_builder.h"
35 #include "chrome/browser/browsing_data/browsing_data_helper.h" 36 #include "chrome/browser/browsing_data/browsing_data_helper.h"
36 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h" 37 #include "chrome/browser/browsing_data/browsing_data_remover_factory.h"
37 #include "chrome/browser/browsing_data/browsing_data_remover_test_util.h" 38 #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; 127 using content::BrowserThread;
127 using content::StoragePartition; 128 using content::StoragePartition;
128 using domain_reliability::CLEAR_BEACONS; 129 using domain_reliability::CLEAR_BEACONS;
129 using domain_reliability::CLEAR_CONTEXTS; 130 using domain_reliability::CLEAR_CONTEXTS;
130 using domain_reliability::DomainReliabilityClearMode; 131 using domain_reliability::DomainReliabilityClearMode;
131 using domain_reliability::DomainReliabilityMonitor; 132 using domain_reliability::DomainReliabilityMonitor;
132 using domain_reliability::DomainReliabilityService; 133 using domain_reliability::DomainReliabilityService;
133 using domain_reliability::DomainReliabilityServiceFactory; 134 using domain_reliability::DomainReliabilityServiceFactory;
134 using testing::_; 135 using testing::_;
135 using testing::ByRef; 136 using testing::ByRef;
137 using testing::Eq;
136 using testing::Invoke; 138 using testing::Invoke;
137 using testing::IsEmpty; 139 using testing::IsEmpty;
138 using testing::Matcher; 140 using testing::Matcher;
139 using testing::MakeMatcher; 141 using testing::MakeMatcher;
140 using testing::MatcherInterface; 142 using testing::MatcherInterface;
141 using testing::MatchResultListener; 143 using testing::MatchResultListener;
142 using testing::Not; 144 using testing::Not;
143 using testing::Return; 145 using testing::Return;
146 using testing::SizeIs;
144 using testing::WithArgs; 147 using testing::WithArgs;
145 148
146 namespace { 149 namespace {
147 150
148 const char kTestOrigin1[] = "http://host1.com:1/"; 151 const char kTestOrigin1[] = "http://host1.com:1/";
149 const char kTestRegisterableDomain1[] = "host1.com"; 152 const char kTestRegisterableDomain1[] = "host1.com";
150 const char kTestOrigin2[] = "http://host2.com:1/"; 153 const char kTestOrigin2[] = "http://host2.com:1/";
151 const char kTestOrigin3[] = "http://host3.com:1/"; 154 const char kTestOrigin3[] = "http://host3.com:1/";
152 const char kTestRegisterableDomain3[] = "host3.com"; 155 const char kTestRegisterableDomain3[] = "host3.com";
153 const char kTestOrigin4[] = "https://host3.com:1/"; 156 const char kTestOrigin4[] = "https://host3.com:1/";
(...skipping 2915 matching lines...) Expand 10 before | Expand all | Expand 10 after
3069 // Test that the remover clears bookmark meta data (normally added in a tab 3072 // Test that the remover clears bookmark meta data (normally added in a tab
3070 // helper). 3073 // helper).
3071 TEST_F(BrowsingDataRemoverTest, BookmarkLastVisitDatesGetCleared) { 3074 TEST_F(BrowsingDataRemoverTest, BookmarkLastVisitDatesGetCleared) {
3072 TestingProfile profile; 3075 TestingProfile profile;
3073 profile.CreateBookmarkModel(true); 3076 profile.CreateBookmarkModel(true);
3074 3077
3075 bookmarks::BookmarkModel* bookmark_model = 3078 bookmarks::BookmarkModel* bookmark_model =
3076 BookmarkModelFactory::GetForBrowserContext(&profile); 3079 BookmarkModelFactory::GetForBrowserContext(&profile);
3077 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); 3080 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model);
3078 3081
3082 const base::Time delete_begin =
3083 base::Time::Now() - base::TimeDelta::FromDays(1);
3084 const base::Time delete_end = delete_begin + base::TimeDelta::FromDays(2);
msramek 2017/01/04 14:24:04 nit: This is unnecessary - we can use just base::T
tschumann 2017/01/04 15:08:44 Done.
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, delete_end),
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 }
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