michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests that the toolbox is raised when the debugger gets paused. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_recursion-stack.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gNewTab, gFocusedWindow, gToolbox, gToolboxTab; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gToolbox = gPanel._toolbox; michael@0: gToolboxTab = gToolbox.doc.getElementById("toolbox-tab-jsdebugger"); michael@0: michael@0: waitForSourceShown(gPanel, ".html").then(performTest); michael@0: }); michael@0: } michael@0: michael@0: function performTest() { michael@0: addTab(TAB_URL).then(aTab => { michael@0: isnot(aTab, gTab, michael@0: "The newly added tab is different from the debugger's tab."); michael@0: is(gBrowser.selectedTab, aTab, michael@0: "Debugger's tab is not the selected tab."); michael@0: michael@0: gNewTab = aTab; michael@0: gFocusedWindow = window; michael@0: testPause(); michael@0: }); michael@0: } michael@0: michael@0: function focusMainWindow() { michael@0: // Make sure toolbox is not focused. michael@0: window.addEventListener("focus", onFocus, true); michael@0: info("Focusing main window.") michael@0: michael@0: // Execute soon to avoid any race conditions between toolbox and main window michael@0: // getting focused. michael@0: executeSoon(() => { michael@0: window.focus(); michael@0: }); michael@0: } michael@0: michael@0: function onFocus() { michael@0: window.removeEventListener("focus", onFocus, true); michael@0: info("Main window focused.") michael@0: michael@0: gFocusedWindow = window; michael@0: testPause(); michael@0: } michael@0: michael@0: function testPause() { michael@0: is(gDebugger.gThreadClient.paused, false, michael@0: "Should be running after starting the test."); michael@0: michael@0: is(gFocusedWindow, window, michael@0: "Main window is the top level window before pause."); michael@0: michael@0: if (gToolbox.hostType == devtools.Toolbox.HostType.WINDOW) { michael@0: gToolbox._host._window.onfocus = () => { michael@0: gFocusedWindow = gToolbox._host._window; michael@0: }; michael@0: } michael@0: michael@0: gDebugger.gThreadClient.addOneTimeListener("paused", () => { michael@0: if (gToolbox.hostType == devtools.Toolbox.HostType.WINDOW) { michael@0: is(gFocusedWindow, gToolbox._host._window, michael@0: "Toolbox window is the top level window on pause."); michael@0: } else { michael@0: is(gBrowser.selectedTab, gTab, michael@0: "Debugger's tab got selected."); michael@0: } michael@0: gToolbox.selectTool("webconsole").then(() => { michael@0: ok(gToolboxTab.hasAttribute("highlighted") && michael@0: gToolboxTab.getAttribute("highlighted") == "true", michael@0: "The highlighted class is present"); michael@0: ok(!gToolboxTab.hasAttribute("selected") || michael@0: gToolboxTab.getAttribute("selected") != "true", michael@0: "The tab is not selected"); michael@0: }).then(() => gToolbox.selectTool("jsdebugger")).then(() => { michael@0: ok(gToolboxTab.hasAttribute("highlighted") && michael@0: gToolboxTab.getAttribute("highlighted") == "true", michael@0: "The highlighted class is present"); michael@0: ok(gToolboxTab.hasAttribute("selected") && michael@0: gToolboxTab.getAttribute("selected") == "true", michael@0: "...and the tab is selected, so the glow will not be present."); michael@0: }).then(testResume); michael@0: }); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: gDebugger.document.getElementById("resume"), michael@0: gDebugger); michael@0: } michael@0: michael@0: function testResume() { michael@0: gDebugger.gThreadClient.addOneTimeListener("resumed", () => { michael@0: gToolbox.selectTool("webconsole").then(() => { michael@0: ok(!gToolboxTab.hasAttribute("highlighted") || michael@0: gToolboxTab.getAttribute("highlighted") != "true", michael@0: "The highlighted class is not present now after the resume"); michael@0: ok(!gToolboxTab.hasAttribute("selected") || michael@0: gToolboxTab.getAttribute("selected") != "true", michael@0: "The tab is not selected"); michael@0: }).then(maybeEndTest); michael@0: }); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, michael@0: gDebugger.document.getElementById("resume"), michael@0: gDebugger); michael@0: } michael@0: michael@0: function maybeEndTest() { michael@0: if (gToolbox.hostType == devtools.Toolbox.HostType.BOTTOM) { michael@0: info("Switching to a toolbox window host."); michael@0: gToolbox.switchHost(devtools.Toolbox.HostType.WINDOW).then(focusMainWindow); michael@0: } else { michael@0: info("Switching to main window host."); michael@0: gToolbox.switchHost(devtools.Toolbox.HostType.BOTTOM).then(() => closeDebuggerAndFinish(gPanel)); michael@0: } michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: // Revert to the default toolbox host, so that the following tests proceed michael@0: // normally and not inside a non-default host. michael@0: Services.prefs.setCharPref("devtools.toolbox.host", devtools.Toolbox.HostType.BOTTOM); michael@0: michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: michael@0: removeTab(gNewTab); michael@0: gNewTab = null; michael@0: gFocusedWindow = null; michael@0: gToolbox = null; michael@0: gToolboxTab = null; michael@0: });