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: showTabView(onTabViewWindowLoaded); michael@0: } michael@0: michael@0: let originalGroupItem = null; michael@0: let originalTab = null; 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: is(contentWindow.GroupItems.groupItems.length, 1, "There is one group item on startup"); michael@0: originalGroupItem = contentWindow.GroupItems.groupItems[0]; michael@0: is(originalGroupItem.getChildren().length, 1, "There should be one Tab Item in that group."); michael@0: contentWindow.UI.setActive(originalGroupItem); michael@0: michael@0: [originalTab] = gBrowser.visibleTabs; michael@0: michael@0: testEmptyGroupItem(contentWindow); michael@0: } michael@0: michael@0: function testEmptyGroupItem(contentWindow) { michael@0: let groupItemCount = contentWindow.GroupItems.groupItems.length; michael@0: michael@0: // create empty group item michael@0: let emptyGroupItem = createEmptyGroupItem(contentWindow, 300, 300, 100); michael@0: ok(emptyGroupItem.isEmpty(), "This group is empty"); michael@0: michael@0: is(contentWindow.GroupItems.groupItems.length, ++groupItemCount, michael@0: "The number of groups is increased by 1"); michael@0: michael@0: emptyGroupItem.addSubscriber("close", function onClose() { michael@0: emptyGroupItem.removeSubscriber("close", onClose); michael@0: michael@0: // check the number of groups. michael@0: is(contentWindow.GroupItems.groupItems.length, --groupItemCount, michael@0: "The number of groups is decreased by 1"); michael@0: michael@0: testGroupItemWithTabItem(contentWindow); michael@0: }); michael@0: michael@0: let closeButton = emptyGroupItem.container.getElementsByClassName("close"); michael@0: ok(closeButton[0], "Group close button exists"); michael@0: michael@0: // click the close button michael@0: EventUtils.synthesizeMouse(closeButton[0], 1, 1, {}, contentWindow); michael@0: } michael@0: michael@0: function testGroupItemWithTabItem(contentWindow) { michael@0: let groupItem = createEmptyGroupItem(contentWindow, 300, 300, 200); michael@0: let tabItemCount = 0; michael@0: michael@0: let onTabViewShown = function() { michael@0: let tabItem = groupItem.getChild(groupItem.getChildren().length - 1); michael@0: ok(tabItem, "Tab item exists"); michael@0: michael@0: let tabItemClosed = false; michael@0: tabItem.addSubscriber("close", function onClose() { michael@0: tabItem.removeSubscriber("close", onClose); michael@0: tabItemClosed = true; michael@0: }); michael@0: tabItem.addSubscriber("tabRemoved", function onTabRemoved() { michael@0: tabItem.removeSubscriber("tabRemoved", onTabRemoved); michael@0: michael@0: ok(tabItemClosed, "The tab item is closed"); michael@0: is(groupItem.getChildren().length, --tabItemCount, michael@0: "The number of children in new tab group is decreased by 1"); michael@0: michael@0: ok(TabView.isVisible(), "Tab View is still shown"); michael@0: michael@0: // Now there should only be one tab left, so we need to hide TabView michael@0: // and go into that tab. michael@0: is(gBrowser.tabs.length, 1, "There is only one tab left"); 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: michael@0: closeGroupItem(groupItem, finish); michael@0: }); michael@0: }); michael@0: michael@0: // remove the tab item. The code detects mousedown and mouseup so we stimulate here michael@0: let closeButton = tabItem.container.getElementsByClassName("close"); michael@0: ok(closeButton, "Tab item close button exists"); michael@0: michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, closeButton[0], contentWindow); michael@0: EventUtils.sendMouseEvent({ type: "mouseup" }, closeButton[0], contentWindow); michael@0: }; michael@0: michael@0: whenTabViewIsHidden(function() { michael@0: is(groupItem.getChildren().length, ++tabItemCount, michael@0: "The number of children in new tab group is increased by 1"); michael@0: michael@0: ok(!TabView.isVisible(), "Tab View is hidden because we just opened a tab"); michael@0: showTabView(onTabViewShown); michael@0: }); michael@0: groupItem.newTab(); michael@0: }