| 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 // This file contains download browser tests that are known to be runnable | 5 // This file contains download browser tests that are known to be runnable |
| 6 // in a pure content context. Over time tests should be migrated here. | 6 // in a pure content context. Over time tests should be migrated here. |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #include "base/threading/platform_thread.h" | 23 #include "base/threading/platform_thread.h" |
| 24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #include "content/browser/byte_stream.h" | 26 #include "content/browser/byte_stream.h" |
| 27 #include "content/browser/download/download_file_factory.h" | 27 #include "content/browser/download/download_file_factory.h" |
| 28 #include "content/browser/download/download_file_impl.h" | 28 #include "content/browser/download/download_file_impl.h" |
| 29 #include "content/browser/download/download_item_impl.h" | 29 #include "content/browser/download/download_item_impl.h" |
| 30 #include "content/browser/download/download_manager_impl.h" | 30 #include "content/browser/download/download_manager_impl.h" |
| 31 #include "content/browser/download/download_resource_handler.h" | 31 #include "content/browser/download/download_resource_handler.h" |
| 32 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 32 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 33 #include "content/browser/power_save_blocker_factory.h" |
| 33 #include "content/browser/web_contents/web_contents_impl.h" | 34 #include "content/browser/web_contents/web_contents_impl.h" |
| 34 #include "content/public/browser/download_danger_type.h" | 35 #include "content/public/browser/download_danger_type.h" |
| 35 #include "content/public/browser/power_save_blocker_factory.h" | |
| 36 #include "content/public/browser/resource_dispatcher_host_delegate.h" | 36 #include "content/public/browser/resource_dispatcher_host_delegate.h" |
| 37 #include "content/public/browser/resource_throttle.h" | 37 #include "content/public/browser/resource_throttle.h" |
| 38 #include "content/public/common/content_features.h" | 38 #include "content/public/common/content_features.h" |
| 39 #include "content/public/common/webplugininfo.h" | 39 #include "content/public/common/webplugininfo.h" |
| 40 #include "content/public/test/browser_test_utils.h" | 40 #include "content/public/test/browser_test_utils.h" |
| 41 #include "content/public/test/content_browser_test.h" | 41 #include "content/public/test/content_browser_test.h" |
| 42 #include "content/public/test/content_browser_test_utils.h" | 42 #include "content/public/test/content_browser_test_utils.h" |
| 43 #include "content/public/test/download_test_observer.h" | 43 #include "content/public/test/download_test_observer.h" |
| 44 #include "content/public/test/test_download_request_handler.h" | 44 #include "content/public/test/test_download_request_handler.h" |
| 45 #include "content/public/test/test_file_error_injector.h" | 45 #include "content/public/test/test_file_error_injector.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 static DownloadManagerImpl* DownloadManagerForShell(Shell* shell) { | 115 static DownloadManagerImpl* DownloadManagerForShell(Shell* shell) { |
| 116 // We're in a content_browsertest; we know that the DownloadManager | 116 // We're in a content_browsertest; we know that the DownloadManager |
| 117 // is a DownloadManagerImpl. | 117 // is a DownloadManagerImpl. |
| 118 return static_cast<DownloadManagerImpl*>( | 118 return static_cast<DownloadManagerImpl*>( |
| 119 BrowserContext::GetDownloadManager( | 119 BrowserContext::GetDownloadManager( |
| 120 shell->web_contents()->GetBrowserContext())); | 120 shell->web_contents()->GetBrowserContext())); |
| 121 } | 121 } |
| 122 | 122 |
| 123 class DownloadFileWithDelay : public DownloadFileImpl { | 123 class DownloadFileWithDelay : public DownloadFileImpl { |
| 124 public: | 124 public: |
| 125 DownloadFileWithDelay(std::unique_ptr<DownloadSaveInfo> save_info, | 125 DownloadFileWithDelay( |
| 126 const base::FilePath& default_download_directory, | 126 std::unique_ptr<DownloadSaveInfo> save_info, |
| 127 std::unique_ptr<ByteStreamReader> stream, | 127 const base::FilePath& default_download_directory, |
| 128 const net::BoundNetLog& bound_net_log, | 128 std::unique_ptr<ByteStreamReader> stream, |
| 129 std::unique_ptr<PowerSaveBlocker> power_save_blocker, | 129 const net::BoundNetLog& bound_net_log, |
| 130 base::WeakPtr<DownloadDestinationObserver> observer, | 130 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, |
| 131 base::WeakPtr<DownloadFileWithDelayFactory> owner); | 131 base::WeakPtr<DownloadDestinationObserver> observer, |
| 132 base::WeakPtr<DownloadFileWithDelayFactory> owner); |
| 132 | 133 |
| 133 ~DownloadFileWithDelay() override; | 134 ~DownloadFileWithDelay() override; |
| 134 | 135 |
| 135 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, | 136 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, |
| 136 // storing it in the factory that produced this object for later | 137 // storing it in the factory that produced this object for later |
| 137 // retrieval. | 138 // retrieval. |
| 138 void RenameAndUniquify(const base::FilePath& full_path, | 139 void RenameAndUniquify(const base::FilePath& full_path, |
| 139 const RenameCompletionCallback& callback) override; | 140 const RenameCompletionCallback& callback) override; |
| 140 void RenameAndAnnotate(const base::FilePath& full_path, | 141 void RenameAndAnnotate(const base::FilePath& full_path, |
| 141 const std::string& client_guid, | 142 const std::string& client_guid, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; | 187 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; |
| 187 | 188 |
| 188 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); | 189 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); |
| 189 }; | 190 }; |
| 190 | 191 |
| 191 DownloadFileWithDelay::DownloadFileWithDelay( | 192 DownloadFileWithDelay::DownloadFileWithDelay( |
| 192 std::unique_ptr<DownloadSaveInfo> save_info, | 193 std::unique_ptr<DownloadSaveInfo> save_info, |
| 193 const base::FilePath& default_download_directory, | 194 const base::FilePath& default_download_directory, |
| 194 std::unique_ptr<ByteStreamReader> stream, | 195 std::unique_ptr<ByteStreamReader> stream, |
| 195 const net::BoundNetLog& bound_net_log, | 196 const net::BoundNetLog& bound_net_log, |
| 196 std::unique_ptr<PowerSaveBlocker> power_save_blocker, | 197 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, |
| 197 base::WeakPtr<DownloadDestinationObserver> observer, | 198 base::WeakPtr<DownloadDestinationObserver> observer, |
| 198 base::WeakPtr<DownloadFileWithDelayFactory> owner) | 199 base::WeakPtr<DownloadFileWithDelayFactory> owner) |
| 199 : DownloadFileImpl(std::move(save_info), | 200 : DownloadFileImpl(std::move(save_info), |
| 200 default_download_directory, | 201 default_download_directory, |
| 201 std::move(stream), | 202 std::move(stream), |
| 202 bound_net_log, | 203 bound_net_log, |
| 203 observer), | 204 observer), |
| 204 owner_(owner) {} | 205 owner_(owner) {} |
| 205 | 206 |
| 206 DownloadFileWithDelay::~DownloadFileWithDelay() {} | 207 DownloadFileWithDelay::~DownloadFileWithDelay() {} |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 weak_ptr_factory_(this) {} | 248 weak_ptr_factory_(this) {} |
| 248 | 249 |
| 249 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} | 250 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} |
| 250 | 251 |
| 251 DownloadFile* DownloadFileWithDelayFactory::CreateFile( | 252 DownloadFile* DownloadFileWithDelayFactory::CreateFile( |
| 252 std::unique_ptr<DownloadSaveInfo> save_info, | 253 std::unique_ptr<DownloadSaveInfo> save_info, |
| 253 const base::FilePath& default_download_directory, | 254 const base::FilePath& default_download_directory, |
| 254 std::unique_ptr<ByteStreamReader> stream, | 255 std::unique_ptr<ByteStreamReader> stream, |
| 255 const net::BoundNetLog& bound_net_log, | 256 const net::BoundNetLog& bound_net_log, |
| 256 base::WeakPtr<DownloadDestinationObserver> observer) { | 257 base::WeakPtr<DownloadDestinationObserver> observer) { |
| 257 std::unique_ptr<PowerSaveBlocker> psb(CreatePowerSaveBlocker( | 258 std::unique_ptr<device::PowerSaveBlocker> psb(CreatePowerSaveBlocker( |
| 258 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 259 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 259 PowerSaveBlocker::kReasonOther, "Download in progress")); | 260 device::PowerSaveBlocker::kReasonOther, "Download in progress")); |
| 260 return new DownloadFileWithDelay(std::move(save_info), | 261 return new DownloadFileWithDelay(std::move(save_info), |
| 261 default_download_directory, | 262 default_download_directory, |
| 262 std::move(stream), | 263 std::move(stream), |
| 263 bound_net_log, | 264 bound_net_log, |
| 264 std::move(psb), | 265 std::move(psb), |
| 265 observer, | 266 observer, |
| 266 weak_ptr_factory_.GetWeakPtr()); | 267 weak_ptr_factory_.GetWeakPtr()); |
| 267 } | 268 } |
| 268 | 269 |
| 269 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { | 270 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 284 | 285 |
| 285 if (rename_callbacks_.empty()) { | 286 if (rename_callbacks_.empty()) { |
| 286 waiting_ = true; | 287 waiting_ = true; |
| 287 RunMessageLoop(); | 288 RunMessageLoop(); |
| 288 waiting_ = false; | 289 waiting_ = false; |
| 289 } | 290 } |
| 290 } | 291 } |
| 291 | 292 |
| 292 class CountingDownloadFile : public DownloadFileImpl { | 293 class CountingDownloadFile : public DownloadFileImpl { |
| 293 public: | 294 public: |
| 294 CountingDownloadFile(std::unique_ptr<DownloadSaveInfo> save_info, | 295 CountingDownloadFile( |
| 295 const base::FilePath& default_downloads_directory, | 296 std::unique_ptr<DownloadSaveInfo> save_info, |
| 296 std::unique_ptr<ByteStreamReader> stream, | 297 const base::FilePath& default_downloads_directory, |
| 297 const net::BoundNetLog& bound_net_log, | 298 std::unique_ptr<ByteStreamReader> stream, |
| 298 std::unique_ptr<PowerSaveBlocker> power_save_blocker, | 299 const net::BoundNetLog& bound_net_log, |
| 299 base::WeakPtr<DownloadDestinationObserver> observer) | 300 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, |
| 301 base::WeakPtr<DownloadDestinationObserver> observer) |
| 300 : DownloadFileImpl(std::move(save_info), | 302 : DownloadFileImpl(std::move(save_info), |
| 301 default_downloads_directory, | 303 default_downloads_directory, |
| 302 std::move(stream), | 304 std::move(stream), |
| 303 bound_net_log, | 305 bound_net_log, |
| 304 observer) {} | 306 observer) {} |
| 305 | 307 |
| 306 ~CountingDownloadFile() override { | 308 ~CountingDownloadFile() override { |
| 307 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 309 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 308 active_files_--; | 310 active_files_--; |
| 309 } | 311 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 CountingDownloadFileFactory() {} | 345 CountingDownloadFileFactory() {} |
| 344 ~CountingDownloadFileFactory() override {} | 346 ~CountingDownloadFileFactory() override {} |
| 345 | 347 |
| 346 // DownloadFileFactory interface. | 348 // DownloadFileFactory interface. |
| 347 DownloadFile* CreateFile( | 349 DownloadFile* CreateFile( |
| 348 std::unique_ptr<DownloadSaveInfo> save_info, | 350 std::unique_ptr<DownloadSaveInfo> save_info, |
| 349 const base::FilePath& default_downloads_directory, | 351 const base::FilePath& default_downloads_directory, |
| 350 std::unique_ptr<ByteStreamReader> stream, | 352 std::unique_ptr<ByteStreamReader> stream, |
| 351 const net::BoundNetLog& bound_net_log, | 353 const net::BoundNetLog& bound_net_log, |
| 352 base::WeakPtr<DownloadDestinationObserver> observer) override { | 354 base::WeakPtr<DownloadDestinationObserver> observer) override { |
| 353 std::unique_ptr<PowerSaveBlocker> psb(CreatePowerSaveBlocker( | 355 std::unique_ptr<device::PowerSaveBlocker> psb(CreatePowerSaveBlocker( |
| 354 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 356 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 355 PowerSaveBlocker::kReasonOther, "Download in progress")); | 357 device::PowerSaveBlocker::kReasonOther, "Download in progress")); |
| 356 return new CountingDownloadFile(std::move(save_info), | 358 return new CountingDownloadFile(std::move(save_info), |
| 357 default_downloads_directory, | 359 default_downloads_directory, |
| 358 std::move(stream), | 360 std::move(stream), |
| 359 bound_net_log, | 361 bound_net_log, |
| 360 std::move(psb), | 362 std::move(psb), |
| 361 observer); | 363 observer); |
| 362 } | 364 } |
| 363 }; | 365 }; |
| 364 | 366 |
| 365 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { | 367 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { |
| (...skipping 2100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2466 | 2468 |
| 2467 std::vector<DownloadItem*> downloads; | 2469 std::vector<DownloadItem*> downloads; |
| 2468 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 2470 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 2469 ASSERT_EQ(1u, downloads.size()); | 2471 ASSERT_EQ(1u, downloads.size()); |
| 2470 | 2472 |
| 2471 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 2473 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
| 2472 downloads[0]->GetTargetFilePath().BaseName().value()); | 2474 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 2473 } | 2475 } |
| 2474 | 2476 |
| 2475 } // namespace content | 2477 } // namespace content |
| OLD | NEW |