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

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

Issue 1533583002: [Downloads] Factor out request handling logic between DRH and UD. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments and change .Pass() -> std::move(...) per PRESUBMIT check Created 4 years, 12 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
« no previous file with comments | « no previous file | content/browser/download/download_create_info.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 8 #include <vector>
9 9
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 1503 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 request_handler.StartServing(parameters); 1514 request_handler.StartServing(parameters);
1515 1515
1516 DownloadItem* download = StartDownloadAndReturnItem( 1516 DownloadItem* download = StartDownloadAndReturnItem(
1517 initiator_shell_for_resumption(), request_handler.url()); 1517 initiator_shell_for_resumption(), request_handler.url());
1518 WaitForInterrupt(download); 1518 WaitForInterrupt(download);
1519 1519
1520 base::FilePath intermediate_path(download->GetFullPath()); 1520 base::FilePath intermediate_path(download->GetFullPath());
1521 ASSERT_FALSE(intermediate_path.empty()); 1521 ASSERT_FALSE(intermediate_path.empty());
1522 EXPECT_TRUE(base::PathExists(intermediate_path)); 1522 EXPECT_TRUE(base::PathExists(intermediate_path));
1523 1523
1524 // Resume and remove download. We expect only a single OnDownloadCreated() 1524 // Resume and cancel download. We expect only a single OnDownloadCreated()
1525 // call, and that's for the second download created below. 1525 // call, and that's for the second download created below.
1526 MockDownloadManagerObserver dm_observer( 1526 MockDownloadManagerObserver dm_observer(
1527 DownloadManagerForShell(initiator_shell_for_resumption())); 1527 DownloadManagerForShell(initiator_shell_for_resumption()));
1528 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1); 1528 EXPECT_CALL(dm_observer, OnDownloadCreated(_,_)).Times(1);
1529 1529
1530 TestRequestStartHandler request_start_handler; 1530 TestRequestStartHandler request_start_handler;
1531 parameters.on_start_handler = request_start_handler.GetOnStartHandler(); 1531 parameters.on_start_handler = request_start_handler.GetOnStartHandler();
1532 request_handler.StartServing(parameters); 1532 request_handler.StartServing(parameters);
1533 1533
1534 PrepareToResume(); 1534 PrepareToResume();
(...skipping 18 matching lines...) Expand all
1553 1553
1554 // Start the second download and wait until it's done. This exercises the 1554 // Start the second download and wait until it's done. This exercises the
1555 // entire downloads stack and effectively flushes all of our worker threads. 1555 // entire downloads stack and effectively flushes all of our worker threads.
1556 // We are testing whether the URL request created in the previous 1556 // We are testing whether the URL request created in the previous
1557 // DownloadItem::Resume() call reulted in a new download or not. 1557 // DownloadItem::Resume() call reulted in a new download or not.
1558 NavigateToURLAndWaitForDownload(shell(), request_handler.url(), 1558 NavigateToURLAndWaitForDownload(shell(), request_handler.url(),
1559 DownloadItem::COMPLETE); 1559 DownloadItem::COMPLETE);
1560 EXPECT_TRUE(EnsureNoPendingDownloads()); 1560 EXPECT_TRUE(EnsureNoPendingDownloads());
1561 } 1561 }
1562 1562
1563 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RemoveResumedDownload) {
1564 TestDownloadRequestHandler::Parameters parameters =
1565 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
1566 TestDownloadRequestHandler request_handler;
1567 request_handler.StartServing(parameters);
1568
1569 DownloadItem* download = StartDownloadAndReturnItem(
1570 initiator_shell_for_resumption(), request_handler.url());
1571 WaitForInterrupt(download);
1572
1573 base::FilePath intermediate_path(download->GetFullPath());
1574 base::FilePath target_path(download->GetTargetFilePath());
1575 ASSERT_FALSE(intermediate_path.empty());
1576 EXPECT_TRUE(base::PathExists(intermediate_path));
1577 EXPECT_FALSE(base::PathExists(target_path));
1578
1579 // Resume and remove download. We don't expect OnDownloadCreated() calls.
1580 MockDownloadManagerObserver dm_observer(
1581 DownloadManagerForShell(initiator_shell_for_resumption()));
1582 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0);
1583
1584 PrepareToResume();
1585 download->Resume();
1586 WaitForInProgress(download);
1587
1588 download->Remove();
1589
1590 // The intermediate file should now be gone.
1591 RunAllPendingInMessageLoop(BrowserThread::FILE);
1592 RunAllPendingInMessageLoop();
1593 EXPECT_FALSE(base::PathExists(intermediate_path));
1594 EXPECT_FALSE(base::PathExists(target_path));
1595 EXPECT_TRUE(EnsureNoPendingDownloads());
1596 }
1597
1598 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, CancelResumedDownload) {
1599 TestDownloadRequestHandler::Parameters parameters =
1600 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
1601 TestDownloadRequestHandler request_handler;
1602 request_handler.StartServing(parameters);
1603
1604 DownloadItem* download = StartDownloadAndReturnItem(
1605 initiator_shell_for_resumption(), request_handler.url());
1606 WaitForInterrupt(download);
1607
1608 base::FilePath intermediate_path(download->GetFullPath());
1609 base::FilePath target_path(download->GetTargetFilePath());
1610 ASSERT_FALSE(intermediate_path.empty());
1611 EXPECT_TRUE(base::PathExists(intermediate_path));
1612 EXPECT_FALSE(base::PathExists(target_path));
1613
1614 // Resume and remove download. We don't expect OnDownloadCreated() calls.
1615 MockDownloadManagerObserver dm_observer(
1616 DownloadManagerForShell(initiator_shell_for_resumption()));
1617 EXPECT_CALL(dm_observer, OnDownloadCreated(_, _)).Times(0);
1618
1619 PrepareToResume();
1620 download->Resume();
1621 WaitForInProgress(download);
1622
1623 download->Cancel(true);
1624
1625 // The intermediate file should now be gone.
1626 RunAllPendingInMessageLoop(BrowserThread::FILE);
1627 RunAllPendingInMessageLoop();
1628 EXPECT_FALSE(base::PathExists(intermediate_path));
1629 EXPECT_FALSE(base::PathExists(target_path));
1630 EXPECT_TRUE(EnsureNoPendingDownloads());
1631 }
1632
1563 // Check that the cookie policy is correctly updated when downloading a file 1633 // Check that the cookie policy is correctly updated when downloading a file
1564 // that redirects cross origin. 1634 // that redirects cross origin.
1565 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { 1635 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) {
1566 net::EmbeddedTestServer origin_one; 1636 net::EmbeddedTestServer origin_one;
1567 net::EmbeddedTestServer origin_two; 1637 net::EmbeddedTestServer origin_two;
1568 ASSERT_TRUE(origin_one.Start()); 1638 ASSERT_TRUE(origin_one.Start());
1569 ASSERT_TRUE(origin_two.Start()); 1639 ASSERT_TRUE(origin_two.Start());
1570 1640
1571 // Block third-party cookies. 1641 // Block third-party cookies.
1572 ShellNetworkDelegate::SetAcceptAllCookies(false); 1642 ShellNetworkDelegate::SetAcceptAllCookies(false);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
1698 1768
1699 // The file empty.bin is served with a MIME type of application/octet-stream. 1769 // The file empty.bin is served with a MIME type of application/octet-stream.
1700 // The content body is empty. Make sure this case is handled properly and we 1770 // The content body is empty. Make sure this case is handled properly and we
1701 // don't regress on http://crbug.com/320394. 1771 // don't regress on http://crbug.com/320394.
1702 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadGZipWithNoContent) { 1772 IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadGZipWithNoContent) {
1703 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("empty.bin"); 1773 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("empty.bin");
1704 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); 1774 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE);
1705 // That's it. This should work without crashing. 1775 // That's it. This should work without crashing.
1706 } 1776 }
1707 1777
1778 // Make sure that sniffed MIME types are correctly passed through to the
1779 // download item.
1780 IN_PROC_BROWSER_TEST_F(DownloadContentTest, SniffedMimeType) {
1781 GURL url = net::URLRequestMockHTTPJob::GetMockUrl("gzip-content.gz");
1782 DownloadItem* item = StartDownloadAndReturnItem(shell(), url);
1783 WaitForCompletion(item);
1784
1785 EXPECT_STREQ("application/x-gzip", item->GetMimeType().c_str());
1786 EXPECT_TRUE(item->GetOriginalMimeType().empty());
1787 }
1788
1708 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Spam) { 1789 IN_PROC_BROWSER_TEST_F(DownloadContentTest, Spam) {
1709 ASSERT_TRUE(embedded_test_server()->Start()); 1790 ASSERT_TRUE(embedded_test_server()->Start());
1710 1791
1711 NavigateToURLAndWaitForDownload( 1792 NavigateToURLAndWaitForDownload(
1712 shell(), 1793 shell(),
1713 embedded_test_server()->GetURL( 1794 embedded_test_server()->GetURL(
1714 "/download/double-content-disposition.txt"), 1795 "/download/double-content-disposition.txt"),
1715 DownloadItem::COMPLETE); 1796 DownloadItem::COMPLETE);
1716 1797
1717 std::vector<DownloadItem*> downloads; 1798 std::vector<DownloadItem*> downloads;
1718 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 1799 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
1719 ASSERT_EQ(1u, downloads.size()); 1800 ASSERT_EQ(1u, downloads.size());
1720 1801
1721 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), 1802 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"),
1722 downloads[0]->GetTargetFilePath().BaseName().value()); 1803 downloads[0]->GetTargetFilePath().BaseName().value());
1723 } 1804 }
1724 1805
1725 } // namespace content 1806 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/download/download_create_info.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698