michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let origTab = gBrowser.visibleTabs[0]; michael@0: let contentWindow; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: test1(); michael@0: } michael@0: michael@0: // Open a new tab when the active tab item belongs to a group item. michael@0: function test1() { michael@0: registerCleanupFunction(function () TabView.hide()); michael@0: michael@0: showTabView(function() { michael@0: ok(origTab._tabViewTabItem.parent, "The original tab belongs to a group"); michael@0: michael@0: contentWindow = TabView.getContentWindow(); michael@0: contentWindow.UI.setActive(origTab._tabViewTabItem); michael@0: michael@0: testCreateTabAndThen(test2); michael@0: }); michael@0: } michael@0: michael@0: // Open a new tab when the active tab item is nothing. michael@0: function test2() { michael@0: showTabView(function() { michael@0: contentWindow.UI.setActive(null, { onlyRemoveActiveTab: true }); michael@0: michael@0: testCreateTabAndThen(test3); michael@0: }); michael@0: } michael@0: michael@0: // Open a new tab when the active tab item is an orphan tab. michael@0: function test3() { michael@0: showTabView(function() { michael@0: let groupItem = origTab._tabViewTabItem.parent; michael@0: let tabItems = groupItem.getChildren(); michael@0: is(tabItems.length, 3, "There are 3 tab items in the group"); michael@0: michael@0: let lastTabItem = tabItems[tabItems.length - 1]; michael@0: groupItem.remove(lastTabItem); michael@0: michael@0: let orphanedTabs = contentWindow.GroupItems.getOrphanedTabs(); michael@0: is(orphanedTabs.length, 1, "There should be 1 orphan tab"); michael@0: is(orphanedTabs[0], lastTabItem, "The tab item is the same as the orphan tab"); michael@0: michael@0: contentWindow.UI.setActive(lastTabItem); michael@0: michael@0: testCreateTabAndThen(function() { michael@0: hideTabView(finish); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function testCreateTabAndThen(callback) { michael@0: ok(TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: // detect tab open and zoomed in event. michael@0: let onTabOpen = function(event) { michael@0: gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, false); michael@0: michael@0: // ensure that the default tabview listener is called before so the michael@0: // tab._tabViewTabItem exists michael@0: executeSoon(function() { michael@0: let tab = event.target; michael@0: tabItem = tab._tabViewTabItem; michael@0: ok(tabItem, "Tab item is available after tab open"); michael@0: michael@0: registerCleanupFunction(function () gBrowser.removeTab(tab)) michael@0: michael@0: tabItem.addSubscriber("zoomedIn", function onZoomedIn() { michael@0: tabItem.removeSubscriber("zoomedIn", onZoomedIn); michael@0: michael@0: is(gBrowser.selectedTab, tab, michael@0: "The selected tab is the same as the newly opened tab"); michael@0: executeSoon(callback); michael@0: }); michael@0: }); michael@0: } michael@0: gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, false); michael@0: // use the menu item (the same as pressing cmd/ctrl + t) michael@0: document.getElementById("menu_newNavigatorTab").doCommand(); michael@0: }