|
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 let temp = {} |
|
6 Cu.import("resource:///modules/devtools/gDevTools.jsm", temp); |
|
7 let DevTools = temp.DevTools; |
|
8 |
|
9 Cu.import("resource://gre/modules/devtools/Loader.jsm", temp); |
|
10 let devtools = temp.devtools; |
|
11 |
|
12 let Toolbox = devtools.Toolbox; |
|
13 |
|
14 let toolbox, target; |
|
15 |
|
16 function test() |
|
17 { |
|
18 waitForExplicitFinish(); |
|
19 |
|
20 gBrowser.selectedTab = gBrowser.addTab(); |
|
21 target = TargetFactory.forTab(gBrowser.selectedTab); |
|
22 |
|
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); |
|
29 |
|
30 content.location = "data:text/html,test for opening toolbox in different hosts"; |
|
31 } |
|
32 |
|
33 function testBottomHost(aToolbox) |
|
34 { |
|
35 toolbox = aToolbox; |
|
36 |
|
37 checkHostType(Toolbox.HostType.BOTTOM); |
|
38 |
|
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"); |
|
43 |
|
44 checkToolboxLoaded(iframe); |
|
45 |
|
46 toolbox.switchHost(Toolbox.HostType.SIDE).then(testSidebarHost); |
|
47 } |
|
48 |
|
49 function testSidebarHost() |
|
50 { |
|
51 checkHostType(Toolbox.HostType.SIDE); |
|
52 |
|
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"); |
|
57 |
|
58 let iframe = document.getAnonymousElementByAttribute(nbox, "class", "devtools-toolbox-side-iframe"); |
|
59 ok(iframe, "toolbox side iframe exists"); |
|
60 |
|
61 checkToolboxLoaded(iframe); |
|
62 |
|
63 toolbox.switchHost(Toolbox.HostType.WINDOW).then(testWindowHost); |
|
64 } |
|
65 |
|
66 function testWindowHost() |
|
67 { |
|
68 checkHostType(Toolbox.HostType.WINDOW); |
|
69 |
|
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"); |
|
73 |
|
74 let win = Services.wm.getMostRecentWindow("devtools:toolbox"); |
|
75 ok(win, "toolbox separate window exists"); |
|
76 |
|
77 let iframe = win.document.getElementById("toolbox-iframe"); |
|
78 checkToolboxLoaded(iframe); |
|
79 |
|
80 testToolSelect(); |
|
81 } |
|
82 |
|
83 function testToolSelect() |
|
84 { |
|
85 // make sure we can load a tool after switching hosts |
|
86 toolbox.selectTool("inspector").then(testDestroy); |
|
87 } |
|
88 |
|
89 function testDestroy() |
|
90 { |
|
91 toolbox.destroy().then(function() { |
|
92 target = TargetFactory.forTab(gBrowser.selectedTab); |
|
93 gDevTools.showToolbox(target).then(testRememberHost); |
|
94 }); |
|
95 } |
|
96 |
|
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"); |
|
102 |
|
103 let win = Services.wm.getMostRecentWindow("devtools:toolbox"); |
|
104 ok(win, "toolbox separate window exists"); |
|
105 |
|
106 cleanup(); |
|
107 } |
|
108 |
|
109 function checkHostType(hostType) |
|
110 { |
|
111 is(toolbox.hostType, hostType, "host type is " + hostType); |
|
112 |
|
113 let pref = Services.prefs.getCharPref("devtools.toolbox.host"); |
|
114 is(pref, hostType, "host pref is " + hostType); |
|
115 } |
|
116 |
|
117 function checkToolboxLoaded(iframe) |
|
118 { |
|
119 let tabs = iframe.contentDocument.getElementById("toolbox-tabs"); |
|
120 ok(tabs, "toolbox UI has been loaded into iframe"); |
|
121 } |
|
122 |
|
123 function cleanup() |
|
124 { |
|
125 Services.prefs.setCharPref("devtools.toolbox.host", Toolbox.HostType.BOTTOM); |
|
126 |
|
127 toolbox.destroy().then(function() { |
|
128 DevTools = Toolbox = toolbox = target = null; |
|
129 gBrowser.removeCurrentTab(); |
|
130 finish(); |
|
131 }); |
|
132 } |