Skip to content

Commit

Permalink
fix(downloads): fix acceptDownloads complaint (microsoft#1777)
Browse files Browse the repository at this point in the history
This patch fixes `download.path()` throwing an error that
`acceptDownloads` is not set when using a download within a `page.on`
handler even when `acceptDownloads` had been set to `true`;

Fixes microsoft#1777
  • Loading branch information
rwoll committed Apr 22, 2020
1 parent fbc52e7 commit f3a99ab
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ export class Download {
this._finishedPromise = new Promise(f => this._finishedCallback = f);
for (const barrier of this._page._frameManager._signalBarriers)
barrier.addDownload();
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
3 changes: 2 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();
});
fit(`should report download path within page.on('download', …) handler`, async({browser, server}) => {
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, rej) => {
setTimeout(() => { rej('failed to find path quickly'); }, 1000);
Expand All @@ -83,6 +83,7 @@ describe('Download', function() {
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.
Expand Down

0 comments on commit f3a99ab

Please sign in to comment.