| 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 | |
| 146 /** | 140 /** |
| 147 * @param {string|!Object} messageOrObject | 141 * @param {string|!Object} messageOrObject |
| 148 */ | 142 */ |
| 149 DevToolsAPI.dispatchMessage = function(messageOrObject) | 143 DevToolsAPI.dispatchMessage = function(messageOrObject) |
| 150 { | 144 { |
| 151 var messageObject = (typeof messageOrObject === "string" ? JSON.parse(messag
eOrObject) : messageOrObject); | 145 var messageObject = (typeof messageOrObject === "string" ? JSON.parse(messag
eOrObject) : messageOrObject); |
| 152 if (InspectorTest._dumpInspectorProtocolMessages) | 146 if (InspectorTest._dumpInspectorProtocolMessages) |
| 153 testRunner.logToStderr("backend: " + JSON.stringify(messageObject)); | 147 testRunner.logToStderr("backend: " + JSON.stringify(messageObject)); |
| 154 var messageId = messageObject["id"]; | 148 var messageId = messageObject["id"]; |
| 155 try { | 149 try { |
| 156 if (typeof messageId === "number") { | 150 if (typeof messageId === "number") { |
| 157 var handler = InspectorTest._dispatchTable[messageId]; | 151 var handler = InspectorTest._dispatchTable[messageId]; |
| 158 if (handler && typeof handler === "function") | 152 if (handler && typeof handler === "function") |
| 159 handler(messageObject); | 153 handler(messageObject); |
| 160 } else { | 154 } else { |
| 161 var eventName = messageObject["method"]; | 155 var eventName = messageObject["method"]; |
| 162 var eventHandler = InspectorTest.eventHandler[eventName]; | 156 var eventHandler = InspectorTest.eventHandler[eventName]; |
| 163 if (eventHandler) | 157 if (eventHandler) |
| 164 eventHandler(messageObject); | 158 eventHandler(messageObject); |
| 165 } | 159 } |
| 166 } catch(e) { | 160 } catch(e) { |
| 167 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.
stack + "\n message = " + JSON.stringify(messageObject, null, 2)); | 161 InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.
stack + "\n message = " + JSON.stringify(messageObject, null, 2)); |
| 168 InspectorTest.completeTest(); | 162 InspectorTest.completeTest(); |
| 169 } | 163 } |
| 170 } | 164 } |
| 171 | 165 |
| 172 /** | 166 /** |
| 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 /** | |
| 187 * Logs message to document. | 167 * Logs message to document. |
| 188 * @param {string} message | 168 * @param {string} message |
| 189 */ | 169 */ |
| 190 InspectorTest.log = function(message) | 170 InspectorTest.log = function(message) |
| 191 { | 171 { |
| 192 this.sendCommand("Runtime.evaluate", { "expression": "log(" + JSON.stringify
(message) + ")" } ); | 172 this.sendCommand("Runtime.evaluate", { "expression": "log(" + JSON.stringify
(message) + ")" } ); |
| 193 } | 173 } |
| 194 | 174 |
| 195 /** | 175 /** |
| 196 * Formats and logs object to document. | 176 * Formats and logs object to document. |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 var callbacks = pendingPromiseEvalRequests[callId]; | 373 var callbacks = pendingPromiseEvalRequests[callId]; |
| 394 if (!callbacks) { | 374 if (!callbacks) { |
| 395 InspectorTest.log("Missing callback for async eval " + callId + ", perha
ps callback invoked twice?"); | 375 InspectorTest.log("Missing callback for async eval " + callId + ", perha
ps callback invoked twice?"); |
| 396 return; | 376 return; |
| 397 } | 377 } |
| 398 var callback = didResolve ? callbacks.resolve : callbacks.reject; | 378 var callback = didResolve ? callbacks.resolve : callbacks.reject; |
| 399 delete pendingPromiseEvalRequests[callId]; | 379 delete pendingPromiseEvalRequests[callId]; |
| 400 callback(value); | 380 callback(value); |
| 401 } | 381 } |
| 402 | 382 |
| 403 window.addEventListener("load", InspectorTest.readyForTest.bind(InspectorTest),
false); | 383 InspectorTest.eventHandler["Inspector.evaluateForTestInFrontend"] = function(mes
sage) |
| 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); |
| 404 | 399 |
| 405 </script> | 400 </script> |
| 406 </head> | 401 </head> |
| 407 </html> | 402 </html> |
| OLD | NEW |