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>
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
) {
16 function processStep(currentStep
) {
18 processStepOrFail(currentStep
);
20 InspectorTest
.log(e
.stack
);
21 InspectorTest
.completeTest();
25 function processStepOrFail(currentStep
) {
27 InspectorTest
.completeTest();
30 if (!currentStep
.command
) {
31 // A simple loopback step.
32 var next
= currentStep
.callback();
37 var innerCallback = function(response
) {
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();
47 next
= currentStep
.errorHandler(response
.error
);
49 InspectorTest
.log(e
.stack
);
50 InspectorTest
.completeTest();
55 next
= currentStep
.callback(response
.result
);
57 InspectorTest
.log(e
.stack
);
58 InspectorTest
.completeTest();
64 InspectorTest
.sendCommand(currentStep
.command
, currentStep
.params
, innerCallback
);
68 function logEqualsCheck(actual
, expected
)
70 if (actual
== expected
) {
71 InspectorTest
.log("PASS, result value: " + actual
);
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
};
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
);
141 var compileError
= errorData
.compileError
;
142 logCheck("Reported error is a compile error", !!compileError
);
144 logEqualsCheck(compileError
.lineNumber
, 2);
153 <body onLoad=
"runTest();">