OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/downloads_counter.h" | 5 #include "chrome/browser/browsing_data/downloads_counter.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/guid.h" | 10 #include "base/guid.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 content::BrowserContext::GetDownloadManager(browser()->profile()); | 39 content::BrowserContext::GetDownloadManager(browser()->profile()); |
40 history_ = | 40 history_ = |
41 DownloadServiceFactory::GetForBrowserContext(browser()->profile())-> | 41 DownloadServiceFactory::GetForBrowserContext(browser()->profile())-> |
42 GetDownloadHistory(); | 42 GetDownloadHistory(); |
43 history_->AddObserver(this); | 43 history_->AddObserver(this); |
44 | 44 |
45 otr_manager_ = | 45 otr_manager_ = |
46 content::BrowserContext::GetDownloadManager( | 46 content::BrowserContext::GetDownloadManager( |
47 browser()->profile()->GetOffTheRecordProfile()); | 47 browser()->profile()->GetOffTheRecordProfile()); |
48 SetDownloadsDeletionPref(true); | 48 SetDownloadsDeletionPref(true); |
49 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 49 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); |
50 } | 50 } |
51 | 51 |
52 void TearDownOnMainThread() override { | 52 void TearDownOnMainThread() override { |
53 history_->RemoveObserver(this); | 53 history_->RemoveObserver(this); |
54 } | 54 } |
55 | 55 |
56 // Adding and removing download items. --------------------------------------- | 56 // Adding and removing download items. --------------------------------------- |
57 | 57 |
58 std::string AddDownload() { | 58 std::string AddDownload() { |
59 std::string guid = AddDownloadInternal( | 59 std::string guid = AddDownloadInternal( |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 241 |
242 bool finished_; | 242 bool finished_; |
243 browsing_data::BrowsingDataCounter::ResultInt result_; | 243 browsing_data::BrowsingDataCounter::ResultInt result_; |
244 }; | 244 }; |
245 | 245 |
246 // Tests that we count the total number of downloads correctly. | 246 // Tests that we count the total number of downloads correctly. |
247 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, Count) { | 247 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, Count) { |
248 Profile* profile = browser()->profile(); | 248 Profile* profile = browser()->profile(); |
249 DownloadsCounter counter(profile); | 249 DownloadsCounter counter(profile); |
250 counter.Init(profile->GetPrefs(), | 250 counter.Init(profile->GetPrefs(), |
| 251 browsing_data::ClearBrowsingDataTab::ADVANCED, |
251 base::Bind(&DownloadsCounterTest::ResultCallback, | 252 base::Bind(&DownloadsCounterTest::ResultCallback, |
252 base::Unretained(this))); | 253 base::Unretained(this))); |
253 counter.Restart(); | 254 counter.Restart(); |
254 EXPECT_EQ(0u, GetResult()); | 255 EXPECT_EQ(0u, GetResult()); |
255 | 256 |
256 std::string first_download = AddDownload(); | 257 std::string first_download = AddDownload(); |
257 AddDownload(); | 258 AddDownload(); |
258 std::string last_download = AddDownload(); | 259 std::string last_download = AddDownload(); |
259 WaitForDownloadHistory(); | 260 WaitForDownloadHistory(); |
260 counter.Restart(); | 261 counter.Restart(); |
261 EXPECT_EQ(3, GetResult()); | 262 EXPECT_EQ(3, GetResult()); |
262 | 263 |
263 RemoveDownload(last_download); | 264 RemoveDownload(last_download); |
264 RemoveDownload(first_download); | 265 RemoveDownload(first_download); |
265 WaitForDownloadHistory(); | 266 WaitForDownloadHistory(); |
266 counter.Restart(); | 267 counter.Restart(); |
267 EXPECT_EQ(1, GetResult()); | 268 EXPECT_EQ(1, GetResult()); |
268 | 269 |
269 AddDownload(); | 270 AddDownload(); |
270 WaitForDownloadHistory(); | 271 WaitForDownloadHistory(); |
271 counter.Restart(); | 272 counter.Restart(); |
272 EXPECT_EQ(2, GetResult()); | 273 EXPECT_EQ(2, GetResult()); |
273 } | 274 } |
274 | 275 |
275 // Tests that not just standard complete downloads are counted. | 276 // Tests that not just standard complete downloads are counted. |
276 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, Types) { | 277 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, Types) { |
277 Profile* profile = browser()->profile(); | 278 Profile* profile = browser()->profile(); |
278 DownloadsCounter counter(profile); | 279 DownloadsCounter counter(profile); |
279 counter.Init(profile->GetPrefs(), | 280 counter.Init(profile->GetPrefs(), |
| 281 browsing_data::ClearBrowsingDataTab::ADVANCED, |
280 base::Bind(&DownloadsCounterTest::ResultCallback, | 282 base::Bind(&DownloadsCounterTest::ResultCallback, |
281 base::Unretained(this))); | 283 base::Unretained(this))); |
282 | 284 |
283 AddDownload(); | 285 AddDownload(); |
284 AddDownloadWithProperties( | 286 AddDownloadWithProperties( |
285 content::DownloadItem::COMPLETE, | 287 content::DownloadItem::COMPLETE, |
286 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 288 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
287 content::DOWNLOAD_INTERRUPT_REASON_NONE); | 289 content::DOWNLOAD_INTERRUPT_REASON_NONE); |
288 AddDownloadWithProperties( | 290 AddDownloadWithProperties( |
289 content::DownloadItem::COMPLETE, | 291 content::DownloadItem::COMPLETE, |
(...skipping 15 matching lines...) Expand all Loading... |
305 WaitForDownloadHistory(); | 307 WaitForDownloadHistory(); |
306 counter.Restart(); | 308 counter.Restart(); |
307 EXPECT_EQ(6u, GetResult()); | 309 EXPECT_EQ(6u, GetResult()); |
308 } | 310 } |
309 | 311 |
310 // Tests that downloads not persisted by DownloadHistory are not counted. | 312 // Tests that downloads not persisted by DownloadHistory are not counted. |
311 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, NotPersisted) { | 313 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, NotPersisted) { |
312 Profile* profile = browser()->profile(); | 314 Profile* profile = browser()->profile(); |
313 DownloadsCounter counter(profile); | 315 DownloadsCounter counter(profile); |
314 counter.Init(profile->GetPrefs(), | 316 counter.Init(profile->GetPrefs(), |
| 317 browsing_data::ClearBrowsingDataTab::ADVANCED, |
315 base::Bind(&DownloadsCounterTest::ResultCallback, | 318 base::Bind(&DownloadsCounterTest::ResultCallback, |
316 base::Unretained(this))); | 319 base::Unretained(this))); |
317 | 320 |
318 // Extension and user scripts download are not persisted. | 321 // Extension and user scripts download are not persisted. |
319 AddDownload(); | 322 AddDownload(); |
320 #if BUILDFLAG(ENABLE_EXTENSIONS) | 323 #if BUILDFLAG(ENABLE_EXTENSIONS) |
321 AddUserScriptDownload(); | 324 AddUserScriptDownload(); |
322 AddExtensionDownload(); | 325 AddExtensionDownload(); |
323 #endif | 326 #endif |
324 | 327 |
(...skipping 29 matching lines...) Expand all Loading... |
354 RevertTimeInHours(30 * 24); | 357 RevertTimeInHours(30 * 24); |
355 AddDownload(); | 358 AddDownload(); |
356 AddDownload(); | 359 AddDownload(); |
357 AddDownload(); // 11 items | 360 AddDownload(); // 11 items |
358 | 361 |
359 WaitForDownloadHistory(); | 362 WaitForDownloadHistory(); |
360 | 363 |
361 Profile* profile = browser()->profile(); | 364 Profile* profile = browser()->profile(); |
362 DownloadsCounter counter(profile); | 365 DownloadsCounter counter(profile); |
363 counter.Init(profile->GetPrefs(), | 366 counter.Init(profile->GetPrefs(), |
| 367 browsing_data::ClearBrowsingDataTab::ADVANCED, |
364 base::Bind(&DownloadsCounterTest::ResultCallback, | 368 base::Bind(&DownloadsCounterTest::ResultCallback, |
365 base::Unretained(this))); | 369 base::Unretained(this))); |
366 | 370 |
367 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 371 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_HOUR); |
368 EXPECT_EQ(2u, GetResult()); | 372 EXPECT_EQ(2u, GetResult()); |
369 | 373 |
370 SetDeletionPeriodPref(browsing_data::LAST_DAY); | 374 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_DAY); |
371 EXPECT_EQ(5u, GetResult()); | 375 EXPECT_EQ(5u, GetResult()); |
372 | 376 |
373 SetDeletionPeriodPref(browsing_data::LAST_WEEK); | 377 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_WEEK); |
374 EXPECT_EQ(7u, GetResult()); | 378 EXPECT_EQ(7u, GetResult()); |
375 | 379 |
376 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 380 SetDeletionPeriodPref(browsing_data::TimePeriod::FOUR_WEEKS); |
377 EXPECT_EQ(8u, GetResult()); | 381 EXPECT_EQ(8u, GetResult()); |
378 | 382 |
379 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 383 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); |
380 EXPECT_EQ(11u, GetResult()); | 384 EXPECT_EQ(11u, GetResult()); |
381 } | 385 } |
382 | 386 |
383 } // namespace | 387 } // namespace |
OLD | NEW |