| 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" | 
|   11 #include "base/run_loop.h" |   11 #include "base/run_loop.h" | 
|   12 #include "base/strings/string_util.h" |   12 #include "base/strings/string_util.h" | 
|   13 #include "chrome/browser/download/download_history.h" |   13 #include "chrome/browser/download/download_history.h" | 
|   14 #include "chrome/browser/download/download_service.h" |   14 #include "chrome/browser/download/download_service.h" | 
|   15 #include "chrome/browser/download/download_service_factory.h" |   15 #include "chrome/browser/download/download_service_factory.h" | 
|   16 #include "chrome/browser/profiles/profile.h" |   16 #include "chrome/browser/profiles/profile.h" | 
|   17 #include "chrome/browser/ui/browser.h" |   17 #include "chrome/browser/ui/browser.h" | 
|   18 #include "chrome/test/base/in_process_browser_test.h" |   18 #include "chrome/test/base/in_process_browser_test.h" | 
|   19 #include "components/browsing_data/core/browsing_data_utils.h" |   19 #include "components/browsing_data/core/browsing_data_utils.h" | 
|   20 #include "components/browsing_data/core/pref_names.h" |   20 #include "components/browsing_data/core/pref_names.h" | 
|   21 #include "components/history/core/browser/download_row.h" |   21 #include "components/history/core/browser/download_row.h" | 
|   22 #include "components/prefs/pref_service.h" |   22 #include "components/prefs/pref_service.h" | 
|   23 #include "content/public/browser/download_manager.h" |   23 #include "content/public/browser/download_manager.h" | 
 |   24 #include "extensions/features/features.h" | 
|   24  |   25  | 
|   25 #if defined(ENABLE_EXTENSIONS) |   26 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
|   26 #include "extensions/common/extension.h" |   27 #include "extensions/common/extension.h" | 
|   27 #endif |   28 #endif | 
|   28  |   29  | 
|   29 namespace { |   30 namespace { | 
|   30  |   31  | 
|   31 class DownloadsCounterTest : public InProcessBrowserTest, |   32 class DownloadsCounterTest : public InProcessBrowserTest, | 
|   32                              public DownloadHistory::Observer { |   33                              public DownloadHistory::Observer { | 
|   33  public: |   34  public: | 
|   34   void SetUpOnMainThread() override { |   35   void SetUpOnMainThread() override { | 
|   35     time_ = base::Time::Now(); |   36     time_ = base::Time::Now(); | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   71     // wait for a callback from them, so we don't add them to |guids_to_add_|. |   72     // wait for a callback from them, so we don't add them to |guids_to_add_|. | 
|   72     return AddDownloadInternal( |   73     return AddDownloadInternal( | 
|   73         content::DownloadItem::COMPLETE, |   74         content::DownloadItem::COMPLETE, | 
|   74         content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |   75         content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 
|   75         content::DOWNLOAD_INTERRUPT_REASON_NONE, |   76         content::DOWNLOAD_INTERRUPT_REASON_NONE, | 
|   76         GURL(), |   77         GURL(), | 
|   77         std::string(), |   78         std::string(), | 
|   78         true); |   79         true); | 
|   79   } |   80   } | 
|   80  |   81  | 
|   81 #if defined(ENABLE_EXTENSIONS) |   82 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
|   82   std::string AddExtensionDownload() { |   83   std::string AddExtensionDownload() { | 
|   83     // Extension downloads are not expected to be persisted. We don't need to |   84     // Extension downloads are not expected to be persisted. We don't need to | 
|   84     // wait for a callback from them, so we don't add them to |guids_to_add_|. |   85     // wait for a callback from them, so we don't add them to |guids_to_add_|. | 
|   85     return AddDownloadInternal( |   86     return AddDownloadInternal( | 
|   86         content::DownloadItem::COMPLETE, |   87         content::DownloadItem::COMPLETE, | 
|   87         content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |   88         content::DownloadDangerType::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 
|   88         content::DOWNLOAD_INTERRUPT_REASON_NONE, |   89         content::DOWNLOAD_INTERRUPT_REASON_NONE, | 
|   89         GURL(), |   90         GURL(), | 
|   90         extensions::Extension::kMimeType, |   91         extensions::Extension::kMimeType, | 
|   91         false); |   92         false); | 
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  324 // Tests that downloads not persisted by DownloadHistory are not counted. |  325 // Tests that downloads not persisted by DownloadHistory are not counted. | 
|  325 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, NotPersisted) { |  326 IN_PROC_BROWSER_TEST_F(DownloadsCounterTest, NotPersisted) { | 
|  326   Profile* profile = browser()->profile(); |  327   Profile* profile = browser()->profile(); | 
|  327   DownloadsCounter counter(profile); |  328   DownloadsCounter counter(profile); | 
|  328   counter.Init(profile->GetPrefs(), |  329   counter.Init(profile->GetPrefs(), | 
|  329                base::Bind(&DownloadsCounterTest::ResultCallback, |  330                base::Bind(&DownloadsCounterTest::ResultCallback, | 
|  330                           base::Unretained(this))); |  331                           base::Unretained(this))); | 
|  331  |  332  | 
|  332   // Extension and user scripts download are not persisted. |  333   // Extension and user scripts download are not persisted. | 
|  333   AddDownload(); |  334   AddDownload(); | 
|  334 #if defined(ENABLE_EXTENSIONS) |  335 #if BUILDFLAG(ENABLE_EXTENSIONS) | 
|  335   AddUserScriptDownload(); |  336   AddUserScriptDownload(); | 
|  336   AddExtensionDownload(); |  337   AddExtensionDownload(); | 
|  337 #endif |  338 #endif | 
|  338  |  339  | 
|  339   WaitForDownloadHistory(); |  340   WaitForDownloadHistory(); | 
|  340   counter.Restart(); |  341   counter.Restart(); | 
|  341   EXPECT_EQ(1u, GetResult()); |  342   EXPECT_EQ(1u, GetResult()); | 
|  342  |  343  | 
|  343   // Neither are downloads in incognito mode. |  344   // Neither are downloads in incognito mode. | 
|  344   AddIncognitoDownload(); |  345   AddIncognitoDownload(); | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  388   EXPECT_EQ(7u, GetResult()); |  389   EXPECT_EQ(7u, GetResult()); | 
|  389  |  390  | 
|  390   SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); |  391   SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 
|  391   EXPECT_EQ(8u, GetResult()); |  392   EXPECT_EQ(8u, GetResult()); | 
|  392  |  393  | 
|  393   SetDeletionPeriodPref(browsing_data::ALL_TIME); |  394   SetDeletionPeriodPref(browsing_data::ALL_TIME); | 
|  394   EXPECT_EQ(11u, GetResult()); |  395   EXPECT_EQ(11u, GetResult()); | 
|  395 } |  396 } | 
|  396  |  397  | 
|  397 }  // namespace |  398 }  // namespace | 
| OLD | NEW |