michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let cw; michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); michael@0: waitForExplicitFinish(); michael@0: michael@0: newWindowWithTabView(function(win) { michael@0: cw = win.TabView.getContentWindow(); michael@0: michael@0: let groupItemOne = cw.GroupItems.groupItems[0]; michael@0: is(groupItemOne.getChildren().length, 1, "Group one has 1 tab item"); michael@0: michael@0: let groupItemTwo = createGroupItemWithBlankTabs(win, 300, 300, 40, 2); michael@0: is(groupItemTwo.getChildren().length, 2, "Group two has 2 tab items"); michael@0: michael@0: let groupItemThree = createGroupItemWithBlankTabs(win, 300, 300, 40, 2); michael@0: is(groupItemThree.getChildren().length, 2, "Group three has 2 tab items"); michael@0: michael@0: waitForFocus(() => { michael@0: testMoreRecentlyUsedGroup(groupItemOne, groupItemTwo, function() { michael@0: testMoreRecentlyUsedGroup(groupItemOne, groupItemThree, function() { michael@0: testRemoveGroupAndCheckMoreRecentlyUsedGroup(groupItemOne, groupItemTwo); michael@0: }); michael@0: }); michael@0: }, cw); michael@0: }); michael@0: } michael@0: michael@0: function testMoreRecentlyUsedGroup(groupItemOne, otherGroupItem, callback) { michael@0: let tabItem = otherGroupItem.getChild(1); michael@0: cw.UI.setActive(tabItem); michael@0: is(otherGroupItem.getActiveTab(), tabItem, "The second item in the other group is active"); michael@0: is(cw.GroupItems.getActiveGroupItem(), otherGroupItem, "The other group is active"); michael@0: michael@0: let tabItemInGroupItemOne = groupItemOne.getChild(0); michael@0: cw.UI.setActive(tabItemInGroupItemOne); michael@0: is(groupItemOne.getActiveTab(), tabItemInGroupItemOne, "The first item in group one is active"); michael@0: is(cw.GroupItems.getActiveGroupItem(), groupItemOne, "The group one is active"); michael@0: michael@0: groupItemOne.addSubscriber("groupHidden", function onHide() { michael@0: groupItemOne.removeSubscriber("groupHidden", onHide); michael@0: michael@0: // group item three should have the focus michael@0: is(otherGroupItem.getActiveTab(), tabItem, "The second item in the other group is active after group one is hidden"); michael@0: is(cw.GroupItems.getActiveGroupItem(), otherGroupItem, "The other group is active active after group one is hidden"); michael@0: michael@0: groupItemOne.addSubscriber("groupShown", function onShown() { michael@0: groupItemOne.removeSubscriber("groupShown", onShown); michael@0: michael@0: is(groupItemOne.getActiveTab(), tabItemInGroupItemOne, "The first item in group one is active after it is shown"); michael@0: is(cw.GroupItems.getActiveGroupItem(), groupItemOne, "The group one is active after it is shown"); michael@0: michael@0: callback(); michael@0: }); michael@0: // click on the undo button michael@0: EventUtils.sendMouseEvent( michael@0: { type: "click" }, groupItemOne.$undoContainer[0], cw); michael@0: }); michael@0: // click on the close button of group item one michael@0: let closeButton = groupItemOne.container.getElementsByClassName("close"); michael@0: ok(closeButton[0], "Group item one close button exists"); michael@0: EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], cw); michael@0: } michael@0: michael@0: function testRemoveGroupAndCheckMoreRecentlyUsedGroup(groupItemOne, groupItemTwo) { michael@0: let tabItem = groupItemTwo.getChild(0); michael@0: cw.UI.setActive(tabItem); michael@0: michael@0: is(groupItemTwo.getActiveTab(), tabItem, "The first item in the group two is active"); michael@0: is(cw.GroupItems.getActiveGroupItem(), groupItemTwo, "The group two is active"); michael@0: michael@0: let tabItemInGroupItemOne = groupItemOne.getChild(0); michael@0: michael@0: tabItemInGroupItemOne.addSubscriber("close", function onClose() { michael@0: tabItemInGroupItemOne.removeSubscriber("close", onClose); michael@0: michael@0: is(groupItemTwo.getActiveTab(), tabItem, "The first item in the group two is still active after group one is closed"); michael@0: is(cw.GroupItems.getActiveGroupItem(), groupItemTwo, "The group two is still active after group one is closed"); michael@0: michael@0: promiseWindowClosed(cw.top).then(() => { michael@0: cw = null; michael@0: finish(); michael@0: }); michael@0: }); michael@0: // close the tab item and the group item michael@0: let closeButton = tabItemInGroupItemOne.container.getElementsByClassName("close"); michael@0: ok(closeButton[0], "Tab item close button exists"); michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, closeButton[0], cw); michael@0: EventUtils.sendMouseEvent({ type: "mouseup" }, closeButton[0], cw); michael@0: }