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