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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/callback_helpers.h" | 13 #include "base/callback_helpers.h" |
14 #include "base/feature_list.h" | 14 #include "base/feature_list.h" |
15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
16 #include "base/files/file_util.h" | 16 #include "base/files/file_util.h" |
17 #include "base/files/scoped_temp_dir.h" | 17 #include "base/files/scoped_temp_dir.h" |
18 #include "base/format_macros.h" | 18 #include "base/format_macros.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
| 21 #include "base/run_loop.h" |
21 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "base/threading/platform_thread.h" | 24 #include "base/threading/platform_thread.h" |
24 #include "base/time/time.h" | 25 #include "base/time/time.h" |
25 #include "build/build_config.h" | 26 #include "build/build_config.h" |
26 #include "content/browser/byte_stream.h" | 27 #include "content/browser/byte_stream.h" |
27 #include "content/browser/download/download_file_factory.h" | 28 #include "content/browser/download/download_file_factory.h" |
28 #include "content/browser/download/download_file_impl.h" | 29 #include "content/browser/download/download_file_impl.h" |
29 #include "content/browser/download/download_item_impl.h" | 30 #include "content/browser/download/download_item_impl.h" |
30 #include "content/browser/download/download_manager_impl.h" | 31 #include "content/browser/download/download_manager_impl.h" |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 } | 325 } |
325 | 326 |
326 // Can be called on any thread, and will block (running message loop) | 327 // Can be called on any thread, and will block (running message loop) |
327 // until data is returned. | 328 // until data is returned. |
328 static int GetNumberActiveFilesFromFileThread() { | 329 static int GetNumberActiveFilesFromFileThread() { |
329 int result = -1; | 330 int result = -1; |
330 BrowserThread::PostTaskAndReply( | 331 BrowserThread::PostTaskAndReply( |
331 BrowserThread::FILE, FROM_HERE, | 332 BrowserThread::FILE, FROM_HERE, |
332 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result), | 333 base::Bind(&CountingDownloadFile::GetNumberActiveFiles, &result), |
333 base::MessageLoop::current()->QuitWhenIdleClosure()); | 334 base::MessageLoop::current()->QuitWhenIdleClosure()); |
334 base::MessageLoop::current()->Run(); | 335 base::RunLoop().Run(); |
335 DCHECK_NE(-1, result); | 336 DCHECK_NE(-1, result); |
336 return result; | 337 return result; |
337 } | 338 } |
338 | 339 |
339 private: | 340 private: |
340 static int active_files_; | 341 static int active_files_; |
341 }; | 342 }; |
342 | 343 |
343 int CountingDownloadFile::active_files_ = 0; | 344 int CountingDownloadFile::active_files_ = 0; |
344 | 345 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 DownloadManagerForShell(shell())->SetDownloadFileFactoryForTesting( | 621 DownloadManagerForShell(shell())->SetDownloadFileFactoryForTesting( |
621 std::unique_ptr<DownloadFileFactory>( | 622 std::unique_ptr<DownloadFileFactory>( |
622 new CountingDownloadFileFactory())); | 623 new CountingDownloadFileFactory())); |
623 } | 624 } |
624 | 625 |
625 bool EnsureNoPendingDownloads() { | 626 bool EnsureNoPendingDownloads() { |
626 bool result = true; | 627 bool result = true; |
627 BrowserThread::PostTask( | 628 BrowserThread::PostTask( |
628 BrowserThread::IO, FROM_HERE, | 629 BrowserThread::IO, FROM_HERE, |
629 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); | 630 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); |
630 base::MessageLoop::current()->Run(); | 631 base::RunLoop().Run(); |
631 return result && | 632 return result && |
632 (CountingDownloadFile::GetNumberActiveFilesFromFileThread() == 0); | 633 (CountingDownloadFile::GetNumberActiveFilesFromFileThread() == 0); |
633 } | 634 } |
634 | 635 |
635 void NavigateToURLAndWaitForDownload( | 636 void NavigateToURLAndWaitForDownload( |
636 Shell* shell, | 637 Shell* shell, |
637 const GURL& url, | 638 const GURL& url, |
638 DownloadItem::DownloadState expected_terminal_state) { | 639 DownloadItem::DownloadState expected_terminal_state) { |
639 std::unique_ptr<DownloadTestObserver> observer(CreateWaiter(shell, 1)); | 640 std::unique_ptr<DownloadTestObserver> observer(CreateWaiter(shell, 1)); |
640 NavigateToURL(shell, url); | 641 NavigateToURL(shell, url); |
(...skipping 1831 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2472 | 2473 |
2473 std::vector<DownloadItem*> downloads; | 2474 std::vector<DownloadItem*> downloads; |
2474 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 2475 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
2475 ASSERT_EQ(1u, downloads.size()); | 2476 ASSERT_EQ(1u, downloads.size()); |
2476 | 2477 |
2477 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 2478 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
2478 downloads[0]->GetTargetFilePath().BaseName().value()); | 2479 downloads[0]->GetTargetFilePath().BaseName().value()); |
2479 } | 2480 } |
2480 | 2481 |
2481 } // namespace content | 2482 } // namespace content |
OLD | NEW |