| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
| 5 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 6 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/location.h" | 11 #include "base/location.h" |
| 9 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 11 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 12 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 14 #include "chrome/browser/download/chrome_download_manager_delegate.h" | 17 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 133 |
| 131 // ::testing::Test | 134 // ::testing::Test |
| 132 void SetUp() override; | 135 void SetUp() override; |
| 133 void TearDown() override; | 136 void TearDown() override; |
| 134 | 137 |
| 135 // Verifies and clears test expectations for |delegate_| and | 138 // Verifies and clears test expectations for |delegate_| and |
| 136 // |download_manager_|. | 139 // |download_manager_|. |
| 137 void VerifyAndClearExpectations(); | 140 void VerifyAndClearExpectations(); |
| 138 | 141 |
| 139 // Creates MockDownloadItem and sets up default expectations. | 142 // Creates MockDownloadItem and sets up default expectations. |
| 140 content::MockDownloadItem* CreateActiveDownloadItem(int32 id); | 143 content::MockDownloadItem* CreateActiveDownloadItem(int32_t id); |
| 141 | 144 |
| 142 // Given the relative path |path|, returns the full path under the temporary | 145 // Given the relative path |path|, returns the full path under the temporary |
| 143 // downloads directory. | 146 // downloads directory. |
| 144 base::FilePath GetPathInDownloadDir(const char* path); | 147 base::FilePath GetPathInDownloadDir(const char* path); |
| 145 | 148 |
| 146 // Set the kDownloadDefaultDirectory user preference to |path|. | 149 // Set the kDownloadDefaultDirectory user preference to |path|. |
| 147 void SetDefaultDownloadPath(const base::FilePath& path); | 150 void SetDefaultDownloadPath(const base::FilePath& path); |
| 148 | 151 |
| 149 void DetermineDownloadTarget(DownloadItem* download, | 152 void DetermineDownloadTarget(DownloadItem* download, |
| 150 DownloadTargetInfo* result); | 153 DownloadTargetInfo* result); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 base::RunLoop().RunUntilIdle(); | 193 base::RunLoop().RunUntilIdle(); |
| 191 delegate_->Shutdown(); | 194 delegate_->Shutdown(); |
| 192 ChromeRenderViewHostTestHarness::TearDown(); | 195 ChromeRenderViewHostTestHarness::TearDown(); |
| 193 } | 196 } |
| 194 | 197 |
| 195 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { | 198 void ChromeDownloadManagerDelegateTest::VerifyAndClearExpectations() { |
| 196 ::testing::Mock::VerifyAndClearExpectations(delegate_.get()); | 199 ::testing::Mock::VerifyAndClearExpectations(delegate_.get()); |
| 197 } | 200 } |
| 198 | 201 |
| 199 content::MockDownloadItem* | 202 content::MockDownloadItem* |
| 200 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32 id) { | 203 ChromeDownloadManagerDelegateTest::CreateActiveDownloadItem(int32_t id) { |
| 201 content::MockDownloadItem* item = | 204 content::MockDownloadItem* item = |
| 202 new ::testing::NiceMock<content::MockDownloadItem>(); | 205 new ::testing::NiceMock<content::MockDownloadItem>(); |
| 203 ON_CALL(*item, GetBrowserContext()) | 206 ON_CALL(*item, GetBrowserContext()) |
| 204 .WillByDefault(Return(profile())); | 207 .WillByDefault(Return(profile())); |
| 205 ON_CALL(*item, GetDangerType()) | 208 ON_CALL(*item, GetDangerType()) |
| 206 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)); | 209 .WillByDefault(Return(content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS)); |
| 207 ON_CALL(*item, GetForcedFilePath()) | 210 ON_CALL(*item, GetForcedFilePath()) |
| 208 .WillByDefault(ReturnRefOfCopy(base::FilePath())); | 211 .WillByDefault(ReturnRefOfCopy(base::FilePath())); |
| 209 ON_CALL(*item, GetFullPath()) | 212 ON_CALL(*item, GetFullPath()) |
| 210 .WillByDefault(ReturnRefOfCopy(base::FilePath())); | 213 .WillByDefault(ReturnRefOfCopy(base::FilePath())); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 CreateActiveDownloadItem(1)); | 398 CreateActiveDownloadItem(1)); |
| 396 EXPECT_CALL(*download_item, GetTargetFilePath()) | 399 EXPECT_CALL(*download_item, GetTargetFilePath()) |
| 397 .WillRepeatedly(ReturnRef(existing_path)); | 400 .WillRepeatedly(ReturnRef(existing_path)); |
| 398 EXPECT_TRUE(CheckForFileExistence(download_item.get())); | 401 EXPECT_TRUE(CheckForFileExistence(download_item.get())); |
| 399 | 402 |
| 400 download_item.reset(CreateActiveDownloadItem(1)); | 403 download_item.reset(CreateActiveDownloadItem(1)); |
| 401 EXPECT_CALL(*download_item, GetTargetFilePath()) | 404 EXPECT_CALL(*download_item, GetTargetFilePath()) |
| 402 .WillRepeatedly(ReturnRef(non_existent_path)); | 405 .WillRepeatedly(ReturnRef(non_existent_path)); |
| 403 EXPECT_FALSE(CheckForFileExistence(download_item.get())); | 406 EXPECT_FALSE(CheckForFileExistence(download_item.get())); |
| 404 } | 407 } |
| OLD | NEW |