Skip to content
Permalink
Browse files
Web Inspector: Support user attributes in DOMNode
https://bugs.webkit.org/show_bug.cgi?id=88706

Reviewed by Pavel Feldman.

Source/WebCore:

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):

LayoutTests:

* 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.

Canonical link: https://commits.webkit.org/106829@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@120208 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Alexander Pavlov committed Jun 13, 2012
1 parent f97081f commit e5d20066de4d8f71e99fd32485e01d03b7523c55
@@ -1,3 +1,23 @@
2012-06-13 Alexander Pavlov <apavlov@chromium.org>

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 <vineet.chaudhary@motorola.com>

REGRESSION:Bindings sequence<T> in Console.idl, Internals.idl and ScriptProfileNode.idl should be T[]
@@ -318,6 +318,37 @@ InspectorTest.dumpElementsTree = function(rootNode, depth)
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 @@ InspectorTest.dumpElementsTree = function(rootNode, depth)
} else
expander = " ";

InspectorTest.addResult(prefix + expander + beautify(treeItem.listItemElement));
var userProperties = userPropertyDataDump(treeItem);
InspectorTest.addResult(prefix + expander + beautify(treeItem.listItemElement) + userProperties);
}

if (!treeItem.expanded)
@@ -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();
}
}
@@ -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="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="resources/user-properties.js"></script>
</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="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="resources/user-properties.js"></script>
</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="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="resources/user-properties.js"></script>
</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="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="resources/user-properties.js"></script>
</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="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="resources/user-properties.js"></script>
</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="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="resources/user-properties.js"></script>
</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="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="resources/user-properties.js"></script>
</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="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="resources/user-properties.js"></script>
</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>

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/elements-test.js"></script>
<script src="resources/user-properties.js"></script>
</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>
@@ -1,3 +1,24 @@
2012-06-13 Alexander Pavlov <apavlov@chromium.org>

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 <vineet.chaudhary@motorola.com>

REGRESSION:Bindings sequence<T> in Console.idl, Internals.idl and ScriptProfileNode.idl should be T[]

0 comments on commit e5d2006

Please sign in to comment.