From ff8494c7e3a1abc47af322c30de23e71ddafae14 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Mon, 1 Nov 2021 17:45:22 +0100 Subject: [PATCH] test: add test for downloads in nested downloads (#9924) --- tests/download.spec.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/download.spec.ts b/tests/download.spec.ts index f8e7abaa10..5271dacfb3 100644 --- a/tests/download.spec.ts +++ b/tests/download.spec.ts @@ -568,6 +568,36 @@ it.describe('download event', () => { expect(fs.readFileSync(path).toString()).toBe('Hello world'); await page.close(); }); + + it('should emit download event from nested iframes', async ({ server, browser, browserName }, testInfo) => { + it.fixme(browserName === 'firefox', 'https://github.com/microsoft/playwright/issues/9922'); + const page = await browser.newPage({ acceptDownloads: true }); + server.setRoute('/1', (req, res) => { + res.setHeader('Content-Type', 'text/html'); + res.end(``); + }); + server.setRoute('/2', (req, res) => { + res.setHeader('Content-Type', 'text/html'); + res.end(``); + }); + server.setRoute('/3', (req, res) => { + res.setHeader('Content-Type', 'text/html'); + res.end(` download`); + }); + await page.goto(server.PREFIX + '/1'); + + const [download] = await Promise.all([ + page.waitForEvent('download'), + page.frame({ + url: server.PREFIX + '/3' + }).click('text=download') + ]); + const userPath = testInfo.outputPath('download.txt'); + await download.saveAs(userPath); + expect(fs.existsSync(userPath)).toBeTruthy(); + expect(fs.readFileSync(userPath).toString()).toBe('Hello world'); + await page.close(); + }); }); it('should be able to download a PDF file', async ({ browser, server, asset }) => {