| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script type="text/javascript" src="../../http/tests/inspector-protocol/resource
s/inspector-protocol-test.js"></script> | |
| 4 <script type="text/javascript" src="resources/liveedit-me.js"></script> | |
| 5 <script> | |
| 6 | |
| 7 function test() | |
| 8 { | |
| 9 // A general-purpose engine for sending a sequence of protocol commands. | |
| 10 // The clients provide requests and response handlers, while the engine catc
hes | |
| 11 // errors and makes sure that once there's nothing to do completeTest() is c
alled. | |
| 12 // @param step is an object with command, params and callback fields | |
| 13 function runRequestSeries(step) { | |
| 14 processStep(step); | |
| 15 | |
| 16 function processStep(currentStep) { | |
| 17 try { | |
| 18 processStepOrFail(currentStep); | |
| 19 } catch (e) { | |
| 20 InspectorTest.log(e.stack); | |
| 21 InspectorTest.completeTest(); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 function processStepOrFail(currentStep) { | |
| 26 if (!currentStep) { | |
| 27 InspectorTest.completeTest(); | |
| 28 return; | |
| 29 } | |
| 30 if (!currentStep.command) { | |
| 31 // A simple loopback step. | |
| 32 var next = currentStep.callback(); | |
| 33 processStep(next); | |
| 34 return; | |
| 35 } | |
| 36 | |
| 37 var innerCallback = function(response) { | |
| 38 var next; | |
| 39 if ("error" in response) { | |
| 40 if (!("errorHandler" in currentStep)) { | |
| 41 // Error message is not logged intentionally, it may be
platform-specific. | |
| 42 InspectorTest.log("Protocol command '" + currentStep.com
mand + "' failed"); | |
| 43 InspectorTest.completeTest(); | |
| 44 return; | |
| 45 } | |
| 46 try { | |
| 47 next = currentStep.errorHandler(response.error); | |
| 48 } catch (e) { | |
| 49 InspectorTest.log(e.stack); | |
| 50 InspectorTest.completeTest(); | |
| 51 return; | |
| 52 } | |
| 53 } else { | |
| 54 try { | |
| 55 next = currentStep.callback(response.result); | |
| 56 } catch (e) { | |
| 57 InspectorTest.log(e.stack); | |
| 58 InspectorTest.completeTest(); | |
| 59 return; | |
| 60 } | |
| 61 } | |
| 62 processStep(next); | |
| 63 } | |
| 64 InspectorTest.sendCommand(currentStep.command, currentStep.params, i
nnerCallback); | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 function logEqualsCheck(actual, expected) | |
| 69 { | |
| 70 if (actual == expected) { | |
| 71 InspectorTest.log("PASS, result value: " + actual); | |
| 72 } else { | |
| 73 InspectorTest.log("FAIL, actual value: " + actual + ", expected: " +
expected); | |
| 74 } | |
| 75 } | |
| 76 function logCheck(description, success) | |
| 77 { | |
| 78 InspectorTest.log(description + ": " + (success ? "PASS" : "FAIL")); | |
| 79 } | |
| 80 | |
| 81 var firstStep = { callback: enableDebugger }; | |
| 82 | |
| 83 runRequestSeries(firstStep); | |
| 84 | |
| 85 function enableDebugger() { | |
| 86 return { command: "Debugger.enable", params: {}, callback: evalFunction
}; | |
| 87 } | |
| 88 | |
| 89 function evalFunction(response) { | |
| 90 var expression = "TestExpression(2, 4)"; | |
| 91 return { command: "Runtime.evaluate", params: { expression: expression }
, callback: callbackEvalFunction }; | |
| 92 } | |
| 93 | |
| 94 function callbackEvalFunction(result) { | |
| 95 InspectorTest.log("Function evaluate: " + JSON.stringify(result.result))
; | |
| 96 logEqualsCheck(result.result.value, 6); | |
| 97 | |
| 98 return { command: "Runtime.evaluate", params: { expression: "TestExpress
ion" }, callback: callbackEvalFunctionObject }; | |
| 99 } | |
| 100 | |
| 101 function callbackEvalFunctionObject(result) { | |
| 102 return { command: "Runtime.getProperties", params: { objectId: result.re
sult.objectId }, callback: callbackFunctionDetails }; | |
| 103 } | |
| 104 | |
| 105 function callbackFunctionDetails(result) | |
| 106 { | |
| 107 var scriptId; | |
| 108 for (var prop of result.internalProperties) { | |
| 109 if (prop.name === "[[FunctionLocation]]") | |
| 110 scriptId = prop.value.value.scriptId; | |
| 111 } | |
| 112 return createScriptManipulationArc(scriptId, null); | |
| 113 } | |
| 114 | |
| 115 // Several steps with scriptId in context. | |
| 116 function createScriptManipulationArc(scriptId, next) { | |
| 117 return { command: "Debugger.getScriptSource", params: { scriptId: script
Id }, callback: callbackGetScriptSource }; | |
| 118 | |
| 119 var originalText; | |
| 120 | |
| 121 function callbackGetScriptSource(result) { | |
| 122 originalText = result.scriptSource; | |
| 123 var patched = originalText.replace("a + b", "a * b"); | |
| 124 | |
| 125 return { command: "Debugger.setScriptSource", params: { scriptId: sc
riptId, scriptSource: patched }, callback: callbackSetScriptSource }; | |
| 126 } | |
| 127 | |
| 128 function callbackSetScriptSource(result) { | |
| 129 var expression = "TestExpression(2, 4)"; | |
| 130 return { command: "Runtime.evaluate", params: { expression: expressi
on }, callback: callbackEvalFunction2 }; | |
| 131 } | |
| 132 | |
| 133 function callbackEvalFunction2(result) { | |
| 134 InspectorTest.log("Function evaluate: " + JSON.stringify(result.resu
lt)); | |
| 135 logEqualsCheck(result.result.value, 8); | |
| 136 | |
| 137 var patched = originalText.replace("a + b", "a # b"); | |
| 138 | |
| 139 return { command: "Debugger.setScriptSource", params: { scriptId: sc
riptId, scriptSource: patched }, callback: errorCallbackSetScriptSource2 }; | |
| 140 } | |
| 141 | |
| 142 function errorCallbackSetScriptSource2(result) { | |
| 143 var exceptionDetails = result.exceptionDetails; | |
| 144 logCheck("Has error reported", !!exceptionDetails); | |
| 145 logCheck("Reported error is a compile error", !!exceptionDetails); | |
| 146 if (exceptionDetails) | |
| 147 logEqualsCheck(exceptionDetails.lineNumber, 1); | |
| 148 return next; | |
| 149 } | |
| 150 } | |
| 151 } | |
| 152 </script> | |
| 153 </head> | |
| 154 <body onLoad="runTest();"> | |
| 155 </body> | |
| 156 </html> | |
| OLD | NEW |