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