Commit 9b526a95 authored by asanka's avatar asanka Committed by Commit bot

[Downloads] Add a browser test for <a download> with cross origin iframe.

R=brettw@chromium.org
BUG=596283
CQ_INCLUDE_TRYBOTS=tryserver.chromium.linux:linux_site_isolation

Review-Url: https://codereview.chromium.org/2131423003
Cr-Commit-Position: refs/heads/master@{#405150}
parent f397acb8
......@@ -575,6 +575,10 @@ class DownloadContentTest : public ContentBrowserTest {
make_scoped_refptr(content::BrowserThread::GetBlockingPool())));
}
void SetUpCommandLine(base::CommandLine* commnad_line) override {
IsolateAllSitesForTesting(commnad_line);
}
TestShellDownloadManagerDelegate* GetDownloadManagerDelegate() {
return test_delegate_.get();
}
......@@ -2479,4 +2483,43 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, DuplicateContentDisposition) {
downloads[0]->GetTargetFilePath().BaseName().value());
}
IN_PROC_BROWSER_TEST_F(DownloadContentTest, DownloadAttributeSameOriginIFrame) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL frame_url = embedded_test_server()->GetURL(
"/download/download-attribute.html?target=/download/download-test.lib");
GURL document_url = embedded_test_server()->GetURL(
"/download/iframe-host.html?target=" + frame_url.spec());
DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url);
WaitForCompletion(download);
EXPECT_STREQ(FILE_PATH_LITERAL("suggested-filename"),
download->GetTargetFilePath().BaseName().value().c_str());
}
IN_PROC_BROWSER_TEST_F(DownloadContentTest,
DownloadAttributeCrossOriginIFrame) {
net::EmbeddedTestServer origin_one;
net::EmbeddedTestServer origin_two;
ASSERT_TRUE(origin_one.Start());
ASSERT_TRUE(origin_two.Start());
origin_one.ServeFilesFromDirectory(GetTestFilePath("download", ""));
origin_two.ServeFilesFromDirectory(GetTestFilePath("download", ""));
GURL frame_url =
origin_one.GetURL("/download-attribute.html?target=" +
origin_two.GetURL("/download-test.lib").spec());
GURL::Replacements replacements;
replacements.SetHostStr("localhost");
frame_url = frame_url.ReplaceComponents(replacements);
GURL document_url =
origin_two.GetURL("/iframe-host.html?target=" + frame_url.spec());
DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url);
WaitForCompletion(download);
EXPECT_STREQ(FILE_PATH_LITERAL("download-test.lib"),
download->GetTargetFilePath().BaseName().value().c_str());
}
} // namespace content
<!DOCTYPE html>
<html>
<body>
<iframe id="frame"></iframe>
<script>
var iframeElement = document.querySelector('#frame');
url = window.location.href;
iframeElement.src = url.substr(url.indexOf('=') + 1);
</script>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment