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

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

Powered by Google App Engine
This is Rietveld 408576698