|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 function test() { |
|
5 waitForExplicitFinish(); |
|
6 |
|
7 // verify initial state |
|
8 ok(!TabView.isVisible(), "Tab View starts hidden"); |
|
9 |
|
10 window.addEventListener("tabviewshown", onTabViewWindowLoaded, false); |
|
11 TabView.toggle(); |
|
12 } |
|
13 |
|
14 let originalGroupItem = null; |
|
15 let originalTab = null; |
|
16 let contentWindow = null; |
|
17 |
|
18 function onTabViewWindowLoaded() { |
|
19 window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false); |
|
20 ok(TabView.isVisible(), "Tab View is visible"); |
|
21 |
|
22 contentWindow = document.getElementById("tab-view").contentWindow; |
|
23 |
|
24 is(contentWindow.GroupItems.groupItems.length, 1, "There is one group item on startup"); |
|
25 originalGroupItem = contentWindow.GroupItems.groupItems[0]; |
|
26 is(originalGroupItem.getChildren().length, 1, "There should be one Tab Item in that group."); |
|
27 contentWindow.UI.setActive(originalGroupItem); |
|
28 |
|
29 [originalTab] = gBrowser.visibleTabs; |
|
30 |
|
31 testEmptyGroupItem(contentWindow); |
|
32 } |
|
33 |
|
34 function testEmptyGroupItem(contentWindow) { |
|
35 let groupItemCount = contentWindow.GroupItems.groupItems.length; |
|
36 |
|
37 // Preparation |
|
38 // |
|
39 |
|
40 // create empty group item |
|
41 let emptyGroupItem = createEmptyGroupItem(contentWindow, 253, 335, 100); |
|
42 ok(emptyGroupItem.isEmpty(), "This group is empty"); |
|
43 |
|
44 is(contentWindow.GroupItems.groupItems.length, ++groupItemCount, |
|
45 "The number of groups is increased by 1"); |
|
46 |
|
47 // add four blank items |
|
48 contentWindow.UI.setActive(emptyGroupItem); |
|
49 |
|
50 let numNewTabs = 4; |
|
51 let items = []; |
|
52 for(let t=0; t<numNewTabs; t++) { |
|
53 let newItem = contentWindow.gBrowser.loadOneTab("about:blank")._tabViewTabItem; |
|
54 ok(newItem.container, "Created element "+t+":"+newItem.container); |
|
55 items.push(newItem); |
|
56 } |
|
57 |
|
58 // Define main test function |
|
59 // |
|
60 |
|
61 let mainTestFunc = function() { |
|
62 for(let j=0; j<numNewTabs; j++) { |
|
63 for(let i=0; i<numNewTabs; i++) { |
|
64 if (j!=i) { |
|
65 // make sure there is no overlap between j's title and i's box. |
|
66 let jitem = items[j]; |
|
67 let iitem = items[i]; |
|
68 let $jtitle = contentWindow.iQ(jitem.container).find(".tab-title"); |
|
69 let jbounds = $jtitle.bounds(); |
|
70 let ibounds = contentWindow.iQ(iitem.container).bounds(); |
|
71 |
|
72 ok( |
|
73 (jbounds.top+jbounds.height < ibounds.top) || |
|
74 (jbounds.top > ibounds.top + ibounds.height) || |
|
75 (jbounds.left+jbounds.width < ibounds.left) || |
|
76 (jbounds.left > ibounds.left + ibounds.width), |
|
77 "Items do not overlap: " |
|
78 +jbounds.left+","+jbounds.top+","+jbounds.width+","+jbounds.height+" ; " |
|
79 +ibounds.left+","+ibounds.top+","+ibounds.width+","+ibounds.height); |
|
80 } |
|
81 } |
|
82 } |
|
83 |
|
84 // Shut down |
|
85 emptyGroupItem.addSubscriber("close", function onClose() { |
|
86 emptyGroupItem.removeSubscriber("close", onClose); |
|
87 |
|
88 // check the number of groups. |
|
89 is(contentWindow.GroupItems.groupItems.length, --groupItemCount, |
|
90 "The number of groups is decreased by 1"); |
|
91 |
|
92 let onTabViewHidden = function() { |
|
93 window.removeEventListener("tabviewhidden", onTabViewHidden, false); |
|
94 // assert that we're no longer in tab view |
|
95 ok(!TabView.isVisible(), "Tab View is hidden"); |
|
96 finish(); |
|
97 }; |
|
98 window.addEventListener("tabviewhidden", onTabViewHidden, false); |
|
99 |
|
100 TabView.toggle(); |
|
101 }); |
|
102 |
|
103 let closeButton = emptyGroupItem.container.getElementsByClassName("close"); |
|
104 ok(closeButton[0], "Group close button exists"); |
|
105 |
|
106 // click the close button |
|
107 EventUtils.synthesizeMouse(closeButton[0], 1, 1, {}, contentWindow); |
|
108 }; |
|
109 |
|
110 mainTestFunc(); |
|
111 } |