Web Inspector: [Extensions API] add audit formatters for remote objects and DOM elements
[WebKit-https.git] / LayoutTests / inspector / audits / audits-test.js
1 function initialize_AuditTests()
2 {
3
4 InspectorTest.collectAuditResults = function()
5 {
6     WebInspector.panels.audits.showResults(WebInspector.panels.audits.auditResultsTreeElement.children[0].results);
7     var liElements = WebInspector.panels.audits.visibleView.element.getElementsByTagName("li");
8     for (var j = 0; j < liElements.length; ++j) {
9         if (liElements[j].treeElement)
10             liElements[j].treeElement.expand();
11     }
12     InspectorTest.collectTextContent(WebInspector.panels.audits.visibleView.element, 0);
13 }
14
15 InspectorTest.collectTextContent = function(element, level)
16 {
17     var nodeOutput = "";
18     var child = element.firstChild;
19
20     while (child) {
21         if (child.nodeType === Node.TEXT_NODE) {
22             for (var i = 0; i < level; ++i)
23                 nodeOutput += " ";
24             nodeOutput += child.nodeValue.replace("\u200B", "");
25         } else if (child.nodeType === Node.ELEMENT_NODE) {
26             if (nodeOutput !== "") {
27                 InspectorTest.addResult(nodeOutput);
28                 nodeOutput = "";
29             }
30             InspectorTest.collectTextContent(child, level + 1);
31         }
32         child = child.nextSibling;
33     }
34     if (nodeOutput !== "")
35         InspectorTest.addResult(nodeOutput);
36 }
37
38 }