From 1725b70cf85c2daebcb0f478f7034d3ee7298ac9 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 5 Mar 2020 12:30:31 -0800 Subject: [PATCH 1/3] fix(chromium): do not create default page and context in headless --- src/server/chromium.ts | 10 ++++--- test/chromium/browsercontext.spec.js | 40 ++++++++++++++++++++++++++++ test/playwright.spec.js | 4 +++ 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 test/chromium/browsercontext.spec.js diff --git a/src/server/chromium.ts b/src/server/chromium.ts index 7f6f0423bbcc2..2701cc50506e1 100644 --- a/src/server/chromium.ts +++ b/src/server/chromium.ts @@ -197,11 +197,13 @@ export class Chromium implements BrowserType { '--mute-audio' ); } - if (launchType !== 'persistent') + if (launchType === 'persistent') { + chromeArguments.push(...args); + if (args.every(arg => arg.startsWith('-'))) + chromeArguments.push('about:blank'); + } else { chromeArguments.push('--no-startup-window'); - chromeArguments.push(...args); - if (args.every(arg => arg.startsWith('-'))) - chromeArguments.push('about:blank'); + } return chromeArguments; } diff --git a/test/chromium/browsercontext.spec.js b/test/chromium/browsercontext.spec.js new file mode 100644 index 0000000000000..67d7dc86f0975 --- /dev/null +++ b/test/chromium/browsercontext.spec.js @@ -0,0 +1,40 @@ +/** + * Copyright (c) Microsoft Corporation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @type {BrowserTestSuite} + */ +module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FFOX, WEBKIT}) { + const {describe, xdescribe, fdescribe} = testRunner; + const {it, fit, xit, dit} = testRunner; + const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; + + describe('BrowserContext', function() { + it('should not create pages automatically', async function({browser}) { + const browserSession = await browser.createBrowserSession(); + const targets = []; + browserSession.on('Target.targetCreated', async ({targetInfo}) => { + if (targetInfo.type !== 'browser') + targets.push(targetInfo); + }); + await browserSession.send('Target.setDiscoverTargets', { discover: true }); + const context = await browser.newContext(); + await context.close(); + await browserSession.detach(); + expect(targets.length).toBe(0); + }); + }); +}; diff --git a/test/playwright.spec.js b/test/playwright.spec.js index cc5ac30273260..277412ef1ea5c 100644 --- a/test/playwright.spec.js +++ b/test/playwright.spec.js @@ -200,6 +200,10 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => { testRunner.loadTests(require('./ignorehttpserrors.spec.js'), testOptions); testRunner.loadTests(require('./popup.spec.js'), testOptions); }); + + describe.skip(!CHROMIUM)('[Chromium]', () => { + testRunner.loadTests(require('./chromium/browsercontext.spec.js'), testOptions); + }); }); // Top-level tests that launch Browser themselves. From 92c88d13f745ede5ae4f49ac82be317085ed4344 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 5 Mar 2020 13:16:33 -0800 Subject: [PATCH 2/3] Keep adding args --- src/server/chromium.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/server/chromium.ts b/src/server/chromium.ts index 2701cc50506e1..e74dc6b7868dd 100644 --- a/src/server/chromium.ts +++ b/src/server/chromium.ts @@ -197,8 +197,8 @@ export class Chromium implements BrowserType { '--mute-audio' ); } + chromeArguments.push(...args); if (launchType === 'persistent') { - chromeArguments.push(...args); if (args.every(arg => arg.startsWith('-'))) chromeArguments.push('about:blank'); } else { From 1bfeb46cb75f5c1b554e54b255252fd8b5c2a6dc Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 5 Mar 2020 14:38:25 -0800 Subject: [PATCH 3/3] Move test to launcer.spec.js --- test/chromium/browsercontext.spec.js | 40 ---------------------------- test/chromium/launcher.spec.js | 16 +++++++++++ test/playwright.spec.js | 4 --- 3 files changed, 16 insertions(+), 44 deletions(-) delete mode 100644 test/chromium/browsercontext.spec.js diff --git a/test/chromium/browsercontext.spec.js b/test/chromium/browsercontext.spec.js deleted file mode 100644 index 67d7dc86f0975..0000000000000 --- a/test/chromium/browsercontext.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright (c) Microsoft Corporation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @type {BrowserTestSuite} - */ -module.exports.describe = function({testRunner, expect, playwright, CHROMIUM, FFOX, WEBKIT}) { - const {describe, xdescribe, fdescribe} = testRunner; - const {it, fit, xit, dit} = testRunner; - const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; - - describe('BrowserContext', function() { - it('should not create pages automatically', async function({browser}) { - const browserSession = await browser.createBrowserSession(); - const targets = []; - browserSession.on('Target.targetCreated', async ({targetInfo}) => { - if (targetInfo.type !== 'browser') - targets.push(targetInfo); - }); - await browserSession.send('Target.setDiscoverTargets', { discover: true }); - const context = await browser.newContext(); - await context.close(); - await browserSession.detach(); - expect(targets.length).toBe(0); - }); - }); -}; diff --git a/test/chromium/launcher.spec.js b/test/chromium/launcher.spec.js index bc75ec5dabc10..0137b1210b481 100644 --- a/test/chromium/launcher.spec.js +++ b/test/chromium/launcher.spec.js @@ -120,4 +120,20 @@ module.exports.describe = function({testRunner, expect, defaultBrowserOptions, p await rmAsync(downloadsFolder); }); }); + + describe('BrowserContext', function() { + it('should not create pages automatically', async function() { + const browser = await playwright.launch(); + const browserSession = await browser.createBrowserSession(); + const targets = []; + browserSession.on('Target.targetCreated', async ({targetInfo}) => { + if (targetInfo.type !== 'browser') + targets.push(targetInfo); + }); + await browserSession.send('Target.setDiscoverTargets', { discover: true }); + await browser.newContext(); + await browser.close(); + expect(targets.length).toBe(0); + }); + }); }; diff --git a/test/playwright.spec.js b/test/playwright.spec.js index 277412ef1ea5c..cc5ac30273260 100644 --- a/test/playwright.spec.js +++ b/test/playwright.spec.js @@ -200,10 +200,6 @@ module.exports.describe = ({testRunner, product, playwrightPath}) => { testRunner.loadTests(require('./ignorehttpserrors.spec.js'), testOptions); testRunner.loadTests(require('./popup.spec.js'), testOptions); }); - - describe.skip(!CHROMIUM)('[Chromium]', () => { - testRunner.loadTests(require('./chromium/browsercontext.spec.js'), testOptions); - }); }); // Top-level tests that launch Browser themselves.