From d0de03950ba4aa20d7273cea9f13065be9fbf2cd Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 10 Aug 2023 08:58:47 +0200 Subject: [PATCH] fix: ignore cert errors in the test driver (#1161) Closes #1162 --- src/bidiServer/bidiServerRunner.ts | 47 +++++++++++++------ src/bidiServer/index.ts | 16 +++++-- .../set_viewport/set_viewport.py.ini | 6 --- .../set_viewport/set_viewport.py.ini | 6 --- .../set_viewport/set_viewport.py.ini | 6 --- 5 files changed, 45 insertions(+), 36 deletions(-) delete mode 100644 wpt-metadata/chromedriver/headless/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini delete mode 100644 wpt-metadata/mapper/headful/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini delete mode 100644 wpt-metadata/mapper/headless/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini diff --git a/src/bidiServer/bidiServerRunner.ts b/src/bidiServer/bidiServerRunner.ts index ce8d2c6741..5b7da23668 100644 --- a/src/bidiServer/bidiServerRunner.ts +++ b/src/bidiServer/bidiServerRunner.ts @@ -53,9 +53,11 @@ export class BidiServerRunner { run( bidiPort: number, onNewBidiConnectionOpen: ( - bidiServer: ITransport + bidiServer: ITransport, + args?: string[] ) => Promise<() => void> | (() => void) ) { + let jsonBody: any; const server = http.createServer( async (request: http.IncomingMessage, response: http.ServerResponse) => { debugInternal( @@ -67,20 +69,30 @@ export class BidiServerRunner { // https://w3c.github.io/webdriver-bidi/#transport, step 2. if (request.url === '/session') { - response.writeHead(200, { - 'Content-Type': 'application/json;charset=utf-8', - 'Cache-Control': 'no-cache', - }); - response.write( - JSON.stringify({ - value: { - sessionId: '1', - capabilities: { - webSocketUrl: `ws://localhost:${bidiPort}`, - }, - }, + const body: Uint8Array[] = []; + request + .on('data', (chunk) => { + body.push(chunk); }) - ); + .on('end', () => { + jsonBody = JSON.parse(Buffer.concat(body).toString()); + response.writeHead(200, { + 'Content-Type': 'application/json;charset=utf-8', + 'Cache-Control': 'no-cache', + }); + response.write( + JSON.stringify({ + value: { + sessionId: '1', + capabilities: { + webSocketUrl: `ws://localhost:${bidiPort}`, + }, + }, + }) + ); + return response.end(); + }); + return; } else if (request.url.startsWith('/session')) { debugInternal( `Unknown session command ${ @@ -126,11 +138,16 @@ export class BidiServerRunner { }); wsServer.on('request', async (request: websocket.request) => { + const chromeOptions = + jsonBody?.capabilities?.alwaysMatch?.['goog:chromeOptions']; debugInternal('new WS request received:', request.resourceURL.path); const bidiServer = new BidiServer(); - const onBidiConnectionClosed = await onNewBidiConnectionOpen(bidiServer); + const onBidiConnectionClosed = await onNewBidiConnectionOpen( + bidiServer, + chromeOptions?.args + ); const connection = request.accept(); diff --git a/src/bidiServer/index.ts b/src/bidiServer/index.ts index 7d192c66f6..67743d26d4 100644 --- a/src/bidiServer/index.ts +++ b/src/bidiServer/index.ts @@ -82,8 +82,14 @@ function parseArguments(): { debugInfo('Launching BiDi server...'); - new BidiServerRunner().run(port, (bidiServer) => { - return onNewBidiConnectionOpen(channel, headless, bidiServer, verbose); + new BidiServerRunner().run(port, (bidiServer, chromeArgs) => { + return onNewBidiConnectionOpen( + channel, + headless, + bidiServer, + verbose, + chromeArgs + ); }); debugInfo('BiDi server launched'); } catch (e) { @@ -104,7 +110,8 @@ async function onNewBidiConnectionOpen( channel: ChromeReleaseChannel, headless: boolean, bidiTransport: ITransport, - verbose: boolean + verbose: boolean, + chromeArgs?: string[] ) { // 1. Launch the browser using @puppeteer/browsers. const profileDir = await mkdtemp( @@ -127,6 +134,9 @@ async function onNewBidiConnectionOpen( '--use-mock-keychain', `--user-data-dir=${profileDir}`, // keep-sorted end + ...(chromeArgs + ? chromeArgs.filter((arg) => !arg.startsWith('--headless')) + : []), 'about:blank', ]; diff --git a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini b/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini deleted file mode 100644 index b353a374f8..0000000000 --- a/wpt-metadata/chromedriver/headless/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini +++ /dev/null @@ -1,6 +0,0 @@ -[set_viewport.py] - [test_set_viewport_persists_on_navigation[https\]] - expected: FAIL - - [test_set_viewport_persists_on_navigation[https coop\]] - expected: FAIL diff --git a/wpt-metadata/mapper/headful/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini b/wpt-metadata/mapper/headful/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini deleted file mode 100644 index b353a374f8..0000000000 --- a/wpt-metadata/mapper/headful/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini +++ /dev/null @@ -1,6 +0,0 @@ -[set_viewport.py] - [test_set_viewport_persists_on_navigation[https\]] - expected: FAIL - - [test_set_viewport_persists_on_navigation[https coop\]] - expected: FAIL diff --git a/wpt-metadata/mapper/headless/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini b/wpt-metadata/mapper/headless/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini deleted file mode 100644 index b353a374f8..0000000000 --- a/wpt-metadata/mapper/headless/webdriver/tests/bidi/browsing_context/set_viewport/set_viewport.py.ini +++ /dev/null @@ -1,6 +0,0 @@ -[set_viewport.py] - [test_set_viewport_persists_on_navigation[https\]] - expected: FAIL - - [test_set_viewport_persists_on_navigation[https coop\]] - expected: FAIL