| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains download browser tests that are known to be runnable | 5 // This file contains download browser tests that are known to be runnable |
| 6 // in a pure content context. Over time tests should be migrated here. | 6 // in a pure content context. Over time tests should be migrated here. |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "net/test/url_request/url_request_mock_http_job.h" | 41 #include "net/test/url_request/url_request_mock_http_job.h" |
| 42 #include "net/test/url_request/url_request_slow_download_job.h" | 42 #include "net/test/url_request/url_request_slow_download_job.h" |
| 43 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "url/gurl.h" | 45 #include "url/gurl.h" |
| 46 | 46 |
| 47 #if defined(ENABLE_PLUGINS) | 47 #if defined(ENABLE_PLUGINS) |
| 48 #include "content/browser/plugin_service_impl.h" | 48 #include "content/browser/plugin_service_impl.h" |
| 49 #endif | 49 #endif |
| 50 | 50 |
| 51 using ::net::test_server::EmbeddedTestServer; | |
| 52 using ::testing::AllOf; | 51 using ::testing::AllOf; |
| 53 using ::testing::Field; | 52 using ::testing::Field; |
| 54 using ::testing::InSequence; | 53 using ::testing::InSequence; |
| 55 using ::testing::Property; | 54 using ::testing::Property; |
| 56 using ::testing::Return; | 55 using ::testing::Return; |
| 57 using ::testing::StrictMock; | 56 using ::testing::StrictMock; |
| 58 using ::testing::_; | 57 using ::testing::_; |
| 59 | 58 |
| 60 namespace content { | 59 namespace content { |
| 61 | 60 |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 if (request.relative_url == relative_url) { | 513 if (request.relative_url == relative_url) { |
| 515 response.reset(new net::test_server::BasicHttpResponse); | 514 response.reset(new net::test_server::BasicHttpResponse); |
| 516 response->set_code(net::HTTP_FOUND); | 515 response->set_code(net::HTTP_FOUND); |
| 517 response->AddCustomHeader("Location", target_url.spec()); | 516 response->AddCustomHeader("Location", target_url.spec()); |
| 518 } | 517 } |
| 519 return response.Pass(); | 518 return response.Pass(); |
| 520 } | 519 } |
| 521 | 520 |
| 522 // Creates a request handler for EmbeddedTestServer that responds with a HTTP | 521 // Creates a request handler for EmbeddedTestServer that responds with a HTTP |
| 523 // 302 redirect if the request URL matches |relative_url|. | 522 // 302 redirect if the request URL matches |relative_url|. |
| 524 EmbeddedTestServer::HandleRequestCallback CreateRedirectHandler( | 523 net::EmbeddedTestServer::HandleRequestCallback CreateRedirectHandler( |
| 525 const std::string& relative_url, | 524 const std::string& relative_url, |
| 526 const GURL& target_url) { | 525 const GURL& target_url) { |
| 527 return base::Bind( | 526 return base::Bind( |
| 528 &HandleRequestAndSendRedirectResponse, relative_url, target_url); | 527 &HandleRequestAndSendRedirectResponse, relative_url, target_url); |
| 529 } | 528 } |
| 530 | 529 |
| 531 // Request handler to be used with CreateBasicResponseHandler(). | 530 // Request handler to be used with CreateBasicResponseHandler(). |
| 532 scoped_ptr<net::test_server::HttpResponse> HandleRequestAndSendBasicResponse( | 531 scoped_ptr<net::test_server::HttpResponse> HandleRequestAndSendBasicResponse( |
| 533 const std::string& relative_url, | 532 const std::string& relative_url, |
| 534 const std::string& content_type, | 533 const std::string& content_type, |
| 535 const std::string& body, | 534 const std::string& body, |
| 536 const net::test_server::HttpRequest& request) { | 535 const net::test_server::HttpRequest& request) { |
| 537 scoped_ptr<net::test_server::BasicHttpResponse> response; | 536 scoped_ptr<net::test_server::BasicHttpResponse> response; |
| 538 if (request.relative_url == relative_url) { | 537 if (request.relative_url == relative_url) { |
| 539 response.reset(new net::test_server::BasicHttpResponse); | 538 response.reset(new net::test_server::BasicHttpResponse); |
| 540 response->set_content_type(content_type); | 539 response->set_content_type(content_type); |
| 541 response->set_content(body); | 540 response->set_content(body); |
| 542 } | 541 } |
| 543 return response.Pass(); | 542 return response.Pass(); |
| 544 } | 543 } |
| 545 | 544 |
| 546 // Creates a request handler for an EmbeddedTestServer that response with an | 545 // Creates a request handler for an EmbeddedTestServer that response with an |
| 547 // HTTP 200 status code, a Content-Type header and a body. | 546 // HTTP 200 status code, a Content-Type header and a body. |
| 548 EmbeddedTestServer::HandleRequestCallback CreateBasicResponseHandler( | 547 net::EmbeddedTestServer::HandleRequestCallback CreateBasicResponseHandler( |
| 549 const std::string& relative_url, | 548 const std::string& relative_url, |
| 550 const std::string& content_type, | 549 const std::string& content_type, |
| 551 const std::string& body) { | 550 const std::string& body) { |
| 552 return base::Bind( | 551 return base::Bind( |
| 553 &HandleRequestAndSendBasicResponse, relative_url, content_type, body); | 552 &HandleRequestAndSendBasicResponse, relative_url, content_type, body); |
| 554 } | 553 } |
| 555 | 554 |
| 556 } // namespace | 555 } // namespace |
| 557 | 556 |
| 558 class DownloadContentTest : public ContentBrowserTest { | 557 class DownloadContentTest : public ContentBrowserTest { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 ASSERT_EQ(size, download->GetReceivedBytes()); | 694 ASSERT_EQ(size, download->GetReceivedBytes()); |
| 696 ASSERT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); | 695 ASSERT_EQ(DownloadItem::IN_PROGRESS, download->GetState()); |
| 697 } | 696 } |
| 698 | 697 |
| 699 // Tell the test server to release a pending RST and confirm | 698 // Tell the test server to release a pending RST and confirm |
| 700 // that the interrupt is received properly (for download resumption | 699 // that the interrupt is received properly (for download resumption |
| 701 // testing). | 700 // testing). |
| 702 void ReleaseRSTAndConfirmInterruptForResume(DownloadItem* download) { | 701 void ReleaseRSTAndConfirmInterruptForResume(DownloadItem* download) { |
| 703 scoped_ptr<DownloadTestObserver> rst_observer( | 702 scoped_ptr<DownloadTestObserver> rst_observer( |
| 704 CreateInterruptedWaiter(shell(), 1)); | 703 CreateInterruptedWaiter(shell(), 1)); |
| 705 NavigateToURL(shell(), test_server()->GetURL("download-finish")); | 704 NavigateToURL(shell(), spawned_test_server()->GetURL("download-finish")); |
| 706 rst_observer->WaitForFinished(); | 705 rst_observer->WaitForFinished(); |
| 707 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); | 706 EXPECT_EQ(DownloadItem::INTERRUPTED, download->GetState()); |
| 708 } | 707 } |
| 709 | 708 |
| 710 // Confirm file status expected for the given location in a stream | 709 // Confirm file status expected for the given location in a stream |
| 711 // provided by the resume test server. | 710 // provided by the resume test server. |
| 712 void ConfirmFileStatusForResume( | 711 void ConfirmFileStatusForResume( |
| 713 DownloadItem* download, bool file_exists, | 712 DownloadItem* download, bool file_exists, |
| 714 int received_bytes, int total_bytes, | 713 int received_bytes, int total_bytes, |
| 715 const base::FilePath& expected_filename) { | 714 const base::FilePath& expected_filename) { |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1065 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); | 1064 EXPECT_CALL(observer, OnDownloadDestroyed(items[0])); |
| 1066 | 1065 |
| 1067 // Shutdown the download manager. Mostly this is confirming a lack of | 1066 // Shutdown the download manager. Mostly this is confirming a lack of |
| 1068 // crashes. | 1067 // crashes. |
| 1069 DownloadManagerForShell(shell())->Shutdown(); | 1068 DownloadManagerForShell(shell())->Shutdown(); |
| 1070 } | 1069 } |
| 1071 | 1070 |
| 1072 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeInterruptedDownload) { | 1071 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeInterruptedDownload) { |
| 1073 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1072 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1074 switches::kEnableDownloadResumption); | 1073 switches::kEnableDownloadResumption); |
| 1075 ASSERT_TRUE(test_server()->Start()); | 1074 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1076 | 1075 |
| 1077 GURL url = test_server()->GetURL( | 1076 GURL url = spawned_test_server()->GetURL( |
| 1078 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", | 1077 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", |
| 1079 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); | 1078 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
| 1080 | 1079 |
| 1081 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); | 1080 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); |
| 1082 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); | 1081 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); |
| 1083 | 1082 |
| 1084 DownloadItem* download(StartDownloadAndReturnItem(url)); | 1083 DownloadItem* download(StartDownloadAndReturnItem(url)); |
| 1085 WaitForData(download, GetSafeBufferChunk()); | 1084 WaitForData(download, GetSafeBufferChunk()); |
| 1086 ::testing::Mock::VerifyAndClearExpectations(&dm_observer); | 1085 ::testing::Mock::VerifyAndClearExpectations(&dm_observer); |
| 1087 | 1086 |
| 1088 // Confirm resumption while in progress doesn't do anything. | 1087 // Confirm resumption while in progress doesn't do anything. |
| 1089 download->Resume(); | 1088 download->Resume(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 ASSERT_EQ(DownloadItem::COMPLETE, download->GetState()); | 1131 ASSERT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 1133 RunAllPendingInMessageLoop(); | 1132 RunAllPendingInMessageLoop(); |
| 1134 ASSERT_EQ(GetSafeBufferChunk() * 3, download->GetReceivedBytes()); | 1133 ASSERT_EQ(GetSafeBufferChunk() * 3, download->GetReceivedBytes()); |
| 1135 ASSERT_EQ(DownloadItem::COMPLETE, download->GetState()); | 1134 ASSERT_EQ(DownloadItem::COMPLETE, download->GetState()); |
| 1136 } | 1135 } |
| 1137 | 1136 |
| 1138 // Confirm restart fallback happens if a range request is bounced. | 1137 // Confirm restart fallback happens if a range request is bounced. |
| 1139 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeInterruptedDownloadNoRange) { | 1138 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeInterruptedDownloadNoRange) { |
| 1140 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1139 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1141 switches::kEnableDownloadResumption); | 1140 switches::kEnableDownloadResumption); |
| 1142 ASSERT_TRUE(test_server()->Start()); | 1141 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1143 | 1142 |
| 1144 // Auto-restart if server doesn't handle ranges. | 1143 // Auto-restart if server doesn't handle ranges. |
| 1145 GURL url = test_server()->GetURL( | 1144 GURL url = spawned_test_server()->GetURL(base::StringPrintf( |
| 1146 base::StringPrintf( | 1145 // First download hits an RST, rest don't, no ranges. |
| 1147 // First download hits an RST, rest don't, no ranges. | 1146 "rangereset?size=%d&rst_boundary=%d&" |
| 1148 "rangereset?size=%d&rst_boundary=%d&" | 1147 "token=NoRange&rst_limit=1&bounce_range", |
| 1149 "token=NoRange&rst_limit=1&bounce_range", | 1148 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
| 1150 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); | |
| 1151 | 1149 |
| 1152 // Start the download and wait for first data chunk. | 1150 // Start the download and wait for first data chunk. |
| 1153 DownloadItem* download(StartDownloadAndReturnItem(url)); | 1151 DownloadItem* download(StartDownloadAndReturnItem(url)); |
| 1154 WaitForData(download, GetSafeBufferChunk()); | 1152 WaitForData(download, GetSafeBufferChunk()); |
| 1155 | 1153 |
| 1156 RecordingDownloadObserver recorder(download); | 1154 RecordingDownloadObserver recorder(download); |
| 1157 | 1155 |
| 1158 ReleaseRSTAndConfirmInterruptForResume(download); | 1156 ReleaseRSTAndConfirmInterruptForResume(download); |
| 1159 ConfirmFileStatusForResume( | 1157 ConfirmFileStatusForResume( |
| 1160 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, | 1158 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1181 }; | 1179 }; |
| 1182 | 1180 |
| 1183 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); | 1181 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); |
| 1184 } | 1182 } |
| 1185 | 1183 |
| 1186 // Confirm restart fallback happens if a precondition is failed. | 1184 // Confirm restart fallback happens if a precondition is failed. |
| 1187 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1185 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1188 ResumeInterruptedDownloadBadPrecondition) { | 1186 ResumeInterruptedDownloadBadPrecondition) { |
| 1189 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1187 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1190 switches::kEnableDownloadResumption); | 1188 switches::kEnableDownloadResumption); |
| 1191 ASSERT_TRUE(test_server()->Start()); | 1189 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1192 | 1190 |
| 1193 GURL url = test_server()->GetURL(base::StringPrintf( | 1191 GURL url = spawned_test_server()->GetURL(base::StringPrintf( |
| 1194 // First download hits an RST, rest don't, precondition fail. | 1192 // First download hits an RST, rest don't, precondition fail. |
| 1195 "rangereset?size=%d&rst_boundary=%d&" | 1193 "rangereset?size=%d&rst_boundary=%d&" |
| 1196 "token=BadPrecondition&rst_limit=1&fail_precondition=2", | 1194 "token=BadPrecondition&rst_limit=1&fail_precondition=2", |
| 1197 GetSafeBufferChunk() * 3, | 1195 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
| 1198 GetSafeBufferChunk())); | |
| 1199 | 1196 |
| 1200 // Start the download and wait for first data chunk. | 1197 // Start the download and wait for first data chunk. |
| 1201 DownloadItem* download(StartDownloadAndReturnItem(url)); | 1198 DownloadItem* download(StartDownloadAndReturnItem(url)); |
| 1202 WaitForData(download, GetSafeBufferChunk()); | 1199 WaitForData(download, GetSafeBufferChunk()); |
| 1203 | 1200 |
| 1204 RecordingDownloadObserver recorder(download); | 1201 RecordingDownloadObserver recorder(download); |
| 1205 | 1202 |
| 1206 ReleaseRSTAndConfirmInterruptForResume(download); | 1203 ReleaseRSTAndConfirmInterruptForResume(download); |
| 1207 ConfirmFileStatusForResume( | 1204 ConfirmFileStatusForResume( |
| 1208 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, | 1205 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1233 }; | 1230 }; |
| 1234 | 1231 |
| 1235 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); | 1232 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); |
| 1236 } | 1233 } |
| 1237 | 1234 |
| 1238 // Confirm we don't try to resume if we don't have a verifier. | 1235 // Confirm we don't try to resume if we don't have a verifier. |
| 1239 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1236 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1240 ResumeInterruptedDownloadNoVerifiers) { | 1237 ResumeInterruptedDownloadNoVerifiers) { |
| 1241 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1238 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1242 switches::kEnableDownloadResumption); | 1239 switches::kEnableDownloadResumption); |
| 1243 ASSERT_TRUE(test_server()->Start()); | 1240 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1244 | 1241 |
| 1245 GURL url = test_server()->GetURL( | 1242 GURL url = spawned_test_server()->GetURL(base::StringPrintf( |
| 1246 base::StringPrintf( | 1243 // First download hits an RST, rest don't, no verifiers. |
| 1247 // First download hits an RST, rest don't, no verifiers. | 1244 "rangereset?size=%d&rst_boundary=%d&" |
| 1248 "rangereset?size=%d&rst_boundary=%d&" | 1245 "token=NoRange&rst_limit=1&no_verifiers", |
| 1249 "token=NoRange&rst_limit=1&no_verifiers", | 1246 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
| 1250 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); | |
| 1251 | 1247 |
| 1252 // Start the download and wait for first data chunk. | 1248 // Start the download and wait for first data chunk. |
| 1253 DownloadItem* download(StartDownloadAndReturnItem(url)); | 1249 DownloadItem* download(StartDownloadAndReturnItem(url)); |
| 1254 WaitForData(download, GetSafeBufferChunk()); | 1250 WaitForData(download, GetSafeBufferChunk()); |
| 1255 | 1251 |
| 1256 RecordingDownloadObserver recorder(download); | 1252 RecordingDownloadObserver recorder(download); |
| 1257 | 1253 |
| 1258 ReleaseRSTAndConfirmInterruptForResume(download); | 1254 ReleaseRSTAndConfirmInterruptForResume(download); |
| 1259 ConfirmFileStatusForResume( | 1255 ConfirmFileStatusForResume( |
| 1260 download, false, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, | 1256 download, false, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1277 // Completion. | 1273 // Completion. |
| 1278 {DownloadItem::COMPLETE, GetSafeBufferChunk() * 3}, | 1274 {DownloadItem::COMPLETE, GetSafeBufferChunk() * 3}, |
| 1279 }; | 1275 }; |
| 1280 | 1276 |
| 1281 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); | 1277 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); |
| 1282 } | 1278 } |
| 1283 | 1279 |
| 1284 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithDeletedFile) { | 1280 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeWithDeletedFile) { |
| 1285 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1281 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1286 switches::kEnableDownloadResumption); | 1282 switches::kEnableDownloadResumption); |
| 1287 ASSERT_TRUE(test_server()->Start()); | 1283 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1288 | 1284 |
| 1289 GURL url = test_server()->GetURL( | 1285 GURL url = spawned_test_server()->GetURL(base::StringPrintf( |
| 1290 base::StringPrintf( | 1286 // First download hits an RST, rest don't |
| 1291 // First download hits an RST, rest don't | 1287 "rangereset?size=%d&rst_boundary=%d&" |
| 1292 "rangereset?size=%d&rst_boundary=%d&" | 1288 "token=NoRange&rst_limit=1", |
| 1293 "token=NoRange&rst_limit=1", | 1289 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
| 1294 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); | |
| 1295 | 1290 |
| 1296 // Start the download and wait for first data chunk. | 1291 // Start the download and wait for first data chunk. |
| 1297 DownloadItem* download(StartDownloadAndReturnItem(url)); | 1292 DownloadItem* download(StartDownloadAndReturnItem(url)); |
| 1298 WaitForData(download, GetSafeBufferChunk()); | 1293 WaitForData(download, GetSafeBufferChunk()); |
| 1299 | 1294 |
| 1300 RecordingDownloadObserver recorder(download); | 1295 RecordingDownloadObserver recorder(download); |
| 1301 | 1296 |
| 1302 ReleaseRSTAndConfirmInterruptForResume(download); | 1297 ReleaseRSTAndConfirmInterruptForResume(download); |
| 1303 ConfirmFileStatusForResume( | 1298 ConfirmFileStatusForResume( |
| 1304 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, | 1299 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 download->Resume(); | 1476 download->Resume(); |
| 1482 completion_observer.WaitForEvent(); | 1477 completion_observer.WaitForEvent(); |
| 1483 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1478 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
| 1484 } | 1479 } |
| 1485 | 1480 |
| 1486 // An interrupted download should remove the intermediate file when it is | 1481 // An interrupted download should remove the intermediate file when it is |
| 1487 // cancelled. | 1482 // cancelled. |
| 1488 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelInterruptedDownload) { | 1483 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelInterruptedDownload) { |
| 1489 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1484 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1490 switches::kEnableDownloadResumption); | 1485 switches::kEnableDownloadResumption); |
| 1491 ASSERT_TRUE(test_server()->Start()); | 1486 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1492 | 1487 |
| 1493 GURL url1 = test_server()->GetURL( | 1488 GURL url1 = spawned_test_server()->GetURL( |
| 1494 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", | 1489 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", |
| 1495 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); | 1490 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
| 1496 | 1491 |
| 1497 DownloadItem* download(StartDownloadAndReturnItem(url1)); | 1492 DownloadItem* download(StartDownloadAndReturnItem(url1)); |
| 1498 WaitForData(download, GetSafeBufferChunk()); | 1493 WaitForData(download, GetSafeBufferChunk()); |
| 1499 | 1494 |
| 1500 ReleaseRSTAndConfirmInterruptForResume(download); | 1495 ReleaseRSTAndConfirmInterruptForResume(download); |
| 1501 ConfirmFileStatusForResume( | 1496 ConfirmFileStatusForResume( |
| 1502 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, | 1497 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, |
| 1503 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload"))); | 1498 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload"))); |
| 1504 | 1499 |
| 1505 base::FilePath intermediate_path(download->GetFullPath()); | 1500 base::FilePath intermediate_path(download->GetFullPath()); |
| 1506 ASSERT_FALSE(intermediate_path.empty()); | 1501 ASSERT_FALSE(intermediate_path.empty()); |
| 1507 EXPECT_TRUE(base::PathExists(intermediate_path)); | 1502 EXPECT_TRUE(base::PathExists(intermediate_path)); |
| 1508 | 1503 |
| 1509 download->Cancel(true /* user_cancel */); | 1504 download->Cancel(true /* user_cancel */); |
| 1510 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1505 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1511 RunAllPendingInMessageLoop(); | 1506 RunAllPendingInMessageLoop(); |
| 1512 | 1507 |
| 1513 // The intermediate file should now be gone. | 1508 // The intermediate file should now be gone. |
| 1514 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1509 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1515 EXPECT_TRUE(download->GetFullPath().empty()); | 1510 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1516 } | 1511 } |
| 1517 | 1512 |
| 1518 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveDownload) { | 1513 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveDownload) { |
| 1519 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1514 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1520 switches::kEnableDownloadResumption); | 1515 switches::kEnableDownloadResumption); |
| 1521 ASSERT_TRUE(test_server()->Start()); | 1516 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1522 | 1517 |
| 1523 // An interrupted download should remove the intermediate file when it is | 1518 // An interrupted download should remove the intermediate file when it is |
| 1524 // removed. | 1519 // removed. |
| 1525 { | 1520 { |
| 1526 GURL url1 = test_server()->GetURL( | 1521 GURL url1 = spawned_test_server()->GetURL( |
| 1527 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", | 1522 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", |
| 1528 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); | 1523 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
| 1529 | 1524 |
| 1530 DownloadItem* download(StartDownloadAndReturnItem(url1)); | 1525 DownloadItem* download(StartDownloadAndReturnItem(url1)); |
| 1531 WaitForData(download, GetSafeBufferChunk()); | 1526 WaitForData(download, GetSafeBufferChunk()); |
| 1532 ReleaseRSTAndConfirmInterruptForResume(download); | 1527 ReleaseRSTAndConfirmInterruptForResume(download); |
| 1533 ConfirmFileStatusForResume( | 1528 ConfirmFileStatusForResume( |
| 1534 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, | 1529 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3, |
| 1535 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload"))); | 1530 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload"))); |
| 1536 | 1531 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1565 | 1560 |
| 1566 // The file should still exist. | 1561 // The file should still exist. |
| 1567 EXPECT_TRUE(base::PathExists(target_path)); | 1562 EXPECT_TRUE(base::PathExists(target_path)); |
| 1568 } | 1563 } |
| 1569 } | 1564 } |
| 1570 | 1565 |
| 1571 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { | 1566 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RemoveResumingDownload) { |
| 1572 SetupEnsureNoPendingDownloads(); | 1567 SetupEnsureNoPendingDownloads(); |
| 1573 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1568 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1574 switches::kEnableDownloadResumption); | 1569 switches::kEnableDownloadResumption); |
| 1575 ASSERT_TRUE(test_server()->Start()); | 1570 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1576 | 1571 |
| 1577 GURL url = test_server()->GetURL( | 1572 GURL url = spawned_test_server()->GetURL( |
| 1578 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", | 1573 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", |
| 1579 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); | 1574 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
| 1580 | 1575 |
| 1581 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); | 1576 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); |
| 1582 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); | 1577 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); |
| 1583 | 1578 |
| 1584 DownloadItem* download(StartDownloadAndReturnItem(url)); | 1579 DownloadItem* download(StartDownloadAndReturnItem(url)); |
| 1585 WaitForData(download, GetSafeBufferChunk()); | 1580 WaitForData(download, GetSafeBufferChunk()); |
| 1586 ::testing::Mock::VerifyAndClearExpectations(&dm_observer); | 1581 ::testing::Mock::VerifyAndClearExpectations(&dm_observer); |
| 1587 | 1582 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1602 download->Remove(); | 1597 download->Remove(); |
| 1603 | 1598 |
| 1604 // The intermediate file should now be gone. | 1599 // The intermediate file should now be gone. |
| 1605 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1600 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1606 RunAllPendingInMessageLoop(); | 1601 RunAllPendingInMessageLoop(); |
| 1607 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1602 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1608 | 1603 |
| 1609 // Start the second download and wait until it's done. The test server is | 1604 // Start the second download and wait until it's done. The test server is |
| 1610 // single threaded. The response to this download request should follow the | 1605 // single threaded. The response to this download request should follow the |
| 1611 // response to the previous resumption request. | 1606 // response to the previous resumption request. |
| 1612 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); | 1607 GURL url2( |
| 1608 spawned_test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); |
| 1613 NavigateToURLAndWaitForDownload(shell(), url2, DownloadItem::COMPLETE); | 1609 NavigateToURLAndWaitForDownload(shell(), url2, DownloadItem::COMPLETE); |
| 1614 | 1610 |
| 1615 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1611 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1616 } | 1612 } |
| 1617 | 1613 |
| 1618 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumingDownload) { | 1614 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumingDownload) { |
| 1619 SetupEnsureNoPendingDownloads(); | 1615 SetupEnsureNoPendingDownloads(); |
| 1620 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 1616 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1621 switches::kEnableDownloadResumption); | 1617 switches::kEnableDownloadResumption); |
| 1622 ASSERT_TRUE(test_server()->Start()); | 1618 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1623 | 1619 |
| 1624 GURL url = test_server()->GetURL( | 1620 GURL url = spawned_test_server()->GetURL( |
| 1625 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", | 1621 base::StringPrintf("rangereset?size=%d&rst_boundary=%d", |
| 1626 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); | 1622 GetSafeBufferChunk() * 3, GetSafeBufferChunk())); |
| 1627 | 1623 |
| 1628 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); | 1624 MockDownloadManagerObserver dm_observer(DownloadManagerForShell(shell())); |
| 1629 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); | 1625 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); |
| 1630 | 1626 |
| 1631 DownloadItem* download(StartDownloadAndReturnItem(url)); | 1627 DownloadItem* download(StartDownloadAndReturnItem(url)); |
| 1632 WaitForData(download, GetSafeBufferChunk()); | 1628 WaitForData(download, GetSafeBufferChunk()); |
| 1633 ::testing::Mock::VerifyAndClearExpectations(&dm_observer); | 1629 ::testing::Mock::VerifyAndClearExpectations(&dm_observer); |
| 1634 | 1630 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1650 | 1646 |
| 1651 // The intermediate file should now be gone. | 1647 // The intermediate file should now be gone. |
| 1652 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1648 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1653 RunAllPendingInMessageLoop(); | 1649 RunAllPendingInMessageLoop(); |
| 1654 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1650 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1655 EXPECT_TRUE(download->GetFullPath().empty()); | 1651 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1656 | 1652 |
| 1657 // Start the second download and wait until it's done. The test server is | 1653 // Start the second download and wait until it's done. The test server is |
| 1658 // single threaded. The response to this download request should follow the | 1654 // single threaded. The response to this download request should follow the |
| 1659 // response to the previous resumption request. | 1655 // response to the previous resumption request. |
| 1660 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); | 1656 GURL url2( |
| 1657 spawned_test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); |
| 1661 NavigateToURLAndWaitForDownload(shell(), url2, DownloadItem::COMPLETE); | 1658 NavigateToURLAndWaitForDownload(shell(), url2, DownloadItem::COMPLETE); |
| 1662 | 1659 |
| 1663 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1660 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1664 } | 1661 } |
| 1665 | 1662 |
| 1666 // Check that the cookie policy is correctly updated when downloading a file | 1663 // Check that the cookie policy is correctly updated when downloading a file |
| 1667 // that redirects cross origin. | 1664 // that redirects cross origin. |
| 1668 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { | 1665 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { |
| 1669 ASSERT_TRUE(test_server()->Start()); | 1666 ASSERT_TRUE(spawned_test_server()->Start()); |
| 1670 net::HostPortPair host_port = test_server()->host_port_pair(); | 1667 net::HostPortPair host_port = spawned_test_server()->host_port_pair(); |
| 1671 DCHECK_EQ(host_port.host(), std::string("127.0.0.1")); | 1668 DCHECK_EQ(host_port.host(), std::string("127.0.0.1")); |
| 1672 | 1669 |
| 1673 // Block third-party cookies. | 1670 // Block third-party cookies. |
| 1674 ShellNetworkDelegate::SetAcceptAllCookies(false); | 1671 ShellNetworkDelegate::SetAcceptAllCookies(false); |
| 1675 | 1672 |
| 1676 // |url| redirects to a different origin |download| which tries to set a | 1673 // |url| redirects to a different origin |download| which tries to set a |
| 1677 // cookie. | 1674 // cookie. |
| 1678 std::string download(base::StringPrintf( | 1675 std::string download(base::StringPrintf( |
| 1679 "http://localhost:%d/set-cookie?A=B", host_port.port())); | 1676 "http://localhost:%d/set-cookie?A=B", host_port.port())); |
| 1680 GURL url(test_server()->GetURL("server-redirect?" + download)); | 1677 GURL url(spawned_test_server()->GetURL("server-redirect?" + download)); |
| 1681 | 1678 |
| 1682 // Download the file. | 1679 // Download the file. |
| 1683 SetupEnsureNoPendingDownloads(); | 1680 SetupEnsureNoPendingDownloads(); |
| 1684 scoped_ptr<DownloadUrlParameters> dl_params( | 1681 scoped_ptr<DownloadUrlParameters> dl_params( |
| 1685 DownloadUrlParameters::FromWebContents(shell()->web_contents(), url)); | 1682 DownloadUrlParameters::FromWebContents(shell()->web_contents(), url)); |
| 1686 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(shell(), 1)); | 1683 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(shell(), 1)); |
| 1687 DownloadManagerForShell(shell())->DownloadUrl(dl_params.Pass()); | 1684 DownloadManagerForShell(shell())->DownloadUrl(dl_params.Pass()); |
| 1688 observer->WaitForFinished(); | 1685 observer->WaitForFinished(); |
| 1689 | 1686 |
| 1690 // Get the important info from other threads and check it. | 1687 // Get the important info from other threads and check it. |
| 1691 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1688 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1692 | 1689 |
| 1693 std::vector<DownloadItem*> downloads; | 1690 std::vector<DownloadItem*> downloads; |
| 1694 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 1691 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 1695 ASSERT_EQ(1u, downloads.size()); | 1692 ASSERT_EQ(1u, downloads.size()); |
| 1696 ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); | 1693 ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); |
| 1697 | 1694 |
| 1698 // Check that the cookies were correctly set. | 1695 // Check that the cookies were correctly set. |
| 1699 EXPECT_EQ("A=B", | 1696 EXPECT_EQ("A=B", |
| 1700 content::GetCookies(shell()->web_contents()->GetBrowserContext(), | 1697 content::GetCookies(shell()->web_contents()->GetBrowserContext(), |
| 1701 GURL(download))); | 1698 GURL(download))); |
| 1702 } | 1699 } |
| 1703 | 1700 |
| 1704 // A filename suggestion specified via a @download attribute should not be | 1701 // A filename suggestion specified via a @download attribute should not be |
| 1705 // effective if the final download URL is in another origin from the original | 1702 // effective if the final download URL is in another origin from the original |
| 1706 // download URL. | 1703 // download URL. |
| 1707 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1704 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1708 DownloadAttributeCrossOriginRedirect) { | 1705 DownloadAttributeCrossOriginRedirect) { |
| 1709 EmbeddedTestServer origin_one; | 1706 net::EmbeddedTestServer origin_one; |
| 1710 EmbeddedTestServer origin_two; | 1707 net::EmbeddedTestServer origin_two; |
| 1711 ASSERT_TRUE(origin_one.InitializeAndWaitUntilReady()); | 1708 ASSERT_TRUE(origin_one.Start()); |
| 1712 ASSERT_TRUE(origin_two.InitializeAndWaitUntilReady()); | 1709 ASSERT_TRUE(origin_two.Start()); |
| 1713 | 1710 |
| 1714 // The download-attribute.html page contains an anchor element whose href is | 1711 // The download-attribute.html page contains an anchor element whose href is |
| 1715 // set to the value of the query parameter (specified as |target| in the URL | 1712 // set to the value of the query parameter (specified as |target| in the URL |
| 1716 // below). The suggested filename for the anchor is 'suggested-filename'. When | 1713 // below). The suggested filename for the anchor is 'suggested-filename'. When |
| 1717 // the page is loaded, a script simulates a click on the anchor, triggering a | 1714 // the page is loaded, a script simulates a click on the anchor, triggering a |
| 1718 // download of the target URL. | 1715 // download of the target URL. |
| 1719 // | 1716 // |
| 1720 // We construct two test servers; origin_one and origin_two. Once started, the | 1717 // We construct two test servers; origin_one and origin_two. Once started, the |
| 1721 // server URLs will differ by the port number. Therefore they will be in | 1718 // server URLs will differ by the port number. Therefore they will be in |
| 1722 // different origins. | 1719 // different origins. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1744 ASSERT_TRUE(origin_one.ShutdownAndWaitUntilComplete()); | 1741 ASSERT_TRUE(origin_one.ShutdownAndWaitUntilComplete()); |
| 1745 ASSERT_TRUE(origin_two.ShutdownAndWaitUntilComplete()); | 1742 ASSERT_TRUE(origin_two.ShutdownAndWaitUntilComplete()); |
| 1746 } | 1743 } |
| 1747 | 1744 |
| 1748 // A filename suggestion specified via a @download attribute should be effective | 1745 // A filename suggestion specified via a @download attribute should be effective |
| 1749 // if the final download URL is in the same origin as the initial download URL. | 1746 // if the final download URL is in the same origin as the initial download URL. |
| 1750 // Test that this holds even if there are cross origin redirects in the middle | 1747 // Test that this holds even if there are cross origin redirects in the middle |
| 1751 // of the redirect chain. | 1748 // of the redirect chain. |
| 1752 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1749 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1753 DownloadAttributeSameOriginRedirect) { | 1750 DownloadAttributeSameOriginRedirect) { |
| 1754 EmbeddedTestServer origin_one; | 1751 net::EmbeddedTestServer origin_one; |
| 1755 EmbeddedTestServer origin_two; | 1752 net::EmbeddedTestServer origin_two; |
| 1756 ASSERT_TRUE(origin_one.InitializeAndWaitUntilReady()); | 1753 ASSERT_TRUE(origin_one.Start()); |
| 1757 ASSERT_TRUE(origin_two.InitializeAndWaitUntilReady()); | 1754 ASSERT_TRUE(origin_two.Start()); |
| 1758 | 1755 |
| 1759 // The download-attribute.html page contains an anchor element whose href is | 1756 // The download-attribute.html page contains an anchor element whose href is |
| 1760 // set to the value of the query parameter (specified as |target| in the URL | 1757 // set to the value of the query parameter (specified as |target| in the URL |
| 1761 // below). The suggested filename for the anchor is 'suggested-filename'. When | 1758 // below). The suggested filename for the anchor is 'suggested-filename'. When |
| 1762 // the page is loaded, a script simulates a click on the anchor, triggering a | 1759 // the page is loaded, a script simulates a click on the anchor, triggering a |
| 1763 // download of the target URL. | 1760 // download of the target URL. |
| 1764 // | 1761 // |
| 1765 // We construct two test servers; origin_one and origin_two. Once started, the | 1762 // We construct two test servers; origin_one and origin_two. Once started, the |
| 1766 // server URLs will differ by the port number. Therefore they will be in | 1763 // server URLs will differ by the port number. Therefore they will be in |
| 1767 // different origins. | 1764 // different origins. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1790 EXPECT_EQ(FILE_PATH_LITERAL("suggested-filename"), | 1787 EXPECT_EQ(FILE_PATH_LITERAL("suggested-filename"), |
| 1791 downloads[0]->GetTargetFilePath().BaseName().value()); | 1788 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 1792 ASSERT_TRUE(origin_one.ShutdownAndWaitUntilComplete()); | 1789 ASSERT_TRUE(origin_one.ShutdownAndWaitUntilComplete()); |
| 1793 ASSERT_TRUE(origin_two.ShutdownAndWaitUntilComplete()); | 1790 ASSERT_TRUE(origin_two.ShutdownAndWaitUntilComplete()); |
| 1794 } | 1791 } |
| 1795 | 1792 |
| 1796 // The file empty.bin is served with a MIME type of application/octet-stream. | 1793 // The file empty.bin is served with a MIME type of application/octet-stream. |
| 1797 // The content body is empty. Make sure this case is handled properly and we | 1794 // The content body is empty. Make sure this case is handled properly and we |
| 1798 // don't regress on http://crbug.com/320394. | 1795 // don't regress on http://crbug.com/320394. |
| 1799 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadGZipWithNoContent) { | 1796 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadGZipWithNoContent) { |
| 1800 EmbeddedTestServer test_server; | 1797 net::EmbeddedTestServer test_server; |
| 1801 ASSERT_TRUE(test_server.InitializeAndWaitUntilReady()); | 1798 ASSERT_TRUE(test_server.Start()); |
| 1802 | 1799 |
| 1803 GURL url = test_server.GetURL("/empty.bin"); | 1800 GURL url = test_server.GetURL("/empty.bin"); |
| 1804 test_server.ServeFilesFromDirectory(GetTestFilePath("download", "")); | 1801 test_server.ServeFilesFromDirectory(GetTestFilePath("download", "")); |
| 1805 | 1802 |
| 1806 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); | 1803 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); |
| 1807 // That's it. This should work without crashing. | 1804 // That's it. This should work without crashing. |
| 1808 } | 1805 } |
| 1809 | 1806 |
| 1810 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Spam) { | 1807 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Spam) { |
| 1811 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 1808 ASSERT_TRUE(embedded_test_server()->Start()); |
| 1812 | 1809 |
| 1813 NavigateToURLAndWaitForDownload( | 1810 NavigateToURLAndWaitForDownload( |
| 1814 shell(), | 1811 shell(), |
| 1815 embedded_test_server()->GetURL( | 1812 embedded_test_server()->GetURL( |
| 1816 "/download/double-content-disposition.txt"), | 1813 "/download/double-content-disposition.txt"), |
| 1817 DownloadItem::COMPLETE); | 1814 DownloadItem::COMPLETE); |
| 1818 | 1815 |
| 1819 std::vector<DownloadItem*> downloads; | 1816 std::vector<DownloadItem*> downloads; |
| 1820 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 1817 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 1821 ASSERT_EQ(1u, downloads.size()); | 1818 ASSERT_EQ(1u, downloads.size()); |
| 1822 | 1819 |
| 1823 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 1820 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
| 1824 downloads[0]->GetTargetFilePath().BaseName().value()); | 1821 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 1825 } | 1822 } |
| 1826 | 1823 |
| 1827 } // namespace content | 1824 } // namespace content |
| OLD | NEW |