michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() michael@0: { michael@0: // Test is slow on Linux EC2 instances - Bug 962931 michael@0: requestLongerTimeout(2); michael@0: michael@0: let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); michael@0: let {Task} = Cu.import("resource://gre/modules/Task.jsm", {}); michael@0: let Toolbox = devtools.Toolbox; michael@0: let toolbox; michael@0: michael@0: addTab("data:text/html;charset=utf-8,Web Console test for splitting"); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: testConsoleLoadOnDifferentPanel() michael@0: }, true); michael@0: michael@0: function testConsoleLoadOnDifferentPanel() michael@0: { michael@0: info("About to check console loads even when non-webconsole panel is open"); michael@0: michael@0: openPanel("inspector").then(() => { michael@0: toolbox.on("webconsole-ready", () => { michael@0: ok(true, "Webconsole has been triggered as loaded while another tool is active"); michael@0: testKeyboardShortcuts(); michael@0: }); michael@0: michael@0: // Opens split console. michael@0: toolbox.toggleSplitConsole(); michael@0: }); michael@0: } michael@0: michael@0: function testKeyboardShortcuts() michael@0: { michael@0: info("About to check that panel responds to ESCAPE keyboard shortcut"); michael@0: michael@0: toolbox.once("split-console", () => { michael@0: ok(true, "Split console has been triggered via ESCAPE keypress"); michael@0: checkAllTools(); michael@0: }); michael@0: michael@0: // Closes split console. michael@0: EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); michael@0: } michael@0: michael@0: function checkAllTools() michael@0: { michael@0: info("About to check split console with each panel individually."); michael@0: michael@0: Task.spawn(function() { michael@0: yield openAndCheckPanel("jsdebugger"); michael@0: yield openAndCheckPanel("inspector"); michael@0: yield openAndCheckPanel("styleeditor"); michael@0: yield openAndCheckPanel("jsprofiler"); michael@0: yield openAndCheckPanel("netmonitor"); michael@0: michael@0: yield checkWebconsolePanelOpened(); michael@0: testBottomHost(); michael@0: }); michael@0: } michael@0: michael@0: function getCurrentUIState() michael@0: { michael@0: let win = toolbox.doc.defaultView; michael@0: let deck = toolbox.doc.querySelector("#toolbox-deck"); michael@0: let webconsolePanel = toolbox.doc.querySelector("#toolbox-panel-webconsole"); michael@0: let splitter = toolbox.doc.querySelector("#toolbox-console-splitter"); michael@0: michael@0: let containerHeight = parseFloat(win.getComputedStyle(deck.parentNode).getPropertyValue("height")); michael@0: let deckHeight = parseFloat(win.getComputedStyle(deck).getPropertyValue("height")); michael@0: let webconsoleHeight = parseFloat(win.getComputedStyle(webconsolePanel).getPropertyValue("height")); michael@0: let splitterVisibility = !splitter.getAttribute("hidden"); michael@0: let openedConsolePanel = toolbox.currentToolId === "webconsole"; michael@0: let cmdButton = toolbox.doc.querySelector("#command-button-splitconsole"); michael@0: michael@0: return { michael@0: deckHeight: deckHeight, michael@0: containerHeight: containerHeight, michael@0: webconsoleHeight: webconsoleHeight, michael@0: splitterVisibility: splitterVisibility, michael@0: openedConsolePanel: openedConsolePanel, michael@0: buttonSelected: cmdButton.hasAttribute("checked") michael@0: }; michael@0: } michael@0: michael@0: function checkWebconsolePanelOpened() michael@0: { michael@0: info("About to check special cases when webconsole panel is open."); michael@0: michael@0: let deferred = promise.defer(); michael@0: michael@0: // Start with console split, so we can test for transition to main panel. michael@0: toolbox.toggleSplitConsole(); michael@0: michael@0: let currentUIState = getCurrentUIState(); michael@0: michael@0: ok (currentUIState.splitterVisibility, "Splitter is visible when console is split"); michael@0: ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split"); michael@0: ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split"); michael@0: ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); michael@0: ok (currentUIState.buttonSelected, "The command button is selected"); michael@0: michael@0: openPanel("webconsole").then(() => { michael@0: michael@0: let currentUIState = getCurrentUIState(); michael@0: michael@0: ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened."); michael@0: is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened."); michael@0: is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height."); michael@0: ok (currentUIState.openedConsolePanel, "The console panel is the current tool"); michael@0: ok (currentUIState.buttonSelected, "The command button is still selected."); michael@0: michael@0: // Make sure splitting console does nothing while webconsole is opened michael@0: toolbox.toggleSplitConsole(); michael@0: michael@0: let currentUIState = getCurrentUIState(); michael@0: michael@0: ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened."); michael@0: is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened."); michael@0: is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height."); michael@0: ok (currentUIState.openedConsolePanel, "The console panel is the current tool"); michael@0: ok (currentUIState.buttonSelected, "The command button is still selected."); michael@0: michael@0: // Make sure that split state is saved after opening another panel michael@0: openPanel("inspector").then(() => { michael@0: let currentUIState = getCurrentUIState(); michael@0: ok (currentUIState.splitterVisibility, "Splitter is visible when console is split"); michael@0: ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split"); michael@0: ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split"); michael@0: ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); michael@0: ok (currentUIState.buttonSelected, "The command button is still selected."); michael@0: michael@0: toolbox.toggleSplitConsole(); michael@0: deferred.resolve(); michael@0: michael@0: }); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function openPanel(toolId, callback) michael@0: { michael@0: let deferred = promise.defer(); michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: gDevTools.showToolbox(target, toolId).then(function(box) { michael@0: toolbox = box; michael@0: deferred.resolve(); michael@0: }).then(null, console.error); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function openAndCheckPanel(toolId) michael@0: { michael@0: let deferred = promise.defer(); michael@0: openPanel(toolId).then(() => { michael@0: info ("Checking toolbox for " + toolId); michael@0: checkToolboxUI(toolbox.getCurrentPanel()); michael@0: deferred.resolve(); michael@0: }); michael@0: return deferred.promise; michael@0: } michael@0: michael@0: function checkToolboxUI() michael@0: { michael@0: let currentUIState = getCurrentUIState(); michael@0: michael@0: ok (!currentUIState.splitterVisibility, "Splitter is hidden by default"); michael@0: is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 by default"); michael@0: is (currentUIState.webconsoleHeight, 0, "Web console is collapsed by default"); michael@0: ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); michael@0: ok (!currentUIState.buttonSelected, "The command button is not selected."); michael@0: michael@0: toolbox.toggleSplitConsole(); michael@0: michael@0: let currentUIState = getCurrentUIState(); michael@0: michael@0: ok (currentUIState.splitterVisibility, "Splitter is visible when console is split"); michael@0: ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split"); michael@0: ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split"); michael@0: is (currentUIState.deckHeight + currentUIState.webconsoleHeight, michael@0: currentUIState.containerHeight, michael@0: "Everything adds up to container height"); michael@0: ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); michael@0: ok (currentUIState.buttonSelected, "The command button is selected."); michael@0: michael@0: toolbox.toggleSplitConsole(); michael@0: michael@0: let currentUIState = getCurrentUIState(); michael@0: michael@0: ok (!currentUIState.splitterVisibility, "Splitter is hidden after toggling"); michael@0: is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 after toggling"); michael@0: is (currentUIState.webconsoleHeight, 0, "Web console is collapsed after toggling"); michael@0: ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); michael@0: ok (!currentUIState.buttonSelected, "The command button is not selected."); michael@0: } michael@0: michael@0: function testBottomHost() michael@0: { michael@0: checkHostType(Toolbox.HostType.BOTTOM); michael@0: michael@0: checkToolboxUI(); michael@0: michael@0: toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost); michael@0: } michael@0: michael@0: function testSidebarHost() michael@0: { michael@0: checkHostType(Toolbox.HostType.SIDE); michael@0: michael@0: checkToolboxUI(); michael@0: michael@0: toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost); michael@0: } michael@0: michael@0: function testWindowHost() michael@0: { michael@0: checkHostType(Toolbox.HostType.WINDOW); michael@0: michael@0: checkToolboxUI(); michael@0: michael@0: toolbox.switchHost(Toolbox.HostType.BOTTOM).then(testDestroy); michael@0: } michael@0: michael@0: function checkHostType(hostType) michael@0: { michael@0: is(toolbox.hostType, hostType, "host type is " + hostType); michael@0: michael@0: let pref = Services.prefs.getCharPref("devtools.toolbox.host"); michael@0: is(pref, hostType, "host pref is " + hostType); michael@0: } michael@0: michael@0: function testDestroy() michael@0: { michael@0: toolbox.destroy().then(function() { michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: gDevTools.showToolbox(target).then(finish); michael@0: }); michael@0: } michael@0: michael@0: function finish() michael@0: { michael@0: toolbox = null; michael@0: finishTest(); michael@0: } michael@0: }