browser/components/tabview/test/browser_tabview_bug637840.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:ee2fa43ab321
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 let cw;
5
6 function test() {
7 requestLongerTimeout(2);
8 waitForExplicitFinish();
9
10 newWindowWithTabView(function(win) {
11 cw = win.TabView.getContentWindow();
12
13 let groupItemOne = cw.GroupItems.groupItems[0];
14 is(groupItemOne.getChildren().length, 1, "Group one has 1 tab item");
15
16 let groupItemTwo = createGroupItemWithBlankTabs(win, 300, 300, 40, 2);
17 is(groupItemTwo.getChildren().length, 2, "Group two has 2 tab items");
18
19 let groupItemThree = createGroupItemWithBlankTabs(win, 300, 300, 40, 2);
20 is(groupItemThree.getChildren().length, 2, "Group three has 2 tab items");
21
22 waitForFocus(() => {
23 testMoreRecentlyUsedGroup(groupItemOne, groupItemTwo, function() {
24 testMoreRecentlyUsedGroup(groupItemOne, groupItemThree, function() {
25 testRemoveGroupAndCheckMoreRecentlyUsedGroup(groupItemOne, groupItemTwo);
26 });
27 });
28 }, cw);
29 });
30 }
31
32 function testMoreRecentlyUsedGroup(groupItemOne, otherGroupItem, callback) {
33 let tabItem = otherGroupItem.getChild(1);
34 cw.UI.setActive(tabItem);
35 is(otherGroupItem.getActiveTab(), tabItem, "The second item in the other group is active");
36 is(cw.GroupItems.getActiveGroupItem(), otherGroupItem, "The other group is active");
37
38 let tabItemInGroupItemOne = groupItemOne.getChild(0);
39 cw.UI.setActive(tabItemInGroupItemOne);
40 is(groupItemOne.getActiveTab(), tabItemInGroupItemOne, "The first item in group one is active");
41 is(cw.GroupItems.getActiveGroupItem(), groupItemOne, "The group one is active");
42
43 groupItemOne.addSubscriber("groupHidden", function onHide() {
44 groupItemOne.removeSubscriber("groupHidden", onHide);
45
46 // group item three should have the focus
47 is(otherGroupItem.getActiveTab(), tabItem, "The second item in the other group is active after group one is hidden");
48 is(cw.GroupItems.getActiveGroupItem(), otherGroupItem, "The other group is active active after group one is hidden");
49
50 groupItemOne.addSubscriber("groupShown", function onShown() {
51 groupItemOne.removeSubscriber("groupShown", onShown);
52
53 is(groupItemOne.getActiveTab(), tabItemInGroupItemOne, "The first item in group one is active after it is shown");
54 is(cw.GroupItems.getActiveGroupItem(), groupItemOne, "The group one is active after it is shown");
55
56 callback();
57 });
58 // click on the undo button
59 EventUtils.sendMouseEvent(
60 { type: "click" }, groupItemOne.$undoContainer[0], cw);
61 });
62 // click on the close button of group item one
63 let closeButton = groupItemOne.container.getElementsByClassName("close");
64 ok(closeButton[0], "Group item one close button exists");
65 EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], cw);
66 }
67
68 function testRemoveGroupAndCheckMoreRecentlyUsedGroup(groupItemOne, groupItemTwo) {
69 let tabItem = groupItemTwo.getChild(0);
70 cw.UI.setActive(tabItem);
71
72 is(groupItemTwo.getActiveTab(), tabItem, "The first item in the group two is active");
73 is(cw.GroupItems.getActiveGroupItem(), groupItemTwo, "The group two is active");
74
75 let tabItemInGroupItemOne = groupItemOne.getChild(0);
76
77 tabItemInGroupItemOne.addSubscriber("close", function onClose() {
78 tabItemInGroupItemOne.removeSubscriber("close", onClose);
79
80 is(groupItemTwo.getActiveTab(), tabItem, "The first item in the group two is still active after group one is closed");
81 is(cw.GroupItems.getActiveGroupItem(), groupItemTwo, "The group two is still active after group one is closed");
82
83 promiseWindowClosed(cw.top).then(() => {
84 cw = null;
85 finish();
86 });
87 });
88 // close the tab item and the group item
89 let closeButton = tabItemInGroupItemOne.container.getElementsByClassName("close");
90 ok(closeButton[0], "Tab item close button exists");
91 EventUtils.sendMouseEvent({ type: "mousedown" }, closeButton[0], cw);
92 EventUtils.sendMouseEvent({ type: "mouseup" }, closeButton[0], cw);
93 }

mercurial