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">
11 function initialize_extensionsPanelTest()
13 InspectorTest.getPanelSize = function()
15 var boundingRect = WebInspector.inspectorView._tabbedPane._contentElement.getBoundingClientRect();
17 width: boundingRect.width,
18 height: boundingRect.height
22 InspectorTest.dumpStatusBarButtons = function()
24 var panel = WebInspector.inspectorView.currentPanel();
25 var items = panel._panelStatusBarElement.children;
26 InspectorTest.addResult("Status bar buttons state:");
27 for (var i = 0; i < items.length; ++i) {
29 if (!(item instanceof HTMLButtonElement)) {
30 InspectorTest.addResult("status bar item " + i + " is not a button.");
33 // Strip url(...) and prefix of the URL within, leave just last 3 components.
34 var url = item.style.backgroundImage.replace(/^url\(.*(([/][^/]*){3}[^/)]*)\)$/, "...$1");
35 InspectorTest.addResult("status bar item " + i + ", icon: " + url + ", tooltip: '" + item.title + "', disabled: " + item.disabled);
39 InspectorTest.clickButton = function(index)
41 var panel = WebInspector.inspectorView.currentPanel();
42 panel._panelStatusBarElement.children[index].click();
45 InspectorTest.clickOnURL = function()
47 WebInspector.inspectorView.showPanel("console");
48 var xpathResult = document.evaluate("//a[starts-with(., 'extensions-panel.html')]",
49 WebInspector.inspectorView.panel("console").element, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
50 var click = document.createEvent("MouseEvent");
51 click.initMouseEvent("click", true, true);
52 xpathResult.singleNodeValue.dispatchEvent(click);
55 InspectorTest.installShowResourceLocationHooks = function()
57 function showURL(panelName, url, lineNumber)
59 var url = url.replace(/^.*(([/][^/]*){3}[^/)]*)$/, "...$1");
60 InspectorTest.addResult("Showing resource " + url + " in panel " + panelName + " (" + WebInspector.inspectorView.currentPanel().name + "), line: " + lineNumber);
62 InspectorTest.recordNetwork();
64 WebInspector.settings.createSetting("drawerEditorShown", true).set(false);
65 InspectorTest.addSniffer(WebInspector.inspectorView.panel("sources"), "showUILocation", showUILocationHook, true);
66 InspectorTest.addSniffer(WebInspector.inspectorView.panel("resources"), "showResource", showResourceHook, true);
67 InspectorTest.addSniffer(WebInspector.inspectorView.panel("network"), "revealAndHighlightRequest", showRequestHook, true);
69 function showUILocationHook(uiLocation)
71 showURL("sources", uiLocation.uiSourceCode.url, uiLocation.lineNumber);
74 function showResourceHook(resource, lineNumber)
76 showURL("resources", resource.url, lineNumber);
79 function showRequestHook(request)
81 showURL("network", request.url);
85 InspectorTest.switchToLastPanel = function()
87 var lastPanelName = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id;
88 WebInspector.inspectorView.showPanel(lastPanelName);
92 function extension_testCreatePanel(nextTest)
94 var expectOnShown = false;
96 function onPanelShown(panel, window)
99 output("FAIL: unexpected onShown event");
103 output("Panel shown");
104 panel.onShown.removeListener(onPanelShown);
105 evaluateOnFrontend("reply(InspectorTest.getPanelSize())", function(result) {
106 if (result.width !== window.innerWidth)
107 output("panel width mismatch, outer: " + result.width + ", inner:" + window.innerWidth);
108 else if (result.height !== window.innerHeight)
109 output("panel height mismatch, outer: " + result.height + ", inner:" + window.innerHeight);
111 output("Extension panel size correct");
116 function onPanelCreated(panel)
118 function onPanelShown(window)
120 if (!expectOnShown) {
121 output("FAIL: unexpected onShown event");
125 output("Panel shown");
126 panel.onShown.removeListener(onPanelShown);
127 panel.onHidden.addListener(onPanelHidden);
128 evaluateOnFrontend("reply(InspectorTest.getPanelSize())", function(result) {
129 if (result.width !== window.innerWidth)
130 output("panel width mismatch, outer: " + result.width + ", inner:" + window.innerWidth);
131 else if (result.height !== window.innerHeight)
132 output("panel height mismatch, outer: " + result.height + ", inner:" + window.innerHeight);
134 output("Extension panel size correct");
135 extension_showPanel("console");
139 function onPanelHidden()
141 panel.onHidden.removeListener(onPanelHidden);
142 output("Panel hidden");
146 output("Panel created");
148 panel.onShown.addListener(onPanelShown);
150 // This is not authorized and therefore should not produce any output
152 extension_showPanel("console");
154 function handleOpenResource(resource, lineNumber)
156 // This will force extension iframe to be really loaded.
159 webInspector.panels.setOpenResourceHandler(handleOpenResource);
160 evaluateOnFrontend("WebInspector.openAnchorLocationRegistry._activeHandler = 'test extension'");
161 webInspector.inspectedWindow.eval("logMessage()", function() {
162 expectOnShown = true;
163 evaluateOnFrontend("InspectorTest.clickOnURL();");
166 var basePath = location.pathname.replace(/\/[^/]*$/, "/");
167 webInspector.panels.create("Test Panel", basePath + "extension-panel.png", basePath + "extension-panel.html", onPanelCreated);
170 function extension_testSearch(nextTest)
172 var callbackCount = 0;
174 function onPanelCreated(panel)
176 var callback = function(action, queryString)
178 output("Panel searched:");
179 dumpObject(Array.prototype.slice.call(arguments));
181 if (callbackCount === 2) {
183 panel.onSearch.removeListener(callback);
186 panel.onSearch.addListener(callback);
188 extension_showPanel("extension");
190 function performSearch(query)
192 var panel = WebInspector.inspectorView.currentPanel();
193 panel.searchableView().showSearchField();
194 panel.searchableView()._searchInputElement.value = query;
195 panel.searchableView()._performSearch(true, true);
196 panel.searchableView().cancelSearch();
199 evaluateOnFrontend(performSearch.toString() + " performSearch(\"hello\");");
201 var basePath = location.pathname.replace(/\/[^/]*$/, "/");
202 webInspector.panels.create("Test Panel", basePath + "extension-panel.png", basePath + "non-existent.html", onPanelCreated);
205 function extension_testStatusBarButtons(nextTest)
207 var basePath = location.pathname.replace(/\/[^/]*$/, "/");
209 function onPanelCreated(panel)
211 var button1 = panel.createStatusBarButton(basePath + "button1.png", "Button One tooltip");
212 var button2 = panel.createStatusBarButton(basePath + "button2.png", "Button Two tooltip", true);
213 output("Created a status bar button, dump follows:");
215 function updateButtons()
217 button1.update(basePath + "button1-updated.png");
218 button2.update(null, "Button Two updated tooltip", false);
219 output("Updated status bar buttons");
220 evaluateOnFrontend("InspectorTest.dumpStatusBarButtons(); InspectorTest.clickButton(1);");
222 button1.onClicked.addListener(function() {
223 output("button1 clicked");
224 evaluateOnFrontend("InspectorTest.dumpStatusBarButtons(); reply();", updateButtons);
226 button2.onClicked.addListener(function() {
227 output("button2 clicked");
230 evaluateOnFrontend("InspectorTest.showPanel('extension'); InspectorTest.clickButton(1); InspectorTest.clickButton(0);", updateButtons);
233 webInspector.panels.create("Buttons Panel", basePath + "extension-panel.png", basePath + "non-existent.html", onPanelCreated);
236 function extension_testOpenResource(nextTest)
241 evaluateOnFrontend("InspectorTest.installShowResourceLocationHooks(); reply();", function() {
242 webInspector.inspectedWindow.eval("loadResources(); location.href", function(inspectedPageURL) {
243 var basePath = inspectedPageURL.replace(/\/[^/]*$/, "/");
244 urls = [inspectedPageURL, basePath + "resources/abe.png", basePath + "resources/missing.txt", "not-found.html", "javascript:console.error('oh no!')"];
248 function showNextURL()
250 if (urlIndex >= urls.length) {
254 var url = urls[urlIndex++];
255 output("Showing " + trimURL(url));
256 webInspector.panels.openResource(url, 1000 + urlIndex, showNextURL);
260 function extension_testGlobalShortcuts(nextTest)
264 evaluateOnFrontend("reply(WebInspector.platform())", function(result) {
266 var basePath = location.pathname.replace(/\/[^/]*$/, "/");
267 webInspector.panels.create("Shortcuts Test Panel", basePath + "extension-panel.png", basePath + "extension-panel.html", onPanelCreated);
269 function dispatchKeydownEvent(attributes)
271 var event = new KeyboardEvent("keydown", attributes);
272 document.dispatchEvent(event);
274 function onPanelCreated(panel)
277 testPanel.onShown.addListener(onPanelShown);
278 testPanel.onHidden.addListener(onPanelHidden);
279 evaluateOnFrontend("InspectorTest.switchToLastPanel();");
282 function onPanelShown(win)
285 testPanel.onShown.removeListener(onPanelShown);
286 output("Panel shown, now toggling console...");
287 panelWindow.addEventListener("resize", onPanelResized);
288 dispatchKeydownEvent({ keyIdentifier: "U+001B" });
290 function onPanelResized()
292 panelWindow.removeEventListener("resize", onPanelResized);
293 output("Panel resized, switching away...");
294 var isMac = platform === "mac";
295 dispatchKeydownEvent({ ctrlKey: !isMac, metaKey: isMac, keyIdentifier: "U+005D" });
297 function onPanelHidden()
299 output("Panel hidden, test passed.");
300 testPanel.onShown.removeListener(onPanelHidden);
301 evaluateOnFrontend("reply(WebInspector.inspectorView.closeDrawer())", nextTest);
305 function loadResources()
307 var xhr = new XMLHttpRequest();
308 xhr.open("GET", "resources/missing.txt", false);
310 var img = document.createElement("img");
311 img.src = "resources/abe.png";
312 document.body.appendChild(img);
316 <body onload="runTest()">
317 <p>Tests WebInspector extension API</p>