e581a55e7a6a9c15a5ac222185538efd066b08e8
[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         webInspector.inspectedWindow.eval("location.href", function(inspectedPageURL) {
27             nestedNode.addChild(results.createResourceLink(inspectedPageURL, 20));
28
29             results.addResult("Rule with details subtree (1)", "This rule has a lot of details", results.Severity.Warning, node);
30
31             // Audit normally terminates when number of added rule results is equal to
32             // the rule count declared when adding a category. done() is only for
33             // emergency cases, when we know we won't be able to run the rest of the rules.
34             results.done();
35         });
36     }
37     function onStartAuditFailedCategory()
38     {
39         pendingOutput.push("failedCategory.onAuditStarted fired, throwing exception");
40         throw "oops!";
41     }
42     function onStartAuditDisabledCategory(results)
43     {
44         pendingOutput.push("FAIL: disabledCategory.onAuditStarted fired");
45         results.done();
46     }
47
48     var category = webInspector.audits.addCategory("Extension audits", 20);
49     category.onAuditStarted.addListener(onStartAuditCategory);
50
51     var failedCategory = webInspector.audits.addCategory("Extension audits that fail", 2);
52     failedCategory.onAuditStarted.addListener(onStartAuditFailedCategory);
53
54     var disabledCategory = webInspector.audits.addCategory("Disabled extension audits", 2);
55     disabledCategory.onAuditStarted.addListener(onStartAuditDisabledCategory);
56
57     function auditsDone()
58     {
59         pendingOutput.sort().forEach(output);
60         nextTest();
61     }
62     webInspector.inspectedWindow.eval("", function() {
63         extension_runAudits(auditsDone);
64     });
65 }
66
67 </script>
68 </head>
69 <body onload="runTest()">
70 <p>Tests audits support in WebInspector Extensions API</p>
71 </body>
72 </html>