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 "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 : DownloadFileImpl( | 194 : DownloadFileImpl( |
195 save_info.Pass(), default_download_directory, url, referrer_url, | 195 save_info.Pass(), default_download_directory, url, referrer_url, |
196 calculate_hash, stream.Pass(), bound_net_log, observer), | 196 calculate_hash, stream.Pass(), bound_net_log, observer), |
197 owner_(owner) {} | 197 owner_(owner) {} |
198 | 198 |
199 DownloadFileWithDelay::~DownloadFileWithDelay() {} | 199 DownloadFileWithDelay::~DownloadFileWithDelay() {} |
200 | 200 |
201 void DownloadFileWithDelay::RenameAndUniquify( | 201 void DownloadFileWithDelay::RenameAndUniquify( |
202 const base::FilePath& full_path, | 202 const base::FilePath& full_path, |
203 const RenameCompletionCallback& callback) { | 203 const RenameCompletionCallback& callback) { |
204 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 204 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
205 DownloadFileImpl::RenameAndUniquify( | 205 DownloadFileImpl::RenameAndUniquify( |
206 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, | 206 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, |
207 owner_, callback)); | 207 owner_, callback)); |
208 } | 208 } |
209 | 209 |
210 void DownloadFileWithDelay::RenameAndAnnotate( | 210 void DownloadFileWithDelay::RenameAndAnnotate( |
211 const base::FilePath& full_path, const RenameCompletionCallback& callback) { | 211 const base::FilePath& full_path, const RenameCompletionCallback& callback) { |
212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 212 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
213 DownloadFileImpl::RenameAndAnnotate( | 213 DownloadFileImpl::RenameAndAnnotate( |
214 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, | 214 full_path, base::Bind(DownloadFileWithDelay::RenameCallbackWrapper, |
215 owner_, callback)); | 215 owner_, callback)); |
216 } | 216 } |
217 | 217 |
218 // static | 218 // static |
219 void DownloadFileWithDelay::RenameCallbackWrapper( | 219 void DownloadFileWithDelay::RenameCallbackWrapper( |
220 const base::WeakPtr<DownloadFileWithDelayFactory>& factory, | 220 const base::WeakPtr<DownloadFileWithDelayFactory>& factory, |
221 const RenameCompletionCallback& original_callback, | 221 const RenameCompletionCallback& original_callback, |
222 DownloadInterruptReason reason, | 222 DownloadInterruptReason reason, |
223 const base::FilePath& path) { | 223 const base::FilePath& path) { |
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 224 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
225 if (!factory) | 225 if (!factory) |
226 return; | 226 return; |
227 factory->AddRenameCallback(base::Bind(original_callback, reason, path)); | 227 factory->AddRenameCallback(base::Bind(original_callback, reason, path)); |
228 } | 228 } |
229 | 229 |
230 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() | 230 DownloadFileWithDelayFactory::DownloadFileWithDelayFactory() |
231 : waiting_(false), | 231 : waiting_(false), |
232 weak_ptr_factory_(this) {} | 232 weak_ptr_factory_(this) {} |
233 | 233 |
234 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} | 234 DownloadFileWithDelayFactory::~DownloadFileWithDelayFactory() {} |
(...skipping 10 matching lines...) Expand all Loading... |
245 scoped_ptr<PowerSaveBlocker> psb(PowerSaveBlocker::Create( | 245 scoped_ptr<PowerSaveBlocker> psb(PowerSaveBlocker::Create( |
246 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 246 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
247 PowerSaveBlocker::kReasonOther, "Download in progress")); | 247 PowerSaveBlocker::kReasonOther, "Download in progress")); |
248 return new DownloadFileWithDelay( | 248 return new DownloadFileWithDelay( |
249 save_info.Pass(), default_download_directory, url, referrer_url, | 249 save_info.Pass(), default_download_directory, url, referrer_url, |
250 calculate_hash, stream.Pass(), bound_net_log, | 250 calculate_hash, stream.Pass(), bound_net_log, |
251 psb.Pass(), observer, weak_ptr_factory_.GetWeakPtr()); | 251 psb.Pass(), observer, weak_ptr_factory_.GetWeakPtr()); |
252 } | 252 } |
253 | 253 |
254 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { | 254 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { |
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 255 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
256 rename_callbacks_.push_back(callback); | 256 rename_callbacks_.push_back(callback); |
257 if (waiting_) | 257 if (waiting_) |
258 base::MessageLoopForUI::current()->Quit(); | 258 base::MessageLoopForUI::current()->Quit(); |
259 } | 259 } |
260 | 260 |
261 void DownloadFileWithDelayFactory::GetAllRenameCallbacks( | 261 void DownloadFileWithDelayFactory::GetAllRenameCallbacks( |
262 std::vector<base::Closure>* results) { | 262 std::vector<base::Closure>* results) { |
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 263 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
264 results->swap(rename_callbacks_); | 264 results->swap(rename_callbacks_); |
265 } | 265 } |
266 | 266 |
267 void DownloadFileWithDelayFactory::WaitForSomeCallback() { | 267 void DownloadFileWithDelayFactory::WaitForSomeCallback() { |
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 268 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
269 | 269 |
270 if (rename_callbacks_.empty()) { | 270 if (rename_callbacks_.empty()) { |
271 waiting_ = true; | 271 waiting_ = true; |
272 RunMessageLoop(); | 272 RunMessageLoop(); |
273 waiting_ = false; | 273 waiting_ = false; |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 class CountingDownloadFile : public DownloadFileImpl { | 277 class CountingDownloadFile : public DownloadFileImpl { |
278 public: | 278 public: |
279 CountingDownloadFile( | 279 CountingDownloadFile( |
280 scoped_ptr<DownloadSaveInfo> save_info, | 280 scoped_ptr<DownloadSaveInfo> save_info, |
281 const base::FilePath& default_downloads_directory, | 281 const base::FilePath& default_downloads_directory, |
282 const GURL& url, | 282 const GURL& url, |
283 const GURL& referrer_url, | 283 const GURL& referrer_url, |
284 bool calculate_hash, | 284 bool calculate_hash, |
285 scoped_ptr<ByteStreamReader> stream, | 285 scoped_ptr<ByteStreamReader> stream, |
286 const net::BoundNetLog& bound_net_log, | 286 const net::BoundNetLog& bound_net_log, |
287 scoped_ptr<PowerSaveBlocker> power_save_blocker, | 287 scoped_ptr<PowerSaveBlocker> power_save_blocker, |
288 base::WeakPtr<DownloadDestinationObserver> observer) | 288 base::WeakPtr<DownloadDestinationObserver> observer) |
289 : DownloadFileImpl(save_info.Pass(), default_downloads_directory, | 289 : DownloadFileImpl(save_info.Pass(), default_downloads_directory, |
290 url, referrer_url, calculate_hash, | 290 url, referrer_url, calculate_hash, |
291 stream.Pass(), bound_net_log, observer) {} | 291 stream.Pass(), bound_net_log, observer) {} |
292 | 292 |
293 ~CountingDownloadFile() override { | 293 ~CountingDownloadFile() override { |
294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 294 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
295 active_files_--; | 295 active_files_--; |
296 } | 296 } |
297 | 297 |
298 void Initialize(const InitializeCallback& callback) override { | 298 void Initialize(const InitializeCallback& callback) override { |
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 299 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
300 active_files_++; | 300 active_files_++; |
301 return DownloadFileImpl::Initialize(callback); | 301 return DownloadFileImpl::Initialize(callback); |
302 } | 302 } |
303 | 303 |
304 static void GetNumberActiveFiles(int* result) { | 304 static void GetNumberActiveFiles(int* result) { |
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 305 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
306 *result = active_files_; | 306 *result = active_files_; |
307 } | 307 } |
308 | 308 |
309 // Can be called on any thread, and will block (running message loop) | 309 // Can be called on any thread, and will block (running message loop) |
310 // until data is returned. | 310 // until data is returned. |
311 static int GetNumberActiveFilesFromFileThread() { | 311 static int GetNumberActiveFilesFromFileThread() { |
312 int result = -1; | 312 int result = -1; |
313 BrowserThread::PostTaskAndReply( | 313 BrowserThread::PostTaskAndReply( |
314 BrowserThread::FILE, | 314 BrowserThread::FILE, |
315 FROM_HERE, | 315 FROM_HERE, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 void OnDownloadCreated(DownloadManager* manager, | 463 void OnDownloadCreated(DownloadManager* manager, |
464 DownloadItem* download) override { | 464 DownloadItem* download) override { |
465 if (!item_) | 465 if (!item_) |
466 item_ = download; | 466 item_ = download; |
467 | 467 |
468 if (waiting_) | 468 if (waiting_) |
469 base::MessageLoopForUI::current()->Quit(); | 469 base::MessageLoopForUI::current()->Quit(); |
470 } | 470 } |
471 | 471 |
472 DownloadItem* WaitForFinished() { | 472 DownloadItem* WaitForFinished() { |
473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 473 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
474 if (!item_) { | 474 if (!item_) { |
475 waiting_ = true; | 475 waiting_ = true; |
476 RunMessageLoop(); | 476 RunMessageLoop(); |
477 waiting_ = false; | 477 waiting_ = false; |
478 } | 478 } |
479 return item_; | 479 return item_; |
480 } | 480 } |
481 | 481 |
482 private: | 482 private: |
483 DownloadManager* manager_; | 483 DownloadManager* manager_; |
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1809 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); | 1809 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); |
1810 | 1810 |
1811 GURL url = test_server.GetURL("/empty.bin"); | 1811 GURL url = test_server.GetURL("/empty.bin"); |
1812 test_server.ServeFilesFromDirectory(GetTestFilePath("download", "")); | 1812 test_server.ServeFilesFromDirectory(GetTestFilePath("download", "")); |
1813 | 1813 |
1814 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); | 1814 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); |
1815 // That's it. This should work without crashing. | 1815 // That's it. This should work without crashing. |
1816 } | 1816 } |
1817 | 1817 |
1818 } // namespace content | 1818 } // namespace content |
OLD | NEW |