1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_split.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,249 @@ 1.4 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +function test() 1.10 +{ 1.11 + // Test is slow on Linux EC2 instances - Bug 962931 1.12 + requestLongerTimeout(2); 1.13 + 1.14 + let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); 1.15 + let {Task} = Cu.import("resource://gre/modules/Task.jsm", {}); 1.16 + let Toolbox = devtools.Toolbox; 1.17 + let toolbox; 1.18 + 1.19 + addTab("data:text/html;charset=utf-8,Web Console test for splitting"); 1.20 + browser.addEventListener("load", function onLoad() { 1.21 + browser.removeEventListener("load", onLoad, true); 1.22 + testConsoleLoadOnDifferentPanel() 1.23 + }, true); 1.24 + 1.25 + function testConsoleLoadOnDifferentPanel() 1.26 + { 1.27 + info("About to check console loads even when non-webconsole panel is open"); 1.28 + 1.29 + openPanel("inspector").then(() => { 1.30 + toolbox.on("webconsole-ready", () => { 1.31 + ok(true, "Webconsole has been triggered as loaded while another tool is active"); 1.32 + testKeyboardShortcuts(); 1.33 + }); 1.34 + 1.35 + // Opens split console. 1.36 + toolbox.toggleSplitConsole(); 1.37 + }); 1.38 + } 1.39 + 1.40 + function testKeyboardShortcuts() 1.41 + { 1.42 + info("About to check that panel responds to ESCAPE keyboard shortcut"); 1.43 + 1.44 + toolbox.once("split-console", () => { 1.45 + ok(true, "Split console has been triggered via ESCAPE keypress"); 1.46 + checkAllTools(); 1.47 + }); 1.48 + 1.49 + // Closes split console. 1.50 + EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); 1.51 + } 1.52 + 1.53 + function checkAllTools() 1.54 + { 1.55 + info("About to check split console with each panel individually."); 1.56 + 1.57 + Task.spawn(function() { 1.58 + yield openAndCheckPanel("jsdebugger"); 1.59 + yield openAndCheckPanel("inspector"); 1.60 + yield openAndCheckPanel("styleeditor"); 1.61 + yield openAndCheckPanel("jsprofiler"); 1.62 + yield openAndCheckPanel("netmonitor"); 1.63 + 1.64 + yield checkWebconsolePanelOpened(); 1.65 + testBottomHost(); 1.66 + }); 1.67 + } 1.68 + 1.69 + function getCurrentUIState() 1.70 + { 1.71 + let win = toolbox.doc.defaultView; 1.72 + let deck = toolbox.doc.querySelector("#toolbox-deck"); 1.73 + let webconsolePanel = toolbox.doc.querySelector("#toolbox-panel-webconsole"); 1.74 + let splitter = toolbox.doc.querySelector("#toolbox-console-splitter"); 1.75 + 1.76 + let containerHeight = parseFloat(win.getComputedStyle(deck.parentNode).getPropertyValue("height")); 1.77 + let deckHeight = parseFloat(win.getComputedStyle(deck).getPropertyValue("height")); 1.78 + let webconsoleHeight = parseFloat(win.getComputedStyle(webconsolePanel).getPropertyValue("height")); 1.79 + let splitterVisibility = !splitter.getAttribute("hidden"); 1.80 + let openedConsolePanel = toolbox.currentToolId === "webconsole"; 1.81 + let cmdButton = toolbox.doc.querySelector("#command-button-splitconsole"); 1.82 + 1.83 + return { 1.84 + deckHeight: deckHeight, 1.85 + containerHeight: containerHeight, 1.86 + webconsoleHeight: webconsoleHeight, 1.87 + splitterVisibility: splitterVisibility, 1.88 + openedConsolePanel: openedConsolePanel, 1.89 + buttonSelected: cmdButton.hasAttribute("checked") 1.90 + }; 1.91 + } 1.92 + 1.93 + function checkWebconsolePanelOpened() 1.94 + { 1.95 + info("About to check special cases when webconsole panel is open."); 1.96 + 1.97 + let deferred = promise.defer(); 1.98 + 1.99 + // Start with console split, so we can test for transition to main panel. 1.100 + toolbox.toggleSplitConsole(); 1.101 + 1.102 + let currentUIState = getCurrentUIState(); 1.103 + 1.104 + ok (currentUIState.splitterVisibility, "Splitter is visible when console is split"); 1.105 + ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split"); 1.106 + ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split"); 1.107 + ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); 1.108 + ok (currentUIState.buttonSelected, "The command button is selected"); 1.109 + 1.110 + openPanel("webconsole").then(() => { 1.111 + 1.112 + let currentUIState = getCurrentUIState(); 1.113 + 1.114 + ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened."); 1.115 + is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened."); 1.116 + is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height."); 1.117 + ok (currentUIState.openedConsolePanel, "The console panel is the current tool"); 1.118 + ok (currentUIState.buttonSelected, "The command button is still selected."); 1.119 + 1.120 + // Make sure splitting console does nothing while webconsole is opened 1.121 + toolbox.toggleSplitConsole(); 1.122 + 1.123 + let currentUIState = getCurrentUIState(); 1.124 + 1.125 + ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened."); 1.126 + is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened."); 1.127 + is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height."); 1.128 + ok (currentUIState.openedConsolePanel, "The console panel is the current tool"); 1.129 + ok (currentUIState.buttonSelected, "The command button is still selected."); 1.130 + 1.131 + // Make sure that split state is saved after opening another panel 1.132 + openPanel("inspector").then(() => { 1.133 + let currentUIState = getCurrentUIState(); 1.134 + ok (currentUIState.splitterVisibility, "Splitter is visible when console is split"); 1.135 + ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split"); 1.136 + ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split"); 1.137 + ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); 1.138 + ok (currentUIState.buttonSelected, "The command button is still selected."); 1.139 + 1.140 + toolbox.toggleSplitConsole(); 1.141 + deferred.resolve(); 1.142 + 1.143 + }); 1.144 + }); 1.145 + return deferred.promise; 1.146 + } 1.147 + 1.148 + function openPanel(toolId, callback) 1.149 + { 1.150 + let deferred = promise.defer(); 1.151 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.152 + gDevTools.showToolbox(target, toolId).then(function(box) { 1.153 + toolbox = box; 1.154 + deferred.resolve(); 1.155 + }).then(null, console.error); 1.156 + return deferred.promise; 1.157 + } 1.158 + 1.159 + function openAndCheckPanel(toolId) 1.160 + { 1.161 + let deferred = promise.defer(); 1.162 + openPanel(toolId).then(() => { 1.163 + info ("Checking toolbox for " + toolId); 1.164 + checkToolboxUI(toolbox.getCurrentPanel()); 1.165 + deferred.resolve(); 1.166 + }); 1.167 + return deferred.promise; 1.168 + } 1.169 + 1.170 + function checkToolboxUI() 1.171 + { 1.172 + let currentUIState = getCurrentUIState(); 1.173 + 1.174 + ok (!currentUIState.splitterVisibility, "Splitter is hidden by default"); 1.175 + is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 by default"); 1.176 + is (currentUIState.webconsoleHeight, 0, "Web console is collapsed by default"); 1.177 + ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); 1.178 + ok (!currentUIState.buttonSelected, "The command button is not selected."); 1.179 + 1.180 + toolbox.toggleSplitConsole(); 1.181 + 1.182 + let currentUIState = getCurrentUIState(); 1.183 + 1.184 + ok (currentUIState.splitterVisibility, "Splitter is visible when console is split"); 1.185 + ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split"); 1.186 + ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split"); 1.187 + is (currentUIState.deckHeight + currentUIState.webconsoleHeight, 1.188 + currentUIState.containerHeight, 1.189 + "Everything adds up to container height"); 1.190 + ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); 1.191 + ok (currentUIState.buttonSelected, "The command button is selected."); 1.192 + 1.193 + toolbox.toggleSplitConsole(); 1.194 + 1.195 + let currentUIState = getCurrentUIState(); 1.196 + 1.197 + ok (!currentUIState.splitterVisibility, "Splitter is hidden after toggling"); 1.198 + is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 after toggling"); 1.199 + is (currentUIState.webconsoleHeight, 0, "Web console is collapsed after toggling"); 1.200 + ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); 1.201 + ok (!currentUIState.buttonSelected, "The command button is not selected."); 1.202 + } 1.203 + 1.204 + function testBottomHost() 1.205 + { 1.206 + checkHostType(Toolbox.HostType.BOTTOM); 1.207 + 1.208 + checkToolboxUI(); 1.209 + 1.210 + toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost); 1.211 + } 1.212 + 1.213 + function testSidebarHost() 1.214 + { 1.215 + checkHostType(Toolbox.HostType.SIDE); 1.216 + 1.217 + checkToolboxUI(); 1.218 + 1.219 + toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost); 1.220 + } 1.221 + 1.222 + function testWindowHost() 1.223 + { 1.224 + checkHostType(Toolbox.HostType.WINDOW); 1.225 + 1.226 + checkToolboxUI(); 1.227 + 1.228 + toolbox.switchHost(Toolbox.HostType.BOTTOM).then(testDestroy); 1.229 + } 1.230 + 1.231 + function checkHostType(hostType) 1.232 + { 1.233 + is(toolbox.hostType, hostType, "host type is " + hostType); 1.234 + 1.235 + let pref = Services.prefs.getCharPref("devtools.toolbox.host"); 1.236 + is(pref, hostType, "host pref is " + hostType); 1.237 + } 1.238 + 1.239 + function testDestroy() 1.240 + { 1.241 + toolbox.destroy().then(function() { 1.242 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.243 + gDevTools.showToolbox(target).then(finish); 1.244 + }); 1.245 + } 1.246 + 1.247 + function finish() 1.248 + { 1.249 + toolbox = null; 1.250 + finishTest(); 1.251 + } 1.252 +}