1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug637840.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let cw; 1.8 + 1.9 +function test() { 1.10 + requestLongerTimeout(2); 1.11 + waitForExplicitFinish(); 1.12 + 1.13 + newWindowWithTabView(function(win) { 1.14 + cw = win.TabView.getContentWindow(); 1.15 + 1.16 + let groupItemOne = cw.GroupItems.groupItems[0]; 1.17 + is(groupItemOne.getChildren().length, 1, "Group one has 1 tab item"); 1.18 + 1.19 + let groupItemTwo = createGroupItemWithBlankTabs(win, 300, 300, 40, 2); 1.20 + is(groupItemTwo.getChildren().length, 2, "Group two has 2 tab items"); 1.21 + 1.22 + let groupItemThree = createGroupItemWithBlankTabs(win, 300, 300, 40, 2); 1.23 + is(groupItemThree.getChildren().length, 2, "Group three has 2 tab items"); 1.24 + 1.25 + waitForFocus(() => { 1.26 + testMoreRecentlyUsedGroup(groupItemOne, groupItemTwo, function() { 1.27 + testMoreRecentlyUsedGroup(groupItemOne, groupItemThree, function() { 1.28 + testRemoveGroupAndCheckMoreRecentlyUsedGroup(groupItemOne, groupItemTwo); 1.29 + }); 1.30 + }); 1.31 + }, cw); 1.32 + }); 1.33 +} 1.34 + 1.35 +function testMoreRecentlyUsedGroup(groupItemOne, otherGroupItem, callback) { 1.36 + let tabItem = otherGroupItem.getChild(1); 1.37 + cw.UI.setActive(tabItem); 1.38 + is(otherGroupItem.getActiveTab(), tabItem, "The second item in the other group is active"); 1.39 + is(cw.GroupItems.getActiveGroupItem(), otherGroupItem, "The other group is active"); 1.40 + 1.41 + let tabItemInGroupItemOne = groupItemOne.getChild(0); 1.42 + cw.UI.setActive(tabItemInGroupItemOne); 1.43 + is(groupItemOne.getActiveTab(), tabItemInGroupItemOne, "The first item in group one is active"); 1.44 + is(cw.GroupItems.getActiveGroupItem(), groupItemOne, "The group one is active"); 1.45 + 1.46 + groupItemOne.addSubscriber("groupHidden", function onHide() { 1.47 + groupItemOne.removeSubscriber("groupHidden", onHide); 1.48 + 1.49 + // group item three should have the focus 1.50 + is(otherGroupItem.getActiveTab(), tabItem, "The second item in the other group is active after group one is hidden"); 1.51 + is(cw.GroupItems.getActiveGroupItem(), otherGroupItem, "The other group is active active after group one is hidden"); 1.52 + 1.53 + groupItemOne.addSubscriber("groupShown", function onShown() { 1.54 + groupItemOne.removeSubscriber("groupShown", onShown); 1.55 + 1.56 + is(groupItemOne.getActiveTab(), tabItemInGroupItemOne, "The first item in group one is active after it is shown"); 1.57 + is(cw.GroupItems.getActiveGroupItem(), groupItemOne, "The group one is active after it is shown"); 1.58 + 1.59 + callback(); 1.60 + }); 1.61 + // click on the undo button 1.62 + EventUtils.sendMouseEvent( 1.63 + { type: "click" }, groupItemOne.$undoContainer[0], cw); 1.64 + }); 1.65 + // click on the close button of group item one 1.66 + let closeButton = groupItemOne.container.getElementsByClassName("close"); 1.67 + ok(closeButton[0], "Group item one close button exists"); 1.68 + EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], cw); 1.69 +} 1.70 + 1.71 +function testRemoveGroupAndCheckMoreRecentlyUsedGroup(groupItemOne, groupItemTwo) { 1.72 + let tabItem = groupItemTwo.getChild(0); 1.73 + cw.UI.setActive(tabItem); 1.74 + 1.75 + is(groupItemTwo.getActiveTab(), tabItem, "The first item in the group two is active"); 1.76 + is(cw.GroupItems.getActiveGroupItem(), groupItemTwo, "The group two is active"); 1.77 + 1.78 + let tabItemInGroupItemOne = groupItemOne.getChild(0); 1.79 + 1.80 + tabItemInGroupItemOne.addSubscriber("close", function onClose() { 1.81 + tabItemInGroupItemOne.removeSubscriber("close", onClose); 1.82 + 1.83 + is(groupItemTwo.getActiveTab(), tabItem, "The first item in the group two is still active after group one is closed"); 1.84 + is(cw.GroupItems.getActiveGroupItem(), groupItemTwo, "The group two is still active after group one is closed"); 1.85 + 1.86 + promiseWindowClosed(cw.top).then(() => { 1.87 + cw = null; 1.88 + finish(); 1.89 + }); 1.90 + }); 1.91 + // close the tab item and the group item 1.92 + let closeButton = tabItemInGroupItemOne.container.getElementsByClassName("close"); 1.93 + ok(closeButton[0], "Tab item close button exists"); 1.94 + EventUtils.sendMouseEvent({ type: "mousedown" }, closeButton[0], cw); 1.95 + EventUtils.sendMouseEvent({ type: "mouseup" }, closeButton[0], cw); 1.96 +}