michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: registerCleanupFunction(function() { michael@0: while (gBrowser.tabs[1]) michael@0: gBrowser.removeTab(gBrowser.tabs[1]); michael@0: hideTabView(); michael@0: }); michael@0: showTabView(onTabViewWindowLoaded); michael@0: } michael@0: michael@0: function onTabViewWindowLoaded() { michael@0: ok(TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: let contentWindow = TabView.getContentWindow(); michael@0: michael@0: registerCleanupFunction(function() { michael@0: let groupItem = contentWindow.GroupItems.groupItem(groupItemId); michael@0: if (groupItem) michael@0: closeGroupItem(groupItem); michael@0: }); michael@0: michael@0: // create a group item michael@0: let groupItem = createGroupItemWithBlankTabs(window, 300, 300, 400, 1); michael@0: let groupItemId = groupItem.id; michael@0: is(groupItem.getChildren().length, 1, "The new group has a tab item"); michael@0: // start the tests michael@0: waitForFocus(function() { michael@0: testUndoGroup(contentWindow, groupItem); michael@0: }, contentWindow); michael@0: } michael@0: michael@0: function testUndoGroup(contentWindow, groupItem) { michael@0: groupItem.addSubscriber("groupHidden", function onHidden() { michael@0: groupItem.removeSubscriber("groupHidden", onHidden); michael@0: michael@0: // check the data of the group michael@0: let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id); michael@0: ok(theGroupItem, "The group item still exists"); michael@0: is(theGroupItem.getChildren().length, 1, michael@0: "The tab item in the group still exists"); michael@0: michael@0: // check the visibility of the group element and undo element michael@0: is(theGroupItem.container.style.display, "none", michael@0: "The group element is hidden"); michael@0: ok(theGroupItem.$undoContainer, "Undo container is avaliable"); michael@0: michael@0: EventUtils.sendMouseEvent( michael@0: { type: "click" }, theGroupItem.$undoContainer[0], contentWindow); michael@0: }); michael@0: michael@0: groupItem.addSubscriber("groupShown", function onShown() { michael@0: groupItem.removeSubscriber("groupShown", onShown); michael@0: michael@0: // check the data of the group michael@0: let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id); michael@0: ok(theGroupItem, "The group item still exists"); michael@0: is(theGroupItem.getChildren().length, 1, michael@0: "The tab item in the group still exists"); michael@0: michael@0: // check the visibility of the group element and undo element michael@0: is(theGroupItem.container.style.display, "", "The group element is visible"); michael@0: ok(!theGroupItem.$undoContainer, "Undo container is not avaliable"); michael@0: michael@0: // start the next test michael@0: testCloseUndoGroup(contentWindow, groupItem); michael@0: }); michael@0: michael@0: let closeButton = groupItem.container.getElementsByClassName("close"); michael@0: ok(closeButton[0], "Group item close button exists"); michael@0: EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow); michael@0: } michael@0: michael@0: function testCloseUndoGroup(contentWindow, groupItem) { michael@0: groupItem.addSubscriber("groupHidden", function onHidden() { michael@0: groupItem.removeSubscriber("groupHidden", onHidden); michael@0: michael@0: // check the data of the group michael@0: let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id); michael@0: ok(theGroupItem, "The group item still exists"); michael@0: is(theGroupItem.getChildren().length, 1, michael@0: "The tab item in the group still exists"); michael@0: michael@0: // check the visibility of the group element and undo element michael@0: is(theGroupItem.container.style.display, "none", michael@0: "The group element is hidden"); michael@0: ok(theGroupItem.$undoContainer, "Undo container is avaliable"); michael@0: michael@0: // click on close michael@0: let closeButton = theGroupItem.$undoContainer.find(".close"); michael@0: EventUtils.sendMouseEvent( michael@0: { type: "click" }, closeButton[0], contentWindow); michael@0: }); michael@0: michael@0: groupItem.addSubscriber("close", function onClose() { michael@0: groupItem.removeSubscriber("close", onClose); michael@0: michael@0: let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id); michael@0: ok(!theGroupItem, "The group item doesn't exists"); michael@0: michael@0: // after the last selected tabitem is closed, there would be not active michael@0: // tabitem on the UI so we set the active tabitem before toggling the michael@0: // visibility of tabview michael@0: let tabItems = contentWindow.TabItems.getItems(); michael@0: ok(tabItems[0], "A tab item exists"); michael@0: contentWindow.UI.setActive(tabItems[0]); michael@0: michael@0: hideTabView(function() { michael@0: ok(!TabView.isVisible(), "Tab View is hidden"); michael@0: finish(); michael@0: }); michael@0: }); michael@0: michael@0: let closeButton = groupItem.container.getElementsByClassName("close"); michael@0: ok(closeButton[0], "Group item close button exists"); michael@0: EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow); michael@0: }