1 var initialize_ElementTest = function() {
4 InspectorTest.nodeWithId = function(idValue, callback)
7 var topLevelChildrenRequested = false;
8 var pendingRequests = 0;
9 function processChildren(topLevel, children)
15 for (var i = 0; children && i < children.length; ++i) {
16 var childNode = children[i];
17 if (childNode.getAttribute("id") === idValue) {
24 WebInspector.domAgent.getChildNodesAsync(childNode, processChildren.bind(null, false));
28 topLevelChildrenRequested = true;
29 if (topLevelChildrenRequested && !result && !pendingRequests)
33 WebInspector.domAgent.getChildNodesAsync(WebInspector.domAgent.document, processChildren.bind(this, true));
36 InspectorTest.expandedNodeWithId = function(idValue)
39 function callback(node)
43 InspectorTest.nodeWithId(idValue, callback);
47 InspectorTest.selectNodeWithId = function(idValue, callback)
49 function mycallback(node)
52 WebInspector.updateFocusedNode(node.id);
54 InspectorTest.runAfterPendingDispatches(callback.bind(null, node));
56 InspectorTest.nodeWithId(idValue, mycallback);
59 InspectorTest.dumpSelectedElementStyles = function(excludeComputed, excludeMatched, omitLonghands)
61 var styleSections = WebInspector.panels.elements.sidebarPanes.styles.sections;
62 for (var pseudoId in styleSections) {
63 var pseudoName = WebInspector.StylesSidebarPane.PseudoIdNames[pseudoId];
64 var sections = styleSections[pseudoId];
65 for (var i = 0; i < sections.length; ++i) {
66 var section = sections[i];
67 if (section.computedStyle && excludeComputed)
69 if (section.rule && excludeMatched)
71 if (section.element.previousSibling && section.element.previousSibling.className === "styles-sidebar-separator")
72 InspectorTest.addResult("======== " + section.element.previousSibling.textContent + " ========");
73 InspectorTest.addResult((section.expanded ? "[expanded] " : "[collapsed] ") + section.titleElement.textContent + " (" + section.subtitleAsTextForTest + ")");
75 InspectorTest.dumpStyleTreeOutline(section.propertiesTreeOutline, omitLonghands ? 1 : 2);
76 InspectorTest.addResult("");
78 InspectorTest.addResult("");
82 // FIXME: this returns the first tree item found (may fail for same-named properties in a style).
83 InspectorTest.getElementStylePropertyTreeItem = function(propertyName)
85 var styleSections = WebInspector.panels.elements.sidebarPanes.styles.sections[0];
86 var elementStyleSection = styleSections[1];
87 var outline = elementStyleSection.propertiesTreeOutline;
88 for (var i = 0; i < outline.children.length; ++i) {
89 var treeItem = outline.children[i];
90 if (treeItem.name === propertyName)
96 InspectorTest.dumpStyleTreeOutline = function(treeItem, depth)
98 var children = treeItem.children;
99 for (var i = 0; i < children.length; ++i)
100 InspectorTest.dumpStyleTreeItem(children[i], "", depth || 2);
103 InspectorTest.dumpStyleTreeItem = function(treeItem, prefix, depth)
105 // Filter out width and height properties in order to minimize
107 if (!treeItem.listItemElement.textContent.indexOf("width") ||
108 !treeItem.listItemElement.textContent.indexOf("height"))
111 if (treeItem.listItemElement.hasStyleClass("inherited"))
114 if (treeItem.listItemElement.hasStyleClass("overloaded"))
115 typePrefix += "/-- overloaded --/ ";
116 if (treeItem.listItemElement.hasStyleClass("disabled"))
117 typePrefix += "/-- disabled --/ ";
118 var textContent = treeItem.listItemElement.textContent;
120 // Add non-selectable url text.
121 var textData = treeItem.listItemElement.querySelector("[data-uncopyable]");
123 textContent += textData.getAttribute("data-uncopyable");
124 InspectorTest.addResult(prefix + typePrefix + textContent);
127 var children = treeItem.children;
128 for (var i = 0; children && i < children.length; ++i)
129 InspectorTest.dumpStyleTreeItem(children[i], prefix + " ", depth);
133 InspectorTest.dumpElementsTree = function(rootNode)
135 function beautify(element)
137 return element.textContent.replace(/\u200b/g, "").replace(/\n/g, "").trim();
140 function print(treeItem, prefix)
142 if (treeItem.listItemElement) {
144 if (treeItem.hasChildren) {
145 if (treeItem.expanded)
152 InspectorTest.addResult(prefix + expander + beautify(treeItem.listItemElement));
156 if (!treeItem.expanded)
159 var children = treeItem.children;
160 for (var i = 0; children && i < children.length - 1; ++i)
161 print(children[i], prefix + " ");
164 if (children && children.length)
165 print(children[children.length - 1], prefix);
168 WebInspector.panels.elements.updateModifiedNodes();
169 var treeOutline = WebInspector.panels.elements.treeOutline;
170 print(rootNode ? treeOutline.findTreeElement(rootNode) : treeOutline, "");
173 InspectorTest.expandElementsTree = function(callback)
175 function expand(treeItem)
177 var children = treeItem.children;
178 for (var i = 0; children && i < children.length; ++i) {
179 children[i].expand();
184 function mycallback()
186 WebInspector.panels.elements.updateModifiedNodes();
187 expand(WebInspector.panels.elements.treeOutline);
191 InspectorTest.nodeWithId(/nonstring/, mycallback);
194 InspectorTest.dumpDOMAgentTree = function()
196 function dump(node, prefix)
198 InspectorTest.addResult(prefix + node.nodeName + "[" + node.id + "]");
199 var children = node.children;
200 for (var i = 0; children && i < children.length; ++i)
201 dump(children[i], prefix + " ");
203 dump(WebInspector.domAgent.document, "");