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