| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 #include "content/public/test/content_browser_test_utils.h" | 50 #include "content/public/test/content_browser_test_utils.h" |
| 51 #include "content/public/test/download_test_observer.h" | 51 #include "content/public/test/download_test_observer.h" |
| 52 #include "content/public/test/test_download_request_handler.h" | 52 #include "content/public/test/test_download_request_handler.h" |
| 53 #include "content/public/test/test_file_error_injector.h" | 53 #include "content/public/test/test_file_error_injector.h" |
| 54 #include "content/public/test/test_utils.h" | 54 #include "content/public/test/test_utils.h" |
| 55 #include "content/shell/browser/shell.h" | 55 #include "content/shell/browser/shell.h" |
| 56 #include "content/shell/browser/shell_browser_context.h" | 56 #include "content/shell/browser/shell_browser_context.h" |
| 57 #include "content/shell/browser/shell_download_manager_delegate.h" | 57 #include "content/shell/browser/shell_download_manager_delegate.h" |
| 58 #include "content/shell/browser/shell_network_delegate.h" | 58 #include "content/shell/browser/shell_network_delegate.h" |
| 59 #include "content/test/content_browser_test_utils_internal.h" | 59 #include "content/test/content_browser_test_utils_internal.h" |
| 60 #include "device/power_save_blocker/power_save_blocker.h" | |
| 61 #include "net/dns/mock_host_resolver.h" | 60 #include "net/dns/mock_host_resolver.h" |
| 62 #include "net/test/embedded_test_server/embedded_test_server.h" | 61 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 63 #include "net/test/embedded_test_server/http_request.h" | 62 #include "net/test/embedded_test_server/http_request.h" |
| 64 #include "net/test/embedded_test_server/http_response.h" | 63 #include "net/test/embedded_test_server/http_response.h" |
| 65 #include "net/test/url_request/url_request_mock_http_job.h" | 64 #include "net/test/url_request/url_request_mock_http_job.h" |
| 66 #include "net/test/url_request/url_request_slow_download_job.h" | 65 #include "net/test/url_request/url_request_slow_download_job.h" |
| 67 #include "ppapi/features/features.h" | 66 #include "ppapi/features/features.h" |
| 68 #include "testing/gmock/include/gmock/gmock.h" | 67 #include "testing/gmock/include/gmock/gmock.h" |
| 69 #include "testing/gtest/include/gtest/gtest.h" | 68 #include "testing/gtest/include/gtest/gtest.h" |
| 70 #include "url/gurl.h" | 69 #include "url/gurl.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 shell->web_contents()->GetBrowserContext())); | 141 shell->web_contents()->GetBrowserContext())); |
| 143 } | 142 } |
| 144 | 143 |
| 145 class DownloadFileWithDelay : public DownloadFileImpl { | 144 class DownloadFileWithDelay : public DownloadFileImpl { |
| 146 public: | 145 public: |
| 147 DownloadFileWithDelay( | 146 DownloadFileWithDelay( |
| 148 std::unique_ptr<DownloadSaveInfo> save_info, | 147 std::unique_ptr<DownloadSaveInfo> save_info, |
| 149 const base::FilePath& default_download_directory, | 148 const base::FilePath& default_download_directory, |
| 150 std::unique_ptr<ByteStreamReader> stream, | 149 std::unique_ptr<ByteStreamReader> stream, |
| 151 const net::NetLogWithSource& net_log, | 150 const net::NetLogWithSource& net_log, |
| 152 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, | |
| 153 base::WeakPtr<DownloadDestinationObserver> observer, | 151 base::WeakPtr<DownloadDestinationObserver> observer, |
| 154 base::WeakPtr<DownloadFileWithDelayFactory> owner); | 152 base::WeakPtr<DownloadFileWithDelayFactory> owner); |
| 155 | 153 |
| 156 ~DownloadFileWithDelay() override; | 154 ~DownloadFileWithDelay() override; |
| 157 | 155 |
| 158 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, | 156 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, |
| 159 // storing it in the factory that produced this object for later | 157 // storing it in the factory that produced this object for later |
| 160 // retrieval. | 158 // retrieval. |
| 161 void RenameAndUniquify(const base::FilePath& full_path, | 159 void RenameAndUniquify(const base::FilePath& full_path, |
| 162 const RenameCompletionCallback& callback) override; | 160 const RenameCompletionCallback& callback) override; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; | 207 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; |
| 210 | 208 |
| 211 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); | 209 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); |
| 212 }; | 210 }; |
| 213 | 211 |
| 214 DownloadFileWithDelay::DownloadFileWithDelay( | 212 DownloadFileWithDelay::DownloadFileWithDelay( |
| 215 std::unique_ptr<DownloadSaveInfo> save_info, | 213 std::unique_ptr<DownloadSaveInfo> save_info, |
| 216 const base::FilePath& default_download_directory, | 214 const base::FilePath& default_download_directory, |
| 217 std::unique_ptr<ByteStreamReader> stream, | 215 std::unique_ptr<ByteStreamReader> stream, |
| 218 const net::NetLogWithSource& net_log, | 216 const net::NetLogWithSource& net_log, |
| 219 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, | |
| 220 base::WeakPtr<DownloadDestinationObserver> observer, | 217 base::WeakPtr<DownloadDestinationObserver> observer, |
| 221 base::WeakPtr<DownloadFileWithDelayFactory> owner) | 218 base::WeakPtr<DownloadFileWithDelayFactory> owner) |
| 222 : DownloadFileImpl(std::move(save_info), | 219 : DownloadFileImpl(std::move(save_info), |
| 223 default_download_directory, | 220 default_download_directory, |
| 224 std::move(stream), | 221 std::move(stream), |
| 225 net_log, | 222 net_log, |
| 226 observer), | 223 observer), |
| 227 owner_(owner) {} | 224 owner_(owner) {} |
| 228 | 225 |
| 229 DownloadFileWithDelay::~DownloadFileWithDelay() {} | 226 DownloadFileWithDelay::~DownloadFileWithDelay() {} |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 weak_ptr_factory_(this) {} | 267 weak_ptr_factory_(this) {} |
| 271 | 268 |
| 272 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} | 269 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} |
| 273 | 270 |
| 274 DownloadFile* DownloadFileWithDelayFactory::CreateFile( | 271 DownloadFile* DownloadFileWithDelayFactory::CreateFile( |
| 275 std::unique_ptr<DownloadSaveInfo> save_info, | 272 std::unique_ptr<DownloadSaveInfo> save_info, |
| 276 const base::FilePath& default_download_directory, | 273 const base::FilePath& default_download_directory, |
| 277 std::unique_ptr<ByteStreamReader> stream, | 274 std::unique_ptr<ByteStreamReader> stream, |
| 278 const net::NetLogWithSource& net_log, | 275 const net::NetLogWithSource& net_log, |
| 279 base::WeakPtr<DownloadDestinationObserver> observer) { | 276 base::WeakPtr<DownloadDestinationObserver> observer) { |
| 280 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( | |
| 281 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | |
| 282 device::PowerSaveBlocker::kReasonOther, "Download in progress", | |
| 283 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | |
| 284 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | |
| 285 return new DownloadFileWithDelay(std::move(save_info), | 277 return new DownloadFileWithDelay(std::move(save_info), |
| 286 default_download_directory, | 278 default_download_directory, |
| 287 std::move(stream), | 279 std::move(stream), |
| 288 net_log, | 280 net_log, |
| 289 std::move(psb), | |
| 290 observer, | 281 observer, |
| 291 weak_ptr_factory_.GetWeakPtr()); | 282 weak_ptr_factory_.GetWeakPtr()); |
| 292 } | 283 } |
| 293 | 284 |
| 294 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { | 285 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { |
| 295 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 286 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 296 rename_callbacks_.push_back(callback); | 287 rename_callbacks_.push_back(callback); |
| 297 if (waiting_) | 288 if (waiting_) |
| 298 base::MessageLoopForUI::current()->QuitWhenIdle(); | 289 base::MessageLoopForUI::current()->QuitWhenIdle(); |
| 299 } | 290 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 314 } | 305 } |
| 315 } | 306 } |
| 316 | 307 |
| 317 class CountingDownloadFile : public DownloadFileImpl { | 308 class CountingDownloadFile : public DownloadFileImpl { |
| 318 public: | 309 public: |
| 319 CountingDownloadFile( | 310 CountingDownloadFile( |
| 320 std::unique_ptr<DownloadSaveInfo> save_info, | 311 std::unique_ptr<DownloadSaveInfo> save_info, |
| 321 const base::FilePath& default_downloads_directory, | 312 const base::FilePath& default_downloads_directory, |
| 322 std::unique_ptr<ByteStreamReader> stream, | 313 std::unique_ptr<ByteStreamReader> stream, |
| 323 const net::NetLogWithSource& net_log, | 314 const net::NetLogWithSource& net_log, |
| 324 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, | |
| 325 base::WeakPtr<DownloadDestinationObserver> observer) | 315 base::WeakPtr<DownloadDestinationObserver> observer) |
| 326 : DownloadFileImpl(std::move(save_info), | 316 : DownloadFileImpl(std::move(save_info), |
| 327 default_downloads_directory, | 317 default_downloads_directory, |
| 328 std::move(stream), | 318 std::move(stream), |
| 329 net_log, | 319 net_log, |
| 330 observer) {} | 320 observer) {} |
| 331 | 321 |
| 332 ~CountingDownloadFile() override { | 322 ~CountingDownloadFile() override { |
| 333 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 323 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 334 active_files_--; | 324 active_files_--; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 CountingDownloadFileFactory() {} | 364 CountingDownloadFileFactory() {} |
| 375 ~CountingDownloadFileFactory() override {} | 365 ~CountingDownloadFileFactory() override {} |
| 376 | 366 |
| 377 // DownloadFileFactory interface. | 367 // DownloadFileFactory interface. |
| 378 DownloadFile* CreateFile( | 368 DownloadFile* CreateFile( |
| 379 std::unique_ptr<DownloadSaveInfo> save_info, | 369 std::unique_ptr<DownloadSaveInfo> save_info, |
| 380 const base::FilePath& default_downloads_directory, | 370 const base::FilePath& default_downloads_directory, |
| 381 std::unique_ptr<ByteStreamReader> stream, | 371 std::unique_ptr<ByteStreamReader> stream, |
| 382 const net::NetLogWithSource& net_log, | 372 const net::NetLogWithSource& net_log, |
| 383 base::WeakPtr<DownloadDestinationObserver> observer) override { | 373 base::WeakPtr<DownloadDestinationObserver> observer) override { |
| 384 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( | |
| 385 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | |
| 386 device::PowerSaveBlocker::kReasonOther, "Download in progress", | |
| 387 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | |
| 388 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | |
| 389 return new CountingDownloadFile(std::move(save_info), | 374 return new CountingDownloadFile(std::move(save_info), |
| 390 default_downloads_directory, | 375 default_downloads_directory, |
| 391 std::move(stream), | 376 std::move(stream), |
| 392 net_log, | 377 net_log, |
| 393 std::move(psb), | |
| 394 observer); | 378 observer); |
| 395 } | 379 } |
| 396 }; | 380 }; |
| 397 | 381 |
| 398 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { | 382 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { |
| 399 public: | 383 public: |
| 400 TestShellDownloadManagerDelegate() | 384 TestShellDownloadManagerDelegate() |
| 401 : delay_download_open_(false) {} | 385 : delay_download_open_(false) {} |
| 402 ~TestShellDownloadManagerDelegate() override {} | 386 ~TestShellDownloadManagerDelegate() override {} |
| 403 | 387 |
| (...skipping 2335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2739 | 2723 |
| 2740 std::vector<DownloadItem*> downloads; | 2724 std::vector<DownloadItem*> downloads; |
| 2741 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 2725 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 2742 ASSERT_EQ(1u, downloads.size()); | 2726 ASSERT_EQ(1u, downloads.size()); |
| 2743 | 2727 |
| 2744 EXPECT_EQ(FILE_PATH_LITERAL("foo"), | 2728 EXPECT_EQ(FILE_PATH_LITERAL("foo"), |
| 2745 downloads[0]->GetTargetFilePath().BaseName().value()); | 2729 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 2746 } | 2730 } |
| 2747 | 2731 |
| 2748 } // namespace content | 2732 } // namespace content |
| OLD | NEW |