InspectorTest = {};
InspectorTest._dispatchTable = [];
InspectorTest._requestId = -1;
+InspectorTest._dumpInspectorProtocolMessages = false;
InspectorTest.eventHandler = {};
+InspectorTest.startDumpingProtocolMessages = function()
+{
+ InspectorTest._dumpInspectorProtocolMessages = true;
+}
+
/**
* @param {string} method
* @param {object} params
"params": params,
"id": this._requestId };
+ if (InspectorTest._dumpInspectorProtocolMessages)
+ testRunner.logToStderr("frontend: " + JSON.stringify(messageObject));
InspectorFrontendHost.sendMessageToBackend(JSON.stringify(messageObject));
return this._requestId;
}
/**
- * @param {string} message
+ * @param {string|!Object} messageOrObject
*/
-InspectorFrontendAPI.dispatchMessage = function(message)
+InspectorFrontendAPI.dispatchMessage = function(messageOrObject)
{
- var messageObject = JSON.parse(message);
+ if (InspectorTest._dumpInspectorProtocolMessages)
+ testRunner.logToStderr("backend: " + (typeof messageOrObject === "string" ? messageOrObject : JSON.stringify(messageOrObject)));
+ var messageObject = (typeof messageOrObject === "string" ? JSON.parse(messageOrObject) : messageOrObject);
var messageId = messageObject["id"];
try {
if (typeof messageId === "number") {
eventHandler(messageObject);
}
} catch(e) {
- InspectorTest.log("Exception when dispatching message: " + e + "\n\n message = " + JSON.stringify(messageObject, null, 2));
+ InspectorTest.log("Exception when dispatching message: " + e + "\n" + e.stack + "\n message = " + JSON.stringify(messageObject, null, 2));
InspectorTest.completeTest();
}
}
this.sendCommand("Runtime.evaluate", { "expression": "closeTest();"} );
}
+/**
+ * Evaluates string in page.
+ * @param {string} message
+ * @param {!function} callback
+ */
+InspectorTest.evaluateInPage = function(string, callback)
+{
+ this.sendCommand("Runtime.evaluate", { "expression": string }, function(message) {
+ if (message.error)
+ InspectorTest.log("Error while executing '" + string + "': " + message.error.message);
+ else
+ callback();
+ });
+};
+
InspectorTest.completeTestIfError = function(messageObject)
{
if (messageObject.error) {