1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/framework/test/browser_toolbox_window_title_changes.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let Toolbox = devtools.Toolbox; 1.8 +let temp = {}; 1.9 +Cu.import("resource://gre/modules/Services.jsm", temp); 1.10 +let Services = temp.Services; 1.11 +temp = null; 1.12 + 1.13 +function test() { 1.14 + waitForExplicitFinish(); 1.15 + 1.16 + const URL_1 = "data:text/plain;charset=UTF-8,abcde"; 1.17 + const URL_2 = "data:text/plain;charset=UTF-8,12345"; 1.18 + 1.19 + const TOOL_ID_1 = "webconsole"; 1.20 + const TOOL_ID_2 = "jsdebugger"; 1.21 + 1.22 + const LABEL_1 = "Console"; 1.23 + const LABEL_2 = "Debugger"; 1.24 + 1.25 + let toolbox; 1.26 + 1.27 + addTab(URL_1, function () { 1.28 + let target = TargetFactory.forTab(gBrowser.selectedTab); 1.29 + gDevTools.showToolbox(target, null, Toolbox.HostType.BOTTOM) 1.30 + .then(function (aToolbox) { toolbox = aToolbox; }) 1.31 + .then(function () toolbox.selectTool(TOOL_ID_1)) 1.32 + 1.33 + // undock toolbox and check title 1.34 + .then(function () toolbox.switchHost(Toolbox.HostType.WINDOW)) 1.35 + .then(checkTitle.bind(null, LABEL_1, URL_1, "toolbox undocked")) 1.36 + 1.37 + // switch to different tool and check title 1.38 + .then(function () toolbox.selectTool(TOOL_ID_2)) 1.39 + .then(checkTitle.bind(null, LABEL_2, URL_1, "tool changed")) 1.40 + 1.41 + // navigate to different url and check title 1.42 + .then(function () { 1.43 + let deferred = promise.defer(); 1.44 + target.once("navigate", function () deferred.resolve()); 1.45 + gBrowser.loadURI(URL_2); 1.46 + return deferred.promise; 1.47 + }) 1.48 + .then(checkTitle.bind(null, LABEL_2, URL_2, "url changed")) 1.49 + 1.50 + // destroy toolbox, create new one hosted in a window (with a 1.51 + // different tool id), and check title 1.52 + .then(function () { 1.53 + // Give the tools a chance to handle the navigation event before 1.54 + // destroying the toolbox. 1.55 + executeSoon(function() { 1.56 + toolbox.destroy() 1.57 + .then(function () { 1.58 + // After destroying the toolbox, a fresh target is required. 1.59 + target = TargetFactory.forTab(gBrowser.selectedTab); 1.60 + return gDevTools.showToolbox(target, null, Toolbox.HostType.WINDOW); 1.61 + }) 1.62 + .then(function (aToolbox) { toolbox = aToolbox; }) 1.63 + .then(function () toolbox.selectTool(TOOL_ID_1)) 1.64 + .then(checkTitle.bind(null, LABEL_1, URL_2, 1.65 + "toolbox destroyed and recreated")) 1.66 + 1.67 + // clean up 1.68 + .then(function () toolbox.destroy()) 1.69 + .then(function () { 1.70 + toolbox = null; 1.71 + gBrowser.removeCurrentTab(); 1.72 + Services.prefs.clearUserPref("devtools.toolbox.host"); 1.73 + Services.prefs.clearUserPref("devtools.toolbox.selectedTool"); 1.74 + Services.prefs.clearUserPref("devtools.toolbox.sideEnabled"); 1.75 + finish(); 1.76 + }); 1.77 + }); 1.78 + }); 1.79 + }); 1.80 +} 1.81 + 1.82 +function checkTitle(toolLabel, url, context) { 1.83 + let win = Services.wm.getMostRecentWindow("devtools:toolbox"); 1.84 + let definitions = gDevTools.getToolDefinitionMap(); 1.85 + let expectedTitle = toolLabel + " - " + url; 1.86 + is(win.document.title, expectedTitle, context); 1.87 +}