1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_group.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 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 + showTabView(onTabViewWindowLoaded); 1.11 +} 1.12 + 1.13 +let originalGroupItem = null; 1.14 +let originalTab = null; 1.15 + 1.16 +function onTabViewWindowLoaded() { 1.17 + ok(TabView.isVisible(), "Tab View is visible"); 1.18 + 1.19 + let contentWindow = TabView.getContentWindow(); 1.20 + 1.21 + is(contentWindow.GroupItems.groupItems.length, 1, "There is one group item on startup"); 1.22 + originalGroupItem = contentWindow.GroupItems.groupItems[0]; 1.23 + is(originalGroupItem.getChildren().length, 1, "There should be one Tab Item in that group."); 1.24 + contentWindow.UI.setActive(originalGroupItem); 1.25 + 1.26 + [originalTab] = gBrowser.visibleTabs; 1.27 + 1.28 + testEmptyGroupItem(contentWindow); 1.29 +} 1.30 + 1.31 +function testEmptyGroupItem(contentWindow) { 1.32 + let groupItemCount = contentWindow.GroupItems.groupItems.length; 1.33 + 1.34 + // create empty group item 1.35 + let emptyGroupItem = createEmptyGroupItem(contentWindow, 300, 300, 100); 1.36 + ok(emptyGroupItem.isEmpty(), "This group is empty"); 1.37 + 1.38 + is(contentWindow.GroupItems.groupItems.length, ++groupItemCount, 1.39 + "The number of groups is increased by 1"); 1.40 + 1.41 + emptyGroupItem.addSubscriber("close", function onClose() { 1.42 + emptyGroupItem.removeSubscriber("close", onClose); 1.43 + 1.44 + // check the number of groups. 1.45 + is(contentWindow.GroupItems.groupItems.length, --groupItemCount, 1.46 + "The number of groups is decreased by 1"); 1.47 + 1.48 + testGroupItemWithTabItem(contentWindow); 1.49 + }); 1.50 + 1.51 + let closeButton = emptyGroupItem.container.getElementsByClassName("close"); 1.52 + ok(closeButton[0], "Group close button exists"); 1.53 + 1.54 + // click the close button 1.55 + EventUtils.synthesizeMouse(closeButton[0], 1, 1, {}, contentWindow); 1.56 +} 1.57 + 1.58 +function testGroupItemWithTabItem(contentWindow) { 1.59 + let groupItem = createEmptyGroupItem(contentWindow, 300, 300, 200); 1.60 + let tabItemCount = 0; 1.61 + 1.62 + let onTabViewShown = function() { 1.63 + let tabItem = groupItem.getChild(groupItem.getChildren().length - 1); 1.64 + ok(tabItem, "Tab item exists"); 1.65 + 1.66 + let tabItemClosed = false; 1.67 + tabItem.addSubscriber("close", function onClose() { 1.68 + tabItem.removeSubscriber("close", onClose); 1.69 + tabItemClosed = true; 1.70 + }); 1.71 + tabItem.addSubscriber("tabRemoved", function onTabRemoved() { 1.72 + tabItem.removeSubscriber("tabRemoved", onTabRemoved); 1.73 + 1.74 + ok(tabItemClosed, "The tab item is closed"); 1.75 + is(groupItem.getChildren().length, --tabItemCount, 1.76 + "The number of children in new tab group is decreased by 1"); 1.77 + 1.78 + ok(TabView.isVisible(), "Tab View is still shown"); 1.79 + 1.80 + // Now there should only be one tab left, so we need to hide TabView 1.81 + // and go into that tab. 1.82 + is(gBrowser.tabs.length, 1, "There is only one tab left"); 1.83 + 1.84 + // after the last selected tabitem is closed, there would be not active 1.85 + // tabitem on the UI so we set the active tabitem before toggling the 1.86 + // visibility of tabview 1.87 + let tabItems = contentWindow.TabItems.getItems(); 1.88 + ok(tabItems[0], "A tab item exists"); 1.89 + contentWindow.UI.setActive(tabItems[0]); 1.90 + 1.91 + hideTabView(function() { 1.92 + ok(!TabView.isVisible(), "Tab View is hidden"); 1.93 + 1.94 + closeGroupItem(groupItem, finish); 1.95 + }); 1.96 + }); 1.97 + 1.98 + // remove the tab item. The code detects mousedown and mouseup so we stimulate here 1.99 + let closeButton = tabItem.container.getElementsByClassName("close"); 1.100 + ok(closeButton, "Tab item close button exists"); 1.101 + 1.102 + EventUtils.sendMouseEvent({ type: "mousedown" }, closeButton[0], contentWindow); 1.103 + EventUtils.sendMouseEvent({ type: "mouseup" }, closeButton[0], contentWindow); 1.104 + }; 1.105 + 1.106 + whenTabViewIsHidden(function() { 1.107 + is(groupItem.getChildren().length, ++tabItemCount, 1.108 + "The number of children in new tab group is increased by 1"); 1.109 + 1.110 + ok(!TabView.isVisible(), "Tab View is hidden because we just opened a tab"); 1.111 + showTabView(onTabViewShown); 1.112 + }); 1.113 + groupItem.newTab(); 1.114 +}