| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 lines.push(firstLinePrefix + "["); | 94 lines.push(firstLinePrefix + "["); |
| 95 for (var i = 0; i < object.length; ++i) | 95 for (var i = 0; i < object.length; ++i) |
| 96 dumpValue(object[i], " " + prefix, " " + prefix + "[" + i + "] : "); | 96 dumpValue(object[i], " " + prefix, " " + prefix + "[" + i + "] : "); |
| 97 lines.push(prefix + "]"); | 97 lines.push(prefix + "]"); |
| 98 } | 98 } |
| 99 | 99 |
| 100 dumpValue(object, "", title || ""); | 100 dumpValue(object, "", title || ""); |
| 101 InspectorTest.log(lines.join("\n")); | 101 InspectorTest.log(lines.join("\n")); |
| 102 } | 102 } |
| 103 | 103 |
| 104 InspectorTest.logCallFrames = function(callFrames) |
| 105 { |
| 106 for (var frame of callFrames) { |
| 107 var functionName = frame.functionName || '(anonymous)'; |
| 108 var url = frame.url ? frame.url : InspectorTest._scriptMap.get(frame.locatio
n.scriptId).url; |
| 109 var lineNumber = frame.location ? frame.location.lineNumber : frame.lineNumb
er; |
| 110 var columnNumber = frame.location ? frame.location.columnNumber : frame.colu
mnNumber; |
| 111 InspectorTest.log(`${functionName} (${url}:${lineNumber}:${columnNumber})`); |
| 112 } |
| 113 } |
| 114 |
| 104 InspectorTest.completeTest = function() | 115 InspectorTest.completeTest = function() |
| 105 { | 116 { |
| 106 Protocol.Debugger.disable().then(() => quit()); | 117 Protocol.Debugger.disable().then(() => quit()); |
| 107 } | 118 } |
| 108 | 119 |
| 109 InspectorTest.completeTestAfterPendingTimeouts = function() | 120 InspectorTest.completeTestAfterPendingTimeouts = function() |
| 110 { | 121 { |
| 111 Protocol.Runtime.evaluate({ | 122 Protocol.Runtime.evaluate({ |
| 112 expression: "new Promise(resolve => setTimeout(resolve, 0))", | 123 expression: "new Promise(resolve => setTimeout(resolve, 0))", |
| 113 awaitPromise: true }).then(InspectorTest.completeTest); | 124 awaitPromise: true }).then(InspectorTest.completeTest); |
| 114 } | 125 } |
| 115 | 126 |
| 116 InspectorTest.addScript = (string) => compileAndRunWithOrigin(string, "", 0, 0); | 127 InspectorTest.addScript = (string, lineOffset, columnOffset) => compileAndRunWit
hOrigin(string, "", lineOffset || 0, columnOffset || 0); |
| 117 InspectorTest.addScriptWithUrl = (string, url) => compileAndRunWithOrigin(string
, url, 0, 0); | 128 InspectorTest.addScriptWithUrl = (string, url) => compileAndRunWithOrigin(string
, url, 0, 0); |
| 118 | 129 |
| 119 InspectorTest.startDumpingProtocolMessages = function() | 130 InspectorTest.startDumpingProtocolMessages = function() |
| 120 { | 131 { |
| 121 InspectorTest._dumpInspectorProtocolMessages = true; | 132 InspectorTest._dumpInspectorProtocolMessages = true; |
| 122 } | 133 } |
| 123 | 134 |
| 124 InspectorTest.sendRawCommand = function(requestId, command, handler) | 135 InspectorTest.sendRawCommand = function(requestId, command, handler) |
| 125 { | 136 { |
| 126 if (InspectorTest._dumpInspectorProtocolMessages) | 137 if (InspectorTest._dumpInspectorProtocolMessages) |
| 127 print("frontend: " + command); | 138 print("frontend: " + command); |
| 128 InspectorTest._dispatchTable.set(requestId, handler); | 139 InspectorTest._dispatchTable.set(requestId, handler); |
| 129 sendMessageToBackend(command); | 140 sendMessageToBackend(command); |
| 130 } | 141 } |
| 131 | 142 |
| 132 InspectorTest.checkExpectation = function(fail, name, messageObject) | 143 InspectorTest.checkExpectation = function(fail, name, messageObject) |
| 133 { | 144 { |
| 134 if (fail === !!messageObject.error) { | 145 if (fail === !!messageObject.error) { |
| 135 InspectorTest.log("PASS: " + name); | 146 InspectorTest.log("PASS: " + name); |
| 136 return true; | 147 return true; |
| 137 } | 148 } |
| 138 | 149 |
| 139 InspectorTest.log("FAIL: " + name + ": " + JSON.stringify(messageObject)); | 150 InspectorTest.log("FAIL: " + name + ": " + JSON.stringify(messageObject)); |
| 140 InspectorTest.completeTest(); | 151 InspectorTest.completeTest(); |
| 141 return false; | 152 return false; |
| 142 } | 153 } |
| 143 InspectorTest.expectedSuccess = InspectorTest.checkExpectation.bind(null, false)
; | 154 InspectorTest.expectedSuccess = InspectorTest.checkExpectation.bind(null, false)
; |
| 144 InspectorTest.expectedError = InspectorTest.checkExpectation.bind(null, true); | 155 InspectorTest.expectedError = InspectorTest.checkExpectation.bind(null, true); |
| 145 | 156 |
| 157 InspectorTest.setupScriptMap = function() { |
| 158 if (InspectorTest._scriptMap) |
| 159 return; |
| 160 InspectorTest._scriptMap = new Map(); |
| 161 } |
| 162 |
| 146 InspectorTest.runTestSuite = function(testSuite) | 163 InspectorTest.runTestSuite = function(testSuite) |
| 147 { | 164 { |
| 148 function nextTest() | 165 function nextTest() |
| 149 { | 166 { |
| 150 if (!testSuite.length) { | 167 if (!testSuite.length) { |
| 151 InspectorTest.completeTest(); | 168 InspectorTest.completeTest(); |
| 152 return; | 169 return; |
| 153 } | 170 } |
| 154 var fun = testSuite.shift(); | 171 var fun = testSuite.shift(); |
| 155 InspectorTest.log("\nRunning test: " + fun.name); | 172 InspectorTest.log("\nRunning test: " + fun.name); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 var handler = InspectorTest._dispatchTable.get(messageId); | 206 var handler = InspectorTest._dispatchTable.get(messageId); |
| 190 if (handler) { | 207 if (handler) { |
| 191 handler(messageObject); | 208 handler(messageObject); |
| 192 InspectorTest._dispatchTable.delete(messageId); | 209 InspectorTest._dispatchTable.delete(messageId); |
| 193 } | 210 } |
| 194 } else { | 211 } else { |
| 195 var eventName = messageObject["method"]; | 212 var eventName = messageObject["method"]; |
| 196 var eventHandler = InspectorTest._eventHandler[eventName]; | 213 var eventHandler = InspectorTest._eventHandler[eventName]; |
| 197 if (eventHandler) | 214 if (eventHandler) |
| 198 eventHandler(messageObject); | 215 eventHandler(messageObject); |
| 216 if (InspectorTest._scriptMap && eventName === "Debugger.scriptParsed") { |
| 217 InspectorTest._scriptMap.set(messageObject.params.scriptId, messageObjec
t.params); |
| 218 } |
| 199 } | 219 } |
| 200 } catch (e) { | 220 } catch (e) { |
| 201 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); | 221 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stac
k + "\n message = " + JSON.stringify(messageObject, null, 2)); |
| 202 InspectorTest.completeTest(); | 222 InspectorTest.completeTest(); |
| 203 } | 223 } |
| 204 } | 224 } |
| OLD | NEW |