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

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: Removed extra empty line 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
43 SetHistoryDeletionPref(true); 47 SetHistoryDeletionPref(true);
44 SetDeletionPeriodPref(browsing_data::EVERYTHING); 48 SetDeletionPeriodPref(browsing_data::EVERYTHING);
45 } 49 }
46 50
47 void AddVisit(const std::string url) { 51 void AddVisit(const std::string url) {
48 service_->AddPage(GURL(url), time_, history::SOURCE_BROWSED); 52 history_service_->AddPage(GURL(url), time_, history::SOURCE_BROWSED);
49 } 53 }
50 54
51 const base::Time& GetCurrentTime() { 55 const base::Time& GetCurrentTime() {
52 return time_; 56 return time_;
53 } 57 }
54 58
55 void RevertTimeInDays(int days) { 59 void RevertTimeInDays(int days) {
56 time_ -= base::TimeDelta::FromDays(days); 60 time_ -= base::TimeDelta::FromDays(days);
57 } 61 }
58 62
(...skipping 20 matching lines...) Expand all
79 bool HasSyncedVisits() { 83 bool HasSyncedVisits() {
80 DCHECK(finished_); 84 DCHECK(finished_);
81 return has_synced_visits_; 85 return has_synced_visits_;
82 } 86 }
83 87
84 void Callback( 88 void Callback(
85 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { 89 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) {
86 finished_ = result->Finished(); 90 finished_ = result->Finished();
87 91
88 if (finished_) { 92 if (finished_) {
89 HistoryCounter::HistoryResult* history_result = 93 browsing_data::HistoryCounter::HistoryResult* history_result =
90 static_cast<HistoryCounter::HistoryResult*>(result.get()); 94 static_cast<browsing_data::HistoryCounter::HistoryResult*>(
95 result.get());
91 96
92 local_result_ = history_result->Value(); 97 local_result_ = history_result->Value();
93 has_synced_visits_ = history_result->has_synced_visits(); 98 has_synced_visits_ = history_result->has_synced_visits();
94 } 99 }
95 100
96 if (run_loop_ && finished_) 101 if (run_loop_ && finished_)
97 run_loop_->Quit(); 102 run_loop_->Quit();
98 } 103 }
99 104
100 bool CountingFinishedSinceLastAsked() { 105 bool CountingFinishedSinceLastAsked() {
101 bool result = finished_; 106 bool result = finished_;
102 finished_ = false; 107 finished_ = false;
103 return result; 108 return result;
104 } 109 }
105 110
106 void WaitForCountingOrConfirmFinished() { 111 void WaitForCountingOrConfirmFinished() {
107 if (CountingFinishedSinceLastAsked()) 112 if (CountingFinishedSinceLastAsked())
108 return; 113 return;
109 114
110 WaitForCounting(); 115 WaitForCounting();
111 CountingFinishedSinceLastAsked(); 116 CountingFinishedSinceLastAsked();
112 } 117 }
113 118
119 history::WebHistoryService* GetWebHistoryService(Profile* profile) {
120 return WebHistoryServiceFactory::GetForProfile(profile);
121 }
122
123 history::HistoryService* GetHistoryService() { return history_service_; }
124
114 private: 125 private:
115 std::unique_ptr<base::RunLoop> run_loop_; 126 std::unique_ptr<base::RunLoop> run_loop_;
116 history::HistoryService* service_; 127 history::HistoryService* history_service_;
117 base::Time time_; 128 base::Time time_;
118 129
119 bool finished_; 130 bool finished_;
120 browsing_data::BrowsingDataCounter::ResultInt local_result_; 131 browsing_data::BrowsingDataCounter::ResultInt local_result_;
121 bool has_synced_visits_; 132 bool has_synced_visits_;
122 }; 133 };
123 134
124 // Tests that the counter considers duplicate visits from the same day 135 // Tests that the counter considers duplicate visits from the same day
125 // to be a single item. 136 // to be a single item.
126 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DuplicateVisits) { 137 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DuplicateVisits) {
(...skipping 13 matching lines...) Expand all
140 AddVisit("https://www.chrome.com"); // 6 items 151 AddVisit("https://www.chrome.com"); // 6 items
141 AddVisit("https://www.chrome.com"); 152 AddVisit("https://www.chrome.com");
142 AddVisit("https://www.google.com"); // 7 items 153 AddVisit("https://www.google.com"); // 7 items
143 AddVisit("https://www.chrome.com"); 154 AddVisit("https://www.chrome.com");
144 AddVisit("https://www.google.com"); 155 AddVisit("https://www.google.com");
145 AddVisit("https://www.google.com"); 156 AddVisit("https://www.google.com");
146 AddVisit("https://www.chrome.com"); 157 AddVisit("https://www.chrome.com");
147 158
148 Profile* profile = browser()->profile(); 159 Profile* profile = browser()->profile();
149 160
150 HistoryCounter counter(profile); 161 browsing_data::HistoryCounter counter(
162 GetHistoryService(),
163 base::Bind(&HistoryCounterTest::GetWebHistoryService,
164 base::Unretained(this), base::Unretained(profile)),
165 ProfileSyncServiceFactory::GetForProfile(profile));
166
151 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 167 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
152 base::Unretained(this))); 168 base::Unretained(this)));
153 counter.Restart(); 169 counter.Restart();
154 170
155 WaitForCounting(); 171 WaitForCounting();
156 EXPECT_EQ(7u, GetLocalResult()); 172 EXPECT_EQ(7u, GetLocalResult());
157 } 173 }
158 174
159 // Tests that the counter starts counting automatically when the deletion 175 // Tests that the counter starts counting automatically when the deletion
160 // pref changes to true. 176 // pref changes to true.
161 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) { 177 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) {
162 SetHistoryDeletionPref(false); 178 SetHistoryDeletionPref(false);
163 AddVisit("https://www.google.com"); 179 AddVisit("https://www.google.com");
164 AddVisit("https://www.chrome.com"); 180 AddVisit("https://www.chrome.com");
165 181
166 Profile* profile = browser()->profile(); 182 Profile* profile = browser()->profile();
167 183
168 HistoryCounter counter(profile); 184 browsing_data::HistoryCounter counter(
185 GetHistoryService(),
186 base::Bind(&HistoryCounterTest::GetWebHistoryService,
187 base::Unretained(this), base::Unretained(profile)),
188 ProfileSyncServiceFactory::GetForProfile(profile));
189
169 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 190 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
170 base::Unretained(this))); 191 base::Unretained(this)));
171 SetHistoryDeletionPref(true); 192 SetHistoryDeletionPref(true);
172 193
173 WaitForCounting(); 194 WaitForCounting();
174 EXPECT_EQ(2u, GetLocalResult()); 195 EXPECT_EQ(2u, GetLocalResult());
175 } 196 }
176 197
177 // Tests that the counter does not count history if the deletion 198 // Tests that the counter does not count history if the deletion
178 // preference is false. 199 // preference is false.
179 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefIsFalse) { 200 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefIsFalse) {
180 SetHistoryDeletionPref(false); 201 SetHistoryDeletionPref(false);
181 AddVisit("https://www.google.com"); 202 AddVisit("https://www.google.com");
182 203
183 Profile* profile = browser()->profile(); 204 Profile* profile = browser()->profile();
184 205
185 HistoryCounter counter(profile); 206 browsing_data::HistoryCounter counter(
207 GetHistoryService(),
208 base::Bind(&HistoryCounterTest::GetWebHistoryService,
209 base::Unretained(this), base::Unretained(profile)),
210 ProfileSyncServiceFactory::GetForProfile(profile));
211
186 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 212 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
187 base::Unretained(this))); 213 base::Unretained(this)));
188 counter.Restart(); 214 counter.Restart();
189 215
190 EXPECT_FALSE(counter.HasTrackedTasks()); 216 EXPECT_FALSE(counter.HasTrackedTasks());
191 } 217 }
192 218
193 // Tests that changing the deletion period restarts the counting, and that 219 // Tests that changing the deletion period restarts the counting, and that
194 // the result takes visit dates into account. 220 // the result takes visit dates into account.
195 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) { 221 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) {
(...skipping 13 matching lines...) Expand all
209 AddVisit("https://www.chrome.com"); 235 AddVisit("https://www.chrome.com");
210 AddVisit("https://www.example.com"); 236 AddVisit("https://www.example.com");
211 237
212 RevertTimeInDays(10); 238 RevertTimeInDays(10);
213 AddVisit("https://www.example.com"); 239 AddVisit("https://www.example.com");
214 AddVisit("https://www.example.com"); 240 AddVisit("https://www.example.com");
215 AddVisit("https://www.example.com"); 241 AddVisit("https://www.example.com");
216 242
217 Profile* profile = browser()->profile(); 243 Profile* profile = browser()->profile();
218 244
219 HistoryCounter counter(profile); 245 browsing_data::HistoryCounter counter(
246 GetHistoryService(),
247 base::Bind(&HistoryCounterTest::GetWebHistoryService,
248 base::Unretained(this), base::Unretained(profile)),
249 ProfileSyncServiceFactory::GetForProfile(profile));
250
220 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 251 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
221 base::Unretained(this))); 252 base::Unretained(this)));
222 253
223 SetDeletionPeriodPref(browsing_data::LAST_HOUR); 254 SetDeletionPeriodPref(browsing_data::LAST_HOUR);
224 WaitForCounting(); 255 WaitForCounting();
225 EXPECT_EQ(1u, GetLocalResult()); 256 EXPECT_EQ(1u, GetLocalResult());
226 257
227 SetDeletionPeriodPref(browsing_data::LAST_DAY); 258 SetDeletionPeriodPref(browsing_data::LAST_DAY);
228 WaitForCounting(); 259 WaitForCounting();
229 EXPECT_EQ(1u, GetLocalResult()); 260 EXPECT_EQ(1u, GetLocalResult());
(...skipping 10 matching lines...) Expand all
240 WaitForCounting(); 271 WaitForCounting();
241 EXPECT_EQ(9u, GetLocalResult()); 272 EXPECT_EQ(9u, GetLocalResult());
242 } 273 }
243 274
244 // Test the behavior for a profile that syncs history. 275 // Test the behavior for a profile that syncs history.
245 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) { 276 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) {
246 // WebHistoryService makes network requests, so we need to use a fake one 277 // WebHistoryService makes network requests, so we need to use a fake one
247 // for testing. 278 // for testing.
248 Profile* profile = browser()->profile(); 279 Profile* profile = browser()->profile();
249 280
250 std::unique_ptr<history::FakeWebHistoryService> service( 281 std::unique_ptr<history::FakeWebHistoryService> web_history_service(
251 new history::FakeWebHistoryService( 282 new history::FakeWebHistoryService(
252 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), 283 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
253 SigninManagerFactory::GetForProfile(profile), 284 SigninManagerFactory::GetForProfile(profile),
254 profile->GetRequestContext())); 285 profile->GetRequestContext()));
255 286
256 HistoryCounter counter(profile); 287 browsing_data::HistoryCounter counter(
257 counter.SetWebHistoryServiceForTesting(service.get()); 288 GetHistoryService(),
289 base::Bind(&HistoryCounterTest::GetWebHistoryService,
290 base::Unretained(this),
291 base::Unretained(profile)),
292 ProfileSyncServiceFactory::GetForProfile(profile));
293
294 counter.SetWebHistoryServiceForTesting(web_history_service.get());
258 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 295 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
259 base::Unretained(this))); 296 base::Unretained(this)));
260 297
261 // No entries locally and no entries in Sync. 298 // No entries locally and no entries in Sync.
262 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 299 web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
263 counter.Restart(); 300 counter.Restart();
264 WaitForCounting(); 301 WaitForCounting();
265 EXPECT_EQ(0u, GetLocalResult()); 302 EXPECT_EQ(0u, GetLocalResult());
266 EXPECT_FALSE(HasSyncedVisits()); 303 EXPECT_FALSE(HasSyncedVisits());
267 304
268 // No entries locally. There are some entries in Sync, but they are out of the 305 // No entries locally. There are some entries in Sync, but they are out of the
269 // time range. 306 // time range.
270 SetDeletionPeriodPref(browsing_data::LAST_HOUR); 307 SetDeletionPeriodPref(browsing_data::LAST_HOUR);
271 service->AddSyncedVisit( 308 web_history_service->AddSyncedVisit(
272 "www.google.com", GetCurrentTime() - base::TimeDelta::FromHours(2)); 309 "www.google.com", GetCurrentTime() - base::TimeDelta::FromHours(2));
273 service->AddSyncedVisit( 310 web_history_service->AddSyncedVisit(
274 "www.chrome.com", GetCurrentTime() - base::TimeDelta::FromHours(2)); 311 "www.chrome.com", GetCurrentTime() - base::TimeDelta::FromHours(2));
275 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 312 web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
276 counter.Restart(); 313 counter.Restart();
277 WaitForCounting(); 314 WaitForCounting();
278 EXPECT_EQ(0u, GetLocalResult()); 315 EXPECT_EQ(0u, GetLocalResult());
279 EXPECT_FALSE(HasSyncedVisits()); 316 EXPECT_FALSE(HasSyncedVisits());
280 317
281 // No entries locally, but some entries in Sync. 318 // No entries locally, but some entries in Sync.
282 service->AddSyncedVisit("www.google.com", GetCurrentTime()); 319 web_history_service->AddSyncedVisit("www.google.com", GetCurrentTime());
283 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 320 web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
284 counter.Restart(); 321 counter.Restart();
285 WaitForCounting(); 322 WaitForCounting();
286 EXPECT_EQ(0u, GetLocalResult()); 323 EXPECT_EQ(0u, GetLocalResult());
287 EXPECT_TRUE(HasSyncedVisits()); 324 EXPECT_TRUE(HasSyncedVisits());
288 325
289 // To err on the safe side, if the server request fails, we assume that there 326 // To err on the safe side, if the server request fails, we assume that there
290 // might be some items on the server. 327 // might be some items on the server.
291 service->SetupFakeResponse(true /* success */, 328 web_history_service->SetupFakeResponse(true /* success */,
292 net::HTTP_INTERNAL_SERVER_ERROR); 329 net::HTTP_INTERNAL_SERVER_ERROR);
293 counter.Restart(); 330 counter.Restart();
294 WaitForCounting(); 331 WaitForCounting();
295 EXPECT_EQ(0u, GetLocalResult()); 332 EXPECT_EQ(0u, GetLocalResult());
296 EXPECT_TRUE(HasSyncedVisits()); 333 EXPECT_TRUE(HasSyncedVisits());
297 334
298 // Same when the entire query fails. 335 // Same when the entire query fails.
299 service->SetupFakeResponse(false /* success */, 336 web_history_service->SetupFakeResponse(false /* success */,
300 net::HTTP_INTERNAL_SERVER_ERROR); 337 net::HTTP_INTERNAL_SERVER_ERROR);
301 counter.Restart(); 338 counter.Restart();
302 WaitForCounting(); 339 WaitForCounting();
303 EXPECT_EQ(0u, GetLocalResult()); 340 EXPECT_EQ(0u, GetLocalResult());
304 EXPECT_TRUE(HasSyncedVisits()); 341 EXPECT_TRUE(HasSyncedVisits());
305 342
306 // Nonzero local count, nonempty sync. 343 // Nonzero local count, nonempty sync.
307 AddVisit("https://www.google.com"); 344 AddVisit("https://www.google.com");
308 AddVisit("https://www.chrome.com"); 345 AddVisit("https://www.chrome.com");
309 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 346 web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
310 counter.Restart(); 347 counter.Restart();
311 WaitForCounting(); 348 WaitForCounting();
312 EXPECT_EQ(2u, GetLocalResult()); 349 EXPECT_EQ(2u, GetLocalResult());
313 EXPECT_TRUE(HasSyncedVisits()); 350 EXPECT_TRUE(HasSyncedVisits());
314 351
315 // Nonzero local count, empty sync. 352 // Nonzero local count, empty sync.
316 service->ClearSyncedVisits(); 353 web_history_service->ClearSyncedVisits();
317 service->SetupFakeResponse(true /* success */, net::HTTP_OK); 354 web_history_service->SetupFakeResponse(true /* success */, net::HTTP_OK);
318 counter.Restart(); 355 counter.Restart();
319 WaitForCounting(); 356 WaitForCounting();
320 EXPECT_EQ(2u, GetLocalResult()); 357 EXPECT_EQ(2u, GetLocalResult());
321 EXPECT_FALSE(HasSyncedVisits()); 358 EXPECT_FALSE(HasSyncedVisits());
322 } 359 }
323 360
324 // Test that the counting restarts when history sync state changes. 361 // Test that the counting restarts when history sync state changes.
325 // TODO(crbug.com/553421): Enable this test and move it to the 362 // TODO(crbug.com/553421): Enable this test and move it to the
326 // sync/test/integration directory. 363 // sync/test/integration directory.
327 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DISABLED_RestartOnSyncChange) { 364 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DISABLED_RestartOnSyncChange) {
328 // Set up the Sync client. 365 // Set up the Sync client.
329 ASSERT_TRUE(SetupClients()); 366 ASSERT_TRUE(SetupClients());
330 static const int kFirstProfileIndex = 0; 367 static const int kFirstProfileIndex = 0;
331 ProfileSyncService* sync_service = GetSyncService(kFirstProfileIndex); 368 ProfileSyncService* sync_service = GetSyncService(kFirstProfileIndex);
332 Profile* profile = GetProfile(kFirstProfileIndex); 369 Profile* profile = GetProfile(kFirstProfileIndex);
333 370
334 // Set up the fake web history service and the counter. 371 // Set up the fake web history service and the counter.
372
335 std::unique_ptr<history::FakeWebHistoryService> web_history_service( 373 std::unique_ptr<history::FakeWebHistoryService> web_history_service(
336 new history::FakeWebHistoryService( 374 new history::FakeWebHistoryService(
337 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()), 375 ProfileOAuth2TokenServiceFactory::GetForProfile(
338 SigninManagerFactory::GetForProfile(browser()->profile()), 376 browser()->profile()),
339 browser()->profile()->GetRequestContext())); 377 SigninManagerFactory::GetForProfile(browser()->profile()),
340 HistoryCounter counter(profile); 378 browser()->profile()->GetRequestContext()));
379
380 browsing_data::HistoryCounter counter(
381 GetHistoryService(),
382 base::Bind(&HistoryCounterTest::GetWebHistoryService,
383 base::Unretained(this),
384 base::Unretained(profile)),
385 sync_service);
386
341 counter.SetWebHistoryServiceForTesting(web_history_service.get()); 387 counter.SetWebHistoryServiceForTesting(web_history_service.get());
342 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, 388 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback,
343 base::Unretained(this))); 389 base::Unretained(this)));
344 390
345 // Note that some Sync operations notify observers immediately (and thus there 391 // 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), 392 // 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 393 // while other operations only post the task on UI thread's message loop
348 // (which requires calling |WaitForCounting()| for them to run). Therefore, 394 // (which requires calling |WaitForCounting()| for them to run). Therefore,
349 // this test always checks if the callback has already run and only waits 395 // this test always checks if the callback has already run and only waits
350 // if it has not. 396 // if it has not.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // history deletion did not change. However, in reality we can get two 440 // 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 441 // notifications, one that history sync has stopped and another that it is
396 // active again. 442 // active again.
397 443
398 // Stopping the Sync service triggers a restart. 444 // Stopping the Sync service triggers a restart.
399 sync_service->RequestStop(sync_driver::SyncService::CLEAR_DATA); 445 sync_service->RequestStop(sync_driver::SyncService::CLEAR_DATA);
400 WaitForCountingOrConfirmFinished(); 446 WaitForCountingOrConfirmFinished();
401 } 447 }
402 448
403 } // namespace 449 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698