OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 InspectorTest = {}; | 5 InspectorTest = {}; |
6 InspectorTest._dispatchTable = new Map(); | 6 InspectorTest._dispatchTable = new Map(); |
7 InspectorTest._requestId = 0; | 7 InspectorTest._requestId = 0; |
8 InspectorTest._dumpInspectorProtocolMessages = false; | 8 InspectorTest._dumpInspectorProtocolMessages = false; |
9 InspectorTest._eventHandler = {}; | 9 InspectorTest._eventHandler = {}; |
10 | 10 |
11 Protocol = new Proxy({}, { | 11 Protocol = new Proxy({}, { |
12 get: function(target, agentName, receiver) { | 12 get: function(target, agentName, receiver) { |
13 return new Proxy({}, { | 13 return new Proxy({}, { |
14 get: function(target, methodName, receiver) { | 14 get: function(target, methodName, receiver) { |
15 const eventPattern = /^on(ce)?([A-Z][A-Za-z0-9]+)/; | 15 const eventPattern = /^on(ce)?([A-Z][A-Za-z0-9]+)/; |
16 var match = eventPattern.exec(methodName); | 16 var match = eventPattern.exec(methodName); |
17 if (!match) { | 17 if (!match) { |
18 return (args) => InspectorTest._sendCommandPromise(`${agentName}.${met
hodName}`, args || {}); | 18 return (args, contextGroupId) => InspectorTest._sendCommandPromise(`${
agentName}.${methodName}`, args || {}, contextGroupId); |
19 } else { | 19 } else { |
20 var eventName = match[2]; | 20 var eventName = match[2]; |
21 eventName = eventName.charAt(0).toLowerCase() + eventName.slice(1); | 21 eventName = eventName.charAt(0).toLowerCase() + eventName.slice(1); |
22 if (match[1]) | 22 if (match[1]) |
23 return () => InspectorTest._waitForEventPromise( | 23 return () => InspectorTest._waitForEventPromise( |
24 `${agentName}.${eventName}`); | 24 `${agentName}.${eventName}`); |
25 else | 25 else |
26 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e
ventName}`] = listener }; | 26 return (listener) => { InspectorTest._eventHandler[`${agentName}.${e
ventName}`] = listener }; |
27 } | 27 } |
28 } | 28 } |
(...skipping 16 matching lines...) Expand all Loading... |
45 utils.setlocale = setlocale; | 45 utils.setlocale = setlocale; |
46 this.setlocale = null; | 46 this.setlocale = null; |
47 utils.setCurrentTimeMSForTest = setCurrentTimeMSForTest; | 47 utils.setCurrentTimeMSForTest = setCurrentTimeMSForTest; |
48 this.setCurrentTimeMSForTest = null; | 48 this.setCurrentTimeMSForTest = null; |
49 utils.schedulePauseOnNextStatement = schedulePauseOnNextStatement; | 49 utils.schedulePauseOnNextStatement = schedulePauseOnNextStatement; |
50 this.schedulePauseOnNextStatement = null; | 50 this.schedulePauseOnNextStatement = null; |
51 utils.cancelPauseOnNextStatement = cancelPauseOnNextStatement; | 51 utils.cancelPauseOnNextStatement = cancelPauseOnNextStatement; |
52 this.cancelPauseOnNextStatement = null; | 52 this.cancelPauseOnNextStatement = null; |
53 utils.reconnect = reconnect; | 53 utils.reconnect = reconnect; |
54 this.reconnect = null; | 54 this.reconnect = null; |
| 55 utils.createContextGroup = createContextGroup; |
| 56 this.createContextGroup = null; |
55 })(); | 57 })(); |
56 | 58 |
57 InspectorTest.log = utils.print.bind(null); | 59 InspectorTest.log = utils.print.bind(null); |
58 | 60 |
59 InspectorTest.logMessage = function(originalMessage) | 61 InspectorTest.logMessage = function(originalMessage) |
60 { | 62 { |
61 var message = JSON.parse(JSON.stringify(originalMessage)); | 63 var message = JSON.parse(JSON.stringify(originalMessage)); |
62 if (message.id) | 64 if (message.id) |
63 message.id = "<messageId>"; | 65 message.id = "<messageId>"; |
64 | 66 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 200 |
199 InspectorTest.addScript = (string, lineOffset, columnOffset) => utils.compileAnd
RunWithOrigin(string, "", lineOffset || 0, columnOffset || 0, false); | 201 InspectorTest.addScript = (string, lineOffset, columnOffset) => utils.compileAnd
RunWithOrigin(string, "", lineOffset || 0, columnOffset || 0, false); |
200 InspectorTest.addScriptWithUrl = (string, url) => utils.compileAndRunWithOrigin(
string, url, 0, 0, false); | 202 InspectorTest.addScriptWithUrl = (string, url) => utils.compileAndRunWithOrigin(
string, url, 0, 0, false); |
201 InspectorTest.addModule = (string, url, lineOffset, columnOffset) => utils.compi
leAndRunWithOrigin(string, url, lineOffset || 0, columnOffset || 0, true); | 203 InspectorTest.addModule = (string, url, lineOffset, columnOffset) => utils.compi
leAndRunWithOrigin(string, url, lineOffset || 0, columnOffset || 0, true); |
202 | 204 |
203 InspectorTest.startDumpingProtocolMessages = function() | 205 InspectorTest.startDumpingProtocolMessages = function() |
204 { | 206 { |
205 InspectorTest._dumpInspectorProtocolMessages = true; | 207 InspectorTest._dumpInspectorProtocolMessages = true; |
206 } | 208 } |
207 | 209 |
208 InspectorTest.sendRawCommand = function(requestId, command, handler) | 210 InspectorTest.sendRawCommand = function(requestId, command, handler, contextGrou
pId) |
209 { | 211 { |
210 if (InspectorTest._dumpInspectorProtocolMessages) | 212 if (InspectorTest._dumpInspectorProtocolMessages) |
211 utils.print("frontend: " + command); | 213 utils.print("frontend: " + command); |
212 InspectorTest._dispatchTable.set(requestId, handler); | 214 InspectorTest._dispatchTable.set(requestId, handler); |
213 sendMessageToBackend(command); | 215 sendMessageToBackend(command, contextGroupId || 0); |
214 } | 216 } |
215 | 217 |
216 InspectorTest.checkExpectation = function(fail, name, messageObject) | 218 InspectorTest.checkExpectation = function(fail, name, messageObject) |
217 { | 219 { |
218 if (fail === !!messageObject.error) { | 220 if (fail === !!messageObject.error) { |
219 InspectorTest.log("PASS: " + name); | 221 InspectorTest.log("PASS: " + name); |
220 return true; | 222 return true; |
221 } | 223 } |
222 | 224 |
223 InspectorTest.log("FAIL: " + name + ": " + JSON.stringify(messageObject)); | 225 InspectorTest.log("FAIL: " + name + ": " + JSON.stringify(messageObject)); |
(...skipping 25 matching lines...) Expand all Loading... |
249 } | 251 } |
250 | 252 |
251 InspectorTest.runAsyncTestSuite = async function(testSuite) { | 253 InspectorTest.runAsyncTestSuite = async function(testSuite) { |
252 for (var test of testSuite) { | 254 for (var test of testSuite) { |
253 InspectorTest.log("\nRunning test: " + test.name); | 255 InspectorTest.log("\nRunning test: " + test.name); |
254 await test(); | 256 await test(); |
255 } | 257 } |
256 InspectorTest.completeTest(); | 258 InspectorTest.completeTest(); |
257 } | 259 } |
258 | 260 |
259 InspectorTest._sendCommandPromise = function(method, params) | 261 InspectorTest._sendCommandPromise = function(method, params, contextGroupId) |
260 { | 262 { |
261 var requestId = ++InspectorTest._requestId; | 263 var requestId = ++InspectorTest._requestId; |
262 var messageObject = { "id": requestId, "method": method, "params": params }; | 264 var messageObject = { "id": requestId, "method": method, "params": params }; |
263 var fulfillCallback; | 265 var fulfillCallback; |
264 var promise = new Promise(fulfill => fulfillCallback = fulfill); | 266 var promise = new Promise(fulfill => fulfillCallback = fulfill); |
265 InspectorTest.sendRawCommand(requestId, JSON.stringify(messageObject), fulfill
Callback); | 267 InspectorTest.sendRawCommand(requestId, JSON.stringify(messageObject), fulfill
Callback, contextGroupId); |
266 return promise; | 268 return promise; |
267 } | 269 } |
268 | 270 |
269 InspectorTest._waitForEventPromise = function(eventName) | 271 InspectorTest._waitForEventPromise = function(eventName) |
270 { | 272 { |
271 return new Promise(fulfill => InspectorTest._eventHandler[eventName] = fullfil
lAndClearListener.bind(null, fulfill)); | 273 return new Promise(fulfill => InspectorTest._eventHandler[eventName] = fullfil
lAndClearListener.bind(null, fulfill)); |
272 | 274 |
273 function fullfillAndClearListener(fulfill, result) | 275 function fullfillAndClearListener(fulfill, result) |
274 { | 276 { |
275 delete InspectorTest._eventHandler[eventName]; | 277 delete InspectorTest._eventHandler[eventName]; |
(...skipping 25 matching lines...) Expand all Loading... |
301 } | 303 } |
302 } catch (e) { | 304 } catch (e) { |
303 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); | 305 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); |
304 InspectorTest.completeTest(); | 306 InspectorTest.completeTest(); |
305 } | 307 } |
306 } | 308 } |
307 | 309 |
308 InspectorTest.loadScript = function(fileName) { | 310 InspectorTest.loadScript = function(fileName) { |
309 InspectorTest.addScript(utils.read(fileName)); | 311 InspectorTest.addScript(utils.read(fileName)); |
310 } | 312 } |
OLD | NEW |