|
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/ */ |
|
4 |
|
5 Cu.import("resource://gre/modules/Services.jsm"); |
|
6 let temp = {} |
|
7 Cu.import("resource:///modules/devtools/gDevTools.jsm", temp); |
|
8 let DevTools = temp.DevTools; |
|
9 |
|
10 Cu.import("resource://gre/modules/devtools/Loader.jsm", temp); |
|
11 let devtools = temp.devtools; |
|
12 |
|
13 let Toolbox = devtools.Toolbox; |
|
14 |
|
15 let toolbox, target, tab1, tab2; |
|
16 |
|
17 function test() { |
|
18 waitForExplicitFinish(); |
|
19 |
|
20 gBrowser.selectedTab = tab1 = gBrowser.addTab(); |
|
21 tab2 = gBrowser.addTab(); |
|
22 target = TargetFactory.forTab(gBrowser.selectedTab); |
|
23 |
|
24 gBrowser.selectedBrowser.addEventListener("load", function onLoad(evt) { |
|
25 gBrowser.selectedBrowser.removeEventListener(evt.type, onLoad, true); |
|
26 gDevTools.showToolbox(target) |
|
27 .then(testBottomHost, console.error) |
|
28 .then(null, console.error); |
|
29 }, true); |
|
30 |
|
31 content.location = "data:text/html,test for opening toolbox in different hosts"; |
|
32 } |
|
33 |
|
34 function testBottomHost(aToolbox) { |
|
35 toolbox = aToolbox; |
|
36 |
|
37 // switch to another tab and test toolbox.raise() |
|
38 gBrowser.selectedTab = tab2; |
|
39 executeSoon(function() { |
|
40 is(gBrowser.selectedTab, tab2, "Correct tab is selected before calling raise"); |
|
41 toolbox.raise(); |
|
42 executeSoon(function() { |
|
43 is(gBrowser.selectedTab, tab1, "Correct tab was selected after calling raise"); |
|
44 |
|
45 toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost).then(null, console.error); |
|
46 }); |
|
47 }); |
|
48 } |
|
49 |
|
50 function testWindowHost() { |
|
51 // Make sure toolbox is not focused. |
|
52 window.addEventListener("focus", onFocus, true); |
|
53 |
|
54 // Need to wait for focus as otherwise window.focus() is overridden by |
|
55 // toolbox window getting focused first on Linux and Mac. |
|
56 let onToolboxFocus = () => { |
|
57 toolbox._host._window.removeEventListener("focus", onToolboxFocus, true); |
|
58 info("focusing main window."); |
|
59 window.focus() |
|
60 }; |
|
61 // Need to wait for toolbox window to get focus. |
|
62 toolbox._host._window.addEventListener("focus", onToolboxFocus, true); |
|
63 } |
|
64 |
|
65 function onFocus() { |
|
66 info("Main window is focused before calling toolbox.raise()") |
|
67 window.removeEventListener("focus", onFocus, true); |
|
68 |
|
69 // Check if toolbox window got focus. |
|
70 let onToolboxFocusAgain = () => { |
|
71 toolbox._host._window.removeEventListener("focus", onToolboxFocusAgain, false); |
|
72 ok(true, "Toolbox window is the focused window after calling toolbox.raise()"); |
|
73 cleanup(); |
|
74 }; |
|
75 toolbox._host._window.addEventListener("focus", onToolboxFocusAgain, false); |
|
76 |
|
77 // Now raise toolbox. |
|
78 toolbox.raise(); |
|
79 } |
|
80 |
|
81 function cleanup() { |
|
82 Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM); |
|
83 |
|
84 toolbox.destroy().then(function() { |
|
85 DevTools = Toolbox = toolbox = target = null; |
|
86 gBrowser.removeCurrentTab(); |
|
87 gBrowser.removeCurrentTab(); |
|
88 finish(); |
|
89 }); |
|
90 } |