Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector-protocol / debugger / setScriptSource.html
blob92fb715585a7c335028fd0e33c39381c48c5ce2e
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script type="text/javascript" src="resources/liveedit-me.js"></script>
5 <script>
7 function test()
9 // A general-purpose engine for sending a sequence of protocol commands.
10 // The clients provide requests and response handlers, while the engine catches
11 // errors and makes sure that once there's nothing to do completeTest() is called.
12 // @param step is an object with command, params and callback fields
13 function runRequestSeries(step) {
14 processStep(step);
16 function processStep(currentStep) {
17 try {
18 processStepOrFail(currentStep);
19 } catch (e) {
20 InspectorTest.log(e.stack);
21 InspectorTest.completeTest();
25 function processStepOrFail(currentStep) {
26 if (!currentStep) {
27 InspectorTest.completeTest();
28 return;
30 if (!currentStep.command) {
31 // A simple loopback step.
32 var next = currentStep.callback();
33 processStep(next);
34 return;
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.command + "' failed");
43 InspectorTest.completeTest();
44 return;
46 try {
47 next = currentStep.errorHandler(response.error);
48 } catch (e) {
49 InspectorTest.log(e.stack);
50 InspectorTest.completeTest();
51 return;
53 } else {
54 try {
55 next = currentStep.callback(response.result);
56 } catch (e) {
57 InspectorTest.log(e.stack);
58 InspectorTest.completeTest();
59 return;
62 processStep(next);
64 InspectorTest.sendCommand(currentStep.command, currentStep.params, innerCallback);
68 function logEqualsCheck(actual, expected)
70 if (actual == expected) {
71 InspectorTest.log("PASS, result value: " + actual);
72 } else {
73 InspectorTest.log("FAIL, actual value: " + actual + ", expected: " + expected);
76 function logCheck(description, success)
78 InspectorTest.log(description + ": " + (success ? "PASS" : "FAIL"));
81 var firstStep = { callback: enableDebugger };
83 runRequestSeries(firstStep);
85 function enableDebugger() {
86 return { command: "Debugger.enable", params: {}, callback: evalFunction };
89 function evalFunction(response) {
90 var expression = "TestExpression(2, 4)";
91 return { command: "Runtime.evaluate", params: { expression: expression }, callback: callbackEvalFunction };
94 function callbackEvalFunction(result) {
95 InspectorTest.log("Function evaluate: " + JSON.stringify(result.result));
96 logEqualsCheck(result.result.value, 6);
98 return { command: "Runtime.evaluate", params: { expression: "TestExpression" }, callback: callbackEvalFunctionObject };
101 function callbackEvalFunctionObject(result) {
102 return { command: "Debugger.getFunctionDetails", params: { functionId: result.result.objectId }, callback: callbackFunctionDetails };
105 function callbackFunctionDetails(result) {
106 return createScriptManipulationArc(result.details.location.scriptId, null);
109 // Several steps with scriptId in context.
110 function createScriptManipulationArc(scriptId, next) {
111 return { command: "Debugger.getScriptSource", params: { scriptId: scriptId }, callback: callbackGetScriptSource };
113 var originalText;
115 function callbackGetScriptSource(result) {
116 originalText = result.scriptSource;
117 var patched = originalText.replace("a + b", "a * b");
119 return { command: "Debugger.setScriptSource", params: { scriptId: scriptId, scriptSource: patched }, callback: callbackSetScriptSource };
122 function callbackSetScriptSource(result) {
123 var expression = "TestExpression(2, 4)";
124 return { command: "Runtime.evaluate", params: { expression: expression }, callback: callbackEvalFunction2 };
127 function callbackEvalFunction2(result) {
128 InspectorTest.log("Function evaluate: " + JSON.stringify(result.result));
129 logEqualsCheck(result.result.value, 8);
131 var patched = originalText.replace("a + b", "a # b");
133 return { command: "Debugger.setScriptSource", params: { scriptId: scriptId, scriptSource: patched }, errorHandler: errorCallbackSetScriptSource2 };
136 function errorCallbackSetScriptSource2(error) {
137 logEqualsCheck(error.code, -32000);
138 var errorData = error.data;
139 logCheck("Has error reported", !!errorData);
140 if (errorData) {
141 var compileError = errorData.compileError;
142 logCheck("Reported error is a compile error", !!compileError);
143 if (compileError) {
144 logEqualsCheck(compileError.lineNumber, 2);
147 return next;
151 </script>
152 </head>
153 <body onLoad="runTest();">
154 </body>
155 </html>