Diff
Modified: trunk/LayoutTests/ChangeLog (103708 => 103709)
--- trunk/LayoutTests/ChangeLog 2011-12-27 15:29:56 UTC (rev 103708)
+++ trunk/LayoutTests/ChangeLog 2011-12-27 16:21:50 UTC (rev 103709)
@@ -1,3 +1,16 @@
+2011-12-27 Yury Semikhatsky <[email protected]>
+
+ Web Inspector: report per document JS event listener count
+ https://bugs.webkit.org/show_bug.cgi?id=74298
+
+ Added a test for basic functionality of MemoryAgent.
+
+ Reviewed by Pavel Feldman.
+
+ * inspector/dom-statistics-expected.txt: Added.
+ * inspector/dom-statistics.html: Added.
+ * platform/chromium/inspector/dom-statistics-expected.txt: Added.
+
2011-12-27 Csaba Osztrogonác <[email protected]>
[Qt] Unreviewed Xmas gardening after r103617, add additional console message:
Added: trunk/LayoutTests/inspector/dom-statistics-expected.txt (0 => 103709)
--- trunk/LayoutTests/inspector/dom-statistics-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/dom-statistics-expected.txt 2011-12-27 16:21:50 UTC (rev 103709)
@@ -0,0 +1,119 @@
+
+Tests that per document Node count is correctly calculated by the Memory agent. Bug 74100. Bug 74298.
+
+result = [
+ {
+ "title": "div",
+ "size": 1,
+ "nodeCount": [
+ {
+ "nodeName": "div",
+ "count": 1
+ }
+ ],
+ "listenerCount": [
+ {
+ "type": "mouseover",
+ "count": 1
+ },
+ {
+ "type": "click",
+ "count": 1
+ }
+ ]
+ },
+ {
+ "title": "div",
+ "size": 1,
+ "nodeCount": [
+ {
+ "nodeName": "div",
+ "count": 1
+ }
+ ],
+ "listenerCount": [
+ {
+ "type": "mouseover",
+ "count": 1
+ },
+ {
+ "type": "click",
+ "count": 1
+ }
+ ]
+ },
+ {
+ "title": "#document",
+ "documentURI": "...about:blank",
+ "size": 3,
+ "nodeCount": [
+ {
+ "nodeName": "body",
+ "count": 1
+ },
+ {
+ "nodeName": "head",
+ "count": 1
+ },
+ {
+ "nodeName": "html",
+ "count": 1
+ }
+ ],
+ "listenerCount": []
+ },
+ {
+ "title": "#document",
+ "documentURI": "...dom-statistics.html",
+ "size": 23,
+ "nodeCount": [
+ {
+ "nodeName": "#text",
+ "count": 13
+ },
+ {
+ "nodeName": "a",
+ "count": 2
+ },
+ {
+ "nodeName": "body",
+ "count": 1
+ },
+ {
+ "nodeName": "div",
+ "count": 1
+ },
+ {
+ "nodeName": "head",
+ "count": 1
+ },
+ {
+ "nodeName": "html",
+ "count": 1
+ },
+ {
+ "nodeName": "iframe",
+ "count": 1
+ },
+ {
+ "nodeName": "p",
+ "count": 1
+ },
+ {
+ "nodeName": "script",
+ "count": 2
+ }
+ ],
+ "listenerCount": [
+ {
+ "type": "click",
+ "count": 2
+ },
+ {
+ "type": "mouseover",
+ "count": 1
+ }
+ ]
+ }
+]
+
Property changes on: trunk/LayoutTests/inspector/dom-statistics-expected.txt
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/inspector/dom-statistics.html (0 => 103709)
--- trunk/LayoutTests/inspector/dom-statistics.html (rev 0)
+++ trunk/LayoutTests/inspector/dom-statistics.html 2011-12-27 16:21:50 UTC (rev 103709)
@@ -0,0 +1,84 @@
+<html>
+<head>
+<script src=""
+<script>
+
+function test()
+{
+ function callback(error, result)
+ {
+ for (var i = 0; i < result.length; i++) {
+ var url = ""
+ if (!url)
+ continue;
+ var index = url.lastIndexOf("/");
+ if (index != -1)
+ url = "" + 1);
+ result[i].documentURI = "..." + url;
+
+ result[i].nodeCount.sort(function(a, b) {
+ return a.nodeName.localeCompare(b.nodeName);
+ });
+ result[i].listenerCount.sort(function(a, b) {
+ return a.type.localeCompare(b.type);
+ });
+ }
+
+ function stringCompare(a, b)
+ {
+ if (a && b)
+ return a.localeCompare(b);
+ if (!a && !b)
+ return 0;
+ if (a)
+ return 1;
+ return -1;
+ }
+
+ result.sort(function(a, b) {
+ var r = stringCompare(a.documentURI, b.documentURI);
+ if (r)
+ return r;
+ return stringCompare(a.title, b.title);
+ });
+
+ InspectorTest.addResult("result = " + JSON.stringify(result, null, 4));
+ InspectorTest.completeTest();
+ }
+ MemoryAgent.getDOMNodeCount(callback);
+}
+
+var detachedDivs = [];
+function createDetachedNode()
+{
+ var detachedDiv = document.createElement("div");
+ detachedDiv.addEventListener("click", function(e) {});
+ detachedDiv.addEventListener("mouseover", function(e) {});
+ detachedDiv.appendChild(document.createElement("div"));
+ return detachedDiv;
+}
+
+function prepareAndRunTest()
+{
+ var p = document.getElementById("paragraph");
+ p.addEventListener("click", function(e) {});
+ p.addEventListener("mouseover", function(e) {});
+ document.body.appendChild(document.createElement("div"));
+ detachedDivs.push(createDetachedNode());
+ detachedDivs.push(createDetachedNode());
+
+ runTest();
+}
+
+</script>
+</head>
+
+<body _onload_="prepareAndRunTest()">
+<iframe src=""
+<p id="paragraph" _onclick_="alert(1)">
+Tests that per document Node count is correctly calculated by the Memory agent.
+<a href="" 74100.</a>
+<a href="" 74298.</a>
+</p>
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/dom-statistics.html
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/platform/chromium/inspector/dom-statistics-expected.txt (0 => 103709)
--- trunk/LayoutTests/platform/chromium/inspector/dom-statistics-expected.txt (rev 0)
+++ trunk/LayoutTests/platform/chromium/inspector/dom-statistics-expected.txt 2011-12-27 16:21:50 UTC (rev 103709)
@@ -0,0 +1,119 @@
+
+Tests that per document Node count is correctly calculated by the Memory agent. Bug 74100. Bug 74298.
+
+result = [
+ {
+ "title": "div",
+ "size": 1,
+ "nodeCount": [
+ {
+ "nodeName": "div",
+ "count": 1
+ }
+ ],
+ "listenerCount": [
+ {
+ "type": "mouseover",
+ "count": 1
+ },
+ {
+ "type": "click",
+ "count": 1
+ }
+ ]
+ },
+ {
+ "title": "div",
+ "size": 1,
+ "nodeCount": [
+ {
+ "nodeName": "div",
+ "count": 1
+ }
+ ],
+ "listenerCount": [
+ {
+ "type": "mouseover",
+ "count": 1
+ },
+ {
+ "type": "click",
+ "count": 1
+ }
+ ]
+ },
+ {
+ "title": "#document",
+ "documentURI": "...about:blank",
+ "size": 3,
+ "nodeCount": [
+ {
+ "nodeName": "body",
+ "count": 1
+ },
+ {
+ "nodeName": "head",
+ "count": 1
+ },
+ {
+ "nodeName": "html",
+ "count": 1
+ }
+ ],
+ "listenerCount": []
+ },
+ {
+ "title": "#document",
+ "documentURI": "...dom-statistics.html",
+ "size": 23,
+ "nodeCount": [
+ {
+ "nodeName": "#text",
+ "count": 13
+ },
+ {
+ "nodeName": "a",
+ "count": 2
+ },
+ {
+ "nodeName": "body",
+ "count": 1
+ },
+ {
+ "nodeName": "div",
+ "count": 1
+ },
+ {
+ "nodeName": "head",
+ "count": 1
+ },
+ {
+ "nodeName": "html",
+ "count": 1
+ },
+ {
+ "nodeName": "iframe",
+ "count": 1
+ },
+ {
+ "nodeName": "p",
+ "count": 1
+ },
+ {
+ "nodeName": "script",
+ "count": 2
+ }
+ ],
+ "listenerCount": [
+ {
+ "type": "click",
+ "count": 2
+ },
+ {
+ "type": "mouseover",
+ "count": 1
+ }
+ ]
+ }
+]
+
Property changes on: trunk/LayoutTests/platform/chromium/inspector/dom-statistics-expected.txt
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/Source/WebCore/ChangeLog (103708 => 103709)
--- trunk/Source/WebCore/ChangeLog 2011-12-27 15:29:56 UTC (rev 103708)
+++ trunk/Source/WebCore/ChangeLog 2011-12-27 16:21:50 UTC (rev 103709)
@@ -1,3 +1,18 @@
+2011-12-27 Yury Semikhatsky <[email protected]>
+
+ Web Inspector: report per document JS event listener count
+ https://bugs.webkit.org/show_bug.cgi?id=74298
+
+ This patch adds JS event listener count to the memory agent
+ report.
+
+ Reviewed by Pavel Feldman.
+
+ Test: inspector/dom-statistics.html
+
+ * inspector/Inspector.json:
+ * inspector/InspectorMemoryAgent.cpp:
+
2011-12-27 Alexander Pavlov <[email protected]>
Web Inspector: [REGRESSION] Go to Function dialog always has a minimal height
Modified: trunk/Source/WebCore/inspector/Inspector.json (103708 => 103709)
--- trunk/Source/WebCore/inspector/Inspector.json 2011-12-27 15:29:56 UTC (rev 103708)
+++ trunk/Source/WebCore/inspector/Inspector.json 2011-12-27 16:21:50 UTC (rev 103709)
@@ -59,13 +59,23 @@
"description": "Number of nodes with given name."
},
{
+ "id": "ListenerCount",
+ "type": "object",
+ "properties": [
+ { "name": "type", "type": "string" },
+ { "name": "count", "type": "integer" }
+ ],
+ "description": "Number of JS event listeners by event type."
+ },
+ {
"id": "DOMGroup",
"type": "object",
"properties": [
{ "name": "size", "type": "integer" },
{ "name": "title", "type": "string" },
{ "name": "documentURI", "type": "string", "optional": true },
- { "name": "nodeCount", "type": "array", "items": { "$ref": "NodeCount" }}
+ { "name": "nodeCount", "type": "array", "items": { "$ref": "NodeCount" }},
+ { "name": "listenerCount", "type": "array", "items": { "$ref": "ListenerCount" }}
]
}
],
Modified: trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp (103708 => 103709)
--- trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2011-12-27 15:29:56 UTC (rev 103708)
+++ trunk/Source/WebCore/inspector/InspectorMemoryAgent.cpp 2011-12-27 16:21:50 UTC (rev 103709)
@@ -35,6 +35,7 @@
#include "DOMWrapperVisitor.h"
#include "Document.h"
+#include "EventListenerMap.h"
#include "Frame.h"
#include "InspectorState.h"
#include "InspectorValues.h"
@@ -81,13 +82,16 @@
static void collectTreeStatistics(Node* rootNode, InspectorObject* result)
{
unsigned count = 0;
+ HashMap<AtomicString, int> eventTypeToCount;
HashMap<String, int> nameToCount;
Node* currentNode = rootNode;
+ collectListenersInfo(rootNode, eventTypeToCount);
while ((currentNode = currentNode->traverseNextNode(rootNode))) {
++count;
String name = nodeName(currentNode);
int currentCount = nameToCount.get(name);
nameToCount.set(name, currentCount + 1);
+ collectListenersInfo(currentNode, eventTypeToCount);
}
RefPtr<InspectorArray> childrenStats = InspectorArray::create();
@@ -98,10 +102,41 @@
childrenStats->pushObject(nodeCount);
}
+ RefPtr<InspectorArray> listenerStats = InspectorArray::create();
+ for (HashMap<AtomicString, int>::iterator it = eventTypeToCount.begin(); it != eventTypeToCount.end(); ++it) {
+ RefPtr<InspectorObject> eventCount = InspectorObject::create();
+ eventCount->setString("type", it->first);
+ eventCount->setNumber("count", it->second);
+ listenerStats->pushObject(eventCount);
+ }
+
result->setNumber("size", count);
result->setArray("nodeCount", childrenStats);
+ result->setArray("listenerCount", listenerStats);
}
+ static void collectListenersInfo(Node* node, HashMap<AtomicString, int>& result)
+ {
+ EventTargetData* d = node->eventTargetData();
+ if (!d)
+ return;
+ EventListenerMap& eventListenerMap = d->eventListenerMap;
+ if (eventListenerMap.isEmpty())
+ return;
+ Vector<AtomicString> eventNames = eventListenerMap.eventTypes();
+ for (Vector<AtomicString>::iterator it = eventNames.begin(); it != eventNames.end(); ++it) {
+ AtomicString name = *it;
+ EventListenerVector* listeners = eventListenerMap.find(name);
+ int count = 0;
+ for (EventListenerVector::iterator j = listeners->begin(); j != listeners->end(); ++j) {
+ if (j->listener->type() == EventListener::JSEventListenerType)
+ ++count;
+ }
+ if (count)
+ result.set(name, result.get(name) + count);
+ }
+ }
+
static String nodeName(Node* node)
{
if (node->document()->isXHTMLDocument())