Web Inspector: [Extensions API] add audit formatters for remote objects and DOM elements
[WebKit-https.git] / LayoutTests / inspector / extensions / extensions-audits.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/extensions-test.js"></script>
5 <script src="../audits/audits-test.js"></script>
6 <script src="extensions-audits-tests.js"></script>
7
8 <script type="text/javascript">
9
10 function extension_testAudits(nextTest)
11 {
12     var pendingOutput = [];
13
14     function onStartAuditCategory(results)
15     {
16         pendingOutput.push("category.onAuditStarted fired");
17         results.addResult("Passed rule", "this rule always passes ok", results.Severity.Info);
18         results.addResult("Failed rule (42)", "this rule always fails", results.Severity.Severe);
19
20         var node = results.createResult("Subtree");
21         node.addChild("Some url: ", results.createURL("http://www.webkit.org", "WebKit"), " more text ", results.createURL("http://www.google.com"));
22         var nestedNode = node.addChild("... and a snippet");
23         nestedNode.expanded = true;
24         nestedNode.addChild(results.createSnippet("function rand()\n{\n    return 4;\n}"));
25         nestedNode.addChild(results.createResourceLink("file:///path/to/error.html", 10));
26         nestedNode.addChild(results.createObject("({a: 42, b: 'foo'})", "object details"));
27         nestedNode.addChild(results.createNode("document.getElementById('test-element')"));
28
29         webInspector.inspectedWindow.eval("location.href", function(inspectedPageURL) {
30             nestedNode.addChild(results.createResourceLink(inspectedPageURL, 20));
31
32             results.addResult("Rule with details subtree (1)", "This rule has a lot of details", results.Severity.Warning, node);
33
34             // Audit normally terminates when number of added rule results is equal to
35             // the rule count declared when adding a category. done() is only for
36             // emergency cases, when we know we won't be able to run the rest of the rules.
37             results.done();
38         });
39     }
40     function onStartAuditFailedCategory()
41     {
42         pendingOutput.push("failedCategory.onAuditStarted fired, throwing exception");
43         throw "oops!";
44     }
45     function onStartAuditDisabledCategory(results)
46     {
47         pendingOutput.push("FAIL: disabledCategory.onAuditStarted fired");
48         results.done();
49     }
50
51     var category = webInspector.audits.addCategory("Extension audits", 20);
52     category.onAuditStarted.addListener(onStartAuditCategory);
53
54     var failedCategory = webInspector.audits.addCategory("Extension audits that fail", 2);
55     failedCategory.onAuditStarted.addListener(onStartAuditFailedCategory);
56
57     var disabledCategory = webInspector.audits.addCategory("Disabled extension audits", 2);
58     disabledCategory.onAuditStarted.addListener(onStartAuditDisabledCategory);
59
60     function auditsDone()
61     {
62         pendingOutput.sort().forEach(output);
63         nextTest();
64     }
65     webInspector.inspectedWindow.eval("", function() {
66         extension_runAudits(auditsDone);
67     });
68 }
69
70 </script>
71 </head>
72 <body onload="runTest()">
73 <p>Tests audits support in WebInspector Extensions API</p>
74 <span id="test-element"><b></b></span>
75 </body>
76 </html>