|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 const Cu = Components.utils; |
|
6 let {ToolSidebar} = devtools.require("devtools/framework/sidebar"); |
|
7 |
|
8 const toolURL = "data:text/xml;charset=utf8,<?xml version='1.0'?>" + |
|
9 "<?xml-stylesheet href='chrome://browser/skin/devtools/common.css' type='text/css'?>" + |
|
10 "<window xmlns='http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul'>" + |
|
11 "<hbox flex='1'><description flex='1'>foo</description><splitter class='devtools-side-splitter'/>" + |
|
12 "<tabbox flex='1' id='sidebar' class='devtools-sidebar-tabs'><tabs/><tabpanels flex='1'/></tabbox>" + |
|
13 "</hbox>" + |
|
14 "</window>"; |
|
15 |
|
16 const tab1URL = "data:text/html;charset=utf8,<title>1</title><p>1</p>"; |
|
17 const tab2URL = "data:text/html;charset=utf8,<title>2</title><p>2</p>"; |
|
18 const tab3URL = "data:text/html;charset=utf8,<title>3</title><p>3</p>"; |
|
19 |
|
20 let panelDoc; |
|
21 let tab1Selected = false; |
|
22 let registeredTabs = {}; |
|
23 let readyTabs = {}; |
|
24 |
|
25 let toolDefinition = { |
|
26 id: "fakeTool4242", |
|
27 visibilityswitch: "devtools.fakeTool4242.enabled", |
|
28 url: toolURL, |
|
29 label: "FAKE TOOL!!!", |
|
30 isTargetSupported: function() true, |
|
31 build: function(iframeWindow, toolbox) { |
|
32 let deferred = promise.defer(); |
|
33 executeSoon(function() { |
|
34 deferred.resolve({ |
|
35 target: toolbox.target, |
|
36 toolbox: toolbox, |
|
37 isReady: true, |
|
38 destroy: function(){}, |
|
39 panelDoc: iframeWindow.document, |
|
40 }); |
|
41 }.bind(this)); |
|
42 return deferred.promise; |
|
43 }, |
|
44 }; |
|
45 |
|
46 gDevTools.registerTool(toolDefinition); |
|
47 |
|
48 addTab("about:blank", function(aBrowser, aTab) { |
|
49 let target = TargetFactory.forTab(gBrowser.selectedTab); |
|
50 gDevTools.showToolbox(target, toolDefinition.id).then(function(toolbox) { |
|
51 let panel = toolbox.getPanel(toolDefinition.id); |
|
52 ok(true, "Tool open"); |
|
53 |
|
54 let tabbox = panel.panelDoc.getElementById("sidebar"); |
|
55 panel.sidebar = new ToolSidebar(tabbox, panel, "testbug865688", true); |
|
56 |
|
57 panel.sidebar.on("new-tab-registered", function(event, id) { |
|
58 registeredTabs[id] = true; |
|
59 }); |
|
60 |
|
61 panel.sidebar.once("tab1-ready", function(event) { |
|
62 info(event); |
|
63 readyTabs.tab1 = true; |
|
64 allTabsReady(panel); |
|
65 }); |
|
66 |
|
67 panel.sidebar.once("tab2-ready", function(event) { |
|
68 info(event); |
|
69 readyTabs.tab2 = true; |
|
70 allTabsReady(panel); |
|
71 }); |
|
72 |
|
73 panel.sidebar.once("tab3-ready", function(event) { |
|
74 info(event); |
|
75 readyTabs.tab3 = true; |
|
76 allTabsReady(panel); |
|
77 }); |
|
78 |
|
79 panel.sidebar.once("tab1-selected", function(event) { |
|
80 info(event); |
|
81 tab1Selected = true; |
|
82 allTabsReady(panel); |
|
83 }); |
|
84 |
|
85 panel.sidebar.addTab("tab1", tab1URL, true); |
|
86 panel.sidebar.addTab("tab2", tab2URL); |
|
87 panel.sidebar.addTab("tab3", tab3URL); |
|
88 |
|
89 panel.sidebar.show(); |
|
90 }).then(null, console.error); |
|
91 }); |
|
92 |
|
93 function allTabsReady(panel) { |
|
94 if (!tab1Selected || !readyTabs.tab1 || !readyTabs.tab2 || !readyTabs.tab3) { |
|
95 return; |
|
96 } |
|
97 |
|
98 ok(registeredTabs.tab1, "tab1 registered"); |
|
99 ok(registeredTabs.tab2, "tab2 registered"); |
|
100 ok(registeredTabs.tab3, "tab3 registered"); |
|
101 ok(readyTabs.tab1, "tab1 ready"); |
|
102 ok(readyTabs.tab2, "tab2 ready"); |
|
103 ok(readyTabs.tab3, "tab3 ready"); |
|
104 |
|
105 let tabs = panel.sidebar._tabbox.querySelectorAll("tab"); |
|
106 let panels = panel.sidebar._tabbox.querySelectorAll("tabpanel"); |
|
107 let label = 1; |
|
108 for (let tab of tabs) { |
|
109 is(tab.getAttribute("label"), label++, "Tab has the right title"); |
|
110 } |
|
111 is(label, 4, "Found the right amount of tabs."); |
|
112 is(panel.sidebar._tabbox.selectedPanel, panels[0], "First tab is selected"); |
|
113 ok(panel.sidebar.getCurrentTabID(), "tab1", "getCurrentTabID() is correct"); |
|
114 |
|
115 panel.sidebar.once("tab1-unselected", function() { |
|
116 ok(true, "received 'unselected' event"); |
|
117 panel.sidebar.once("tab2-selected", function() { |
|
118 ok(true, "received 'selected' event"); |
|
119 panel.sidebar.hide(); |
|
120 is(panel.sidebar._tabbox.getAttribute("hidden"), "true", "Sidebar hidden"); |
|
121 is(panel.sidebar.getWindowForTab("tab1").location.href, tab1URL, "Window is accessible"); |
|
122 testWidth(panel); |
|
123 }); |
|
124 }); |
|
125 |
|
126 panel.sidebar.select("tab2"); |
|
127 } |
|
128 |
|
129 function testWidth(panel) { |
|
130 let tabbox = panel.panelDoc.getElementById("sidebar"); |
|
131 tabbox.width = 420; |
|
132 panel.sidebar.destroy().then(function() { |
|
133 tabbox.width = 0; |
|
134 panel.sidebar = new ToolSidebar(tabbox, panel, "testbug865688", true); |
|
135 panel.sidebar.show(); |
|
136 is(panel.panelDoc.getElementById("sidebar").width, 420, "Width restored") |
|
137 finishUp(panel); |
|
138 }); |
|
139 } |
|
140 |
|
141 function finishUp(panel) { |
|
142 panel.sidebar.destroy(); |
|
143 gDevTools.unregisterTool(toolDefinition.id); |
|
144 |
|
145 executeSoon(function() { |
|
146 gBrowser.removeCurrentTab(); |
|
147 finish(); |
|
148 }); |
|
149 } |
|
150 } |