OLD | NEW |
---|---|
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 Loading... | |
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(Profile* profile, | |
124 bool check_sync_status) { | |
msramek
2016/07/21 12:17:11
nit: alignment
ioanap
2016/07/21 13:27:14
Done.
| |
125 // |check_sync_status| is true when the factory should check if | |
126 // history sync is enabled. | |
127 if (!check_sync_status | |
128 || WebHistoryServiceFactory::GetForProfile(profile)) { | |
msramek
2016/07/21 12:17:11
style nit: operator || on the previous line
ioanap
2016/07/21 13:27:14
Done.
| |
129 return fake_web_history_service_.get(); | |
130 } | |
131 return nullptr; | |
132 } | |
133 | |
134 history::WebHistoryService* GetRealWebHistoryService(Profile* profile) { | |
135 return WebHistoryServiceFactory::GetForProfile(profile); | |
136 } | |
137 | |
138 history::HistoryService* GetHistoryService() { return history_service_; } | |
139 | |
114 private: | 140 private: |
115 std::unique_ptr<base::RunLoop> run_loop_; | 141 std::unique_ptr<base::RunLoop> run_loop_; |
116 history::HistoryService* service_; | 142 history::HistoryService* history_service_; |
143 std::unique_ptr<history::FakeWebHistoryService> fake_web_history_service_; | |
117 base::Time time_; | 144 base::Time time_; |
118 | 145 |
119 bool finished_; | 146 bool finished_; |
120 browsing_data::BrowsingDataCounter::ResultInt local_result_; | 147 browsing_data::BrowsingDataCounter::ResultInt local_result_; |
121 bool has_synced_visits_; | 148 bool has_synced_visits_; |
122 }; | 149 }; |
123 | 150 |
124 // Tests that the counter considers duplicate visits from the same day | 151 // Tests that the counter considers duplicate visits from the same day |
125 // to be a single item. | 152 // to be a single item. |
126 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DuplicateVisits) { | 153 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DuplicateVisits) { |
(...skipping 13 matching lines...) Expand all Loading... | |
140 AddVisit("https://www.chrome.com"); // 6 items | 167 AddVisit("https://www.chrome.com"); // 6 items |
141 AddVisit("https://www.chrome.com"); | 168 AddVisit("https://www.chrome.com"); |
142 AddVisit("https://www.google.com"); // 7 items | 169 AddVisit("https://www.google.com"); // 7 items |
143 AddVisit("https://www.chrome.com"); | 170 AddVisit("https://www.chrome.com"); |
144 AddVisit("https://www.google.com"); | 171 AddVisit("https://www.google.com"); |
145 AddVisit("https://www.google.com"); | 172 AddVisit("https://www.google.com"); |
146 AddVisit("https://www.chrome.com"); | 173 AddVisit("https://www.chrome.com"); |
147 | 174 |
148 Profile* profile = browser()->profile(); | 175 Profile* profile = browser()->profile(); |
149 | 176 |
150 HistoryCounter counter(profile); | 177 browsing_data::HistoryCounter counter( |
178 GetHistoryService(), | |
179 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, | |
180 base::Unretained(this), | |
181 base::Unretained(profile)), | |
182 ProfileSyncServiceFactory::GetForProfile(profile)); | |
183 | |
151 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 184 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
152 base::Unretained(this))); | 185 base::Unretained(this))); |
153 counter.Restart(); | 186 counter.Restart(); |
154 | 187 |
155 WaitForCounting(); | 188 WaitForCounting(); |
156 EXPECT_EQ(7u, GetLocalResult()); | 189 EXPECT_EQ(7u, GetLocalResult()); |
157 } | 190 } |
158 | 191 |
159 // Tests that the counter starts counting automatically when the deletion | 192 // Tests that the counter starts counting automatically when the deletion |
160 // pref changes to true. | 193 // pref changes to true. |
161 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) { | 194 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) { |
162 SetHistoryDeletionPref(false); | 195 SetHistoryDeletionPref(false); |
163 AddVisit("https://www.google.com"); | 196 AddVisit("https://www.google.com"); |
164 AddVisit("https://www.chrome.com"); | 197 AddVisit("https://www.chrome.com"); |
165 | 198 |
166 Profile* profile = browser()->profile(); | 199 Profile* profile = browser()->profile(); |
167 | 200 |
168 HistoryCounter counter(profile); | 201 browsing_data::HistoryCounter counter( |
202 GetHistoryService(), | |
203 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, | |
204 base::Unretained(this), | |
205 base::Unretained(profile)), | |
206 ProfileSyncServiceFactory::GetForProfile(profile)); | |
207 | |
169 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 208 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
170 base::Unretained(this))); | 209 base::Unretained(this))); |
171 SetHistoryDeletionPref(true); | 210 SetHistoryDeletionPref(true); |
172 | 211 |
173 WaitForCounting(); | 212 WaitForCounting(); |
174 EXPECT_EQ(2u, GetLocalResult()); | 213 EXPECT_EQ(2u, GetLocalResult()); |
175 } | 214 } |
176 | 215 |
177 // Tests that the counter does not count history if the deletion | 216 // Tests that the counter does not count history if the deletion |
178 // preference is false. | 217 // preference is false. |
179 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefIsFalse) { | 218 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefIsFalse) { |
180 SetHistoryDeletionPref(false); | 219 SetHistoryDeletionPref(false); |
181 AddVisit("https://www.google.com"); | 220 AddVisit("https://www.google.com"); |
182 | 221 |
183 Profile* profile = browser()->profile(); | 222 Profile* profile = browser()->profile(); |
184 | 223 |
185 HistoryCounter counter(profile); | 224 browsing_data::HistoryCounter counter( |
225 GetHistoryService(), | |
226 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, | |
227 base::Unretained(this), | |
228 base::Unretained(profile)), | |
229 ProfileSyncServiceFactory::GetForProfile(profile)); | |
230 | |
186 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 231 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
187 base::Unretained(this))); | 232 base::Unretained(this))); |
188 counter.Restart(); | 233 counter.Restart(); |
189 | 234 |
190 EXPECT_FALSE(counter.HasTrackedTasks()); | 235 EXPECT_FALSE(counter.HasTrackedTasks()); |
191 } | 236 } |
192 | 237 |
193 // Tests that changing the deletion period restarts the counting, and that | 238 // Tests that changing the deletion period restarts the counting, and that |
194 // the result takes visit dates into account. | 239 // the result takes visit dates into account. |
195 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) { | 240 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) { |
(...skipping 13 matching lines...) Expand all Loading... | |
209 AddVisit("https://www.chrome.com"); | 254 AddVisit("https://www.chrome.com"); |
210 AddVisit("https://www.example.com"); | 255 AddVisit("https://www.example.com"); |
211 | 256 |
212 RevertTimeInDays(10); | 257 RevertTimeInDays(10); |
213 AddVisit("https://www.example.com"); | 258 AddVisit("https://www.example.com"); |
214 AddVisit("https://www.example.com"); | 259 AddVisit("https://www.example.com"); |
215 AddVisit("https://www.example.com"); | 260 AddVisit("https://www.example.com"); |
216 | 261 |
217 Profile* profile = browser()->profile(); | 262 Profile* profile = browser()->profile(); |
218 | 263 |
219 HistoryCounter counter(profile); | 264 browsing_data::HistoryCounter counter( |
265 GetHistoryService(), | |
266 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, | |
267 base::Unretained(this), | |
268 base::Unretained(profile)), | |
269 ProfileSyncServiceFactory::GetForProfile(profile)); | |
270 | |
220 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 271 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
221 base::Unretained(this))); | 272 base::Unretained(this))); |
222 | 273 |
223 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 274 SetDeletionPeriodPref(browsing_data::LAST_HOUR); |
224 WaitForCounting(); | 275 WaitForCounting(); |
225 EXPECT_EQ(1u, GetLocalResult()); | 276 EXPECT_EQ(1u, GetLocalResult()); |
226 | 277 |
227 SetDeletionPeriodPref(browsing_data::LAST_DAY); | 278 SetDeletionPeriodPref(browsing_data::LAST_DAY); |
228 WaitForCounting(); | 279 WaitForCounting(); |
229 EXPECT_EQ(1u, GetLocalResult()); | 280 EXPECT_EQ(1u, GetLocalResult()); |
(...skipping 10 matching lines...) Expand all Loading... | |
240 WaitForCounting(); | 291 WaitForCounting(); |
241 EXPECT_EQ(9u, GetLocalResult()); | 292 EXPECT_EQ(9u, GetLocalResult()); |
242 } | 293 } |
243 | 294 |
244 // Test the behavior for a profile that syncs history. | 295 // Test the behavior for a profile that syncs history. |
245 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) { | 296 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, Synced) { |
246 // WebHistoryService makes network requests, so we need to use a fake one | 297 // WebHistoryService makes network requests, so we need to use a fake one |
247 // for testing. | 298 // for testing. |
248 Profile* profile = browser()->profile(); | 299 Profile* profile = browser()->profile(); |
249 | 300 |
250 std::unique_ptr<history::FakeWebHistoryService> service( | 301 browsing_data::HistoryCounter counter( |
251 new history::FakeWebHistoryService( | 302 GetHistoryService(), |
252 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 303 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService, |
253 SigninManagerFactory::GetForProfile(profile), | 304 base::Unretained(this), |
254 profile->GetRequestContext())); | 305 base::Unretained(profile), |
306 false), | |
307 ProfileSyncServiceFactory::GetForProfile(profile)); | |
255 | 308 |
256 HistoryCounter counter(profile); | |
257 counter.SetWebHistoryServiceForTesting(service.get()); | |
258 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 309 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
259 base::Unretained(this))); | 310 base::Unretained(this))); |
260 | 311 |
312 history::FakeWebHistoryService* service = | |
313 static_cast<history::FakeWebHistoryService*>(GetFakeWebHistoryService( | |
314 profile, false)); | |
315 | |
261 // No entries locally and no entries in Sync. | 316 // No entries locally and no entries in Sync. |
262 service->SetupFakeResponse(true /* success */, net::HTTP_OK); | 317 service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
263 counter.Restart(); | 318 counter.Restart(); |
264 WaitForCounting(); | 319 WaitForCounting(); |
265 EXPECT_EQ(0u, GetLocalResult()); | 320 EXPECT_EQ(0u, GetLocalResult()); |
266 EXPECT_FALSE(HasSyncedVisits()); | 321 EXPECT_FALSE(HasSyncedVisits()); |
267 | 322 |
268 // No entries locally. There are some entries in Sync, but they are out of the | 323 // No entries locally. There are some entries in Sync, but they are out of the |
269 // time range. | 324 // time range. |
270 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 325 SetDeletionPeriodPref(browsing_data::LAST_HOUR); |
(...skipping 11 matching lines...) Expand all Loading... | |
282 service->AddSyncedVisit("www.google.com", GetCurrentTime()); | 337 service->AddSyncedVisit("www.google.com", GetCurrentTime()); |
283 service->SetupFakeResponse(true /* success */, net::HTTP_OK); | 338 service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
284 counter.Restart(); | 339 counter.Restart(); |
285 WaitForCounting(); | 340 WaitForCounting(); |
286 EXPECT_EQ(0u, GetLocalResult()); | 341 EXPECT_EQ(0u, GetLocalResult()); |
287 EXPECT_TRUE(HasSyncedVisits()); | 342 EXPECT_TRUE(HasSyncedVisits()); |
288 | 343 |
289 // To err on the safe side, if the server request fails, we assume that there | 344 // To err on the safe side, if the server request fails, we assume that there |
290 // might be some items on the server. | 345 // might be some items on the server. |
291 service->SetupFakeResponse(true /* success */, | 346 service->SetupFakeResponse(true /* success */, |
292 net::HTTP_INTERNAL_SERVER_ERROR); | 347 net::HTTP_INTERNAL_SERVER_ERROR); |
293 counter.Restart(); | 348 counter.Restart(); |
294 WaitForCounting(); | 349 WaitForCounting(); |
295 EXPECT_EQ(0u, GetLocalResult()); | 350 EXPECT_EQ(0u, GetLocalResult()); |
296 EXPECT_TRUE(HasSyncedVisits()); | 351 EXPECT_TRUE(HasSyncedVisits()); |
297 | 352 |
298 // Same when the entire query fails. | 353 // Same when the entire query fails. |
299 service->SetupFakeResponse(false /* success */, | 354 service->SetupFakeResponse(false /* success */, |
300 net::HTTP_INTERNAL_SERVER_ERROR); | 355 net::HTTP_INTERNAL_SERVER_ERROR); |
301 counter.Restart(); | 356 counter.Restart(); |
302 WaitForCounting(); | 357 WaitForCounting(); |
303 EXPECT_EQ(0u, GetLocalResult()); | 358 EXPECT_EQ(0u, GetLocalResult()); |
304 EXPECT_TRUE(HasSyncedVisits()); | 359 EXPECT_TRUE(HasSyncedVisits()); |
305 | 360 |
306 // Nonzero local count, nonempty sync. | 361 // Nonzero local count, nonempty sync. |
307 AddVisit("https://www.google.com"); | 362 AddVisit("https://www.google.com"); |
308 AddVisit("https://www.chrome.com"); | 363 AddVisit("https://www.chrome.com"); |
309 service->SetupFakeResponse(true /* success */, net::HTTP_OK); | 364 service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
310 counter.Restart(); | 365 counter.Restart(); |
(...skipping 14 matching lines...) Expand all Loading... | |
325 // TODO(crbug.com/553421): Enable this test and move it to the | 380 // TODO(crbug.com/553421): Enable this test and move it to the |
326 // sync/test/integration directory. | 381 // sync/test/integration directory. |
327 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DISABLED_RestartOnSyncChange) { | 382 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, DISABLED_RestartOnSyncChange) { |
328 // Set up the Sync client. | 383 // Set up the Sync client. |
329 ASSERT_TRUE(SetupClients()); | 384 ASSERT_TRUE(SetupClients()); |
330 static const int kFirstProfileIndex = 0; | 385 static const int kFirstProfileIndex = 0; |
331 ProfileSyncService* sync_service = GetSyncService(kFirstProfileIndex); | 386 ProfileSyncService* sync_service = GetSyncService(kFirstProfileIndex); |
332 Profile* profile = GetProfile(kFirstProfileIndex); | 387 Profile* profile = GetProfile(kFirstProfileIndex); |
333 | 388 |
334 // Set up the fake web history service and the counter. | 389 // Set up the fake web history service and the counter. |
335 std::unique_ptr<history::FakeWebHistoryService> web_history_service( | 390 |
336 new history::FakeWebHistoryService( | 391 browsing_data::HistoryCounter counter( |
337 ProfileOAuth2TokenServiceFactory::GetForProfile(browser()->profile()), | 392 GetHistoryService(), |
338 SigninManagerFactory::GetForProfile(browser()->profile()), | 393 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService, |
339 browser()->profile()->GetRequestContext())); | 394 base::Unretained(this), |
340 HistoryCounter counter(profile); | 395 base::Unretained(profile), |
341 counter.SetWebHistoryServiceForTesting(web_history_service.get()); | 396 true), |
397 sync_service); | |
398 | |
342 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 399 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, |
343 base::Unretained(this))); | 400 base::Unretained(this))); |
344 | 401 |
345 // Note that some Sync operations notify observers immediately (and thus there | 402 // 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), | 403 // 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 | 404 // while other operations only post the task on UI thread's message loop |
348 // (which requires calling |WaitForCounting()| for them to run). Therefore, | 405 // (which requires calling |WaitForCounting()| for them to run). Therefore, |
349 // this test always checks if the callback has already run and only waits | 406 // this test always checks if the callback has already run and only waits |
350 // if it has not. | 407 // if it has not. |
351 | 408 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 // history deletion did not change. However, in reality we can get two | 451 // 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 | 452 // notifications, one that history sync has stopped and another that it is |
396 // active again. | 453 // active again. |
397 | 454 |
398 // Stopping the Sync service triggers a restart. | 455 // Stopping the Sync service triggers a restart. |
399 sync_service->RequestStop(sync_driver::SyncService::CLEAR_DATA); | 456 sync_service->RequestStop(sync_driver::SyncService::CLEAR_DATA); |
400 WaitForCountingOrConfirmFinished(); | 457 WaitForCountingOrConfirmFinished(); |
401 } | 458 } |
402 | 459 |
403 } // namespace | 460 } // namespace |
OLD | NEW |