test: add a test for non-navigation downloads (#1895)
This commit is contained in:
parent
47c384112c
commit
5d986317cf
|
|
@ -51,6 +51,25 @@ describe('Download', function() {
|
||||||
expect(fs.readFileSync(path).toString()).toBe('Hello world');
|
expect(fs.readFileSync(path).toString()).toBe('Hello world');
|
||||||
await page.close();
|
await page.close();
|
||||||
});
|
});
|
||||||
|
it.fail(WEBKIT)('should report non-navigation downloads', async({browser, server}) => {
|
||||||
|
// Our WebKit embedder does not download in this case.
|
||||||
|
server.setRoute('/download', (req, res) => {
|
||||||
|
res.setHeader('Content-Type', 'application/octet-stream');
|
||||||
|
res.end(`Hello world`);
|
||||||
|
});
|
||||||
|
|
||||||
|
const page = await browser.newPage({ acceptDownloads: true });
|
||||||
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
await page.setContent(`<a download="file.txt" href="${server.PREFIX}/download">download</a>`);
|
||||||
|
const [ download ] = await Promise.all([
|
||||||
|
page.waitForEvent('download'),
|
||||||
|
page.click('a')
|
||||||
|
]);
|
||||||
|
const path = await download.path();
|
||||||
|
expect(fs.existsSync(path)).toBeTruthy();
|
||||||
|
expect(fs.readFileSync(path).toString()).toBe('Hello world');
|
||||||
|
await page.close();
|
||||||
|
});
|
||||||
it('should delete file', async({browser, server}) => {
|
it('should delete file', async({browser, server}) => {
|
||||||
const page = await browser.newPage({ acceptDownloads: true });
|
const page = await browser.newPage({ acceptDownloads: true });
|
||||||
await page.setContent(`<a download=true href="${server.PREFIX}/download">download</a>`);
|
await page.setContent(`<a download=true href="${server.PREFIX}/download">download</a>`);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue