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 // -*- Mode: js2; tab-width: 2; indent-tabs-mode: nil; js2-basic-offset: 2; js2-skip-preprocessor-directives: t; -*-
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 "use strict";
8 let mockTab = function(aName, aIsClosing) {
9 this.name = aName;
10 this.isClosing = aIsClosing;
11 };
13 mockTab.prototype = {
14 get chromeTab () {
15 let getAttribute = () => this.isClosing;
16 return {
17 hasAttribute: getAttribute
18 }
19 }
20 };
22 let getMockBrowserTabs = function(aTestTabs, aSelected) {
23 let result = {
24 _tabs: aTestTabs,
25 _selectedTab: aTestTabs[aSelected || 0],
26 getTabAtIndex: function(i) this._tabs[i]
27 };
29 return [result, Browser.getNextTab.bind(result)];
30 };
32 gTests.push({
33 desc: "Test Browser.getNextTab",
34 run: function() {
35 let [lonlyTab, fakeGetNextTab] = getMockBrowserTabs(
36 [new mockTab("a", false)]);
38 ok(fakeGetNextTab(lonlyTab._selectedTab) == null, "null when only 1 tab left");
39 ok(fakeGetNextTab(new mockTab("x", false)) == null, "null when tab doesnt exist");
41 let [twoTabs, fakeGetNextTab] = getMockBrowserTabs(
42 [new mockTab("a", false), new mockTab("b", false)]);
43 ok(fakeGetNextTab(twoTabs._selectedTab).name == "b", "get next tab");
44 ok(fakeGetNextTab(twoTabs._tabs[1]).name == "a", "get selected tab");
46 let [twoTabsSecondSelected, fakeGetNextTab] = getMockBrowserTabs(
47 [new mockTab("a", false), new mockTab("b", false)], 1);
48 ok(fakeGetNextTab(twoTabsSecondSelected._selectedTab).name == "a", "get previous tab");
50 let [twoTabsOneClosing, fakeGetNextTab] = getMockBrowserTabs(
51 [new mockTab("a", false), new mockTab("b", true)]);
52 ok(fakeGetNextTab(twoTabsOneClosing._selectedTab) == null, "can't select closing tab");
53 ok(fakeGetNextTab(twoTabsOneClosing._tabs[1]).name == "a", "get previous tab");
55 let [twoTabsBothClosing, fakeGetNextTab] = getMockBrowserTabs(
56 [new mockTab("a", true), new mockTab("b", true)]);
57 ok(fakeGetNextTab(twoTabsBothClosing._selectedTab) == null, "can't select closing tab");
58 ok(fakeGetNextTab(twoTabsBothClosing._tabs[1]) == null, "can't select closing tab");
60 let [fiveTabsLastNotClosing, fakeGetNextTab] = getMockBrowserTabs(
61 [new mockTab("a", false), new mockTab("b", true), new mockTab("c", true), new mockTab("d", true), new mockTab("e", false)]);
62 ok(fakeGetNextTab(fiveTabsLastNotClosing._selectedTab).name == "e", "get next non-closing tab");
64 let [fiveTabsLastNotClosingLastSelected, fakeGetNextTab] = getMockBrowserTabs(
65 [new mockTab("a", false), new mockTab("b", true), new mockTab("c", true), new mockTab("d", true), new mockTab("e", false)], 4);
66 ok(fakeGetNextTab(fiveTabsLastNotClosingLastSelected._selectedTab).name == "a", "get previous non-closing tab");
67 }
68 });
70 function test() {
71 runTests();
72 }