|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 * |
|
5 * Contributor(s): |
|
6 * Mihai Sucan <mihai.sucan@gmail.com> |
|
7 * Raymond Lee <raymond@appcoast.com> |
|
8 * Ian Gilman <ian@iangilman.com> |
|
9 */ |
|
10 |
|
11 function test() { |
|
12 requestLongerTimeout(2); |
|
13 waitForExplicitFinish(); |
|
14 |
|
15 newWindowWithTabView(onTabViewShown); |
|
16 } |
|
17 |
|
18 function onTabViewShown(win) { |
|
19 let TabView = win.TabView; |
|
20 let gBrowser = win.gBrowser; |
|
21 let document = win.document; |
|
22 |
|
23 ok(TabView.isVisible(), "Tab View is visible"); |
|
24 |
|
25 let contentWindow = document.getElementById("tab-view").contentWindow; |
|
26 let iQ = contentWindow.iQ; |
|
27 |
|
28 // establish initial state |
|
29 is(contentWindow.GroupItems.groupItems.length, 1, |
|
30 "we start with one group (the default)"); |
|
31 is(gBrowser.tabs.length, 1, "we start with one tab"); |
|
32 let originalTab = gBrowser.tabs[0]; |
|
33 |
|
34 // create a group |
|
35 let box = new contentWindow.Rect(20, 20, 210, 200); |
|
36 let groupItem = new contentWindow.GroupItem([], |
|
37 { bounds: box, title: "test1" }); |
|
38 is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups"); |
|
39 contentWindow.UI.setActive(groupItem); |
|
40 |
|
41 // create a tab |
|
42 let xulTabs = []; |
|
43 xulTabs.push(gBrowser.loadOneTab("about:blank")); |
|
44 is(gBrowser.tabs.length, 2, "we now have two tabs"); |
|
45 is(groupItem._children.length, 1, "the new tab was added to the group"); |
|
46 |
|
47 // make sure the group has no app tabs |
|
48 is(appTabCount(groupItem), 0, "there are no app tab icons"); |
|
49 |
|
50 let tray = groupItem.$appTabTray; |
|
51 let trayContainer = iQ(tray[0].parentNode); |
|
52 |
|
53 is(parseInt(trayContainer.css("width")), 0, |
|
54 "$appTabTray container is not visible"); |
|
55 |
|
56 // pin the tab, make sure the TabItem goes away and the icon comes on |
|
57 whenAppTabIconAdded(groupItem, function () { |
|
58 is(groupItem._children.length, 0, |
|
59 "the app tab's TabItem was removed from the group"); |
|
60 is(appTabCount(groupItem), 1, "there's now one app tab icon"); |
|
61 |
|
62 is(tray.css("-moz-column-count"), 1, |
|
63 "$appTabTray column count is 1"); |
|
64 isnot(parseInt(trayContainer.css("width")), 0, |
|
65 "$appTabTray container is visible"); |
|
66 |
|
67 |
|
68 let iconHeight = iQ(iQ(".appTabIcon", tray)[0]).height(); |
|
69 let trayHeight = parseInt(trayContainer.css("height")); |
|
70 let rows = Math.floor(trayHeight / iconHeight); |
|
71 let icons = rows * 2; |
|
72 |
|
73 function pinnedSomeTabs() { |
|
74 is(appTabCount(groupItem), icons, "number of app tab icons is correct"); |
|
75 |
|
76 is(tray.css("-moz-column-count"), 2, |
|
77 "$appTabTray column count is 2"); |
|
78 |
|
79 ok(!trayContainer.hasClass("appTabTrayContainerTruncated"), |
|
80 "$appTabTray container does not have .appTabTrayContainerTruncated"); |
|
81 |
|
82 // add one more tab |
|
83 xulTabs.push(gBrowser.loadOneTab("about:blank")); |
|
84 whenAppTabIconAdded(groupItem, function () { |
|
85 is(tray.css("-moz-column-count"), 3, |
|
86 "$appTabTray column count is 3"); |
|
87 |
|
88 ok(trayContainer.hasClass("appTabTrayContainerTruncated"), |
|
89 "$appTabTray container hasClass .appTabTrayContainerTruncated"); |
|
90 |
|
91 // remove all but one app tabs |
|
92 for (let i = 1; i < xulTabs.length; i++) |
|
93 gBrowser.removeTab(xulTabs[i]); |
|
94 |
|
95 is(tray.css("-moz-column-count"), 1, |
|
96 "$appTabTray column count is 1"); |
|
97 |
|
98 is(appTabCount(groupItem), 1, "there's now one app tab icon"); |
|
99 |
|
100 ok(!trayContainer.hasClass("appTabTrayContainerTruncated"), |
|
101 "$appTabTray container does not have .appTabTrayContainerTruncated"); |
|
102 |
|
103 // unpin the last remaining tab |
|
104 gBrowser.unpinTab(xulTabs[0]); |
|
105 |
|
106 is(parseInt(trayContainer.css("width")), 0, |
|
107 "$appTabTray container is not visible"); |
|
108 |
|
109 // When the tab was pinned, the last active group with an item got the focus. |
|
110 // Therefore, switching the focus back to group item one. |
|
111 contentWindow.UI.setActive(groupItem); |
|
112 |
|
113 is(appTabCount(groupItem), 0, "there are no app tab icons"); |
|
114 |
|
115 is(groupItem._children.length, 1, "the normal tab shows in the group"); |
|
116 |
|
117 gBrowser.removeTab(xulTabs[0]); |
|
118 |
|
119 // close the group |
|
120 groupItem.close(); |
|
121 |
|
122 hideTabView(function() { |
|
123 ok(!TabView.isVisible(), "Tab View is hidden"); |
|
124 |
|
125 is(contentWindow.GroupItems.groupItems.length, 1, |
|
126 "we finish with one group"); |
|
127 is(gBrowser.tabs.length, 1, "we finish with one tab"); |
|
128 |
|
129 win.close(); |
|
130 |
|
131 executeSoon(finish); |
|
132 }, win); |
|
133 }); |
|
134 win.gBrowser.pinTab(xulTabs[xulTabs.length-1]); |
|
135 }; |
|
136 |
|
137 // add enough tabs to have two columns |
|
138 let returnCount = 0; |
|
139 for (let i = 1; i < icons; i++) { |
|
140 xulTabs.push(gBrowser.loadOneTab("about:blank")); |
|
141 whenAppTabIconAdded(groupItem, function () { |
|
142 if (++returnCount == (icons - 1)) |
|
143 executeSoon(pinnedSomeTabs); |
|
144 }); |
|
145 win.gBrowser.pinTab(xulTabs[i]); |
|
146 } |
|
147 }); |
|
148 win.gBrowser.pinTab(xulTabs[0]); |
|
149 } |
|
150 |
|
151 function appTabCount(groupItem) { |
|
152 return groupItem.container.getElementsByClassName("appTabIcon").length; |
|
153 } |
|
154 |