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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 return new DownloadFileWithDelay( | 233 return new DownloadFileWithDelay( |
234 save_info.Pass(), default_download_directory, url, referrer_url, | 234 save_info.Pass(), default_download_directory, url, referrer_url, |
235 calculate_hash, stream.Pass(), bound_net_log, | 235 calculate_hash, stream.Pass(), bound_net_log, |
236 psb.Pass(), observer, weak_ptr_factory_.GetWeakPtr()); | 236 psb.Pass(), observer, weak_ptr_factory_.GetWeakPtr()); |
237 } | 237 } |
238 | 238 |
239 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { | 239 void DownloadFileWithDelayFactory::AddRenameCallback(base::Closure callback) { |
240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
241 rename_callbacks_.push_back(callback); | 241 rename_callbacks_.push_back(callback); |
242 if (waiting_) | 242 if (waiting_) |
243 MessageLoopForUI::current()->Quit(); | 243 base::MessageLoopForUI::current()->Quit(); |
244 } | 244 } |
245 | 245 |
246 void DownloadFileWithDelayFactory::GetAllRenameCallbacks( | 246 void DownloadFileWithDelayFactory::GetAllRenameCallbacks( |
247 std::vector<base::Closure>* results) { | 247 std::vector<base::Closure>* results) { |
248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
249 results->swap(rename_callbacks_); | 249 results->swap(rename_callbacks_); |
250 } | 250 } |
251 | 251 |
252 void DownloadFileWithDelayFactory::WaitForSomeCallback() { | 252 void DownloadFileWithDelayFactory::WaitForSomeCallback() { |
253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 289 |
290 static void GetNumberActiveFiles(int* result) { | 290 static void GetNumberActiveFiles(int* result) { |
291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
292 *result = active_files_; | 292 *result = active_files_; |
293 } | 293 } |
294 | 294 |
295 // Can be called on any thread, and will block (running message loop) | 295 // Can be called on any thread, and will block (running message loop) |
296 // until data is returned. | 296 // until data is returned. |
297 static int GetNumberActiveFilesFromFileThread() { | 297 static int GetNumberActiveFilesFromFileThread() { |
298 int result = -1; | 298 int result = -1; |
299 BrowserThread::PostTaskAndReply(BrowserThread::FILE, FROM_HERE, | 299 BrowserThread::PostTaskAndReply( |
| 300 BrowserThread::FILE, |
| 301 FROM_HERE, |
300 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result), | 302 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result), |
301 MessageLoop::current()->QuitClosure()); | 303 base::MessageLoop::current()->QuitClosure()); |
302 MessageLoop::current()->Run(); | 304 base::MessageLoop::current()->Run(); |
303 DCHECK_NE(-1, result); | 305 DCHECK_NE(-1, result); |
304 return result; | 306 return result; |
305 } | 307 } |
306 | 308 |
307 private: | 309 private: |
308 static int active_files_; | 310 static int active_files_; |
309 }; | 311 }; |
310 | 312 |
311 int CountingDownloadFile::active_files_ = 0; | 313 int CountingDownloadFile::active_files_ = 0; |
312 | 314 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 manager_->RemoveObserver(this); | 449 manager_->RemoveObserver(this); |
448 manager_ = NULL; | 450 manager_ = NULL; |
449 } | 451 } |
450 | 452 |
451 virtual void OnDownloadCreated(DownloadManager* manager, | 453 virtual void OnDownloadCreated(DownloadManager* manager, |
452 DownloadItem* download) OVERRIDE { | 454 DownloadItem* download) OVERRIDE { |
453 if (!item_) | 455 if (!item_) |
454 item_ = download; | 456 item_ = download; |
455 | 457 |
456 if (waiting_) | 458 if (waiting_) |
457 MessageLoopForUI::current()->Quit(); | 459 base::MessageLoopForUI::current()->Quit(); |
458 } | 460 } |
459 | 461 |
460 DownloadItem* WaitForFinished() { | 462 DownloadItem* WaitForFinished() { |
461 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
462 if (!item_) { | 464 if (!item_) { |
463 waiting_ = true; | 465 waiting_ = true; |
464 RunMessageLoop(); | 466 RunMessageLoop(); |
465 waiting_ = false; | 467 waiting_ = false; |
466 } | 468 } |
467 return item_; | 469 return item_; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 DownloadManagerForShell(shell())->SetDownloadFileFactoryForTesting( | 563 DownloadManagerForShell(shell())->SetDownloadFileFactoryForTesting( |
562 scoped_ptr<DownloadFileFactory>( | 564 scoped_ptr<DownloadFileFactory>( |
563 new CountingDownloadFileFactory()).Pass()); | 565 new CountingDownloadFileFactory()).Pass()); |
564 } | 566 } |
565 | 567 |
566 bool EnsureNoPendingDownloads() { | 568 bool EnsureNoPendingDownloads() { |
567 bool result = true; | 569 bool result = true; |
568 BrowserThread::PostTask( | 570 BrowserThread::PostTask( |
569 BrowserThread::IO, FROM_HERE, | 571 BrowserThread::IO, FROM_HERE, |
570 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); | 572 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); |
571 MessageLoop::current()->Run(); | 573 base::MessageLoop::current()->Run(); |
572 return result && | 574 return result && |
573 (CountingDownloadFile::GetNumberActiveFilesFromFileThread() == 0); | 575 (CountingDownloadFile::GetNumberActiveFilesFromFileThread() == 0); |
574 } | 576 } |
575 | 577 |
576 void DownloadAndWait(Shell* shell, const GURL& url, | 578 void DownloadAndWait(Shell* shell, const GURL& url, |
577 DownloadItem::DownloadState expected_terminal_state) { | 579 DownloadItem::DownloadState expected_terminal_state) { |
578 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(shell, 1)); | 580 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(shell, 1)); |
579 NavigateToURL(shell, url); | 581 NavigateToURL(shell, url); |
580 observer->WaitForFinished(); | 582 observer->WaitForFinished(); |
581 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(expected_terminal_state)); | 583 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(expected_terminal_state)); |
582 } | 584 } |
583 | 585 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 return; | 674 return; |
673 } | 675 } |
674 } | 676 } |
675 } | 677 } |
676 | 678 |
677 private: | 679 private: |
678 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { | 680 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { |
679 if (URLRequestSlowDownloadJob::NumberOutstandingRequests()) | 681 if (URLRequestSlowDownloadJob::NumberOutstandingRequests()) |
680 *result = false; | 682 *result = false; |
681 BrowserThread::PostTask( | 683 BrowserThread::PostTask( |
682 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); | 684 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); |
683 } | 685 } |
684 | 686 |
685 // Location of the downloads directory for these tests | 687 // Location of the downloads directory for these tests |
686 base::ScopedTempDir downloads_directory_; | 688 base::ScopedTempDir downloads_directory_; |
687 }; | 689 }; |
688 | 690 |
689 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadCancelled) { | 691 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadCancelled) { |
690 SetupEnsureNoPendingDownloads(); | 692 SetupEnsureNoPendingDownloads(); |
691 | 693 |
692 // Create a download, wait until it's started, and confirm | 694 // Create a download, wait until it's started, and confirm |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1375 | 1377 |
1376 // Resume and watch completion. | 1378 // Resume and watch completion. |
1377 DownloadUpdatedObserver completion_observer( | 1379 DownloadUpdatedObserver completion_observer( |
1378 download, base::Bind(DownloadCompleteFilter)); | 1380 download, base::Bind(DownloadCompleteFilter)); |
1379 download->ResumeInterruptedDownload(); | 1381 download->ResumeInterruptedDownload(); |
1380 completion_observer.WaitForEvent(); | 1382 completion_observer.WaitForEvent(); |
1381 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1383 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
1382 } | 1384 } |
1383 | 1385 |
1384 } // namespace content | 1386 } // namespace content |
OLD | NEW |