| 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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 256 |
| 257 bool finished_; | 257 bool finished_; |
| 258 browsing_data::BrowsingDataCounter::ResultInt result_; | 258 browsing_data::BrowsingDataCounter::ResultInt result_; |
| 259 }; | 259 }; |
| 260 | 260 |
| 261 // Tests that we count the total number of downloads correctly. | 261 // Tests that we count the total number of downloads correctly. |
| 262 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, Count) { | 262 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, Count) { |
| 263 Profile* profile = browser()->profile(); | 263 Profile* profile = browser()->profile(); |
| 264 DownloadsCounter counter(profile); | 264 DownloadsCounter counter(profile); |
| 265 counter.Init(profile->GetPrefs(), | 265 counter.Init(profile->GetPrefs(), |
| 266 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 266 base::Bind(&DownloadsCounterTest::ResultCallback, | 267 base::Bind(&DownloadsCounterTest::ResultCallback, |
| 267 base::Unretained(this))); | 268 base::Unretained(this))); |
| 268 counter.Restart(); | 269 counter.Restart(); |
| 269 EXPECT_EQ(0u, GetResult()); | 270 EXPECT_EQ(0u, GetResult()); |
| 270 | 271 |
| 271 std::string first_download = AddDownload(); | 272 std::string first_download = AddDownload(); |
| 272 AddDownload(); | 273 AddDownload(); |
| 273 std::string last_download = AddDownload(); | 274 std::string last_download = AddDownload(); |
| 274 WaitForDownloadHistory(); | 275 WaitForDownloadHistory(); |
| 275 counter.Restart(); | 276 counter.Restart(); |
| 276 EXPECT_EQ(3, GetResult()); | 277 EXPECT_EQ(3, GetResult()); |
| 277 | 278 |
| 278 RemoveDownload(last_download); | 279 RemoveDownload(last_download); |
| 279 RemoveDownload(first_download); | 280 RemoveDownload(first_download); |
| 280 WaitForDownloadHistory(); | 281 WaitForDownloadHistory(); |
| 281 counter.Restart(); | 282 counter.Restart(); |
| 282 EXPECT_EQ(1, GetResult()); | 283 EXPECT_EQ(1, GetResult()); |
| 283 | 284 |
| 284 AddDownload(); | 285 AddDownload(); |
| 285 WaitForDownloadHistory(); | 286 WaitForDownloadHistory(); |
| 286 counter.Restart(); | 287 counter.Restart(); |
| 287 EXPECT_EQ(2, GetResult()); | 288 EXPECT_EQ(2, GetResult()); |
| 288 } | 289 } |
| 289 | 290 |
| 290 // Tests that not just standard complete downloads are counted. | 291 // Tests that not just standard complete downloads are counted. |
| 291 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, Types) { | 292 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, Types) { |
| 292 Profile* profile = browser()->profile(); | 293 Profile* profile = browser()->profile(); |
| 293 DownloadsCounter counter(profile); | 294 DownloadsCounter counter(profile); |
| 294 counter.Init(profile->GetPrefs(), | 295 counter.Init(profile->GetPrefs(), |
| 296 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 295 base::Bind(&DownloadsCounterTest::ResultCallback, | 297 base::Bind(&DownloadsCounterTest::ResultCallback, |
| 296 base::Unretained(this))); | 298 base::Unretained(this))); |
| 297 | 299 |
| 298 AddDownload(); | 300 AddDownload(); |
| 299 AddDownloadWithProperties( | 301 AddDownloadWithProperties( |
| 300 content::DownloadItem::COMPLETE, | 302 content::DownloadItem::COMPLETE, |
| 301 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, | 303 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 302 content::DOWNLOAD_INTERRUPT_REASON_NONE); | 304 content::DOWNLOAD_INTERRUPT_REASON_NONE); |
| 303 AddDownloadWithProperties( | 305 AddDownloadWithProperties( |
| 304 content::DownloadItem::COMPLETE, | 306 content::DownloadItem::COMPLETE, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 320 WaitForDownloadHistory(); | 322 WaitForDownloadHistory(); |
| 321 counter.Restart(); | 323 counter.Restart(); |
| 322 EXPECT_EQ(6u, GetResult()); | 324 EXPECT_EQ(6u, GetResult()); |
| 323 } | 325 } |
| 324 | 326 |
| 325 // Tests that downloads not persisted by DownloadHistory are not counted. | 327 // Tests that downloads not persisted by DownloadHistory are not counted. |
| 326 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, NotPersisted) { | 328 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, NotPersisted) { |
| 327 Profile* profile = browser()->profile(); | 329 Profile* profile = browser()->profile(); |
| 328 DownloadsCounter counter(profile); | 330 DownloadsCounter counter(profile); |
| 329 counter.Init(profile->GetPrefs(), | 331 counter.Init(profile->GetPrefs(), |
| 332 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 330 base::Bind(&DownloadsCounterTest::ResultCallback, | 333 base::Bind(&DownloadsCounterTest::ResultCallback, |
| 331 base::Unretained(this))); | 334 base::Unretained(this))); |
| 332 | 335 |
| 333 // Extension and user scripts download are not persisted. | 336 // Extension and user scripts download are not persisted. |
| 334 AddDownload(); | 337 AddDownload(); |
| 335 #if BUILDFLAG(ENABLE_EXTENSIONS) | 338 #if BUILDFLAG(ENABLE_EXTENSIONS) |
| 336 AddUserScriptDownload(); | 339 AddUserScriptDownload(); |
| 337 AddExtensionDownload(); | 340 AddExtensionDownload(); |
| 338 #endif | 341 #endif |
| 339 | 342 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 369 RevertTimeInHours(30 * 24); | 372 RevertTimeInHours(30 * 24); |
| 370 AddDownload(); | 373 AddDownload(); |
| 371 AddDownload(); | 374 AddDownload(); |
| 372 AddDownload(); // 11 items | 375 AddDownload(); // 11 items |
| 373 | 376 |
| 374 WaitForDownloadHistory(); | 377 WaitForDownloadHistory(); |
| 375 | 378 |
| 376 Profile* profile = browser()->profile(); | 379 Profile* profile = browser()->profile(); |
| 377 DownloadsCounter counter(profile); | 380 DownloadsCounter counter(profile); |
| 378 counter.Init(profile->GetPrefs(), | 381 counter.Init(profile->GetPrefs(), |
| 382 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 379 base::Bind(&DownloadsCounterTest::ResultCallback, | 383 base::Bind(&DownloadsCounterTest::ResultCallback, |
| 380 base::Unretained(this))); | 384 base::Unretained(this))); |
| 381 | 385 |
| 382 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 386 SetDeletionPeriodPref(browsing_data::LAST_HOUR); |
| 383 EXPECT_EQ(2u, GetResult()); | 387 EXPECT_EQ(2u, GetResult()); |
| 384 | 388 |
| 385 SetDeletionPeriodPref(browsing_data::LAST_DAY); | 389 SetDeletionPeriodPref(browsing_data::LAST_DAY); |
| 386 EXPECT_EQ(5u, GetResult()); | 390 EXPECT_EQ(5u, GetResult()); |
| 387 | 391 |
| 388 SetDeletionPeriodPref(browsing_data::LAST_WEEK); | 392 SetDeletionPeriodPref(browsing_data::LAST_WEEK); |
| 389 EXPECT_EQ(7u, GetResult()); | 393 EXPECT_EQ(7u, GetResult()); |
| 390 | 394 |
| 391 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 395 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); |
| 392 EXPECT_EQ(8u, GetResult()); | 396 EXPECT_EQ(8u, GetResult()); |
| 393 | 397 |
| 394 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 398 SetDeletionPeriodPref(browsing_data::ALL_TIME); |
| 395 EXPECT_EQ(11u, GetResult()); | 399 EXPECT_EQ(11u, GetResult()); |
| 396 } | 400 } |
| 397 | 401 |
| 398 } // namespace | 402 } // namespace |
| OLD | NEW |