2011-04-06 Andrey Kosyakov <caseq@chromium.org>
[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_testOnNavigated(nextTest)
32 {
33     var urls = [];
34     var loadCount = 0;
35
36     function onLoad()
37     {
38         ++loadCount;
39         processEvent();
40     }
41     function processEvent()
42     {
43         if (loadCount !== urls.length)
44             return;
45         if (loadCount === 1) {
46             dispatchOnFrontend({ command: "run-when-page-loads" }, onLoad);
47             webInspector.inspectedWindow.eval("location.href = location.origin + location.pathname");
48         }
49         else {
50             webInspector.resources.onNavigated.removeListener(onNavigated);
51             for (var i = 0; i < urls.length; ++i)
52                 output("Navigated to: " + urls[i]);
53             nextTest();
54         }
55     }
56     function onNavigated(url)
57     {
58         urls.push(url.replace(/^(.*\/)*/, ""));
59         processEvent();
60     }
61     webInspector.resources.onNavigated.addListener(onNavigated);
62     dispatchOnFrontend({ command: "run-when-page-loads" }, onLoad);
63     webInspector.inspectedWindow.eval("location.href = location.href + '?navigated'");
64 }
65
66 function extension_testPanelShowHide(nextTest)
67 {
68     var listenersToCleanup = [];
69     function onPanelEvent(type, panelId)
70     {
71         output("Got " + type + " event for panel " + panelId);
72         if (type !== "onShown")
73             return;
74         if (panelId === "extension") {
75             addListener(webInspector.panels.elements, "elements", "onShown");
76             showPanel("elements");
77         } else if (panelId === "elements") {
78             cleanupListeners();
79             nextTest();
80         }
81     }
82     function addListener(panel, panelId, type)
83     {
84         var listener = bind(onPanelEvent, null, type, panelId);
85         var event = panel[type];
86         listenersToCleanup.push({ event: event, listener: listener });
87         event.addListener(listener);
88     }
89     function cleanupListeners()
90     {
91         for (var i = 0; i < listenersToCleanup.length; ++i)
92             listenersToCleanup[i].event.removeListener(listenersToCleanup[i].listener);
93     }
94     function onPanelCreated(panel)
95     {
96         addListener(panel, "extension", "onShown");
97         addListener(panel, "extension", "onHidden");
98         addListener(webInspector.panels.elements, "elements", "onHidden");
99         showPanel("extension");
100     }
101     showPanel("elements");
102     webInspector.panels.create("Test Panel", "extension-panel.png", "extension-panel.html", onPanelCreated);
103 }
104
105 </script>
106 </head>
107 <body onload="runTest()">
108 <p>Tests WebInspector extension API</p>
109 </body>
110 </html>