Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector-protocol / debugger / debugger-setVariableValue.html
blobf4d9e237fe296a12b0a7224bf800debf6ca6a4e2
1 <html>
2 <head>
3 <script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
4 <script>
6 function test()
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) {
13 processStep(step);
15 function processStep(s) {
16 try {
17 processStepOrFail(s);
18 } catch (e) {
19 InspectorTest.log(e.stack);
20 InspectorTest.completeTest();
24 function processStepOrFail(s) {
25 if (!s) {
26 InspectorTest.completeTest();
27 return;
29 if (!s.command) {
30 // A simple loopback step.
31 var next = s.callback();
32 processStep(next);
33 return;
36 var innerCallback = function(response) {
37 var next;
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();
43 return;
45 try {
46 next = s.errorHandler(response.error);
47 } catch (e) {
48 InspectorTest.log(e.stack);
49 InspectorTest.completeTest();
50 return;
52 } else {
53 try {
54 next = s.callback(response.result);
55 } catch (e) {
56 InspectorTest.log(e.stack);
57 InspectorTest.completeTest();
58 return;
61 processStep(next);
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;
84 if (id === undefined)
85 throw new Error("objectId is expected");
86 return createCheckFunctionStepChain(id);
89 function createCheckFunctionStepChain(functionObjectId) {
90 var params = {
91 objectId: functionObjectId,
92 functionDeclaration: "function(){return this(true);}"
94 return {
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')");
102 var params = {
103 functionObjectId: functionObjectId,
104 scopeNumber: 1,
105 variableName: "r",
106 newValue: { value: 4 }
108 return {
109 command: "Debugger.setVariableValue", params: params, callback: setVariableCallback
113 function setVariableCallback() {
114 InspectorTest.log("Debugger.setVariableValue OK");
116 var params = {
117 objectId: functionObjectId,
118 functionDeclaration: "function(){return this(true);}"
120 return {
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')");
130 var params = {
131 // No target is specified
132 scopeNumber: 1,
133 variableName: "r",
134 newValue: { value: 4 }
136 return {
137 command: "Debugger.setVariableValue", params: params, errorHandler: setVariableErrorCallback3
141 function setVariableErrorCallback3(error) {
142 InspectorTest.log("Expected error: " + JSON.stringify(error));
144 var params = {
145 functionObjectId: functionObjectId,
146 scopeNumber: 100, // Wrong scope number
147 variableName: "r",
148 newValue: { value: 4 }
150 return {
151 command: "Debugger.setVariableValue", params: params, errorHandler: setVariableErrorCallback4
155 function setVariableErrorCallback4(error) {
156 InspectorTest.log("Expected error");
158 var params = {
159 functionObjectId: functionObjectId,
160 scopeNumber: 1,
161 variableName: "bad", // Wrong variable name
162 newValue: { value: 4 }
164 return {
165 command: "Debugger.setVariableValue", params: params, errorHandler: setVariableErrorCallback5
169 function setVariableErrorCallback5(error) {
170 InspectorTest.log("Expected error");
172 // End of test.
173 return;
177 </script>
178 </head>
179 <body onLoad="runTest();">
180 </body>
181 </html>