Web Inspector: [Extensions API] add audit formatters for remote objects and DOM elements
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 May 2012 08:29:08 +0000 (08:29 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 11 May 2012 08:29:08 +0000 (08:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=86108

Reviewed by Pavel Feldman.

Source/WebCore:

       - added two new formatters to AuditResults object of webInspector.audits API;

* inspector/front-end/AuditFormatters.js:
(WebInspector.AuditFormatters.resourceLink):
(WebInspector.AuditFormatters.object.onEvaluate):
(WebInspector.AuditFormatters.object): format as a remote object property list;
(WebInspector.AuditFormatters.node.onNodeAvailable):
(WebInspector.AuditFormatters.node.onEvaluate):
(WebInspector.AuditFormatters.node): format as a DOM elements sub-tree;
(WebInspector.AuditFormatters.Utilities.evaluate): common expression evaluation logic for both new formatters;
* inspector/front-end/ExtensionAPI.js:
(injectedExtensionAPI.AuditResultImpl):
* inspector/front-end/auditsPanel.css:
(.audit-result-tree ol.outline-disclosure):
(.audit-result-tree .section .header):
(.audit-result-tree .section .header::before):

LayoutTests:

- rebaselined tests to account for two new AuditResults method and their results;

* inspector/extensions/extensions-audits-api-expected.txt:
* inspector/extensions/extensions-audits-expected.txt:
* inspector/extensions/extensions-audits-tests.js:
(initialize_ExtensionsAuditsTest.InspectorTest.startExtensionAudits.onAuditsDone):
* inspector/extensions/extensions-audits.html:

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

LayoutTests/ChangeLog
LayoutTests/inspector/audits/audits-test.js
LayoutTests/inspector/extensions/extensions-audits-api-expected.txt
LayoutTests/inspector/extensions/extensions-audits-api.html
LayoutTests/inspector/extensions/extensions-audits-expected.txt
LayoutTests/inspector/extensions/extensions-audits-tests.js
LayoutTests/inspector/extensions/extensions-audits.html
Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/AuditFormatters.js
Source/WebCore/inspector/front-end/ExtensionAPI.js
Source/WebCore/inspector/front-end/auditsPanel.css

index be6400a..8f1a399 100644 (file)
@@ -1,3 +1,18 @@
+2012-05-10  Andrey Kosyakov  <caseq@chromium.org>
+
+        Web Inspector: [Extensions API] add audit formatters for remote objects and DOM elements
+        https://bugs.webkit.org/show_bug.cgi?id=86108
+
+        Reviewed by Pavel Feldman.
+
+        - rebaselined tests to account for two new AuditResults method and their results;
+
+        * inspector/extensions/extensions-audits-api-expected.txt:
+        * inspector/extensions/extensions-audits-expected.txt:
+        * inspector/extensions/extensions-audits-tests.js:
+        (initialize_ExtensionsAuditsTest.InspectorTest.startExtensionAudits.onAuditsDone):
+        * inspector/extensions/extensions-audits.html:
+
 2012-05-11  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         Unreviewed gardening, skip a new failing test.
index 554f3c3..75d140b 100644 (file)
@@ -21,7 +21,7 @@ InspectorTest.collectTextContent = function(element, level)
         if (child.nodeType === Node.TEXT_NODE) {
             for (var i = 0; i < level; ++i)
                 nodeOutput += " ";
-            nodeOutput += child.nodeValue;
+            nodeOutput += child.nodeValue.replace("\u200B", "");
         } else if (child.nodeType === Node.ELEMENT_NODE) {
             if (nodeOutput !== "") {
                 InspectorTest.addResult(nodeOutput);
index a1cc714..b4ac25e 100644 (file)
@@ -10,12 +10,13 @@ Added audit category, result dump follows:
         removeListener : <function>
     }
 }
-  Extension audits
 category.onAuditStarted fired, results dump follows:
 {
     createURL : <function>
     createSnippet : <function>
     createText : <function>
+    createObject : <function>
+    createNode : <function>
     addResult : <function>
     createResult : <function>
     done : <function>
@@ -35,5 +36,6 @@ category.onAuditStarted fired, results dump follows:
     expanded : false
     addChild : <function>
 }
+  Extension audits
 All tests done.
 
index 275901e..48ab837 100644 (file)
@@ -15,7 +15,10 @@ function extension_testAuditsAPI(nextTest)
         dumpObject(results);
         var node = results.createResult("Subtree");
         dumpObject(node);
-        results.done();
+        // Make sure dumpObject() pushes stuff through before we continue.
+        evaluateOnFrontend("InspectorTest.runAfterPendingDispatches(reply)", function() {
+            results.done();
+        });
     }
     var category = webInspector.audits.addCategory("Extension audits", 20);
     category.onAuditStarted.addListener(onStartAuditCategory);
index 19845f3..2e8b7d3 100644 (file)
@@ -1,6 +1,6 @@
 Tests audits support in WebInspector Extensions API
 
-Started extension.
+ Started extension.
 Running tests...
 RUNNING TEST: extension_testAudits
   Extension audits
@@ -19,6 +19,25 @@ RUNNING TEST: extension_testAudits
     return 4;
 }
          /path/to/error.html:10
+            object details
+             a
+             : 
+             42
+             b
+             : 
+             "foo"
+             __proto__
+             : 
+             Object
+            <
+             span
+             
+              id
+             ="
+              test-element
+             "
+            >
+           
          extensions-audits.html:20
     Passed rule
      this rule always passes ok
index c442d86..9114d89 100644 (file)
@@ -20,8 +20,10 @@ var initialize_ExtensionsAuditsTest = function()
 
         function onAuditsDone()
         {
-            InspectorTest.collectAuditResults();
-            callback();
+            InspectorTest.runAfterPendingDispatches(function() {
+                InspectorTest.collectAuditResults();
+                callback();
+            });
         }
         InspectorTest.addSniffer(WebInspector.panels.audits, "_auditFinishedCallback", onAuditsDone, true);
 
index e581a55..4941116 100644 (file)
@@ -23,6 +23,9 @@ function extension_testAudits(nextTest)
         nestedNode.expanded = true;
         nestedNode.addChild(results.createSnippet("function rand()\n{\n    return 4;\n}"));
         nestedNode.addChild(results.createResourceLink("file:///path/to/error.html", 10));
+        nestedNode.addChild(results.createObject("({a: 42, b: 'foo'})", "object details"));
+        nestedNode.addChild(results.createNode("document.getElementById('test-element')"));
+
         webInspector.inspectedWindow.eval("location.href", function(inspectedPageURL) {
             nestedNode.addChild(results.createResourceLink(inspectedPageURL, 20));
 
@@ -68,5 +71,6 @@ function extension_testAudits(nextTest)
 </head>
 <body onload="runTest()">
 <p>Tests audits support in WebInspector Extensions API</p>
+<span id="test-element"><b></b></span>
 </body>
 </html>
index b80e79b..dcd08f5 100644 (file)
@@ -1,3 +1,27 @@
+2012-05-10  Andrey Kosyakov  <caseq@chromium.org>
+
+        Web Inspector: [Extensions API] add audit formatters for remote objects and DOM elements
+        https://bugs.webkit.org/show_bug.cgi?id=86108
+
+        Reviewed by Pavel Feldman.
+
+       - added two new formatters to AuditResults object of webInspector.audits API;
+
+        * inspector/front-end/AuditFormatters.js:
+        (WebInspector.AuditFormatters.resourceLink):
+        (WebInspector.AuditFormatters.object.onEvaluate):
+        (WebInspector.AuditFormatters.object): format as a remote object property list;
+        (WebInspector.AuditFormatters.node.onNodeAvailable):
+        (WebInspector.AuditFormatters.node.onEvaluate):
+        (WebInspector.AuditFormatters.node): format as a DOM elements sub-tree;
+        (WebInspector.AuditFormatters.Utilities.evaluate): common expression evaluation logic for both new formatters;
+        * inspector/front-end/ExtensionAPI.js:
+        (injectedExtensionAPI.AuditResultImpl):
+        * inspector/front-end/auditsPanel.css:
+        (.audit-result-tree ol.outline-disclosure):
+        (.audit-result-tree .section .header):
+        (.audit-result-tree .section .header::before):
+
 2012-05-11  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r116727.
index a413a9d..710d134 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -96,5 +96,75 @@ WebInspector.AuditFormatters = {
     {
         // FIXME: use WebInspector.DebuggerPresentationModel.Linkifier
         return WebInspector.linkifyResourceAsNode(url, line, "console-message-url webkit-html-resource-link");
+    },
+
+    /**
+     * @param {string} expression
+     * @param {string} title
+     */
+    object: function(expression, title)
+    {
+        var parentElement = document.createElement("div");
+        function onEvaluate(remoteObject)
+        {
+            var section = new WebInspector.ObjectPropertiesSection(remoteObject, title);
+            section.expanded = true;
+            section.editable = false;
+            parentElement.appendChild(section.element);
+        }
+        WebInspector.AuditFormatters.Utilities.evaluate(expression, onEvaluate);
+        return parentElement;
+    },
+
+    /**
+     * @param {string} expression
+     */
+    node: function(expression)
+    {
+        var treeOutline = new WebInspector.ElementsTreeOutline(false, false, true);
+        /**
+         * @param {?number} nodeId
+         */
+        function onNodeAvailable(nodeId)
+        {
+            if (!nodeId)
+                return;
+            treeOutline.rootDOMNode = WebInspector.domAgent.nodeForId(nodeId);
+            treeOutline.element.addStyleClass("outline-disclosure");
+            treeOutline.setVisible(true);
+        }
+        /**
+         * @param {WebInspector.RemoteObject} remoteObject
+         */
+        function onEvaluate(remoteObject)
+        {
+            remoteObject.pushNodeToFrontend(onNodeAvailable);
+        }
+        WebInspector.AuditFormatters.Utilities.evaluate(expression, onEvaluate);
+        return treeOutline.element;
     }
 };
+
+WebInspector.AuditFormatters.Utilities = {
+    /**
+     * @param {string} expression
+     * @param {function(WebInspector.RemoteObject)} callback
+     */
+    evaluate: function(expression, callback)
+    {
+        /**
+         * @param {?string} error
+         * @param {?RuntimeAgent.RemoteObject} result
+         * @param {boolean=} wasThrown
+         */
+        function onEvaluate(error, result, wasThrown)
+        {
+            if (wasThrown)
+                return;
+            var object = WebInspector.RemoteObject.fromPayload(result);
+            callback(object);
+        }
+        RuntimeAgent.evaluate(expression, "extension-watch", true, undefined, undefined, undefined, onEvaluate);
+    }
+};
+
index ce3f976..d25ab1b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Google Inc. All rights reserved.
+ * Copyright (C) 2012 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -498,6 +498,8 @@ function AuditResultImpl(id)
     this.createURL = this._nodeFactory.bind(null, "url");
     this.createSnippet = this._nodeFactory.bind(null, "snippet");
     this.createText = this._nodeFactory.bind(null, "text");
+    this.createObject = this._nodeFactory.bind(null, "object");
+    this.createNode = this._nodeFactory.bind(null, "node");
 }
 
 AuditResultImpl.prototype = {
index 121baff..4f6f17e 100644 (file)
     margin: 0;
 }
 
+.audit-result-tree ol.outline-disclosure {
+    -webkit-padding-start: 0;
+}
+
+.audit-result-tree .section .header {
+    padding-left: 13px;
+}
+
+.audit-result-tree .section .header::before {
+    left: 2px;
+}
+
 .audit-result-tree li {
     padding: 0 0 0 14px;
     margin-top: 1px;