browser/components/tabview/test/browser_tabview_undo_group.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:1ba907af3048
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 registerCleanupFunction(function() {
8 while (gBrowser.tabs[1])
9 gBrowser.removeTab(gBrowser.tabs[1]);
10 hideTabView();
11 });
12 showTabView(onTabViewWindowLoaded);
13 }
14
15 function onTabViewWindowLoaded() {
16 ok(TabView.isVisible(), "Tab View is visible");
17
18 let contentWindow = TabView.getContentWindow();
19
20 registerCleanupFunction(function() {
21 let groupItem = contentWindow.GroupItems.groupItem(groupItemId);
22 if (groupItem)
23 closeGroupItem(groupItem);
24 });
25
26 // create a group item
27 let groupItem = createGroupItemWithBlankTabs(window, 300, 300, 400, 1);
28 let groupItemId = groupItem.id;
29 is(groupItem.getChildren().length, 1, "The new group has a tab item");
30 // start the tests
31 waitForFocus(function() {
32 testUndoGroup(contentWindow, groupItem);
33 }, contentWindow);
34 }
35
36 function testUndoGroup(contentWindow, groupItem) {
37 groupItem.addSubscriber("groupHidden", function onHidden() {
38 groupItem.removeSubscriber("groupHidden", onHidden);
39
40 // check the data of the group
41 let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
42 ok(theGroupItem, "The group item still exists");
43 is(theGroupItem.getChildren().length, 1,
44 "The tab item in the group still exists");
45
46 // check the visibility of the group element and undo element
47 is(theGroupItem.container.style.display, "none",
48 "The group element is hidden");
49 ok(theGroupItem.$undoContainer, "Undo container is avaliable");
50
51 EventUtils.sendMouseEvent(
52 { type: "click" }, theGroupItem.$undoContainer[0], contentWindow);
53 });
54
55 groupItem.addSubscriber("groupShown", function onShown() {
56 groupItem.removeSubscriber("groupShown", onShown);
57
58 // check the data of the group
59 let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
60 ok(theGroupItem, "The group item still exists");
61 is(theGroupItem.getChildren().length, 1,
62 "The tab item in the group still exists");
63
64 // check the visibility of the group element and undo element
65 is(theGroupItem.container.style.display, "", "The group element is visible");
66 ok(!theGroupItem.$undoContainer, "Undo container is not avaliable");
67
68 // start the next test
69 testCloseUndoGroup(contentWindow, groupItem);
70 });
71
72 let closeButton = groupItem.container.getElementsByClassName("close");
73 ok(closeButton[0], "Group item close button exists");
74 EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow);
75 }
76
77 function testCloseUndoGroup(contentWindow, groupItem) {
78 groupItem.addSubscriber("groupHidden", function onHidden() {
79 groupItem.removeSubscriber("groupHidden", onHidden);
80
81 // check the data of the group
82 let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
83 ok(theGroupItem, "The group item still exists");
84 is(theGroupItem.getChildren().length, 1,
85 "The tab item in the group still exists");
86
87 // check the visibility of the group element and undo element
88 is(theGroupItem.container.style.display, "none",
89 "The group element is hidden");
90 ok(theGroupItem.$undoContainer, "Undo container is avaliable");
91
92 // click on close
93 let closeButton = theGroupItem.$undoContainer.find(".close");
94 EventUtils.sendMouseEvent(
95 { type: "click" }, closeButton[0], contentWindow);
96 });
97
98 groupItem.addSubscriber("close", function onClose() {
99 groupItem.removeSubscriber("close", onClose);
100
101 let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id);
102 ok(!theGroupItem, "The group item doesn't exists");
103
104 // after the last selected tabitem is closed, there would be not active
105 // tabitem on the UI so we set the active tabitem before toggling the
106 // visibility of tabview
107 let tabItems = contentWindow.TabItems.getItems();
108 ok(tabItems[0], "A tab item exists");
109 contentWindow.UI.setActive(tabItems[0]);
110
111 hideTabView(function() {
112 ok(!TabView.isVisible(), "Tab View is hidden");
113 finish();
114 });
115 });
116
117 let closeButton = groupItem.container.getElementsByClassName("close");
118 ok(closeButton[0], "Group item close button exists");
119 EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow);
120 }

mercurial