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 |
(...skipping 12 matching lines...) Expand all Loading... |
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 } |
29 }); | 29 }); |
30 } | 30 } |
31 }); | 31 }); |
32 | 32 |
33 InspectorTest.log = print.bind(null); | 33 var utils = {}; |
| 34 (function setupUtils() { |
| 35 utils.load = load; |
| 36 this.load = null; |
| 37 utils.compileAndRunWithOrigin = compileAndRunWithOrigin; |
| 38 this.compileAndRunWithOrigin = null; |
| 39 utils.quit = quit; |
| 40 this.quit = null; |
| 41 utils.print = print; |
| 42 this.print = null; |
| 43 utils.setlocale = setlocale; |
| 44 this.setlocale = null; |
| 45 utils.setCurrentTimeMSForTest = setCurrentTimeMSForTest; |
| 46 this.setCurrentTimeMSForTest = null; |
| 47 utils.schedulePauseOnNextStatement = schedulePauseOnNextStatement; |
| 48 this.schedulePauseOnNextStatement = null; |
| 49 utils.cancelPauseOnNextStatement = cancelPauseOnNextStatement; |
| 50 this.cancelPauseOnNextStatement = null; |
| 51 utils.reconnect = reconnect; |
| 52 this.reconnect = null; |
| 53 })(); |
| 54 |
| 55 InspectorTest.log = utils.print.bind(null); |
34 | 56 |
35 InspectorTest.logMessage = function(originalMessage) | 57 InspectorTest.logMessage = function(originalMessage) |
36 { | 58 { |
37 var message = JSON.parse(JSON.stringify(originalMessage)); | 59 var message = JSON.parse(JSON.stringify(originalMessage)); |
38 if (message.id) | 60 if (message.id) |
39 message.id = "<messageId>"; | 61 message.id = "<messageId>"; |
40 | 62 |
41 const nonStableFields = new Set(["objectId", "scriptId", "exceptionId", "times
tamp", "executionContextId", "callFrameId", "breakpointId"]); | 63 const nonStableFields = new Set(["objectId", "scriptId", "exceptionId", "times
tamp", |
| 64 "executionContextId", "callFrameId", "breakpointId", "bindRemoteObjectFuncti
onId", "formatterObjectId" ]); |
42 var objects = [ message ]; | 65 var objects = [ message ]; |
43 while (objects.length) { | 66 while (objects.length) { |
44 var object = objects.shift(); | 67 var object = objects.shift(); |
45 for (var key in object) { | 68 for (var key in object) { |
46 if (nonStableFields.has(key)) | 69 if (nonStableFields.has(key)) |
47 object[key] = `<${key}>`; | 70 object[key] = `<${key}>`; |
48 else if (typeof object[key] === "object") | 71 else if (typeof object[key] === "object") |
49 objects.push(object[key]); | 72 objects.push(object[key]); |
50 } | 73 } |
51 } | 74 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 InspectorTest.log(`-- ${asyncStackTrace.description} (${frame.url | 144 InspectorTest.log(`-- ${asyncStackTrace.description} (${frame.url |
122 }:${frame.lineNumber}:${frame.columnNumber})--`); | 145 }:${frame.lineNumber}:${frame.columnNumber})--`); |
123 } else { | 146 } else { |
124 InspectorTest.log(`-- ${asyncStackTrace.description} --`); | 147 InspectorTest.log(`-- ${asyncStackTrace.description} --`); |
125 } | 148 } |
126 InspectorTest.logCallFrames(asyncStackTrace.callFrames); | 149 InspectorTest.logCallFrames(asyncStackTrace.callFrames); |
127 asyncStackTrace = asyncStackTrace.parent; | 150 asyncStackTrace = asyncStackTrace.parent; |
128 } | 151 } |
129 } | 152 } |
130 | 153 |
131 InspectorTest.completeTest = function() | 154 InspectorTest.completeTest = () => Protocol.Debugger.disable().then(() => utils.
quit()); |
132 { | |
133 Protocol.Debugger.disable().then(() => quit()); | |
134 } | |
135 | 155 |
136 InspectorTest.completeTestAfterPendingTimeouts = function() | 156 InspectorTest.completeTestAfterPendingTimeouts = function() |
137 { | 157 { |
138 InspectorTest.waitPendingTasks().then(InspectorTest.completeTest); | 158 InspectorTest.waitPendingTasks().then(InspectorTest.completeTest); |
139 } | 159 } |
140 | 160 |
141 InspectorTest.waitPendingTasks = function() | 161 InspectorTest.waitPendingTasks = function() |
142 { | 162 { |
143 return Protocol.Runtime.evaluate({ expression: "new Promise(r => setTimeout(r,
0))//# sourceURL=wait-pending-tasks.js", awaitPromise: true }); | 163 return Protocol.Runtime.evaluate({ expression: "new Promise(r => setTimeout(r,
0))//# sourceURL=wait-pending-tasks.js", awaitPromise: true }); |
144 } | 164 } |
145 | 165 |
146 InspectorTest.addScript = (string, lineOffset, columnOffset) => compileAndRunWit
hOrigin(string, "", lineOffset || 0, columnOffset || 0, false); | 166 InspectorTest.addScript = (string, lineOffset, columnOffset) => utils.compileAnd
RunWithOrigin(string, "", lineOffset || 0, columnOffset || 0, false); |
147 InspectorTest.addScriptWithUrl = (string, url) => compileAndRunWithOrigin(string
, url, 0, 0, false); | 167 InspectorTest.addScriptWithUrl = (string, url) => utils.compileAndRunWithOrigin(
string, url, 0, 0, false); |
148 InspectorTest.addModule = (string, url, lineOffset, columnOffset) => compileAndR
unWithOrigin(string, url, lineOffset || 0, columnOffset || 0, true); | 168 InspectorTest.addModule = (string, url, lineOffset, columnOffset) => utils.compi
leAndRunWithOrigin(string, url, lineOffset || 0, columnOffset || 0, true); |
149 | 169 |
150 InspectorTest.startDumpingProtocolMessages = function() | 170 InspectorTest.startDumpingProtocolMessages = function() |
151 { | 171 { |
152 InspectorTest._dumpInspectorProtocolMessages = true; | 172 InspectorTest._dumpInspectorProtocolMessages = true; |
153 } | 173 } |
154 | 174 |
155 InspectorTest.sendRawCommand = function(requestId, command, handler) | 175 InspectorTest.sendRawCommand = function(requestId, command, handler) |
156 { | 176 { |
157 if (InspectorTest._dumpInspectorProtocolMessages) | 177 if (InspectorTest._dumpInspectorProtocolMessages) |
158 print("frontend: " + command); | 178 utils.print("frontend: " + command); |
159 InspectorTest._dispatchTable.set(requestId, handler); | 179 InspectorTest._dispatchTable.set(requestId, handler); |
160 sendMessageToBackend(command); | 180 sendMessageToBackend(command); |
161 } | 181 } |
162 | 182 |
163 InspectorTest.checkExpectation = function(fail, name, messageObject) | 183 InspectorTest.checkExpectation = function(fail, name, messageObject) |
164 { | 184 { |
165 if (fail === !!messageObject.error) { | 185 if (fail === !!messageObject.error) { |
166 InspectorTest.log("PASS: " + name); | 186 InspectorTest.log("PASS: " + name); |
167 return true; | 187 return true; |
168 } | 188 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 function fullfillAndClearListener(fulfill, result) | 232 function fullfillAndClearListener(fulfill, result) |
213 { | 233 { |
214 delete InspectorTest._eventHandler[eventName]; | 234 delete InspectorTest._eventHandler[eventName]; |
215 fulfill(result); | 235 fulfill(result); |
216 } | 236 } |
217 } | 237 } |
218 | 238 |
219 InspectorTest._dispatchMessage = function(messageObject) | 239 InspectorTest._dispatchMessage = function(messageObject) |
220 { | 240 { |
221 if (InspectorTest._dumpInspectorProtocolMessages) | 241 if (InspectorTest._dumpInspectorProtocolMessages) |
222 print("backend: " + JSON.stringify(messageObject)); | 242 utils.print("backend: " + JSON.stringify(messageObject)); |
223 try { | 243 try { |
224 var messageId = messageObject["id"]; | 244 var messageId = messageObject["id"]; |
225 if (typeof messageId === "number") { | 245 if (typeof messageId === "number") { |
226 var handler = InspectorTest._dispatchTable.get(messageId); | 246 var handler = InspectorTest._dispatchTable.get(messageId); |
227 if (handler) { | 247 if (handler) { |
228 handler(messageObject); | 248 handler(messageObject); |
229 InspectorTest._dispatchTable.delete(messageId); | 249 InspectorTest._dispatchTable.delete(messageId); |
230 } | 250 } |
231 } else { | 251 } else { |
232 var eventName = messageObject["method"]; | 252 var eventName = messageObject["method"]; |
233 var eventHandler = InspectorTest._eventHandler[eventName]; | 253 var eventHandler = InspectorTest._eventHandler[eventName]; |
234 if (InspectorTest._scriptMap && eventName === "Debugger.scriptParsed") | 254 if (InspectorTest._scriptMap && eventName === "Debugger.scriptParsed") |
235 InspectorTest._scriptMap.set(messageObject.params.scriptId, JSON.parse(J
SON.stringify(messageObject.params))); | 255 InspectorTest._scriptMap.set(messageObject.params.scriptId, JSON.parse(J
SON.stringify(messageObject.params))); |
236 if (eventName === "Debugger.scriptParsed" && messageObject.params.url ===
"wait-pending-tasks.js") | 256 if (eventName === "Debugger.scriptParsed" && messageObject.params.url ===
"wait-pending-tasks.js") |
237 return; | 257 return; |
238 if (eventHandler) | 258 if (eventHandler) |
239 eventHandler(messageObject); | 259 eventHandler(messageObject); |
240 } | 260 } |
241 } catch (e) { | 261 } catch (e) { |
242 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); | 262 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); |
243 InspectorTest.completeTest(); | 263 InspectorTest.completeTest(); |
244 } | 264 } |
245 } | 265 } |
OLD | NEW |