3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/console-test.js"></script>
5 <script src="../../http/tests/inspector/network-test.js"></script>
6 <script src="../../http/tests/inspector/sources-test.js"></script>
7 <script src="../../http/tests/inspector/resources-test.js"></script>
8 <script src="../../http/tests/inspector/extensions-test.js"></script>
9 <script type="text/javascript">
15 function initialize_extensionsPanelTest()
17 InspectorTest.getPanelSize = function()
19 var boundingRect = WebInspector.inspectorView._tabbedPane._contentElement.getBoundingClientRect();
21 width: boundingRect.width,
22 height: boundingRect.height
26 InspectorTest.dumpStatusBarButtons = function()
28 var panel = WebInspector.inspectorView.currentPanel();
29 var items = panel._panelStatusBarElement.children;
30 InspectorTest.addResult("Status bar buttons state:");
31 for (var i = 0; i < items.length; ++i) {
33 if (!(item instanceof HTMLButtonElement)) {
34 InspectorTest.addResult("status bar item " + i + " is not a button.");
37 // Strip url(...) and prefix of the URL within, leave just last 3 components.
38 var url = item.style.backgroundImage.replace(/^url\(.*(([/][^/]*){3}[^/)]*)\)$/, "...$1");
39 InspectorTest.addResult("status bar item " + i + ", icon: " + url + ", tooltip: '" + item.title + "', disabled: " + item.disabled);
43 InspectorTest.clickButton = function(index)
45 var panel = WebInspector.inspectorView.currentPanel();
46 panel._panelStatusBarElement.children[index].click();
49 InspectorTest.clickOnURL = function()
51 InspectorTest.disableConsoleViewport();
52 var xpathResult = document.evaluate("//a[starts-with(., 'extensions-panel.html')]", WebInspector.ConsolePanel._view()._viewport.element, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
53 var click = document.createEvent("MouseEvent");
54 click.initMouseEvent("click", true, true);
55 xpathResult.singleNodeValue.dispatchEvent(click);
58 InspectorTest.installShowResourceLocationHooks = function()
60 function showURL(panelName, url, lineNumber)
62 var url = url.replace(/^.*(([/][^/]*){3}[^/)]*)$/, "...$1");
63 InspectorTest.addResult("Showing resource " + url + " in panel " + panelName + " (" + WebInspector.inspectorView.currentPanel().name + "), line: " + lineNumber);
65 InspectorTest.recordNetwork();
67 InspectorTest.addSniffer(WebInspector.panels.sources, "showUILocation", showUILocationHook, true);
68 InspectorTest.addSniffer(WebInspector.panels.resources, "showResource", showResourceHook, true);
69 InspectorTest.addSniffer(WebInspector.panels.network, "revealAndHighlightRequest", showRequestHook, true);
71 function showUILocationHook(uiLocation)
73 showURL("sources", uiLocation.uiSourceCode.url, uiLocation.lineNumber);
76 function showResourceHook(resource, lineNumber)
78 showURL("resources", resource.url, lineNumber);
81 function showRequestHook(request)
83 showURL("network", request.url);
87 InspectorTest.switchToLastPanel = function()
89 var lastPanelName = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id;
90 return WebInspector.inspectorView.showPanel(lastPanelName);
94 function extension_testCreatePanel(nextTest)
96 var expectOnShown = false;
98 function onPanelShown(panel, window)
100 if (!expectOnShown) {
101 output("FAIL: unexpected onShown event");
105 output("Panel shown");
106 panel.onShown.removeListener(onPanelShown);
107 evaluateOnFrontend("reply(InspectorTest.getPanelSize())", function(result) {
108 if (result.width !== window.innerWidth)
109 output("panel width mismatch, outer: " + result.width + ", inner:" + window.innerWidth);
110 else if (result.height !== window.innerHeight)
111 output("panel height mismatch, outer: " + result.height + ", inner:" + window.innerHeight);
113 output("Extension panel size correct");
118 function onPanelCreated(panel)
120 function onPanelShown(window)
122 if (!expectOnShown) {
123 output("FAIL: unexpected onShown event");
127 output("Panel shown");
128 panel.onShown.removeListener(onPanelShown);
129 panel.onHidden.addListener(onPanelHidden);
130 evaluateOnFrontend("reply(InspectorTest.getPanelSize())", function(result) {
131 if (result.width !== window.innerWidth)
132 output("panel width mismatch, outer: " + result.width + ", inner:" + window.innerWidth);
133 else if (result.height !== window.innerHeight)
134 output("panel height mismatch, outer: " + result.height + ", inner:" + window.innerHeight);
136 output("Extension panel size correct");
137 extension_showPanel("console");
141 function onPanelHidden()
143 panel.onHidden.removeListener(onPanelHidden);
144 output("Panel hidden");
148 output("Panel created");
150 panel.onShown.addListener(onPanelShown);
152 // This is not authorized and therefore should not produce any output
154 extension_showPanel("console");
156 function handleOpenResource(resource, lineNumber)
158 // This will force extension iframe to be really loaded.
161 webInspector.panels.setOpenResourceHandler(handleOpenResource);
162 evaluateOnFrontend("WebInspector.openAnchorLocationRegistry._activeHandler = 'test extension'");
163 webInspector.inspectedWindow.eval("logMessage()", function() {
164 expectOnShown = true;
165 evaluateOnFrontend("InspectorTest.clickOnURL();");
168 var basePath = location.pathname.replace(/\/[^/]*$/, "/");
169 webInspector.panels.create("Test Panel", basePath + "extension-panel.png", basePath + "extension-panel.html", onPanelCreated);
172 function extension_testSearch(nextTest)
174 var callbackCount = 0;
176 function onPanelCreated(panel)
178 var callback = function(action, queryString)
180 output("Panel searched:");
181 dumpObject(Array.prototype.slice.call(arguments));
183 if (callbackCount === 2) {
185 panel.onSearch.removeListener(callback);
188 panel.onSearch.addListener(callback);
190 extension_showPanel("extension");
192 function performSearch(query)
194 var panel = WebInspector.inspectorView.currentPanel();
195 panel.searchableView().showSearchField();
196 panel.searchableView()._searchInputElement.value = query;
197 panel.searchableView()._performSearch(true, true);
198 panel.searchableView().cancelSearch();
201 evaluateOnFrontend(performSearch.toString() + " performSearch(\"hello\");");
203 var basePath = location.pathname.replace(/\/[^/]*$/, "/");
204 webInspector.panels.create("Test Panel", basePath + "extension-panel.png", basePath + "non-existent.html", onPanelCreated);
207 function extension_testStatusBarButtons(nextTest)
209 var basePath = location.pathname.replace(/\/[^/]*$/, "/");
211 function onPanelCreated(panel)
213 var button1 = panel.createStatusBarButton(basePath + "button1.png", "Button One tooltip");
214 var button2 = panel.createStatusBarButton(basePath + "button2.png", "Button Two tooltip", true);
215 output("Created a status bar button, dump follows:");
217 function updateButtons()
219 button1.update(basePath + "button1-updated.png");
220 button2.update(null, "Button Two updated tooltip", false);
221 output("Updated status bar buttons");
222 evaluateOnFrontend("InspectorTest.dumpStatusBarButtons(); InspectorTest.clickButton(1);");
224 button1.onClicked.addListener(function() {
225 output("button1 clicked");
226 evaluateOnFrontend("InspectorTest.dumpStatusBarButtons(); reply();", updateButtons);
228 button2.onClicked.addListener(function() {
229 output("button2 clicked");
232 // First we click on button2 (that is [1] in array). But it is disabled, so this should be a noop. Then we click on button1.
233 // button1 click updates buttons. and clicks button2.
234 evaluateOnFrontend("InspectorTest.showPanel('extension').then(function() { InspectorTest.clickButton(1); InspectorTest.clickButton(0); })");
237 webInspector.panels.create("Buttons Panel", basePath + "extension-panel.png", basePath + "non-existent.html", onPanelCreated);
240 function extension_testOpenResource(nextTest)
245 evaluateOnFrontend("InspectorTest.installShowResourceLocationHooks(); reply();", function() {
246 webInspector.inspectedWindow.eval("loadResources(); location.href", function(inspectedPageURL) {
247 var basePath = inspectedPageURL.replace(/\/[^/]*$/, "/");
248 urls = [inspectedPageURL, basePath + "resources/abe.png", basePath + "resources/missing.txt", "not-found.html", "javascript:console.error('oh no!')"];
252 function showNextURL()
254 if (urlIndex >= urls.length) {
258 var url = urls[urlIndex++];
259 output("Showing " + trimURL(url));
260 webInspector.panels.openResource(url, 1000 + urlIndex, showNextURL);
264 function extension_testGlobalShortcuts(nextTest)
268 evaluateOnFrontend("reply(WebInspector.platform())", function(result) {
270 var basePath = location.pathname.replace(/\/[^/]*$/, "/");
271 webInspector.panels.create("Shortcuts Test Panel", basePath + "extension-panel.png", basePath + "extension-panel.html", onPanelCreated);
273 function dispatchKeydownEvent(attributes)
275 var event = new KeyboardEvent("keydown", attributes);
276 document.dispatchEvent(event);
278 function onPanelCreated(panel)
281 testPanel.onShown.addListener(onPanelShown);
282 testPanel.onHidden.addListener(onPanelHidden);
283 evaluateOnFrontend("InspectorTest.switchToLastPanel();");
286 function onPanelShown(win)
289 testPanel.onShown.removeListener(onPanelShown);
290 output("Panel shown, now toggling console...");
291 panelWindow.addEventListener("resize", onPanelResized);
292 dispatchKeydownEvent({ keyIdentifier: "U+001B" });
294 function onPanelResized()
296 panelWindow.removeEventListener("resize", onPanelResized);
297 output("Panel resized, switching away...");
298 var isMac = platform === "mac";
299 dispatchKeydownEvent({ ctrlKey: !isMac, metaKey: isMac, keyIdentifier: "U+005D" });
301 function onPanelHidden()
303 output("Panel hidden, test passed.");
304 testPanel.onShown.removeListener(onPanelHidden);
305 evaluateOnFrontend("reply(WebInspector.inspectorView.closeDrawer())", nextTest);
309 function loadResources()
311 var xhr = new XMLHttpRequest();
312 xhr.open("GET", "resources/missing.txt", false);
314 var img = document.createElement("img");
315 img.src = "resources/abe.png";
316 document.body.appendChild(img);
320 <body onload="runTest()">
321 <p>Tests WebInspector extension API</p>