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" |
11 #include "base/files/scoped_temp_dir.h" | 11 #include "base/files/scoped_temp_dir.h" |
12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/strings/utf_string_conversions.h" |
13 #include "content/browser/byte_stream.h" | 14 #include "content/browser/byte_stream.h" |
14 #include "content/browser/download/download_file_factory.h" | 15 #include "content/browser/download/download_file_factory.h" |
15 #include "content/browser/download/download_file_impl.h" | 16 #include "content/browser/download/download_file_impl.h" |
16 #include "content/browser/download/download_item_impl.h" | 17 #include "content/browser/download/download_item_impl.h" |
17 #include "content/browser/download/download_manager_impl.h" | 18 #include "content/browser/download/download_manager_impl.h" |
18 #include "content/browser/download/download_resource_handler.h" | 19 #include "content/browser/download/download_resource_handler.h" |
| 20 #include "content/browser/plugin_service_impl.h" |
19 #include "content/browser/web_contents/web_contents_impl.h" | 21 #include "content/browser/web_contents/web_contents_impl.h" |
20 #include "content/public/browser/power_save_blocker.h" | 22 #include "content/public/browser/power_save_blocker.h" |
21 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 24 #include "content/public/common/webplugininfo.h" |
22 #include "content/public/test/download_test_observer.h" | 25 #include "content/public/test/download_test_observer.h" |
23 #include "content/public/test/test_file_error_injector.h" | 26 #include "content/public/test/test_file_error_injector.h" |
24 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
25 #include "content/shell/shell.h" | 28 #include "content/shell/shell.h" |
26 #include "content/shell/shell_browser_context.h" | 29 #include "content/shell/shell_browser_context.h" |
27 #include "content/shell/shell_download_manager_delegate.h" | 30 #include "content/shell/shell_download_manager_delegate.h" |
28 #include "content/test/content_browser_test.h" | 31 #include "content/test/content_browser_test.h" |
29 #include "content/test/content_browser_test_utils.h" | 32 #include "content/test/content_browser_test_utils.h" |
30 #include "content/test/net/url_request_mock_http_job.h" | 33 #include "content/test/net/url_request_mock_http_job.h" |
31 #include "content/test/net/url_request_slow_download_job.h" | 34 #include "content/test/net/url_request_slow_download_job.h" |
(...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + | 775 size_t file_size1 = URLRequestSlowDownloadJob::kFirstDownloadSize + |
773 URLRequestSlowDownloadJob::kSecondDownloadSize; | 776 URLRequestSlowDownloadJob::kSecondDownloadSize; |
774 std::string expected_contents(file_size1, '*'); | 777 std::string expected_contents(file_size1, '*'); |
775 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); | 778 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); |
776 | 779 |
777 base::FilePath file2(download2->GetTargetFilePath()); | 780 base::FilePath file2(download2->GetTargetFilePath()); |
778 ASSERT_TRUE(base::ContentsEqual( | 781 ASSERT_TRUE(base::ContentsEqual( |
779 file2, GetTestFilePath("download", "download-test.lib"))); | 782 file2, GetTestFilePath("download", "download-test.lib"))); |
780 } | 783 } |
781 | 784 |
| 785 #if defined(ENABLE_PLUGINS) |
| 786 // Content served with a MIME type of application/octet-stream should be |
| 787 // downloaded even when a plugin can be found that handles the file type. |
| 788 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadOctetStream) { |
| 789 const base::FilePath::CharType kTestFilePath[] = |
| 790 FILE_PATH_LITERAL("octet-stream.abc"); |
| 791 const char kTestPluginName[] = "TestPlugin"; |
| 792 const char kTestMimeType[] = "application/x-test-mime-type"; |
| 793 const char kTestFileType[] = "abc"; |
| 794 |
| 795 WebPluginInfo plugin_info; |
| 796 plugin_info.name = base::ASCIIToUTF16(kTestPluginName); |
| 797 plugin_info.mime_types.push_back( |
| 798 WebPluginMimeType(kTestMimeType, kTestFileType, "")); |
| 799 PluginServiceImpl::GetInstance()->RegisterInternalPlugin(plugin_info, false); |
| 800 |
| 801 // The following is served with a Content-Type of application/octet-stream. |
| 802 GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kTestFilePath))); |
| 803 DownloadAndWait(shell(), url, DownloadItem::COMPLETE); |
| 804 } |
| 805 #endif |
| 806 |
782 // Try to cancel just before we release the download file, by delaying final | 807 // Try to cancel just before we release the download file, by delaying final |
783 // rename callback. | 808 // rename callback. |
784 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) { | 809 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) { |
785 // Setup new factory. | 810 // Setup new factory. |
786 DownloadFileWithDelayFactory* file_factory = | 811 DownloadFileWithDelayFactory* file_factory = |
787 new DownloadFileWithDelayFactory(); | 812 new DownloadFileWithDelayFactory(); |
788 DownloadManagerImpl* download_manager(DownloadManagerForShell(shell())); | 813 DownloadManagerImpl* download_manager(DownloadManagerForShell(shell())); |
789 download_manager->SetDownloadFileFactoryForTesting( | 814 download_manager->SetDownloadFileFactoryForTesting( |
790 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); | 815 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); |
791 | 816 |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 // Start the second download and wait until it's done. The test server is | 1592 // Start the second download and wait until it's done. The test server is |
1568 // single threaded. The response to this download request should follow the | 1593 // single threaded. The response to this download request should follow the |
1569 // response to the previous resumption request. | 1594 // response to the previous resumption request. |
1570 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); | 1595 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); |
1571 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE); | 1596 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE); |
1572 | 1597 |
1573 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1598 EXPECT_TRUE(EnsureNoPendingDownloads()); |
1574 } | 1599 } |
1575 | 1600 |
1576 } // namespace content | 1601 } // namespace content |
OLD | NEW |