Web Inspector: Test Runtime.saveResult and $n values
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Sep 2015 02:34:22 +0000 (02:34 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 5 Sep 2015 02:34:22 +0000 (02:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148837

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2015-09-04
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/InjectedScriptSource.js:
(InjectedScript.prototype._evaluateOn):
We don't need to be in the console object group to put the value
in the saved results list. That strong reference will ensure $n
values are always alive even if other object groups were used
when creating and subsequently released.

Source/WebInspectorUI:

* UserInterface/Protocol/InspectorBackend.js:
(InspectorBackendClass):
Initialize the dump logging function different if we are in tests or not.
When in tests, using console.log as well as dumping system activity to
the system console results in an infinite loop of logging!

(InspectorBackendClass.prototype.dispatch):
(InspectorBackendClass.prototype._sendCommandToBackendWithCallback):
Use the logging function we figured out earlier.

LayoutTests:

* inspector/runtime/parse.html: Remove unncessary debug flag.
* inspector/runtime/saveResult-expected.txt: Added.
* inspector/runtime/saveResult.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/inspector/runtime/parse.html
LayoutTests/inspector/runtime/saveResult-expected.txt [new file with mode: 0644]
LayoutTests/inspector/runtime/saveResult.html [new file with mode: 0644]
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/InjectedScriptSource.js
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Protocol/InspectorBackend.js

index b0d807d..50eec97 100644 (file)
@@ -1,3 +1,14 @@
+2015-09-04  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Test Runtime.saveResult and $n values
+        https://bugs.webkit.org/show_bug.cgi?id=148837
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/runtime/parse.html: Remove unncessary debug flag.
+        * inspector/runtime/saveResult-expected.txt: Added.
+        * inspector/runtime/saveResult.html: Added.
+
 2015-09-04  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed, land baseline for one of the newly imported w3c tests.
index 3a4b127..285eafb 100644 (file)
@@ -5,8 +5,6 @@
 <script>
 function test()
 {
-    InspectorTest.dumpActivityToSystemConsole = true;
-
     function outputErrorSourceRange(range) {
         var str = " ".repeat("Source: ".length);
         str += " ".repeat(range.startOffset);
diff --git a/LayoutTests/inspector/runtime/saveResult-expected.txt b/LayoutTests/inspector/runtime/saveResult-expected.txt
new file mode 100644 (file)
index 0000000..2e721c3
--- /dev/null
@@ -0,0 +1,36 @@
+Tests for the Runtime.saveResult command ($n values).
+
+
+== Running test suite: Runtime.saveResult
+-- Running test case: SavePrimitiveValue1
+PASS: Value 123 should become $1.
+
+-- Running test case: SavePrimitiveValue2
+PASS: Value true should become $2.
+
+-- Running test case: RepeatPrimitiveValue1
+PASS: Value 123 should have existed as $1.
+
+-- Running test case: $1MatchesValue1
+PASS: $1 value should be 123.
+
+-- Running test case: SaveObject1
+PASS: New Object {"x":100,"y":200} should become $3.
+
+-- Running test case: SaveObject2
+PASS: New Object {"x":100,"y":200} should become $4.
+
+-- Running test case: RepeatSaveObject1
+PASS: Repeat Object should have existed as $3.
+
+-- Running test case: NoContextWithPrimitiveShouldUseMainContext
+PASS: Value 999 should become $5.
+PASS: Value 999 should have existed as $5.
+
+-- Running test case: ClearConsoleShouldResetValues
+PASS: Value 999 should become $1.
+
+-- Running test case: EvaluateWithSaveIndex
+PASS: Evaluated result 990 should become $2.
+PASS: Evaluated result 999 should match previous value $1.
+
diff --git a/LayoutTests/inspector/runtime/saveResult.html b/LayoutTests/inspector/runtime/saveResult.html
new file mode 100644 (file)
index 0000000..00c8c7c
--- /dev/null
@@ -0,0 +1,181 @@
+<!doctype html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script>
+function test()
+{
+    function createCallArgumentWithValue(value) {
+        return {value};
+    }
+
+    function createCallArgumentWithRemoteObject(remoteObject) {
+        return {objectId: remoteObject.objectId};
+    }
+
+    function remoteObjectForSimpleObject(simpleObject, callback) {
+        InspectorTest.evaluateInPage("(" + JSON.stringify(simpleObject) + ")", callback);
+    }
+
+    let contextId = WebInspector.frameResourceManager.mainFrame.pageExecutionContext.id;
+    let remoteObject1;
+
+    let suite = InspectorTest.createAsyncSuite("Runtime.saveResult");
+
+    suite.addTestCase({
+        name: "SavePrimitiveValue1",
+        description: "Saving a new value should produce a new $n value.",
+        test: (resolve, reject) => {
+            let value = 123;
+            RuntimeAgent.saveResult(createCallArgumentWithValue(value), contextId, (error, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                InspectorTest.expectThat(savedResultIndex === 1, `Value ${value} should become $1.`);
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: "SavePrimitiveValue2",
+        description: "Saving a new value should produce a new $n value.",
+        test: (resolve, reject) => {
+            let value = true;
+            RuntimeAgent.saveResult(createCallArgumentWithValue(value), contextId, (error, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                InspectorTest.expectThat(savedResultIndex === 2, `Value ${value} should become $2.`);
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: "RepeatPrimitiveValue1",
+        description: "Saving a previously saved value should produce the original $n value.",
+        test: (resolve, reject) => {
+            let value = 123;
+            RuntimeAgent.saveResult(createCallArgumentWithValue(value), contextId, (error, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                InspectorTest.expectThat(savedResultIndex === 1, `Value ${value} should have existed as $1.`);
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: "$1MatchesValue1",
+        description: "Evaluating $1 should get us the value we saved previously.",
+        test: (resolve, reject) => {
+            RuntimeAgent.evaluate.invoke({expression: "$1", objectGroup: "test", includeCommandLineAPI: true}, (error, remoteObjectPayload, wasThrown, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                let remoteObject = WebInspector.RemoteObject.fromPayload(remoteObjectPayload);
+                InspectorTest.assert(remoteObject.hasValue(), "RemoteObject for $1 should be a value, not an object.");
+                InspectorTest.expectThat(remoteObject.value === 123, "$1 value should be 123.");
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: "SaveObject1",
+        description: "Saving a new object should produce a new $n value.",
+        test: (resolve, reject) => {
+            let object = {x:100, y:200};
+            remoteObjectForSimpleObject(object, (error, remoteObject) => {
+                remoteObject1 = remoteObject;
+                RuntimeAgent.saveResult(createCallArgumentWithRemoteObject(remoteObject), (error, savedResultIndex) => {
+                    InspectorTest.assert(!error, "Should not be a protocol error.");
+                    InspectorTest.expectThat(savedResultIndex === 3, `New Object ${JSON.stringify(object)} should become $3.`);
+                    resolve();
+                });
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: "SaveObject2",
+        description: "Saving a new object should produce a new $n value.",
+        test: (resolve, reject) => {
+            let object = {x:100, y:200};
+            remoteObjectForSimpleObject(object, (error, remoteObject) => {
+                RuntimeAgent.saveResult(createCallArgumentWithRemoteObject(remoteObject), (error, savedResultIndex) => {
+                    InspectorTest.assert(!error, "Should not be a protocol error.");
+                    InspectorTest.expectThat(savedResultIndex === 4, `New Object ${JSON.stringify(object)} should become $4.`);
+                    resolve();
+                });
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: "RepeatSaveObject1",
+        description: "Saving a previously saved value should produce the original $n value.",
+        test: (resolve, reject) => {
+            RuntimeAgent.saveResult(createCallArgumentWithRemoteObject(remoteObject1), (error, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                InspectorTest.expectThat(savedResultIndex === 3, `Repeat Object should have existed as $3.`);
+                resolve();
+            });
+        }
+    });
+
+    // ------
+
+    suite.addTestCase({
+        name: "NoContextWithPrimitiveShouldUseMainContext",
+        description: "Saving a primitive should specify the context.",
+        test: (resolve, reject) => {
+            let value = 999;
+            RuntimeAgent.saveResult(createCallArgumentWithValue(value), (error, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                InspectorTest.expectThat(savedResultIndex === 5, `Value ${value} should become $5.`);
+            });
+            RuntimeAgent.saveResult(createCallArgumentWithValue(value), contextId, (error, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                InspectorTest.expectThat(savedResultIndex === 5, `Value ${value} should have existed as $5.`);
+                resolve();
+            });
+        }
+    });
+
+    // ------
+
+    suite.addTestCase({
+        name: "ClearConsoleShouldResetValues",
+        description: "Clearing the console should reset the $n values.",
+        test: (resolve, reject) => {
+            let value = 999;
+            ConsoleAgent.clearMessages();
+            RuntimeAgent.saveResult(createCallArgumentWithValue(value), (error, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                InspectorTest.expectThat(savedResultIndex === 1, `Value ${value} should become $1.`);
+                resolve();
+            });
+        }
+    });
+
+    // ------
+
+    suite.addTestCase({
+        name: "EvaluateWithSaveIndex",
+        description: "Evalute with the saveIndex option should affect $n.",
+        test: (resolve, reject) => {
+            RuntimeAgent.evaluate.invoke({expression: "900 + 90", objectGroup: "test", includeCommandLineAPI: true, saveResult: true}, (error, remoteObjectPayload, wasThrown, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                InspectorTest.expectThat(savedResultIndex === 2, "Evaluated result 990 should become $2.");
+            });
+            RuntimeAgent.evaluate.invoke({expression: "$2 + 9", objectGroup: "test", includeCommandLineAPI: true, saveResult: true}, (error, remoteObjectPayload, wasThrown, savedResultIndex) => {
+                InspectorTest.assert(!error, "Should not be a protocol error.");
+                InspectorTest.expectThat(savedResultIndex === 1, "Evaluated result 999 should match previous value $1.");
+                resolve();
+            });
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Tests for the Runtime.saveResult command ($n values).</p>
+</body>
+</html>
index 44145c8..b56a9f8 100644 (file)
@@ -1,3 +1,17 @@
+2015-09-04  Joseph Pecoraro  <pecoraro@apple.com>
+
+        Web Inspector: Test Runtime.saveResult and $n values
+        https://bugs.webkit.org/show_bug.cgi?id=148837
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/InjectedScriptSource.js:
+        (InjectedScript.prototype._evaluateOn):
+        We don't need to be in the console object group to put the value
+        in the saved results list. That strong reference will ensure $n
+        values are always alive even if other object groups were used
+        when creating and subsequently released.
+
 2015-09-04  Mark Lam  <mark.lam@apple.com>
 
         [Follow up] StackOverflow stack unwinding should stop at native frames.
index a207c32..ae81d51 100644 (file)
@@ -487,7 +487,7 @@ InjectedScript.prototype = {
             var expressionFunction = evalFunction.call(object, boundExpressionFunctionString);
             var result = expressionFunction.apply(null, parameters);
 
-            if (objectGroup === "console" && saveResult)
+            if (saveResult)
                 this._saveResult(result);
 
             return result;
@@ -507,7 +507,7 @@ InjectedScript.prototype = {
 
             var result = evalFunction.call(inspectedGlobalObject, expression);
 
-            if (objectGroup === "console" && saveResult)
+            if (saveResult)
                 this._saveResult(result);
 
             return result;
index fd91ce7..ca2266e 100644 (file)
@@ -1,5 +1,22 @@
 2015-09-04  Joseph Pecoraro  <pecoraro@apple.com>
 
+        Web Inspector: Test Runtime.saveResult and $n values
+        https://bugs.webkit.org/show_bug.cgi?id=148837
+
+        Reviewed by Timothy Hatcher.
+
+        * UserInterface/Protocol/InspectorBackend.js:
+        (InspectorBackendClass):
+        Initialize the dump logging function different if we are in tests or not.
+        When in tests, using console.log as well as dumping system activity to
+        the system console results in an infinite loop of logging!
+
+        (InspectorBackendClass.prototype.dispatch):
+        (InspectorBackendClass.prototype._sendCommandToBackendWithCallback):
+        Use the logging function we figured out earlier.
+
+2015-09-04  Joseph Pecoraro  <pecoraro@apple.com>
+
         Web Inspector: Clean up and modernize DOMTreeManager
         https://bugs.webkit.org/show_bug.cgi?id=148821
 
index 4bb7ffc..8f84798 100644 (file)
@@ -43,6 +43,8 @@ InspectorBackendClass = class InspectorBackendClass
         this.dumpInspectorProtocolMessages = false;
         this.warnForLongMessageHandling = false;
         this.longMessageHandlingThreshold = 10; // milliseconds.
+
+        this._log = window.InspectorTest ? InspectorFrontendHost.unbufferedLog.bind(InspectorFrontendHost) : console.log.bind(console);
     }
 
     // Public
@@ -77,7 +79,7 @@ InspectorBackendClass = class InspectorBackendClass
     dispatch(message)
     {
         if (this.dumpInspectorProtocolMessages)
-            console.log("backend: " + ((typeof message === "string") ? message : JSON.stringify(message)));
+            this._log("backend: " + ((typeof message === "string") ? message : JSON.stringify(message)));
 
         var messageObject = (typeof message === "string") ? JSON.parse(message) : message;
 
@@ -173,7 +175,7 @@ InspectorBackendClass = class InspectorBackendClass
     {
         let stringifiedMessage = JSON.stringify(messageObject);
         if (this.dumpInspectorProtocolMessages)
-            console.log("frontend: " + stringifiedMessage);
+            this._log("frontend: " + stringifiedMessage);
 
         InspectorFrontendHost.sendMessageToBackend(stringifiedMessage);
     }