| 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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 BrowserContext::GetDownloadManager( | 128 BrowserContext::GetDownloadManager( |
| 129 shell->web_contents()->GetBrowserContext())); | 129 shell->web_contents()->GetBrowserContext())); |
| 130 } | 130 } |
| 131 | 131 |
| 132 class DownloadFileWithDelay : public DownloadFileImpl { | 132 class DownloadFileWithDelay : public DownloadFileImpl { |
| 133 public: | 133 public: |
| 134 DownloadFileWithDelay( | 134 DownloadFileWithDelay( |
| 135 std::unique_ptr<DownloadSaveInfo> save_info, | 135 std::unique_ptr<DownloadSaveInfo> save_info, |
| 136 const base::FilePath& default_download_directory, | 136 const base::FilePath& default_download_directory, |
| 137 std::unique_ptr<ByteStreamReader> stream, | 137 std::unique_ptr<ByteStreamReader> stream, |
| 138 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 138 const net::NetLogWithSource& net_log, | 139 const net::NetLogWithSource& net_log, |
| 139 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, | 140 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, |
| 140 base::WeakPtr<DownloadDestinationObserver> observer, | 141 base::WeakPtr<DownloadDestinationObserver> observer, |
| 141 base::WeakPtr<DownloadFileWithDelayFactory> owner); | 142 base::WeakPtr<DownloadFileWithDelayFactory> owner); |
| 142 | 143 |
| 143 ~DownloadFileWithDelay() override; | 144 ~DownloadFileWithDelay() override; |
| 144 | 145 |
| 145 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, | 146 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, |
| 146 // storing it in the factory that produced this object for later | 147 // storing it in the factory that produced this object for later |
| 147 // retrieval. | 148 // retrieval. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 174 class DownloadFileWithDelayFactory : public DownloadFileFactory { | 175 class DownloadFileWithDelayFactory : public DownloadFileFactory { |
| 175 public: | 176 public: |
| 176 DownloadFileWithDelayFactory(); | 177 DownloadFileWithDelayFactory(); |
| 177 ~DownloadFileWithDelayFactory() override; | 178 ~DownloadFileWithDelayFactory() override; |
| 178 | 179 |
| 179 // DownloadFileFactory interface. | 180 // DownloadFileFactory interface. |
| 180 DownloadFile* CreateFile( | 181 DownloadFile* CreateFile( |
| 181 std::unique_ptr<DownloadSaveInfo> save_info, | 182 std::unique_ptr<DownloadSaveInfo> save_info, |
| 182 const base::FilePath& default_download_directory, | 183 const base::FilePath& default_download_directory, |
| 183 std::unique_ptr<ByteStreamReader> stream, | 184 std::unique_ptr<ByteStreamReader> stream, |
| 185 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 184 const net::NetLogWithSource& net_log, | 186 const net::NetLogWithSource& net_log, |
| 185 base::WeakPtr<DownloadDestinationObserver> observer) override; | 187 base::WeakPtr<DownloadDestinationObserver> observer) override; |
| 186 | 188 |
| 187 void AddRenameCallback(base::Closure callback); | 189 void AddRenameCallback(base::Closure callback); |
| 188 void GetAllRenameCallbacks(std::vector<base::Closure>* results); | 190 void GetAllRenameCallbacks(std::vector<base::Closure>* results); |
| 189 | 191 |
| 190 // Do not return until GetAllRenameCallbacks() will return a non-empty list. | 192 // Do not return until GetAllRenameCallbacks() will return a non-empty list. |
| 191 void WaitForSomeCallback(); | 193 void WaitForSomeCallback(); |
| 192 | 194 |
| 193 private: | 195 private: |
| 194 std::vector<base::Closure> rename_callbacks_; | 196 std::vector<base::Closure> rename_callbacks_; |
| 195 bool waiting_; | 197 bool waiting_; |
| 196 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; | 198 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; |
| 197 | 199 |
| 198 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); | 200 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); |
| 199 }; | 201 }; |
| 200 | 202 |
| 201 DownloadFileWithDelay::DownloadFileWithDelay( | 203 DownloadFileWithDelay::DownloadFileWithDelay( |
| 202 std::unique_ptr<DownloadSaveInfo> save_info, | 204 std::unique_ptr<DownloadSaveInfo> save_info, |
| 203 const base::FilePath& default_download_directory, | 205 const base::FilePath& default_download_directory, |
| 204 std::unique_ptr<ByteStreamReader> stream, | 206 std::unique_ptr<ByteStreamReader> stream, |
| 207 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 205 const net::NetLogWithSource& net_log, | 208 const net::NetLogWithSource& net_log, |
| 206 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, | 209 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, |
| 207 base::WeakPtr<DownloadDestinationObserver> observer, | 210 base::WeakPtr<DownloadDestinationObserver> observer, |
| 208 base::WeakPtr<DownloadFileWithDelayFactory> owner) | 211 base::WeakPtr<DownloadFileWithDelayFactory> owner) |
| 209 : DownloadFileImpl(std::move(save_info), | 212 : DownloadFileImpl(std::move(save_info), |
| 210 default_download_directory, | 213 default_download_directory, |
| 211 std::move(stream), | 214 std::move(stream), |
| 215 received_slices, |
| 212 net_log, | 216 net_log, |
| 213 false, | 217 false, |
| 214 observer), | 218 observer), |
| 215 owner_(owner) {} | 219 owner_(owner) {} |
| 216 | 220 |
| 217 DownloadFileWithDelay::~DownloadFileWithDelay() {} | 221 DownloadFileWithDelay::~DownloadFileWithDelay() {} |
| 218 | 222 |
| 219 void DownloadFileWithDelay::RenameAndUniquify( | 223 void DownloadFileWithDelay::RenameAndUniquify( |
| 220 const base::FilePath& full_path, | 224 const base::FilePath& full_path, |
| 221 const RenameCompletionCallback& callback) { | 225 const RenameCompletionCallback& callback) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() | 260 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() |
| 257 : waiting_(false), | 261 : waiting_(false), |
| 258 weak_ptr_factory_(this) {} | 262 weak_ptr_factory_(this) {} |
| 259 | 263 |
| 260 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} | 264 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} |
| 261 | 265 |
| 262 DownloadFile* DownloadFileWithDelayFactory::CreateFile( | 266 DownloadFile* DownloadFileWithDelayFactory::CreateFile( |
| 263 std::unique_ptr<DownloadSaveInfo> save_info, | 267 std::unique_ptr<DownloadSaveInfo> save_info, |
| 264 const base::FilePath& default_download_directory, | 268 const base::FilePath& default_download_directory, |
| 265 std::unique_ptr<ByteStreamReader> stream, | 269 std::unique_ptr<ByteStreamReader> stream, |
| 270 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 266 const net::NetLogWithSource& net_log, | 271 const net::NetLogWithSource& net_log, |
| 267 base::WeakPtr<DownloadDestinationObserver> observer) { | 272 base::WeakPtr<DownloadDestinationObserver> observer) { |
| 268 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( | 273 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( |
| 269 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 274 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 270 device::PowerSaveBlocker::kReasonOther, "Download in progress", | 275 device::PowerSaveBlocker::kReasonOther, "Download in progress", |
| 271 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 276 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
| 272 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 277 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
| 273 return new DownloadFileWithDelay(std::move(save_info), | 278 return new DownloadFileWithDelay(std::move(save_info), |
| 274 default_download_directory, | 279 default_download_directory, |
| 275 std::move(stream), | 280 std::move(stream), |
| 281 received_slices, |
| 276 net_log, | 282 net_log, |
| 277 std::move(psb), | 283 std::move(psb), |
| 278 observer, | 284 observer, |
| 279 weak_ptr_factory_.GetWeakPtr()); | 285 weak_ptr_factory_.GetWeakPtr()); |
| 280 } | 286 } |
| 281 | 287 |
| 282 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { | 288 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { |
| 283 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 289 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 284 rename_callbacks_.push_back(callback); | 290 rename_callbacks_.push_back(callback); |
| 285 if (waiting_) | 291 if (waiting_) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 301 waiting_ = false; | 307 waiting_ = false; |
| 302 } | 308 } |
| 303 } | 309 } |
| 304 | 310 |
| 305 class CountingDownloadFile : public DownloadFileImpl { | 311 class CountingDownloadFile : public DownloadFileImpl { |
| 306 public: | 312 public: |
| 307 CountingDownloadFile( | 313 CountingDownloadFile( |
| 308 std::unique_ptr<DownloadSaveInfo> save_info, | 314 std::unique_ptr<DownloadSaveInfo> save_info, |
| 309 const base::FilePath& default_downloads_directory, | 315 const base::FilePath& default_downloads_directory, |
| 310 std::unique_ptr<ByteStreamReader> stream, | 316 std::unique_ptr<ByteStreamReader> stream, |
| 317 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 311 const net::NetLogWithSource& net_log, | 318 const net::NetLogWithSource& net_log, |
| 312 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, | 319 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, |
| 313 base::WeakPtr<DownloadDestinationObserver> observer) | 320 base::WeakPtr<DownloadDestinationObserver> observer) |
| 314 : DownloadFileImpl(std::move(save_info), | 321 : DownloadFileImpl(std::move(save_info), |
| 315 default_downloads_directory, | 322 default_downloads_directory, |
| 316 std::move(stream), | 323 std::move(stream), |
| 324 received_slices, |
| 317 net_log, | 325 net_log, |
| 318 false, | 326 false, |
| 319 observer) {} | 327 observer) {} |
| 320 | 328 |
| 321 ~CountingDownloadFile() override { | 329 ~CountingDownloadFile() override { |
| 322 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 330 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 323 active_files_--; | 331 active_files_--; |
| 324 } | 332 } |
| 325 | 333 |
| 326 void Initialize(const InitializeCallback& callback) override { | 334 void Initialize(const InitializeCallback& callback) override { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 356 class CountingDownloadFileFactory : public DownloadFileFactory { | 364 class CountingDownloadFileFactory : public DownloadFileFactory { |
| 357 public: | 365 public: |
| 358 CountingDownloadFileFactory() {} | 366 CountingDownloadFileFactory() {} |
| 359 ~CountingDownloadFileFactory() override {} | 367 ~CountingDownloadFileFactory() override {} |
| 360 | 368 |
| 361 // DownloadFileFactory interface. | 369 // DownloadFileFactory interface. |
| 362 DownloadFile* CreateFile( | 370 DownloadFile* CreateFile( |
| 363 std::unique_ptr<DownloadSaveInfo> save_info, | 371 std::unique_ptr<DownloadSaveInfo> save_info, |
| 364 const base::FilePath& default_downloads_directory, | 372 const base::FilePath& default_downloads_directory, |
| 365 std::unique_ptr<ByteStreamReader> stream, | 373 std::unique_ptr<ByteStreamReader> stream, |
| 374 const std::vector<DownloadItem::ReceivedSlice>& received_slices, |
| 366 const net::NetLogWithSource& net_log, | 375 const net::NetLogWithSource& net_log, |
| 367 base::WeakPtr<DownloadDestinationObserver> observer) override { | 376 base::WeakPtr<DownloadDestinationObserver> observer) override { |
| 368 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( | 377 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( |
| 369 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 378 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 370 device::PowerSaveBlocker::kReasonOther, "Download in progress", | 379 device::PowerSaveBlocker::kReasonOther, "Download in progress", |
| 371 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 380 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
| 372 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 381 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
| 373 return new CountingDownloadFile(std::move(save_info), | 382 return new CountingDownloadFile(std::move(save_info), |
| 374 default_downloads_directory, | 383 default_downloads_directory, |
| 375 std::move(stream), | 384 std::move(stream), |
| 385 received_slices, |
| 376 net_log, | 386 net_log, |
| 377 std::move(psb), | 387 std::move(psb), |
| 378 observer); | 388 observer); |
| 379 } | 389 } |
| 380 }; | 390 }; |
| 381 | 391 |
| 382 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { | 392 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { |
| 383 public: | 393 public: |
| 384 TestShellDownloadManagerDelegate() | 394 TestShellDownloadManagerDelegate() |
| 385 : delay_download_open_(false) {} | 395 : delay_download_open_(false) {} |
| (...skipping 2260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2646 GURL document_url = | 2656 GURL document_url = |
| 2647 origin_two.GetURL("/iframe-host.html?target=" + frame_url.spec()); | 2657 origin_two.GetURL("/iframe-host.html?target=" + frame_url.spec()); |
| 2648 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); | 2658 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); |
| 2649 WaitForCompletion(download); | 2659 WaitForCompletion(download); |
| 2650 | 2660 |
| 2651 EXPECT_STREQ(FILE_PATH_LITERAL("download-test.lib"), | 2661 EXPECT_STREQ(FILE_PATH_LITERAL("download-test.lib"), |
| 2652 download->GetTargetFilePath().BaseName().value().c_str()); | 2662 download->GetTargetFilePath().BaseName().value().c_str()); |
| 2653 } | 2663 } |
| 2654 | 2664 |
| 2655 } // namespace content | 2665 } // namespace content |
| OLD | NEW |