michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: let temp = {} michael@0: Cu.import("resource:///modules/devtools/gDevTools.jsm", temp); michael@0: let DevTools = temp.DevTools; michael@0: michael@0: Cu.import("resource://gre/modules/devtools/Loader.jsm", temp); michael@0: let devtools = temp.devtools; michael@0: michael@0: let Toolbox = devtools.Toolbox; michael@0: michael@0: let toolbox, target, tab1, tab2; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = tab1 = gBrowser.addTab(); michael@0: tab2 = gBrowser.addTab(); michael@0: target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: michael@0: gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { michael@0: gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); michael@0: gDevTools.showToolbox(target) michael@0: .then(testBottomHost, console.error) michael@0: .then(null, console.error); michael@0: }, true); michael@0: michael@0: content.location = "data:text/html,test for opening toolbox in different hosts"; michael@0: } michael@0: michael@0: function testBottomHost(aToolbox) { michael@0: toolbox = aToolbox; michael@0: michael@0: // switch to another tab and test toolbox.raise() michael@0: gBrowser.selectedTab = tab2; michael@0: executeSoon(function() { michael@0: is(gBrowser.selectedTab, tab2, "Correct tab is selected before calling raise"); michael@0: toolbox.raise(); michael@0: executeSoon(function() { michael@0: is(gBrowser.selectedTab, tab1, "Correct tab was selected after calling raise"); michael@0: michael@0: toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost).then(null, console.error); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function testWindowHost() { michael@0: // Make sure toolbox is not focused. michael@0: window.addEventListener("focus", onFocus, true); michael@0: michael@0: // Need to wait for focus as otherwise window.focus() is overridden by michael@0: // toolbox window getting focused first on Linux and Mac. michael@0: let onToolboxFocus = () => { michael@0: toolbox._host._window.removeEventListener("focus", onToolboxFocus, true); michael@0: info("focusing main window."); michael@0: window.focus() michael@0: }; michael@0: // Need to wait for toolbox window to get focus. michael@0: toolbox._host._window.addEventListener("focus", onToolboxFocus, true); michael@0: } michael@0: michael@0: function onFocus() { michael@0: info("Main window is focused before calling toolbox.raise()") michael@0: window.removeEventListener("focus", onFocus, true); michael@0: michael@0: // Check if toolbox window got focus. michael@0: let onToolboxFocusAgain = () => { michael@0: toolbox._host._window.removeEventListener("focus", onToolboxFocusAgain, false); michael@0: ok(true, "Toolbox window is the focused window after calling toolbox.raise()"); michael@0: cleanup(); michael@0: }; michael@0: toolbox._host._window.addEventListener("focus", onToolboxFocusAgain, false); michael@0: michael@0: // Now raise toolbox. michael@0: toolbox.raise(); michael@0: } michael@0: michael@0: function cleanup() { michael@0: Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM); michael@0: michael@0: toolbox.destroy().then(function() { michael@0: DevTools = Toolbox = toolbox = target = null; michael@0: gBrowser.removeCurrentTab(); michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }); michael@0: }