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 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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_CURRENTLY_ON(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()->QuitWhenIdle(); |
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_CURRENTLY_ON(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_CURRENTLY_ON(BrowserThread::UI); | 268 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 static void GetNumberActiveFiles(int* result) { | 304 static void GetNumberActiveFiles(int* result) { |
305 DCHECK_CURRENTLY_ON(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, FROM_HERE, |
315 FROM_HERE, | |
316 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result), | 315 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result), |
317 base::MessageLoop::current()->QuitClosure()); | 316 base::MessageLoop::current()->QuitWhenIdleClosure()); |
318 base::MessageLoop::current()->Run(); | 317 base::MessageLoop::current()->Run(); |
319 DCHECK_NE(-1, result); | 318 DCHECK_NE(-1, result); |
320 return result; | 319 return result; |
321 } | 320 } |
322 | 321 |
323 private: | 322 private: |
324 static int active_files_; | 323 static int active_files_; |
325 }; | 324 }; |
326 | 325 |
327 int CountingDownloadFile::active_files_ = 0; | 326 int CountingDownloadFile::active_files_ = 0; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 manager_->RemoveObserver(this); | 458 manager_->RemoveObserver(this); |
460 manager_ = NULL; | 459 manager_ = NULL; |
461 } | 460 } |
462 | 461 |
463 void OnDownloadCreated(DownloadManager* manager, | 462 void OnDownloadCreated(DownloadManager* manager, |
464 DownloadItem* download) override { | 463 DownloadItem* download) override { |
465 if (!item_) | 464 if (!item_) |
466 item_ = download; | 465 item_ = download; |
467 | 466 |
468 if (waiting_) | 467 if (waiting_) |
469 base::MessageLoopForUI::current()->Quit(); | 468 base::MessageLoopForUI::current()->QuitWhenIdle(); |
470 } | 469 } |
471 | 470 |
472 DownloadItem* WaitForFinished() { | 471 DownloadItem* WaitForFinished() { |
473 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 472 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
474 if (!item_) { | 473 if (!item_) { |
475 waiting_ = true; | 474 waiting_ = true; |
476 RunMessageLoop(); | 475 RunMessageLoop(); |
477 waiting_ = false; | 476 waiting_ = false; |
478 } | 477 } |
479 return item_; | 478 return item_; |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 if (static_cast<char>((i * 2 + 15) % 256) != file_contents[i]) | 737 if (static_cast<char>((i * 2 + 15) % 256) != file_contents[i]) |
739 return; | 738 return; |
740 } | 739 } |
741 } | 740 } |
742 } | 741 } |
743 | 742 |
744 private: | 743 private: |
745 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { | 744 static void EnsureNoPendingDownloadJobsOnIO(bool* result) { |
746 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests()) | 745 if (net::URLRequestSlowDownloadJob::NumberOutstandingRequests()) |
747 *result = false; | 746 *result = false; |
748 BrowserThread::PostTask( | 747 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
749 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); | 748 base::MessageLoop::QuitWhenIdleClosure()); |
750 } | 749 } |
751 | 750 |
752 // Location of the downloads directory for these tests | 751 // Location of the downloads directory for these tests |
753 base::ScopedTempDir downloads_directory_; | 752 base::ScopedTempDir downloads_directory_; |
754 scoped_ptr<TestShellDownloadManagerDelegate> test_delegate_; | 753 scoped_ptr<TestShellDownloadManagerDelegate> test_delegate_; |
755 }; | 754 }; |
756 | 755 |
757 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadCancelled) { | 756 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadCancelled) { |
758 SetupEnsureNoPendingDownloads(); | 757 SetupEnsureNoPendingDownloads(); |
759 | 758 |
(...skipping 1066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1826 | 1825 |
1827 std::vector<DownloadItem*> downloads; | 1826 std::vector<DownloadItem*> downloads; |
1828 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 1827 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
1829 ASSERT_EQ(1u, downloads.size()); | 1828 ASSERT_EQ(1u, downloads.size()); |
1830 | 1829 |
1831 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 1830 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
1832 downloads[0]->GetTargetFilePath().BaseName().value()); | 1831 downloads[0]->GetTargetFilePath().BaseName().value()); |
1833 } | 1832 } |
1834 | 1833 |
1835 } // namespace content | 1834 } // namespace content |
OLD | NEW |