diff --git a/tests/library/browsercontext-network-event.spec.ts b/tests/library/browsercontext-network-event.spec.ts index 14684d82c0820..45d42c41bfb16 100644 --- a/tests/library/browsercontext-network-event.spec.ts +++ b/tests/library/browsercontext-network-event.spec.ts @@ -144,3 +144,23 @@ it('should not fire events for favicon or favicon redirects', async ({ context, expect(events).not.toEqual(expect.arrayContaining([expect.stringContaining(favicon)])); expect(events).not.toEqual(expect.arrayContaining([expect.stringContaining(hashedFaviconUrl)])); }); + +it('should reject response.finished if context closes', async ({ page, server }) => { + await page.goto(server.EMPTY_PAGE); + server.setRoute('/get', (req, res) => { + // In Firefox, |fetch| will be hanging until it receives |Content-Type| header + // from server. + res.setHeader('Content-Type', 'text/plain; charset=utf-8'); + res.write('hello '); + }); + // send request and wait for server response + const [pageResponse] = await Promise.all([ + page.waitForEvent('response'), + page.evaluate(() => fetch('./get', { method: 'GET' })), + ]); + + const finishPromise = pageResponse.finished().catch(e => e); + await page.context().close(); + const error = await finishPromise; + expect(error.message).toContain('closed'); +}); diff --git a/tests/library/fetch-proxy.spec.ts b/tests/library/fetch-proxy.spec.ts index 3b43b5c3a3b30..149bd2f2b1258 100644 --- a/tests/library/fetch-proxy.spec.ts +++ b/tests/library/fetch-proxy.spec.ts @@ -20,14 +20,15 @@ it.skip(({ mode }) => mode !== 'default'); it('context request should pick up proxy credentials', async ({ browserType, server, proxyServer }) => { proxyServer.forwardTo(server.PORT, { allowConnectRequests: true }); - let auth; - proxyServer.setAuthHandler(req => { - const header = req.headers['proxy-authorization']; - // Browser can issue various unrelated requests over the proxy, - // but we are only interested in our own request. - if (proxyServer.connectHosts.includes('non-existent.com:80')) - auth = header; - return !!header; + const authPromise = new Promise(resolve => { + proxyServer.setAuthHandler(req => { + const header = req.headers['proxy-authorization']; + // Browser can issue various unrelated requests over the proxy, + // but we are only interested in our own request. + if (proxyServer.connectHosts.includes('non-existent.com:80')) + resolve(header); + return !!header; + }); }); const browser = await browserType.launch({ proxy: { server: `localhost:${proxyServer.PORT}`, username: 'user', password: 'secret' } @@ -35,6 +36,7 @@ it('context request should pick up proxy credentials', async ({ browserType, ser const context = await browser.newContext(); const response = await context.request.get('http://non-existent.com/simple.json'); expect(proxyServer.connectHosts).toContain('non-existent.com:80'); + const auth = await authPromise; expect(auth).toBe('Basic ' + Buffer.from('user:secret').toString('base64')); expect(await response.json()).toEqual({ foo: 'bar' }); await browser.close(); diff --git a/tests/page/page-network-response.spec.ts b/tests/page/page-network-response.spec.ts index 41d7178208e5a..1224713b2cfc4 100644 --- a/tests/page/page-network-response.spec.ts +++ b/tests/page/page-network-response.spec.ts @@ -129,26 +129,6 @@ it('should reject response.finished if page closes', async ({ page, server }) => expect(error.message).toContain('closed'); }); -it('should reject response.finished if context closes', async ({ page, server }) => { - await page.goto(server.EMPTY_PAGE); - server.setRoute('/get', (req, res) => { - // In Firefox, |fetch| will be hanging until it receives |Content-Type| header - // from server. - res.setHeader('Content-Type', 'text/plain; charset=utf-8'); - res.write('hello '); - }); - // send request and wait for server response - const [pageResponse] = await Promise.all([ - page.waitForEvent('response'), - page.evaluate(() => fetch('./get', { method: 'GET' })), - ]); - - const finishPromise = pageResponse.finished().catch(e => e); - await page.context().close(); - const error = await finishPromise; - expect(error.message).toContain('closed'); -}); - it('should return json', async ({ page, server }) => { const response = await page.goto(server.PREFIX + '/simple.json'); expect(await response.json()).toEqual({ foo: 'bar' });