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

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

Issue 2153863002: Move counters for passwords, history and autofill to components (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@separate_build_targets_in_components_bd
Patch Set: Fixed dependencies Created 4 years, 5 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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/history_counter.h" 5 #include "components/browsing_data/core/counters/history_counter.h"
6 6
7 #include "base/bind.h"
8 #include "base/bind_helpers.h"
7 #include "base/run_loop.h" 9 #include "base/run_loop.h"
8 #include "chrome/browser/history/history_service_factory.h" 10 #include "chrome/browser/history/history_service_factory.h"
9 #include "chrome/browser/history/web_history_service_factory.h" 11 #include "chrome/browser/history/web_history_service_factory.h"
10 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 12 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
11 #include "chrome/browser/signin/signin_manager_factory.h" 13 #include "chrome/browser/signin/signin_manager_factory.h"
14 #include "chrome/browser/sync/profile_sync_service_factory.h"
12 #include "chrome/browser/sync/test/integration/sync_test.h" 15 #include "chrome/browser/sync/test/integration/sync_test.h"
13 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
14 #include "components/browser_sync/browser/profile_sync_service.h" 17 #include "components/browser_sync/browser/profile_sync_service.h"
15 #include "components/browsing_data/core/browsing_data_utils.h" 18 #include "components/browsing_data/core/browsing_data_utils.h"
16 #include "components/browsing_data/core/pref_names.h" 19 #include "components/browsing_data/core/pref_names.h"
17 #include "components/history/core/browser/history_service.h" 20 #include "components/history/core/browser/history_service.h"
18 #include "components/history/core/browser/web_history_service.h" 21 #include "components/history/core/browser/web_history_service.h"
19 #include "components/history/core/test/fake_web_history_service.h" 22 #include "components/history/core/test/fake_web_history_service.h"
20 #include "components/prefs/pref_service.h" 23 #include "components/prefs/pref_service.h"
21 #include "components/signin/core/browser/profile_oauth2_token_service.h" 24 #include "components/signin/core/browser/profile_oauth2_token_service.h"
22 #include "components/signin/core/browser/signin_manager.h" 25 #include "components/signin/core/browser/signin_manager.h"
23 #include "net/http/http_status_code.h" 26 #include "net/http/http_status_code.h"
24 #include "url/gurl.h" 27 #include "url/gurl.h"
25 28
26 namespace { 29 namespace {
27 30
28 class HistoryCounterTest : public SyncTest { 31 class HistoryCounterTest : public SyncTest {
29 public: 32 public:
30 HistoryCounterTest() : SyncTest(SINGLE_CLIENT) { 33 HistoryCounterTest() : SyncTest(SINGLE_CLIENT) {
31 // TODO(msramek): Only one of the test cases, RestartOnSyncChange, is a Sync 34 // TODO(msramek): Only one of the test cases, RestartOnSyncChange, is a Sync
32 // integration test. Extract it and move it to the rest of integration tests 35 // integration test. Extract it and move it to the rest of integration tests
33 // in chrome/browser/sync/test/integration/. Change this class back to 36 // in chrome/browser/sync/test/integration/. Change this class back to
34 // InProcessBrowserTest. 37 // InProcessBrowserTest.
35 } 38 }
36 39
37 ~HistoryCounterTest() override {}; 40 ~HistoryCounterTest() override {};
38 41
39 void SetUpOnMainThread() override { 42 void SetUpOnMainThread() override {
40 time_ = base::Time::Now(); 43 time_ = base::Time::Now();
41 service_ = HistoryServiceFactory::GetForProfileWithoutCreating( 44 history_service_ = HistoryServiceFactory::GetForProfileWithoutCreating(
42 browser()->profile()); 45 browser()->profile());
46 fake_web_history_service_.reset(new history::FakeWebHistoryService(
47 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()),
48 SigninManagerFactory::GetForProfile(browser()->profile()),
49 browser()->profile()->GetRequestContext()));
50
43 SetHistoryDeletionPref(true); 51 SetHistoryDeletionPref(true);
44 SetDeletionPeriodPref(browsing_data::EVERYTHING); 52 SetDeletionPeriodPref(browsing_data::EVERYTHING);
45 } 53 }
46 54
47 void AddVisit(const std::string url) { 55 void AddVisit(const std::string url) {
48 service_->AddPage(GURL(url), time_, history::SOURCE_BROWSED); 56 history_service_->AddPage(GURL(url), time_, history::SOURCE_BROWSED);
49 } 57 }
50 58
51 const base::Time& GetCurrentTime() { 59 const base::Time& GetCurrentTime() {
52 return time_; 60 return time_;
53 } 61 }
54 62
55 void RevertTimeInDays(int days) { 63 void RevertTimeInDays(int days) {
56 time_ -= base::TimeDelta::FromDays(days); 64 time_ -= base::TimeDelta::FromDays(days);
57 } 65 }
58 66
(...skipping 20 matching lines...) Expand all
79 bool HasSyncedVisits() { 87 bool HasSyncedVisits() {
80 DCHECK(finished_); 88 DCHECK(finished_);
81 return has_synced_visits_; 89 return has_synced_visits_;
82 } 90 }
83 91
84 void Callback( 92 void Callback(
85 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { 93 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
86 finished_ = result->Finished(); 94 finished_ = result->Finished();
87 95
88 if (finished_) { 96 if (finished_) {
89 HistoryCounter::HistoryResult* history_result = 97 browsing_data::HistoryCounter::HistoryResult* history_result =
90 static_cast<HistoryCounter::HistoryResult*>(result.get()); 98 static_cast<browsing_data::HistoryCounter::HistoryResult*>(
99 result.get());
91 100
92 local_result_ = history_result->Value(); 101 local_result_ = history_result->Value();
93 has_synced_visits_ = history_result->has_synced_visits(); 102 has_synced_visits_ = history_result->has_synced_visits();
94 } 103 }
95 104
96 if (run_loop_ && finished_) 105 if (run_loop_ && finished_)
97 run_loop_->Quit(); 106 run_loop_->Quit();
98 } 107 }
99 108
100 bool CountingFinishedSinceLastAsked() { 109 bool CountingFinishedSinceLastAsked() {
101 bool result = finished_; 110 bool result = finished_;
102 finished_ = false; 111 finished_ = false;
103 return result; 112 return result;
104 } 113 }
105 114
106 void WaitForCountingOrConfirmFinished() { 115 void WaitForCountingOrConfirmFinished() {
107 if (CountingFinishedSinceLastAsked()) 116 if (CountingFinishedSinceLastAsked())
108 return; 117 return;
109 118
110 WaitForCounting(); 119 WaitForCounting();
111 CountingFinishedSinceLastAsked(); 120 CountingFinishedSinceLastAsked();
112 } 121 }
113 122
123 history::WebHistoryService* GetFakeWebHistoryService() {
124 return fake_web_history_service_.get();
125 }
126
127 history::WebHistoryService* GetRealWebHistoryService(Profile* profile) {
128 return WebHistoryServiceFactory::GetForProfile(profile);
129 }
130
131 history::HistoryService* GetHistoryService() { return history_service_; }
132
114 private: 133 private:
115 std::unique_ptr<base::RunLoop> run_loop_; 134 std::unique_ptr<base::RunLoop> run_loop_;
116 history::HistoryService* service_; 135 history::HistoryService* history_service_;
136 std::unique_ptr<history::FakeWebHistoryService> fake_web_history_service_;
117 base::Time time_; 137 base::Time time_;
118 138
119 bool finished_; 139 bool finished_;
120 browsing_data::BrowsingDataCounter::ResultInt local_result_; 140 browsing_data::BrowsingDataCounter::ResultInt local_result_;
121 bool has_synced_visits_; 141 bool has_synced_visits_;
122 }; 142 };
123 143
124 // Tests that the counter considers duplicate visits from the same day 144 // Tests that the counter considers duplicate visits from the same day
125 // to be a single item. 145 // to be a single item.
126 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DuplicateVisits) { 146 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DuplicateVisits) {
(...skipping 13 matching lines...) Expand all
140 AddVisit("https://www.chrome.com"); // 6 items 160 AddVisit("https://www.chrome.com"); // 6 items
141 AddVisit("https://www.chrome.com"); 161 AddVisit("https://www.chrome.com");
142 AddVisit("https://www.google.com"); // 7 items 162 AddVisit("https://www.google.com"); // 7 items
143 AddVisit("https://www.chrome.com"); 163 AddVisit("https://www.chrome.com");
144 AddVisit("https://www.google.com"); 164 AddVisit("https://www.google.com");
145 AddVisit("https://www.google.com"); 165 AddVisit("https://www.google.com");
146 AddVisit("https://www.chrome.com"); 166 AddVisit("https://www.chrome.com");
147 167
148 Profile* profile = browser()->profile(); 168 Profile* profile = browser()->profile();
149 169
150 HistoryCounter counter(profile); 170 browsing_data::HistoryCounter counter(
171 ProfileSyncServiceFactory::GetForProfile(profile),
172 base::Bind(&HistoryCounterTest::GetRealWebHistoryService,
173 base::Unretained(this), base::Unretained(profile)),
174 GetHistoryService());
175
151 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 176 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
152 base::Unretained(this))); 177 base::Unretained(this)));
153 counter.Restart(); 178 counter.Restart();
154 179
155 WaitForCounting(); 180 WaitForCounting();
156 EXPECT_EQ(7u, GetLocalResult()); 181 EXPECT_EQ(7u, GetLocalResult());
157 } 182 }
158 183
159 // Tests that the counter starts counting automatically when the deletion 184 // Tests that the counter starts counting automatically when the deletion
160 // pref changes to true. 185 // pref changes to true.
161 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) { 186 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) {
162 SetHistoryDeletionPref(false); 187 SetHistoryDeletionPref(false);
163 AddVisit("https://www.google.com"); 188 AddVisit("https://www.google.com");
164 AddVisit("https://www.chrome.com"); 189 AddVisit("https://www.chrome.com");
165 190
166 Profile* profile = browser()->profile(); 191 Profile* profile = browser()->profile();
167 192
168 HistoryCounter counter(profile); 193 browsing_data::HistoryCounter counter(
194 ProfileSyncServiceFactory::GetForProfile(profile),
195 base::Bind(&HistoryCounterTest::GetRealWebHistoryService,
196 base::Unretained(this), base::Unretained(profile)),
197 GetHistoryService());
198
169 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 199 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
170 base::Unretained(this))); 200 base::Unretained(this)));
171 SetHistoryDeletionPref(true); 201 SetHistoryDeletionPref(true);
172 202
173 WaitForCounting(); 203 WaitForCounting();
174 EXPECT_EQ(2u, GetLocalResult()); 204 EXPECT_EQ(2u, GetLocalResult());
175 } 205 }
176 206
177 // Tests that the counter does not count history if the deletion 207 // Tests that the counter does not count history if the deletion
178 // preference is false. 208 // preference is false.
179 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefIsFalse) { 209 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefIsFalse) {
180 SetHistoryDeletionPref(false); 210 SetHistoryDeletionPref(false);
181 AddVisit("https://www.google.com"); 211 AddVisit("https://www.google.com");
182 212
183 Profile* profile = browser()->profile(); 213 Profile* profile = browser()->profile();
184 214
185 HistoryCounter counter(profile); 215 browsing_data::HistoryCounter counter(
216 ProfileSyncServiceFactory::GetForProfile(profile),
217 base::Bind(&HistoryCounterTest::GetRealWebHistoryService,
218 base::Unretained(this), base::Unretained(profile)),
219 GetHistoryService());
220
186 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 221 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
187 base::Unretained(this))); 222 base::Unretained(this)));
188 counter.Restart(); 223 counter.Restart();
189 224
190 EXPECT_FALSE(counter.HasTrackedTasks()); 225 EXPECT_FALSE(counter.HasTrackedTasks());
191 } 226 }
192 227
193 // Tests that changing the deletion period restarts the counting, and that 228 // Tests that changing the deletion period restarts the counting, and that
194 // the result takes visit dates into account. 229 // the result takes visit dates into account.
195 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) { 230 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) {
(...skipping 13 matching lines...) Expand all
209 AddVisit("https://www.chrome.com"); 244 AddVisit("https://www.chrome.com");
210 AddVisit("https://www.example.com"); 245 AddVisit("https://www.example.com");
211 246
212 RevertTimeInDays(10); 247 RevertTimeInDays(10);
213 AddVisit("https://www.example.com"); 248 AddVisit("https://www.example.com");
214 AddVisit("https://www.example.com"); 249 AddVisit("https://www.example.com");
215 AddVisit("https://www.example.com"); 250 AddVisit("https://www.example.com");
216 251
217 Profile* profile = browser()->profile(); 252 Profile* profile = browser()->profile();
218 253
219 HistoryCounter counter(profile); 254 browsing_data::HistoryCounter counter(
255 ProfileSyncServiceFactory::GetForProfile(profile),
256 base::Bind(&HistoryCounterTest::GetRealWebHistoryService,
257 base::Unretained(this), base::Unretained(profile)),
258 GetHistoryService());
259
220 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 260 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
221 base::Unretained(this))); 261 base::Unretained(this)));
222 262
223 SetDeletionPeriodPref(browsing_data::LAST_HOUR); 263 SetDeletionPeriodPref(browsing_data::LAST_HOUR);
224 WaitForCounting(); 264 WaitForCounting();
225 EXPECT_EQ(1u, GetLocalResult()); 265 EXPECT_EQ(1u, GetLocalResult());
226 266
227 SetDeletionPeriodPref(browsing_data::LAST_DAY); 267 SetDeletionPeriodPref(browsing_data::LAST_DAY);
228 WaitForCounting(); 268 WaitForCounting();
229 EXPECT_EQ(1u, GetLocalResult()); 269 EXPECT_EQ(1u, GetLocalResult());
(...skipping 10 matching lines...) Expand all
240 WaitForCounting(); 280 WaitForCounting();
241 EXPECT_EQ(9u, GetLocalResult()); 281 EXPECT_EQ(9u, GetLocalResult());
242 } 282 }
243 283
244 // Test the behavior for a profile that syncs history. 284 // Test the behavior for a profile that syncs history.
245 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) { 285 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) {
246 // WebHistoryService makes network requests, so we need to use a fake one 286 // WebHistoryService makes network requests, so we need to use a fake one
247 // for testing. 287 // for testing.
248 Profile* profile = browser()->profile(); 288 Profile* profile = browser()->profile();
249 289
250 std::unique_ptr<history::FakeWebHistoryService> service( 290 browsing_data::HistoryCounter counter(
251 new history::FakeWebHistoryService( 291 ProfileSyncServiceFactory::GetForProfile(profile),
252 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), 292 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService,
253 SigninManagerFactory::GetForProfile(profile), 293 base::Unretained(this)),
254 profile->GetRequestContext())); 294 GetHistoryService());
255 295
256 HistoryCounter counter(profile);
257 counter.SetWebHistoryServiceForTesting(service.get());
258 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 296 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
259 base::Unretained(this))); 297 base::Unretained(this)));
260 298
299 history::FakeWebHistoryService* fake_web_history_service =
300 static_cast<history::FakeWebHistoryService*>(GetFakeWebHistoryService());
301
261 // No entries locally and no entries in Sync. 302 // No entries locally and no entries in Sync.
262 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 303 fake_web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
msramek 2016/07/20 13:41:16 This renaming seems very unnecessary.
ioanap 2016/07/20 17:50:36 Is web_history_service okay?
msramek 2016/07/20 18:26:12 Hm. This seems to be a misunderstanding. What I m
ioanap 2016/07/21 11:47:36 Changed it back to |service|. The reason I took o
msramek 2016/07/21 12:17:11 I see it now. Yes, that bypass is a bit weird. One
263 counter.Restart(); 304 counter.Restart();
264 WaitForCounting(); 305 WaitForCounting();
265 EXPECT_EQ(0u, GetLocalResult()); 306 EXPECT_EQ(0u, GetLocalResult());
266 EXPECT_FALSE(HasSyncedVisits()); 307 EXPECT_FALSE(HasSyncedVisits());
267 308
268 // No entries locally. There are some entries in Sync, but they are out of the 309 // No entries locally. There are some entries in Sync, but they are out of the
269 // time range. 310 // time range.
270 SetDeletionPeriodPref(browsing_data::LAST_HOUR); 311 SetDeletionPeriodPref(browsing_data::LAST_HOUR);
271 service->AddSyncedVisit( 312 fake_web_history_service->AddSyncedVisit(
272 "www.google.com", GetCurrentTime() - base::TimeDelta::FromHours(2)); 313 "www.google.com", GetCurrentTime() - base::TimeDelta::FromHours(2));
273 service->AddSyncedVisit( 314 fake_web_history_service->AddSyncedVisit(
274 "www.chrome.com", GetCurrentTime() - base::TimeDelta::FromHours(2)); 315 "www.chrome.com", GetCurrentTime() - base::TimeDelta::FromHours(2));
275 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 316 fake_web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
276 counter.Restart(); 317 counter.Restart();
277 WaitForCounting(); 318 WaitForCounting();
278 EXPECT_EQ(0u, GetLocalResult()); 319 EXPECT_EQ(0u, GetLocalResult());
279 EXPECT_FALSE(HasSyncedVisits()); 320 EXPECT_FALSE(HasSyncedVisits());
280 321
281 // No entries locally, but some entries in Sync. 322 // No entries locally, but some entries in Sync.
282 service->AddSyncedVisit("www.google.com", GetCurrentTime()); 323 fake_web_history_service->AddSyncedVisit("www.google.com", GetCurrentTime());
283 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 324 fake_web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
284 counter.Restart(); 325 counter.Restart();
285 WaitForCounting(); 326 WaitForCounting();
286 EXPECT_EQ(0u, GetLocalResult()); 327 EXPECT_EQ(0u, GetLocalResult());
287 EXPECT_TRUE(HasSyncedVisits()); 328 EXPECT_TRUE(HasSyncedVisits());
288 329
289 // To err on the safe side, if the server request fails, we assume that there 330 // To err on the safe side, if the server request fails, we assume that there
290 // might be some items on the server. 331 // might be some items on the server.
291 service->SetupFakeResponse(true /* success */, 332 fake_web_history_service->SetupFakeResponse(true /* success */,
292 net::HTTP_INTERNAL_SERVER_ERROR); 333 net::HTTP_INTERNAL_SERVER_ERROR);
293 counter.Restart(); 334 counter.Restart();
294 WaitForCounting(); 335 WaitForCounting();
295 EXPECT_EQ(0u, GetLocalResult()); 336 EXPECT_EQ(0u, GetLocalResult());
296 EXPECT_TRUE(HasSyncedVisits()); 337 EXPECT_TRUE(HasSyncedVisits());
297 338
298 // Same when the entire query fails. 339 // Same when the entire query fails.
299 service->SetupFakeResponse(false /* success */, 340 fake_web_history_service->SetupFakeResponse(false /* success */,
300 net::HTTP_INTERNAL_SERVER_ERROR); 341 net::HTTP_INTERNAL_SERVER_ERROR);
301 counter.Restart(); 342 counter.Restart();
302 WaitForCounting(); 343 WaitForCounting();
303 EXPECT_EQ(0u, GetLocalResult()); 344 EXPECT_EQ(0u, GetLocalResult());
304 EXPECT_TRUE(HasSyncedVisits()); 345 EXPECT_TRUE(HasSyncedVisits());
305 346
306 // Nonzero local count, nonempty sync. 347 // Nonzero local count, nonempty sync.
307 AddVisit("https://www.google.com"); 348 AddVisit("https://www.google.com");
308 AddVisit("https://www.chrome.com"); 349 AddVisit("https://www.chrome.com");
309 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 350 fake_web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
310 counter.Restart(); 351 counter.Restart();
311 WaitForCounting(); 352 WaitForCounting();
312 EXPECT_EQ(2u, GetLocalResult()); 353 EXPECT_EQ(2u, GetLocalResult());
313 EXPECT_TRUE(HasSyncedVisits()); 354 EXPECT_TRUE(HasSyncedVisits());
314 355
315 // Nonzero local count, empty sync. 356 // Nonzero local count, empty sync.
316 service->ClearSyncedVisits(); 357 fake_web_history_service->ClearSyncedVisits();
317 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 358 fake_web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
318 counter.Restart(); 359 counter.Restart();
319 WaitForCounting(); 360 WaitForCounting();
320 EXPECT_EQ(2u, GetLocalResult()); 361 EXPECT_EQ(2u, GetLocalResult());
321 EXPECT_FALSE(HasSyncedVisits()); 362 EXPECT_FALSE(HasSyncedVisits());
322 } 363 }
323 364
324 // Test that the counting restarts when history sync state changes. 365 // Test that the counting restarts when history sync state changes.
325 // TODO(crbug.com/553421): Enable this test and move it to the 366 // TODO(crbug.com/553421): Enable this test and move it to the
326 // sync/test/integration directory. 367 // sync/test/integration directory.
327 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DISABLED_RestartOnSyncChange) { 368 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DISABLED_RestartOnSyncChange) {
328 // Set up the Sync client. 369 // Set up the Sync client.
329 ASSERT_TRUE(SetupClients()); 370 ASSERT_TRUE(SetupClients());
330 static const int kFirstProfileIndex = 0; 371 static const int kFirstProfileIndex = 0;
331 ProfileSyncService* sync_service = GetSyncService(kFirstProfileIndex); 372 ProfileSyncService* sync_service = GetSyncService(kFirstProfileIndex);
332 Profile* profile = GetProfile(kFirstProfileIndex); 373 Profile* profile = GetProfile(kFirstProfileIndex);
333 374
334 // Set up the fake web history service and the counter. 375 // Set up the fake web history service and the counter.
335 std::unique_ptr<history::FakeWebHistoryService> web_history_service( 376
336 new history::FakeWebHistoryService( 377 browsing_data::HistoryCounter counter(
337 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()), 378 sync_service, base::Bind(&HistoryCounterTest::GetFakeWebHistoryService,
338 SigninManagerFactory::GetForProfile(browser()->profile()), 379 base::Unretained(this)),
339 browser()->profile()->GetRequestContext())); 380 GetHistoryService());
340 HistoryCounter counter(profile); 381
341 counter.SetWebHistoryServiceForTesting(web_history_service.get());
342 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 382 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
343 base::Unretained(this))); 383 base::Unretained(this)));
344 384
345 // Note that some Sync operations notify observers immediately (and thus there 385 // Note that some Sync operations notify observers immediately (and thus there
346 // is no need to call |WaitForCounting()|; in fact, it would block the test), 386 // is no need to call |WaitForCounting()|; in fact, it would block the test),
347 // while other operations only post the task on UI thread's message loop 387 // while other operations only post the task on UI thread's message loop
348 // (which requires calling |WaitForCounting()| for them to run). Therefore, 388 // (which requires calling |WaitForCounting()| for them to run). Therefore,
349 // this test always checks if the callback has already run and only waits 389 // this test always checks if the callback has already run and only waits
350 // if it has not. 390 // if it has not.
351 391
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // history deletion did not change. However, in reality we can get two 434 // history deletion did not change. However, in reality we can get two
395 // notifications, one that history sync has stopped and another that it is 435 // notifications, one that history sync has stopped and another that it is
396 // active again. 436 // active again.
397 437
398 // Stopping the Sync service triggers a restart. 438 // Stopping the Sync service triggers a restart.
399 sync_service->RequestStop(sync_driver::SyncService::CLEAR_DATA); 439 sync_service->RequestStop(sync_driver::SyncService::CLEAR_DATA);
400 WaitForCountingOrConfirmFinished(); 440 WaitForCountingOrConfirmFinished();
401 } 441 }
402 442
403 } // namespace 443 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698