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: 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; michael@0: michael@0: function test() michael@0: { michael@0: waitForExplicitFinish(); michael@0: michael@0: gBrowser.selectedTab = 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: { michael@0: toolbox = aToolbox; michael@0: michael@0: checkHostType(Toolbox.HostType.BOTTOM); michael@0: michael@0: // test UI presence michael@0: let nbox = gBrowser.getNotificationBox(); michael@0: let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe"); michael@0: ok(iframe, "toolbox bottom iframe exists"); michael@0: michael@0: checkToolboxLoaded(iframe); 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: // test UI presence michael@0: let nbox = gBrowser.getNotificationBox(); michael@0: let bottom = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe"); michael@0: ok(!bottom, "toolbox bottom iframe doesn't exist"); michael@0: michael@0: let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe"); michael@0: ok(iframe, "toolbox side iframe exists"); michael@0: michael@0: checkToolboxLoaded(iframe); 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: let nbox = gBrowser.getNotificationBox(); michael@0: let sidebar = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe"); michael@0: ok(!sidebar, "toolbox sidebar iframe doesn't exist"); michael@0: michael@0: let win = Services.wm.getMostRecentWindow("devtools:toolbox"); michael@0: ok(win, "toolbox separate window exists"); michael@0: michael@0: let iframe = win.document.getElementById("toolbox-iframe"); michael@0: checkToolboxLoaded(iframe); michael@0: michael@0: testToolSelect(); michael@0: } michael@0: michael@0: function testToolSelect() michael@0: { michael@0: // make sure we can load a tool after switching hosts michael@0: toolbox.selectTool("inspector").then(testDestroy); michael@0: } michael@0: michael@0: function testDestroy() michael@0: { michael@0: toolbox.destroy().then(function() { michael@0: target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: gDevTools.showToolbox(target).then(testRememberHost); michael@0: }); michael@0: } michael@0: michael@0: function testRememberHost(aToolbox) michael@0: { michael@0: toolbox = aToolbox; michael@0: // last host was the window - make sure it's the same when re-opening michael@0: is(toolbox.hostType, Toolbox.HostType.WINDOW, "host remembered"); michael@0: michael@0: let win = Services.wm.getMostRecentWindow("devtools:toolbox"); michael@0: ok(win, "toolbox separate window exists"); michael@0: michael@0: cleanup(); 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 checkToolboxLoaded(iframe) michael@0: { michael@0: let tabs = iframe.contentDocument.getElementById("toolbox-tabs"); michael@0: ok(tabs, "toolbox UI has been loaded into iframe"); michael@0: } michael@0: michael@0: function cleanup() michael@0: { 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: finish(); michael@0: }); michael@0: }