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 /* vim: set ts=2 et sw=2 tw=80: */
2 /* Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/ */
5 let temp = {}
6 Cu.import("resource:///modules/devtools/gDevTools.jsm", temp);
7 let DevTools = temp.DevTools;
9 Cu.import("resource://gre/modules/devtools/Loader.jsm", temp);
10 let devtools = temp.devtools;
12 let Toolbox = devtools.Toolbox;
14 let toolbox, target;
16 function test()
17 {
18 waitForExplicitFinish();
20 gBrowser.selectedTab = gBrowser.addTab();
21 target = TargetFactory.forTab(gBrowser.selectedTab);
23 gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) {
24 gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true);
25 gDevTools.showToolbox(target)
26 .then(testBottomHost, console.error)
27 .then(null, console.error);
28 }, true);
30 content.location = "data:text/html,test for opening toolbox in different hosts";
31 }
33 function testBottomHost(aToolbox)
34 {
35 toolbox = aToolbox;
37 checkHostType(Toolbox.HostType.BOTTOM);
39 // test UI presence
40 let nbox = gBrowser.getNotificationBox();
41 let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe");
42 ok(iframe, "toolbox bottom iframe exists");
44 checkToolboxLoaded(iframe);
46 toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost);
47 }
49 function testSidebarHost()
50 {
51 checkHostType(Toolbox.HostType.SIDE);
53 // test UI presence
54 let nbox = gBrowser.getNotificationBox();
55 let bottom = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-bottom-iframe");
56 ok(!bottom, "toolbox bottom iframe doesn't exist");
58 let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe");
59 ok(iframe, "toolbox side iframe exists");
61 checkToolboxLoaded(iframe);
63 toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost);
64 }
66 function testWindowHost()
67 {
68 checkHostType(Toolbox.HostType.WINDOW);
70 let nbox = gBrowser.getNotificationBox();
71 let sidebar = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe");
72 ok(!sidebar, "toolbox sidebar iframe doesn't exist");
74 let win = Services.wm.getMostRecentWindow("devtools:toolbox");
75 ok(win, "toolbox separate window exists");
77 let iframe = win.document.getElementById("toolbox-iframe");
78 checkToolboxLoaded(iframe);
80 testToolSelect();
81 }
83 function testToolSelect()
84 {
85 // make sure we can load a tool after switching hosts
86 toolbox.selectTool("inspector").then(testDestroy);
87 }
89 function testDestroy()
90 {
91 toolbox.destroy().then(function() {
92 target = TargetFactory.forTab(gBrowser.selectedTab);
93 gDevTools.showToolbox(target).then(testRememberHost);
94 });
95 }
97 function testRememberHost(aToolbox)
98 {
99 toolbox = aToolbox;
100 // last host was the window - make sure it's the same when re-opening
101 is(toolbox.hostType, Toolbox.HostType.WINDOW, "host remembered");
103 let win = Services.wm.getMostRecentWindow("devtools:toolbox");
104 ok(win, "toolbox separate window exists");
106 cleanup();
107 }
109 function checkHostType(hostType)
110 {
111 is(toolbox.hostType, hostType, "host type is " + hostType);
113 let pref = Services.prefs.getCharPref("devtools.toolbox.host");
114 is(pref, hostType, "host pref is " + hostType);
115 }
117 function checkToolboxLoaded(iframe)
118 {
119 let tabs = iframe.contentDocument.getElementById("toolbox-tabs");
120 ok(tabs, "toolbox UI has been loaded into iframe");
121 }
123 function cleanup()
124 {
125 Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM);
127 toolbox.destroy().then(function() {
128 DevTools = Toolbox = toolbox = target = null;
129 gBrowser.removeCurrentTab();
130 finish();
131 });
132 }