Chromium Code Reviews| 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/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "content/public/test/content_browser_test_utils.h" | 29 #include "content/public/test/content_browser_test_utils.h" |
| 30 #include "content/public/test/download_test_observer.h" | 30 #include "content/public/test/download_test_observer.h" |
| 31 #include "content/public/test/test_file_error_injector.h" | 31 #include "content/public/test/test_file_error_injector.h" |
| 32 #include "content/public/test/test_utils.h" | 32 #include "content/public/test/test_utils.h" |
| 33 #include "content/shell/browser/shell.h" | 33 #include "content/shell/browser/shell.h" |
| 34 #include "content/shell/browser/shell_browser_context.h" | 34 #include "content/shell/browser/shell_browser_context.h" |
| 35 #include "content/shell/browser/shell_download_manager_delegate.h" | 35 #include "content/shell/browser/shell_download_manager_delegate.h" |
| 36 #include "content/shell/browser/shell_network_delegate.h" | 36 #include "content/shell/browser/shell_network_delegate.h" |
| 37 #include "content/test/net/url_request_mock_http_job.h" | 37 #include "content/test/net/url_request_mock_http_job.h" |
| 38 #include "content/test/net/url_request_slow_download_job.h" | 38 #include "content/test/net/url_request_slow_download_job.h" |
| 39 #include "net/test/embedded_test_server/embedded_test_server.h" | |
| 40 #include "net/test/embedded_test_server/http_request.h" | |
| 41 #include "net/test/embedded_test_server/http_response.h" | |
| 39 #include "net/test/spawned_test_server/spawned_test_server.h" | 42 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 40 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
| 41 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 42 #include "url/gurl.h" | 45 #include "url/gurl.h" |
| 43 | 46 |
| 44 using ::testing::_; | 47 using ::net::test_server::EmbeddedTestServer; |
| 45 using ::testing::AllOf; | 48 using ::testing::AllOf; |
| 46 using ::testing::Field; | 49 using ::testing::Field; |
| 47 using ::testing::InSequence; | 50 using ::testing::InSequence; |
| 48 using ::testing::Property; | 51 using ::testing::Property; |
| 49 using ::testing::Return; | 52 using ::testing::Return; |
| 50 using ::testing::StrictMock; | 53 using ::testing::StrictMock; |
| 54 using ::testing::_; | |
| 51 | 55 |
| 52 namespace content { | 56 namespace content { |
| 53 | 57 |
| 54 namespace { | 58 namespace { |
| 55 | 59 |
| 56 class MockDownloadItemObserver : public DownloadItem::Observer { | 60 class MockDownloadItemObserver : public DownloadItem::Observer { |
| 57 public: | 61 public: |
| 58 MockDownloadItemObserver() {} | 62 MockDownloadItemObserver() {} |
| 59 virtual ~MockDownloadItemObserver() {} | 63 virtual ~MockDownloadItemObserver() {} |
| 60 | 64 |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 // Filter for saving the size of the download when the first IN_PROGRESS | 500 // Filter for saving the size of the download when the first IN_PROGRESS |
| 497 // is hit. | 501 // is hit. |
| 498 bool InitialSizeFilter(int* download_size, DownloadItem* download) { | 502 bool InitialSizeFilter(int* download_size, DownloadItem* download) { |
| 499 if (download->GetState() != DownloadItem::IN_PROGRESS) | 503 if (download->GetState() != DownloadItem::IN_PROGRESS) |
| 500 return false; | 504 return false; |
| 501 | 505 |
| 502 *download_size = download->GetReceivedBytes(); | 506 *download_size = download->GetReceivedBytes(); |
| 503 return true; | 507 return true; |
| 504 } | 508 } |
| 505 | 509 |
| 510 // Request handler to be used with CreateRedirectHandler(). | |
| 511 scoped_ptr<net::test_server::HttpResponse> HandleRequestAndSendRedirectResponse( | |
| 512 const std::string& relative_url, | |
| 513 const GURL& target_url, | |
| 514 const net::test_server::HttpRequest& request) { | |
| 515 scoped_ptr<net::test_server::BasicHttpResponse> response; | |
| 516 if (request.relative_url == relative_url) { | |
| 517 response.reset(new net::test_server::BasicHttpResponse); | |
| 518 response->set_code(net::HTTP_FOUND); | |
| 519 response->AddCustomHeader("Location", target_url.spec()); | |
| 520 } | |
| 521 return response.PassAs<net::test_server::HttpResponse>(); | |
| 522 } | |
| 523 | |
| 524 // Creates a request handler for EmbeddedTestServer that responds with a HTTP | |
| 525 // 302 redirect if the request URL matches |relative_url|. | |
| 526 EmbeddedTestServer::HandleRequestCallback CreateRedirectHandler( | |
| 527 const std::string& relative_url, | |
| 528 const GURL& target_url) { | |
| 529 return base::Bind( | |
| 530 &HandleRequestAndSendRedirectResponse, relative_url, target_url); | |
| 531 } | |
| 532 | |
| 533 // Request handler to be used with CreateBasicResponseHandler(). | |
| 534 scoped_ptr<net::test_server::HttpResponse> HandleRequestAndSendBasicResponse( | |
| 535 const std::string& relative_url, | |
| 536 const std::string& content_type, | |
| 537 const std::string& body, | |
| 538 const net::test_server::HttpRequest& request) { | |
| 539 scoped_ptr<net::test_server::BasicHttpResponse> response; | |
| 540 if (request.relative_url == relative_url) { | |
| 541 response.reset(new net::test_server::BasicHttpResponse); | |
| 542 response->set_content_type(content_type); | |
| 543 response->set_content(body); | |
| 544 } | |
| 545 return response.PassAs<net::test_server::HttpResponse>(); | |
| 546 } | |
| 547 | |
| 548 // Creates a request handler for an EmbeddedTestServer that response with an | |
| 549 // HTTP 200 status code, a Content-Type header and a body. | |
| 550 EmbeddedTestServer::HandleRequestCallback CreateBasicResponseHandler( | |
| 551 const std::string& relative_url, | |
| 552 const std::string& content_type, | |
| 553 const std::string& body) { | |
| 554 return base::Bind( | |
| 555 &HandleRequestAndSendBasicResponse, relative_url, content_type, body); | |
| 556 } | |
| 557 | |
| 506 } // namespace | 558 } // namespace |
| 507 | 559 |
| 508 class DownloadContentTest : public ContentBrowserTest { | 560 class DownloadContentTest : public ContentBrowserTest { |
| 509 protected: | 561 protected: |
| 510 // An initial send from a website of at least this size will not be | 562 // An initial send from a website of at least this size will not be |
| 511 // help up by buffering in the underlying downloads ByteStream data | 563 // help up by buffering in the underlying downloads ByteStream data |
| 512 // transfer. This is important because on resumption tests we wait | 564 // transfer. This is important because on resumption tests we wait |
| 513 // until we've gotten the data we expect before allowing the test server | 565 // until we've gotten the data we expect before allowing the test server |
| 514 // to send its reset, to get around hard close semantics on the Windows | 566 // to send its reset, to get around hard close semantics on the Windows |
| 515 // socket layer implementation. | 567 // socket layer implementation. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 bool EnsureNoPendingDownloads() { | 627 bool EnsureNoPendingDownloads() { |
| 576 bool result = true; | 628 bool result = true; |
| 577 BrowserThread::PostTask( | 629 BrowserThread::PostTask( |
| 578 BrowserThread::IO, FROM_HERE, | 630 BrowserThread::IO, FROM_HERE, |
| 579 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); | 631 base::Bind(&EnsureNoPendingDownloadJobsOnIO, &result)); |
| 580 base::MessageLoop::current()->Run(); | 632 base::MessageLoop::current()->Run(); |
| 581 return result && | 633 return result && |
| 582 (CountingDownloadFile::GetNumberActiveFilesFromFileThread() == 0); | 634 (CountingDownloadFile::GetNumberActiveFilesFromFileThread() == 0); |
| 583 } | 635 } |
| 584 | 636 |
| 585 void DownloadAndWait(Shell* shell, const GURL& url, | 637 void NavigateToURLAndWaitForDownload( |
| 586 DownloadItem::DownloadState expected_terminal_state) { | 638 Shell* shell, |
| 639 const GURL& url, | |
| 640 DownloadItem::DownloadState expected_terminal_state) { | |
| 587 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(shell, 1)); | 641 scoped_ptr<DownloadTestObserver> observer(CreateWaiter(shell, 1)); |
| 588 NavigateToURL(shell, url); | 642 NavigateToURL(shell, url); |
| 589 observer->WaitForFinished(); | 643 observer->WaitForFinished(); |
| 590 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(expected_terminal_state)); | 644 EXPECT_EQ(1u, observer->NumDownloadsSeenInState(expected_terminal_state)); |
| 591 } | 645 } |
| 592 | 646 |
| 593 // Checks that |path| is has |file_size| bytes, and matches the |value| | 647 // Checks that |path| is has |file_size| bytes, and matches the |value| |
| 594 // string. | 648 // string. |
| 595 bool VerifyFile(const base::FilePath& path, | 649 bool VerifyFile(const base::FilePath& path, |
| 596 const std::string& value, | 650 const std::string& value, |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 std::vector<DownloadItem*> downloads; | 793 std::vector<DownloadItem*> downloads; |
| 740 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 794 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 741 ASSERT_EQ(1u, downloads.size()); | 795 ASSERT_EQ(1u, downloads.size()); |
| 742 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); | 796 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); |
| 743 DownloadItem* download1 = downloads[0]; // The only download. | 797 DownloadItem* download1 = downloads[0]; // The only download. |
| 744 | 798 |
| 745 // Start the second download and wait until it's done. | 799 // Start the second download and wait until it's done. |
| 746 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); | 800 base::FilePath file(FILE_PATH_LITERAL("download-test.lib")); |
| 747 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); | 801 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); |
| 748 // Download the file and wait. | 802 // Download the file and wait. |
| 749 DownloadAndWait(shell(), url, DownloadItem::COMPLETE); | 803 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); |
| 750 | 804 |
| 751 // Should now have 2 items on the manager. | 805 // Should now have 2 items on the manager. |
| 752 downloads.clear(); | 806 downloads.clear(); |
| 753 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 807 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 754 ASSERT_EQ(2u, downloads.size()); | 808 ASSERT_EQ(2u, downloads.size()); |
| 755 // We don't know the order of the downloads. | 809 // We don't know the order of the downloads. |
| 756 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; | 810 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; |
| 757 | 811 |
| 758 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); | 812 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); |
| 759 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); | 813 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 793 const char kTestFileType[] = "abc"; | 847 const char kTestFileType[] = "abc"; |
| 794 | 848 |
| 795 WebPluginInfo plugin_info; | 849 WebPluginInfo plugin_info; |
| 796 plugin_info.name = base::ASCIIToUTF16(kTestPluginName); | 850 plugin_info.name = base::ASCIIToUTF16(kTestPluginName); |
| 797 plugin_info.mime_types.push_back( | 851 plugin_info.mime_types.push_back( |
| 798 WebPluginMimeType(kTestMimeType, kTestFileType, "")); | 852 WebPluginMimeType(kTestMimeType, kTestFileType, "")); |
| 799 PluginServiceImpl::GetInstance()->RegisterInternalPlugin(plugin_info, false); | 853 PluginServiceImpl::GetInstance()->RegisterInternalPlugin(plugin_info, false); |
| 800 | 854 |
| 801 // The following is served with a Content-Type of application/octet-stream. | 855 // The following is served with a Content-Type of application/octet-stream. |
| 802 GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kTestFilePath))); | 856 GURL url(URLRequestMockHTTPJob::GetMockUrl(base::FilePath(kTestFilePath))); |
| 803 DownloadAndWait(shell(), url, DownloadItem::COMPLETE); | 857 NavigateToURLAndWaitForDownload(shell(), url, DownloadItem::COMPLETE); |
| 804 } | 858 } |
| 805 #endif | 859 #endif |
| 806 | 860 |
| 807 // Try to cancel just before we release the download file, by delaying final | 861 // Try to cancel just before we release the download file, by delaying final |
| 808 // rename callback. | 862 // rename callback. |
| 809 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) { | 863 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelAtFinalRename) { |
| 810 // Setup new factory. | 864 // Setup new factory. |
| 811 DownloadFileWithDelayFactory* file_factory = | 865 DownloadFileWithDelayFactory* file_factory = |
| 812 new DownloadFileWithDelayFactory(); | 866 new DownloadFileWithDelayFactory(); |
| 813 DownloadManagerImpl* download_manager(DownloadManagerForShell(shell())); | 867 DownloadManagerImpl* download_manager(DownloadManagerForShell(shell())); |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1553 | 1607 |
| 1554 // The intermediate file should now be gone. | 1608 // The intermediate file should now be gone. |
| 1555 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1609 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1556 RunAllPendingInMessageLoop(); | 1610 RunAllPendingInMessageLoop(); |
| 1557 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1611 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1558 | 1612 |
| 1559 // Start the second download and wait until it's done. The test server is | 1613 // Start the second download and wait until it's done. The test server is |
| 1560 // single threaded. The response to this download request should follow the | 1614 // single threaded. The response to this download request should follow the |
| 1561 // response to the previous resumption request. | 1615 // response to the previous resumption request. |
| 1562 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); | 1616 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); |
| 1563 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE); | 1617 NavigateToURLAndWaitForDownload(shell(), url2, DownloadItem::COMPLETE); |
| 1564 | 1618 |
| 1565 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1619 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1566 } | 1620 } |
| 1567 | 1621 |
| 1568 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumingDownload) { | 1622 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CancelResumingDownload) { |
| 1569 SetupEnsureNoPendingDownloads(); | 1623 SetupEnsureNoPendingDownloads(); |
| 1570 CommandLine::ForCurrentProcess()->AppendSwitch( | 1624 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 1571 switches::kEnableDownloadResumption); | 1625 switches::kEnableDownloadResumption); |
| 1572 ASSERT_TRUE(test_server()->Start()); | 1626 ASSERT_TRUE(test_server()->Start()); |
| 1573 | 1627 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1601 // The intermediate file should now be gone. | 1655 // The intermediate file should now be gone. |
| 1602 RunAllPendingInMessageLoop(BrowserThread::FILE); | 1656 RunAllPendingInMessageLoop(BrowserThread::FILE); |
| 1603 RunAllPendingInMessageLoop(); | 1657 RunAllPendingInMessageLoop(); |
| 1604 EXPECT_FALSE(base::PathExists(intermediate_path)); | 1658 EXPECT_FALSE(base::PathExists(intermediate_path)); |
| 1605 EXPECT_TRUE(download->GetFullPath().empty()); | 1659 EXPECT_TRUE(download->GetFullPath().empty()); |
| 1606 | 1660 |
| 1607 // Start the second download and wait until it's done. The test server is | 1661 // Start the second download and wait until it's done. The test server is |
| 1608 // single threaded. The response to this download request should follow the | 1662 // single threaded. The response to this download request should follow the |
| 1609 // response to the previous resumption request. | 1663 // response to the previous resumption request. |
| 1610 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); | 1664 GURL url2(test_server()->GetURL("rangereset?size=100&rst_limit=0&token=x")); |
| 1611 DownloadAndWait(shell(), url2, DownloadItem::COMPLETE); | 1665 NavigateToURLAndWaitForDownload(shell(), url2, DownloadItem::COMPLETE); |
| 1612 | 1666 |
| 1613 EXPECT_TRUE(EnsureNoPendingDownloads()); | 1667 EXPECT_TRUE(EnsureNoPendingDownloads()); |
| 1614 } | 1668 } |
| 1615 | 1669 |
| 1616 // Check that the cookie policy is correctly updated when downloading a file | 1670 // Check that the cookie policy is correctly updated when downloading a file |
| 1617 // that redirects cross origin. | 1671 // that redirects cross origin. |
| 1618 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { | 1672 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { |
| 1619 ASSERT_TRUE(test_server()->Start()); | 1673 ASSERT_TRUE(test_server()->Start()); |
| 1620 net::HostPortPair host_port = test_server()->host_port_pair(); | 1674 net::HostPortPair host_port = test_server()->host_port_pair(); |
| 1621 DCHECK_EQ(host_port.host(), std::string("127.0.0.1")); | 1675 DCHECK_EQ(host_port.host(), std::string("127.0.0.1")); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1644 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 1698 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 1645 ASSERT_EQ(1u, downloads.size()); | 1699 ASSERT_EQ(1u, downloads.size()); |
| 1646 ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); | 1700 ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); |
| 1647 | 1701 |
| 1648 // Check that the cookies were correctly set. | 1702 // Check that the cookies were correctly set. |
| 1649 EXPECT_EQ("A=B", | 1703 EXPECT_EQ("A=B", |
| 1650 content::GetCookies(shell()->web_contents()->GetBrowserContext(), | 1704 content::GetCookies(shell()->web_contents()->GetBrowserContext(), |
| 1651 GURL(download))); | 1705 GURL(download))); |
| 1652 } | 1706 } |
| 1653 | 1707 |
| 1708 // A filename suggestion specified via a @download attribute should not be | |
| 1709 // effective if the final download URL is in another origin from the original | |
| 1710 // download URL. | |
| 1711 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | |
| 1712 DownloadAttributeCrossOriginRedirect) { | |
| 1713 EmbeddedTestServer origin_one; | |
| 1714 EmbeddedTestServer origin_two; | |
| 1715 ASSERT_TRUE(origin_one.InitializeAndWaitUntilReady()); | |
| 1716 ASSERT_TRUE(origin_two.InitializeAndWaitUntilReady()); | |
| 1717 | |
| 1718 // The download-attribute.html page contains an anchor element whose href is | |
| 1719 // set to the value of the query parameter (specified as |target| in the URL | |
| 1720 // below). The suggested filename for the anchor is 'suggested-filename'. When | |
| 1721 // the page is loaded, a script simulates a click on the anchor, triggering a | |
| 1722 // download of the target URL. | |
| 1723 // | |
| 1724 // We construct two test servers; origin_one and origin_two. Once started, the | |
| 1725 // server URLs will differ by the port number. Therefore they will be in | |
| 1726 // different origins. | |
| 1727 GURL download_url = origin_one.GetURL("/ping"); | |
| 1728 GURL referrer_url = origin_one.GetURL( | |
| 1729 std::string("/download-attribute.html?target=") + download_url.spec()); | |
| 1730 | |
| 1731 // <origin_one>/download-attribute.html initiates a download of | |
| 1732 // <origin_one>/ping, which redirects to <origin_two>/download. | |
| 1733 origin_one.ServeFilesFromDirectory(GetTestFilePath("download", "")); | |
| 1734 origin_one.RegisterRequestHandler( | |
| 1735 CreateRedirectHandler("/ping", origin_two.GetURL("/download"))); | |
| 1736 origin_two.RegisterRequestHandler(CreateBasicResponseHandler( | |
| 1737 "/download", "application/octet-stream", "Hello")); | |
| 1738 | |
| 1739 NavigateToURLAndWaitForDownload( | |
| 1740 shell(), referrer_url, DownloadItem::COMPLETE); | |
| 1741 | |
| 1742 std::vector<DownloadItem*> downloads; | |
| 1743 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | |
| 1744 ASSERT_EQ(1u, downloads.size()); | |
| 1745 | |
| 1746 EXPECT_EQ(FILE_PATH_LITERAL("download"), | |
|
Randy Smith (Not in Mondays)
2014/04/24 22:08:43
Suggestion: Comment that this is the key check, an
asanka
2014/04/25 22:08:07
Done.
| |
| 1747 downloads[0]->GetTargetFilePath().BaseName().value()); | |
| 1748 ASSERT_TRUE(origin_one.ShutdownAndWaitUntilComplete()); | |
| 1749 ASSERT_TRUE(origin_two.ShutdownAndWaitUntilComplete()); | |
| 1750 } | |
| 1751 | |
| 1752 // A filename suggestion specified via a @download attribute should be effective | |
| 1753 // if the final download URL is in the same origin as the initial download URL. | |
| 1754 // Test that this holds even if there are cross origin redirects in the middle | |
| 1755 // of the redirect chain. | |
| 1756 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | |
| 1757 DownloadAttributeSameOriginRedirect) { | |
| 1758 EmbeddedTestServer origin_one; | |
| 1759 EmbeddedTestServer origin_two; | |
| 1760 ASSERT_TRUE(origin_one.InitializeAndWaitUntilReady()); | |
| 1761 ASSERT_TRUE(origin_two.InitializeAndWaitUntilReady()); | |
| 1762 | |
| 1763 // The download-attribute.html page contains an anchor element whose href is | |
| 1764 // set to the value of the query parameter (specified as |target| in the URL | |
| 1765 // below). The suggested filename for the anchor is 'suggested-filename'. When | |
| 1766 // the page is loaded, a script simulates a click on the anchor, triggering a | |
| 1767 // download of the target URL. | |
| 1768 // | |
| 1769 // We construct two test servers; origin_one and origin_two. Once started, the | |
| 1770 // server URLs will differ by the port number. Therefore they will be in | |
| 1771 // different origins. | |
| 1772 GURL download_url = origin_one.GetURL("/ping"); | |
| 1773 GURL referrer_url = origin_one.GetURL( | |
| 1774 std::string("/download-attribute.html?target=") + download_url.spec()); | |
| 1775 origin_one.ServeFilesFromDirectory(GetTestFilePath("download", "")); | |
| 1776 | |
| 1777 // <origin_one>/download-attribute.html initiates a download of | |
| 1778 // <origin_one>/ping, which redirects to <origin_two>/pong, and then finally | |
| 1779 // to <origin_one>/download. | |
| 1780 origin_one.RegisterRequestHandler( | |
| 1781 CreateRedirectHandler("/ping", origin_two.GetURL("/pong"))); | |
| 1782 origin_two.RegisterRequestHandler( | |
| 1783 CreateRedirectHandler("/pong", origin_one.GetURL("/download"))); | |
| 1784 origin_one.RegisterRequestHandler(CreateBasicResponseHandler( | |
| 1785 "/download", "application/octet-stream", "Hello")); | |
| 1786 | |
| 1787 NavigateToURLAndWaitForDownload( | |
| 1788 shell(), referrer_url, DownloadItem::COMPLETE); | |
| 1789 | |
| 1790 std::vector<DownloadItem*> downloads; | |
| 1791 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | |
| 1792 ASSERT_EQ(1u, downloads.size()); | |
| 1793 | |
| 1794 EXPECT_EQ(FILE_PATH_LITERAL("suggested-filename"), | |
| 1795 downloads[0]->GetTargetFilePath().BaseName().value()); | |
| 1796 ASSERT_TRUE(origin_one.ShutdownAndWaitUntilComplete()); | |
| 1797 ASSERT_TRUE(origin_two.ShutdownAndWaitUntilComplete()); | |
| 1798 } | |
| 1799 | |
| 1654 } // namespace content | 1800 } // namespace content |
| OLD | NEW |