|
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 showTabView(onTabViewWindowLoaded); |
|
8 } |
|
9 |
|
10 let originalGroupItem = null; |
|
11 let originalTab = null; |
|
12 |
|
13 function onTabViewWindowLoaded() { |
|
14 ok(TabView.isVisible(), "Tab View is visible"); |
|
15 |
|
16 let contentWindow = TabView.getContentWindow(); |
|
17 |
|
18 is(contentWindow.GroupItems.groupItems.length, 1, "There is one group item on startup"); |
|
19 originalGroupItem = contentWindow.GroupItems.groupItems[0]; |
|
20 is(originalGroupItem.getChildren().length, 1, "There should be one Tab Item in that group."); |
|
21 contentWindow.UI.setActive(originalGroupItem); |
|
22 |
|
23 [originalTab] = gBrowser.visibleTabs; |
|
24 |
|
25 testEmptyGroupItem(contentWindow); |
|
26 } |
|
27 |
|
28 function testEmptyGroupItem(contentWindow) { |
|
29 let groupItemCount = contentWindow.GroupItems.groupItems.length; |
|
30 |
|
31 // create empty group item |
|
32 let emptyGroupItem = createEmptyGroupItem(contentWindow, 300, 300, 100); |
|
33 ok(emptyGroupItem.isEmpty(), "This group is empty"); |
|
34 |
|
35 is(contentWindow.GroupItems.groupItems.length, ++groupItemCount, |
|
36 "The number of groups is increased by 1"); |
|
37 |
|
38 emptyGroupItem.addSubscriber("close", function onClose() { |
|
39 emptyGroupItem.removeSubscriber("close", onClose); |
|
40 |
|
41 // check the number of groups. |
|
42 is(contentWindow.GroupItems.groupItems.length, --groupItemCount, |
|
43 "The number of groups is decreased by 1"); |
|
44 |
|
45 testGroupItemWithTabItem(contentWindow); |
|
46 }); |
|
47 |
|
48 let closeButton = emptyGroupItem.container.getElementsByClassName("close"); |
|
49 ok(closeButton[0], "Group close button exists"); |
|
50 |
|
51 // click the close button |
|
52 EventUtils.synthesizeMouse(closeButton[0], 1, 1, {}, contentWindow); |
|
53 } |
|
54 |
|
55 function testGroupItemWithTabItem(contentWindow) { |
|
56 let groupItem = createEmptyGroupItem(contentWindow, 300, 300, 200); |
|
57 let tabItemCount = 0; |
|
58 |
|
59 let onTabViewShown = function() { |
|
60 let tabItem = groupItem.getChild(groupItem.getChildren().length - 1); |
|
61 ok(tabItem, "Tab item exists"); |
|
62 |
|
63 let tabItemClosed = false; |
|
64 tabItem.addSubscriber("close", function onClose() { |
|
65 tabItem.removeSubscriber("close", onClose); |
|
66 tabItemClosed = true; |
|
67 }); |
|
68 tabItem.addSubscriber("tabRemoved", function onTabRemoved() { |
|
69 tabItem.removeSubscriber("tabRemoved", onTabRemoved); |
|
70 |
|
71 ok(tabItemClosed, "The tab item is closed"); |
|
72 is(groupItem.getChildren().length, --tabItemCount, |
|
73 "The number of children in new tab group is decreased by 1"); |
|
74 |
|
75 ok(TabView.isVisible(), "Tab View is still shown"); |
|
76 |
|
77 // Now there should only be one tab left, so we need to hide TabView |
|
78 // and go into that tab. |
|
79 is(gBrowser.tabs.length, 1, "There is only one tab left"); |
|
80 |
|
81 // after the last selected tabitem is closed, there would be not active |
|
82 // tabitem on the UI so we set the active tabitem before toggling the |
|
83 // visibility of tabview |
|
84 let tabItems = contentWindow.TabItems.getItems(); |
|
85 ok(tabItems[0], "A tab item exists"); |
|
86 contentWindow.UI.setActive(tabItems[0]); |
|
87 |
|
88 hideTabView(function() { |
|
89 ok(!TabView.isVisible(), "Tab View is hidden"); |
|
90 |
|
91 closeGroupItem(groupItem, finish); |
|
92 }); |
|
93 }); |
|
94 |
|
95 // remove the tab item. The code detects mousedown and mouseup so we stimulate here |
|
96 let closeButton = tabItem.container.getElementsByClassName("close"); |
|
97 ok(closeButton, "Tab item close button exists"); |
|
98 |
|
99 EventUtils.sendMouseEvent({ type: "mousedown" }, closeButton[0], contentWindow); |
|
100 EventUtils.sendMouseEvent({ type: "mouseup" }, closeButton[0], contentWindow); |
|
101 }; |
|
102 |
|
103 whenTabViewIsHidden(function() { |
|
104 is(groupItem.getChildren().length, ++tabItemCount, |
|
105 "The number of children in new tab group is increased by 1"); |
|
106 |
|
107 ok(!TabView.isVisible(), "Tab View is hidden because we just opened a tab"); |
|
108 showTabView(onTabViewShown); |
|
109 }); |
|
110 groupItem.newTab(); |
|
111 } |