Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector-protocol / resources / protocol-test.html
index 016870f..bfd6a99 100644 (file)
@@ -31,8 +31,14 @@ InspectorFrontendAPI = {};
 InspectorTest = {};
 InspectorTest._dispatchTable = [];
 InspectorTest._requestId = -1;
+InspectorTest._dumpInspectorProtocolMessages = false;
 InspectorTest.eventHandler = {};
 
+InspectorTest.startDumpingProtocolMessages = function()
+{
+    InspectorTest._dumpInspectorProtocolMessages = true;
+}
+
 /**
  * @param {string} method
  * @param {object} params
@@ -46,6 +52,8 @@ InspectorTest.sendCommand = function(method, params, handler)
                           "params": params,
                           "id": this._requestId };
 
+    if (InspectorTest._dumpInspectorProtocolMessages)
+        testRunner.logToStderr("frontend: " + JSON.stringify(messageObject));
     InspectorFrontendHost.sendMessageToBackend(JSON.stringify(messageObject));
 
     return this._requestId;
@@ -128,11 +136,13 @@ InspectorTest.sendRawCommand = function(command, handler)
 }
 
 /**
- * @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") {
@@ -146,7 +156,7 @@ InspectorFrontendAPI.dispatchMessage = function(message)
                 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();
     }
 }
@@ -228,6 +238,21 @@ InspectorTest.completeTest = function()
     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) {