1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_undo_group.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,120 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + waitForExplicitFinish(); 1.9 + 1.10 + registerCleanupFunction(function() { 1.11 + while (gBrowser.tabs[1]) 1.12 + gBrowser.removeTab(gBrowser.tabs[1]); 1.13 + hideTabView(); 1.14 + }); 1.15 + showTabView(onTabViewWindowLoaded); 1.16 +} 1.17 + 1.18 +function onTabViewWindowLoaded() { 1.19 + ok(TabView.isVisible(), "Tab View is visible"); 1.20 + 1.21 + let contentWindow = TabView.getContentWindow(); 1.22 + 1.23 + registerCleanupFunction(function() { 1.24 + let groupItem = contentWindow.GroupItems.groupItem(groupItemId); 1.25 + if (groupItem) 1.26 + closeGroupItem(groupItem); 1.27 + }); 1.28 + 1.29 + // create a group item 1.30 + let groupItem = createGroupItemWithBlankTabs(window, 300, 300, 400, 1); 1.31 + let groupItemId = groupItem.id; 1.32 + is(groupItem.getChildren().length, 1, "The new group has a tab item"); 1.33 + // start the tests 1.34 + waitForFocus(function() { 1.35 + testUndoGroup(contentWindow, groupItem); 1.36 + }, contentWindow); 1.37 +} 1.38 + 1.39 +function testUndoGroup(contentWindow, groupItem) { 1.40 + groupItem.addSubscriber("groupHidden", function onHidden() { 1.41 + groupItem.removeSubscriber("groupHidden", onHidden); 1.42 + 1.43 + // check the data of the group 1.44 + let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id); 1.45 + ok(theGroupItem, "The group item still exists"); 1.46 + is(theGroupItem.getChildren().length, 1, 1.47 + "The tab item in the group still exists"); 1.48 + 1.49 + // check the visibility of the group element and undo element 1.50 + is(theGroupItem.container.style.display, "none", 1.51 + "The group element is hidden"); 1.52 + ok(theGroupItem.$undoContainer, "Undo container is avaliable"); 1.53 + 1.54 + EventUtils.sendMouseEvent( 1.55 + { type: "click" }, theGroupItem.$undoContainer[0], contentWindow); 1.56 + }); 1.57 + 1.58 + groupItem.addSubscriber("groupShown", function onShown() { 1.59 + groupItem.removeSubscriber("groupShown", onShown); 1.60 + 1.61 + // check the data of the group 1.62 + let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id); 1.63 + ok(theGroupItem, "The group item still exists"); 1.64 + is(theGroupItem.getChildren().length, 1, 1.65 + "The tab item in the group still exists"); 1.66 + 1.67 + // check the visibility of the group element and undo element 1.68 + is(theGroupItem.container.style.display, "", "The group element is visible"); 1.69 + ok(!theGroupItem.$undoContainer, "Undo container is not avaliable"); 1.70 + 1.71 + // start the next test 1.72 + testCloseUndoGroup(contentWindow, groupItem); 1.73 + }); 1.74 + 1.75 + let closeButton = groupItem.container.getElementsByClassName("close"); 1.76 + ok(closeButton[0], "Group item close button exists"); 1.77 + EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow); 1.78 +} 1.79 + 1.80 +function testCloseUndoGroup(contentWindow, groupItem) { 1.81 + groupItem.addSubscriber("groupHidden", function onHidden() { 1.82 + groupItem.removeSubscriber("groupHidden", onHidden); 1.83 + 1.84 + // check the data of the group 1.85 + let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id); 1.86 + ok(theGroupItem, "The group item still exists"); 1.87 + is(theGroupItem.getChildren().length, 1, 1.88 + "The tab item in the group still exists"); 1.89 + 1.90 + // check the visibility of the group element and undo element 1.91 + is(theGroupItem.container.style.display, "none", 1.92 + "The group element is hidden"); 1.93 + ok(theGroupItem.$undoContainer, "Undo container is avaliable"); 1.94 + 1.95 + // click on close 1.96 + let closeButton = theGroupItem.$undoContainer.find(".close"); 1.97 + EventUtils.sendMouseEvent( 1.98 + { type: "click" }, closeButton[0], contentWindow); 1.99 + }); 1.100 + 1.101 + groupItem.addSubscriber("close", function onClose() { 1.102 + groupItem.removeSubscriber("close", onClose); 1.103 + 1.104 + let theGroupItem = contentWindow.GroupItems.groupItem(groupItem.id); 1.105 + ok(!theGroupItem, "The group item doesn't exists"); 1.106 + 1.107 + // after the last selected tabitem is closed, there would be not active 1.108 + // tabitem on the UI so we set the active tabitem before toggling the 1.109 + // visibility of tabview 1.110 + let tabItems = contentWindow.TabItems.getItems(); 1.111 + ok(tabItems[0], "A tab item exists"); 1.112 + contentWindow.UI.setActive(tabItems[0]); 1.113 + 1.114 + hideTabView(function() { 1.115 + ok(!TabView.isVisible(), "Tab View is hidden"); 1.116 + finish(); 1.117 + }); 1.118 + }); 1.119 + 1.120 + let closeButton = groupItem.container.getElementsByClassName("close"); 1.121 + ok(closeButton[0], "Group item close button exists"); 1.122 + EventUtils.sendMouseEvent({ type: "click" }, closeButton[0], contentWindow); 1.123 +}