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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 | 636 |
637 // Check the contents. | 637 // Check the contents. |
638 EXPECT_EQ(value, file_contents); | 638 EXPECT_EQ(value, file_contents); |
639 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) | 639 if (memcmp(file_contents.c_str(), value.c_str(), expected_size) != 0) |
640 return false; | 640 return false; |
641 | 641 |
642 return true; | 642 return true; |
643 } | 643 } |
644 | 644 |
645 // Start a download and return the item. | 645 // Start a download and return the item. |
646 DownloadItem* StartDownloadAndReturnItem(GURL url) { | 646 DownloadItem* StartDownloadAndReturnItem(Shell* shell, GURL url) { |
647 scoped_ptr<DownloadCreateObserver> observer( | 647 scoped_ptr<DownloadCreateObserver> observer( |
648 new DownloadCreateObserver(DownloadManagerForShell(shell()))); | 648 new DownloadCreateObserver(DownloadManagerForShell(shell))); |
649 shell()->LoadURL(url); | 649 shell->LoadURL(url); |
650 return observer->WaitForFinished(); | 650 return observer->WaitForFinished(); |
651 } | 651 } |
652 | 652 |
653 static void ReadAndVerifyFileContents(int seed, | 653 static void ReadAndVerifyFileContents(int seed, |
654 int64_t expected_size, | 654 int64_t expected_size, |
655 const base::FilePath& path) { | 655 const base::FilePath& path) { |
656 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); | 656 base::File file(path, base::File::FLAG_OPEN | base::File::FLAG_READ); |
657 ASSERT_TRUE(file.IsValid()); | 657 ASSERT_TRUE(file.IsValid()); |
658 int64_t file_length = file.GetLength(); | 658 int64_t file_length = file.GetLength(); |
659 ASSERT_EQ(expected_size, file_length); | 659 ASSERT_EQ(expected_size, file_length); |
(...skipping 23 matching lines...) Expand all Loading... | |
683 *result = false; | 683 *result = false; |
684 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 684 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
685 base::MessageLoop::QuitWhenIdleClosure()); | 685 base::MessageLoop::QuitWhenIdleClosure()); |
686 } | 686 } |
687 | 687 |
688 // Location of the downloads directory for these tests | 688 // Location of the downloads directory for these tests |
689 base::ScopedTempDir downloads_directory_; | 689 base::ScopedTempDir downloads_directory_; |
690 scoped_ptr<TestShellDownloadManagerDelegate> test_delegate_; | 690 scoped_ptr<TestShellDownloadManagerDelegate> test_delegate_; |
691 }; | 691 }; |
692 | 692 |
693 // Parameters for DownloadResumptionContentTest. | |
694 enum class DownloadResumptionTestType { | |
695 RESUME_WITH_RENDERER, // Resume() is called while the originating WebContents | |
696 // is still alive. | |
697 RESUME_WITHOUT_RENDERER // Resume() is called after the originating | |
698 // WebContents has been deleted. | |
699 }; | |
700 | |
701 // Parameterized test for download resumption. Tests using this fixure will be | |
702 // run once with RESUME_WITH_RENDERER and once with RESUME_WITHOUT_RENDERER. | |
703 // Use download_shell() to retrieve the Shell object that should be used as the | |
704 // originator for the initial download. Prior to calling Resume(), call | |
705 // PrepareToResume() which will cause the originating Shell to be deleted if the | |
706 // test parameter is RESUME_WITHOUT_RENDERER. | |
707 class DownloadResumptionContentTest | |
708 : public DownloadContentTest, | |
709 public ::testing::WithParamInterface<DownloadResumptionTestType> { | |
710 public: | |
711 void SetUpOnMainThread() override { | |
712 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
713 switches::kEnableDownloadResumption); | |
714 DownloadContentTest::SetUpOnMainThread(); | |
715 | |
716 if (GetParam() == DownloadResumptionTestType::RESUME_WITHOUT_RENDERER) | |
717 download_shell_ = CreateBrowser(); | |
718 else | |
719 download_shell_ = shell(); | |
720 | |
721 ASSERT_EQ(DownloadManagerForShell(shell()), | |
722 DownloadManagerForShell(download_shell())); | |
723 } | |
724 | |
725 // Shell to use for initiating a download. Only valid *before* | |
726 // PrepareToResume() is called. | |
727 Shell* download_shell() const { | |
728 DCHECK(download_shell_); | |
729 return download_shell_; | |
730 } | |
731 | |
732 // Should be called once before calling DownloadItem::Resume() on an | |
733 // interrupted download. This may cause download_shell() to become | |
734 // invalidated. | |
735 void PrepareToResume() { | |
736 if (GetParam() == DownloadResumptionTestType::RESUME_WITH_RENDERER) | |
737 return; | |
738 DCHECK_NE(download_shell(), shell()); | |
739 DCHECK(download_shell()); | |
740 download_shell_->Close(); | |
741 download_shell_ = nullptr; | |
742 } | |
743 | |
744 private: | |
745 Shell* download_shell_ = nullptr; | |
746 }; | |
747 | |
748 INSTANTIATE_TEST_CASE_P( | |
749 _, | |
750 DownloadResumptionContentTest, | |
751 ::testing::Values(DownloadResumptionTestType::RESUME_WITH_RENDERER, | |
svaldez
2015/12/14 21:18:15
Is the :: at the beginning necessary?
asanka
2015/12/14 21:31:02
Not strictly necessary, but it's common for the te
svaldez
2015/12/14 22:01:36
Acknowledged.
| |
752 DownloadResumptionTestType::RESUME_WITHOUT_RENDERER)); | |
753 | |
693 } // namespace | 754 } // namespace |
694 | 755 |
695 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadCancelled) { | 756 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadCancelled) { |
696 SetupEnsureNoPendingDownloads(); | 757 SetupEnsureNoPendingDownloads(); |
697 | 758 |
698 // Create a download, wait until it's started, and confirm | 759 // Create a download, wait until it's started, and confirm |
699 // we're in the expected state. | 760 // we're in the expected state. |
700 DownloadItem* download = StartDownloadAndReturnItem( | 761 DownloadItem* download = StartDownloadAndReturnItem( |
701 GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 762 shell(), GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
702 ASSERT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); | 763 ASSERT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); |
703 | 764 |
704 // Cancel the download and wait for download system quiesce. | 765 // Cancel the download and wait for download system quiesce. |
705 download->Cancel(true); | 766 download->Cancel(true); |
706 scoped_refptr<DownloadTestFlushObserver> flush_observer( | 767 scoped_refptr<DownloadTestFlushObserver> flush_observer( |
707 new DownloadTestFlushObserver(DownloadManagerForShell(shell()))); | 768 new DownloadTestFlushObserver(DownloadManagerForShell(shell()))); |
708 flush_observer->WaitForFlush(); | 769 flush_observer->WaitForFlush(); |
709 | 770 |
710 // Get the important info from other threads and check it. | 771 // Get the important info from other threads and check it. |
711 EXPECT_TRUE(EnsureNoPendingDownloads()); | 772 EXPECT_TRUE(EnsureNoPendingDownloads()); |
712 } | 773 } |
713 | 774 |
714 // Check that downloading multiple (in this case, 2) files does not result in | 775 // Check that downloading multiple (in this case, 2) files does not result in |
715 // corrupted files. | 776 // corrupted files. |
716 IN_PROC_BROWSER_TEST_F(DownloadContentTest, MultiDownload) { | 777 IN_PROC_BROWSER_TEST_F(DownloadContentTest, MultiDownload) { |
717 SetupEnsureNoPendingDownloads(); | 778 SetupEnsureNoPendingDownloads(); |
718 | 779 |
719 // Create a download, wait until it's started, and confirm | 780 // Create a download, wait until it's started, and confirm |
720 // we're in the expected state. | 781 // we're in the expected state. |
721 DownloadItem* download1 = StartDownloadAndReturnItem( | 782 DownloadItem* download1 = StartDownloadAndReturnItem( |
722 GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 783 shell(), GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
723 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); | 784 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); |
724 | 785 |
725 // Start the second download and wait until it's done. | 786 // Start the second download and wait until it's done. |
726 GURL url(net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); | 787 GURL url(net::URLRequestMockHTTPJob::GetMockUrl("download-test.lib")); |
727 DownloadItem* download2 = StartDownloadAndReturnItem(url); | 788 DownloadItem* download2 = StartDownloadAndReturnItem(shell(), url); |
728 WaitForCompletion(download2); | 789 WaitForCompletion(download2); |
729 | 790 |
730 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); | 791 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); |
731 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); | 792 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); |
732 | 793 |
733 // Allow the first request to finish. | 794 // Allow the first request to finish. |
734 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(shell(), 1)); | 795 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(shell(), 1)); |
735 NavigateToURL(shell(), | 796 NavigateToURL(shell(), |
736 GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); | 797 GURL(net::URLRequestSlowDownloadJob::kFinishDownloadUrl)); |
737 observer2->WaitForFinished(); // Wait for the third request. | 798 observer2->WaitForFinished(); // Wait for the third request. |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
883 #define MAYBE_ShutdownInProgress DISABLED_ShutdownInProgress | 944 #define MAYBE_ShutdownInProgress DISABLED_ShutdownInProgress |
884 #else | 945 #else |
885 #define MAYBE_ShutdownInProgress ShutdownInProgress | 946 #define MAYBE_ShutdownInProgress ShutdownInProgress |
886 #endif | 947 #endif |
887 | 948 |
888 // Try to shutdown with a download in progress to make sure shutdown path | 949 // Try to shutdown with a download in progress to make sure shutdown path |
889 // works properly. | 950 // works properly. |
890 IN_PROC_BROWSER_TEST_F(DownloadContentTest, MAYBE_ShutdownInProgress) { | 951 IN_PROC_BROWSER_TEST_F(DownloadContentTest, MAYBE_ShutdownInProgress) { |
891 // Create a download that won't complete. | 952 // Create a download that won't complete. |
892 DownloadItem* download = StartDownloadAndReturnItem( | 953 DownloadItem* download = StartDownloadAndReturnItem( |
893 GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 954 shell(), GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
894 | 955 |
895 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); | 956 EXPECT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); |
896 | 957 |
897 // Shutdown the download manager and make sure we get the right | 958 // Shutdown the download manager and make sure we get the right |
898 // notifications in the right order. | 959 // notifications in the right order. |
899 StrictMock<MockDownloadItemObserver> item_observer; | 960 StrictMock<MockDownloadItemObserver> item_observer; |
900 download->AddObserver(&item_observer); | 961 download->AddObserver(&item_observer); |
901 MockDownloadManagerObserver manager_observer( | 962 MockDownloadManagerObserver manager_observer( |
902 DownloadManagerForShell(shell())); | 963 DownloadManagerForShell(shell())); |
903 // Don't care about ModelChanged() events. | 964 // Don't care about ModelChanged() events. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
983 MockDownloadItemObserver observer; | 1044 MockDownloadItemObserver observer; |
984 items[0]->AddObserver(&observer); | 1045 items[0]->AddObserver(&observer); |
985 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); | 1046 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); |
986 | 1047 |
987 // Shutdown the download manager. Mostly this is confirming a lack of | 1048 // Shutdown the download manager. Mostly this is confirming a lack of |
988 // crashes. | 1049 // crashes. |
989 DownloadManagerForShell(shell())->Shutdown(); | 1050 DownloadManagerForShell(shell())->Shutdown(); |
990 } | 1051 } |
991 | 1052 |
992 // Test resumption with a response that contains strong validators. | 1053 // Test resumption with a response that contains strong validators. |
993 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Resume_WithStrongValidators) { | 1054 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, StrongValidators) { |
994 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
995 switches::kEnableDownloadResumption); | |
996 | |
997 TestDownloadRequestHandler request_handler; | 1055 TestDownloadRequestHandler request_handler; |
998 TestDownloadRequestHandler::Parameters parameters = | 1056 TestDownloadRequestHandler::Parameters parameters = |
999 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1057 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
1000 const TestDownloadRequestHandler::InjectedError interruption = | 1058 const TestDownloadRequestHandler::InjectedError interruption = |
1001 parameters.injected_errors.front(); | 1059 parameters.injected_errors.front(); |
1002 request_handler.StartServing(parameters); | 1060 request_handler.StartServing(parameters); |
1003 | 1061 |
1004 DownloadItem* download = StartDownloadAndReturnItem(request_handler.url()); | 1062 DownloadItem* download = |
1063 StartDownloadAndReturnItem(download_shell(), request_handler.url()); | |
1005 WaitForInterrupt(download); | 1064 WaitForInterrupt(download); |
1006 | 1065 |
1007 ASSERT_EQ(interruption.offset, download->GetReceivedBytes()); | 1066 ASSERT_EQ(interruption.offset, download->GetReceivedBytes()); |
1008 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1067 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
1009 | 1068 |
1069 PrepareToResume(); | |
1010 download->Resume(); | 1070 download->Resume(); |
1011 WaitForCompletion(download); | 1071 WaitForCompletion(download); |
1012 | 1072 |
1013 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); | 1073 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
1014 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1074 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
1015 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( | 1075 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( |
1016 parameters.pattern_generator_seed, parameters.size, | 1076 parameters.pattern_generator_seed, parameters.size, |
1017 download->GetTargetFilePath())); | 1077 download->GetTargetFilePath())); |
1018 | 1078 |
1019 // Characterization risk: The next portion of the test examines the requests | 1079 // Characterization risk: The next portion of the test examines the requests |
(...skipping 22 matching lines...) Expand all Loading... | |
1042 net::HttpRequestHeaders::kRange, &value)); | 1102 net::HttpRequestHeaders::kRange, &value)); |
1043 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), | 1103 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), |
1044 value); | 1104 value); |
1045 } | 1105 } |
1046 | 1106 |
1047 // A partial resumption results in an HTTP 200 response. I.e. the server ignored | 1107 // A partial resumption results in an HTTP 200 response. I.e. the server ignored |
1048 // the range request and sent the entire resource instead. For If-Range requests | 1108 // the range request and sent the entire resource instead. For If-Range requests |
1049 // (as opposed to If-Match), the behavior for a precondition failure is also to | 1109 // (as opposed to If-Match), the behavior for a precondition failure is also to |
1050 // respond with a 200. So this test case covers both validation failure and | 1110 // respond with a 200. So this test case covers both validation failure and |
1051 // ignoring the range request. | 1111 // ignoring the range request. |
1052 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1112 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, |
1053 Resume_RestartIfNotPartialResponse) { | 1113 RestartIfNotPartialResponse) { |
1054 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
1055 switches::kEnableDownloadResumption); | |
1056 const int kOriginalPatternGeneratorSeed = 1; | 1114 const int kOriginalPatternGeneratorSeed = 1; |
1057 const int kNewPatternGeneratorSeed = 2; | 1115 const int kNewPatternGeneratorSeed = 2; |
1058 | 1116 |
1059 TestDownloadRequestHandler::Parameters parameters = | 1117 TestDownloadRequestHandler::Parameters parameters = |
1060 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1118 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
1061 parameters.pattern_generator_seed = kOriginalPatternGeneratorSeed; | 1119 parameters.pattern_generator_seed = kOriginalPatternGeneratorSeed; |
1062 const TestDownloadRequestHandler::InjectedError interruption = | 1120 const TestDownloadRequestHandler::InjectedError interruption = |
1063 parameters.injected_errors.front(); | 1121 parameters.injected_errors.front(); |
1064 | 1122 |
1065 TestDownloadRequestHandler request_handler; | 1123 TestDownloadRequestHandler request_handler; |
1066 request_handler.StartServing(parameters); | 1124 request_handler.StartServing(parameters); |
1067 | 1125 |
1068 DownloadItem* download = StartDownloadAndReturnItem(request_handler.url()); | 1126 DownloadItem* download = |
1127 StartDownloadAndReturnItem(download_shell(), request_handler.url()); | |
1069 WaitForInterrupt(download); | 1128 WaitForInterrupt(download); |
1070 | 1129 |
1071 ASSERT_EQ(interruption.offset, download->GetReceivedBytes()); | 1130 ASSERT_EQ(interruption.offset, download->GetReceivedBytes()); |
1072 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1131 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
1073 | 1132 |
1074 parameters = TestDownloadRequestHandler::Parameters(); | 1133 parameters = TestDownloadRequestHandler::Parameters(); |
1075 parameters.support_byte_ranges = false; | 1134 parameters.support_byte_ranges = false; |
1076 parameters.pattern_generator_seed = kNewPatternGeneratorSeed; | 1135 parameters.pattern_generator_seed = kNewPatternGeneratorSeed; |
1077 request_handler.StartServing(parameters); | 1136 request_handler.StartServing(parameters); |
1078 | 1137 |
1138 PrepareToResume(); | |
1079 download->Resume(); | 1139 download->Resume(); |
1080 WaitForCompletion(download); | 1140 WaitForCompletion(download); |
1081 | 1141 |
1082 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); | 1142 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
1083 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1143 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
1084 ASSERT_NO_FATAL_FAILURE( | 1144 ASSERT_NO_FATAL_FAILURE( |
1085 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, | 1145 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, |
1086 download->GetTargetFilePath())); | 1146 download->GetTargetFilePath())); |
1087 | 1147 |
1088 // When the downloads system sees the full response, it should accept the | 1148 // When the downloads system sees the full response, it should accept the |
(...skipping 17 matching lines...) Expand all Loading... | |
1106 net::HttpRequestHeaders::kIfRange, &value)); | 1166 net::HttpRequestHeaders::kIfRange, &value)); |
1107 EXPECT_EQ(parameters.etag, value); | 1167 EXPECT_EQ(parameters.etag, value); |
1108 | 1168 |
1109 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1169 ASSERT_TRUE(requests[1].request_headers.GetHeader( |
1110 net::HttpRequestHeaders::kRange, &value)); | 1170 net::HttpRequestHeaders::kRange, &value)); |
1111 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), | 1171 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), |
1112 value); | 1172 value); |
1113 } | 1173 } |
1114 | 1174 |
1115 // Confirm we restart if we don't have a verifier. | 1175 // Confirm we restart if we don't have a verifier. |
1116 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Resume_RestartIfNoETag) { | 1176 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RestartIfNoETag) { |
1117 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
1118 switches::kEnableDownloadResumption); | |
1119 const int kOriginalPatternGeneratorSeed = 1; | 1177 const int kOriginalPatternGeneratorSeed = 1; |
1120 const int kNewPatternGeneratorSeed = 2; | 1178 const int kNewPatternGeneratorSeed = 2; |
1121 | 1179 |
1122 TestDownloadRequestHandler::Parameters parameters = | 1180 TestDownloadRequestHandler::Parameters parameters = |
1123 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1181 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
1124 ASSERT_EQ(1u, parameters.injected_errors.size()); | 1182 ASSERT_EQ(1u, parameters.injected_errors.size()); |
1125 parameters.etag.clear(); | 1183 parameters.etag.clear(); |
1126 parameters.pattern_generator_seed = kOriginalPatternGeneratorSeed; | 1184 parameters.pattern_generator_seed = kOriginalPatternGeneratorSeed; |
1127 | 1185 |
1128 TestDownloadRequestHandler request_handler; | 1186 TestDownloadRequestHandler request_handler; |
1129 request_handler.StartServing(parameters); | 1187 request_handler.StartServing(parameters); |
1130 DownloadItem* download = StartDownloadAndReturnItem(request_handler.url()); | 1188 DownloadItem* download = |
1189 StartDownloadAndReturnItem(download_shell(), request_handler.url()); | |
1131 WaitForInterrupt(download); | 1190 WaitForInterrupt(download); |
1132 | 1191 |
1133 parameters.pattern_generator_seed = kNewPatternGeneratorSeed; | 1192 parameters.pattern_generator_seed = kNewPatternGeneratorSeed; |
1134 parameters.ClearInjectedErrors(); | 1193 parameters.ClearInjectedErrors(); |
1135 request_handler.StartServing(parameters); | 1194 request_handler.StartServing(parameters); |
1136 | 1195 |
1196 PrepareToResume(); | |
1137 download->Resume(); | 1197 download->Resume(); |
1138 WaitForCompletion(download); | 1198 WaitForCompletion(download); |
1139 | 1199 |
1140 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); | 1200 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
1141 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1201 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
1142 ASSERT_NO_FATAL_FAILURE( | 1202 ASSERT_NO_FATAL_FAILURE( |
1143 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, | 1203 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, |
1144 download->GetTargetFilePath())); | 1204 download->GetTargetFilePath())); |
1145 | 1205 |
1146 TestDownloadRequestHandler::CompletedRequests requests; | 1206 TestDownloadRequestHandler::CompletedRequests requests; |
1147 request_handler.GetCompletedRequestInfo(&requests); | 1207 request_handler.GetCompletedRequestInfo(&requests); |
1148 | 1208 |
1149 // Neither If-Range nor Range headers should be present in the second request. | 1209 // Neither If-Range nor Range headers should be present in the second request. |
1150 ASSERT_EQ(2u, requests.size()); | 1210 ASSERT_EQ(2u, requests.size()); |
1151 std::string value; | 1211 std::string value; |
1152 EXPECT_FALSE(requests[1].request_headers.GetHeader( | 1212 EXPECT_FALSE(requests[1].request_headers.GetHeader( |
1153 net::HttpRequestHeaders::kIfRange, &value)); | 1213 net::HttpRequestHeaders::kIfRange, &value)); |
1154 EXPECT_FALSE(requests[1].request_headers.GetHeader( | 1214 EXPECT_FALSE(requests[1].request_headers.GetHeader( |
1155 net::HttpRequestHeaders::kRange, &value)); | 1215 net::HttpRequestHeaders::kRange, &value)); |
1156 } | 1216 } |
1157 | 1217 |
1158 // Partial file goes missing before the download is resumed. The download should | 1218 // Partial file goes missing before the download is resumed. The download should |
1159 // restart. | 1219 // restart. |
1160 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Resume_RestartIfNoPartialFile) { | 1220 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RestartIfNoPartialFile) { |
1161 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
1162 switches::kEnableDownloadResumption); | |
1163 TestDownloadRequestHandler::Parameters parameters = | 1221 TestDownloadRequestHandler::Parameters parameters = |
1164 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1222 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
1165 | 1223 |
1166 TestDownloadRequestHandler request_handler; | 1224 TestDownloadRequestHandler request_handler; |
1167 request_handler.StartServing(parameters); | 1225 request_handler.StartServing(parameters); |
1168 DownloadItem* download = StartDownloadAndReturnItem(request_handler.url()); | 1226 DownloadItem* download = |
1227 StartDownloadAndReturnItem(download_shell(), request_handler.url()); | |
1169 WaitForInterrupt(download); | 1228 WaitForInterrupt(download); |
1170 | 1229 |
1171 // Delete the intermediate file. | 1230 // Delete the intermediate file. |
1172 ASSERT_TRUE(base::PathExists(download->GetFullPath())); | 1231 ASSERT_TRUE(base::PathExists(download->GetFullPath())); |
1173 ASSERT_TRUE(base::DeleteFile(download->GetFullPath(), false)); | 1232 ASSERT_TRUE(base::DeleteFile(download->GetFullPath(), false)); |
1174 | 1233 |
1175 parameters.ClearInjectedErrors(); | 1234 parameters.ClearInjectedErrors(); |
1176 request_handler.StartServing(parameters); | 1235 request_handler.StartServing(parameters); |
1177 | 1236 |
1237 PrepareToResume(); | |
1178 download->Resume(); | 1238 download->Resume(); |
1179 WaitForCompletion(download); | 1239 WaitForCompletion(download); |
1180 | 1240 |
1181 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); | 1241 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
1182 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1242 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
1183 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( | 1243 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( |
1184 parameters.pattern_generator_seed, parameters.size, | 1244 parameters.pattern_generator_seed, parameters.size, |
1185 download->GetTargetFilePath())); | 1245 download->GetTargetFilePath())); |
1186 } | 1246 } |
1187 | 1247 |
1188 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Resume_RecoverFromInitFileError) { | 1248 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, |
1189 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1249 RecoverFromInitFileError) { |
1190 switches::kEnableDownloadResumption); | |
1191 TestDownloadRequestHandler request_handler; | 1250 TestDownloadRequestHandler request_handler; |
1192 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); | 1251 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); |
1193 | 1252 |
1194 // Setup the error injector. | 1253 // Setup the error injector. |
1195 scoped_refptr<TestFileErrorInjector> injector( | 1254 scoped_refptr<TestFileErrorInjector> injector( |
1196 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); | 1255 TestFileErrorInjector::Create(DownloadManagerForShell(download_shell()))); |
1197 | 1256 |
1198 const TestFileErrorInjector::FileErrorInfo err = { | 1257 const TestFileErrorInjector::FileErrorInfo err = { |
1199 request_handler.url().spec(), | 1258 request_handler.url().spec(), |
1200 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, | 1259 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, |
1201 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; | 1260 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; |
1202 injector->AddError(err); | 1261 injector->AddError(err); |
1203 injector->InjectErrors(); | 1262 injector->InjectErrors(); |
1204 | 1263 |
1205 // Start and watch for interrupt. | 1264 // Start and watch for interrupt. |
1206 DownloadItem* download(StartDownloadAndReturnItem(request_handler.url())); | 1265 DownloadItem* download( |
1266 StartDownloadAndReturnItem(download_shell(), request_handler.url())); | |
1207 WaitForInterrupt(download); | 1267 WaitForInterrupt(download); |
1208 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1268 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
1209 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 1269 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
1210 download->GetLastReason()); | 1270 download->GetLastReason()); |
1211 EXPECT_EQ(0, download->GetReceivedBytes()); | 1271 EXPECT_EQ(0, download->GetReceivedBytes()); |
1212 EXPECT_TRUE(download->GetFullPath().empty()); | 1272 EXPECT_TRUE(download->GetFullPath().empty()); |
1213 EXPECT_TRUE(download->GetTargetFilePath().empty()); | 1273 EXPECT_TRUE(download->GetTargetFilePath().empty()); |
1214 | 1274 |
1215 // We need to make sure that any cross-thread downloads communication has | 1275 // We need to make sure that any cross-thread downloads communication has |
1216 // quiesced before clearing and injecting the new errors, as the | 1276 // quiesced before clearing and injecting the new errors, as the |
1217 // InjectErrors() routine alters the currently in use download file | 1277 // InjectErrors() routine alters the currently in use download file |
1218 // factory, which is a file thread object. | 1278 // factory, which is a file thread object. |
1219 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1279 RunAllPendingInMessageLoop(BrowserThread::FILE); |
1220 RunAllPendingInMessageLoop(); | 1280 RunAllPendingInMessageLoop(); |
1221 | 1281 |
1222 // Clear the old errors list. | 1282 // Clear the old errors list. |
1223 injector->ClearErrors(); | 1283 injector->ClearErrors(); |
1224 injector->InjectErrors(); | 1284 injector->InjectErrors(); |
1225 | 1285 |
1226 // Resume and watch completion. | 1286 // Resume and watch completion. |
1287 PrepareToResume(); | |
1227 download->Resume(); | 1288 download->Resume(); |
1228 WaitForCompletion(download); | 1289 WaitForCompletion(download); |
1229 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1290 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
1230 } | 1291 } |
1231 | 1292 |
1232 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1293 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, |
1233 Resume_RecoverFromIntermediateFileRenameError) { | 1294 RecoverFromIntermediateFileRenameError) { |
1234 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
1235 switches::kEnableDownloadResumption); | |
1236 TestDownloadRequestHandler request_handler; | 1295 TestDownloadRequestHandler request_handler; |
1237 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); | 1296 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); |
1238 | 1297 |
1239 // Setup the error injector. | 1298 // Setup the error injector. |
1240 scoped_refptr<TestFileErrorInjector> injector( | 1299 scoped_refptr<TestFileErrorInjector> injector( |
1241 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); | 1300 TestFileErrorInjector::Create(DownloadManagerForShell(download_shell()))); |
1242 | 1301 |
1243 const TestFileErrorInjector::FileErrorInfo err = { | 1302 const TestFileErrorInjector::FileErrorInfo err = { |
1244 request_handler.url().spec(), | 1303 request_handler.url().spec(), |
1245 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, 0, | 1304 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, 0, |
1246 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; | 1305 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; |
1247 injector->AddError(err); | 1306 injector->AddError(err); |
1248 injector->InjectErrors(); | 1307 injector->InjectErrors(); |
1249 | 1308 |
1250 // Start and watch for interrupt. | 1309 // Start and watch for interrupt. |
1251 DownloadItem* download(StartDownloadAndReturnItem(request_handler.url())); | 1310 DownloadItem* download( |
1311 StartDownloadAndReturnItem(download_shell(), request_handler.url())); | |
1252 WaitForInterrupt(download); | 1312 WaitForInterrupt(download); |
1253 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1313 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
1254 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 1314 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
1255 download->GetLastReason()); | 1315 download->GetLastReason()); |
1256 EXPECT_TRUE(download->GetFullPath().empty()); | 1316 EXPECT_TRUE(download->GetFullPath().empty()); |
1257 // Target path will have been set after file name determination. GetFullPath() | 1317 // Target path will have been set after file name determination. GetFullPath() |
1258 // being empty is sufficient to signal that filename determination needs to be | 1318 // being empty is sufficient to signal that filename determination needs to be |
1259 // redone. | 1319 // redone. |
1260 EXPECT_FALSE(download->GetTargetFilePath().empty()); | 1320 EXPECT_FALSE(download->GetTargetFilePath().empty()); |
1261 | 1321 |
1262 // We need to make sure that any cross-thread downloads communication has | 1322 // We need to make sure that any cross-thread downloads communication has |
1263 // quiesced before clearing and injecting the new errors, as the | 1323 // quiesced before clearing and injecting the new errors, as the |
1264 // InjectErrors() routine alters the currently in use download file | 1324 // InjectErrors() routine alters the currently in use download file |
1265 // factory, which is a file thread object. | 1325 // factory, which is a file thread object. |
1266 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1326 RunAllPendingInMessageLoop(BrowserThread::FILE); |
1267 RunAllPendingInMessageLoop(); | 1327 RunAllPendingInMessageLoop(); |
1268 | 1328 |
1269 // Clear the old errors list. | 1329 // Clear the old errors list. |
1270 injector->ClearErrors(); | 1330 injector->ClearErrors(); |
1271 injector->InjectErrors(); | 1331 injector->InjectErrors(); |
1272 | 1332 |
1333 PrepareToResume(); | |
1273 download->Resume(); | 1334 download->Resume(); |
1274 WaitForCompletion(download); | 1335 WaitForCompletion(download); |
1275 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1336 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
1276 } | 1337 } |
1277 | 1338 |
1278 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1339 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, |
1279 Resume_RecoverFromFinalRenameError) { | 1340 RecoverFromFinalRenameError) { |
1280 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
1281 switches::kEnableDownloadResumption); | |
1282 TestDownloadRequestHandler request_handler; | 1341 TestDownloadRequestHandler request_handler; |
1283 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); | 1342 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); |
1284 | 1343 |
1285 // Setup the error injector. | 1344 // Setup the error injector. |
1286 scoped_refptr<TestFileErrorInjector> injector( | 1345 scoped_refptr<TestFileErrorInjector> injector( |
1287 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); | 1346 TestFileErrorInjector::Create(DownloadManagerForShell(download_shell()))); |
1288 | 1347 |
1289 DownloadManagerForShell(shell())->RemoveAllDownloads(); | 1348 DownloadManagerForShell(download_shell())->RemoveAllDownloads(); |
1290 TestFileErrorInjector::FileErrorInfo err = { | 1349 TestFileErrorInjector::FileErrorInfo err = { |
1291 request_handler.url().spec(), | 1350 request_handler.url().spec(), |
1292 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, 0, | 1351 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, 0, |
1293 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; | 1352 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; |
1294 injector->AddError(err); | 1353 injector->AddError(err); |
1295 injector->InjectErrors(); | 1354 injector->InjectErrors(); |
1296 | 1355 |
1297 // Start and watch for interrupt. | 1356 // Start and watch for interrupt. |
1298 DownloadItem* download(StartDownloadAndReturnItem(request_handler.url())); | 1357 DownloadItem* download( |
1358 StartDownloadAndReturnItem(download_shell(), request_handler.url())); | |
1299 WaitForInterrupt(download); | 1359 WaitForInterrupt(download); |
1300 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1360 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
1301 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 1361 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
1302 download->GetLastReason()); | 1362 download->GetLastReason()); |
1303 EXPECT_TRUE(download->GetFullPath().empty()); | 1363 EXPECT_TRUE(download->GetFullPath().empty()); |
1304 // Target path should still be intact. | 1364 // Target path should still be intact. |
1305 EXPECT_FALSE(download->GetTargetFilePath().empty()); | 1365 EXPECT_FALSE(download->GetTargetFilePath().empty()); |
1306 | 1366 |
1307 // We need to make sure that any cross-thread downloads communication has | 1367 // We need to make sure that any cross-thread downloads communication has |
1308 // quiesced before clearing and injecting the new errors, as the | 1368 // quiesced before clearing and injecting the new errors, as the |
1309 // InjectErrors() routine alters the currently in use download file | 1369 // InjectErrors() routine alters the currently in use download file |
1310 // factory, which is a file thread object. | 1370 // factory, which is a file thread object. |
1311 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1371 RunAllPendingInMessageLoop(BrowserThread::FILE); |
1312 RunAllPendingInMessageLoop(); | 1372 RunAllPendingInMessageLoop(); |
1313 | 1373 |
1314 // Clear the old errors list. | 1374 // Clear the old errors list. |
1315 injector->ClearErrors(); | 1375 injector->ClearErrors(); |
1316 injector->InjectErrors(); | 1376 injector->InjectErrors(); |
1317 | 1377 |
1378 PrepareToResume(); | |
1318 download->Resume(); | 1379 download->Resume(); |
1319 WaitForCompletion(download); | 1380 WaitForCompletion(download); |
1320 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1381 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
1321 } | 1382 } |
1322 | 1383 |
1323 // An interrupted download should remove the intermediate file when it is | 1384 // An interrupted download should remove the intermediate file when it is |
1324 // cancelled. | 1385 // cancelled. |
1325 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelInterruptedDownload) { | 1386 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, |
1326 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1387 CancelInterruptedDownload) { |
1327 switches::kEnableDownloadResumption); | |
1328 TestDownloadRequestHandler request_handler; | 1388 TestDownloadRequestHandler request_handler; |
1329 request_handler.StartServing( | 1389 request_handler.StartServing( |
1330 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); | 1390 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); |
1331 | 1391 |
1332 DownloadItem* download = StartDownloadAndReturnItem(request_handler.url()); | 1392 DownloadItem* download = |
1393 StartDownloadAndReturnItem(download_shell(), request_handler.url()); | |
1333 WaitForInterrupt(download); | 1394 WaitForInterrupt(download); |
1334 | 1395 |
1335 base::FilePath intermediate_path = download->GetFullPath(); | 1396 base::FilePath intermediate_path = download->GetFullPath(); |
1336 ASSERT_FALSE(intermediate_path.empty()); | 1397 ASSERT_FALSE(intermediate_path.empty()); |
1337 ASSERT_TRUE(base::PathExists(intermediate_path)); | 1398 ASSERT_TRUE(base::PathExists(intermediate_path)); |
1338 | 1399 |
1339 download->Cancel(true /* user_cancel */); | 1400 download->Cancel(true /* user_cancel */); |
1340 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1401 RunAllPendingInMessageLoop(BrowserThread::FILE); |
1341 RunAllPendingInMessageLoop(); | 1402 RunAllPendingInMessageLoop(); |
1342 | 1403 |
1343 // The intermediate file should now be gone. | 1404 // The intermediate file should now be gone. |
1344 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1405 EXPECT_FALSE(base::PathExists(intermediate_path)); |
1345 EXPECT_TRUE(download->GetFullPath().empty()); | 1406 EXPECT_TRUE(download->GetFullPath().empty()); |
1346 } | 1407 } |
1347 | 1408 |
1348 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveInterruptedDownload) { | 1409 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, |
1349 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1410 RemoveInterruptedDownload) { |
1350 switches::kEnableDownloadResumption); | |
1351 TestDownloadRequestHandler request_handler; | 1411 TestDownloadRequestHandler request_handler; |
1352 request_handler.StartServing( | 1412 request_handler.StartServing( |
1353 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); | 1413 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); |
1354 | 1414 |
1355 DownloadItem* download = StartDownloadAndReturnItem(request_handler.url()); | 1415 DownloadItem* download = |
1416 StartDownloadAndReturnItem(download_shell(), request_handler.url()); | |
1356 WaitForInterrupt(download); | 1417 WaitForInterrupt(download); |
1357 | 1418 |
1358 base::FilePath intermediate_path = download->GetFullPath(); | 1419 base::FilePath intermediate_path = download->GetFullPath(); |
1359 ASSERT_FALSE(intermediate_path.empty()); | 1420 ASSERT_FALSE(intermediate_path.empty()); |
1360 ASSERT_TRUE(base::PathExists(intermediate_path)); | 1421 ASSERT_TRUE(base::PathExists(intermediate_path)); |
1361 | 1422 |
1362 download->Remove(); | 1423 download->Remove(); |
1363 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1424 RunAllPendingInMessageLoop(BrowserThread::FILE); |
1364 RunAllPendingInMessageLoop(); | 1425 RunAllPendingInMessageLoop(); |
1365 | 1426 |
1366 // The intermediate file should now be gone. | 1427 // The intermediate file should now be gone. |
1367 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1428 EXPECT_FALSE(base::PathExists(intermediate_path)); |
1368 } | 1429 } |
1369 | 1430 |
1370 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveCompletedDownload) { | 1431 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveCompletedDownload) { |
1371 // A completed download shouldn't delete the downloaded file when it is | 1432 // A completed download shouldn't delete the downloaded file when it is |
1372 // removed. | 1433 // removed. |
1373 TestDownloadRequestHandler request_handler; | 1434 TestDownloadRequestHandler request_handler; |
1374 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); | 1435 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); |
1375 scoped_ptr<DownloadTestObserver> completion_observer( | 1436 scoped_ptr<DownloadTestObserver> completion_observer( |
1376 CreateWaiter(shell(), 1)); | 1437 CreateWaiter(shell(), 1)); |
svaldez
2015/12/14 21:18:15
download_shell()?
asanka
2015/12/14 21:31:02
This isn't a resumption test, and hence doesn't ne
svaldez
2015/12/14 22:01:36
Ah, okay. Might be better to move it out from betw
| |
1377 DownloadItem* download(StartDownloadAndReturnItem(request_handler.url())); | 1438 DownloadItem* download( |
1439 StartDownloadAndReturnItem(shell(), request_handler.url())); | |
svaldez
2015/12/14 21:18:15
download_shell()?
asanka
2015/12/14 21:31:02
Ditto.
svaldez
2015/12/14 22:01:36
Acknowledged.
| |
1378 completion_observer->WaitForFinished(); | 1440 completion_observer->WaitForFinished(); |
1379 | 1441 |
1380 // The target path should exist. | 1442 // The target path should exist. |
1381 base::FilePath target_path(download->GetTargetFilePath()); | 1443 base::FilePath target_path(download->GetTargetFilePath()); |
1382 EXPECT_TRUE(base::PathExists(target_path)); | 1444 EXPECT_TRUE(base::PathExists(target_path)); |
1383 download->Remove(); | 1445 download->Remove(); |
1384 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1446 RunAllPendingInMessageLoop(BrowserThread::FILE); |
1385 RunAllPendingInMessageLoop(); | 1447 RunAllPendingInMessageLoop(); |
1386 | 1448 |
1387 // The file should still exist. | 1449 // The file should still exist. |
1388 EXPECT_TRUE(base::PathExists(target_path)); | 1450 EXPECT_TRUE(base::PathExists(target_path)); |
1389 } | 1451 } |
1390 | 1452 |
1391 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { | 1453 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RemoveResumingDownload) { |
1392 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
1393 switches::kEnableDownloadResumption); | |
1394 TestDownloadRequestHandler::Parameters parameters = | 1454 TestDownloadRequestHandler::Parameters parameters = |
1395 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1455 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
1396 TestDownloadRequestHandler request_handler; | 1456 TestDownloadRequestHandler request_handler; |
1397 request_handler.StartServing(parameters); | 1457 request_handler.StartServing(parameters); |
1398 | 1458 |
1399 DownloadItem* download = StartDownloadAndReturnItem(request_handler.url()); | 1459 DownloadItem* download = |
1460 StartDownloadAndReturnItem(download_shell(), request_handler.url()); | |
1400 WaitForInterrupt(download); | 1461 WaitForInterrupt(download); |
1401 | 1462 |
1402 base::FilePath intermediate_path(download->GetFullPath()); | 1463 base::FilePath intermediate_path(download->GetFullPath()); |
1403 ASSERT_FALSE(intermediate_path.empty()); | 1464 ASSERT_FALSE(intermediate_path.empty()); |
1404 EXPECT_TRUE(base::PathExists(intermediate_path)); | 1465 EXPECT_TRUE(base::PathExists(intermediate_path)); |
1405 | 1466 |
1406 // Resume and remove download. We expect only a single OnDownloadCreated() | 1467 // Resume and remove download. We expect only a single OnDownloadCreated() |
1407 // call, and that's for the second download created below. | 1468 // call, and that's for the second download created below. |
1408 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); | 1469 MockDownloadManagerObserver dm_observer( |
1470 DownloadManagerForShell(download_shell())); | |
1409 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); | 1471 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); |
1410 | 1472 |
1411 TestRequestStartHandler request_start_handler; | 1473 TestRequestStartHandler request_start_handler; |
1412 parameters.on_start_handler = request_start_handler.GetOnStartHandler(); | 1474 parameters.on_start_handler = request_start_handler.GetOnStartHandler(); |
1413 request_handler.StartServing(parameters); | 1475 request_handler.StartServing(parameters); |
1414 | 1476 |
1477 PrepareToResume(); | |
1415 download->Resume(); | 1478 download->Resume(); |
1416 request_start_handler.WaitForCallback(); | 1479 request_start_handler.WaitForCallback(); |
1417 | 1480 |
1418 // At this point, the download resumption request has been sent out, but the | 1481 // At this point, the download resumption request has been sent out, but the |
1419 // reponse hasn't been received yet. | 1482 // reponse hasn't been received yet. |
1420 download->Remove(); | 1483 download->Remove(); |
1421 | 1484 |
1422 request_start_handler.RespondWith(std::string(), net::OK); | 1485 request_start_handler.RespondWith(std::string(), net::OK); |
1423 | 1486 |
1424 // The intermediate file should now be gone. | 1487 // The intermediate file should now be gone. |
1425 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1488 RunAllPendingInMessageLoop(BrowserThread::FILE); |
1426 RunAllPendingInMessageLoop(); | 1489 RunAllPendingInMessageLoop(); |
1427 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1490 EXPECT_FALSE(base::PathExists(intermediate_path)); |
1428 | 1491 |
1429 parameters.ClearInjectedErrors(); | 1492 parameters.ClearInjectedErrors(); |
1430 parameters.on_start_handler.Reset(); | 1493 parameters.on_start_handler.Reset(); |
1431 request_handler.StartServing(parameters); | 1494 request_handler.StartServing(parameters); |
1432 | 1495 |
1433 // Start the second download and wait until it's done. This exercises the | 1496 // Start the second download and wait until it's done. This exercises the |
1434 // entire downloads stack and effectively flushes all of our worker threads. | 1497 // entire downloads stack and effectively flushes all of our worker threads. |
1435 // We are testing whether the URL request created in the previous | 1498 // We are testing whether the URL request created in the previous |
1436 // DownloadItem::Resume() call reulted in a new download or not. | 1499 // DownloadItem::Resume() call reulted in a new download or not. |
1437 NavigateToURLAndWaitForDownload(shell(), request_handler.url(), | 1500 NavigateToURLAndWaitForDownload(shell(), request_handler.url(), |
svaldez
2015/12/14 21:18:15
download_shell()?
asanka
2015/12/14 21:31:02
This call is intentionally using shell() instead o
svaldez
2015/12/14 22:01:36
Acknowledged.
| |
1438 DownloadItem::COMPLETE); | 1501 DownloadItem::COMPLETE); |
1439 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1502 EXPECT_TRUE(EnsureNoPendingDownloads()); |
1440 } | 1503 } |
1441 | 1504 |
1442 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumingDownload) { | 1505 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, CancelResumingDownload) { |
1443 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
1444 switches::kEnableDownloadResumption); | |
1445 TestDownloadRequestHandler::Parameters parameters = | 1506 TestDownloadRequestHandler::Parameters parameters = |
1446 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1507 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
1447 TestDownloadRequestHandler request_handler; | 1508 TestDownloadRequestHandler request_handler; |
1448 request_handler.StartServing(parameters); | 1509 request_handler.StartServing(parameters); |
1449 | 1510 |
1450 DownloadItem* download = StartDownloadAndReturnItem(request_handler.url()); | 1511 DownloadItem* download = |
1512 StartDownloadAndReturnItem(download_shell(), request_handler.url()); | |
1451 WaitForInterrupt(download); | 1513 WaitForInterrupt(download); |
1452 | 1514 |
1453 base::FilePath intermediate_path(download->GetFullPath()); | 1515 base::FilePath intermediate_path(download->GetFullPath()); |
1454 ASSERT_FALSE(intermediate_path.empty()); | 1516 ASSERT_FALSE(intermediate_path.empty()); |
1455 EXPECT_TRUE(base::PathExists(intermediate_path)); | 1517 EXPECT_TRUE(base::PathExists(intermediate_path)); |
1456 | 1518 |
1457 // Resume and remove download. We expect only a single OnDownloadCreated() | 1519 // Resume and remove download. We expect only a single OnDownloadCreated() |
1458 // call, and that's for the second download created below. | 1520 // call, and that's for the second download created below. |
1459 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); | 1521 MockDownloadManagerObserver dm_observer( |
1522 DownloadManagerForShell(download_shell())); | |
1460 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); | 1523 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); |
1461 | 1524 |
1462 TestRequestStartHandler request_start_handler; | 1525 TestRequestStartHandler request_start_handler; |
1463 parameters.on_start_handler = request_start_handler.GetOnStartHandler(); | 1526 parameters.on_start_handler = request_start_handler.GetOnStartHandler(); |
1464 request_handler.StartServing(parameters); | 1527 request_handler.StartServing(parameters); |
1465 | 1528 |
1529 PrepareToResume(); | |
1466 download->Resume(); | 1530 download->Resume(); |
1467 request_start_handler.WaitForCallback(); | 1531 request_start_handler.WaitForCallback(); |
1468 | 1532 |
1469 // At this point, the download item has initiated a network request for the | 1533 // At this point, the download item has initiated a network request for the |
1470 // resumption attempt, but hasn't received a response yet. | 1534 // resumption attempt, but hasn't received a response yet. |
1471 download->Cancel(true /* user_cancel */); | 1535 download->Cancel(true /* user_cancel */); |
1472 | 1536 |
1473 request_start_handler.RespondWith(std::string(), net::OK); | 1537 request_start_handler.RespondWith(std::string(), net::OK); |
1474 | 1538 |
1475 // The intermediate file should now be gone. | 1539 // The intermediate file should now be gone. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1647 | 1711 |
1648 std::vector<DownloadItem*> downloads; | 1712 std::vector<DownloadItem*> downloads; |
1649 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 1713 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
1650 ASSERT_EQ(1u, downloads.size()); | 1714 ASSERT_EQ(1u, downloads.size()); |
1651 | 1715 |
1652 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 1716 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
1653 downloads[0]->GetTargetFilePath().BaseName().value()); | 1717 downloads[0]->GetTargetFilePath().BaseName().value()); |
1654 } | 1718 } |
1655 | 1719 |
1656 } // namespace content | 1720 } // namespace content |
OLD | NEW |