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