OLD | NEW |
1 <!-- | 1 <!-- |
2 Copyright (C) 2012 Samsung Electronics. All rights reserved. | 2 Copyright (C) 2012 Samsung Electronics. All rights reserved. |
3 | 3 |
4 Redistribution and use in source and binary forms, with or without | 4 Redistribution and use in source and binary forms, with or without |
5 modification, are permitted provided that the following conditions | 5 modification, are permitted provided that the following conditions |
6 are met: | 6 are met: |
7 | 7 |
8 1. Redistributions of source code must retain the above copyright | 8 1. Redistributions of source code must retain the above copyright |
9 notice, this list of conditions and the following disclaimer. | 9 notice, this list of conditions and the following disclaimer. |
10 2. Redistributions in binary form must reproduce the above copyright | 10 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 * @param {function({object} messageObject)=} handler | 130 * @param {function({object} messageObject)=} handler |
131 */ | 131 */ |
132 InspectorTest.sendRawCommand = function(command, handler) | 132 InspectorTest.sendRawCommand = function(command, handler) |
133 { | 133 { |
134 this._dispatchTable[++this._requestId] = handler; | 134 this._dispatchTable[++this._requestId] = handler; |
135 var embedderMessage = { "id": ++this._embedderRequestId, "method": "dispatch
ProtocolMessage", "params": [command] }; | 135 var embedderMessage = { "id": ++this._embedderRequestId, "method": "dispatch
ProtocolMessage", "params": [command] }; |
136 DevToolsHost.sendMessageToEmbedder(JSON.stringify(embedderMessage)); | 136 DevToolsHost.sendMessageToEmbedder(JSON.stringify(embedderMessage)); |
137 return this._requestId; | 137 return this._requestId; |
138 } | 138 } |
139 | 139 |
| 140 InspectorTest.readyForTest = function() |
| 141 { |
| 142 var embedderMessage = { "id": ++this._embedderRequestId, "method": "readyFor
Test" }; |
| 143 DevToolsHost.sendMessageToEmbedder(JSON.stringify(embedderMessage)); |
| 144 } |
| 145 |
140 /** | 146 /** |
141 * @param {string|!Object} messageOrObject | 147 * @param {string|!Object} messageOrObject |
142 */ | 148 */ |
143 DevToolsAPI.dispatchMessage = function(messageOrObject) | 149 DevToolsAPI.dispatchMessage = function(messageOrObject) |
144 { | 150 { |
145 var messageObject = (typeof messageOrObject === "string" ? JSON.parse(messag
eOrObject) : messageOrObject); | 151 var messageObject = (typeof messageOrObject === "string" ? JSON.parse(messag
eOrObject) : messageOrObject); |
146 if (InspectorTest._dumpInspectorProtocolMessages) | 152 if (InspectorTest._dumpInspectorProtocolMessages) |
147 testRunner.logToStderr("backend: " + JSON.stringify(messageObject)); | 153 testRunner.logToStderr("backend: " + JSON.stringify(messageObject)); |
148 var messageId = messageObject["id"]; | 154 var messageId = messageObject["id"]; |
149 try { | 155 try { |
150 if (typeof messageId === "number") { | 156 if (typeof messageId === "number") { |
151 var handler = InspectorTest._dispatchTable[messageId]; | 157 var handler = InspectorTest._dispatchTable[messageId]; |
152 if (handler && typeof handler === "function") | 158 if (handler && typeof handler === "function") |
153 handler(messageObject); | 159 handler(messageObject); |
154 } else { | 160 } else { |
155 var eventName = messageObject["method"]; | 161 var eventName = messageObject["method"]; |
156 var eventHandler = InspectorTest.eventHandler[eventName]; | 162 var eventHandler = InspectorTest.eventHandler[eventName]; |
157 if (eventHandler) | 163 if (eventHandler) |
158 eventHandler(messageObject); | 164 eventHandler(messageObject); |
159 } | 165 } |
160 } catch(e) { | 166 } catch(e) { |
161 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.
stack + "\n message = " + JSON.stringify(messageObject, null, 2)); | 167 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.
stack + "\n message = " + JSON.stringify(messageObject, null, 2)); |
162 InspectorTest.completeTest(); | 168 InspectorTest.completeTest(); |
163 } | 169 } |
164 } | 170 } |
165 | 171 |
166 /** | 172 /** |
| 173 * @param {number} callId |
| 174 * @param {string} script |
| 175 */ |
| 176 DevToolsAPI.evaluateForTestInFrontend = function(callId, script) |
| 177 { |
| 178 try { |
| 179 eval(script); |
| 180 } catch (e) { |
| 181 InspectorTest.log("FAIL: exception in evaluateForTestInFrontend: " + e); |
| 182 InspectorTest.completeTest(); |
| 183 } |
| 184 } |
| 185 |
| 186 /** |
167 * Logs message to document. | 187 * Logs message to document. |
168 * @param {string} message | 188 * @param {string} message |
169 */ | 189 */ |
170 InspectorTest.log = function(message) | 190 InspectorTest.log = function(message) |
171 { | 191 { |
172 this.sendCommand("Runtime.evaluate", { "expression": "log(" + JSON.stringify
(message) + ")" } ); | 192 this.sendCommand("Runtime.evaluate", { "expression": "log(" + JSON.stringify
(message) + ")" } ); |
173 } | 193 } |
174 | 194 |
175 /** | 195 /** |
176 * Formats and logs object to document. | 196 * Formats and logs object to document. |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 var callbacks = pendingPromiseEvalRequests[callId]; | 393 var callbacks = pendingPromiseEvalRequests[callId]; |
374 if (!callbacks) { | 394 if (!callbacks) { |
375 InspectorTest.log("Missing callback for async eval " + callId + ", perha
ps callback invoked twice?"); | 395 InspectorTest.log("Missing callback for async eval " + callId + ", perha
ps callback invoked twice?"); |
376 return; | 396 return; |
377 } | 397 } |
378 var callback = didResolve ? callbacks.resolve : callbacks.reject; | 398 var callback = didResolve ? callbacks.resolve : callbacks.reject; |
379 delete pendingPromiseEvalRequests[callId]; | 399 delete pendingPromiseEvalRequests[callId]; |
380 callback(value); | 400 callback(value); |
381 } | 401 } |
382 | 402 |
383 InspectorTest.eventHandler["Inspector.evaluateForTestInFrontend"] = function(mes
sage) | 403 window.addEventListener("load", InspectorTest.readyForTest.bind(InspectorTest),
false); |
384 { | |
385 try { | |
386 eval(message.params.script); | |
387 } catch (e) { | |
388 InspectorTest.log("FAIL: exception in evaluateForTestInFrontend: " + e); | |
389 InspectorTest.completeTest(); | |
390 } | |
391 }; | |
392 | |
393 function enableInspectorAgent() | |
394 { | |
395 InspectorTest.sendCommand("Inspector.enable", { }); | |
396 } | |
397 | |
398 window.addEventListener("load", enableInspectorAgent, false); | |
399 | 404 |
400 </script> | 405 </script> |
401 </head> | 406 </head> |
402 </html> | 407 </html> |
OLD | NEW |