michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function test() { michael@0: // There should be one tab when we start the test michael@0: let [origTab] = gBrowser.visibleTabs; michael@0: michael@0: // Add a tab that will get pinned michael@0: let pinned = gBrowser.addTab(); michael@0: gBrowser.pinTab(pinned); michael@0: michael@0: let testTab = gBrowser.addTab(); michael@0: michael@0: let visible = gBrowser.visibleTabs; michael@0: is(visible.length, 3, "3 tabs should be open"); michael@0: is(visible[0], pinned, "the pinned tab is first"); michael@0: is(visible[1], origTab, "original tab is next"); michael@0: is(visible[2], testTab, "last created tab is last"); michael@0: michael@0: // Only show the test tab (but also get pinned and selected) michael@0: is(gBrowser.selectedTab, origTab, "sanity check that we're on the original tab"); michael@0: gBrowser.showOnlyTheseTabs([testTab]); michael@0: is(gBrowser.visibleTabs.length, 3, "all 3 tabs are still visible"); michael@0: michael@0: // Select the test tab and only show that (and pinned) michael@0: gBrowser.selectedTab = testTab; michael@0: gBrowser.showOnlyTheseTabs([testTab]); michael@0: michael@0: // if the tabview frame is initialized, we need to move the orignal tab to michael@0: // another group; otherwise, selecting a tab would make all three tabs in michael@0: // the same group to display. michael@0: let tabViewWindow = TabView.getContentWindow(); michael@0: if (tabViewWindow) michael@0: tabViewWindow.GroupItems.moveTabToGroupItem(origTab, null); michael@0: michael@0: visible = gBrowser.visibleTabs; michael@0: is(visible.length, 2, "2 tabs should be visible including the pinned"); michael@0: is(visible[0], pinned, "first is pinned"); michael@0: is(visible[1], testTab, "next is the test tab"); michael@0: is(gBrowser.tabs.length, 3, "3 tabs should still be open"); michael@0: michael@0: gBrowser.selectTabAtIndex(0); michael@0: is(gBrowser.selectedTab, pinned, "first tab is pinned"); michael@0: gBrowser.selectTabAtIndex(1); michael@0: is(gBrowser.selectedTab, testTab, "second tab is the test tab"); michael@0: gBrowser.selectTabAtIndex(2); michael@0: is(gBrowser.selectedTab, testTab, "no third tab, so no change"); michael@0: gBrowser.selectTabAtIndex(0); michael@0: is(gBrowser.selectedTab, pinned, "switch back to the pinned"); michael@0: gBrowser.selectTabAtIndex(2); michael@0: is(gBrowser.selectedTab, pinned, "no third tab, so no change"); michael@0: gBrowser.selectTabAtIndex(-1); michael@0: is(gBrowser.selectedTab, testTab, "last tab is the test tab"); michael@0: michael@0: gBrowser.tabContainer.advanceSelectedTab(1, true); michael@0: is(gBrowser.selectedTab, pinned, "wrapped around the end to pinned"); michael@0: gBrowser.tabContainer.advanceSelectedTab(1, true); michael@0: is(gBrowser.selectedTab, testTab, "next to test tab"); michael@0: gBrowser.tabContainer.advanceSelectedTab(1, true); michael@0: is(gBrowser.selectedTab, pinned, "next to pinned again"); michael@0: michael@0: gBrowser.tabContainer.advanceSelectedTab(-1, true); michael@0: is(gBrowser.selectedTab, testTab, "going backwards to last tab"); michael@0: gBrowser.tabContainer.advanceSelectedTab(-1, true); michael@0: is(gBrowser.selectedTab, pinned, "next to pinned"); michael@0: gBrowser.tabContainer.advanceSelectedTab(-1, true); michael@0: is(gBrowser.selectedTab, testTab, "next to test tab again"); michael@0: michael@0: // Try showing all tabs michael@0: gBrowser.showOnlyTheseTabs(Array.slice(gBrowser.tabs)); michael@0: is(gBrowser.visibleTabs.length, 3, "all 3 tabs are visible again"); michael@0: michael@0: // Select the pinned tab and show the testTab to make sure selection updates michael@0: gBrowser.selectedTab = pinned; michael@0: gBrowser.showOnlyTheseTabs([testTab]); michael@0: is(gBrowser.tabs[1], origTab, "make sure origTab is in the middle"); michael@0: is(origTab.hidden, true, "make sure it's hidden"); michael@0: gBrowser.removeTab(pinned); michael@0: is(gBrowser.selectedTab, testTab, "making sure origTab was skipped"); michael@0: is(gBrowser.visibleTabs.length, 1, "only testTab is there"); michael@0: michael@0: // Only show one of the non-pinned tabs (but testTab is selected) michael@0: gBrowser.showOnlyTheseTabs([origTab]); michael@0: is(gBrowser.visibleTabs.length, 2, "got 2 tabs"); michael@0: michael@0: // Now really only show one of the tabs michael@0: gBrowser.showOnlyTheseTabs([testTab]); michael@0: visible = gBrowser.visibleTabs; michael@0: is(visible.length, 1, "only the original tab is visible"); michael@0: is(visible[0], testTab, "it's the original tab"); michael@0: is(gBrowser.tabs.length, 2, "still have 2 open tabs"); michael@0: michael@0: // Close the last visible tab and make sure we still get a visible tab michael@0: gBrowser.removeTab(testTab); michael@0: is(gBrowser.visibleTabs.length, 1, "only orig is left and visible"); michael@0: is(gBrowser.tabs.length, 1, "sanity check that it matches"); michael@0: is(gBrowser.selectedTab, origTab, "got the orig tab"); michael@0: is(origTab.hidden, false, "and it's not hidden -- visible!"); michael@0: michael@0: if (tabViewWindow) michael@0: tabViewWindow.GroupItems.groupItems[0].close(); michael@0: }