|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Tests devtools API |
|
5 |
|
6 const Cu = Components.utils; |
|
7 |
|
8 let toolbox, target; |
|
9 |
|
10 let tempScope = {}; |
|
11 |
|
12 function test() { |
|
13 addTab("about:blank", function(aBrowser, aTab) { |
|
14 target = TargetFactory.forTab(gBrowser.selectedTab); |
|
15 loadWebConsole(aTab).then(function() { |
|
16 console.log('loaded'); |
|
17 }, console.error); |
|
18 }); |
|
19 } |
|
20 |
|
21 function loadWebConsole(aTab) { |
|
22 ok(gDevTools, "gDevTools exists"); |
|
23 |
|
24 return gDevTools.showToolbox(target, "webconsole").then(function(aToolbox) { |
|
25 toolbox = aToolbox; |
|
26 checkToolLoading(); |
|
27 }, console.error); |
|
28 } |
|
29 |
|
30 function checkToolLoading() { |
|
31 is(toolbox.currentToolId, "webconsole", "The web console is selected"); |
|
32 ok(toolbox.isReady, "toolbox is ready") |
|
33 |
|
34 selectAndCheckById("jsdebugger").then(function() { |
|
35 selectAndCheckById("styleeditor").then(function() { |
|
36 testToggle(); |
|
37 }); |
|
38 }, console.error); |
|
39 } |
|
40 |
|
41 function selectAndCheckById(id) { |
|
42 let doc = toolbox.frame.contentDocument; |
|
43 |
|
44 return toolbox.selectTool(id).then(function() { |
|
45 let tab = doc.getElementById("toolbox-tab-" + id); |
|
46 is(tab.hasAttribute("selected"), true, "The " + id + " tab is selected"); |
|
47 }); |
|
48 } |
|
49 |
|
50 function testToggle() { |
|
51 toolbox.once("destroyed", function() { |
|
52 // Cannot reuse a target after it's destroyed. |
|
53 target = TargetFactory.forTab(gBrowser.selectedTab); |
|
54 gDevTools.showToolbox(target, "styleeditor").then(function(aToolbox) { |
|
55 toolbox = aToolbox; |
|
56 is(toolbox.currentToolId, "styleeditor", "The style editor is selected"); |
|
57 finishUp(); |
|
58 }); |
|
59 }.bind(this)); |
|
60 |
|
61 toolbox.destroy(); |
|
62 } |
|
63 |
|
64 function finishUp() { |
|
65 toolbox.destroy().then(function() { |
|
66 toolbox = null; |
|
67 target = null; |
|
68 gBrowser.removeCurrentTab(); |
|
69 finish(); |
|
70 }); |
|
71 } |