|
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 function onTabViewWindowLoaded() { |
|
11 ok(TabView.isVisible(), "Tab View is visible"); |
|
12 |
|
13 let contentWindow = TabView.getContentWindow(); |
|
14 |
|
15 // establish initial state |
|
16 is(contentWindow.GroupItems.groupItems.length, 1, |
|
17 "we start with one group (the default)"); |
|
18 is(gBrowser.tabs.length, 1, "we start with one tab"); |
|
19 let originalTab = gBrowser.tabs[0]; |
|
20 |
|
21 // create a group |
|
22 let box = new contentWindow.Rect(20, 20, 180, 180); |
|
23 let groupItemOne = new contentWindow.GroupItem([], |
|
24 { bounds: box, title: "test1" }); |
|
25 is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups"); |
|
26 contentWindow.UI.setActive(groupItemOne); |
|
27 |
|
28 // create a tab |
|
29 let xulTab = gBrowser.loadOneTab("about:blank"); |
|
30 is(gBrowser.tabs.length, 2, "we now have two tabs"); |
|
31 is(groupItemOne._children.length, 1, "the new tab was added to the group"); |
|
32 |
|
33 // make sure the group has no app tabs |
|
34 is(appTabCount(groupItemOne), 0, "there are no app tab icons"); |
|
35 |
|
36 // pin the tab, make sure the TabItem goes away and the icon comes on |
|
37 whenAppTabIconAdded(groupItemOne, function () { |
|
38 is(groupItemOne._children.length, 0, |
|
39 "the app tab's TabItem was removed from the group"); |
|
40 is(appTabCount(groupItemOne), 1, "there's now one app tab icon"); |
|
41 |
|
42 // create a second group and make sure it gets the icon too |
|
43 box.offset(box.width + 20, 0); |
|
44 let groupItemTwo = new contentWindow.GroupItem([], |
|
45 { bounds: box, title: "test2" }); |
|
46 whenAppTabIconAdded(groupItemTwo, function() { |
|
47 is(contentWindow.GroupItems.groupItems.length, 3, "we now have three groups"); |
|
48 is(appTabCount(groupItemTwo), 1, |
|
49 "there's an app tab icon in the second group"); |
|
50 |
|
51 // When the tab was pinned, the last active group with an item got the focus. |
|
52 // Therefore, switching the focus back to group item one. |
|
53 contentWindow.UI.setActive(groupItemOne); |
|
54 |
|
55 // unpin the tab, make sure the icon goes away and the TabItem comes on |
|
56 gBrowser.unpinTab(xulTab); |
|
57 is(groupItemOne._children.length, 1, "the app tab's TabItem is back"); |
|
58 is(appTabCount(groupItemOne), 0, "the icon is gone from group one"); |
|
59 is(appTabCount(groupItemTwo), 0, "the icon is gone from group two"); |
|
60 |
|
61 whenAppTabIconAdded(groupItemOne, function() { |
|
62 // close the second group |
|
63 groupItemTwo.close(); |
|
64 |
|
65 // find app tab in group and hit it |
|
66 whenTabViewIsHidden(function() { |
|
67 ok(!TabView.isVisible(), |
|
68 "Tab View is hidden because we clicked on the app tab"); |
|
69 |
|
70 // delete the app tab and make sure its icon goes away |
|
71 gBrowser.removeTab(xulTab); |
|
72 is(appTabCount(groupItemOne), 0, "closing app tab removes its icon"); |
|
73 |
|
74 // clean up |
|
75 groupItemOne.close(); |
|
76 |
|
77 is(contentWindow.GroupItems.groupItems.length, 1, |
|
78 "we finish with one group"); |
|
79 is(gBrowser.tabs.length, 1, "we finish with one tab"); |
|
80 ok(!TabView.isVisible(), "we finish with Tab View not visible"); |
|
81 |
|
82 finish(); |
|
83 }); |
|
84 |
|
85 let appTabIcons = groupItemOne.container.getElementsByClassName("appTabIcon"); |
|
86 EventUtils.sendMouseEvent({ type: "click" }, appTabIcons[0], contentWindow); |
|
87 }); |
|
88 gBrowser.pinTab(xulTab); |
|
89 }); |
|
90 }); |
|
91 gBrowser.pinTab(xulTab); |
|
92 } |
|
93 |
|
94 function appTabCount(groupItem) { |
|
95 return groupItem.container.getElementsByClassName("appTabIcon").length; |
|
96 } |