Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests(downloads): add a test for Blob downloads (#1936) #1939

Merged
merged 3 commits into from
Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/assets/download-blob.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<!DOCTYPE html>
<html>
<head>
<title>Blob Download Example</title>
</head>
<body>
<script>
const download = (data, filename) => {
const a = document.createElement("a");
a.style = "display: none";
document.body.appendChild(a);
a.style = "display: none";

const blob = new Blob([data], { type: "octet/stream" });
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
};

const downloadIt = () => {
download("Hello world", "example.txt");
}
</script>
<a onclick="javascipt:downloadIt();">Download</a>
</body>
</html>
15 changes: 14 additions & 1 deletion test/download.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('Download', function() {
expect(fs.readFileSync(path).toString()).toBe('Hello world');
await page.close();
});
it(`should report download path within page.on('download', …) handler`, async({browser, server}) => {
it(`should report download path within page.on('download', …) handler for Files`, async({browser, server}) => {
const page = await browser.newPage({ acceptDownloads: true });
const onDownloadPathPath = new Promise((res) => {
page.on('download', dl => {
Expand All @@ -83,6 +83,19 @@ describe('Download', function() {
expect(fs.readFileSync(path).toString()).toBe('Hello world');
await page.close();
})
it(`should report download path within page.on('download', …) handler for Blobs`, async({browser, server}) => {
rwoll marked this conversation as resolved.
Show resolved Hide resolved
const page = await browser.newPage({ acceptDownloads: true });
const onDownloadPathPath = new Promise((res) => {
rwoll marked this conversation as resolved.
Show resolved Hide resolved
page.on('download', dl => {
dl.path().then(res);
});
});
await page.goto(server.PREFIX + '/download-blob.html');
await page.click('a');
const path = await onDownloadPathPath;
expect(fs.readFileSync(path).toString()).toBe('Hello world');
await page.close();
})
it.skip(FFOX).fail(CHROMIUM || WEBKIT)('should report alt-click downloads', async({browser, server}) => {
// Firefox does not download on alt-click by default.
// Our WebKit embedder does not download on alt-click, although Safari does.
Expand Down