diff --git a/index.d.ts b/index.d.ts index f05630a9e4..6e42281a77 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,6 +2,6 @@ // Licensed under the MIT license. export * from './lib/api'; -export function playwright(browser: 'chromium'): import('./lib/api').Chromium; -export function playwright(browser: 'firefox'): import('./lib/api').Firefox; -export function playwright(browser: 'webkit'): import('./lib/api').WebKit; +export function playwright(browser: 'chromium'): import('./lib/api').ChromiumPlaywright; +export function playwright(browser: 'firefox'): import('./lib/api').FirefoxPlaywright; +export function playwright(browser: 'webkit'): import('./lib/api').WebKitPlaywright; diff --git a/src/browserContext.ts b/src/browserContext.ts index 48dad9fee3..386624c229 100644 --- a/src/browserContext.ts +++ b/src/browserContext.ts @@ -53,9 +53,13 @@ export class BrowserContext { constructor(delegate: BrowserContextDelegate, options: BrowserContextOptions) { this._delegate = delegate; - this._options = options; - if (!options.viewport && options.viewport !== null) - options.viewport = { width: 800, height: 600 }; + this._options = { ...options }; + if (!this._options.viewport && this._options.viewport !== null) + this._options.viewport = { width: 800, height: 600 }; + if (this._options.viewport) + this._options.viewport = { ...this._options.viewport }; + if (this._options.geolocation) + this._options.geolocation = { ...this._options.geolocation }; } async pages(): Promise { diff --git a/test/accessibility.spec.js b/test/accessibility.spec.js index 17923058b1..6e07115dfc 100644 --- a/test/accessibility.spec.js +++ b/test/accessibility.spec.js @@ -193,7 +193,7 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROME, WEBKIT}) { expect(await page.accessibility.snapshot()).toEqual(golden); }); // WebKit rich text accessibility is iffy - !WEBKIT && fit('rich text editable fields should have children', async function({page}) { + !WEBKIT && it('rich text editable fields should have children', async function({page}) { await page.setContent(`
Edit this image: my fake image diff --git a/test/browsercontext.spec.js b/test/browsercontext.spec.js index 17b8236e1c..f7675b4554 100644 --- a/test/browsercontext.spec.js +++ b/test/browsercontext.spec.js @@ -131,6 +131,16 @@ module.exports.describe = function({testRunner, expect, playwright, CHROME, WEBK expect(await page.evaluate('window.innerWidth')).toBe(456); expect(await page.evaluate('window.innerHeight')).toBe(789); }); + it('should make a copy of default viewport', async({ newContext }) => { + const viewport = { width: 456, height: 789 }; + const context = await newContext({ viewport }); + viewport.width = 567; + const page = await context.newPage(); + expect(page.viewport().width).toBe(456); + expect(page.viewport().height).toBe(789); + expect(await page.evaluate('window.innerWidth')).toBe(456); + expect(await page.evaluate('window.innerHeight')).toBe(789); + }); }); describe('BrowserContext({setUserAgent})', function() { @@ -174,6 +184,17 @@ module.exports.describe = function({testRunner, expect, playwright, CHROME, WEBK expect(await page.evaluate(() => navigator.userAgent)).toContain('iPhone'); } }); + it('should make a copy of default options', async({newContext, server}) => { + const options = { userAgent: 'foobar' }; + const context = await newContext(options); + options.userAgent = 'wrong'; + const page = await context.newPage(); + const [request] = await Promise.all([ + server.waitForRequest('/empty.html'), + page.goto(server.EMPTY_PAGE), + ]); + expect(request.headers['user-agent']).toBe('foobar'); + }); }); describe('BrowserContext({bypassCSP})', function() { diff --git a/test/geolocation.spec.js b/test/geolocation.spec.js index f978d85e5d..a7fc0758e2 100644 --- a/test/geolocation.spec.js +++ b/test/geolocation.spec.js @@ -44,6 +44,12 @@ module.exports.describe = function ({ testRunner, expect, FFOX }) { } expect(error.message).toContain('Invalid longitude "200"'); }); + it('should not modify passed default options object', async({newContext}) => { + const geolocation = { longitude: 10, latitude: 10 }; + const options = { geolocation }; + const context = await newContext(options); + await context.setGeolocation({ longitude: 20, latitude: 20 }); + expect(options.geolocation).toBe(geolocation); + }); }); - };