11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst childProcess = require('child_process'); 81cb0ef41Sopenharmony_ciconst http = require('http'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_cilet port; 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst server = http.createServer(common.mustCall((req, res) => { 131cb0ef41Sopenharmony_ci if (req.url.startsWith('/json')) { 141cb0ef41Sopenharmony_ci res.writeHead(200); 151cb0ef41Sopenharmony_ci res.end(`[ { 161cb0ef41Sopenharmony_ci "description": "", 171cb0ef41Sopenharmony_ci "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:${port}/devtools/page/DAB7FB6187B554E10B0BD18821265734", 181cb0ef41Sopenharmony_ci "cid": "DAB7FB6187B554E10B0BD18821265734", 191cb0ef41Sopenharmony_ci "title": "Fhqwhgads", 201cb0ef41Sopenharmony_ci "type": "page", 211cb0ef41Sopenharmony_ci "url": "https://www.example.com/", 221cb0ef41Sopenharmony_ci "webSocketDebuggerUrl": "ws://localhost:${port}/devtools/page/DAB7FB6187B554E10B0BD18821265734" 231cb0ef41Sopenharmony_ci } ]`); 241cb0ef41Sopenharmony_ci } else { 251cb0ef41Sopenharmony_ci res.setHeader('Upgrade', 'websocket'); 261cb0ef41Sopenharmony_ci res.setHeader('Connection', 'Upgrade'); 271cb0ef41Sopenharmony_ci res.setHeader('Sec-WebSocket-Accept', 'fhqwhgads'); 281cb0ef41Sopenharmony_ci res.setHeader('Sec-WebSocket-Protocol', 'chat'); 291cb0ef41Sopenharmony_ci res.writeHead(101); 301cb0ef41Sopenharmony_ci res.end(); 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci}, 2)).listen(0, common.mustCall(() => { 331cb0ef41Sopenharmony_ci port = server.address().port; 341cb0ef41Sopenharmony_ci const proc = 351cb0ef41Sopenharmony_ci childProcess.spawn(process.execPath, ['inspect', `localhost:${port}`]); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci let stdout = ''; 381cb0ef41Sopenharmony_ci proc.stdout.on('data', (data) => { 391cb0ef41Sopenharmony_ci stdout += data.toString(); 401cb0ef41Sopenharmony_ci assert.doesNotMatch(stdout, /\bok\b/); 411cb0ef41Sopenharmony_ci }); 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci let stderr = ''; 441cb0ef41Sopenharmony_ci proc.stderr.on('data', (data) => { 451cb0ef41Sopenharmony_ci stderr += data.toString(); 461cb0ef41Sopenharmony_ci }); 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci proc.on('exit', common.mustCall((code, signal) => { 491cb0ef41Sopenharmony_ci assert.match(stderr, /\bWebSocket secret mismatch\b/); 501cb0ef41Sopenharmony_ci assert.notStrictEqual(code, 0); 511cb0ef41Sopenharmony_ci assert.strictEqual(signal, null); 521cb0ef41Sopenharmony_ci server.close(); 531cb0ef41Sopenharmony_ci })); 541cb0ef41Sopenharmony_ci})); 55