1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug624265_perwindowpb.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,166 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +function test() { 1.8 + let tests = []; 1.9 + 1.10 + let getContentWindow = function (aWindow) { 1.11 + return aWindow.TabView.getContentWindow(); 1.12 + } 1.13 + 1.14 + let assertOneSingleGroupItem = function (aWindow) { 1.15 + is(getContentWindow(aWindow).GroupItems.groupItems.length, 1, 'There is one single groupItem'); 1.16 + } 1.17 + 1.18 + let assertNumberOfVisibleTabs = function (aWindow, numTabs) { 1.19 + is(aWindow.gBrowser.visibleTabs.length, numTabs, 'There should be ' + numTabs + ' visible tabs'); 1.20 + } 1.21 + 1.22 + let next = function (aWindow) { 1.23 + while (aWindow.gBrowser.tabs.length-1) 1.24 + aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]); 1.25 + 1.26 + hideTabView(function() { 1.27 + let callback = tests.shift(); 1.28 + 1.29 + if (!callback) { 1.30 + executeSoon(function() { 1.31 + assertOneSingleGroupItem(aWindow); 1.32 + aWindow.close(); 1.33 + finish(); 1.34 + }); 1.35 + } else { 1.36 + assertOneSingleGroupItem(aWindow); 1.37 + callback(aWindow); 1.38 + } 1.39 + }, aWindow); 1.40 + } 1.41 + 1.42 + // [624265] testing undo close tab 1.43 + let testUndoCloseTabs = function (aWindow) { 1.44 + aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true}); 1.45 + aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true}); 1.46 + 1.47 + afterAllTabsLoaded(function () { 1.48 + assertNumberOfVisibleTabs(aWindow, 3); 1.49 + 1.50 + aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]); 1.51 + aWindow.gBrowser.selectedTab = aWindow.gBrowser.tabs[1]; 1.52 + 1.53 + restoreTab(function () { 1.54 + assertNumberOfVisibleTabs(aWindow, 3); 1.55 + assertOneSingleGroupItem(aWindow); 1.56 + next(aWindow); 1.57 + }, 0, aWindow); 1.58 + }, aWindow); 1.59 + } 1.60 + 1.61 + // [623792] duplicating tab via middle click on reload button 1.62 + let testDuplicateTab = function (aWindow) { 1.63 + aWindow.gBrowser.loadOneTab('http://mochi.test:8888/', {inBackground: true}); 1.64 + 1.65 + afterAllTabsLoaded(function () { 1.66 + // Valid choices for 'where' are window|tabshifted|tab 1.67 + aWindow.duplicateTabIn(aWindow.gBrowser.selectedTab, 'tab'); 1.68 + 1.69 + afterAllTabsLoaded(function () { 1.70 + assertNumberOfVisibleTabs(aWindow, 3); 1.71 + assertOneSingleGroupItem(aWindow); 1.72 + next(aWindow); 1.73 + }, aWindow); 1.74 + }, aWindow); 1.75 + } 1.76 + 1.77 + // [623792] duplicating tabs via middle click on forward/back buttons 1.78 + let testBackForwardDuplicateTab = function (aWindow) { 1.79 + let tab = aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#1', {inBackground: true}); 1.80 + aWindow.gBrowser.selectedTab = tab; 1.81 + 1.82 + afterAllTabsLoaded(function () { 1.83 + tab.linkedBrowser.loadURI('http://mochi.test:8888/#2'); 1.84 + 1.85 + afterAllTabsLoaded(function () { 1.86 + ok(aWindow.gBrowser.canGoBack, 'browser can go back in history'); 1.87 + aWindow.BrowserBack({button: 1}); 1.88 + 1.89 + afterAllTabsLoaded(function () { 1.90 + assertNumberOfVisibleTabs(aWindow, 3); 1.91 + 1.92 + ok(aWindow.gBrowser.canGoForward, 'browser can go forward in history'); 1.93 + aWindow.BrowserForward({button: 1}); 1.94 + 1.95 + afterAllTabsLoaded(function () { 1.96 + assertNumberOfVisibleTabs(aWindow, 4); 1.97 + assertOneSingleGroupItem(aWindow); 1.98 + next(aWindow); 1.99 + }, aWindow); 1.100 + }, aWindow); 1.101 + }, aWindow); 1.102 + }, aWindow); 1.103 + } 1.104 + 1.105 + // [624102] check state after return from private browsing 1.106 + let testPrivateBrowsing = function (aWindow) { 1.107 + aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#1', {inBackground: true}); 1.108 + aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#2', {inBackground: true}); 1.109 + 1.110 + let cw = getContentWindow(aWindow); 1.111 + let box = new cw.Rect(20, 20, 250, 200); 1.112 + let groupItem = new cw.GroupItem([], {bounds: box, immediately: true}); 1.113 + cw.UI.setActive(groupItem); 1.114 + 1.115 + aWindow.gBrowser.selectedTab = aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#3', {inBackground: true}); 1.116 + aWindow.gBrowser.loadOneTab('http://mochi.test:8888/#4', {inBackground: true}); 1.117 + 1.118 + afterAllTabsLoaded(function () { 1.119 + assertNumberOfVisibleTabs(aWindow, 2); 1.120 + 1.121 + enterAndLeavePrivateBrowsing(function () { 1.122 + assertNumberOfVisibleTabs(aWindow, 2); 1.123 + aWindow.gBrowser.selectedTab = aWindow.gBrowser.tabs[0]; 1.124 + closeGroupItem(cw.GroupItems.groupItems[1], function() { 1.125 + next(aWindow); 1.126 + }); 1.127 + }); 1.128 + }, aWindow); 1.129 + } 1.130 + 1.131 + function testOnWindow(aIsPrivate, aCallback) { 1.132 + let win = OpenBrowserWindow({private: aIsPrivate}); 1.133 + win.addEventListener("load", function onLoad() { 1.134 + win.removeEventListener("load", onLoad, false); 1.135 + executeSoon(function() { aCallback(win) }); 1.136 + }, false); 1.137 + } 1.138 + 1.139 + function enterAndLeavePrivateBrowsing(callback) { 1.140 + testOnWindow(true, function (aWindow) { 1.141 + aWindow.close(); 1.142 + callback(); 1.143 + }); 1.144 + } 1.145 + 1.146 + waitForExplicitFinish(); 1.147 + 1.148 + // Tests for #624265 1.149 + tests.push(testUndoCloseTabs); 1.150 + 1.151 + // Tests for #623792 1.152 + tests.push(testDuplicateTab); 1.153 + tests.push(testBackForwardDuplicateTab); 1.154 + 1.155 + // Tests for #624102 1.156 + tests.push(testPrivateBrowsing); 1.157 + 1.158 + testOnWindow(false, function(aWindow) { 1.159 + loadTabView(function() { 1.160 + next(aWindow); 1.161 + }, aWindow); 1.162 + }); 1.163 +} 1.164 + 1.165 +function loadTabView(callback, aWindow) { 1.166 + showTabView(function () { 1.167 + hideTabView(callback, aWindow); 1.168 + }, aWindow); 1.169 +} 1.170 \ No newline at end of file