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 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 bool ShouldOpenDownload( | 376 bool ShouldOpenDownload( |
377 DownloadItem* item, | 377 DownloadItem* item, |
378 const DownloadOpenDelayedCallback& callback) override { | 378 const DownloadOpenDelayedCallback& callback) override { |
379 if (delay_download_open_) { | 379 if (delay_download_open_) { |
380 delayed_callbacks_.push_back(callback); | 380 delayed_callbacks_.push_back(callback); |
381 return false; | 381 return false; |
382 } | 382 } |
383 return true; | 383 return true; |
384 } | 384 } |
385 | 385 |
| 386 bool GenerateFileHash() override { return true; } |
| 387 |
386 void SetDelayedOpen(bool delay) { | 388 void SetDelayedOpen(bool delay) { |
387 delay_download_open_ = delay; | 389 delay_download_open_ = delay; |
388 } | 390 } |
389 | 391 |
390 void GetDelayedCallbacks( | 392 void GetDelayedCallbacks( |
391 std::vector<DownloadOpenDelayedCallback>* callbacks) { | 393 std::vector<DownloadOpenDelayedCallback>* callbacks) { |
392 callbacks->swap(delayed_callbacks_); | 394 callbacks->swap(delayed_callbacks_); |
393 } | 395 } |
394 private: | 396 private: |
395 bool delay_download_open_; | 397 bool delay_download_open_; |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 // Clear the old errors list. | 1394 // Clear the old errors list. |
1393 injector->ClearErrors(); | 1395 injector->ClearErrors(); |
1394 injector->InjectErrors(); | 1396 injector->InjectErrors(); |
1395 | 1397 |
1396 PrepareToResume(); | 1398 PrepareToResume(); |
1397 download->Resume(); | 1399 download->Resume(); |
1398 WaitForCompletion(download); | 1400 WaitForCompletion(download); |
1399 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); | 1401 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); |
1400 } | 1402 } |
1401 | 1403 |
| 1404 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, Resume_Hash) { |
| 1405 using InjectedError = TestDownloadRequestHandler::InjectedError; |
| 1406 const char kExpectedHash[] = |
| 1407 "\xa7\x44\x49\x86\x24\xc6\x84\x6c\x89\xdf\xd8\xec\xa0\xe0\x61\x12\xdc\x80" |
| 1408 "\x13\xf2\x83\x49\xa9\x14\x52\x32\xf0\x95\x20\xca\x5b\x30"; |
| 1409 std::string expected_hash(kExpectedHash); |
| 1410 TestDownloadRequestHandler request_handler; |
| 1411 TestDownloadRequestHandler::Parameters parameters; |
| 1412 |
| 1413 // As a control, let's try GetHash() on an uninterrupted download. |
| 1414 request_handler.StartServing(parameters); |
| 1415 DownloadItem* uninterrupted_download(StartDownloadAndReturnItem( |
| 1416 initiator_shell_for_resumption(), request_handler.url())); |
| 1417 WaitForCompletion(uninterrupted_download); |
| 1418 EXPECT_EQ(expected_hash, uninterrupted_download->GetHash()); |
| 1419 |
| 1420 // Now with interruptions. |
| 1421 parameters.injected_errors.push( |
| 1422 InjectedError(100, net::ERR_CONNECTION_RESET)); |
| 1423 parameters.injected_errors.push( |
| 1424 InjectedError(211, net::ERR_CONNECTION_RESET)); |
| 1425 parameters.injected_errors.push( |
| 1426 InjectedError(337, net::ERR_CONNECTION_RESET)); |
| 1427 parameters.injected_errors.push( |
| 1428 InjectedError(400, net::ERR_CONNECTION_RESET)); |
| 1429 parameters.injected_errors.push( |
| 1430 InjectedError(512, net::ERR_CONNECTION_RESET)); |
| 1431 request_handler.StartServing(parameters); |
| 1432 |
| 1433 // Start and watch for interrupt. |
| 1434 DownloadItem* download(StartDownloadAndReturnItem( |
| 1435 initiator_shell_for_resumption(), request_handler.url())); |
| 1436 WaitForInterrupt(download); |
| 1437 |
| 1438 PrepareToResume(); |
| 1439 download->Resume(); |
| 1440 WaitForInterrupt(download); |
| 1441 |
| 1442 download->Resume(); |
| 1443 WaitForInterrupt(download); |
| 1444 |
| 1445 download->Resume(); |
| 1446 WaitForInterrupt(download); |
| 1447 |
| 1448 download->Resume(); |
| 1449 WaitForInterrupt(download); |
| 1450 |
| 1451 download->Resume(); |
| 1452 WaitForCompletion(download); |
| 1453 |
| 1454 EXPECT_EQ(expected_hash, download->GetHash()); |
| 1455 } |
| 1456 |
1402 // An interrupted download should remove the intermediate file when it is | 1457 // An interrupted download should remove the intermediate file when it is |
1403 // cancelled. | 1458 // cancelled. |
1404 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, | 1459 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, |
1405 CancelInterruptedDownload) { | 1460 CancelInterruptedDownload) { |
1406 TestDownloadRequestHandler request_handler; | 1461 TestDownloadRequestHandler request_handler; |
1407 request_handler.StartServing( | 1462 request_handler.StartServing( |
1408 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); | 1463 TestDownloadRequestHandler::Parameters::WithSingleInterruption()); |
1409 | 1464 |
1410 DownloadItem* download = StartDownloadAndReturnItem( | 1465 DownloadItem* download = StartDownloadAndReturnItem( |
1411 initiator_shell_for_resumption(), request_handler.url()); | 1466 initiator_shell_for_resumption(), request_handler.url()); |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 | 1865 |
1811 std::vector<DownloadItem*> downloads; | 1866 std::vector<DownloadItem*> downloads; |
1812 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 1867 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
1813 ASSERT_EQ(1u, downloads.size()); | 1868 ASSERT_EQ(1u, downloads.size()); |
1814 | 1869 |
1815 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 1870 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
1816 downloads[0]->GetTargetFilePath().BaseName().value()); | 1871 downloads[0]->GetTargetFilePath().BaseName().value()); |
1817 } | 1872 } |
1818 | 1873 |
1819 } // namespace content | 1874 } // namespace content |
OLD | NEW |