1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_visibleTabs.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +function test() { 1.9 + // There should be one tab when we start the test 1.10 + let [origTab] = gBrowser.visibleTabs; 1.11 + 1.12 + // Add a tab that will get pinned 1.13 + let pinned = gBrowser.addTab(); 1.14 + gBrowser.pinTab(pinned); 1.15 + 1.16 + let testTab = gBrowser.addTab(); 1.17 + 1.18 + let visible = gBrowser.visibleTabs; 1.19 + is(visible.length, 3, "3 tabs should be open"); 1.20 + is(visible[0], pinned, "the pinned tab is first"); 1.21 + is(visible[1], origTab, "original tab is next"); 1.22 + is(visible[2], testTab, "last created tab is last"); 1.23 + 1.24 + // Only show the test tab (but also get pinned and selected) 1.25 + is(gBrowser.selectedTab, origTab, "sanity check that we're on the original tab"); 1.26 + gBrowser.showOnlyTheseTabs([testTab]); 1.27 + is(gBrowser.visibleTabs.length, 3, "all 3 tabs are still visible"); 1.28 + 1.29 + // Select the test tab and only show that (and pinned) 1.30 + gBrowser.selectedTab = testTab; 1.31 + gBrowser.showOnlyTheseTabs([testTab]); 1.32 + 1.33 + // if the tabview frame is initialized, we need to move the orignal tab to 1.34 + // another group; otherwise, selecting a tab would make all three tabs in 1.35 + // the same group to display. 1.36 + let tabViewWindow = TabView.getContentWindow(); 1.37 + if (tabViewWindow) 1.38 + tabViewWindow.GroupItems.moveTabToGroupItem(origTab, null); 1.39 + 1.40 + visible = gBrowser.visibleTabs; 1.41 + is(visible.length, 2, "2 tabs should be visible including the pinned"); 1.42 + is(visible[0], pinned, "first is pinned"); 1.43 + is(visible[1], testTab, "next is the test tab"); 1.44 + is(gBrowser.tabs.length, 3, "3 tabs should still be open"); 1.45 + 1.46 + gBrowser.selectTabAtIndex(0); 1.47 + is(gBrowser.selectedTab, pinned, "first tab is pinned"); 1.48 + gBrowser.selectTabAtIndex(1); 1.49 + is(gBrowser.selectedTab, testTab, "second tab is the test tab"); 1.50 + gBrowser.selectTabAtIndex(2); 1.51 + is(gBrowser.selectedTab, testTab, "no third tab, so no change"); 1.52 + gBrowser.selectTabAtIndex(0); 1.53 + is(gBrowser.selectedTab, pinned, "switch back to the pinned"); 1.54 + gBrowser.selectTabAtIndex(2); 1.55 + is(gBrowser.selectedTab, pinned, "no third tab, so no change"); 1.56 + gBrowser.selectTabAtIndex(-1); 1.57 + is(gBrowser.selectedTab, testTab, "last tab is the test tab"); 1.58 + 1.59 + gBrowser.tabContainer.advanceSelectedTab(1, true); 1.60 + is(gBrowser.selectedTab, pinned, "wrapped around the end to pinned"); 1.61 + gBrowser.tabContainer.advanceSelectedTab(1, true); 1.62 + is(gBrowser.selectedTab, testTab, "next to test tab"); 1.63 + gBrowser.tabContainer.advanceSelectedTab(1, true); 1.64 + is(gBrowser.selectedTab, pinned, "next to pinned again"); 1.65 + 1.66 + gBrowser.tabContainer.advanceSelectedTab(-1, true); 1.67 + is(gBrowser.selectedTab, testTab, "going backwards to last tab"); 1.68 + gBrowser.tabContainer.advanceSelectedTab(-1, true); 1.69 + is(gBrowser.selectedTab, pinned, "next to pinned"); 1.70 + gBrowser.tabContainer.advanceSelectedTab(-1, true); 1.71 + is(gBrowser.selectedTab, testTab, "next to test tab again"); 1.72 + 1.73 + // Try showing all tabs 1.74 + gBrowser.showOnlyTheseTabs(Array.slice(gBrowser.tabs)); 1.75 + is(gBrowser.visibleTabs.length, 3, "all 3 tabs are visible again"); 1.76 + 1.77 + // Select the pinned tab and show the testTab to make sure selection updates 1.78 + gBrowser.selectedTab = pinned; 1.79 + gBrowser.showOnlyTheseTabs([testTab]); 1.80 + is(gBrowser.tabs[1], origTab, "make sure origTab is in the middle"); 1.81 + is(origTab.hidden, true, "make sure it's hidden"); 1.82 + gBrowser.removeTab(pinned); 1.83 + is(gBrowser.selectedTab, testTab, "making sure origTab was skipped"); 1.84 + is(gBrowser.visibleTabs.length, 1, "only testTab is there"); 1.85 + 1.86 + // Only show one of the non-pinned tabs (but testTab is selected) 1.87 + gBrowser.showOnlyTheseTabs([origTab]); 1.88 + is(gBrowser.visibleTabs.length, 2, "got 2 tabs"); 1.89 + 1.90 + // Now really only show one of the tabs 1.91 + gBrowser.showOnlyTheseTabs([testTab]); 1.92 + visible = gBrowser.visibleTabs; 1.93 + is(visible.length, 1, "only the original tab is visible"); 1.94 + is(visible[0], testTab, "it's the original tab"); 1.95 + is(gBrowser.tabs.length, 2, "still have 2 open tabs"); 1.96 + 1.97 + // Close the last visible tab and make sure we still get a visible tab 1.98 + gBrowser.removeTab(testTab); 1.99 + is(gBrowser.visibleTabs.length, 1, "only orig is left and visible"); 1.100 + is(gBrowser.tabs.length, 1, "sanity check that it matches"); 1.101 + is(gBrowser.selectedTab, origTab, "got the orig tab"); 1.102 + is(origTab.hidden, false, "and it's not hidden -- visible!"); 1.103 + 1.104 + if (tabViewWindow) 1.105 + tabViewWindow.GroupItems.groupItems[0].close(); 1.106 +}