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: // Show TabView michael@0: window.addEventListener("tabviewshown", onTabViewWindowLoaded, false); michael@0: TabView.toggle(); michael@0: } michael@0: michael@0: function onTabViewWindowLoaded() { michael@0: window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false); michael@0: ok(TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: let contentWindow = document.getElementById("tab-view").contentWindow; michael@0: michael@0: // establish initial state michael@0: is(contentWindow.GroupItems.groupItems.length, 1, "we start with one group (the default)"); michael@0: is(gBrowser.tabs.length, 1, "we start with one tab"); michael@0: michael@0: let originalTab = gBrowser.tabs[0]; michael@0: ok(contentWindow.GroupItems.groupItems[0]._children[0].tab == originalTab, michael@0: "the original tab is in the original group"); michael@0: michael@0: // create a second group michael@0: let box = new contentWindow.Rect(20, 20, 180, 180); michael@0: let groupItem = new contentWindow.GroupItem([], { bounds: box }); michael@0: is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups"); michael@0: contentWindow.UI.setActive(groupItem); michael@0: michael@0: // create a second tab michael@0: let normalXulTab = gBrowser.loadOneTab("about:blank"); michael@0: is(gBrowser.tabs.length, 2, "we now have two tabs"); michael@0: is(groupItem._children.length, 1, "the new tab was added to the group"); michael@0: michael@0: // create a third tab michael@0: let appXulTab = gBrowser.loadOneTab("about:blank"); michael@0: is(gBrowser.tabs.length, 3, "we now have three tabs"); michael@0: gBrowser.pinTab(appXulTab); michael@0: is(groupItem._children.length, 1, "the app tab is not in the group"); michael@0: michael@0: // We now have two groups with one tab each, plus an app tab. michael@0: // Click into one of the tabs, close it and make sure we don't go back to Tab View. michael@0: function onTabViewHidden() { michael@0: window.removeEventListener("tabviewhidden", onTabViewHidden, false); michael@0: ok(!TabView.isVisible(), "Tab View is hidden because we clicked on the app tab"); michael@0: michael@0: // Remove the tab we're looking at. michael@0: gBrowser.removeTab(normalXulTab); michael@0: michael@0: // Make sure we haven't returned to TabView; this is the crux of this test michael@0: ok(!TabView.isVisible(), "Tab View remains hidden"); michael@0: michael@0: // clean up michael@0: gBrowser.selectedTab = originalTab; michael@0: michael@0: gBrowser.unpinTab(appXulTab); michael@0: gBrowser.removeTab(appXulTab); michael@0: michael@0: ok(groupItem.closeIfEmpty(), "the second group was empty"); michael@0: michael@0: // Verify ending state michael@0: is(gBrowser.tabs.length, 1, "we finish with one tab"); michael@0: is(contentWindow.GroupItems.groupItems.length, 1, michael@0: "we finish with one group"); michael@0: ok(!TabView.isVisible(), "we finish with Tab View hidden"); michael@0: michael@0: finish(); michael@0: } michael@0: michael@0: window.addEventListener("tabviewhidden", onTabViewHidden, false); michael@0: EventUtils.sendMouseEvent({ type: "mousedown" }, normalXulTab._tabViewTabItem.container, contentWindow); michael@0: EventUtils.sendMouseEvent({ type: "mouseup" }, normalXulTab._tabViewTabItem.container, contentWindow); michael@0: }