From 3541b894f5d4f1b9496344dd04e9f717b10a503d Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Mon, 25 Feb 2019 12:51:06 -0800 Subject: [PATCH] test: split out all chromium-specific tests into chromiumonly.spec.js (#4068) --- test/browser.spec.js | 24 ++++++++- test/chromiumonly.spec.js | 110 +++++++++++++++++++++++++++++++++----- test/firefoxonly.spec.js | 39 -------------- test/launcher.spec.js | 79 --------------------------- test/network.spec.js | 19 ------- test/puppeteer.spec.js | 7 +-- 6 files changed, 125 insertions(+), 153 deletions(-) delete mode 100644 test/firefoxonly.spec.js diff --git a/test/browser.spec.js b/test/browser.spec.js index e49b3785992..c821c34b9c0 100644 --- a/test/browser.spec.js +++ b/test/browser.spec.js @@ -14,11 +14,33 @@ * limitations under the License. */ -module.exports.addTests = function({testRunner, expect, headless, puppeteer}) { +module.exports.addTests = function({testRunner, expect, headless, puppeteer, CHROME}) { const {describe, xdescribe, fdescribe} = testRunner; const {it, fit, xit, it_fails_ffox} = testRunner; const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; + describe('Browser.version', function() { + it('should return whether we are in headless', async({browser}) => { + const version = await browser.version(); + expect(version.length).toBeGreaterThan(0); + if (CHROME) + expect(version.startsWith('Headless')).toBe(headless); + else + expect(version.startsWith('Firefox/')).toBe(true); + }); + }); + + describe('Browser.userAgent', function() { + it('should include WebKit', async({browser}) => { + const userAgent = await browser.userAgent(); + expect(userAgent.length).toBeGreaterThan(0); + if (CHROME) + expect(userAgent).toContain('WebKit'); + else + expect(userAgent).toContain('Gecko'); + }); + }); + describe('Browser.target', function() { it('should return browser target', async({browser}) => { const target = browser.target(); diff --git a/test/chromiumonly.spec.js b/test/chromiumonly.spec.js index d47f1fd69b6..cd3a5ccd8c4 100644 --- a/test/chromiumonly.spec.js +++ b/test/chromiumonly.spec.js @@ -13,27 +13,113 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -module.exports.addTests = function({testRunner, expect, product, headless}) { + +module.exports.addLauncherTests = function({testRunner, expect, defaultBrowserOptions, puppeteer}) { const {describe, xdescribe, fdescribe} = testRunner; const {it, fit, xit} = testRunner; const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; - describe('Chromium-specific tests', function() { - describe('Browser.version', function() { - it('should return whether we are in headless', async({browser}) => { - const version = await browser.version(); - expect(version.length).toBeGreaterThan(0); - expect(version.startsWith('Headless')).toBe(headless); + describe('Chromium-Specific Launcher tests', function() { + describe('Puppeteer.launch |browserURL| option', function() { + it('should be able to connect using browserUrl, with and without trailing slash', async({server}) => { + const originalBrowser = await puppeteer.launch(Object.assign({}, defaultBrowserOptions, { + args: ['--remote-debugging-port=21222'] + })); + const browserURL = 'http://127.0.0.1:21222'; + + const browser1 = await puppeteer.connect({browserURL}); + const page1 = await browser1.newPage(); + expect(await page1.evaluate(() => 7 * 8)).toBe(56); + browser1.disconnect(); + + const browser2 = await puppeteer.connect({browserURL: browserURL + '/'}); + const page2 = await browser2.newPage(); + expect(await page2.evaluate(() => 8 * 7)).toBe(56); + browser2.disconnect(); + originalBrowser.close(); + }); + it('should throw when using both browserWSEndpoint and browserURL', async({server}) => { + const originalBrowser = await puppeteer.launch(Object.assign({}, defaultBrowserOptions, { + args: ['--remote-debugging-port=21222'] + })); + const browserURL = 'http://127.0.0.1:21222'; + + let error = null; + await puppeteer.connect({browserURL, browserWSEndpoint: originalBrowser.wsEndpoint()}).catch(e => error = e); + expect(error.message).toContain('Exactly one of browserWSEndpoint, browserURL or transport'); + + originalBrowser.close(); + }); + it('should throw when trying to connect to non-existing browser', async({server}) => { + const originalBrowser = await puppeteer.launch(Object.assign({}, defaultBrowserOptions, { + args: ['--remote-debugging-port=21222'] + })); + const browserURL = 'http://127.0.0.1:32333'; + + let error = null; + await puppeteer.connect({browserURL}).catch(e => error = e); + expect(error.message).toContain('Failed to fetch browser webSocket url from'); + originalBrowser.close(); }); }); - describe('Browser.userAgent', function() { - it('should include WebKit', async({browser}) => { - const userAgent = await browser.userAgent(); - expect(userAgent.length).toBeGreaterThan(0); - expect(userAgent).toContain('WebKit'); + describe('Puppeteer.launch |pipe| option', function() { + it('should support the pipe option', async() => { + const options = Object.assign({pipe: true}, defaultBrowserOptions); + const browser = await puppeteer.launch(options); + expect((await browser.pages()).length).toBe(1); + expect(browser.wsEndpoint()).toBe(''); + const page = await browser.newPage(); + expect(await page.evaluate('11 * 11')).toBe(121); + await page.close(); + await browser.close(); + }); + it('should support the pipe argument', async() => { + const options = Object.assign({}, defaultBrowserOptions); + options.args = ['--remote-debugging-pipe'].concat(options.args || []); + const browser = await puppeteer.launch(options); + expect(browser.wsEndpoint()).toBe(''); + const page = await browser.newPage(); + expect(await page.evaluate('11 * 11')).toBe(121); + await page.close(); + await browser.close(); + }); + it('should fire "disconnected" when closing with pipe', async() => { + const options = Object.assign({pipe: true}, defaultBrowserOptions); + const browser = await puppeteer.launch(options); + const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve)); + // Emulate user exiting browser. + browser.process().kill(); + await disconnectedEventPromise; }); }); }); }; +module.exports.addPageTests = function({testRunner, expect}) { + const {describe, xdescribe, fdescribe} = testRunner; + const {it, fit, xit} = testRunner; + const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; + + describe('Chromium-Specific Page Tests', function() { + it('Page.setRequestInterception should work with intervention headers', async({server, page}) => { + server.setRoute('/intervention', (req, res) => res.end(` + + `)); + server.setRedirect('/intervention.js', '/redirect.js'); + let serverRequest = null; + server.setRoute('/redirect.js', (req, res) => { + serverRequest = req; + res.end('console.log(1);'); + }); + + await page.setRequestInterception(true); + page.on('request', request => request.continue()); + await page.goto(server.PREFIX + '/intervention'); + expect(serverRequest.headers.intervention).toContain('www.chromestatus.com'); + }); + }); +}; + diff --git a/test/firefoxonly.spec.js b/test/firefoxonly.spec.js deleted file mode 100644 index c2f18bed279..00000000000 --- a/test/firefoxonly.spec.js +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2019 Google Inc. All rights reserved. - * - * 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. - */ -module.exports.addTests = function({testRunner, expect, product}) { - const {describe, xdescribe, fdescribe} = testRunner; - const {it, fit, xit} = testRunner; - const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; - - describe('Firefox-specific tests', function() { - describe('Browser.version', function() { - it('should return whether we are in headless', async({browser}) => { - const version = await browser.version(); - expect(version.length).toBeGreaterThan(0); - expect(version.startsWith('Firefox/')).toBe(true); - }); - }); - - describe('Browser.userAgent', function() { - it('should include WebKit', async({browser}) => { - const userAgent = await browser.userAgent(); - expect(userAgent.length).toBeGreaterThan(0); - expect(userAgent).toContain('Gecko'); - }); - }); - }); -}; - diff --git a/test/launcher.spec.js b/test/launcher.spec.js index 58b70206b28..953fce52572 100644 --- a/test/launcher.spec.js +++ b/test/launcher.spec.js @@ -256,85 +256,6 @@ module.exports.addTests = function({testRunner, expect, defaultBrowserOptions, p await browser.close(); }); }); - // "browserURL" is a chrome-only option. - (CHROME ? describe : xdescribe)('|browserURL| option', function() { - it('should be able to connect using browserUrl, with and without trailing slash', async({server}) => { - const originalBrowser = await puppeteer.launch(Object.assign({}, defaultBrowserOptions, { - args: ['--remote-debugging-port=21222'] - })); - const browserURL = 'http://127.0.0.1:21222'; - - const browser1 = await puppeteer.connect({browserURL}); - const page1 = await browser1.newPage(); - expect(await page1.evaluate(() => 7 * 8)).toBe(56); - browser1.disconnect(); - - const browser2 = await puppeteer.connect({browserURL: browserURL + '/'}); - const page2 = await browser2.newPage(); - expect(await page2.evaluate(() => 8 * 7)).toBe(56); - browser2.disconnect(); - originalBrowser.close(); - }); - it('should throw when using both browserWSEndpoint and browserURL', async({server}) => { - const originalBrowser = await puppeteer.launch(Object.assign({}, defaultBrowserOptions, { - args: ['--remote-debugging-port=21222'] - })); - const browserURL = 'http://127.0.0.1:21222'; - - let error = null; - await puppeteer.connect({browserURL, browserWSEndpoint: originalBrowser.wsEndpoint()}).catch(e => error = e); - expect(error.message).toContain('Exactly one of browserWSEndpoint, browserURL or transport'); - - originalBrowser.close(); - }); - it('should throw when trying to connect to non-existing browser', async({server}) => { - const originalBrowser = await puppeteer.launch(Object.assign({}, defaultBrowserOptions, { - args: ['--remote-debugging-port=21222'] - })); - const browserURL = 'http://127.0.0.1:32333'; - - let error = null; - await puppeteer.connect({browserURL}).catch(e => error = e); - if (CHROME) - expect(error.message).toContain('Failed to fetch browser webSocket url from'); - else - expect(error.message).toContain('Invalid URL'); - - originalBrowser.close(); - }); - }); - - // "pipe" is a chrome-only feature. - (CHROME ? describe : xdescribe)('|pipe| option', function() { - it('should support the pipe option', async() => { - const options = Object.assign({pipe: true}, defaultBrowserOptions); - const browser = await puppeteer.launch(options); - expect((await browser.pages()).length).toBe(1); - expect(browser.wsEndpoint()).toBe(''); - const page = await browser.newPage(); - expect(await page.evaluate('11 * 11')).toBe(121); - await page.close(); - await browser.close(); - }); - it('should support the pipe argument', async() => { - const options = Object.assign({}, defaultBrowserOptions); - options.args = ['--remote-debugging-pipe'].concat(options.args || []); - const browser = await puppeteer.launch(options); - expect(browser.wsEndpoint()).toBe(''); - const page = await browser.newPage(); - expect(await page.evaluate('11 * 11')).toBe(121); - await page.close(); - await browser.close(); - }); - it('should fire "disconnected" when closing with pipe', async() => { - const options = Object.assign({pipe: true}, defaultBrowserOptions); - const browser = await puppeteer.launch(options); - const disconnectedEventPromise = new Promise(resolve => browser.once('disconnected', resolve)); - // Emulate user exiting browser. - browser.process().kill(); - await disconnectedEventPromise; - }); - }); describe('Puppeteer.connect', function() { it('should be able to connect multiple times to the same browser', async({server}) => { const originalBrowser = await puppeteer.launch(defaultBrowserOptions); diff --git a/test/network.spec.js b/test/network.spec.js index 469c8404c43..1aa37f049c7 100644 --- a/test/network.spec.js +++ b/test/network.spec.js @@ -395,25 +395,6 @@ module.exports.addTests = function({testRunner, expect, CHROME}) { expect(response.ok()).toBe(true); expect(response.remoteAddress().port).toBe(server.PORT); }); - // Intervention headers are chrome-specific. - (CHROME ? it : xit)('should work with intervention headers', async({page, server}) => { - server.setRoute('/intervention', (req, res) => res.end(` - - `)); - server.setRedirect('/intervention.js', '/redirect.js'); - let serverRequest = null; - server.setRoute('/redirect.js', (req, res) => { - serverRequest = req; - res.end('console.log(1);'); - }); - - await page.setRequestInterception(true); - page.on('request', request => request.continue()); - await page.goto(server.PREFIX + '/intervention'); - expect(serverRequest.headers.intervention).toContain('www.chromestatus.com'); - }); it('should work when POST is redirected with 302', async({page, server}) => { server.setRedirect('/rredirect', '/empty.html'); await page.goto(server.EMPTY_PAGE); diff --git a/test/puppeteer.spec.js b/test/puppeteer.spec.js index 60739e40e99..de8611db9af 100644 --- a/test/puppeteer.spec.js +++ b/test/puppeteer.spec.js @@ -147,9 +147,8 @@ module.exports.addTests = ({testRunner, product, puppeteerPath}) => { require('./accessibility.spec.js').addTests(testOptions); require('./CDPSession.spec.js').addTests(testOptions); require('./coverage.spec.js').addTests(testOptions); - require('./chromiumonly.spec.js').addTests(testOptions); - } else { - require('./firefoxonly.spec.js').addTests(testOptions); + // Add page-level Chromium-specific tests. + require('./chromiumonly.spec.js').addPageTests(testOptions); } }); @@ -164,5 +163,7 @@ module.exports.addTests = ({testRunner, product, puppeteerPath}) => { if (CHROME) { require('./headful.spec.js').addTests(testOptions); require('./tracing.spec.js').addTests(testOptions); + // Add top-level Chromium-specific tests. + require('./chromiumonly.spec.js').addLauncherTests(testOptions); } };