browser/base/content/test/general/browser_visibleTabs.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 function test() {
michael@0 6 // There should be one tab when we start the test
michael@0 7 let [origTab] = gBrowser.visibleTabs;
michael@0 8
michael@0 9 // Add a tab that will get pinned
michael@0 10 let pinned = gBrowser.addTab();
michael@0 11 gBrowser.pinTab(pinned);
michael@0 12
michael@0 13 let testTab = gBrowser.addTab();
michael@0 14
michael@0 15 let visible = gBrowser.visibleTabs;
michael@0 16 is(visible.length, 3, "3 tabs should be open");
michael@0 17 is(visible[0], pinned, "the pinned tab is first");
michael@0 18 is(visible[1], origTab, "original tab is next");
michael@0 19 is(visible[2], testTab, "last created tab is last");
michael@0 20
michael@0 21 // Only show the test tab (but also get pinned and selected)
michael@0 22 is(gBrowser.selectedTab, origTab, "sanity check that we're on the original tab");
michael@0 23 gBrowser.showOnlyTheseTabs([testTab]);
michael@0 24 is(gBrowser.visibleTabs.length, 3, "all 3 tabs are still visible");
michael@0 25
michael@0 26 // Select the test tab and only show that (and pinned)
michael@0 27 gBrowser.selectedTab = testTab;
michael@0 28 gBrowser.showOnlyTheseTabs([testTab]);
michael@0 29
michael@0 30 // if the tabview frame is initialized, we need to move the orignal tab to
michael@0 31 // another group; otherwise, selecting a tab would make all three tabs in
michael@0 32 // the same group to display.
michael@0 33 let tabViewWindow = TabView.getContentWindow();
michael@0 34 if (tabViewWindow)
michael@0 35 tabViewWindow.GroupItems.moveTabToGroupItem(origTab, null);
michael@0 36
michael@0 37 visible = gBrowser.visibleTabs;
michael@0 38 is(visible.length, 2, "2 tabs should be visible including the pinned");
michael@0 39 is(visible[0], pinned, "first is pinned");
michael@0 40 is(visible[1], testTab, "next is the test tab");
michael@0 41 is(gBrowser.tabs.length, 3, "3 tabs should still be open");
michael@0 42
michael@0 43 gBrowser.selectTabAtIndex(0);
michael@0 44 is(gBrowser.selectedTab, pinned, "first tab is pinned");
michael@0 45 gBrowser.selectTabAtIndex(1);
michael@0 46 is(gBrowser.selectedTab, testTab, "second tab is the test tab");
michael@0 47 gBrowser.selectTabAtIndex(2);
michael@0 48 is(gBrowser.selectedTab, testTab, "no third tab, so no change");
michael@0 49 gBrowser.selectTabAtIndex(0);
michael@0 50 is(gBrowser.selectedTab, pinned, "switch back to the pinned");
michael@0 51 gBrowser.selectTabAtIndex(2);
michael@0 52 is(gBrowser.selectedTab, pinned, "no third tab, so no change");
michael@0 53 gBrowser.selectTabAtIndex(-1);
michael@0 54 is(gBrowser.selectedTab, testTab, "last tab is the test tab");
michael@0 55
michael@0 56 gBrowser.tabContainer.advanceSelectedTab(1, true);
michael@0 57 is(gBrowser.selectedTab, pinned, "wrapped around the end to pinned");
michael@0 58 gBrowser.tabContainer.advanceSelectedTab(1, true);
michael@0 59 is(gBrowser.selectedTab, testTab, "next to test tab");
michael@0 60 gBrowser.tabContainer.advanceSelectedTab(1, true);
michael@0 61 is(gBrowser.selectedTab, pinned, "next to pinned again");
michael@0 62
michael@0 63 gBrowser.tabContainer.advanceSelectedTab(-1, true);
michael@0 64 is(gBrowser.selectedTab, testTab, "going backwards to last tab");
michael@0 65 gBrowser.tabContainer.advanceSelectedTab(-1, true);
michael@0 66 is(gBrowser.selectedTab, pinned, "next to pinned");
michael@0 67 gBrowser.tabContainer.advanceSelectedTab(-1, true);
michael@0 68 is(gBrowser.selectedTab, testTab, "next to test tab again");
michael@0 69
michael@0 70 // Try showing all tabs
michael@0 71 gBrowser.showOnlyTheseTabs(Array.slice(gBrowser.tabs));
michael@0 72 is(gBrowser.visibleTabs.length, 3, "all 3 tabs are visible again");
michael@0 73
michael@0 74 // Select the pinned tab and show the testTab to make sure selection updates
michael@0 75 gBrowser.selectedTab = pinned;
michael@0 76 gBrowser.showOnlyTheseTabs([testTab]);
michael@0 77 is(gBrowser.tabs[1], origTab, "make sure origTab is in the middle");
michael@0 78 is(origTab.hidden, true, "make sure it's hidden");
michael@0 79 gBrowser.removeTab(pinned);
michael@0 80 is(gBrowser.selectedTab, testTab, "making sure origTab was skipped");
michael@0 81 is(gBrowser.visibleTabs.length, 1, "only testTab is there");
michael@0 82
michael@0 83 // Only show one of the non-pinned tabs (but testTab is selected)
michael@0 84 gBrowser.showOnlyTheseTabs([origTab]);
michael@0 85 is(gBrowser.visibleTabs.length, 2, "got 2 tabs");
michael@0 86
michael@0 87 // Now really only show one of the tabs
michael@0 88 gBrowser.showOnlyTheseTabs([testTab]);
michael@0 89 visible = gBrowser.visibleTabs;
michael@0 90 is(visible.length, 1, "only the original tab is visible");
michael@0 91 is(visible[0], testTab, "it's the original tab");
michael@0 92 is(gBrowser.tabs.length, 2, "still have 2 open tabs");
michael@0 93
michael@0 94 // Close the last visible tab and make sure we still get a visible tab
michael@0 95 gBrowser.removeTab(testTab);
michael@0 96 is(gBrowser.visibleTabs.length, 1, "only orig is left and visible");
michael@0 97 is(gBrowser.tabs.length, 1, "sanity check that it matches");
michael@0 98 is(gBrowser.selectedTab, origTab, "got the orig tab");
michael@0 99 is(origTab.hidden, false, "and it's not hidden -- visible!");
michael@0 100
michael@0 101 if (tabViewWindow)
michael@0 102 tabViewWindow.GroupItems.groupItems[0].close();
michael@0 103 }

mercurial