8dc99dd95f139a46b8e69c5193dcdf872c913250
[WebKit-https.git] / LayoutTests / inspector / extensions / extensions-events.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 type="text/javascript">
6
7 function extension_testOnSelectionChanged(nextTest)
8 {
9     function onSelectionChanged()
10     {
11         webInspector.panels.elements.onSelectionChanged.removeListener(onSelectionChanged);
12         output("onSelectionChanged fired");
13         nextTest();
14     }
15     webInspector.panels.elements.onSelectionChanged.addListener(onSelectionChanged);
16     webInspector.inspectedWindow.eval("inspect(document.body.children[0])");
17 }
18
19 function extension_testOnResourceFinished(nextTest)
20 {
21     function onFinished()
22     {
23         webInspector.resources.onFinished.removeListener(onFinished);
24         output("onFinished fired");
25         nextTest();
26     }
27     webInspector.resources.onFinished.addListener(onFinished);
28     webInspector.inspectedWindow.eval("var xhr = new XMLHttpRequest(); xhr.open('GET', '" + location.href + "', false); xhr.send(null);");
29 }
30
31 function extension_testPageLoadEvents(nextTest)
32 {
33     var queuedOutput = [];
34
35     // Logging on onLoaded is tricky due to race conditions with output("Page reloaded") in page initialization code.
36     // So only log when we're sure all handlers are called and reload is done.
37     function queueOutputAndContinue(message)
38     {
39         queuedOutput.push(message);
40         if (queuedOutput.length != 3)
41             return;
42         for (i = 0; i < queuedOutput.length; ++i) {
43             if (queuedOutput[i])
44                 output(queuedOutput[i]);
45         }
46         nextTest();
47     }
48
49     webInspector.inspectedWindow.onDOMContentLoaded.addListener(function(time) {
50         queueOutputAndContinue("onDOMContentLoaded fired: " + typeof time);
51     });
52
53     webInspector.inspectedWindow.onLoaded.addListener(function(time) {
54         queueOutputAndContinue("onLoaded fired: " + typeof time);
55     });
56     dispatchOnFrontend({ command: "reload" }, queueOutputAndContinue);
57 }
58
59 function extension_testPanelShowHide(nextTest)
60 {
61     var listenersToCleanup = [];
62     function onPanelEvent(type, panelId)
63     {
64         output("Got " + type + " event for panel " + panelId);
65         if (type !== "onShown")
66             return;
67         if (panelId === "extension") {
68             addListener(webInspector.panels.elements, "elements", "onShown");
69             showPanel("elements");
70         } else if (panelId === "elements") {
71             cleanupListeners();
72             nextTest();
73         }
74     }
75     function addListener(panel, panelId, type)
76     {
77         var listener = bind(onPanelEvent, null, type, panelId);
78         var event = panel[type];
79         listenersToCleanup.push({ event: event, listener: listener });
80         event.addListener(listener);
81     }
82     function cleanupListeners()
83     {
84         for (var i = 0; i < listenersToCleanup.length; ++i)
85             listenersToCleanup[i].event.removeListener(listenersToCleanup[i].listener);
86     }
87     function onPanelCreated(panel)
88     {
89         addListener(panel, "extension", "onShown");
90         addListener(panel, "extension", "onHidden");
91         addListener(webInspector.panels.elements, "elements", "onHidden");
92         showPanel("extension");
93     }
94     showPanel("elements");
95     webInspector.panels.create("Test Panel", "extension-panel.png", "extension-panel.html", onPanelCreated);
96 }
97
98 </script>
99 </head>
100 <body onload="runTest()">
101 <p>Tests WebInspector extension API</p>
102 </body>
103 </html>