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 createGroupItem = function (aWindow) { |
michael@0 | 6 | let cw = aWindow.TabView.getContentWindow(); |
michael@0 | 7 | let bounds = new cw.Rect(20, 20, 400, 200); |
michael@0 | 8 | let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true}); |
michael@0 | 9 | cw.UI.setActive(groupItem); |
michael@0 | 10 | |
michael@0 | 11 | let groupItemId = groupItem.id; |
michael@0 | 12 | registerCleanupFunction(function() { |
michael@0 | 13 | let groupItem = cw.GroupItems.groupItem(groupItemId); |
michael@0 | 14 | if (groupItem) |
michael@0 | 15 | groupItem.close(); |
michael@0 | 16 | }); |
michael@0 | 17 | |
michael@0 | 18 | for (let i=0; i<3; i++) |
michael@0 | 19 | aWindow.gBrowser.addTab('about:blank'); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | let assertTabViewIsHidden = function (aWindow, prefix) { |
michael@0 | 23 | ok(!aWindow.TabView.isVisible(), prefix + ': tabview is hidden'); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | let assertNumberOfTabs = function (aWindow, prefix, num) { |
michael@0 | 27 | is(aWindow.gBrowser.tabs.length, num, prefix + ': there are ' + num + ' tabs'); |
michael@0 | 28 | } |
michael@0 | 29 | |
michael@0 | 30 | let assertNumberOfPinnedTabs = function (aWindow, prefix, num) { |
michael@0 | 31 | is(aWindow.gBrowser._numPinnedTabs, num, prefix + ': there are ' + num + ' pinned tabs'); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | let assertNumberOfGroups = function (aCW, prefix, num) { |
michael@0 | 35 | is(aCW.GroupItems.groupItems.length, num, prefix + ': there are ' + num + ' groups'); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | let assertOneTabInGroup = function (prefix, groupItem) { |
michael@0 | 39 | is(groupItem.getChildren().length, 1, prefix + ': group contains one tab'); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | let assertValidPrerequisites = function (aWindow, prefix) { |
michael@0 | 43 | assertNumberOfTabs(aWindow, prefix, 1); |
michael@0 | 44 | assertNumberOfPinnedTabs(aWindow, prefix, 0); |
michael@0 | 45 | assertTabViewIsHidden(aWindow, prefix); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | let assertValidSetup = function (aWindow, prefix) { |
michael@0 | 49 | let cw = aWindow.TabView.getContentWindow(); |
michael@0 | 50 | assertNumberOfGroups(cw, prefix, 2); |
michael@0 | 51 | assertNumberOfTabs(aWindow, prefix, 4); |
michael@0 | 52 | assertNumberOfPinnedTabs(aWindow, prefix, 2); |
michael@0 | 53 | |
michael@0 | 54 | let [group1, group2] = cw.GroupItems.groupItems; |
michael@0 | 55 | assertOneTabInGroup(prefix, group1); |
michael@0 | 56 | assertOneTabInGroup(prefix, group2); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | let testStateAfterEnteringPB = function (aWindow, aCallback) { |
michael@0 | 60 | let prefix = 'window is private'; |
michael@0 | 61 | ok(PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix); |
michael@0 | 62 | |
michael@0 | 63 | assertTabViewIsHidden(aWindow, prefix); |
michael@0 | 64 | |
michael@0 | 65 | showTabView(function () { |
michael@0 | 66 | let cw = aWindow.TabView.getContentWindow(); |
michael@0 | 67 | |
michael@0 | 68 | assertNumberOfGroups(cw, prefix, 1); |
michael@0 | 69 | assertNumberOfTabs(aWindow, prefix, 1); |
michael@0 | 70 | assertOneTabInGroup(prefix, cw.GroupItems.groupItems[0]); |
michael@0 | 71 | aCallback(); |
michael@0 | 72 | }, aWindow); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | let testStateAfterLeavingPB = function (aWindow) { |
michael@0 | 76 | let prefix = 'window is not private'; |
michael@0 | 77 | ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix); |
michael@0 | 78 | |
michael@0 | 79 | assertTabViewIsHidden(aWindow, prefix); |
michael@0 | 80 | |
michael@0 | 81 | showTabView(function () { |
michael@0 | 82 | assertValidSetup(aWindow, prefix); |
michael@0 | 83 | finishTest(aWindow); |
michael@0 | 84 | }, aWindow); |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | let finishTest = function (aWindow) { |
michael@0 | 88 | let cw = aWindow.TabView.getContentWindow(); |
michael@0 | 89 | |
michael@0 | 90 | // Remove pinned tabs |
michael@0 | 91 | aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[0]); |
michael@0 | 92 | aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[0]); |
michael@0 | 93 | |
michael@0 | 94 | cw.GroupItems.groupItems[1].closeAll(); |
michael@0 | 95 | |
michael@0 | 96 | hideTabView(function () { |
michael@0 | 97 | assertValidPrerequisites(aWindow, 'exit'); |
michael@0 | 98 | assertNumberOfGroups(cw, 'exit', 1); |
michael@0 | 99 | aWindow.close(); |
michael@0 | 100 | finish(); |
michael@0 | 101 | }, aWindow); |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | let testOnWindow = function(aIsPrivate, aCallback) { |
michael@0 | 105 | let win = OpenBrowserWindow({private: aIsPrivate}); |
michael@0 | 106 | win.addEventListener("load", function onLoad() { |
michael@0 | 107 | win.removeEventListener("load", onLoad, false); |
michael@0 | 108 | executeSoon(function() { aCallback(win) }); |
michael@0 | 109 | }, false); |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | waitForExplicitFinish(); |
michael@0 | 113 | testOnWindow(false, function(publicWindow) { |
michael@0 | 114 | registerCleanupFunction(function () publicWindow.TabView.hide()); |
michael@0 | 115 | assertValidPrerequisites(publicWindow, 'start'); |
michael@0 | 116 | |
michael@0 | 117 | showTabView(function () { |
michael@0 | 118 | let cw = publicWindow.TabView.getContentWindow(); |
michael@0 | 119 | assertNumberOfGroups(cw, 'start', 1); |
michael@0 | 120 | createGroupItem(publicWindow); |
michael@0 | 121 | |
michael@0 | 122 | afterAllTabsLoaded(function () { |
michael@0 | 123 | // Setup |
michael@0 | 124 | let groupItems = cw.GroupItems.groupItems; |
michael@0 | 125 | let [tabItem1, tabItem2, ] = groupItems[1].getChildren(); |
michael@0 | 126 | publicWindow.gBrowser.pinTab(tabItem1.tab); |
michael@0 | 127 | publicWindow.gBrowser.pinTab(tabItem2.tab); |
michael@0 | 128 | |
michael@0 | 129 | assertValidSetup(publicWindow, 'setup'); |
michael@0 | 130 | hideTabView(function() { |
michael@0 | 131 | testOnWindow(true, function(privateWindow) { |
michael@0 | 132 | testStateAfterEnteringPB(privateWindow, function() { |
michael@0 | 133 | privateWindow.close(); |
michael@0 | 134 | hideTabView(function() { |
michael@0 | 135 | testStateAfterLeavingPB(publicWindow); |
michael@0 | 136 | }, publicWindow); |
michael@0 | 137 | }); |
michael@0 | 138 | }); |
michael@0 | 139 | }, publicWindow); |
michael@0 | 140 | }); |
michael@0 | 141 | }, publicWindow); |
michael@0 | 142 | }); |
michael@0 | 143 | } |