Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / inspector / extensions / extensions-events.html
blob44f2d925b790fa0098c7613f4d29b62c8042737a
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="../../http/tests/inspector/debugger-test.js"></script>
6 <script src="../sources/debugger/resources/edit-me.js"></script>
7 <script type="text/javascript">
9 function initialize_extensionsSidebarTest()
11 InspectorTest.expandSidebar = function(callback)
13 var sidebar = InspectorTest._extensionSidebar();
14 InspectorTest.runAfterPendingDispatches(function() {
15 sidebar.expand();
16 callback();
17 });
20 InspectorTest._extensionSidebar = function()
22 return WebInspector.extensionServer.sidebarPanes()[0];
26 function extension_expandSidebar(callback)
28 evaluateOnFrontend("InspectorTest.expandSidebar(reply);", callback);
31 function extension_testOnSelectionChanged(nextTest)
33 function onSelectionChanged()
35 webInspector.panels.elements.onSelectionChanged.removeListener(onSelectionChanged);
36 output("onSelectionChanged fired");
37 nextTest();
39 webInspector.panels.elements.onSelectionChanged.addListener(onSelectionChanged);
40 webInspector.inspectedWindow.eval("inspect(document.body.children[0]), 0");
43 function extension_testOnRequestFinished(nextTest)
45 function onRequestFinished()
47 webInspector.network.onRequestFinished.removeListener(onRequestFinished);
48 output("onRequestFinished fired");
49 nextTest();
51 webInspector.network.onRequestFinished.addListener(onRequestFinished);
52 webInspector.inspectedWindow.eval("var xhr = new XMLHttpRequest(); xhr.open('GET', '" + location.href + "', false); xhr.send(null);");
55 function extension_testOnNavigated(nextTest)
57 var urls = [];
58 var loadCount = 0;
60 function onLoad()
62 ++loadCount;
63 processEvent();
65 function processEvent()
67 if (loadCount !== urls.length)
68 return;
69 if (loadCount === 1)
70 evaluateOnFrontend("InspectorTest.navigate(InspectorTest.resourceTreeModel.inspectedPageURL().substring(0, InspectorTest.resourceTreeModel.inspectedPageURL().indexOf('?')), reply)", onLoad);
71 else {
72 webInspector.network.onNavigated.removeListener(onNavigated);
73 for (var i = 0; i < urls.length; ++i)
74 output("Navigated to: " + urls[i]);
75 nextTest();
78 function onNavigated(url)
80 urls.push(url.replace(/^(.*\/)*/, ""));
81 processEvent();
83 webInspector.network.onNavigated.addListener(onNavigated);
84 evaluateOnFrontend("InspectorTest.navigate(InspectorTest.resourceTreeModel.inspectedPageURL() + '?navigated', reply)", onLoad);
87 function extension_testViewShowHide(nextTest)
89 var listenersToCleanup = [];
90 var sidebar;
91 var beenToExtensionPanel = false;
93 function onViewEvent(type, viewName, viewWindow)
95 output("Got " + type + " event for " + viewName);
96 if (type !== "onShown")
97 return;
98 if (viewName === "panel") {
99 output("Panel shown, location: " + trimURL(viewWindow.location.href));
100 extension_showPanel("elements");
101 } else if (viewName === "sidebar") {
102 output("Sidebar shown, location: " + trimURL(viewWindow.location.href));
103 if (!beenToExtensionPanel) {
104 extension_showPanel("extension");
105 beenToExtensionPanel = true;
106 } else {
107 cleanupListeners();
108 nextTest();
112 function addListener(view, viewName, type)
114 var listener = bind(onViewEvent, null, type, viewName);
115 var event = view[type];
116 listenersToCleanup.push({ event: event, listener: listener });
117 event.addListener(listener);
119 function cleanupListeners()
121 for (var i = 0; i < listenersToCleanup.length; ++i)
122 listenersToCleanup[i].event.removeListener(listenersToCleanup[i].listener);
124 function onPanelCreated(panel)
126 addListener(panel, "panel", "onShown");
127 addListener(panel, "panel", "onHidden");
128 addListener(sidebar, "sidebar", "onHidden");
129 addListener(sidebar, "sidebar", "onShown");
130 sidebar.setPage(basePath + "extension-sidebar.html");
132 extension_showPanel("elements", extension_expandSidebar);
133 var basePath = location.pathname.replace(/\/[^/]*$/, "/");
134 function onSidebarCreated(sidebarPane)
136 sidebar = sidebarPane;
137 webInspector.panels.create("Test Panel", basePath + "extension-panel.png", basePath + "extension-panel.html", onPanelCreated);
139 webInspector.panels.elements.createSidebarPane("Test Sidebar", onSidebarCreated);
142 </script>
143 </head>
144 <body onload="runTest()">
145 <p>Tests WebInspector extension API</p>
146 </body>
147 </html>