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.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | function test() { |
michael@0 | 5 | let tests = []; |
michael@0 | 6 | |
michael@0 | 7 | let getContentWindow = function (aWindow) { |
michael@0 | 8 | return aWindow.TabView.getContentWindow(); |
michael@0 | 9 | } |
michael@0 | 10 | |
michael@0 | 11 | let assertOneSingleGroupItem = function (aWindow) { |
michael@0 | 12 | is(getContentWindow(aWindow).GroupItems.groupItems.length, 1, 'There is one single groupItem'); |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | let assertNumberOfVisibleTabs = function (aWindow, numTabs) { |
michael@0 | 16 | is(aWindow.gBrowser.visibleTabs.length, numTabs, 'There should be ' + numTabs + ' visible tabs'); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | let next = function (aWindow) { |
michael@0 | 20 | while (aWindow.gBrowser.tabs.length-1) |
michael@0 | 21 | aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]); |
michael@0 | 22 | |
michael@0 | 23 | hideTabView(function() { |
michael@0 | 24 | let callback = tests.shift(); |
michael@0 | 25 | |
michael@0 | 26 | if (!callback) { |
michael@0 | 27 | executeSoon(function() { |
michael@0 | 28 | assertOneSingleGroupItem(aWindow); |
michael@0 | 29 | aWindow.close(); |
michael@0 | 30 | finish(); |
michael@0 | 31 | }); |
michael@0 | 32 | } else { |
michael@0 | 33 | assertOneSingleGroupItem(aWindow); |
michael@0 | 34 | callback(aWindow); |
michael@0 | 35 | } |
michael@0 | 36 | }, aWindow); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | // [624265] testing undo close tab |
michael@0 | 40 | let testUndoCloseTabs = function (aWindow) { |
michael@0 | 41 | aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true}); |
michael@0 | 42 | aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true}); |
michael@0 | 43 | |
michael@0 | 44 | afterAllTabsLoaded(function () { |
michael@0 | 45 | assertNumberOfVisibleTabs(aWindow, 3); |
michael@0 | 46 | |
michael@0 | 47 | aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]); |
michael@0 | 48 | aWindow.gBrowser.selectedTab = aWindow.gBrowser.tabs[1]; |
michael@0 | 49 | |
michael@0 | 50 | restoreTab(function () { |
michael@0 | 51 | assertNumberOfVisibleTabs(aWindow, 3); |
michael@0 | 52 | assertOneSingleGroupItem(aWindow); |
michael@0 | 53 | next(aWindow); |
michael@0 | 54 | }, 0, aWindow); |
michael@0 | 55 | }, aWindow); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | // [623792] duplicating tab via middle click on reload button |
michael@0 | 59 | let testDuplicateTab = function (aWindow) { |
michael@0 | 60 | aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true}); |
michael@0 | 61 | |
michael@0 | 62 | afterAllTabsLoaded(function () { |
michael@0 | 63 | // Valid choices for 'where' are window|tabshifted|tab |
michael@0 | 64 | aWindow.duplicateTabIn(aWindow.gBrowser.selectedTab, 'tab'); |
michael@0 | 65 | |
michael@0 | 66 | afterAllTabsLoaded(function () { |
michael@0 | 67 | assertNumberOfVisibleTabs(aWindow, 3); |
michael@0 | 68 | assertOneSingleGroupItem(aWindow); |
michael@0 | 69 | next(aWindow); |
michael@0 | 70 | }, aWindow); |
michael@0 | 71 | }, aWindow); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | // [623792] duplicating tabs via middle click on forward/back buttons |
michael@0 | 75 | let testBackForwardDuplicateTab = function (aWindow) { |
michael@0 | 76 | let tab = aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#1', {inBackground: true}); |
michael@0 | 77 | aWindow.gBrowser.selectedTab = tab; |
michael@0 | 78 | |
michael@0 | 79 | afterAllTabsLoaded(function () { |
michael@0 | 80 | tab.linkedBrowser.loadURI('http://mochi.test:8888/#2'); |
michael@0 | 81 | |
michael@0 | 82 | afterAllTabsLoaded(function () { |
michael@0 | 83 | ok(aWindow.gBrowser.canGoBack, 'browser can go back in history'); |
michael@0 | 84 | aWindow.BrowserBack({button: 1}); |
michael@0 | 85 | |
michael@0 | 86 | afterAllTabsLoaded(function () { |
michael@0 | 87 | assertNumberOfVisibleTabs(aWindow, 3); |
michael@0 | 88 | |
michael@0 | 89 | ok(aWindow.gBrowser.canGoForward, 'browser can go forward in history'); |
michael@0 | 90 | aWindow.BrowserForward({button: 1}); |
michael@0 | 91 | |
michael@0 | 92 | afterAllTabsLoaded(function () { |
michael@0 | 93 | assertNumberOfVisibleTabs(aWindow, 4); |
michael@0 | 94 | assertOneSingleGroupItem(aWindow); |
michael@0 | 95 | next(aWindow); |
michael@0 | 96 | }, aWindow); |
michael@0 | 97 | }, aWindow); |
michael@0 | 98 | }, aWindow); |
michael@0 | 99 | }, aWindow); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | // [624102] check state after return from private browsing |
michael@0 | 103 | let testPrivateBrowsing = function (aWindow) { |
michael@0 | 104 | aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#1', {inBackground: true}); |
michael@0 | 105 | aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#2', {inBackground: true}); |
michael@0 | 106 | |
michael@0 | 107 | let cw = getContentWindow(aWindow); |
michael@0 | 108 | let box = new cw.Rect(20, 20, 250, 200); |
michael@0 | 109 | let groupItem = new cw.GroupItem([], {bounds: box, immediately: true}); |
michael@0 | 110 | cw.UI.setActive(groupItem); |
michael@0 | 111 | |
michael@0 | 112 | aWindow.gBrowser.selectedTab = aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#3', {inBackground: true}); |
michael@0 | 113 | aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#4', {inBackground: true}); |
michael@0 | 114 | |
michael@0 | 115 | afterAllTabsLoaded(function () { |
michael@0 | 116 | assertNumberOfVisibleTabs(aWindow, 2); |
michael@0 | 117 | |
michael@0 | 118 | enterAndLeavePrivateBrowsing(function () { |
michael@0 | 119 | assertNumberOfVisibleTabs(aWindow, 2); |
michael@0 | 120 | aWindow.gBrowser.selectedTab = aWindow.gBrowser.tabs[0]; |
michael@0 | 121 | closeGroupItem(cw.GroupItems.groupItems[1], function() { |
michael@0 | 122 | next(aWindow); |
michael@0 | 123 | }); |
michael@0 | 124 | }); |
michael@0 | 125 | }, aWindow); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | function testOnWindow(aIsPrivate, aCallback) { |
michael@0 | 129 | let win = OpenBrowserWindow({private: aIsPrivate}); |
michael@0 | 130 | win.addEventListener("load", function onLoad() { |
michael@0 | 131 | win.removeEventListener("load", onLoad, false); |
michael@0 | 132 | executeSoon(function() { aCallback(win) }); |
michael@0 | 133 | }, false); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | function enterAndLeavePrivateBrowsing(callback) { |
michael@0 | 137 | testOnWindow(true, function (aWindow) { |
michael@0 | 138 | aWindow.close(); |
michael@0 | 139 | callback(); |
michael@0 | 140 | }); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | waitForExplicitFinish(); |
michael@0 | 144 | |
michael@0 | 145 | // Tests for #624265 |
michael@0 | 146 | tests.push(testUndoCloseTabs); |
michael@0 | 147 | |
michael@0 | 148 | // Tests for #623792 |
michael@0 | 149 | tests.push(testDuplicateTab); |
michael@0 | 150 | tests.push(testBackForwardDuplicateTab); |
michael@0 | 151 | |
michael@0 | 152 | // Tests for #624102 |
michael@0 | 153 | tests.push(testPrivateBrowsing); |
michael@0 | 154 | |
michael@0 | 155 | testOnWindow(false, function(aWindow) { |
michael@0 | 156 | loadTabView(function() { |
michael@0 | 157 | next(aWindow); |
michael@0 | 158 | }, aWindow); |
michael@0 | 159 | }); |
michael@0 | 160 | } |
michael@0 | 161 | |
michael@0 | 162 | function loadTabView(callback, aWindow) { |
michael@0 | 163 | showTabView(function () { |
michael@0 | 164 | hideTabView(callback, aWindow); |
michael@0 | 165 | }, aWindow); |
michael@0 | 166 | } |