| <html> |
| <head> |
| <script src="../../http/tests/inspector/inspector-test.js"></script> |
| <script src="../../http/tests/inspector/console-test.js"></script> |
| <script src="../../http/tests/inspector/network-test.js"></script> |
| <script src="../../http/tests/inspector/sources-test.js"></script> |
| <script src="../../http/tests/inspector/resources-test.js"></script> |
| <script src="../../http/tests/inspector/extensions-test.js"></script> |
| <script type="text/javascript"> |
| function logMessage() |
| { |
| console.log("hello"); |
| } |
| |
| function initialize_extensionsPanelTest() |
| { |
| InspectorTest.getPanelSize = function() |
| { |
| var boundingRect = WebInspector.inspectorView._tabbedPane._contentElement.getBoundingClientRect(); |
| return { |
| width: boundingRect.width, |
| height: boundingRect.height |
| }; |
| } |
| |
| InspectorTest.dumpStatusBarButtons = function() |
| { |
| var panel = WebInspector.inspectorView.currentPanel(); |
| var items = panel._panelToolbar._contentElement.children; |
| InspectorTest.addResult("Status bar buttons state:"); |
| for (var i = 0; i < items.length; ++i) { |
| var item = items[i]; |
| if (item instanceof HTMLContentElement) |
| continue; |
| if (!(item instanceof HTMLButtonElement)) { |
| InspectorTest.addResult("status bar item " + i + " is not a button: " + item); |
| continue; |
| } |
| // Strip url(...) and prefix of the URL within, leave just last 3 components. |
| var url = item.style.backgroundImage.replace(/^url\(.*(([/][^/]*){3}[^/)]*)\)$/, "...$1"); |
| InspectorTest.addResult("status bar item " + i + ", icon: \"" + url + ", tooltip: '" + item[WebInspector.Tooltip._symbol].content + "', disabled: " + item.disabled); |
| } |
| } |
| |
| InspectorTest.clickButton = function(index) |
| { |
| var panel = WebInspector.inspectorView.currentPanel(); |
| var items = panel._panelToolbar._contentElement.children; |
| for (var i = 0, buttonIndex = 0; i < items.length; ++i) { |
| if (items[i] instanceof HTMLButtonElement) { |
| if (buttonIndex === index) { |
| items[i].click(); |
| return; |
| } |
| buttonIndex++; |
| } |
| } |
| InspectorTest.addResult("No button with index " + index); |
| items[index].click(); |
| } |
| |
| InspectorTest.logMessageAndClickOnURL = function() |
| { |
| InspectorTest.disableConsoleViewport(); |
| InspectorTest.evaluateInPage("logMessage()"); |
| var wrappedConsoleMessageAdded = InspectorTest.safeWrap(consoleMessageAdded); |
| WebInspector.multitargetConsoleModel.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, wrappedConsoleMessageAdded); |
| |
| function consoleMessageAdded() |
| { |
| WebInspector.multitargetConsoleModel.removeEventListener(WebInspector.ConsoleModel.Events.MessageAdded, wrappedConsoleMessageAdded); |
| WebInspector.ConsoleView.instance()._viewportThrottler.flush(); |
| InspectorTest.deprecatedRunAfterPendingDispatches(clickOnMessage) |
| } |
| |
| function clickOnMessage() |
| { |
| var xpathResult = document.evaluate("//a[starts-with(., 'extensions-panel.html')]", WebInspector.ConsoleView.instance()._viewport.element, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null); |
| |
| var click = document.createEvent("MouseEvent"); |
| click.initMouseEvent("click", true, true); |
| xpathResult.singleNodeValue.dispatchEvent(click); |
| } |
| } |
| |
| InspectorTest.installShowResourceLocationHooks = function() |
| { |
| function showURL(panelName, url, lineNumber) |
| { |
| var url = url.replace(/^.*(([/][^/]*){3}[^/)]*)$/, "...$1"); |
| InspectorTest.addResult("Showing resource " + url + " in panel " + panelName + " (" + WebInspector.inspectorView.currentPanel().name + "), line: " + lineNumber); |
| } |
| InspectorTest.recordNetwork(); |
| |
| InspectorTest.addSniffer(WebInspector.panels.sources, "showUILocation", showUILocationHook, true); |
| InspectorTest.addSniffer(WebInspector.panels.resources, "showResource", showResourceHook, true); |
| InspectorTest.addSniffer(WebInspector.panels.network, "revealAndHighlightRequest", showRequestHook, true); |
| |
| function showUILocationHook(uiLocation) |
| { |
| var networkURL = WebInspector.networkMapping.networkURL(uiLocation.uiSourceCode); |
| showURL("sources", networkURL, uiLocation.lineNumber); |
| } |
| |
| function showResourceHook(resource, lineNumber) |
| { |
| showURL("resources", resource.url, lineNumber); |
| } |
| |
| function showRequestHook(request) |
| { |
| showURL("network", request.url); |
| } |
| } |
| |
| InspectorTest.switchToLastPanel = function() |
| { |
| var lastPanelName = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id; |
| return WebInspector.inspectorView.showPanel(lastPanelName); |
| } |
| } |
| |
| function extension_testCreatePanel(nextTest) |
| { |
| var expectOnShown = false; |
| |
| function onPanelShown(panel, window) |
| { |
| if (!expectOnShown) { |
| output("FAIL: unexpected onShown event"); |
| nextTest(); |
| return; |
| } |
| output("Panel shown"); |
| panel.onShown.removeListener(onPanelShown); |
| evaluateOnFrontend("reply(InspectorTest.getPanelSize())", function(result) { |
| if (result.width !== window.innerWidth) |
| output("panel width mismatch, outer: " + result.width + ", inner:" + window.innerWidth); |
| else if (result.height !== window.innerHeight) |
| output("panel height mismatch, outer: " + result.height + ", inner:" + window.innerHeight); |
| else |
| output("Extension panel size correct"); |
| nextTest(); |
| }); |
| } |
| |
| function onPanelCreated(panel) |
| { |
| function onPanelShown(window) |
| { |
| if (!expectOnShown) { |
| output("FAIL: unexpected onShown event"); |
| nextTest(); |
| return; |
| } |
| output("Panel shown"); |
| panel.onShown.removeListener(onPanelShown); |
| panel.onHidden.addListener(onPanelHidden); |
| evaluateOnFrontend("reply(InspectorTest.getPanelSize())", function(result) { |
| if (result.width !== window.innerWidth) |
| output("panel width mismatch, outer: " + result.width + ", inner:" + window.innerWidth); |
| else if (result.height !== window.innerHeight) |
| output("panel height mismatch, outer: " + result.height + ", inner:" + window.innerHeight); |
| else |
| output("Extension panel size correct"); |
| extension_showPanel("console"); |
| }); |
| } |
| |
| function onPanelHidden() |
| { |
| panel.onHidden.removeListener(onPanelHidden); |
| output("Panel hidden"); |
| nextTest(); |
| } |
| |
| output("Panel created"); |
| dumpObject(panel); |
| panel.onShown.addListener(onPanelShown); |
| |
| // This is not authorized and therefore should not produce any output |
| panel.show(); |
| extension_showPanel("console"); |
| |
| function handleOpenResource(resource, lineNumber) |
| { |
| // This will force extension iframe to be really loaded. |
| panel.show(); |
| } |
| webInspector.panels.setOpenResourceHandler(handleOpenResource); |
| evaluateOnFrontend("WebInspector.openAnchorLocationRegistry._activeHandler = 'test extension'"); |
| evaluateOnFrontend("InspectorTest.logMessageAndClickOnURL();"); |
| expectOnShown = true; |
| } |
| var basePath = location.pathname.replace(/\/[^/]*$/, "/"); |
| webInspector.panels.create("Test Panel", basePath + "extension-panel.png", basePath + "extension-panel.html", onPanelCreated); |
| } |
| |
| function extension_testSearch(nextTest) |
| { |
| var callbackCount = 0; |
| |
| function onPanelCreated(panel) |
| { |
| var callback = function(action, queryString) |
| { |
| output("Panel searched:"); |
| dumpObject(Array.prototype.slice.call(arguments)); |
| callbackCount++; |
| if (callbackCount === 2) { |
| nextTest(); |
| panel.onSearch.removeListener(callback); |
| } |
| }; |
| panel.onSearch.addListener(callback); |
| |
| extension_showPanel("extension"); |
| |
| function performSearch(query) |
| { |
| var panel = WebInspector.inspectorView.currentPanel(); |
| panel.searchableView().showSearchField(); |
| panel.searchableView()._searchInputElement.value = query; |
| panel.searchableView()._performSearch(true, true); |
| panel.searchableView().cancelSearch(); |
| } |
| |
| evaluateOnFrontend(performSearch.toString() + " performSearch(\"hello\");"); |
| } |
| var basePath = location.pathname.replace(/\/[^/]*$/, "/"); |
| webInspector.panels.create("Test Panel", basePath + "extension-panel.png", basePath + "non-existent.html", onPanelCreated); |
| } |
| |
| function extension_testStatusBarButtons(nextTest) |
| { |
| var basePath = location.pathname.replace(/\/[^/]*$/, "/"); |
| |
| function onPanelCreated(panel) |
| { |
| var button1 = panel.createStatusBarButton(basePath + "button1.png", "Button One tooltip"); |
| var button2 = panel.createStatusBarButton(basePath + "button2.png", "Button Two tooltip", true); |
| output("Created a status bar button, dump follows:"); |
| dumpObject(button1); |
| function updateButtons() |
| { |
| button1.update(basePath + "button1-updated.png"); |
| button2.update(null, "Button Two updated tooltip", false); |
| output("Updated status bar buttons"); |
| evaluateOnFrontend("InspectorTest.dumpStatusBarButtons(); InspectorTest.clickButton(1);"); |
| } |
| button1.onClicked.addListener(function() { |
| output("button1 clicked"); |
| evaluateOnFrontend("InspectorTest.dumpStatusBarButtons(); reply();", updateButtons); |
| }); |
| button2.onClicked.addListener(function() { |
| output("button2 clicked"); |
| nextTest(); |
| }); |
| // 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. |
| // button1 click updates buttons. and clicks button2. |
| evaluateOnFrontend("InspectorTest.showPanel('extension').then(function() { InspectorTest.clickButton(1); InspectorTest.clickButton(0); })"); |
| } |
| |
| webInspector.panels.create("Buttons Panel", basePath + "extension-panel.png", basePath + "non-existent.html", onPanelCreated); |
| } |
| |
| function extension_testOpenResource(nextTest) |
| { |
| var urls; |
| var urlIndex = 0; |
| |
| evaluateOnFrontend("InspectorTest.installShowResourceLocationHooks(); reply();", function() { |
| webInspector.inspectedWindow.eval("loadResources(); location.href", function(inspectedPageURL) { |
| var basePath = inspectedPageURL.replace(/\/[^/]*$/, "/"); |
| urls = [inspectedPageURL, basePath + "resources/abe.png", basePath + "resources/missing.txt", "not-found.html", "javascript:console.error('oh no!')"]; |
| showNextURL(); |
| }); |
| }); |
| function showNextURL() |
| { |
| if (urlIndex >= urls.length) { |
| nextTest(); |
| return; |
| } |
| var url = urls[urlIndex++]; |
| output("Showing " + trimURL(url)); |
| webInspector.panels.openResource(url, 1000 + urlIndex, showNextURL); |
| } |
| } |
| |
| function extension_testGlobalShortcuts(nextTest) |
| { |
| var platform; |
| var testPanel; |
| evaluateOnFrontend("reply(WebInspector.platform())", function(result) { |
| platform = result; |
| var basePath = location.pathname.replace(/\/[^/]*$/, "/"); |
| webInspector.panels.create("Shortcuts Test Panel", basePath + "extension-panel.png", basePath + "extension-panel.html", onPanelCreated); |
| }); |
| function dispatchKeydownEvent(attributes) |
| { |
| var event = new KeyboardEvent("keydown", attributes); |
| document.dispatchEvent(event); |
| } |
| function onPanelCreated(panel) |
| { |
| testPanel = panel; |
| testPanel.onShown.addListener(onPanelShown); |
| testPanel.onHidden.addListener(onPanelHidden); |
| evaluateOnFrontend("InspectorTest.switchToLastPanel();"); |
| } |
| var panelWindow; |
| function onPanelShown(win) |
| { |
| panelWindow = win; |
| testPanel.onShown.removeListener(onPanelShown); |
| output("Panel shown, now toggling console..."); |
| panelWindow.addEventListener("resize", onPanelResized); |
| dispatchKeydownEvent({ key: "Escape", keyIdentifier: "U+001B" }); |
| } |
| function onPanelResized() |
| { |
| panelWindow.removeEventListener("resize", onPanelResized); |
| output("Panel resized, switching away..."); |
| var isMac = platform === "mac"; |
| dispatchKeydownEvent({ ctrlKey: !isMac, metaKey: isMac, key: "]" }); |
| } |
| function onPanelHidden() |
| { |
| output("Panel hidden, test passed."); |
| testPanel.onShown.removeListener(onPanelHidden); |
| evaluateOnFrontend("reply(WebInspector.inspectorView.closeDrawer())", nextTest); |
| } |
| } |
| |
| function loadResources() |
| { |
| var xhr = new XMLHttpRequest(); |
| xhr.open("GET", "resources/missing.txt", false); |
| xhr.send(); |
| var img = document.createElement("img"); |
| img.src = "resources/abe.png"; |
| document.body.appendChild(img); |
| } |
| </script> |
| </head> |
| <body onload="runTest()"> |
| <p>Tests WebInspector extension API</p> |
| </body> |
| </html> |