3 <script type=
"text/javascript" src=
"../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
8 // A general-purpose engine for sending a sequence of protocol commands.
9 // The clients provide requests and response handlers, while the engine catches
10 // errors and makes sure that once there's nothing to do completeTest() is called.
11 // @param step is an object with command, params and callback fields
12 function runRequestSeries(step
) {
15 function processStep(s
) {
19 InspectorTest
.log(e
.stack
);
20 InspectorTest
.completeTest();
24 function processStepOrFail(s
) {
26 InspectorTest
.completeTest();
30 // A simple loopback step.
31 var next
= s
.callback();
36 var innerCallback = function(response
) {
38 if ("error" in response
) {
39 if (!("errorHandler" in s
)) {
40 // Error message is not logged intentionally, it may be platform-specific.
41 InspectorTest
.log("Protocol command '" + s
.command
+ "' failed");
42 InspectorTest
.completeTest();
46 next
= s
.errorHandler(response
.error
);
48 InspectorTest
.log(e
.stack
);
49 InspectorTest
.completeTest();
54 next
= s
.callback(response
.result
);
56 InspectorTest
.log(e
.stack
);
57 InspectorTest
.completeTest();
63 InspectorTest
.sendCommand(s
.command
, s
.params
, innerCallback
);
67 var firstStep
= { callback
: enableDebugger
};
69 runRequestSeries(firstStep
);
71 function enableDebugger() {
72 return { command
: "Debugger.enable", params
: {}, callback
: evalFunction
};
75 // Testing function/closure scopes.
77 function evalFunction(response
) {
78 var expression
= "(function(p){var r=5;with({year:2013}){return function Closure(q){return p+q+r+year};}})('ttt')";
79 return { command
: "Runtime.evaluate", params
: {expression
: expression
}, callback
: callbackEvalFunction
};
82 function callbackEvalFunction(result
) {
83 var id
= result
.result
.objectId
;
85 throw new Error("objectId is expected");
86 return createCheckFunctionStepChain(id
);
89 function createCheckFunctionStepChain(functionObjectId
) {
91 objectId
: functionObjectId
,
92 functionDeclaration
: "function(){return this(true);}"
95 command
: "Runtime.callFunctionOn", params
: params
, callback
: callbackLogClosureEval
98 function callbackLogClosureEval(result
) {
99 InspectorTest
.log("Closure returns: " + JSON
.stringify(result
.result
));
100 InspectorTest
.log(" (expected: 'ttttrue52013')");
103 functionObjectId
: functionObjectId
,
106 newValue
: { value
: 4 }
109 command
: "Debugger.setVariableValue", params
: params
, callback
: setVariableCallback
113 function setVariableCallback() {
114 InspectorTest
.log("Debugger.setVariableValue OK");
117 objectId
: functionObjectId
,
118 functionDeclaration
: "function(){return this(true);}"
121 command
: "Runtime.callFunctionOn", params
: params
, callback
: callbackLogClosureEval2
126 function callbackLogClosureEval2(result
) {
127 InspectorTest
.log("Closure returns: " + JSON
.stringify(result
.result
));
128 InspectorTest
.log(" (expected: 'ttttrue42013')");
131 // No target is specified
134 newValue
: { value
: 4 }
137 command
: "Debugger.setVariableValue", params
: params
, errorHandler
: setVariableErrorCallback3
141 function setVariableErrorCallback3(error
) {
142 InspectorTest
.log("Expected error: " + JSON
.stringify(error
));
145 functionObjectId
: functionObjectId
,
146 scopeNumber
: 100, // Wrong scope number
148 newValue
: { value
: 4 }
151 command
: "Debugger.setVariableValue", params
: params
, errorHandler
: setVariableErrorCallback4
155 function setVariableErrorCallback4(error
) {
156 InspectorTest
.log("Expected error");
159 functionObjectId
: functionObjectId
,
161 variableName
: "bad", // Wrong variable name
162 newValue
: { value
: 4 }
165 command
: "Debugger.setVariableValue", params
: params
, errorHandler
: setVariableErrorCallback5
169 function setVariableErrorCallback5(error
) {
170 InspectorTest
.log("Expected error");
179 <body onLoad=
"runTest();">