| 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 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 NavigateToURL(shell(), GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 790 NavigateToURL(shell(), GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 791 observer1->WaitForFinished(); | 791 observer1->WaitForFinished(); |
| 792 | 792 |
| 793 std::vector<DownloadItem*> downloads; | 793 std::vector<DownloadItem*> downloads; |
| 794 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 794 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 795 ASSERT_EQ(1u, downloads.size()); | 795 ASSERT_EQ(1u, downloads.size()); |
| 796 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 796 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
| 797 DownloadItem* download1 = downloads[0]; // The only download. | 797 DownloadItem* download1 = downloads[0]; // The only download. |
| 798 | 798 |
| 799 // Start the second download and wait until it's done. | 799 // Start the second download and wait until it's done. |
| 800 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); | 800 GURL url(net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); |
| 801 GURL url(net::URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 802 // Download the file and wait. | 801 // Download the file and wait. |
| 803 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); | 802 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); |
| 804 | 803 |
| 805 // Should now have 2 items on the manager. | 804 // Should now have 2 items on the manager. |
| 806 downloads.clear(); | 805 downloads.clear(); |
| 807 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 806 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 808 ASSERT_EQ(2u, downloads.size()); | 807 ASSERT_EQ(2u, downloads.size()); |
| 809 // We don't know the order of the downloads. | 808 // We don't know the order of the downloads. |
| 810 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; | 809 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; |
| 811 | 810 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 834 | 833 |
| 835 base::FilePath file2(download2->GetTargetFilePath()); | 834 base::FilePath file2(download2->GetTargetFilePath()); |
| 836 ASSERT_TRUE(base::ContentsEqual( | 835 ASSERT_TRUE(base::ContentsEqual( |
| 837 file2, GetTestFilePath("download", "download-test.lib"))); | 836 file2, GetTestFilePath("download", "download-test.lib"))); |
| 838 } | 837 } |
| 839 | 838 |
| 840 #if defined(ENABLE_PLUGINS) | 839 #if defined(ENABLE_PLUGINS) |
| 841 // Content served with a MIME type of application/octet-stream should be | 840 // Content served with a MIME type of application/octet-stream should be |
| 842 // downloaded even when a plugin can be found that handles the file type. | 841 // downloaded even when a plugin can be found that handles the file type. |
| 843 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadOctetStream) { | 842 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadOctetStream) { |
| 844 const base::FilePath::CharType kTestFilePath[] = | |
| 845 FILE_PATH_LITERAL("octet-stream.abc"); | |
| 846 const char kTestPluginName[] = "TestPlugin"; | 843 const char kTestPluginName[] = "TestPlugin"; |
| 847 const char kTestMimeType[] = "application/x-test-mime-type"; | 844 const char kTestMimeType[] = "application/x-test-mime-type"; |
| 848 const char kTestFileType[] = "abc"; | 845 const char kTestFileType[] = "abc"; |
| 849 | 846 |
| 850 WebPluginInfo plugin_info; | 847 WebPluginInfo plugin_info; |
| 851 plugin_info.name = base::ASCIIToUTF16(kTestPluginName); | 848 plugin_info.name = base::ASCIIToUTF16(kTestPluginName); |
| 852 plugin_info.mime_types.push_back( | 849 plugin_info.mime_types.push_back( |
| 853 WebPluginMimeType(kTestMimeType, kTestFileType, "")); | 850 WebPluginMimeType(kTestMimeType, kTestFileType, "")); |
| 854 plugin_info.type = WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS; | 851 plugin_info.type = WebPluginInfo::PLUGIN_TYPE_PEPPER_IN_PROCESS; |
| 855 PluginServiceImpl::GetInstance()->RegisterInternalPlugin(plugin_info, false); | 852 PluginServiceImpl::GetInstance()->RegisterInternalPlugin(plugin_info, false); |
| 856 | 853 |
| 857 // The following is served with a Content-Type of application/octet-stream. | 854 // The following is served with a Content-Type of application/octet-stream. |
| 858 GURL url( | 855 GURL url( |
| 859 net::URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kTestFilePath))); | 856 net::URLRequestMockHTTPJob::GetMockUrl("octet-stream.abc")); |
| 860 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); | 857 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); |
| 861 } | 858 } |
| 862 #endif | 859 #endif |
| 863 | 860 |
| 864 // Try to cancel just before we release the download file, by delaying final | 861 // Try to cancel just before we release the download file, by delaying final |
| 865 // rename callback. | 862 // rename callback. |
| 866 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) { | 863 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) { |
| 867 // Setup new factory. | 864 // Setup new factory. |
| 868 DownloadFileWithDelayFactory* file_factory = | 865 DownloadFileWithDelayFactory* file_factory = |
| 869 new DownloadFileWithDelayFactory(); | 866 new DownloadFileWithDelayFactory(); |
| 870 DownloadManagerImpl* download_manager(DownloadManagerForShell(shell())); | 867 DownloadManagerImpl* download_manager(DownloadManagerForShell(shell())); |
| 871 download_manager->SetDownloadFileFactoryForTesting( | 868 download_manager->SetDownloadFileFactoryForTesting( |
| 872 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); | 869 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); |
| 873 | 870 |
| 874 // Create a download | 871 // Create a download |
| 875 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); | 872 NavigateToURL(shell(), |
| 876 NavigateToURL(shell(), net::URLRequestMockHTTPJob::GetMockUrl(file)); | 873 net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); |
| 877 | 874 |
| 878 // Wait until the first (intermediate file) rename and execute the callback. | 875 // Wait until the first (intermediate file) rename and execute the callback. |
| 879 file_factory->WaitForSomeCallback(); | 876 file_factory->WaitForSomeCallback(); |
| 880 std::vector<base::Closure> callbacks; | 877 std::vector<base::Closure> callbacks; |
| 881 file_factory->GetAllRenameCallbacks(&callbacks); | 878 file_factory->GetAllRenameCallbacks(&callbacks); |
| 882 ASSERT_EQ(1u, callbacks.size()); | 879 ASSERT_EQ(1u, callbacks.size()); |
| 883 callbacks[0].Run(); | 880 callbacks[0].Run(); |
| 884 callbacks.clear(); | 881 callbacks.clear(); |
| 885 | 882 |
| 886 // Wait until the second (final) rename callback is posted. | 883 // Wait until the second (final) rename callback is posted. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 914 // Mark delegate for delayed open. | 911 // Mark delegate for delayed open. |
| 915 GetDownloadManagerDelegate()->SetDelayedOpen(true); | 912 GetDownloadManagerDelegate()->SetDelayedOpen(true); |
| 916 | 913 |
| 917 // Setup new factory. | 914 // Setup new factory. |
| 918 DownloadFileWithDelayFactory* file_factory = | 915 DownloadFileWithDelayFactory* file_factory = |
| 919 new DownloadFileWithDelayFactory(); | 916 new DownloadFileWithDelayFactory(); |
| 920 download_manager->SetDownloadFileFactoryForTesting( | 917 download_manager->SetDownloadFileFactoryForTesting( |
| 921 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); | 918 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); |
| 922 | 919 |
| 923 // Create a download | 920 // Create a download |
| 924 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); | 921 NavigateToURL(shell(), |
| 925 NavigateToURL(shell(), net::URLRequestMockHTTPJob::GetMockUrl(file)); | 922 net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); |
| 926 | 923 |
| 927 // Wait until the first (intermediate file) rename and execute the callback. | 924 // Wait until the first (intermediate file) rename and execute the callback. |
| 928 file_factory->WaitForSomeCallback(); | 925 file_factory->WaitForSomeCallback(); |
| 929 std::vector<base::Closure> callbacks; | 926 std::vector<base::Closure> callbacks; |
| 930 file_factory->GetAllRenameCallbacks(&callbacks); | 927 file_factory->GetAllRenameCallbacks(&callbacks); |
| 931 ASSERT_EQ(1u, callbacks.size()); | 928 ASSERT_EQ(1u, callbacks.size()); |
| 932 callbacks[0].Run(); | 929 callbacks[0].Run(); |
| 933 callbacks.clear(); | 930 callbacks.clear(); |
| 934 | 931 |
| 935 // Wait until the second (final) rename callback is posted. | 932 // Wait until the second (final) rename callback is posted. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 // Mark delegate for delayed open. | 1021 // Mark delegate for delayed open. |
| 1025 GetDownloadManagerDelegate()->SetDelayedOpen(true); | 1022 GetDownloadManagerDelegate()->SetDelayedOpen(true); |
| 1026 | 1023 |
| 1027 // Setup new factory. | 1024 // Setup new factory. |
| 1028 DownloadFileWithDelayFactory* file_factory = | 1025 DownloadFileWithDelayFactory* file_factory = |
| 1029 new DownloadFileWithDelayFactory(); | 1026 new DownloadFileWithDelayFactory(); |
| 1030 download_manager->SetDownloadFileFactoryForTesting( | 1027 download_manager->SetDownloadFileFactoryForTesting( |
| 1031 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); | 1028 scoped_ptr<DownloadFileFactory>(file_factory).Pass()); |
| 1032 | 1029 |
| 1033 // Create a download | 1030 // Create a download |
| 1034 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); | 1031 NavigateToURL(shell(), |
| 1035 NavigateToURL(shell(), net::URLRequestMockHTTPJob::GetMockUrl(file)); | 1032 net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); |
| 1036 | 1033 |
| 1037 // Wait until the first (intermediate file) rename and execute the callback. | 1034 // Wait until the first (intermediate file) rename and execute the callback. |
| 1038 file_factory->WaitForSomeCallback(); | 1035 file_factory->WaitForSomeCallback(); |
| 1039 std::vector<base::Closure> callbacks; | 1036 std::vector<base::Closure> callbacks; |
| 1040 file_factory->GetAllRenameCallbacks(&callbacks); | 1037 file_factory->GetAllRenameCallbacks(&callbacks); |
| 1041 ASSERT_EQ(1u, callbacks.size()); | 1038 ASSERT_EQ(1u, callbacks.size()); |
| 1042 callbacks[0].Run(); | 1039 callbacks[0].Run(); |
| 1043 callbacks.clear(); | 1040 callbacks.clear(); |
| 1044 | 1041 |
| 1045 // Wait until the second (final) rename callback is posted. | 1042 // Wait until the second (final) rename callback is posted. |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1331 // Completion. | 1328 // Completion. |
| 1332 {DownloadItem::COMPLETE, GetSafeBufferChunk() * 3}, | 1329 {DownloadItem::COMPLETE, GetSafeBufferChunk() * 3}, |
| 1333 }; | 1330 }; |
| 1334 | 1331 |
| 1335 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); | 1332 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); |
| 1336 } | 1333 } |
| 1337 | 1334 |
| 1338 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithFileInitError) { | 1335 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithFileInitError) { |
| 1339 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1336 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1340 switches::kEnableDownloadResumption); | 1337 switches::kEnableDownloadResumption); |
| 1341 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); | 1338 GURL url(net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); |
| 1342 GURL url(net::URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1343 | 1339 |
| 1344 // Setup the error injector. | 1340 // Setup the error injector. |
| 1345 scoped_refptr<TestFileErrorInjector> injector( | 1341 scoped_refptr<TestFileErrorInjector> injector( |
| 1346 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); | 1342 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); |
| 1347 | 1343 |
| 1348 TestFileErrorInjector::FileErrorInfo err = { | 1344 TestFileErrorInjector::FileErrorInfo err = { |
| 1349 url.spec(), | 1345 url.spec(), |
| 1350 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, | 1346 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, |
| 1351 0, | 1347 0, |
| 1352 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE | 1348 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1382 download, base::Bind(DownloadCompleteFilter)); | 1378 download, base::Bind(DownloadCompleteFilter)); |
| 1383 download->Resume(); | 1379 download->Resume(); |
| 1384 completion_observer.WaitForEvent(); | 1380 completion_observer.WaitForEvent(); |
| 1385 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1381 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
| 1386 } | 1382 } |
| 1387 | 1383 |
| 1388 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1384 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1389 ResumeWithFileIntermediateRenameError) { | 1385 ResumeWithFileIntermediateRenameError) { |
| 1390 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1386 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1391 switches::kEnableDownloadResumption); | 1387 switches::kEnableDownloadResumption); |
| 1392 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); | 1388 GURL url(net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); |
| 1393 GURL url(net::URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1394 | 1389 |
| 1395 // Setup the error injector. | 1390 // Setup the error injector. |
| 1396 scoped_refptr<TestFileErrorInjector> injector( | 1391 scoped_refptr<TestFileErrorInjector> injector( |
| 1397 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); | 1392 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); |
| 1398 | 1393 |
| 1399 TestFileErrorInjector::FileErrorInfo err = { | 1394 TestFileErrorInjector::FileErrorInfo err = { |
| 1400 url.spec(), | 1395 url.spec(), |
| 1401 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, | 1396 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, |
| 1402 0, | 1397 0, |
| 1403 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE | 1398 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1434 DownloadUpdatedObserver completion_observer( | 1429 DownloadUpdatedObserver completion_observer( |
| 1435 download, base::Bind(DownloadCompleteFilter)); | 1430 download, base::Bind(DownloadCompleteFilter)); |
| 1436 download->Resume(); | 1431 download->Resume(); |
| 1437 completion_observer.WaitForEvent(); | 1432 completion_observer.WaitForEvent(); |
| 1438 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1433 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
| 1439 } | 1434 } |
| 1440 | 1435 |
| 1441 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithFileFinalRenameError) { | 1436 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithFileFinalRenameError) { |
| 1442 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1437 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1443 switches::kEnableDownloadResumption); | 1438 switches::kEnableDownloadResumption); |
| 1444 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); | 1439 GURL url(net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); |
| 1445 GURL url(net::URLRequestMockHTTPJob::GetMockUrl(file)); | |
| 1446 | 1440 |
| 1447 // Setup the error injector. | 1441 // Setup the error injector. |
| 1448 scoped_refptr<TestFileErrorInjector> injector( | 1442 scoped_refptr<TestFileErrorInjector> injector( |
| 1449 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); | 1443 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); |
| 1450 | 1444 |
| 1451 DownloadManagerForShell(shell())->RemoveAllDownloads(); | 1445 DownloadManagerForShell(shell())->RemoveAllDownloads(); |
| 1452 TestFileErrorInjector::FileErrorInfo err = { | 1446 TestFileErrorInjector::FileErrorInfo err = { |
| 1453 url.spec(), | 1447 url.spec(), |
| 1454 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, | 1448 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, |
| 1455 0, | 1449 0, |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1549 RunAllPendingInMessageLoop(); | 1543 RunAllPendingInMessageLoop(); |
| 1550 | 1544 |
| 1551 // The intermediate file should now be gone. | 1545 // The intermediate file should now be gone. |
| 1552 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1546 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1553 } | 1547 } |
| 1554 | 1548 |
| 1555 // A completed download shouldn't delete the downloaded file when it is | 1549 // A completed download shouldn't delete the downloaded file when it is |
| 1556 // removed. | 1550 // removed. |
| 1557 { | 1551 { |
| 1558 // Start the second download and wait until it's done. | 1552 // Start the second download and wait until it's done. |
| 1559 base::FilePath file2(FILE_PATH_LITERAL("download-test.lib")); | 1553 GURL url2(net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); |
| 1560 GURL url2(net::URLRequestMockHTTPJob::GetMockUrl(file2)); | |
| 1561 scoped_ptr<DownloadTestObserver> completion_observer( | 1554 scoped_ptr<DownloadTestObserver> completion_observer( |
| 1562 CreateWaiter(shell(), 1)); | 1555 CreateWaiter(shell(), 1)); |
| 1563 DownloadItem* download(StartDownloadAndReturnItem(url2)); | 1556 DownloadItem* download(StartDownloadAndReturnItem(url2)); |
| 1564 completion_observer->WaitForFinished(); | 1557 completion_observer->WaitForFinished(); |
| 1565 | 1558 |
| 1566 // The target path should exist. | 1559 // The target path should exist. |
| 1567 base::FilePath target_path(download->GetTargetFilePath()); | 1560 base::FilePath target_path(download->GetTargetFilePath()); |
| 1568 EXPECT_TRUE(base::PathExists(target_path)); | 1561 EXPECT_TRUE(base::PathExists(target_path)); |
| 1569 download->Remove(); | 1562 download->Remove(); |
| 1570 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1563 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1825 | 1818 |
| 1826 std::vector<DownloadItem*> downloads; | 1819 std::vector<DownloadItem*> downloads; |
| 1827 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 1820 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 1828 ASSERT_EQ(1u, downloads.size()); | 1821 ASSERT_EQ(1u, downloads.size()); |
| 1829 | 1822 |
| 1830 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 1823 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
| 1831 downloads[0]->GetTargetFilePath().BaseName().value()); | 1824 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 1832 } | 1825 } |
| 1833 | 1826 |
| 1834 } // namespace content | 1827 } // namespace content |
| OLD | NEW |