mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(browserContext): make a copy of passed options object (#370)
This commit is contained in:
parent
62888d8543
commit
cf6f04893c
6
index.d.ts
vendored
6
index.d.ts
vendored
@ -2,6 +2,6 @@
|
|||||||
// Licensed under the MIT license.
|
// Licensed under the MIT license.
|
||||||
|
|
||||||
export * from './lib/api';
|
export * from './lib/api';
|
||||||
export function playwright(browser: 'chromium'): import('./lib/api').Chromium;
|
export function playwright(browser: 'chromium'): import('./lib/api').ChromiumPlaywright;
|
||||||
export function playwright(browser: 'firefox'): import('./lib/api').Firefox;
|
export function playwright(browser: 'firefox'): import('./lib/api').FirefoxPlaywright;
|
||||||
export function playwright(browser: 'webkit'): import('./lib/api').WebKit;
|
export function playwright(browser: 'webkit'): import('./lib/api').WebKitPlaywright;
|
||||||
|
@ -53,9 +53,13 @@ export class BrowserContext {
|
|||||||
|
|
||||||
constructor(delegate: BrowserContextDelegate, options: BrowserContextOptions) {
|
constructor(delegate: BrowserContextDelegate, options: BrowserContextOptions) {
|
||||||
this._delegate = delegate;
|
this._delegate = delegate;
|
||||||
this._options = options;
|
this._options = { ...options };
|
||||||
if (!options.viewport && options.viewport !== null)
|
if (!this._options.viewport && this._options.viewport !== null)
|
||||||
options.viewport = { width: 800, height: 600 };
|
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<Page[]> {
|
async pages(): Promise<Page[]> {
|
||||||
|
@ -193,7 +193,7 @@ module.exports.describe = function({testRunner, expect, FFOX, CHROME, WEBKIT}) {
|
|||||||
expect(await page.accessibility.snapshot()).toEqual(golden);
|
expect(await page.accessibility.snapshot()).toEqual(golden);
|
||||||
});
|
});
|
||||||
// WebKit rich text accessibility is iffy
|
// 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(`
|
await page.setContent(`
|
||||||
<div contenteditable="true">
|
<div contenteditable="true">
|
||||||
Edit this image: <img src="fakeimage.png" alt="my fake image">
|
Edit this image: <img src="fakeimage.png" alt="my fake image">
|
||||||
|
@ -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.innerWidth')).toBe(456);
|
||||||
expect(await page.evaluate('window.innerHeight')).toBe(789);
|
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() {
|
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');
|
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() {
|
describe('BrowserContext({bypassCSP})', function() {
|
||||||
|
@ -44,6 +44,12 @@ module.exports.describe = function ({ testRunner, expect, FFOX }) {
|
|||||||
}
|
}
|
||||||
expect(error.message).toContain('Invalid longitude "200"');
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user