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 "components/browsing_data/core/counters/history_counter.h" | 5 #include "components/browsing_data/core/counters/history_counter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "chrome/browser/history/history_service_factory.h" | 10 #include "chrome/browser/history/history_service_factory.h" |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 Profile* profile = browser()->profile(); | 175 Profile* profile = browser()->profile(); |
176 | 176 |
177 browsing_data::HistoryCounter counter( | 177 browsing_data::HistoryCounter counter( |
178 GetHistoryService(), | 178 GetHistoryService(), |
179 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, | 179 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, |
180 base::Unretained(this), | 180 base::Unretained(this), |
181 base::Unretained(profile)), | 181 base::Unretained(profile)), |
182 ProfileSyncServiceFactory::GetForProfile(profile)); | 182 ProfileSyncServiceFactory::GetForProfile(profile)); |
183 | 183 |
184 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 184 counter.Init( |
185 base::Unretained(this))); | 185 profile->GetPrefs(), |
| 186 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 187 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this))); |
186 counter.Restart(); | 188 counter.Restart(); |
187 | 189 |
188 WaitForCounting(); | 190 WaitForCounting(); |
189 EXPECT_EQ(7u, GetLocalResult()); | 191 EXPECT_EQ(7u, GetLocalResult()); |
190 } | 192 } |
191 | 193 |
192 // Tests that the counter starts counting automatically when the deletion | 194 // Tests that the counter starts counting automatically when the deletion |
193 // pref changes to true. | 195 // pref changes to true. |
194 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) { | 196 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PrefChanged) { |
195 SetHistoryDeletionPref(false); | 197 SetHistoryDeletionPref(false); |
196 AddVisit("https://www.google.com"); | 198 AddVisit("https://www.google.com"); |
197 AddVisit("https://www.chrome.com"); | 199 AddVisit("https://www.chrome.com"); |
198 | 200 |
199 Profile* profile = browser()->profile(); | 201 Profile* profile = browser()->profile(); |
200 | 202 |
201 browsing_data::HistoryCounter counter( | 203 browsing_data::HistoryCounter counter( |
202 GetHistoryService(), | 204 GetHistoryService(), |
203 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, | 205 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, |
204 base::Unretained(this), | 206 base::Unretained(this), |
205 base::Unretained(profile)), | 207 base::Unretained(profile)), |
206 ProfileSyncServiceFactory::GetForProfile(profile)); | 208 ProfileSyncServiceFactory::GetForProfile(profile)); |
207 | 209 |
208 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 210 counter.Init( |
209 base::Unretained(this))); | 211 profile->GetPrefs(), |
| 212 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 213 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this))); |
210 SetHistoryDeletionPref(true); | 214 SetHistoryDeletionPref(true); |
211 | 215 |
212 WaitForCounting(); | 216 WaitForCounting(); |
213 EXPECT_EQ(2u, GetLocalResult()); | 217 EXPECT_EQ(2u, GetLocalResult()); |
214 } | 218 } |
215 | 219 |
216 // Tests that changing the deletion period restarts the counting, and that | 220 // Tests that changing the deletion period restarts the counting, and that |
217 // the result takes visit dates into account. | 221 // the result takes visit dates into account. |
218 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) { | 222 IN_PROC_BROWSER_TEST_F(HistoryCounterTest, PeriodChanged) { |
219 AddVisit("https://www.google.com"); | 223 AddVisit("https://www.google.com"); |
(...skipping 19 matching lines...) Expand all Loading... |
239 | 243 |
240 Profile* profile = browser()->profile(); | 244 Profile* profile = browser()->profile(); |
241 | 245 |
242 browsing_data::HistoryCounter counter( | 246 browsing_data::HistoryCounter counter( |
243 GetHistoryService(), | 247 GetHistoryService(), |
244 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, | 248 base::Bind(&HistoryCounterTest::GetRealWebHistoryService, |
245 base::Unretained(this), | 249 base::Unretained(this), |
246 base::Unretained(profile)), | 250 base::Unretained(profile)), |
247 ProfileSyncServiceFactory::GetForProfile(profile)); | 251 ProfileSyncServiceFactory::GetForProfile(profile)); |
248 | 252 |
249 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 253 counter.Init( |
250 base::Unretained(this))); | 254 profile->GetPrefs(), |
| 255 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 256 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this))); |
251 | 257 |
252 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 258 SetDeletionPeriodPref(browsing_data::LAST_HOUR); |
253 WaitForCounting(); | 259 WaitForCounting(); |
254 EXPECT_EQ(1u, GetLocalResult()); | 260 EXPECT_EQ(1u, GetLocalResult()); |
255 | 261 |
256 SetDeletionPeriodPref(browsing_data::LAST_DAY); | 262 SetDeletionPeriodPref(browsing_data::LAST_DAY); |
257 WaitForCounting(); | 263 WaitForCounting(); |
258 EXPECT_EQ(1u, GetLocalResult()); | 264 EXPECT_EQ(1u, GetLocalResult()); |
259 | 265 |
260 SetDeletionPeriodPref(browsing_data::LAST_WEEK); | 266 SetDeletionPeriodPref(browsing_data::LAST_WEEK); |
(...skipping 16 matching lines...) Expand all Loading... |
277 Profile* profile = browser()->profile(); | 283 Profile* profile = browser()->profile(); |
278 | 284 |
279 browsing_data::HistoryCounter counter( | 285 browsing_data::HistoryCounter counter( |
280 GetHistoryService(), | 286 GetHistoryService(), |
281 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService, | 287 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService, |
282 base::Unretained(this), | 288 base::Unretained(this), |
283 base::Unretained(profile), | 289 base::Unretained(profile), |
284 false), | 290 false), |
285 ProfileSyncServiceFactory::GetForProfile(profile)); | 291 ProfileSyncServiceFactory::GetForProfile(profile)); |
286 | 292 |
287 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 293 counter.Init( |
288 base::Unretained(this))); | 294 profile->GetPrefs(), |
| 295 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 296 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this))); |
289 | 297 |
290 history::FakeWebHistoryService* service = | 298 history::FakeWebHistoryService* service = |
291 static_cast<history::FakeWebHistoryService*>(GetFakeWebHistoryService( | 299 static_cast<history::FakeWebHistoryService*>(GetFakeWebHistoryService( |
292 profile, false)); | 300 profile, false)); |
293 | 301 |
294 // No entries locally and no entries in Sync. | 302 // No entries locally and no entries in Sync. |
295 service->SetupFakeResponse(true /* success */, net::HTTP_OK); | 303 service->SetupFakeResponse(true /* success */, net::HTTP_OK); |
296 counter.Restart(); | 304 counter.Restart(); |
297 WaitForCounting(); | 305 WaitForCounting(); |
298 EXPECT_EQ(0u, GetLocalResult()); | 306 EXPECT_EQ(0u, GetLocalResult()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 // Set up the fake web history service and the counter. | 376 // Set up the fake web history service and the counter. |
369 | 377 |
370 browsing_data::HistoryCounter counter( | 378 browsing_data::HistoryCounter counter( |
371 GetHistoryService(), | 379 GetHistoryService(), |
372 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService, | 380 base::Bind(&HistoryCounterTest::GetFakeWebHistoryService, |
373 base::Unretained(this), | 381 base::Unretained(this), |
374 base::Unretained(profile), | 382 base::Unretained(profile), |
375 true), | 383 true), |
376 sync_service); | 384 sync_service); |
377 | 385 |
378 counter.Init(profile->GetPrefs(), base::Bind(&HistoryCounterTest::Callback, | 386 counter.Init( |
379 base::Unretained(this))); | 387 profile->GetPrefs(), |
| 388 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 389 base::Bind(&HistoryCounterTest::Callback, base::Unretained(this))); |
380 | 390 |
381 // Note that some Sync operations notify observers immediately (and thus there | 391 // Note that some Sync operations notify observers immediately (and thus there |
382 // 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), |
383 // 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 |
384 // (which requires calling |WaitForCounting()| for them to run). Therefore, | 394 // (which requires calling |WaitForCounting()| for them to run). Therefore, |
385 // 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 |
386 // if it has not. | 396 // if it has not. |
387 | 397 |
388 // We sync all datatypes by default, so starting Sync means that we start | 398 // We sync all datatypes by default, so starting Sync means that we start |
389 // syncing history deletion, and this should restart the counter. | 399 // syncing history deletion, and this should restart the counter. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 // 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 |
431 // 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 |
432 // active again. | 442 // active again. |
433 | 443 |
434 // Stopping the Sync service triggers a restart. | 444 // Stopping the Sync service triggers a restart. |
435 sync_service->RequestStop(syncer::SyncService::CLEAR_DATA); | 445 sync_service->RequestStop(syncer::SyncService::CLEAR_DATA); |
436 WaitForCountingOrConfirmFinished(); | 446 WaitForCountingOrConfirmFinished(); |
437 } | 447 } |
438 | 448 |
439 } // namespace | 449 } // namespace |
OLD | NEW |