Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(444)

Side by Side Diff: content/browser/download/download_browsertest.cc

Issue 1750943002: [Downloads] Stop keying TestFileErrorInjector off of URLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplify TestFileErrorInjector Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1474 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, 1474 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest,
1475 RecoverFromInitFileError) { 1475 RecoverFromInitFileError) {
1476 TestDownloadRequestHandler request_handler; 1476 TestDownloadRequestHandler request_handler;
1477 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); 1477 request_handler.StartServing(TestDownloadRequestHandler::Parameters());
1478 1478
1479 // Setup the error injector. 1479 // Setup the error injector.
1480 scoped_refptr<TestFileErrorInjector> injector(TestFileErrorInjector::Create( 1480 scoped_refptr<TestFileErrorInjector> injector(TestFileErrorInjector::Create(
1481 DownloadManagerForShell(initiator_shell_for_resumption()))); 1481 DownloadManagerForShell(initiator_shell_for_resumption())));
1482 1482
1483 const TestFileErrorInjector::FileErrorInfo err = { 1483 const TestFileErrorInjector::FileErrorInfo err = {
1484 request_handler.url().spec(),
1485 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0, 1484 TestFileErrorInjector::FILE_OPERATION_INITIALIZE, 0,
1486 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; 1485 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE};
1487 injector->AddError(err); 1486 injector->InjectError(err);
1488 injector->InjectErrors();
1489 1487
1490 // Start and watch for interrupt. 1488 // Start and watch for interrupt.
1491 DownloadItem* download(StartDownloadAndReturnItem( 1489 DownloadItem* download(StartDownloadAndReturnItem(
1492 initiator_shell_for_resumption(), request_handler.url())); 1490 initiator_shell_for_resumption(), request_handler.url()));
1493 WaitForInterrupt(download); 1491 WaitForInterrupt(download);
1494 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 1492 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState());
1495 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 1493 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
1496 download->GetLastReason()); 1494 download->GetLastReason());
1497 EXPECT_EQ(0, download->GetReceivedBytes()); 1495 EXPECT_EQ(0, download->GetReceivedBytes());
1498 EXPECT_TRUE(download->GetFullPath().empty()); 1496 EXPECT_TRUE(download->GetFullPath().empty());
1499 EXPECT_FALSE(download->GetTargetFilePath().empty()); 1497 EXPECT_FALSE(download->GetTargetFilePath().empty());
1500 1498
1501 // We need to make sure that any cross-thread downloads communication has 1499 // We need to make sure that any cross-thread downloads communication has
1502 // quiesced before clearing and injecting the new errors, as the 1500 // quiesced before clearing and injecting the new errors, as the
1503 // InjectErrors() routine alters the currently in use download file 1501 // InjectErrors() routine alters the currently in use download file
1504 // factory, which is a file thread object. 1502 // factory, which is a file thread object.
1505 RunAllPendingInMessageLoop(BrowserThread::FILE); 1503 RunAllPendingInMessageLoop(BrowserThread::FILE);
1506 RunAllPendingInMessageLoop(); 1504 RunAllPendingInMessageLoop();
1507 1505
1508 // Clear the old errors list. 1506 // Clear the old errors list.
1509 injector->ClearErrors(); 1507 injector->ClearError();
1510 injector->InjectErrors();
1511 1508
1512 // Resume and watch completion. 1509 // Resume and watch completion.
1513 PrepareToResume(); 1510 PrepareToResume();
1514 download->Resume(); 1511 download->Resume();
1515 WaitForCompletion(download); 1512 WaitForCompletion(download);
1516 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); 1513 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE);
1517 } 1514 }
1518 1515
1519 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, 1516 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest,
1520 RecoverFromIntermediateFileRenameError) { 1517 RecoverFromIntermediateFileRenameError) {
1521 TestDownloadRequestHandler request_handler; 1518 TestDownloadRequestHandler request_handler;
1522 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); 1519 request_handler.StartServing(TestDownloadRequestHandler::Parameters());
1523 1520
1524 // Setup the error injector. 1521 // Setup the error injector.
1525 scoped_refptr<TestFileErrorInjector> injector(TestFileErrorInjector::Create( 1522 scoped_refptr<TestFileErrorInjector> injector(TestFileErrorInjector::Create(
1526 DownloadManagerForShell(initiator_shell_for_resumption()))); 1523 DownloadManagerForShell(initiator_shell_for_resumption())));
1527 1524
1528 const TestFileErrorInjector::FileErrorInfo err = { 1525 const TestFileErrorInjector::FileErrorInfo err = {
1529 request_handler.url().spec(),
1530 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, 0, 1526 TestFileErrorInjector::FILE_OPERATION_RENAME_UNIQUIFY, 0,
1531 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE}; 1527 DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE};
1532 injector->AddError(err); 1528 injector->InjectError(err);
1533 injector->InjectErrors();
1534 1529
1535 // Start and watch for interrupt. 1530 // Start and watch for interrupt.
1536 DownloadItem* download(StartDownloadAndReturnItem( 1531 DownloadItem* download(StartDownloadAndReturnItem(
1537 initiator_shell_for_resumption(), request_handler.url())); 1532 initiator_shell_for_resumption(), request_handler.url()));
1538 WaitForInterrupt(download); 1533 WaitForInterrupt(download);
1539 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 1534 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState());
1540 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE, 1535 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE,
1541 download->GetLastReason()); 1536 download->GetLastReason());
1542 EXPECT_TRUE(download->GetFullPath().empty()); 1537 EXPECT_TRUE(download->GetFullPath().empty());
1543 // Target path will have been set after file name determination. GetFullPath() 1538 // Target path will have been set after file name determination. GetFullPath()
1544 // being empty is sufficient to signal that filename determination needs to be 1539 // being empty is sufficient to signal that filename determination needs to be
1545 // redone. 1540 // redone.
1546 EXPECT_FALSE(download->GetTargetFilePath().empty()); 1541 EXPECT_FALSE(download->GetTargetFilePath().empty());
1547 1542
1548 // We need to make sure that any cross-thread downloads communication has 1543 // We need to make sure that any cross-thread downloads communication has
1549 // quiesced before clearing and injecting the new errors, as the 1544 // quiesced before clearing and injecting the new errors, as the
1550 // InjectErrors() routine alters the currently in use download file 1545 // InjectErrors() routine alters the currently in use download file
1551 // factory, which is a file thread object. 1546 // factory, which is a file thread object.
1552 RunAllPendingInMessageLoop(BrowserThread::FILE); 1547 RunAllPendingInMessageLoop(BrowserThread::FILE);
1553 RunAllPendingInMessageLoop(); 1548 RunAllPendingInMessageLoop();
1554 1549
1555 // Clear the old errors list. 1550 // Clear the old errors list.
1556 injector->ClearErrors(); 1551 injector->ClearError();
1557 injector->InjectErrors();
1558 1552
1559 PrepareToResume(); 1553 PrepareToResume();
1560 download->Resume(); 1554 download->Resume();
1561 WaitForCompletion(download); 1555 WaitForCompletion(download);
1562 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); 1556 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE);
1563 } 1557 }
1564 1558
1565 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, 1559 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest,
1566 RecoverFromFinalRenameError) { 1560 RecoverFromFinalRenameError) {
1567 TestDownloadRequestHandler request_handler; 1561 TestDownloadRequestHandler request_handler;
1568 request_handler.StartServing(TestDownloadRequestHandler::Parameters()); 1562 request_handler.StartServing(TestDownloadRequestHandler::Parameters());
1569 1563
1570 // Setup the error injector. 1564 // Setup the error injector.
1571 scoped_refptr<TestFileErrorInjector> injector(TestFileErrorInjector::Create( 1565 scoped_refptr<TestFileErrorInjector> injector(TestFileErrorInjector::Create(
1572 DownloadManagerForShell(initiator_shell_for_resumption()))); 1566 DownloadManagerForShell(initiator_shell_for_resumption())));
1573 1567
1574 DownloadManagerForShell(initiator_shell_for_resumption()) 1568 DownloadManagerForShell(initiator_shell_for_resumption())
1575 ->RemoveAllDownloads(); 1569 ->RemoveAllDownloads();
1576 TestFileErrorInjector::FileErrorInfo err = { 1570 TestFileErrorInjector::FileErrorInfo err = {
1577 request_handler.url().spec(),
1578 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, 0, 1571 TestFileErrorInjector::FILE_OPERATION_RENAME_ANNOTATE, 0,
1579 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED}; 1572 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED};
1580 injector->AddError(err); 1573 injector->InjectError(err);
1581 injector->InjectErrors();
1582 1574
1583 // Start and watch for interrupt. 1575 // Start and watch for interrupt.
1584 DownloadItem* download(StartDownloadAndReturnItem( 1576 DownloadItem* download(StartDownloadAndReturnItem(
1585 initiator_shell_for_resumption(), request_handler.url())); 1577 initiator_shell_for_resumption(), request_handler.url()));
1586 WaitForInterrupt(download); 1578 WaitForInterrupt(download);
1587 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState()); 1579 ASSERT_EQ(DownloadItem::INTERRUPTED, download->GetState());
1588 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, download->GetLastReason()); 1580 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, download->GetLastReason());
1589 EXPECT_TRUE(download->GetFullPath().empty()); 1581 EXPECT_TRUE(download->GetFullPath().empty());
1590 // Target path should still be intact. 1582 // Target path should still be intact.
1591 EXPECT_FALSE(download->GetTargetFilePath().empty()); 1583 EXPECT_FALSE(download->GetTargetFilePath().empty());
1592 1584
1593 // We need to make sure that any cross-thread downloads communication has 1585 // We need to make sure that any cross-thread downloads communication has
1594 // quiesced before clearing and injecting the new errors, as the 1586 // quiesced before clearing and injecting the new errors, as the
1595 // InjectErrors() routine alters the currently in use download file 1587 // InjectErrors() routine alters the currently in use download file
1596 // factory, which is a file thread object. 1588 // factory, which is a file thread object.
1597 RunAllPendingInMessageLoop(BrowserThread::FILE); 1589 RunAllPendingInMessageLoop(BrowserThread::FILE);
1598 RunAllPendingInMessageLoop(); 1590 RunAllPendingInMessageLoop();
1599 1591
1600 // Clear the old errors list. 1592 // Clear the old errors list.
1601 injector->ClearErrors(); 1593 injector->ClearError();
1602 injector->InjectErrors();
1603 1594
1604 PrepareToResume(); 1595 PrepareToResume();
1605 download->Resume(); 1596 download->Resume();
1606 WaitForCompletion(download); 1597 WaitForCompletion(download);
1607 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE); 1598 EXPECT_EQ(download->GetState(), DownloadItem::COMPLETE);
1608 } 1599 }
1609 1600
1610 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, Resume_Hash) { 1601 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, Resume_Hash) {
1611 using InjectedError = TestDownloadRequestHandler::InjectedError; 1602 using InjectedError = TestDownloadRequestHandler::InjectedError;
1612 const char kExpectedHash[] = 1603 const char kExpectedHash[] =
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
2136 2127
2137 std::vector<DownloadItem*> downloads; 2128 std::vector<DownloadItem*> downloads;
2138 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 2129 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
2139 ASSERT_EQ(1u, downloads.size()); 2130 ASSERT_EQ(1u, downloads.size());
2140 2131
2141 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), 2132 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"),
2142 downloads[0]->GetTargetFilePath().BaseName().value()); 2133 downloads[0]->GetTargetFilePath().BaseName().value());
2143 } 2134 }
2144 2135
2145 } // namespace content 2136 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/download/download_browsertest.cc ('k') | content/public/test/test_file_error_injector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698