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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 BrowserContext::GetDownloadManager( | 121 BrowserContext::GetDownloadManager( |
122 shell->web_contents()->GetBrowserContext())); | 122 shell->web_contents()->GetBrowserContext())); |
123 } | 123 } |
124 | 124 |
125 class DownloadFileWithDelay : public DownloadFileImpl { | 125 class DownloadFileWithDelay : public DownloadFileImpl { |
126 public: | 126 public: |
127 DownloadFileWithDelay( | 127 DownloadFileWithDelay( |
128 std::unique_ptr<DownloadSaveInfo> save_info, | 128 std::unique_ptr<DownloadSaveInfo> save_info, |
129 const base::FilePath& default_download_directory, | 129 const base::FilePath& default_download_directory, |
130 std::unique_ptr<ByteStreamReader> stream, | 130 std::unique_ptr<ByteStreamReader> stream, |
131 const net::BoundNetLog& bound_net_log, | 131 const net::NetLogWithSource& net_log, |
132 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, | 132 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, |
133 base::WeakPtr<DownloadDestinationObserver> observer, | 133 base::WeakPtr<DownloadDestinationObserver> observer, |
134 base::WeakPtr<DownloadFileWithDelayFactory> owner); | 134 base::WeakPtr<DownloadFileWithDelayFactory> owner); |
135 | 135 |
136 ~DownloadFileWithDelay() override; | 136 ~DownloadFileWithDelay() override; |
137 | 137 |
138 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, | 138 // Wraps DownloadFileImpl::Rename* and intercepts the return callback, |
139 // storing it in the factory that produced this object for later | 139 // storing it in the factory that produced this object for later |
140 // retrieval. | 140 // retrieval. |
141 void RenameAndUniquify(const base::FilePath& full_path, | 141 void RenameAndUniquify(const base::FilePath& full_path, |
(...skipping 25 matching lines...) Expand all Loading... |
167 class DownloadFileWithDelayFactory : public DownloadFileFactory { | 167 class DownloadFileWithDelayFactory : public DownloadFileFactory { |
168 public: | 168 public: |
169 DownloadFileWithDelayFactory(); | 169 DownloadFileWithDelayFactory(); |
170 ~DownloadFileWithDelayFactory() override; | 170 ~DownloadFileWithDelayFactory() override; |
171 | 171 |
172 // DownloadFileFactory interface. | 172 // DownloadFileFactory interface. |
173 DownloadFile* CreateFile( | 173 DownloadFile* CreateFile( |
174 std::unique_ptr<DownloadSaveInfo> save_info, | 174 std::unique_ptr<DownloadSaveInfo> save_info, |
175 const base::FilePath& default_download_directory, | 175 const base::FilePath& default_download_directory, |
176 std::unique_ptr<ByteStreamReader> stream, | 176 std::unique_ptr<ByteStreamReader> stream, |
177 const net::BoundNetLog& bound_net_log, | 177 const net::NetLogWithSource& net_log, |
178 base::WeakPtr<DownloadDestinationObserver> observer) override; | 178 base::WeakPtr<DownloadDestinationObserver> observer) override; |
179 | 179 |
180 void AddRenameCallback(base::Closure callback); | 180 void AddRenameCallback(base::Closure callback); |
181 void GetAllRenameCallbacks(std::vector<base::Closure>* results); | 181 void GetAllRenameCallbacks(std::vector<base::Closure>* results); |
182 | 182 |
183 // Do not return until GetAllRenameCallbacks() will return a non-empty list. | 183 // Do not return until GetAllRenameCallbacks() will return a non-empty list. |
184 void WaitForSomeCallback(); | 184 void WaitForSomeCallback(); |
185 | 185 |
186 private: | 186 private: |
187 std::vector<base::Closure> rename_callbacks_; | 187 std::vector<base::Closure> rename_callbacks_; |
188 bool waiting_; | 188 bool waiting_; |
189 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; | 189 base::WeakPtrFactory<DownloadFileWithDelayFactory> weak_ptr_factory_; |
190 | 190 |
191 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); | 191 DISALLOW_COPY_AND_ASSIGN(DownloadFileWithDelayFactory); |
192 }; | 192 }; |
193 | 193 |
194 DownloadFileWithDelay::DownloadFileWithDelay( | 194 DownloadFileWithDelay::DownloadFileWithDelay( |
195 std::unique_ptr<DownloadSaveInfo> save_info, | 195 std::unique_ptr<DownloadSaveInfo> save_info, |
196 const base::FilePath& default_download_directory, | 196 const base::FilePath& default_download_directory, |
197 std::unique_ptr<ByteStreamReader> stream, | 197 std::unique_ptr<ByteStreamReader> stream, |
198 const net::BoundNetLog& bound_net_log, | 198 const net::NetLogWithSource& net_log, |
199 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, | 199 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, |
200 base::WeakPtr<DownloadDestinationObserver> observer, | 200 base::WeakPtr<DownloadDestinationObserver> observer, |
201 base::WeakPtr<DownloadFileWithDelayFactory> owner) | 201 base::WeakPtr<DownloadFileWithDelayFactory> owner) |
202 : DownloadFileImpl(std::move(save_info), | 202 : DownloadFileImpl(std::move(save_info), |
203 default_download_directory, | 203 default_download_directory, |
204 std::move(stream), | 204 std::move(stream), |
205 bound_net_log, | 205 net_log, |
206 observer), | 206 observer), |
207 owner_(owner) {} | 207 owner_(owner) {} |
208 | 208 |
209 DownloadFileWithDelay::~DownloadFileWithDelay() {} | 209 DownloadFileWithDelay::~DownloadFileWithDelay() {} |
210 | 210 |
211 void DownloadFileWithDelay::RenameAndUniquify( | 211 void DownloadFileWithDelay::RenameAndUniquify( |
212 const base::FilePath& full_path, | 212 const base::FilePath& full_path, |
213 const RenameCompletionCallback& callback) { | 213 const RenameCompletionCallback& callback) { |
214 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 214 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
215 DownloadFileImpl::RenameAndUniquify( | 215 DownloadFileImpl::RenameAndUniquify( |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() | 248 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() |
249 : waiting_(false), | 249 : waiting_(false), |
250 weak_ptr_factory_(this) {} | 250 weak_ptr_factory_(this) {} |
251 | 251 |
252 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} | 252 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} |
253 | 253 |
254 DownloadFile* DownloadFileWithDelayFactory::CreateFile( | 254 DownloadFile* DownloadFileWithDelayFactory::CreateFile( |
255 std::unique_ptr<DownloadSaveInfo> save_info, | 255 std::unique_ptr<DownloadSaveInfo> save_info, |
256 const base::FilePath& default_download_directory, | 256 const base::FilePath& default_download_directory, |
257 std::unique_ptr<ByteStreamReader> stream, | 257 std::unique_ptr<ByteStreamReader> stream, |
258 const net::BoundNetLog& bound_net_log, | 258 const net::NetLogWithSource& net_log, |
259 base::WeakPtr<DownloadDestinationObserver> observer) { | 259 base::WeakPtr<DownloadDestinationObserver> observer) { |
260 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( | 260 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( |
261 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 261 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
262 device::PowerSaveBlocker::kReasonOther, "Download in progress", | 262 device::PowerSaveBlocker::kReasonOther, "Download in progress", |
263 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 263 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
264 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 264 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
265 return new DownloadFileWithDelay(std::move(save_info), | 265 return new DownloadFileWithDelay(std::move(save_info), |
266 default_download_directory, | 266 default_download_directory, |
267 std::move(stream), | 267 std::move(stream), |
268 bound_net_log, | 268 net_log, |
269 std::move(psb), | 269 std::move(psb), |
270 observer, | 270 observer, |
271 weak_ptr_factory_.GetWeakPtr()); | 271 weak_ptr_factory_.GetWeakPtr()); |
272 } | 272 } |
273 | 273 |
274 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { | 274 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { |
275 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 275 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
276 rename_callbacks_.push_back(callback); | 276 rename_callbacks_.push_back(callback); |
277 if (waiting_) | 277 if (waiting_) |
278 base::MessageLoopForUI::current()->QuitWhenIdle(); | 278 base::MessageLoopForUI::current()->QuitWhenIdle(); |
(...skipping 14 matching lines...) Expand all Loading... |
293 waiting_ = false; | 293 waiting_ = false; |
294 } | 294 } |
295 } | 295 } |
296 | 296 |
297 class CountingDownloadFile : public DownloadFileImpl { | 297 class CountingDownloadFile : public DownloadFileImpl { |
298 public: | 298 public: |
299 CountingDownloadFile( | 299 CountingDownloadFile( |
300 std::unique_ptr<DownloadSaveInfo> save_info, | 300 std::unique_ptr<DownloadSaveInfo> save_info, |
301 const base::FilePath& default_downloads_directory, | 301 const base::FilePath& default_downloads_directory, |
302 std::unique_ptr<ByteStreamReader> stream, | 302 std::unique_ptr<ByteStreamReader> stream, |
303 const net::BoundNetLog& bound_net_log, | 303 const net::NetLogWithSource& net_log, |
304 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, | 304 std::unique_ptr<device::PowerSaveBlocker> power_save_blocker, |
305 base::WeakPtr<DownloadDestinationObserver> observer) | 305 base::WeakPtr<DownloadDestinationObserver> observer) |
306 : DownloadFileImpl(std::move(save_info), | 306 : DownloadFileImpl(std::move(save_info), |
307 default_downloads_directory, | 307 default_downloads_directory, |
308 std::move(stream), | 308 std::move(stream), |
309 bound_net_log, | 309 net_log, |
310 observer) {} | 310 observer) {} |
311 | 311 |
312 ~CountingDownloadFile() override { | 312 ~CountingDownloadFile() override { |
313 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 313 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
314 active_files_--; | 314 active_files_--; |
315 } | 315 } |
316 | 316 |
317 void Initialize(const InitializeCallback& callback) override { | 317 void Initialize(const InitializeCallback& callback) override { |
318 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 318 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
319 active_files_++; | 319 active_files_++; |
(...skipping 27 matching lines...) Expand all Loading... |
347 class CountingDownloadFileFactory : public DownloadFileFactory { | 347 class CountingDownloadFileFactory : public DownloadFileFactory { |
348 public: | 348 public: |
349 CountingDownloadFileFactory() {} | 349 CountingDownloadFileFactory() {} |
350 ~CountingDownloadFileFactory() override {} | 350 ~CountingDownloadFileFactory() override {} |
351 | 351 |
352 // DownloadFileFactory interface. | 352 // DownloadFileFactory interface. |
353 DownloadFile* CreateFile( | 353 DownloadFile* CreateFile( |
354 std::unique_ptr<DownloadSaveInfo> save_info, | 354 std::unique_ptr<DownloadSaveInfo> save_info, |
355 const base::FilePath& default_downloads_directory, | 355 const base::FilePath& default_downloads_directory, |
356 std::unique_ptr<ByteStreamReader> stream, | 356 std::unique_ptr<ByteStreamReader> stream, |
357 const net::BoundNetLog& bound_net_log, | 357 const net::NetLogWithSource& net_log, |
358 base::WeakPtr<DownloadDestinationObserver> observer) override { | 358 base::WeakPtr<DownloadDestinationObserver> observer) override { |
359 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( | 359 std::unique_ptr<device::PowerSaveBlocker> psb(new device::PowerSaveBlocker( |
360 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 360 device::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
361 device::PowerSaveBlocker::kReasonOther, "Download in progress", | 361 device::PowerSaveBlocker::kReasonOther, "Download in progress", |
362 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | 362 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), |
363 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 363 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
364 return new CountingDownloadFile(std::move(save_info), | 364 return new CountingDownloadFile(std::move(save_info), |
365 default_downloads_directory, | 365 default_downloads_directory, |
366 std::move(stream), | 366 std::move(stream), |
367 bound_net_log, | 367 net_log, |
368 std::move(psb), | 368 std::move(psb), |
369 observer); | 369 observer); |
370 } | 370 } |
371 }; | 371 }; |
372 | 372 |
373 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { | 373 class TestShellDownloadManagerDelegate : public ShellDownloadManagerDelegate { |
374 public: | 374 public: |
375 TestShellDownloadManagerDelegate() | 375 TestShellDownloadManagerDelegate() |
376 : delay_download_open_(false) {} | 376 : delay_download_open_(false) {} |
377 ~TestShellDownloadManagerDelegate() override {} | 377 ~TestShellDownloadManagerDelegate() override {} |
(...skipping 2166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2544 GURL document_url = | 2544 GURL document_url = |
2545 origin_two.GetURL("/iframe-host.html?target=" + frame_url.spec()); | 2545 origin_two.GetURL("/iframe-host.html?target=" + frame_url.spec()); |
2546 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); | 2546 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); |
2547 WaitForCompletion(download); | 2547 WaitForCompletion(download); |
2548 | 2548 |
2549 EXPECT_STREQ(FILE_PATH_LITERAL("download-test.lib"), | 2549 EXPECT_STREQ(FILE_PATH_LITERAL("download-test.lib"), |
2550 download->GetTargetFilePath().BaseName().value().c_str()); | 2550 download->GetTargetFilePath().BaseName().value().c_str()); |
2551 } | 2551 } |
2552 | 2552 |
2553 } // namespace content | 2553 } // namespace content |
OLD | NEW |