Diff
Modified: trunk/LayoutTests/ChangeLog (120207 => 120208)
--- trunk/LayoutTests/ChangeLog 2012-06-13 15:01:49 UTC (rev 120207)
+++ trunk/LayoutTests/ChangeLog 2012-06-13 15:03:56 UTC (rev 120208)
@@ -1,3 +1,23 @@
+2012-06-13 Alexander Pavlov <[email protected]>
+
+ Web Inspector: Support user attributes in DOMNode
+ https://bugs.webkit.org/show_bug.cgi?id=88706
+
+ Reviewed by Pavel Feldman.
+
+ * http/tests/inspector/elements-test.js:
+ (initialize_ElementTest.InspectorTest.dumpElementsTree.dumpMap):
+ (initialize_ElementTest.InspectorTest.dumpElementsTree.userPropertyDataDump):
+ (initialize_ElementTest.InspectorTest.dumpElementsTree.print):
+ (initialize_ElementTest.InspectorTest.dumpElementsTree):
+ * inspector/elements/resources/user-properties.js: Added.
+ (test.step0):
+ (test.step1):
+ (test.step2):
+ (test):
+ * inspector/elements/user-properties-expected.txt: Added.
+ * inspector/elements/user-properties.html: Added.
+
2012-06-13 Vineet Chaudhary <[email protected]>
REGRESSION:Bindings sequence<T> in Console.idl, Internals.idl and ScriptProfileNode.idl should be T[]
Modified: trunk/LayoutTests/http/tests/inspector/elements-test.js (120207 => 120208)
--- trunk/LayoutTests/http/tests/inspector/elements-test.js 2012-06-13 15:01:49 UTC (rev 120207)
+++ trunk/LayoutTests/http/tests/inspector/elements-test.js 2012-06-13 15:03:56 UTC (rev 120208)
@@ -318,6 +318,37 @@
return element.textContent.replace(/\u200b/g, "").replace(/\n/g, "").trim();
}
+ function dumpMap(name, map)
+ {
+ var result = [];
+ for (var id in map)
+ result.push(id + "=" + map[id]);
+ if (!result.length)
+ return "";
+ return name + ":[" + result.join(",") + "]";
+ }
+
+ function userPropertyDataDump(treeItem)
+ {
+ if (treeItem._elementCloseTag)
+ return "";
+
+ var userProperties = "";
+ var node = treeItem.representedObject;
+ if (node) {
+ userProperties += dumpMap("userProperties", node._userProperties);
+ var dump = dumpMap("descendantUserAttributeCounters", node._descendantUserPropertyCounters);
+ if (dump) {
+ if (userProperties)
+ userProperties += ", ";
+ userProperties += dump;
+ }
+ if (userProperties)
+ userProperties = " [" + userProperties + "]";
+ }
+ return userProperties;
+ }
+
function print(treeItem, prefix, depth)
{
if (treeItem.listItemElement) {
@@ -330,7 +361,8 @@
} else
expander = " ";
- InspectorTest.addResult(prefix + expander + beautify(treeItem.listItemElement));
+ var userProperties = userPropertyDataDump(treeItem);
+ InspectorTest.addResult(prefix + expander + beautify(treeItem.listItemElement) + userProperties);
}
if (!treeItem.expanded)
Added: trunk/LayoutTests/inspector/elements/resources/user-properties.js (0 => 120208)
--- trunk/LayoutTests/inspector/elements/resources/user-properties.js (rev 0)
+++ trunk/LayoutTests/inspector/elements/resources/user-properties.js 2012-06-13 15:03:56 UTC (rev 120208)
@@ -0,0 +1,70 @@
+function test()
+{
+ var containerNode;
+ var child1Node;
+ var child2Node;
+ var aNode;
+
+ InspectorTest.expandElementsTree(step0);
+
+ function step0()
+ {
+ containerNode = InspectorTest.expandedNodeWithId("container");
+ child1Node = InspectorTest.expandedNodeWithId("child1");
+ child2Node = InspectorTest.expandedNodeWithId("child2");
+ aNode = InspectorTest.expandedNodeWithId("aNode");
+
+ aNode.setUserProperty("attr1", true);
+ InspectorTest.addResult("attr1 set on aNode");
+ InspectorTest.dumpElementsTree(null);
+
+ child2Node.setUserProperty("attr2", "value");
+ InspectorTest.addResult("attr2 set on child2");
+ InspectorTest.dumpElementsTree(null);
+
+ child2Node.setUserProperty("attr1", true);
+ InspectorTest.addResult("attr1 set on child2");
+ InspectorTest.dumpElementsTree(null);
+
+ aNode.setUserProperty("attr1", "anotherValue");
+ InspectorTest.addResult("attr1 modified on aNode");
+ InspectorTest.dumpElementsTree(null);
+
+ child2Node.setUserProperty("attr2", "anotherValue");
+ InspectorTest.addResult("attr2 modified on child2");
+ InspectorTest.dumpElementsTree(null);
+
+ aNode.removeUserProperty("attr1");
+ InspectorTest.addResult("attr1 removed from aNode");
+ InspectorTest.dumpElementsTree(null);
+
+ aNode.removeNode(step1);
+ }
+
+ function step1(error)
+ {
+ if (error) {
+ InspectorTest.addResult("Failed to remove aNode");
+ InspectorTest.completeTest();
+ return;
+ }
+
+ InspectorTest.addResult("aNode removed");
+ InspectorTest.dumpElementsTree(null);
+
+ child2Node.removeNode(step2);
+ }
+
+ function step2(error)
+ {
+ if (error) {
+ InspectorTest.addResult("Failed to remove child2");
+ InspectorTest.completeTest();
+ return;
+ }
+
+ InspectorTest.addResult("child2 removed");
+ InspectorTest.dumpElementsTree(null);
+ InspectorTest.completeTest();
+ }
+}
Property changes on: trunk/LayoutTests/inspector/elements/resources/user-properties.js
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/inspector/elements/user-properties-expected.txt (0 => 120208)
--- trunk/LayoutTests/inspector/elements/user-properties-expected.txt (rev 0)
+++ trunk/LayoutTests/inspector/elements/user-properties-expected.txt 2012-06-13 15:03:56 UTC (rev 120208)
@@ -0,0 +1,145 @@
+Tests that DOMNode properly tracks own and descendants' user properties.
+
+attr1 set on aNode
+ <!DOCTYPE html>
+- <html> [descendantUserAttributeCounters:[attr1=1]]
+ - <head>
+ <script src=""
+ <script src=""
+ <script src=""
+ </head>
+ - <body _onload_="runTest()"> [descendantUserAttributeCounters:[attr1=1]]
+ <p>Tests that DOMNode properly tracks own and descendants' user properties.</p>
+ - <div id="container"> [descendantUserAttributeCounters:[attr1=1]]
+ <div id="child1"></div>
+ - <div id="child2"> [descendantUserAttributeCounters:[attr1=1]]
+ <a href="" id="aNode">Third-level node</a> [userProperties:[attr1=true]]
+ </div>
+ </div>
+ </body>
+ </html>
+attr2 set on child2
+ <!DOCTYPE html>
+- <html> [descendantUserAttributeCounters:[attr1=1,attr2=1]]
+ - <head>
+ <script src=""
+ <script src=""
+ <script src=""
+ </head>
+ - <body _onload_="runTest()"> [descendantUserAttributeCounters:[attr1=1,attr2=1]]
+ <p>Tests that DOMNode properly tracks own and descendants' user properties.</p>
+ - <div id="container"> [descendantUserAttributeCounters:[attr1=1,attr2=1]]
+ <div id="child1"></div>
+ - <div id="child2"> [userProperties:[attr2=value], descendantUserAttributeCounters:[attr1=1]]
+ <a href="" id="aNode">Third-level node</a> [userProperties:[attr1=true]]
+ </div>
+ </div>
+ </body>
+ </html>
+attr1 set on child2
+ <!DOCTYPE html>
+- <html> [descendantUserAttributeCounters:[attr1=2,attr2=1]]
+ - <head>
+ <script src=""
+ <script src=""
+ <script src=""
+ </head>
+ - <body _onload_="runTest()"> [descendantUserAttributeCounters:[attr1=2,attr2=1]]
+ <p>Tests that DOMNode properly tracks own and descendants' user properties.</p>
+ - <div id="container"> [descendantUserAttributeCounters:[attr1=2,attr2=1]]
+ <div id="child1"></div>
+ - <div id="child2"> [userProperties:[attr2=value,attr1=true], descendantUserAttributeCounters:[attr1=1]]
+ <a href="" id="aNode">Third-level node</a> [userProperties:[attr1=true]]
+ </div>
+ </div>
+ </body>
+ </html>
+attr1 modified on aNode
+ <!DOCTYPE html>
+- <html> [descendantUserAttributeCounters:[attr1=2,attr2=1]]
+ - <head>
+ <script src=""
+ <script src=""
+ <script src=""
+ </head>
+ - <body _onload_="runTest()"> [descendantUserAttributeCounters:[attr1=2,attr2=1]]
+ <p>Tests that DOMNode properly tracks own and descendants' user properties.</p>
+ - <div id="container"> [descendantUserAttributeCounters:[attr1=2,attr2=1]]
+ <div id="child1"></div>
+ - <div id="child2"> [userProperties:[attr2=value,attr1=true], descendantUserAttributeCounters:[attr1=1]]
+ <a href="" id="aNode">Third-level node</a> [userProperties:[attr1=anotherValue]]
+ </div>
+ </div>
+ </body>
+ </html>
+attr2 modified on child2
+ <!DOCTYPE html>
+- <html> [descendantUserAttributeCounters:[attr1=2,attr2=1]]
+ - <head>
+ <script src=""
+ <script src=""
+ <script src=""
+ </head>
+ - <body _onload_="runTest()"> [descendantUserAttributeCounters:[attr1=2,attr2=1]]
+ <p>Tests that DOMNode properly tracks own and descendants' user properties.</p>
+ - <div id="container"> [descendantUserAttributeCounters:[attr1=2,attr2=1]]
+ <div id="child1"></div>
+ - <div id="child2"> [userProperties:[attr2=anotherValue,attr1=true], descendantUserAttributeCounters:[attr1=1]]
+ <a href="" id="aNode">Third-level node</a> [userProperties:[attr1=anotherValue]]
+ </div>
+ </div>
+ </body>
+ </html>
+attr1 removed from aNode
+ <!DOCTYPE html>
+- <html> [descendantUserAttributeCounters:[attr1=1,attr2=1]]
+ - <head>
+ <script src=""
+ <script src=""
+ <script src=""
+ </head>
+ - <body _onload_="runTest()"> [descendantUserAttributeCounters:[attr1=1,attr2=1]]
+ <p>Tests that DOMNode properly tracks own and descendants' user properties.</p>
+ - <div id="container"> [descendantUserAttributeCounters:[attr1=1,attr2=1]]
+ <div id="child1"></div>
+ - <div id="child2"> [userProperties:[attr2=anotherValue,attr1=true]]
+ <a href="" id="aNode">Third-level node</a>
+ </div>
+ </div>
+ </body>
+ </html>
+aNode removed
+ <!DOCTYPE html>
+- <html> [descendantUserAttributeCounters:[attr1=1,attr2=1]]
+ - <head>
+ <script src=""
+ <script src=""
+ <script src=""
+ </head>
+ - <body _onload_="runTest()"> [descendantUserAttributeCounters:[attr1=1,attr2=1]]
+ <p>Tests that DOMNode properly tracks own and descendants' user properties.</p>
+ - <div id="container"> [descendantUserAttributeCounters:[attr1=1,attr2=1]]
+ <div id="child1"></div>
+ - <div id="child2"> [userProperties:[attr2=anotherValue,attr1=true]]
+ </div>
+ </div>
+ + <div>…</div>
+ </body>
+ </html>
+child2 removed
+ <!DOCTYPE html>
+- <html>
+ - <head>
+ <script src=""
+ <script src=""
+ <script src=""
+ </head>
+ - <body _onload_="runTest()">
+ <p>Tests that DOMNode properly tracks own and descendants' user properties.</p>
+ - <div id="container">
+ <div id="child1"></div>
+ </div>
+ + <div>…</div>
+ </body>
+ </html>
+
Property changes on: trunk/LayoutTests/inspector/elements/user-properties-expected.txt
___________________________________________________________________
Added: svn:eol-style
Added: trunk/LayoutTests/inspector/elements/user-properties.html (0 => 120208)
--- trunk/LayoutTests/inspector/elements/user-properties.html (rev 0)
+++ trunk/LayoutTests/inspector/elements/user-properties.html 2012-06-13 15:03:56 UTC (rev 120208)
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+<script src=""
+</head>
+
+<body _onload_="runTest()">
+<p>
+Tests that DOMNode properly tracks own and descendants' user properties.
+</p>
+
+<div id="container">
+ <div id="child1"></div>
+ <div id="child2"><a href="" id="aNode">Third-level node</a></div>
+</div>
+
+</body>
+</html>
Property changes on: trunk/LayoutTests/inspector/elements/user-properties.html
___________________________________________________________________
Added: svn:eol-style
Modified: trunk/Source/WebCore/ChangeLog (120207 => 120208)
--- trunk/Source/WebCore/ChangeLog 2012-06-13 15:01:49 UTC (rev 120207)
+++ trunk/Source/WebCore/ChangeLog 2012-06-13 15:03:56 UTC (rev 120208)
@@ -1,3 +1,24 @@
+2012-06-13 Alexander Pavlov <[email protected]>
+
+ Web Inspector: Support user attributes in DOMNode
+ https://bugs.webkit.org/show_bug.cgi?id=88706
+
+ Reviewed by Pavel Feldman.
+
+ This change allows clients to store arbitrary properties on DOMNodes and know if there are descendants
+ (and how many of them) having a certain property set.
+
+ Test: inspector/elements/user-attributes.html
+
+ * inspector/front-end/DOMAgent.js:
+ (WebInspector.DOMNode.prototype._removeChild):
+ (WebInspector.DOMNode.prototype._updateChildUserPropertyCountsOnRemoval):
+ (WebInspector.DOMNode.prototype._updateDescendantUserPropertyCount):
+ (WebInspector.DOMNode.prototype.setUserProperty):
+ (WebInspector.DOMNode.prototype.removeUserProperty):
+ (WebInspector.DOMNode.prototype.getUserProperty):
+ (WebInspector.DOMNode.prototype.descendantUserPropertyCount):
+
2012-06-13 Vineet Chaudhary <[email protected]>
REGRESSION:Bindings sequence<T> in Console.idl, Internals.idl and ScriptProfileNode.idl should be T[]
Modified: trunk/Source/WebCore/inspector/front-end/DOMAgent.js (120207 => 120208)
--- trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2012-06-13 15:01:49 UTC (rev 120207)
+++ trunk/Source/WebCore/inspector/front-end/DOMAgent.js 2012-06-13 15:03:56 UTC (rev 120208)
@@ -55,6 +55,9 @@
if (payload.attributes)
this._setAttributesPayload(payload.attributes);
+ this._userProperties = {};
+ this._descendantUserPropertyCounters = {};
+
this._childNodeCount = payload.childNodeCount;
this.children = null;
@@ -458,6 +461,7 @@
{
this.children.splice(this.children.indexOf(node), 1);
node.parentNode = null;
+ node._updateChildUserPropertyCountsOnRemoval(this);
this._renumber();
},
@@ -669,6 +673,69 @@
}
}
return -1; // An error occurred: |this| not found in parent's children.
+ },
+
+ _updateChildUserPropertyCountsOnRemoval: function(parentNode)
+ {
+ var result = {};
+ if (this._userProperties) {
+ for (var name in this._userProperties)
+ result[name] = (result[name] || 0) + 1;
+ }
+
+ if (this._descendantUserPropertyCounters) {
+ for (var name in this._descendantUserPropertyCounters) {
+ var counter = this._descendantUserPropertyCounters[name];
+ result[name] = (result[name] || 0) + counter;
+ }
+ }
+
+ for (var name in result)
+ parentNode._updateDescendantUserPropertyCount(name, -result[name]);
+ },
+
+ _updateDescendantUserPropertyCount: function(name, delta)
+ {
+ if (!this._descendantUserPropertyCounters.hasOwnProperty(name))
+ this._descendantUserPropertyCounters[name] = 0;
+ this._descendantUserPropertyCounters[name] += delta;
+ if (!this._descendantUserPropertyCounters[name])
+ delete this._descendantUserPropertyCounters[name];
+ if (this.parentNode)
+ this.parentNode._updateDescendantUserPropertyCount(name, delta);
+ },
+
+ setUserProperty: function(name, value)
+ {
+ if (value === null) {
+ this.removeUserProperty(name);
+ return;
+ }
+
+ if (this.parentNode && !this._userProperties.hasOwnProperty(name))
+ this.parentNode._updateDescendantUserPropertyCount(name, 1);
+
+ this._userProperties[name] = value;
+ },
+
+ removeUserProperty: function(name)
+ {
+ if (!this._userProperties.hasOwnProperty(name))
+ return;
+
+ delete this._userProperties[name];
+ if (this.parentNode)
+ this.parentNode._updateDescendantUserPropertyCount(name, -1);
+ },
+
+ getUserProperty: function(name)
+ {
+ return this._userProperties ? this._userProperties[name] : null;
+ },
+
+ descendantUserPropertyCount: function(name)
+ {
+ return this._descendantUserPropertyCounters && this._descendantUserPropertyCounters[name] ? this._descendantUserPropertyCounters[name] : 0;
}
}