Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | function test() |
michael@0 | 7 | { |
michael@0 | 8 | // Test is slow on Linux EC2 instances - Bug 962931 |
michael@0 | 9 | requestLongerTimeout(2); |
michael@0 | 10 | |
michael@0 | 11 | let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
michael@0 | 12 | let {Task} = Cu.import("resource://gre/modules/Task.jsm", {}); |
michael@0 | 13 | let Toolbox = devtools.Toolbox; |
michael@0 | 14 | let toolbox; |
michael@0 | 15 | |
michael@0 | 16 | addTab("data:text/html;charset=utf-8,Web Console test for splitting"); |
michael@0 | 17 | browser.addEventListener("load", function onLoad() { |
michael@0 | 18 | browser.removeEventListener("load", onLoad, true); |
michael@0 | 19 | testConsoleLoadOnDifferentPanel() |
michael@0 | 20 | }, true); |
michael@0 | 21 | |
michael@0 | 22 | function testConsoleLoadOnDifferentPanel() |
michael@0 | 23 | { |
michael@0 | 24 | info("About to check console loads even when non-webconsole panel is open"); |
michael@0 | 25 | |
michael@0 | 26 | openPanel("inspector").then(() => { |
michael@0 | 27 | toolbox.on("webconsole-ready", () => { |
michael@0 | 28 | ok(true, "Webconsole has been triggered as loaded while another tool is active"); |
michael@0 | 29 | testKeyboardShortcuts(); |
michael@0 | 30 | }); |
michael@0 | 31 | |
michael@0 | 32 | // Opens split console. |
michael@0 | 33 | toolbox.toggleSplitConsole(); |
michael@0 | 34 | }); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | function testKeyboardShortcuts() |
michael@0 | 38 | { |
michael@0 | 39 | info("About to check that panel responds to ESCAPE keyboard shortcut"); |
michael@0 | 40 | |
michael@0 | 41 | toolbox.once("split-console", () => { |
michael@0 | 42 | ok(true, "Split console has been triggered via ESCAPE keypress"); |
michael@0 | 43 | checkAllTools(); |
michael@0 | 44 | }); |
michael@0 | 45 | |
michael@0 | 46 | // Closes split console. |
michael@0 | 47 | EventUtils.sendKey("ESCAPE", toolbox.frame.contentWindow); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function checkAllTools() |
michael@0 | 51 | { |
michael@0 | 52 | info("About to check split console with each panel individually."); |
michael@0 | 53 | |
michael@0 | 54 | Task.spawn(function() { |
michael@0 | 55 | yield openAndCheckPanel("jsdebugger"); |
michael@0 | 56 | yield openAndCheckPanel("inspector"); |
michael@0 | 57 | yield openAndCheckPanel("styleeditor"); |
michael@0 | 58 | yield openAndCheckPanel("jsprofiler"); |
michael@0 | 59 | yield openAndCheckPanel("netmonitor"); |
michael@0 | 60 | |
michael@0 | 61 | yield checkWebconsolePanelOpened(); |
michael@0 | 62 | testBottomHost(); |
michael@0 | 63 | }); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function getCurrentUIState() |
michael@0 | 67 | { |
michael@0 | 68 | let win = toolbox.doc.defaultView; |
michael@0 | 69 | let deck = toolbox.doc.querySelector("#toolbox-deck"); |
michael@0 | 70 | let webconsolePanel = toolbox.doc.querySelector("#toolbox-panel-webconsole"); |
michael@0 | 71 | let splitter = toolbox.doc.querySelector("#toolbox-console-splitter"); |
michael@0 | 72 | |
michael@0 | 73 | let containerHeight = parseFloat(win.getComputedStyle(deck.parentNode).getPropertyValue("height")); |
michael@0 | 74 | let deckHeight = parseFloat(win.getComputedStyle(deck).getPropertyValue("height")); |
michael@0 | 75 | let webconsoleHeight = parseFloat(win.getComputedStyle(webconsolePanel).getPropertyValue("height")); |
michael@0 | 76 | let splitterVisibility = !splitter.getAttribute("hidden"); |
michael@0 | 77 | let openedConsolePanel = toolbox.currentToolId === "webconsole"; |
michael@0 | 78 | let cmdButton = toolbox.doc.querySelector("#command-button-splitconsole"); |
michael@0 | 79 | |
michael@0 | 80 | return { |
michael@0 | 81 | deckHeight: deckHeight, |
michael@0 | 82 | containerHeight: containerHeight, |
michael@0 | 83 | webconsoleHeight: webconsoleHeight, |
michael@0 | 84 | splitterVisibility: splitterVisibility, |
michael@0 | 85 | openedConsolePanel: openedConsolePanel, |
michael@0 | 86 | buttonSelected: cmdButton.hasAttribute("checked") |
michael@0 | 87 | }; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function checkWebconsolePanelOpened() |
michael@0 | 91 | { |
michael@0 | 92 | info("About to check special cases when webconsole panel is open."); |
michael@0 | 93 | |
michael@0 | 94 | let deferred = promise.defer(); |
michael@0 | 95 | |
michael@0 | 96 | // Start with console split, so we can test for transition to main panel. |
michael@0 | 97 | toolbox.toggleSplitConsole(); |
michael@0 | 98 | |
michael@0 | 99 | let currentUIState = getCurrentUIState(); |
michael@0 | 100 | |
michael@0 | 101 | ok (currentUIState.splitterVisibility, "Splitter is visible when console is split"); |
michael@0 | 102 | ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split"); |
michael@0 | 103 | ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split"); |
michael@0 | 104 | ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); |
michael@0 | 105 | ok (currentUIState.buttonSelected, "The command button is selected"); |
michael@0 | 106 | |
michael@0 | 107 | openPanel("webconsole").then(() => { |
michael@0 | 108 | |
michael@0 | 109 | let currentUIState = getCurrentUIState(); |
michael@0 | 110 | |
michael@0 | 111 | ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened."); |
michael@0 | 112 | is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened."); |
michael@0 | 113 | is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height."); |
michael@0 | 114 | ok (currentUIState.openedConsolePanel, "The console panel is the current tool"); |
michael@0 | 115 | ok (currentUIState.buttonSelected, "The command button is still selected."); |
michael@0 | 116 | |
michael@0 | 117 | // Make sure splitting console does nothing while webconsole is opened |
michael@0 | 118 | toolbox.toggleSplitConsole(); |
michael@0 | 119 | |
michael@0 | 120 | let currentUIState = getCurrentUIState(); |
michael@0 | 121 | |
michael@0 | 122 | ok (!currentUIState.splitterVisibility, "Splitter is hidden when console is opened."); |
michael@0 | 123 | is (currentUIState.deckHeight, 0, "Deck has a height == 0 when console is opened."); |
michael@0 | 124 | is (currentUIState.webconsoleHeight, currentUIState.containerHeight, "Web console is full height."); |
michael@0 | 125 | ok (currentUIState.openedConsolePanel, "The console panel is the current tool"); |
michael@0 | 126 | ok (currentUIState.buttonSelected, "The command button is still selected."); |
michael@0 | 127 | |
michael@0 | 128 | // Make sure that split state is saved after opening another panel |
michael@0 | 129 | openPanel("inspector").then(() => { |
michael@0 | 130 | let currentUIState = getCurrentUIState(); |
michael@0 | 131 | ok (currentUIState.splitterVisibility, "Splitter is visible when console is split"); |
michael@0 | 132 | ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split"); |
michael@0 | 133 | ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split"); |
michael@0 | 134 | ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); |
michael@0 | 135 | ok (currentUIState.buttonSelected, "The command button is still selected."); |
michael@0 | 136 | |
michael@0 | 137 | toolbox.toggleSplitConsole(); |
michael@0 | 138 | deferred.resolve(); |
michael@0 | 139 | |
michael@0 | 140 | }); |
michael@0 | 141 | }); |
michael@0 | 142 | return deferred.promise; |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | function openPanel(toolId, callback) |
michael@0 | 146 | { |
michael@0 | 147 | let deferred = promise.defer(); |
michael@0 | 148 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 149 | gDevTools.showToolbox(target, toolId).then(function(box) { |
michael@0 | 150 | toolbox = box; |
michael@0 | 151 | deferred.resolve(); |
michael@0 | 152 | }).then(null, console.error); |
michael@0 | 153 | return deferred.promise; |
michael@0 | 154 | } |
michael@0 | 155 | |
michael@0 | 156 | function openAndCheckPanel(toolId) |
michael@0 | 157 | { |
michael@0 | 158 | let deferred = promise.defer(); |
michael@0 | 159 | openPanel(toolId).then(() => { |
michael@0 | 160 | info ("Checking toolbox for " + toolId); |
michael@0 | 161 | checkToolboxUI(toolbox.getCurrentPanel()); |
michael@0 | 162 | deferred.resolve(); |
michael@0 | 163 | }); |
michael@0 | 164 | return deferred.promise; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | function checkToolboxUI() |
michael@0 | 168 | { |
michael@0 | 169 | let currentUIState = getCurrentUIState(); |
michael@0 | 170 | |
michael@0 | 171 | ok (!currentUIState.splitterVisibility, "Splitter is hidden by default"); |
michael@0 | 172 | is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 by default"); |
michael@0 | 173 | is (currentUIState.webconsoleHeight, 0, "Web console is collapsed by default"); |
michael@0 | 174 | ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); |
michael@0 | 175 | ok (!currentUIState.buttonSelected, "The command button is not selected."); |
michael@0 | 176 | |
michael@0 | 177 | toolbox.toggleSplitConsole(); |
michael@0 | 178 | |
michael@0 | 179 | let currentUIState = getCurrentUIState(); |
michael@0 | 180 | |
michael@0 | 181 | ok (currentUIState.splitterVisibility, "Splitter is visible when console is split"); |
michael@0 | 182 | ok (currentUIState.deckHeight > 0, "Deck has a height > 0 when console is split"); |
michael@0 | 183 | ok (currentUIState.webconsoleHeight > 0, "Web console has a height > 0 when console is split"); |
michael@0 | 184 | is (currentUIState.deckHeight + currentUIState.webconsoleHeight, |
michael@0 | 185 | currentUIState.containerHeight, |
michael@0 | 186 | "Everything adds up to container height"); |
michael@0 | 187 | ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); |
michael@0 | 188 | ok (currentUIState.buttonSelected, "The command button is selected."); |
michael@0 | 189 | |
michael@0 | 190 | toolbox.toggleSplitConsole(); |
michael@0 | 191 | |
michael@0 | 192 | let currentUIState = getCurrentUIState(); |
michael@0 | 193 | |
michael@0 | 194 | ok (!currentUIState.splitterVisibility, "Splitter is hidden after toggling"); |
michael@0 | 195 | is (currentUIState.deckHeight, currentUIState.containerHeight, "Deck has a height > 0 after toggling"); |
michael@0 | 196 | is (currentUIState.webconsoleHeight, 0, "Web console is collapsed after toggling"); |
michael@0 | 197 | ok (!currentUIState.openedConsolePanel, "The console panel is not the current tool"); |
michael@0 | 198 | ok (!currentUIState.buttonSelected, "The command button is not selected."); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | function testBottomHost() |
michael@0 | 202 | { |
michael@0 | 203 | checkHostType(Toolbox.HostType.BOTTOM); |
michael@0 | 204 | |
michael@0 | 205 | checkToolboxUI(); |
michael@0 | 206 | |
michael@0 | 207 | toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost); |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | function testSidebarHost() |
michael@0 | 211 | { |
michael@0 | 212 | checkHostType(Toolbox.HostType.SIDE); |
michael@0 | 213 | |
michael@0 | 214 | checkToolboxUI(); |
michael@0 | 215 | |
michael@0 | 216 | toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost); |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | function testWindowHost() |
michael@0 | 220 | { |
michael@0 | 221 | checkHostType(Toolbox.HostType.WINDOW); |
michael@0 | 222 | |
michael@0 | 223 | checkToolboxUI(); |
michael@0 | 224 | |
michael@0 | 225 | toolbox.switchHost(Toolbox.HostType.BOTTOM).then(testDestroy); |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | function checkHostType(hostType) |
michael@0 | 229 | { |
michael@0 | 230 | is(toolbox.hostType, hostType, "host type is " + hostType); |
michael@0 | 231 | |
michael@0 | 232 | let pref = Services.prefs.getCharPref("devtools.toolbox.host"); |
michael@0 | 233 | is(pref, hostType, "host pref is " + hostType); |
michael@0 | 234 | } |
michael@0 | 235 | |
michael@0 | 236 | function testDestroy() |
michael@0 | 237 | { |
michael@0 | 238 | toolbox.destroy().then(function() { |
michael@0 | 239 | let target = TargetFactory.forTab(gBrowser.selectedTab); |
michael@0 | 240 | gDevTools.showToolbox(target).then(finish); |
michael@0 | 241 | }); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | function finish() |
michael@0 | 245 | { |
michael@0 | 246 | toolbox = null; |
michael@0 | 247 | finishTest(); |
michael@0 | 248 | } |
michael@0 | 249 | } |