browser/devtools/framework/test/browser_toolbox_window_title_changes.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 let Toolbox = devtools.Toolbox;
michael@0 5 let temp = {};
michael@0 6 Cu.import("resource://gre/modules/Services.jsm", temp);
michael@0 7 let Services = temp.Services;
michael@0 8 temp = null;
michael@0 9
michael@0 10 function test() {
michael@0 11 waitForExplicitFinish();
michael@0 12
michael@0 13 const URL_1 = "data:text/plain;charset=UTF-8,abcde";
michael@0 14 const URL_2 = "data:text/plain;charset=UTF-8,12345";
michael@0 15
michael@0 16 const TOOL_ID_1 = "webconsole";
michael@0 17 const TOOL_ID_2 = "jsdebugger";
michael@0 18
michael@0 19 const LABEL_1 = "Console";
michael@0 20 const LABEL_2 = "Debugger";
michael@0 21
michael@0 22 let toolbox;
michael@0 23
michael@0 24 addTab(URL_1, function () {
michael@0 25 let target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0 26 gDevTools.showToolbox(target, null, Toolbox.HostType.BOTTOM)
michael@0 27 .then(function (aToolbox) { toolbox = aToolbox; })
michael@0 28 .then(function () toolbox.selectTool(TOOL_ID_1))
michael@0 29
michael@0 30 // undock toolbox and check title
michael@0 31 .then(function () toolbox.switchHost(Toolbox.HostType.WINDOW))
michael@0 32 .then(checkTitle.bind(null, LABEL_1, URL_1, "toolbox undocked"))
michael@0 33
michael@0 34 // switch to different tool and check title
michael@0 35 .then(function () toolbox.selectTool(TOOL_ID_2))
michael@0 36 .then(checkTitle.bind(null, LABEL_2, URL_1, "tool changed"))
michael@0 37
michael@0 38 // navigate to different url and check title
michael@0 39 .then(function () {
michael@0 40 let deferred = promise.defer();
michael@0 41 target.once("navigate", function () deferred.resolve());
michael@0 42 gBrowser.loadURI(URL_2);
michael@0 43 return deferred.promise;
michael@0 44 })
michael@0 45 .then(checkTitle.bind(null, LABEL_2, URL_2, "url changed"))
michael@0 46
michael@0 47 // destroy toolbox, create new one hosted in a window (with a
michael@0 48 // different tool id), and check title
michael@0 49 .then(function () {
michael@0 50 // Give the tools a chance to handle the navigation event before
michael@0 51 // destroying the toolbox.
michael@0 52 executeSoon(function() {
michael@0 53 toolbox.destroy()
michael@0 54 .then(function () {
michael@0 55 // After destroying the toolbox, a fresh target is required.
michael@0 56 target = TargetFactory.forTab(gBrowser.selectedTab);
michael@0 57 return gDevTools.showToolbox(target, null, Toolbox.HostType.WINDOW);
michael@0 58 })
michael@0 59 .then(function (aToolbox) { toolbox = aToolbox; })
michael@0 60 .then(function () toolbox.selectTool(TOOL_ID_1))
michael@0 61 .then(checkTitle.bind(null, LABEL_1, URL_2,
michael@0 62 "toolbox destroyed and recreated"))
michael@0 63
michael@0 64 // clean up
michael@0 65 .then(function () toolbox.destroy())
michael@0 66 .then(function () {
michael@0 67 toolbox = null;
michael@0 68 gBrowser.removeCurrentTab();
michael@0 69 Services.prefs.clearUserPref("devtools.toolbox.host");
michael@0 70 Services.prefs.clearUserPref("devtools.toolbox.selectedTool");
michael@0 71 Services.prefs.clearUserPref("devtools.toolbox.sideEnabled");
michael@0 72 finish();
michael@0 73 });
michael@0 74 });
michael@0 75 });
michael@0 76 });
michael@0 77 }
michael@0 78
michael@0 79 function checkTitle(toolLabel, url, context) {
michael@0 80 let win = Services.wm.getMostRecentWindow("devtools:toolbox");
michael@0 81 let definitions = gDevTools.getToolDefinitionMap();
michael@0 82 let expectedTitle = toolLabel + " - " + url;
michael@0 83 is(win.document.title, expectedTitle, context);
michael@0 84 }

mercurial