Skip to content

Commit

Permalink
fix(downloads): fix acceptDownloads complaint (#1777) (#1923)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwoll committed Apr 23, 2020
1 parent 00e8d88 commit 53c78a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ export class Download {
this._url = url;
this._finishedCallback = () => {};
this._finishedPromise = new Promise(f => this._finishedCallback = f);
this._page.emit(Events.Page.Download, this);
page._browserContext._downloads.add(this);
this._acceptDownloads = !!this._page._browserContext._options.acceptDownloads;
this._page.emit(Events.Page.Download, this);
}

url(): string {
Expand Down
13 changes: 13 additions & 0 deletions test/download.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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`, async({browser, server}) => {
const page = await browser.newPage({ acceptDownloads: true });
const onDownloadPathPath = new Promise((res) => {
page.on('download', dl => {
dl.path().then(res);
});
});
await page.setContent(`<a href="${server.PREFIX}/download">download</a>`);
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

0 comments on commit 53c78a8

Please sign in to comment.