| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains download browser tests that are known to be runnable | 5 // This file contains download browser tests that are known to be runnable |
| 6 // in a pure content context. Over time tests should be migrated here. | 6 // in a pure content context. Over time tests should be migrated here. |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 | 554 |
| 555 bool used_ = false; | 555 bool used_ = false; |
| 556 base::RunLoop run_loop_; | 556 base::RunLoop run_loop_; |
| 557 net::HttpRequestHeaders request_headers_; | 557 net::HttpRequestHeaders request_headers_; |
| 558 TestDownloadRequestHandler::OnStartResponseCallback response_callback_; | 558 TestDownloadRequestHandler::OnStartResponseCallback response_callback_; |
| 559 }; | 559 }; |
| 560 | 560 |
| 561 class DownloadContentTest : public ContentBrowserTest { | 561 class DownloadContentTest : public ContentBrowserTest { |
| 562 protected: | 562 protected: |
| 563 void SetUpOnMainThread() override { | 563 void SetUpOnMainThread() override { |
| 564 // Enable downloads resumption. |
| 565 base::FeatureList::ClearInstanceForTesting(); |
| 566 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); |
| 567 feature_list->InitializeFromCommandLine(features::kDownloadResumption.name, |
| 568 std::string()); |
| 569 base::FeatureList::SetInstance(std::move(feature_list)); |
| 570 |
| 564 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); | 571 ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); |
| 565 | 572 |
| 566 test_delegate_.reset(new TestShellDownloadManagerDelegate()); | 573 test_delegate_.reset(new TestShellDownloadManagerDelegate()); |
| 567 test_delegate_->SetDownloadBehaviorForTesting(downloads_directory_.path()); | 574 test_delegate_->SetDownloadBehaviorForTesting(downloads_directory_.path()); |
| 568 DownloadManager* manager = DownloadManagerForShell(shell()); | 575 DownloadManager* manager = DownloadManagerForShell(shell()); |
| 569 manager->GetDelegate()->Shutdown(); | 576 manager->GetDelegate()->Shutdown(); |
| 570 manager->SetDelegate(test_delegate_.get()); | 577 manager->SetDelegate(test_delegate_.get()); |
| 571 test_delegate_->SetDownloadManager(manager); | 578 test_delegate_->SetDownloadManager(manager); |
| 572 | 579 |
| 573 BrowserThread::PostTask( | 580 BrowserThread::PostTask( |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 *result = false; | 721 *result = false; |
| 715 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 722 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 716 base::MessageLoop::QuitWhenIdleClosure()); | 723 base::MessageLoop::QuitWhenIdleClosure()); |
| 717 } | 724 } |
| 718 | 725 |
| 719 // Location of the downloads directory for these tests | 726 // Location of the downloads directory for these tests |
| 720 base::ScopedTempDir downloads_directory_; | 727 base::ScopedTempDir downloads_directory_; |
| 721 scoped_ptr<TestShellDownloadManagerDelegate> test_delegate_; | 728 scoped_ptr<TestShellDownloadManagerDelegate> test_delegate_; |
| 722 }; | 729 }; |
| 723 | 730 |
| 724 // Parameters for DownloadResumptionContentTest. | |
| 725 enum class DownloadResumptionTestType { | |
| 726 RESUME_WITH_RENDERER, // Resume() is called while the originating WebContents | |
| 727 // is still alive. | |
| 728 RESUME_WITHOUT_RENDERER // Resume() is called after the originating | |
| 729 // WebContents has been deleted. | |
| 730 }; | |
| 731 | |
| 732 // Parameterized test for download resumption. Tests using this fixure will be | |
| 733 // run once with RESUME_WITH_RENDERER and once with RESUME_WITHOUT_RENDERER. | |
| 734 // Use initiator_shell_for_resumption() to retrieve the Shell object that should | |
| 735 // be used as the originator for the initial download. Prior to calling | |
| 736 // Resume(), call PrepareToResume() which will cause the originating Shell to be | |
| 737 // deleted if the test parameter is RESUME_WITHOUT_RENDERER. | |
| 738 class DownloadResumptionContentTest | |
| 739 : public DownloadContentTest, | |
| 740 public ::testing::WithParamInterface<DownloadResumptionTestType> { | |
| 741 public: | |
| 742 void SetUpOnMainThread() override { | |
| 743 base::FeatureList::ClearInstanceForTesting(); | |
| 744 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList); | |
| 745 feature_list->InitializeFromCommandLine( | |
| 746 features::kDownloadResumption.name, std::string()); | |
| 747 base::FeatureList::SetInstance(std::move(feature_list)); | |
| 748 | |
| 749 DownloadContentTest::SetUpOnMainThread(); | |
| 750 | |
| 751 if (GetParam() == DownloadResumptionTestType::RESUME_WITHOUT_RENDERER) | |
| 752 initiator_shell_for_resumption_ = CreateBrowser(); | |
| 753 else | |
| 754 initiator_shell_for_resumption_ = shell(); | |
| 755 | |
| 756 ASSERT_EQ(DownloadManagerForShell(shell()), | |
| 757 DownloadManagerForShell(initiator_shell_for_resumption())); | |
| 758 } | |
| 759 | |
| 760 // Shell to use for initiating a download. Only valid *before* | |
| 761 // PrepareToResume() is called. | |
| 762 Shell* initiator_shell_for_resumption() const { | |
| 763 DCHECK(initiator_shell_for_resumption_); | |
| 764 return initiator_shell_for_resumption_; | |
| 765 } | |
| 766 | |
| 767 // Should be called once before calling DownloadItem::Resume() on an | |
| 768 // interrupted download. This may cause initiator_shell_for_resumption() to | |
| 769 // become invalidated. | |
| 770 void PrepareToResume() { | |
| 771 if (GetParam() == DownloadResumptionTestType::RESUME_WITH_RENDERER) | |
| 772 return; | |
| 773 DCHECK_NE(initiator_shell_for_resumption(), shell()); | |
| 774 DCHECK(initiator_shell_for_resumption()); | |
| 775 initiator_shell_for_resumption_->Close(); | |
| 776 initiator_shell_for_resumption_ = nullptr; | |
| 777 } | |
| 778 | |
| 779 private: | |
| 780 Shell* initiator_shell_for_resumption_ = nullptr; | |
| 781 }; | |
| 782 | |
| 783 INSTANTIATE_TEST_CASE_P( | |
| 784 _, | |
| 785 DownloadResumptionContentTest, | |
| 786 ::testing::Values(DownloadResumptionTestType::RESUME_WITH_RENDERER, | |
| 787 DownloadResumptionTestType::RESUME_WITHOUT_RENDERER)); | |
| 788 | |
| 789 } // namespace | 731 } // namespace |
| 790 | 732 |
| 791 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadCancelled) { | 733 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadCancelled) { |
| 792 SetupEnsureNoPendingDownloads(); | 734 SetupEnsureNoPendingDownloads(); |
| 793 | 735 |
| 794 // Create a download, wait until it's started, and confirm | 736 // Create a download, wait until it's started, and confirm |
| 795 // we're in the expected state. | 737 // we're in the expected state. |
| 796 DownloadItem* download = StartDownloadAndReturnItem( | 738 DownloadItem* download = StartDownloadAndReturnItem( |
| 797 shell(), GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); | 739 shell(), GURL(net::URLRequestSlowDownloadJob::kUnknownSizeUrl)); |
| 798 ASSERT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); | 740 ASSERT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1079 MockDownloadItemObserver observer; | 1021 MockDownloadItemObserver observer; |
| 1080 items[0]->AddObserver(&observer); | 1022 items[0]->AddObserver(&observer); |
| 1081 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); | 1023 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); |
| 1082 | 1024 |
| 1083 // Shutdown the download manager. Mostly this is confirming a lack of | 1025 // Shutdown the download manager. Mostly this is confirming a lack of |
| 1084 // crashes. | 1026 // crashes. |
| 1085 DownloadManagerForShell(shell())->Shutdown(); | 1027 DownloadManagerForShell(shell())->Shutdown(); |
| 1086 } | 1028 } |
| 1087 | 1029 |
| 1088 // Test resumption with a response that contains strong validators. | 1030 // Test resumption with a response that contains strong validators. |
| 1089 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, StrongValidators) { | 1031 IN_PROC_BROWSER_TEST_F(DownloadContentTest, StrongValidators) { |
| 1090 TestDownloadRequestHandler request_handler; | 1032 TestDownloadRequestHandler request_handler; |
| 1091 TestDownloadRequestHandler::Parameters parameters = | 1033 TestDownloadRequestHandler::Parameters parameters = |
| 1092 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1034 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1093 const TestDownloadRequestHandler::InjectedError interruption = | 1035 const TestDownloadRequestHandler::InjectedError interruption = |
| 1094 parameters.injected_errors.front(); | 1036 parameters.injected_errors.front(); |
| 1095 request_handler.StartServing(parameters); | 1037 request_handler.StartServing(parameters); |
| 1096 | 1038 |
| 1097 DownloadItem* download = StartDownloadAndReturnItem( | 1039 DownloadItem* download = |
| 1098 initiator_shell_for_resumption(), request_handler.url()); | 1040 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1099 WaitForInterrupt(download); | 1041 WaitForInterrupt(download); |
| 1100 | 1042 |
| 1101 ASSERT_EQ(interruption.offset, download->GetReceivedBytes()); | 1043 ASSERT_EQ(interruption.offset, download->GetReceivedBytes()); |
| 1102 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1044 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
| 1103 | 1045 |
| 1104 PrepareToResume(); | |
| 1105 download->Resume(); | 1046 download->Resume(); |
| 1106 WaitForCompletion(download); | 1047 WaitForCompletion(download); |
| 1107 | 1048 |
| 1108 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); | 1049 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
| 1109 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1050 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
| 1110 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( | 1051 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( |
| 1111 parameters.pattern_generator_seed, parameters.size, | 1052 parameters.pattern_generator_seed, parameters.size, |
| 1112 download->GetTargetFilePath())); | 1053 download->GetTargetFilePath())); |
| 1113 | 1054 |
| 1114 // Characterization risk: The next portion of the test examines the requests | 1055 // Characterization risk: The next portion of the test examines the requests |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1134 EXPECT_EQ(parameters.etag, value); | 1075 EXPECT_EQ(parameters.etag, value); |
| 1135 | 1076 |
| 1136 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1077 ASSERT_TRUE(requests[1].request_headers.GetHeader( |
| 1137 net::HttpRequestHeaders::kRange, &value)); | 1078 net::HttpRequestHeaders::kRange, &value)); |
| 1138 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), | 1079 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), |
| 1139 value); | 1080 value); |
| 1140 } | 1081 } |
| 1141 | 1082 |
| 1142 // Resumption should only attempt to contact the final URL if the download has a | 1083 // Resumption should only attempt to contact the final URL if the download has a |
| 1143 // URL chain. | 1084 // URL chain. |
| 1144 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RedirectBeforeResume) { | 1085 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RedirectBeforeResume) { |
| 1145 TestDownloadRequestHandler request_handler_1( | 1086 TestDownloadRequestHandler request_handler_1( |
| 1146 GURL("http://example.com/first-url")); | 1087 GURL("http://example.com/first-url")); |
| 1147 request_handler_1.StartServingStaticResponse( | 1088 request_handler_1.StartServingStaticResponse( |
| 1148 "HTTP/1.1 302 Redirect\r\n" | 1089 "HTTP/1.1 302 Redirect\r\n" |
| 1149 "Location: http://example.com/second-url\r\n" | 1090 "Location: http://example.com/second-url\r\n" |
| 1150 "\r\n"); | 1091 "\r\n"); |
| 1151 | 1092 |
| 1152 TestDownloadRequestHandler request_handler_2( | 1093 TestDownloadRequestHandler request_handler_2( |
| 1153 GURL("http://example.com/second-url")); | 1094 GURL("http://example.com/second-url")); |
| 1154 request_handler_2.StartServingStaticResponse( | 1095 request_handler_2.StartServingStaticResponse( |
| 1155 "HTTP/1.1 302 Redirect\r\n" | 1096 "HTTP/1.1 302 Redirect\r\n" |
| 1156 "Location: http://example.com/third-url\r\n" | 1097 "Location: http://example.com/third-url\r\n" |
| 1157 "\r\n"); | 1098 "\r\n"); |
| 1158 | 1099 |
| 1159 TestDownloadRequestHandler request_handler_3( | 1100 TestDownloadRequestHandler request_handler_3( |
| 1160 GURL("http://example.com/third-url")); | 1101 GURL("http://example.com/third-url")); |
| 1161 request_handler_3.StartServingStaticResponse( | 1102 request_handler_3.StartServingStaticResponse( |
| 1162 "HTTP/1.1 302 Redirect\r\n" | 1103 "HTTP/1.1 302 Redirect\r\n" |
| 1163 "Location: http://example.com/download\r\n" | 1104 "Location: http://example.com/download\r\n" |
| 1164 "\r\n"); | 1105 "\r\n"); |
| 1165 | 1106 |
| 1166 TestDownloadRequestHandler resumable_request_handler( | 1107 TestDownloadRequestHandler resumable_request_handler( |
| 1167 GURL("http://example.com/download")); | 1108 GURL("http://example.com/download")); |
| 1168 TestDownloadRequestHandler::Parameters parameters = | 1109 TestDownloadRequestHandler::Parameters parameters = |
| 1169 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1110 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1170 resumable_request_handler.StartServing(parameters); | 1111 resumable_request_handler.StartServing(parameters); |
| 1171 | 1112 |
| 1172 DownloadItem* download = StartDownloadAndReturnItem( | 1113 DownloadItem* download = |
| 1173 initiator_shell_for_resumption(), request_handler_1.url()); | 1114 StartDownloadAndReturnItem(shell(), request_handler_1.url()); |
| 1174 WaitForInterrupt(download); | 1115 WaitForInterrupt(download); |
| 1175 | 1116 |
| 1176 EXPECT_EQ(4u, download->GetUrlChain().size()); | 1117 EXPECT_EQ(4u, download->GetUrlChain().size()); |
| 1177 EXPECT_EQ(request_handler_1.url(), download->GetOriginalUrl()); | 1118 EXPECT_EQ(request_handler_1.url(), download->GetOriginalUrl()); |
| 1178 EXPECT_EQ(resumable_request_handler.url(), download->GetURL()); | 1119 EXPECT_EQ(resumable_request_handler.url(), download->GetURL()); |
| 1179 | 1120 |
| 1180 // Now that the download is interrupted, make all intermediate servers return | 1121 // Now that the download is interrupted, make all intermediate servers return |
| 1181 // a 404. The only way a resumption request would succeed if the resumption | 1122 // a 404. The only way a resumption request would succeed if the resumption |
| 1182 // request is sent to the final server in the chain. | 1123 // request is sent to the final server in the chain. |
| 1183 const char k404Response[] = "HTTP/1.1 404 Not found\r\n\r\n"; | 1124 const char k404Response[] = "HTTP/1.1 404 Not found\r\n\r\n"; |
| 1184 request_handler_1.StartServingStaticResponse(k404Response); | 1125 request_handler_1.StartServingStaticResponse(k404Response); |
| 1185 request_handler_2.StartServingStaticResponse(k404Response); | 1126 request_handler_2.StartServingStaticResponse(k404Response); |
| 1186 request_handler_3.StartServingStaticResponse(k404Response); | 1127 request_handler_3.StartServingStaticResponse(k404Response); |
| 1187 | 1128 |
| 1188 PrepareToResume(); | |
| 1189 download->Resume(); | 1129 download->Resume(); |
| 1190 WaitForCompletion(download); | 1130 WaitForCompletion(download); |
| 1191 | 1131 |
| 1192 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( | 1132 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( |
| 1193 parameters.pattern_generator_seed, parameters.size, | 1133 parameters.pattern_generator_seed, parameters.size, |
| 1194 download->GetTargetFilePath())); | 1134 download->GetTargetFilePath())); |
| 1195 } | 1135 } |
| 1196 | 1136 |
| 1197 // If a resumption request results in a redirect, the response should be ignored | 1137 // If a resumption request results in a redirect, the response should be ignored |
| 1198 // and the download should be marked as interrupted again. | 1138 // and the download should be marked as interrupted again. |
| 1199 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RedirectWhileResume) { | 1139 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RedirectWhileResume) { |
| 1200 TestDownloadRequestHandler request_handler( | 1140 TestDownloadRequestHandler request_handler( |
| 1201 GURL("http://example.com/first-url")); | 1141 GURL("http://example.com/first-url")); |
| 1202 TestDownloadRequestHandler::Parameters parameters = | 1142 TestDownloadRequestHandler::Parameters parameters = |
| 1203 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1143 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1204 ++parameters.pattern_generator_seed; | 1144 ++parameters.pattern_generator_seed; |
| 1205 request_handler.StartServing(parameters); | 1145 request_handler.StartServing(parameters); |
| 1206 | 1146 |
| 1207 // We should never send a request to the decoy. If we do, the request will | 1147 // We should never send a request to the decoy. If we do, the request will |
| 1208 // always succeed, which results in behavior that diverges from what we want, | 1148 // always succeed, which results in behavior that diverges from what we want, |
| 1209 // which is for the download to return to being interrupted. | 1149 // which is for the download to return to being interrupted. |
| 1210 TestDownloadRequestHandler decoy_request_handler( | 1150 TestDownloadRequestHandler decoy_request_handler( |
| 1211 GURL("http://example.com/decoy")); | 1151 GURL("http://example.com/decoy")); |
| 1212 decoy_request_handler.StartServing(TestDownloadRequestHandler::Parameters()); | 1152 decoy_request_handler.StartServing(TestDownloadRequestHandler::Parameters()); |
| 1213 | 1153 |
| 1214 DownloadItem* download = StartDownloadAndReturnItem( | 1154 DownloadItem* download = |
| 1215 initiator_shell_for_resumption(), request_handler.url()); | 1155 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1216 WaitForInterrupt(download); | 1156 WaitForInterrupt(download); |
| 1217 | 1157 |
| 1218 // Upon resumption, the server starts responding with a redirect. This | 1158 // Upon resumption, the server starts responding with a redirect. This |
| 1219 // response should not be accepted. | 1159 // response should not be accepted. |
| 1220 request_handler.StartServingStaticResponse( | 1160 request_handler.StartServingStaticResponse( |
| 1221 "HTTP/1.1 302 Redirect\r\n" | 1161 "HTTP/1.1 302 Redirect\r\n" |
| 1222 "Location: http://example.com/decoy\r\n" | 1162 "Location: http://example.com/decoy\r\n" |
| 1223 "\r\n"); | 1163 "\r\n"); |
| 1224 PrepareToResume(); | |
| 1225 download->Resume(); | 1164 download->Resume(); |
| 1226 WaitForInterrupt(download); | 1165 WaitForInterrupt(download); |
| 1227 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE, | 1166 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE, |
| 1228 download->GetLastReason()); | 1167 download->GetLastReason()); |
| 1229 | 1168 |
| 1230 // Back to the original request handler. Resumption should now succeed, and | 1169 // Back to the original request handler. Resumption should now succeed, and |
| 1231 // use the partial data it had prior to the first interruption. | 1170 // use the partial data it had prior to the first interruption. |
| 1232 request_handler.StartServing(parameters); | 1171 request_handler.StartServing(parameters); |
| 1233 download->Resume(); | 1172 download->Resume(); |
| 1234 WaitForCompletion(download); | 1173 WaitForCompletion(download); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1252 // redirect response shows up as a response with 0 bytes transferred. | 1191 // redirect response shows up as a response with 0 bytes transferred. |
| 1253 EXPECT_GT(parameters.size, requests[0].transferred_byte_count); | 1192 EXPECT_GT(parameters.size, requests[0].transferred_byte_count); |
| 1254 EXPECT_EQ(0, requests[1].transferred_byte_count); | 1193 EXPECT_EQ(0, requests[1].transferred_byte_count); |
| 1255 EXPECT_GT(parameters.size, requests[2].transferred_byte_count); | 1194 EXPECT_GT(parameters.size, requests[2].transferred_byte_count); |
| 1256 } | 1195 } |
| 1257 | 1196 |
| 1258 // If the server response for the resumption request specifies a bad range (i.e. | 1197 // If the server response for the resumption request specifies a bad range (i.e. |
| 1259 // not the range that was requested or an invalid or missing Content-Range | 1198 // not the range that was requested or an invalid or missing Content-Range |
| 1260 // header), then the download should be marked as interrupted again without | 1199 // header), then the download should be marked as interrupted again without |
| 1261 // discarding the partial state. | 1200 // discarding the partial state. |
| 1262 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, BadRangeHeader) { | 1201 IN_PROC_BROWSER_TEST_F(DownloadContentTest, BadRangeHeader) { |
| 1263 TestDownloadRequestHandler request_handler; | 1202 TestDownloadRequestHandler request_handler; |
| 1264 TestDownloadRequestHandler::Parameters parameters = | 1203 TestDownloadRequestHandler::Parameters parameters = |
| 1265 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1204 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1266 request_handler.StartServing(parameters); | 1205 request_handler.StartServing(parameters); |
| 1267 | 1206 |
| 1268 DownloadItem* download = StartDownloadAndReturnItem( | 1207 DownloadItem* download = |
| 1269 initiator_shell_for_resumption(), request_handler.url()); | 1208 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1270 WaitForInterrupt(download); | 1209 WaitForInterrupt(download); |
| 1271 | 1210 |
| 1272 // Upon resumption, the server starts responding with a bad range header. | 1211 // Upon resumption, the server starts responding with a bad range header. |
| 1273 request_handler.StartServingStaticResponse( | 1212 request_handler.StartServingStaticResponse( |
| 1274 "HTTP/1.1 206 Partial Content\r\n" | 1213 "HTTP/1.1 206 Partial Content\r\n" |
| 1275 "Content-Range: bytes 1000000-2000000/3000000\r\n" | 1214 "Content-Range: bytes 1000000-2000000/3000000\r\n" |
| 1276 "\r\n"); | 1215 "\r\n"); |
| 1277 PrepareToResume(); | |
| 1278 download->Resume(); | 1216 download->Resume(); |
| 1279 WaitForInterrupt(download); | 1217 WaitForInterrupt(download); |
| 1280 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, | 1218 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT, |
| 1281 download->GetLastReason()); | 1219 download->GetLastReason()); |
| 1282 | 1220 |
| 1283 // Or this time, the server sends a response with an invalid Content-Range | 1221 // Or this time, the server sends a response with an invalid Content-Range |
| 1284 // header. | 1222 // header. |
| 1285 request_handler.StartServingStaticResponse( | 1223 request_handler.StartServingStaticResponse( |
| 1286 "HTTP/1.1 206 Partial Content\r\n" | 1224 "HTTP/1.1 206 Partial Content\r\n" |
| 1287 "Content-Range: ooga-booga-booga-booga\r\n" | 1225 "Content-Range: ooga-booga-booga-booga\r\n" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 EXPECT_EQ(0, requests[2].transferred_byte_count); | 1266 EXPECT_EQ(0, requests[2].transferred_byte_count); |
| 1329 EXPECT_EQ(0, requests[3].transferred_byte_count); | 1267 EXPECT_EQ(0, requests[3].transferred_byte_count); |
| 1330 EXPECT_GT(parameters.size, requests[4].transferred_byte_count); | 1268 EXPECT_GT(parameters.size, requests[4].transferred_byte_count); |
| 1331 } | 1269 } |
| 1332 | 1270 |
| 1333 // A partial resumption results in an HTTP 200 response. I.e. the server ignored | 1271 // A partial resumption results in an HTTP 200 response. I.e. the server ignored |
| 1334 // the range request and sent the entire resource instead. For If-Range requests | 1272 // the range request and sent the entire resource instead. For If-Range requests |
| 1335 // (as opposed to If-Match), the behavior for a precondition failure is also to | 1273 // (as opposed to If-Match), the behavior for a precondition failure is also to |
| 1336 // respond with a 200. So this test case covers both validation failure and | 1274 // respond with a 200. So this test case covers both validation failure and |
| 1337 // ignoring the range request. | 1275 // ignoring the range request. |
| 1338 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, | 1276 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNotPartialResponse) { |
| 1339 RestartIfNotPartialResponse) { | |
| 1340 const int kOriginalPatternGeneratorSeed = 1; | 1277 const int kOriginalPatternGeneratorSeed = 1; |
| 1341 const int kNewPatternGeneratorSeed = 2; | 1278 const int kNewPatternGeneratorSeed = 2; |
| 1342 | 1279 |
| 1343 TestDownloadRequestHandler::Parameters parameters = | 1280 TestDownloadRequestHandler::Parameters parameters = |
| 1344 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1281 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1345 parameters.pattern_generator_seed = kOriginalPatternGeneratorSeed; | 1282 parameters.pattern_generator_seed = kOriginalPatternGeneratorSeed; |
| 1346 const TestDownloadRequestHandler::InjectedError interruption = | 1283 const TestDownloadRequestHandler::InjectedError interruption = |
| 1347 parameters.injected_errors.front(); | 1284 parameters.injected_errors.front(); |
| 1348 | 1285 |
| 1349 TestDownloadRequestHandler request_handler; | 1286 TestDownloadRequestHandler request_handler; |
| 1350 request_handler.StartServing(parameters); | 1287 request_handler.StartServing(parameters); |
| 1351 | 1288 |
| 1352 DownloadItem* download = StartDownloadAndReturnItem( | 1289 DownloadItem* download = |
| 1353 initiator_shell_for_resumption(), request_handler.url()); | 1290 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1354 WaitForInterrupt(download); | 1291 WaitForInterrupt(download); |
| 1355 | 1292 |
| 1356 ASSERT_EQ(interruption.offset, download->GetReceivedBytes()); | 1293 ASSERT_EQ(interruption.offset, download->GetReceivedBytes()); |
| 1357 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1294 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
| 1358 | 1295 |
| 1359 parameters = TestDownloadRequestHandler::Parameters(); | 1296 parameters = TestDownloadRequestHandler::Parameters(); |
| 1360 parameters.support_byte_ranges = false; | 1297 parameters.support_byte_ranges = false; |
| 1361 parameters.pattern_generator_seed = kNewPatternGeneratorSeed; | 1298 parameters.pattern_generator_seed = kNewPatternGeneratorSeed; |
| 1362 request_handler.StartServing(parameters); | 1299 request_handler.StartServing(parameters); |
| 1363 | 1300 |
| 1364 PrepareToResume(); | |
| 1365 download->Resume(); | 1301 download->Resume(); |
| 1366 WaitForCompletion(download); | 1302 WaitForCompletion(download); |
| 1367 | 1303 |
| 1368 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); | 1304 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
| 1369 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1305 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
| 1370 ASSERT_NO_FATAL_FAILURE( | 1306 ASSERT_NO_FATAL_FAILURE( |
| 1371 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, | 1307 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, |
| 1372 download->GetTargetFilePath())); | 1308 download->GetTargetFilePath())); |
| 1373 | 1309 |
| 1374 // When the downloads system sees the full response, it should accept the | 1310 // When the downloads system sees the full response, it should accept the |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1392 net::HttpRequestHeaders::kIfRange, &value)); | 1328 net::HttpRequestHeaders::kIfRange, &value)); |
| 1393 EXPECT_EQ(parameters.etag, value); | 1329 EXPECT_EQ(parameters.etag, value); |
| 1394 | 1330 |
| 1395 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1331 ASSERT_TRUE(requests[1].request_headers.GetHeader( |
| 1396 net::HttpRequestHeaders::kRange, &value)); | 1332 net::HttpRequestHeaders::kRange, &value)); |
| 1397 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), | 1333 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), |
| 1398 value); | 1334 value); |
| 1399 } | 1335 } |
| 1400 | 1336 |
| 1401 // Confirm we restart if we don't have a verifier. | 1337 // Confirm we restart if we don't have a verifier. |
| 1402 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RestartIfNoETag) { | 1338 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoETag) { |
| 1403 const int kOriginalPatternGeneratorSeed = 1; | 1339 const int kOriginalPatternGeneratorSeed = 1; |
| 1404 const int kNewPatternGeneratorSeed = 2; | 1340 const int kNewPatternGeneratorSeed = 2; |
| 1405 | 1341 |
| 1406 TestDownloadRequestHandler::Parameters parameters = | 1342 TestDownloadRequestHandler::Parameters parameters = |
| 1407 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1343 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1408 ASSERT_EQ(1u, parameters.injected_errors.size()); | 1344 ASSERT_EQ(1u, parameters.injected_errors.size()); |
| 1409 parameters.etag.clear(); | 1345 parameters.etag.clear(); |
| 1410 parameters.pattern_generator_seed = kOriginalPatternGeneratorSeed; | 1346 parameters.pattern_generator_seed = kOriginalPatternGeneratorSeed; |
| 1411 | 1347 |
| 1412 TestDownloadRequestHandler request_handler; | 1348 TestDownloadRequestHandler request_handler; |
| 1413 request_handler.StartServing(parameters); | 1349 request_handler.StartServing(parameters); |
| 1414 DownloadItem* download = StartDownloadAndReturnItem( | 1350 DownloadItem* download = |
| 1415 initiator_shell_for_resumption(), request_handler.url()); | 1351 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1416 WaitForInterrupt(download); | 1352 WaitForInterrupt(download); |
| 1417 | 1353 |
| 1418 parameters.pattern_generator_seed = kNewPatternGeneratorSeed; | 1354 parameters.pattern_generator_seed = kNewPatternGeneratorSeed; |
| 1419 parameters.ClearInjectedErrors(); | 1355 parameters.ClearInjectedErrors(); |
| 1420 request_handler.StartServing(parameters); | 1356 request_handler.StartServing(parameters); |
| 1421 | 1357 |
| 1422 PrepareToResume(); | |
| 1423 download->Resume(); | 1358 download->Resume(); |
| 1424 WaitForCompletion(download); | 1359 WaitForCompletion(download); |
| 1425 | 1360 |
| 1426 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); | 1361 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
| 1427 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1362 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
| 1428 ASSERT_NO_FATAL_FAILURE( | 1363 ASSERT_NO_FATAL_FAILURE( |
| 1429 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, | 1364 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, |
| 1430 download->GetTargetFilePath())); | 1365 download->GetTargetFilePath())); |
| 1431 | 1366 |
| 1432 TestDownloadRequestHandler::CompletedRequests requests; | 1367 TestDownloadRequestHandler::CompletedRequests requests; |
| 1433 request_handler.GetCompletedRequestInfo(&requests); | 1368 request_handler.GetCompletedRequestInfo(&requests); |
| 1434 | 1369 |
| 1435 // Neither If-Range nor Range headers should be present in the second request. | 1370 // Neither If-Range nor Range headers should be present in the second request. |
| 1436 ASSERT_EQ(2u, requests.size()); | 1371 ASSERT_EQ(2u, requests.size()); |
| 1437 std::string value; | 1372 std::string value; |
| 1438 EXPECT_FALSE(requests[1].request_headers.GetHeader( | 1373 EXPECT_FALSE(requests[1].request_headers.GetHeader( |
| 1439 net::HttpRequestHeaders::kIfRange, &value)); | 1374 net::HttpRequestHeaders::kIfRange, &value)); |
| 1440 EXPECT_FALSE(requests[1].request_headers.GetHeader( | 1375 EXPECT_FALSE(requests[1].request_headers.GetHeader( |
| 1441 net::HttpRequestHeaders::kRange, &value)); | 1376 net::HttpRequestHeaders::kRange, &value)); |
| 1442 } | 1377 } |
| 1443 | 1378 |
| 1444 // Partial file goes missing before the download is resumed. The download should | 1379 // Partial file goes missing before the download is resumed. The download should |
| 1445 // restart. | 1380 // restart. |
| 1446 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RestartIfNoPartialFile) { | 1381 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoPartialFile) { |
| 1447 TestDownloadRequestHandler::Parameters parameters = | 1382 TestDownloadRequestHandler::Parameters parameters = |
| 1448 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1383 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1449 | 1384 |
| 1450 TestDownloadRequestHandler request_handler; | 1385 TestDownloadRequestHandler request_handler; |
| 1451 request_handler.StartServing(parameters); | 1386 request_handler.StartServing(parameters); |
| 1452 DownloadItem* download = StartDownloadAndReturnItem( | 1387 DownloadItem* download = |
| 1453 initiator_shell_for_resumption(), request_handler.url()); | 1388 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1454 WaitForInterrupt(download); | 1389 WaitForInterrupt(download); |
| 1455 | 1390 |
| 1456 // Delete the intermediate file. | 1391 // Delete the intermediate file. |
| 1457 ASSERT_TRUE(base::PathExists(download->GetFullPath())); | 1392 ASSERT_TRUE(base::PathExists(download->GetFullPath())); |
| 1458 ASSERT_TRUE(base::DeleteFile(download->GetFullPath(), false)); | 1393 ASSERT_TRUE(base::DeleteFile(download->GetFullPath(), false)); |
| 1459 | 1394 |
| 1460 parameters.ClearInjectedErrors(); | 1395 parameters.ClearInjectedErrors(); |
| 1461 request_handler.StartServing(parameters); | 1396 request_handler.StartServing(parameters); |
| 1462 | 1397 |
| 1463 PrepareToResume(); | |
| 1464 download->Resume(); | 1398 download->Resume(); |
| 1465 WaitForCompletion(download); | 1399 WaitForCompletion(download); |
| 1466 | 1400 |
| 1467 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); | 1401 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
| 1468 ASSERT_EQ(parameters.size, download->GetTotalBytes()); | 1402 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
| 1469 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( | 1403 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( |
| 1470 parameters.pattern_generator_seed, parameters.size, | 1404 parameters.pattern_generator_seed, parameters.size, |
| 1471 download->GetTargetFilePath())); | 1405 download->GetTargetFilePath())); |
| 1472 } | 1406 } |
| 1473 | 1407 |
| 1474 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, | 1408 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromInitFileError) { |
| 1475 RecoverFromInitFileError) { | |
| 1476 TestDownloadRequestHandler request_handler; | 1409 TestDownloadRequestHandler request_handler; |
| 1477 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); | 1410 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); |
| 1478 | 1411 |
| 1479 // Setup the error injector. | 1412 // Setup the error injector. |
| 1480 scoped_refptr<TestFileErrorInjector> injector(TestFileErrorInjector::Create( | 1413 scoped_refptr<TestFileErrorInjector> injector( |
| 1481 DownloadManagerForShell(initiator_shell_for_resumption()))); | 1414 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); |
| 1482 | 1415 |
| 1483 const TestFileErrorInjector::FileErrorInfo err = { | 1416 const TestFileErrorInjector::FileErrorInfo err = { |
| 1484 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, | 1417 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, |
| 1485 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; | 1418 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; |
| 1486 injector->InjectError(err); | 1419 injector->InjectError(err); |
| 1487 | 1420 |
| 1488 // Start and watch for interrupt. | 1421 // Start and watch for interrupt. |
| 1489 DownloadItem* download(StartDownloadAndReturnItem( | 1422 DownloadItem* download( |
| 1490 initiator_shell_for_resumption(), request_handler.url())); | 1423 StartDownloadAndReturnItem(shell(), request_handler.url())); |
| 1491 WaitForInterrupt(download); | 1424 WaitForInterrupt(download); |
| 1492 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1425 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
| 1493 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 1426 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 1494 download->GetLastReason()); | 1427 download->GetLastReason()); |
| 1495 EXPECT_EQ(0, download->GetReceivedBytes()); | 1428 EXPECT_EQ(0, download->GetReceivedBytes()); |
| 1496 EXPECT_TRUE(download->GetFullPath().empty()); | 1429 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1497 EXPECT_FALSE(download->GetTargetFilePath().empty()); | 1430 EXPECT_FALSE(download->GetTargetFilePath().empty()); |
| 1498 | 1431 |
| 1499 // We need to make sure that any cross-thread downloads communication has | 1432 // We need to make sure that any cross-thread downloads communication has |
| 1500 // quiesced before clearing and injecting the new errors, as the | 1433 // quiesced before clearing and injecting the new errors, as the |
| 1501 // InjectErrors() routine alters the currently in use download file | 1434 // InjectErrors() routine alters the currently in use download file |
| 1502 // factory, which is a file thread object. | 1435 // factory, which is a file thread object. |
| 1503 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1436 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1504 RunAllPendingInMessageLoop(); | 1437 RunAllPendingInMessageLoop(); |
| 1505 | 1438 |
| 1506 // Clear the old errors list. | 1439 // Clear the old errors list. |
| 1507 injector->ClearError(); | 1440 injector->ClearError(); |
| 1508 | 1441 |
| 1509 // Resume and watch completion. | 1442 // Resume and watch completion. |
| 1510 PrepareToResume(); | |
| 1511 download->Resume(); | 1443 download->Resume(); |
| 1512 WaitForCompletion(download); | 1444 WaitForCompletion(download); |
| 1513 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1445 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
| 1514 } | 1446 } |
| 1515 | 1447 |
| 1516 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, | 1448 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1517 RecoverFromIntermediateFileRenameError) { | 1449 RecoverFromIntermediateFileRenameError) { |
| 1518 TestDownloadRequestHandler request_handler; | 1450 TestDownloadRequestHandler request_handler; |
| 1519 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); | 1451 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); |
| 1520 | 1452 |
| 1521 // Setup the error injector. | 1453 // Setup the error injector. |
| 1522 scoped_refptr<TestFileErrorInjector> injector(TestFileErrorInjector::Create( | 1454 scoped_refptr<TestFileErrorInjector> injector( |
| 1523 DownloadManagerForShell(initiator_shell_for_resumption()))); | 1455 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); |
| 1524 | 1456 |
| 1525 const TestFileErrorInjector::FileErrorInfo err = { | 1457 const TestFileErrorInjector::FileErrorInfo err = { |
| 1526 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, 0, | 1458 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, 0, |
| 1527 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; | 1459 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; |
| 1528 injector->InjectError(err); | 1460 injector->InjectError(err); |
| 1529 | 1461 |
| 1530 // Start and watch for interrupt. | 1462 // Start and watch for interrupt. |
| 1531 DownloadItem* download(StartDownloadAndReturnItem( | 1463 DownloadItem* download( |
| 1532 initiator_shell_for_resumption(), request_handler.url())); | 1464 StartDownloadAndReturnItem(shell(), request_handler.url())); |
| 1533 WaitForInterrupt(download); | 1465 WaitForInterrupt(download); |
| 1534 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1466 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
| 1535 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, | 1467 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, |
| 1536 download->GetLastReason()); | 1468 download->GetLastReason()); |
| 1537 EXPECT_TRUE(download->GetFullPath().empty()); | 1469 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1538 // Target path will have been set after file name determination. GetFullPath() | 1470 // Target path will have been set after file name determination. GetFullPath() |
| 1539 // being empty is sufficient to signal that filename determination needs to be | 1471 // being empty is sufficient to signal that filename determination needs to be |
| 1540 // redone. | 1472 // redone. |
| 1541 EXPECT_FALSE(download->GetTargetFilePath().empty()); | 1473 EXPECT_FALSE(download->GetTargetFilePath().empty()); |
| 1542 | 1474 |
| 1543 // We need to make sure that any cross-thread downloads communication has | 1475 // We need to make sure that any cross-thread downloads communication has |
| 1544 // quiesced before clearing and injecting the new errors, as the | 1476 // quiesced before clearing and injecting the new errors, as the |
| 1545 // InjectErrors() routine alters the currently in use download file | 1477 // InjectErrors() routine alters the currently in use download file |
| 1546 // factory, which is a file thread object. | 1478 // factory, which is a file thread object. |
| 1547 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1479 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1548 RunAllPendingInMessageLoop(); | 1480 RunAllPendingInMessageLoop(); |
| 1549 | 1481 |
| 1550 // Clear the old errors list. | 1482 // Clear the old errors list. |
| 1551 injector->ClearError(); | 1483 injector->ClearError(); |
| 1552 | 1484 |
| 1553 PrepareToResume(); | |
| 1554 download->Resume(); | 1485 download->Resume(); |
| 1555 WaitForCompletion(download); | 1486 WaitForCompletion(download); |
| 1556 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1487 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
| 1557 } | 1488 } |
| 1558 | 1489 |
| 1559 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, | 1490 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RecoverFromFinalRenameError) { |
| 1560 RecoverFromFinalRenameError) { | |
| 1561 TestDownloadRequestHandler request_handler; | 1491 TestDownloadRequestHandler request_handler; |
| 1562 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); | 1492 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); |
| 1563 | 1493 |
| 1564 // Setup the error injector. | 1494 // Setup the error injector. |
| 1565 scoped_refptr<TestFileErrorInjector> injector(TestFileErrorInjector::Create( | 1495 scoped_refptr<TestFileErrorInjector> injector( |
| 1566 DownloadManagerForShell(initiator_shell_for_resumption()))); | 1496 TestFileErrorInjector::Create(DownloadManagerForShell(shell()))); |
| 1567 | 1497 |
| 1568 DownloadManagerForShell(initiator_shell_for_resumption()) | 1498 DownloadManagerForShell(shell())->RemoveAllDownloads(); |
| 1569 ->RemoveAllDownloads(); | |
| 1570 TestFileErrorInjector::FileErrorInfo err = { | 1499 TestFileErrorInjector::FileErrorInfo err = { |
| 1571 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, 0, | 1500 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, 0, |
| 1572 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED}; | 1501 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED}; |
| 1573 injector->InjectError(err); | 1502 injector->InjectError(err); |
| 1574 | 1503 |
| 1575 // Start and watch for interrupt. | 1504 // Start and watch for interrupt. |
| 1576 DownloadItem* download(StartDownloadAndReturnItem( | 1505 DownloadItem* download( |
| 1577 initiator_shell_for_resumption(), request_handler.url())); | 1506 StartDownloadAndReturnItem(shell(), request_handler.url())); |
| 1578 WaitForInterrupt(download); | 1507 WaitForInterrupt(download); |
| 1579 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 1508 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
| 1580 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, download->GetLastReason()); | 1509 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, download->GetLastReason()); |
| 1581 EXPECT_TRUE(download->GetFullPath().empty()); | 1510 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1582 // Target path should still be intact. | 1511 // Target path should still be intact. |
| 1583 EXPECT_FALSE(download->GetTargetFilePath().empty()); | 1512 EXPECT_FALSE(download->GetTargetFilePath().empty()); |
| 1584 | 1513 |
| 1585 // We need to make sure that any cross-thread downloads communication has | 1514 // We need to make sure that any cross-thread downloads communication has |
| 1586 // quiesced before clearing and injecting the new errors, as the | 1515 // quiesced before clearing and injecting the new errors, as the |
| 1587 // InjectErrors() routine alters the currently in use download file | 1516 // InjectErrors() routine alters the currently in use download file |
| 1588 // factory, which is a file thread object. | 1517 // factory, which is a file thread object. |
| 1589 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1518 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1590 RunAllPendingInMessageLoop(); | 1519 RunAllPendingInMessageLoop(); |
| 1591 | 1520 |
| 1592 // Clear the old errors list. | 1521 // Clear the old errors list. |
| 1593 injector->ClearError(); | 1522 injector->ClearError(); |
| 1594 | 1523 |
| 1595 PrepareToResume(); | |
| 1596 download->Resume(); | 1524 download->Resume(); |
| 1597 WaitForCompletion(download); | 1525 WaitForCompletion(download); |
| 1598 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1526 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
| 1599 } | 1527 } |
| 1600 | 1528 |
| 1601 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, Resume_Hash) { | 1529 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Resume_Hash) { |
| 1602 using InjectedError = TestDownloadRequestHandler::InjectedError; | 1530 using InjectedError = TestDownloadRequestHandler::InjectedError; |
| 1603 const char kExpectedHash[] = | 1531 const char kExpectedHash[] = |
| 1604 "\xa7\x44\x49\x86\x24\xc6\x84\x6c\x89\xdf\xd8\xec\xa0\xe0\x61\x12\xdc\x80" | 1532 "\xa7\x44\x49\x86\x24\xc6\x84\x6c\x89\xdf\xd8\xec\xa0\xe0\x61\x12\xdc\x80" |
| 1605 "\x13\xf2\x83\x49\xa9\x14\x52\x32\xf0\x95\x20\xca\x5b\x30"; | 1533 "\x13\xf2\x83\x49\xa9\x14\x52\x32\xf0\x95\x20\xca\x5b\x30"; |
| 1606 std::string expected_hash(kExpectedHash); | 1534 std::string expected_hash(kExpectedHash); |
| 1607 TestDownloadRequestHandler request_handler; | 1535 TestDownloadRequestHandler request_handler; |
| 1608 TestDownloadRequestHandler::Parameters parameters; | 1536 TestDownloadRequestHandler::Parameters parameters; |
| 1609 | 1537 |
| 1610 // As a control, let's try GetHash() on an uninterrupted download. | 1538 // As a control, let's try GetHash() on an uninterrupted download. |
| 1611 request_handler.StartServing(parameters); | 1539 request_handler.StartServing(parameters); |
| 1612 DownloadItem* uninterrupted_download(StartDownloadAndReturnItem( | 1540 DownloadItem* uninterrupted_download( |
| 1613 initiator_shell_for_resumption(), request_handler.url())); | 1541 StartDownloadAndReturnItem(shell(), request_handler.url())); |
| 1614 WaitForCompletion(uninterrupted_download); | 1542 WaitForCompletion(uninterrupted_download); |
| 1615 EXPECT_EQ(expected_hash, uninterrupted_download->GetHash()); | 1543 EXPECT_EQ(expected_hash, uninterrupted_download->GetHash()); |
| 1616 | 1544 |
| 1617 // Now with interruptions. | 1545 // Now with interruptions. |
| 1618 parameters.injected_errors.push( | 1546 parameters.injected_errors.push( |
| 1619 InjectedError(100, net::ERR_CONNECTION_RESET)); | 1547 InjectedError(100, net::ERR_CONNECTION_RESET)); |
| 1620 parameters.injected_errors.push( | 1548 parameters.injected_errors.push( |
| 1621 InjectedError(211, net::ERR_CONNECTION_RESET)); | 1549 InjectedError(211, net::ERR_CONNECTION_RESET)); |
| 1622 parameters.injected_errors.push( | 1550 parameters.injected_errors.push( |
| 1623 InjectedError(337, net::ERR_CONNECTION_RESET)); | 1551 InjectedError(337, net::ERR_CONNECTION_RESET)); |
| 1624 parameters.injected_errors.push( | 1552 parameters.injected_errors.push( |
| 1625 InjectedError(400, net::ERR_CONNECTION_RESET)); | 1553 InjectedError(400, net::ERR_CONNECTION_RESET)); |
| 1626 parameters.injected_errors.push( | 1554 parameters.injected_errors.push( |
| 1627 InjectedError(512, net::ERR_CONNECTION_RESET)); | 1555 InjectedError(512, net::ERR_CONNECTION_RESET)); |
| 1628 request_handler.StartServing(parameters); | 1556 request_handler.StartServing(parameters); |
| 1629 | 1557 |
| 1630 // Start and watch for interrupt. | 1558 // Start and watch for interrupt. |
| 1631 DownloadItem* download(StartDownloadAndReturnItem( | 1559 DownloadItem* download( |
| 1632 initiator_shell_for_resumption(), request_handler.url())); | 1560 StartDownloadAndReturnItem(shell(), request_handler.url())); |
| 1633 WaitForInterrupt(download); | 1561 WaitForInterrupt(download); |
| 1634 | 1562 |
| 1635 PrepareToResume(); | |
| 1636 download->Resume(); | 1563 download->Resume(); |
| 1637 WaitForInterrupt(download); | 1564 WaitForInterrupt(download); |
| 1638 | 1565 |
| 1639 download->Resume(); | 1566 download->Resume(); |
| 1640 WaitForInterrupt(download); | 1567 WaitForInterrupt(download); |
| 1641 | 1568 |
| 1642 download->Resume(); | 1569 download->Resume(); |
| 1643 WaitForInterrupt(download); | 1570 WaitForInterrupt(download); |
| 1644 | 1571 |
| 1645 download->Resume(); | 1572 download->Resume(); |
| 1646 WaitForInterrupt(download); | 1573 WaitForInterrupt(download); |
| 1647 | 1574 |
| 1648 download->Resume(); | 1575 download->Resume(); |
| 1649 WaitForCompletion(download); | 1576 WaitForCompletion(download); |
| 1650 | 1577 |
| 1651 EXPECT_EQ(expected_hash, download->GetHash()); | 1578 EXPECT_EQ(expected_hash, download->GetHash()); |
| 1652 } | 1579 } |
| 1653 | 1580 |
| 1654 // An interrupted download should remove the intermediate file when it is | 1581 // An interrupted download should remove the intermediate file when it is |
| 1655 // cancelled. | 1582 // cancelled. |
| 1656 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, | 1583 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelInterruptedDownload) { |
| 1657 CancelInterruptedDownload) { | |
| 1658 TestDownloadRequestHandler request_handler; | 1584 TestDownloadRequestHandler request_handler; |
| 1659 request_handler.StartServing( | 1585 request_handler.StartServing( |
| 1660 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); | 1586 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); |
| 1661 | 1587 |
| 1662 DownloadItem* download = StartDownloadAndReturnItem( | 1588 DownloadItem* download = |
| 1663 initiator_shell_for_resumption(), request_handler.url()); | 1589 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1664 WaitForInterrupt(download); | 1590 WaitForInterrupt(download); |
| 1665 | 1591 |
| 1666 base::FilePath intermediate_path = download->GetFullPath(); | 1592 base::FilePath intermediate_path = download->GetFullPath(); |
| 1667 ASSERT_FALSE(intermediate_path.empty()); | 1593 ASSERT_FALSE(intermediate_path.empty()); |
| 1668 ASSERT_TRUE(base::PathExists(intermediate_path)); | 1594 ASSERT_TRUE(base::PathExists(intermediate_path)); |
| 1669 | 1595 |
| 1670 download->Cancel(true /* user_cancel */); | 1596 download->Cancel(true /* user_cancel */); |
| 1671 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1597 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1672 RunAllPendingInMessageLoop(); | 1598 RunAllPendingInMessageLoop(); |
| 1673 | 1599 |
| 1674 // The intermediate file should now be gone. | 1600 // The intermediate file should now be gone. |
| 1675 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1601 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1676 EXPECT_TRUE(download->GetFullPath().empty()); | 1602 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1677 } | 1603 } |
| 1678 | 1604 |
| 1679 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, | 1605 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveInterruptedDownload) { |
| 1680 RemoveInterruptedDownload) { | |
| 1681 TestDownloadRequestHandler request_handler; | 1606 TestDownloadRequestHandler request_handler; |
| 1682 request_handler.StartServing( | 1607 request_handler.StartServing( |
| 1683 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); | 1608 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); |
| 1684 | 1609 |
| 1685 DownloadItem* download = StartDownloadAndReturnItem( | 1610 DownloadItem* download = |
| 1686 initiator_shell_for_resumption(), request_handler.url()); | 1611 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1687 WaitForInterrupt(download); | 1612 WaitForInterrupt(download); |
| 1688 | 1613 |
| 1689 base::FilePath intermediate_path = download->GetFullPath(); | 1614 base::FilePath intermediate_path = download->GetFullPath(); |
| 1690 ASSERT_FALSE(intermediate_path.empty()); | 1615 ASSERT_FALSE(intermediate_path.empty()); |
| 1691 ASSERT_TRUE(base::PathExists(intermediate_path)); | 1616 ASSERT_TRUE(base::PathExists(intermediate_path)); |
| 1692 | 1617 |
| 1693 download->Remove(); | 1618 download->Remove(); |
| 1694 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1619 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1695 RunAllPendingInMessageLoop(); | 1620 RunAllPendingInMessageLoop(); |
| 1696 | 1621 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1713 base::FilePath target_path(download->GetTargetFilePath()); | 1638 base::FilePath target_path(download->GetTargetFilePath()); |
| 1714 EXPECT_TRUE(base::PathExists(target_path)); | 1639 EXPECT_TRUE(base::PathExists(target_path)); |
| 1715 download->Remove(); | 1640 download->Remove(); |
| 1716 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1641 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1717 RunAllPendingInMessageLoop(); | 1642 RunAllPendingInMessageLoop(); |
| 1718 | 1643 |
| 1719 // The file should still exist. | 1644 // The file should still exist. |
| 1720 EXPECT_TRUE(base::PathExists(target_path)); | 1645 EXPECT_TRUE(base::PathExists(target_path)); |
| 1721 } | 1646 } |
| 1722 | 1647 |
| 1723 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RemoveResumingDownload) { | 1648 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { |
| 1724 TestDownloadRequestHandler::Parameters parameters = | 1649 TestDownloadRequestHandler::Parameters parameters = |
| 1725 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1650 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1726 TestDownloadRequestHandler request_handler; | 1651 TestDownloadRequestHandler request_handler; |
| 1727 request_handler.StartServing(parameters); | 1652 request_handler.StartServing(parameters); |
| 1728 | 1653 |
| 1729 DownloadItem* download = StartDownloadAndReturnItem( | 1654 DownloadItem* download = |
| 1730 initiator_shell_for_resumption(), request_handler.url()); | 1655 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1731 WaitForInterrupt(download); | 1656 WaitForInterrupt(download); |
| 1732 | 1657 |
| 1733 base::FilePath intermediate_path(download->GetFullPath()); | 1658 base::FilePath intermediate_path(download->GetFullPath()); |
| 1734 ASSERT_FALSE(intermediate_path.empty()); | 1659 ASSERT_FALSE(intermediate_path.empty()); |
| 1735 EXPECT_TRUE(base::PathExists(intermediate_path)); | 1660 EXPECT_TRUE(base::PathExists(intermediate_path)); |
| 1736 | 1661 |
| 1737 // Resume and remove download. We expect only a single OnDownloadCreated() | 1662 // Resume and remove download. We expect only a single OnDownloadCreated() |
| 1738 // call, and that's for the second download created below. | 1663 // call, and that's for the second download created below. |
| 1739 MockDownloadManagerObserver dm_observer( | 1664 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); |
| 1740 DownloadManagerForShell(initiator_shell_for_resumption())); | |
| 1741 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); | 1665 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); |
| 1742 | 1666 |
| 1743 TestRequestStartHandler request_start_handler; | 1667 TestRequestStartHandler request_start_handler; |
| 1744 parameters.on_start_handler = request_start_handler.GetOnStartHandler(); | 1668 parameters.on_start_handler = request_start_handler.GetOnStartHandler(); |
| 1745 request_handler.StartServing(parameters); | 1669 request_handler.StartServing(parameters); |
| 1746 | 1670 |
| 1747 PrepareToResume(); | |
| 1748 download->Resume(); | 1671 download->Resume(); |
| 1749 request_start_handler.WaitForCallback(); | 1672 request_start_handler.WaitForCallback(); |
| 1750 | 1673 |
| 1751 // At this point, the download resumption request has been sent out, but the | 1674 // At this point, the download resumption request has been sent out, but the |
| 1752 // reponse hasn't been received yet. | 1675 // reponse hasn't been received yet. |
| 1753 download->Remove(); | 1676 download->Remove(); |
| 1754 | 1677 |
| 1755 request_start_handler.RespondWith(std::string(), net::OK); | 1678 request_start_handler.RespondWith(std::string(), net::OK); |
| 1756 | 1679 |
| 1757 // The intermediate file should now be gone. | 1680 // The intermediate file should now be gone. |
| 1758 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1681 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1759 RunAllPendingInMessageLoop(); | 1682 RunAllPendingInMessageLoop(); |
| 1760 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1683 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1761 | 1684 |
| 1762 parameters.ClearInjectedErrors(); | 1685 parameters.ClearInjectedErrors(); |
| 1763 parameters.on_start_handler.Reset(); | 1686 parameters.on_start_handler.Reset(); |
| 1764 request_handler.StartServing(parameters); | 1687 request_handler.StartServing(parameters); |
| 1765 | 1688 |
| 1766 // Start the second download and wait until it's done. This exercises the | 1689 // Start the second download and wait until it's done. This exercises the |
| 1767 // entire downloads stack and effectively flushes all of our worker threads. | 1690 // entire downloads stack and effectively flushes all of our worker threads. |
| 1768 // We are testing whether the URL request created in the previous | 1691 // We are testing whether the URL request created in the previous |
| 1769 // DownloadItem::Resume() call reulted in a new download or not. | 1692 // DownloadItem::Resume() call reulted in a new download or not. |
| 1770 NavigateToURLAndWaitForDownload(shell(), request_handler.url(), | 1693 NavigateToURLAndWaitForDownload(shell(), request_handler.url(), |
| 1771 DownloadItem::COMPLETE); | 1694 DownloadItem::COMPLETE); |
| 1772 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1695 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1773 } | 1696 } |
| 1774 | 1697 |
| 1775 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, CancelResumingDownload) { | 1698 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumingDownload) { |
| 1776 TestDownloadRequestHandler::Parameters parameters = | 1699 TestDownloadRequestHandler::Parameters parameters = |
| 1777 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1700 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1778 TestDownloadRequestHandler request_handler; | 1701 TestDownloadRequestHandler request_handler; |
| 1779 request_handler.StartServing(parameters); | 1702 request_handler.StartServing(parameters); |
| 1780 | 1703 |
| 1781 DownloadItem* download = StartDownloadAndReturnItem( | 1704 DownloadItem* download = |
| 1782 initiator_shell_for_resumption(), request_handler.url()); | 1705 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1783 WaitForInterrupt(download); | 1706 WaitForInterrupt(download); |
| 1784 | 1707 |
| 1785 base::FilePath intermediate_path(download->GetFullPath()); | 1708 base::FilePath intermediate_path(download->GetFullPath()); |
| 1786 ASSERT_FALSE(intermediate_path.empty()); | 1709 ASSERT_FALSE(intermediate_path.empty()); |
| 1787 EXPECT_TRUE(base::PathExists(intermediate_path)); | 1710 EXPECT_TRUE(base::PathExists(intermediate_path)); |
| 1788 | 1711 |
| 1789 // Resume and cancel download. We expect only a single OnDownloadCreated() | 1712 // Resume and cancel download. We expect only a single OnDownloadCreated() |
| 1790 // call, and that's for the second download created below. | 1713 // call, and that's for the second download created below. |
| 1791 MockDownloadManagerObserver dm_observer( | 1714 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); |
| 1792 DownloadManagerForShell(initiator_shell_for_resumption())); | |
| 1793 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); | 1715 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); |
| 1794 | 1716 |
| 1795 TestRequestStartHandler request_start_handler; | 1717 TestRequestStartHandler request_start_handler; |
| 1796 parameters.on_start_handler = request_start_handler.GetOnStartHandler(); | 1718 parameters.on_start_handler = request_start_handler.GetOnStartHandler(); |
| 1797 request_handler.StartServing(parameters); | 1719 request_handler.StartServing(parameters); |
| 1798 | 1720 |
| 1799 PrepareToResume(); | |
| 1800 download->Resume(); | 1721 download->Resume(); |
| 1801 request_start_handler.WaitForCallback(); | 1722 request_start_handler.WaitForCallback(); |
| 1802 | 1723 |
| 1803 // At this point, the download item has initiated a network request for the | 1724 // At this point, the download item has initiated a network request for the |
| 1804 // resumption attempt, but hasn't received a response yet. | 1725 // resumption attempt, but hasn't received a response yet. |
| 1805 download->Cancel(true /* user_cancel */); | 1726 download->Cancel(true /* user_cancel */); |
| 1806 | 1727 |
| 1807 request_start_handler.RespondWith(std::string(), net::OK); | 1728 request_start_handler.RespondWith(std::string(), net::OK); |
| 1808 | 1729 |
| 1809 // The intermediate file should now be gone. | 1730 // The intermediate file should now be gone. |
| 1810 RunAllPendingInMessageLoop(BrowserThread::IO); | 1731 RunAllPendingInMessageLoop(BrowserThread::IO); |
| 1811 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1732 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1812 RunAllPendingInMessageLoop(); | 1733 RunAllPendingInMessageLoop(); |
| 1813 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1734 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1814 | 1735 |
| 1815 parameters.ClearInjectedErrors(); | 1736 parameters.ClearInjectedErrors(); |
| 1816 parameters.on_start_handler.Reset(); | 1737 parameters.on_start_handler.Reset(); |
| 1817 request_handler.StartServing(parameters); | 1738 request_handler.StartServing(parameters); |
| 1818 | 1739 |
| 1819 // Start the second download and wait until it's done. This exercises the | 1740 // Start the second download and wait until it's done. This exercises the |
| 1820 // entire downloads stack and effectively flushes all of our worker threads. | 1741 // entire downloads stack and effectively flushes all of our worker threads. |
| 1821 // We are testing whether the URL request created in the previous | 1742 // We are testing whether the URL request created in the previous |
| 1822 // DownloadItem::Resume() call reulted in a new download or not. | 1743 // DownloadItem::Resume() call reulted in a new download or not. |
| 1823 NavigateToURLAndWaitForDownload(shell(), request_handler.url(), | 1744 NavigateToURLAndWaitForDownload(shell(), request_handler.url(), |
| 1824 DownloadItem::COMPLETE); | 1745 DownloadItem::COMPLETE); |
| 1825 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1746 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1826 } | 1747 } |
| 1827 | 1748 |
| 1828 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RemoveResumedDownload) { | 1749 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumedDownload) { |
| 1829 TestDownloadRequestHandler::Parameters parameters = | 1750 TestDownloadRequestHandler::Parameters parameters = |
| 1830 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1751 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1831 TestDownloadRequestHandler request_handler; | 1752 TestDownloadRequestHandler request_handler; |
| 1832 request_handler.StartServing(parameters); | 1753 request_handler.StartServing(parameters); |
| 1833 | 1754 |
| 1834 DownloadItem* download = StartDownloadAndReturnItem( | 1755 DownloadItem* download = |
| 1835 initiator_shell_for_resumption(), request_handler.url()); | 1756 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1836 WaitForInterrupt(download); | 1757 WaitForInterrupt(download); |
| 1837 | 1758 |
| 1838 base::FilePath intermediate_path(download->GetFullPath()); | 1759 base::FilePath intermediate_path(download->GetFullPath()); |
| 1839 base::FilePath target_path(download->GetTargetFilePath()); | 1760 base::FilePath target_path(download->GetTargetFilePath()); |
| 1840 ASSERT_FALSE(intermediate_path.empty()); | 1761 ASSERT_FALSE(intermediate_path.empty()); |
| 1841 EXPECT_TRUE(base::PathExists(intermediate_path)); | 1762 EXPECT_TRUE(base::PathExists(intermediate_path)); |
| 1842 EXPECT_FALSE(base::PathExists(target_path)); | 1763 EXPECT_FALSE(base::PathExists(target_path)); |
| 1843 | 1764 |
| 1844 // Resume and remove download. We don't expect OnDownloadCreated() calls. | 1765 // Resume and remove download. We don't expect OnDownloadCreated() calls. |
| 1845 MockDownloadManagerObserver dm_observer( | 1766 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); |
| 1846 DownloadManagerForShell(initiator_shell_for_resumption())); | |
| 1847 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); | 1767 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); |
| 1848 | 1768 |
| 1849 PrepareToResume(); | |
| 1850 download->Resume(); | 1769 download->Resume(); |
| 1851 WaitForInProgress(download); | 1770 WaitForInProgress(download); |
| 1852 | 1771 |
| 1853 download->Remove(); | 1772 download->Remove(); |
| 1854 | 1773 |
| 1855 // The intermediate file should now be gone. | 1774 // The intermediate file should now be gone. |
| 1856 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1775 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1857 RunAllPendingInMessageLoop(); | 1776 RunAllPendingInMessageLoop(); |
| 1858 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1777 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1859 EXPECT_FALSE(base::PathExists(target_path)); | 1778 EXPECT_FALSE(base::PathExists(target_path)); |
| 1860 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1779 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1861 } | 1780 } |
| 1862 | 1781 |
| 1863 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, CancelResumedDownload) { | 1782 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumedDownload) { |
| 1864 TestDownloadRequestHandler::Parameters parameters = | 1783 TestDownloadRequestHandler::Parameters parameters = |
| 1865 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1784 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1866 TestDownloadRequestHandler request_handler; | 1785 TestDownloadRequestHandler request_handler; |
| 1867 request_handler.StartServing(parameters); | 1786 request_handler.StartServing(parameters); |
| 1868 | 1787 |
| 1869 DownloadItem* download = StartDownloadAndReturnItem( | 1788 DownloadItem* download = |
| 1870 initiator_shell_for_resumption(), request_handler.url()); | 1789 StartDownloadAndReturnItem(shell(), request_handler.url()); |
| 1871 WaitForInterrupt(download); | 1790 WaitForInterrupt(download); |
| 1872 | 1791 |
| 1873 base::FilePath intermediate_path(download->GetFullPath()); | 1792 base::FilePath intermediate_path(download->GetFullPath()); |
| 1874 base::FilePath target_path(download->GetTargetFilePath()); | 1793 base::FilePath target_path(download->GetTargetFilePath()); |
| 1875 ASSERT_FALSE(intermediate_path.empty()); | 1794 ASSERT_FALSE(intermediate_path.empty()); |
| 1876 EXPECT_TRUE(base::PathExists(intermediate_path)); | 1795 EXPECT_TRUE(base::PathExists(intermediate_path)); |
| 1877 EXPECT_FALSE(base::PathExists(target_path)); | 1796 EXPECT_FALSE(base::PathExists(target_path)); |
| 1878 | 1797 |
| 1879 // Resume and remove download. We don't expect OnDownloadCreated() calls. | 1798 // Resume and remove download. We don't expect OnDownloadCreated() calls. |
| 1880 MockDownloadManagerObserver dm_observer( | 1799 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); |
| 1881 DownloadManagerForShell(initiator_shell_for_resumption())); | |
| 1882 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); | 1800 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0); |
| 1883 | 1801 |
| 1884 PrepareToResume(); | |
| 1885 download->Resume(); | 1802 download->Resume(); |
| 1886 WaitForInProgress(download); | 1803 WaitForInProgress(download); |
| 1887 | 1804 |
| 1888 download->Cancel(true); | 1805 download->Cancel(true); |
| 1889 | 1806 |
| 1890 // The intermediate file should now be gone. | 1807 // The intermediate file should now be gone. |
| 1891 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1808 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1892 RunAllPendingInMessageLoop(); | 1809 RunAllPendingInMessageLoop(); |
| 1893 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1810 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1894 EXPECT_FALSE(base::PathExists(target_path)); | 1811 EXPECT_FALSE(base::PathExists(target_path)); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2127 | 2044 |
| 2128 std::vector<DownloadItem*> downloads; | 2045 std::vector<DownloadItem*> downloads; |
| 2129 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 2046 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 2130 ASSERT_EQ(1u, downloads.size()); | 2047 ASSERT_EQ(1u, downloads.size()); |
| 2131 | 2048 |
| 2132 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 2049 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
| 2133 downloads[0]->GetTargetFilePath().BaseName().value()); | 2050 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 2134 } | 2051 } |
| 2135 | 2052 |
| 2136 } // namespace content | 2053 } // namespace content |
| OLD | NEW |