2011-03-03 Ilya Tikhonovsky <loislo@chromium.org>
authorloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2011 11:11:58 +0000 (11:11 +0000)
committerloislo@chromium.org <loislo@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2011 11:11:58 +0000 (11:11 +0000)
        Reviewed by Yury Semikhatsky.

        Web Inspector: introduce a protocol test for RuntimeAgent API.
        https://bugs.webkit.org/show_bug.cgi?id=55482

        * http/tests/inspector/protocol-test.js: Added.
        (initialize_ProtocolTest.InspectorTest.filterProps):
        (initialize_ProtocolTest.InspectorTest._dumpStepResult):
        (initialize_ProtocolTest.InspectorTest._runNextStep):
        (initialize_ProtocolTest.InspectorTest.runProtocolTestSuite):
        (initialize_ProtocolTest):
        * inspector/protocol/runtime-agent-expected.txt: Added.
        * inspector/protocol/runtime-agent.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@80341 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/http/tests/inspector/inspector-test.js
LayoutTests/http/tests/inspector/protocol-test.js [new file with mode: 0644]
LayoutTests/inspector/protocol/runtime-agent-expected.txt [new file with mode: 0644]
LayoutTests/inspector/protocol/runtime-agent.html [new file with mode: 0644]

index e3b0d70d8b492eccf132d2c27a31307b600a2b30..3113847e6bc5be55413769b45ce1dbe7255372b7 100644 (file)
@@ -1,3 +1,19 @@
+2011-03-03  Ilya Tikhonovsky  <loislo@chromium.org>
+
+        Reviewed by Yury Semikhatsky.
+
+        Web Inspector: introduce a protocol test for RuntimeAgent API.
+        https://bugs.webkit.org/show_bug.cgi?id=55482
+
+        * http/tests/inspector/protocol-test.js: Added.
+        (initialize_ProtocolTest.InspectorTest.filterProps):
+        (initialize_ProtocolTest.InspectorTest._dumpStepResult):
+        (initialize_ProtocolTest.InspectorTest._runNextStep):
+        (initialize_ProtocolTest.InspectorTest.runProtocolTestSuite):
+        (initialize_ProtocolTest):
+        * inspector/protocol/runtime-agent-expected.txt: Added.
+        * inspector/protocol/runtime-agent.html: Added.
+
 2011-03-03  Pavel Feldman  <pfeldman@chromium.org>
 
         Reviewed by Yury Semikhatsky.
index cf66bd43ed59fc8cfa20407e154e0fcb3966e78a..dd8d19283c6e0586db47898fb7bd08c5bf7f0922 100644 (file)
@@ -90,7 +90,7 @@ InspectorTest.addObject = function(object, nondeterministicProps, prefix, firstL
     firstLinePrefix = firstLinePrefix || prefix;
     InspectorTest.addResult(firstLinePrefix + "{");
     for (var prop in object) {
-        if (!object.hasOwnProperty(prop))
+        if (typeof object.hasOwnProperty === "function" && !object.hasOwnProperty(prop))
             continue;
         var prefixWithName = prefix + "    " + prop + " : ";
         var propValue = object[prop];
diff --git a/LayoutTests/http/tests/inspector/protocol-test.js b/LayoutTests/http/tests/inspector/protocol-test.js
new file mode 100644 (file)
index 0000000..bd74b62
--- /dev/null
@@ -0,0 +1,89 @@
+var initialize_ProtocolTest = function() {
+
+InspectorTest.filterProps = function(something, nondeterministicProps)
+{
+    if (something instanceof Object)
+        for (var prop in something)
+            if (prop in nondeterministicProps)
+                something[prop] = "<" + typeof something[prop] + ">";
+            else
+                something[prop] = this.filterProps(something[prop], nondeterministicProps);
+    else if (something instanceof Array)
+        for (var i = 0; i < something.length; ++i)
+            something[i] = this.filterProps(something[i], nondeterministicProps);
+    else if (typeof something === "number")
+        something = "<number>";
+    return something;
+};
+
+InspectorTest._dumpTestResult = function(callArguments)
+{
+    var functionName = callArguments.shift();
+    this.filterProps(callArguments, this._nondeterministicProps);
+    var expression = JSON.stringify(callArguments);
+    expression = expression.slice(1, expression.length - 1).replace(/\"<number>\"/g, "<number>");;
+    var sentObject = JSON.parse(this._lastSentTestMessage);
+    var receivedObject = (typeof this._lastReceivedMessage === "string") ? JSON.parse(this._lastReceivedMessage) : this._lastReceivedMessage;
+
+    InspectorTest.addResult("-----------------------------------------------------------");
+    InspectorTest.addResult(this._agentName + "." + functionName + "(" + expression + ")");
+    InspectorTest.addResult("");
+    InspectorTest.addResult("request:");
+    InspectorTest.addObject(sentObject, this._nondeterministicProps);
+    InspectorTest.addResult("");
+    InspectorTest.addResult("response:");
+    InspectorTest.addObject(receivedObject, this._nondeterministicProps);
+    InspectorTest.addResult("");
+};
+
+InspectorTest._callback = function(callArguments, result)
+{
+    this._dumpTestResult(callArguments);
+    this._runNextStep(result);
+};
+
+InspectorTest._runNextStep = function(result)
+{
+    var step = ++this._step;
+    var nextTest = this._testSuite[step];
+    if (nextTest) {
+        var nextTestCopy = JSON.parse(JSON.stringify(nextTest));
+        nextTest.push(this._callback.bind(this, nextTestCopy));
+        var functionName = nextTest.shift();
+        this._agentCoverage[functionName] = "checked";
+        this._agent[functionName].apply(this._agent, nextTest);
+        this._lastSentTestMessage = this._lastSentMessage;
+    }
+    else {
+        InspectorTest.addResult("===========================================================");
+        InspectorTest.addResult("Coverage for " + this._agentName);
+        InspectorTest.addObject(this._agentCoverage);
+        InspectorBackend.dispatch = this._originalDispatch;
+        InspectorFrontendHost.sendMessageToBackend = this._originalSendMessageToBackend;
+        this.completeTest();
+    }
+};
+
+InspectorTest.runProtocolTestSuite = function(agentName, testSuite, nondeterministicProps)
+{
+    this._agentName = agentName;
+    this._testSuite = testSuite;
+    this._nondeterministicProps = {};
+    for (var i = 0; i < nondeterministicProps.length; ++i)
+        this._nondeterministicProps[nondeterministicProps[i]] = true;
+    this._agent = window[agentName];
+    this._agentCoverage = {};
+    for (var key in this._agent)
+        this._agentCoverage[key] = "not checked";
+    this._step = -1;
+
+    this._originalDispatch = InspectorBackend.dispatch;
+    InspectorBackend.dispatch = function(message) { InspectorTest._lastReceivedMessage = message; InspectorTest._originalDispatch.apply(InspectorBackend, [message]); }
+
+    this._originalSendMessageToBackend = InspectorFrontendHost.sendMessageToBackend;
+    InspectorFrontendHost.sendMessageToBackend = function(message) { InspectorTest._lastSentMessage = message; InspectorTest._originalSendMessageToBackend.apply(InspectorFrontendHost, [message]); }
+
+    this._runNextStep();
+};
+
+};
\ No newline at end of file
diff --git a/LayoutTests/inspector/protocol/runtime-agent-expected.txt b/LayoutTests/inspector/protocol/runtime-agent-expected.txt
new file mode 100644 (file)
index 0000000..b14526c
--- /dev/null
@@ -0,0 +1,309 @@
+Protocol stability test. It is dumping request/response pairs of RuntimeAgent functions.
+
+-----------------------------------------------------------
+RuntimeAgent.evaluate("testObject","test",false)
+
+request:
+{
+    seq : <number>
+    domain : "Runtime"
+    command : "evaluate"
+    arguments : {
+        expression : "testObject"
+        objectGroup : "test"
+        includeCommandLineAPI : false
+    }
+}
+
+response:
+{
+    seq : <number>
+    domain : "Runtime"
+    success : true
+    body : {
+        result : {
+            objectId : {
+                injectedScriptId : <number>
+                id : <number>
+                groupName : "test"
+            }
+            type : "object"
+            description : "TestObject"
+            hasChildren : true
+        }
+    }
+}
+
+-----------------------------------------------------------
+RuntimeAgent.evaluateOn({"injectedScriptId":<number>,"id":<number>,"groupName":"test"},"this.assignedByEvaluateOn = \"evaluateOn function works fine\";")
+
+request:
+{
+    seq : <number>
+    domain : "Runtime"
+    command : "evaluateOn"
+    arguments : {
+        objectId : {
+            injectedScriptId : <number>
+            id : <number>
+            groupName : "test"
+        }
+        expression : "this.assignedByEvaluateOn = "evaluateOn function works fine";"
+    }
+}
+
+response:
+{
+    seq : <number>
+    domain : "Runtime"
+    success : true
+    body : {
+        result : {
+            objectId : null
+            type : "undefined"
+            description : "undefined"
+            hasChildren : false
+        }
+    }
+}
+
+-----------------------------------------------------------
+RuntimeAgent.setPropertyValue({"injectedScriptId":<number>,"id":<number>,"groupName":"test"},"assignedBySetPropertyValue","true")
+
+request:
+{
+    seq : <number>
+    domain : "Runtime"
+    command : "setPropertyValue"
+    arguments : {
+        objectId : {
+            injectedScriptId : <number>
+            id : <number>
+            groupName : "test"
+        }
+        propertyName : "assignedBySetPropertyValue"
+        expression : "true"
+    }
+}
+
+response:
+{
+    seq : <number>
+    domain : "Runtime"
+    success : true
+    body : {
+        result : true
+    }
+}
+
+-----------------------------------------------------------
+RuntimeAgent.setPropertyValue({"injectedScriptId":<number>,"id":<number>,"groupName":"test"},"removedBySetPropertyValue","")
+
+request:
+{
+    seq : <number>
+    domain : "Runtime"
+    command : "setPropertyValue"
+    arguments : {
+        objectId : {
+            injectedScriptId : <number>
+            id : <number>
+            groupName : "test"
+        }
+        propertyName : "removedBySetPropertyValue"
+        expression : ""
+    }
+}
+
+response:
+{
+    seq : <number>
+    domain : "Runtime"
+    success : true
+    body : {
+        result : true
+    }
+}
+
+-----------------------------------------------------------
+RuntimeAgent.getProperties({"injectedScriptId":<number>,"id":<number>,"groupName":"test"},false,false)
+
+request:
+{
+    seq : <number>
+    domain : "Runtime"
+    command : "getProperties"
+    arguments : {
+        objectId : {
+            injectedScriptId : <number>
+            id : <number>
+            groupName : "test"
+        }
+        ignoreHasOwnProperty : false
+        abbreviate : false
+    }
+}
+
+response:
+{
+    seq : <number>
+    domain : "Runtime"
+    success : true
+    body : {
+        result : {
+            0 : {
+                name : "assignedByEvaluateOn"
+                value : {
+                    objectId : null
+                    type : "string"
+                    description : "evaluateOn function works fine"
+                    hasChildren : false
+                }
+            }
+            1 : {
+                name : "assignedBySetPropertyValue"
+                value : {
+                    objectId : null
+                    type : "boolean"
+                    description : "true"
+                    hasChildren : false
+                }
+            }
+            2 : {
+                name : "__proto__"
+                value : {
+                    objectId : {
+                        injectedScriptId : <number>
+                        id : <number>
+                        groupName : "test"
+                    }
+                    type : "object"
+                    description : "TestObject"
+                    hasChildren : true
+                }
+            }
+        }
+    }
+}
+
+-----------------------------------------------------------
+RuntimeAgent.releaseObject({"injectedScriptId":<number>,"id":<number>,"groupName":"test"})
+
+request:
+{
+    seq : <number>
+    domain : "Runtime"
+    command : "releaseObject"
+    arguments : {
+        objectId : {
+            injectedScriptId : <number>
+            id : <number>
+            groupName : "test"
+        }
+    }
+}
+
+response:
+{
+    seq : <number>
+    domain : "Runtime"
+    success : true
+}
+
+-----------------------------------------------------------
+RuntimeAgent.releaseWrapperObjectGroup(<number>,"test")
+
+request:
+{
+    seq : <number>
+    domain : "Runtime"
+    command : "releaseWrapperObjectGroup"
+    arguments : {
+        injectedScriptId : <number>
+        objectGroup : "test"
+    }
+}
+
+response:
+{
+    seq : <number>
+    domain : "Runtime"
+    success : true
+}
+
+-----------------------------------------------------------
+RuntimeAgent.getCompletions("testProperty",false)
+
+request:
+{
+    seq : <number>
+    domain : "Runtime"
+    command : "getCompletions"
+    arguments : {
+        expression : "testProperty"
+        includeCommandLineAPI : false
+    }
+}
+
+response:
+{
+    seq : <number>
+    domain : "Runtime"
+    success : true
+    body : {
+        result : {
+        }
+    }
+}
+
+-----------------------------------------------------------
+RuntimeAgent.getCompletions("testProperty",true)
+
+request:
+{
+    seq : <number>
+    domain : "Runtime"
+    command : "getCompletions"
+    arguments : {
+        expression : "testProperty"
+        includeCommandLineAPI : true
+    }
+}
+
+response:
+{
+    seq : <number>
+    domain : "Runtime"
+    success : true
+    body : {
+        result : {
+            $ : true
+            $$ : true
+            $x : true
+            dir : true
+            dirxml : true
+            keys : true
+            values : true
+            profile : true
+            profileEnd : true
+            monitorEvents : true
+            unmonitorEvents : true
+            inspect : true
+            copy : true
+            clear : true
+        }
+    }
+}
+
+===========================================================
+Coverage for RuntimeAgent
+{
+    evaluate : "checked"
+    evaluateOn : "checked"
+    getCompletions : "checked"
+    getProperties : "checked"
+    setPropertyValue : "checked"
+    releaseObject : "checked"
+    releaseWrapperObjectGroup : "checked"
+}
+
diff --git a/LayoutTests/inspector/protocol/runtime-agent.html b/LayoutTests/inspector/protocol/runtime-agent.html
new file mode 100644 (file)
index 0000000..eceeccc
--- /dev/null
@@ -0,0 +1,45 @@
+<html>
+<head>
+<script src="../../http/tests/inspector/inspector-test.js"></script>
+<script src="../../http/tests/inspector/protocol-test.js"></script>
+<script>
+
+function TestObject()
+{
+    this.removedBySetPropertyValue = "doesn't work";
+}
+
+testObject = new TestObject();
+testProperty = true;
+
+function test()
+{
+    function callback(result)
+    {
+        var testSuite = [
+            ["evaluate", 'testObject', 'test', false],
+            ["evaluateOn", result.objectId, 'this.assignedByEvaluateOn = "evaluateOn function works fine";'],
+            ["setPropertyValue", result.objectId, 'assignedBySetPropertyValue', 'true'],
+            ["setPropertyValue", result.objectId, 'removedBySetPropertyValue', ''],
+            ["getProperties", result.objectId, false, false],
+            ["releaseObject", result.objectId],
+            ["releaseWrapperObjectGroup", result.objectId.injectedScriptId, 'test'],
+            ["getCompletions", 'testProperty', false],
+            ["getCompletions", 'testProperty', true]];
+
+        InspectorTest.runProtocolTestSuite("RuntimeAgent", testSuite, ['seq', 'id', 'injectedScriptId']);
+    }
+
+    RuntimeAgent.evaluate('window.testObject', 'test', false, callback);
+}
+
+</script>
+</head>
+
+<body onload="runTest()">
+<p>
+Protocol stability test. It is dumping request/response pairs of RuntimeAgent functions.
+</p>
+
+</body>
+</html>