michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let Toolbox = devtools.Toolbox; michael@0: let temp = {}; michael@0: Cu.import("resource://gre/modules/Services.jsm", temp); michael@0: let Services = temp.Services; michael@0: temp = null; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: const URL_1 = "data:text/plain;charset=UTF-8,abcde"; michael@0: const URL_2 = "data:text/plain;charset=UTF-8,12345"; michael@0: michael@0: const TOOL_ID_1 = "webconsole"; michael@0: const TOOL_ID_2 = "jsdebugger"; michael@0: michael@0: const LABEL_1 = "Console"; michael@0: const LABEL_2 = "Debugger"; michael@0: michael@0: let toolbox; michael@0: michael@0: addTab(URL_1, function () { michael@0: let target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: gDevTools.showToolbox(target, null, Toolbox.HostType.BOTTOM) michael@0: .then(function (aToolbox) { toolbox = aToolbox; }) michael@0: .then(function () toolbox.selectTool(TOOL_ID_1)) michael@0: michael@0: // undock toolbox and check title michael@0: .then(function () toolbox.switchHost(Toolbox.HostType.WINDOW)) michael@0: .then(checkTitle.bind(null, LABEL_1, URL_1, "toolbox undocked")) michael@0: michael@0: // switch to different tool and check title michael@0: .then(function () toolbox.selectTool(TOOL_ID_2)) michael@0: .then(checkTitle.bind(null, LABEL_2, URL_1, "tool changed")) michael@0: michael@0: // navigate to different url and check title michael@0: .then(function () { michael@0: let deferred = promise.defer(); michael@0: target.once("navigate", function () deferred.resolve()); michael@0: gBrowser.loadURI(URL_2); michael@0: return deferred.promise; michael@0: }) michael@0: .then(checkTitle.bind(null, LABEL_2, URL_2, "url changed")) michael@0: michael@0: // destroy toolbox, create new one hosted in a window (with a michael@0: // different tool id), and check title michael@0: .then(function () { michael@0: // Give the tools a chance to handle the navigation event before michael@0: // destroying the toolbox. michael@0: executeSoon(function() { michael@0: toolbox.destroy() michael@0: .then(function () { michael@0: // After destroying the toolbox, a fresh target is required. michael@0: target = TargetFactory.forTab(gBrowser.selectedTab); michael@0: return gDevTools.showToolbox(target, null, Toolbox.HostType.WINDOW); michael@0: }) michael@0: .then(function (aToolbox) { toolbox = aToolbox; }) michael@0: .then(function () toolbox.selectTool(TOOL_ID_1)) michael@0: .then(checkTitle.bind(null, LABEL_1, URL_2, michael@0: "toolbox destroyed and recreated")) michael@0: michael@0: // clean up michael@0: .then(function () toolbox.destroy()) michael@0: .then(function () { michael@0: toolbox = null; michael@0: gBrowser.removeCurrentTab(); michael@0: Services.prefs.clearUserPref("devtools.toolbox.host"); michael@0: Services.prefs.clearUserPref("devtools.toolbox.selectedTool"); michael@0: Services.prefs.clearUserPref("devtools.toolbox.sideEnabled"); michael@0: finish(); michael@0: }); michael@0: }); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function checkTitle(toolLabel, url, context) { michael@0: let win = Services.wm.getMostRecentWindow("devtools:toolbox"); michael@0: let definitions = gDevTools.getToolDefinitionMap(); michael@0: let expectedTitle = toolLabel + " - " + url; michael@0: is(win.document.title, expectedTitle, context); michael@0: }