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 | let normalURLs = []; |
michael@0 | 5 | let pbTabURL = "about:privatebrowsing"; |
michael@0 | 6 | let groupTitles = []; |
michael@0 | 7 | let normalIteration = 0; |
michael@0 | 8 | |
michael@0 | 9 | function test() { |
michael@0 | 10 | waitForExplicitFinish(); |
michael@0 | 11 | |
michael@0 | 12 | testOnWindow(false, function(win) { |
michael@0 | 13 | showTabView(function() { |
michael@0 | 14 | onTabViewLoadedAndShown(win); |
michael@0 | 15 | }, win); |
michael@0 | 16 | }); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function testOnWindow(aIsPrivate, aCallback) { |
michael@0 | 20 | let win = OpenBrowserWindow({private: aIsPrivate}); |
michael@0 | 21 | win.addEventListener("load", function onLoad() { |
michael@0 | 22 | win.removeEventListener("load", onLoad, false); |
michael@0 | 23 | executeSoon(function() { aCallback(win); }); |
michael@0 | 24 | }, false); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | function onTabViewLoadedAndShown(aWindow) { |
michael@0 | 28 | ok(aWindow.TabView.isVisible(), "Tab View is visible"); |
michael@0 | 29 | |
michael@0 | 30 | // Establish initial state |
michael@0 | 31 | let contentWindow = aWindow.TabView.getContentWindow(); |
michael@0 | 32 | verifyCleanState(aWindow, "start", contentWindow); |
michael@0 | 33 | |
michael@0 | 34 | // create a group |
michael@0 | 35 | let box = new contentWindow.Rect(20, 20, 180, 180); |
michael@0 | 36 | let groupItem = new contentWindow.GroupItem([], {bounds: box, title: "test1"}); |
michael@0 | 37 | let id = groupItem.id; |
michael@0 | 38 | is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups"); |
michael@0 | 39 | registerCleanupFunction(function() { |
michael@0 | 40 | contentWindow.GroupItems.groupItem(id).close(); |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | // make it the active group so new tabs will be added to it |
michael@0 | 44 | contentWindow.UI.setActive(groupItem); |
michael@0 | 45 | |
michael@0 | 46 | // collect the group titles |
michael@0 | 47 | let count = contentWindow.GroupItems.groupItems.length; |
michael@0 | 48 | for (let a = 0; a < count; a++) { |
michael@0 | 49 | let gi = contentWindow.GroupItems.groupItems[a]; |
michael@0 | 50 | groupTitles[a] = gi.getTitle(); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | contentWindow.gPrefBranch.setBoolPref("animate_zoom", false); |
michael@0 | 54 | |
michael@0 | 55 | // Create a second tab |
michael@0 | 56 | aWindow.gBrowser.addTab("about:mozilla"); |
michael@0 | 57 | is(aWindow.gBrowser.tabs.length, 2, "we now have 2 tabs"); |
michael@0 | 58 | |
michael@0 | 59 | registerCleanupFunction(function() { |
michael@0 | 60 | aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]); |
michael@0 | 61 | contentWindow.gPrefBranch.clearUserPref("animate_zoom"); |
michael@0 | 62 | }); |
michael@0 | 63 | |
michael@0 | 64 | afterAllTabsLoaded(function() { |
michael@0 | 65 | // Get normal tab urls |
michael@0 | 66 | for (let a = 0; a < aWindow.gBrowser.tabs.length; a++) |
michael@0 | 67 | normalURLs.push(aWindow.gBrowser.tabs[a].linkedBrowser.currentURI.spec); |
michael@0 | 68 | |
michael@0 | 69 | // verify that we're all set up for our test |
michael@0 | 70 | verifyNormal(aWindow); |
michael@0 | 71 | |
michael@0 | 72 | // Open private window and make sure Tab View becomes hidden |
michael@0 | 73 | testOnWindow(true, function(privateWin) { |
michael@0 | 74 | whenTabViewIsHidden(function() { |
michael@0 | 75 | ok(!privateWin.TabView.isVisible(), "Tab View is no longer visible"); |
michael@0 | 76 | verifyPB(privateWin); |
michael@0 | 77 | // Close private window |
michael@0 | 78 | privateWin.close(); |
michael@0 | 79 | // Get back to normal window, make sure Tab View is shown again |
michael@0 | 80 | whenTabViewIsShown(function() { |
michael@0 | 81 | ok(aWindow.TabView.isVisible(), "Tab View is visible again"); |
michael@0 | 82 | verifyNormal(aWindow); |
michael@0 | 83 | |
michael@0 | 84 | hideTabView(function() { |
michael@0 | 85 | onTabViewHidden(aWindow, contentWindow); |
michael@0 | 86 | }, aWindow); |
michael@0 | 87 | }, aWindow); |
michael@0 | 88 | }, privateWin); |
michael@0 | 89 | }); |
michael@0 | 90 | }, aWindow); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function onTabViewHidden(aWindow, aContentWindow) { |
michael@0 | 94 | ok(!aWindow.TabView.isVisible(), "Tab View is not visible"); |
michael@0 | 95 | |
michael@0 | 96 | // Open private window and make sure Tab View is hidden |
michael@0 | 97 | testOnWindow(true, function(privateWin) { |
michael@0 | 98 | ok(!privateWin.TabView.isVisible(), "Tab View is still not visible"); |
michael@0 | 99 | verifyPB(privateWin); |
michael@0 | 100 | // Close private window |
michael@0 | 101 | privateWin.close(); |
michael@0 | 102 | |
michael@0 | 103 | // Get back to normal window |
michael@0 | 104 | verifyNormal(aWindow); |
michael@0 | 105 | |
michael@0 | 106 | // end game |
michael@0 | 107 | ok(!aWindow.TabView.isVisible(), "we finish with Tab View not visible"); |
michael@0 | 108 | |
michael@0 | 109 | // verify after all cleanups |
michael@0 | 110 | registerCleanupFunction(function() { |
michael@0 | 111 | verifyCleanState(aWindow, "finish", aContentWindow); |
michael@0 | 112 | aWindow.close(); |
michael@0 | 113 | }); |
michael@0 | 114 | |
michael@0 | 115 | finish(); |
michael@0 | 116 | }); |
michael@0 | 117 | } |
michael@0 | 118 | |
michael@0 | 119 | function verifyCleanState(aWindow, aMode, aContentWindow) { |
michael@0 | 120 | let prefix = "we " + aMode + " with "; |
michael@0 | 121 | is(aWindow.gBrowser.tabs.length, 1, prefix + "one tab"); |
michael@0 | 122 | is(aContentWindow.GroupItems.groupItems.length, 1, prefix + "1 group"); |
michael@0 | 123 | ok(aWindow.gBrowser.tabs[0]._tabViewTabItem.parent == aContentWindow.GroupItems.groupItems[0], |
michael@0 | 124 | "the tab is in the group"); |
michael@0 | 125 | ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix + "private browsing off"); |
michael@0 | 126 | } |
michael@0 | 127 | |
michael@0 | 128 | function verifyPB(aWindow) { |
michael@0 | 129 | showTabView(function() { |
michael@0 | 130 | let cw = aWindow.TabView.getContentWindow(); |
michael@0 | 131 | ok(PrivateBrowsingUtils.isWindowPrivate(aWindow), "window is private"); |
michael@0 | 132 | is(aWindow.gBrowser.tabs.length, 1, "we have 1 tab in private window"); |
michael@0 | 133 | is(cw.GroupItems.groupItems.length, 1, "we have 1 group in private window"); |
michael@0 | 134 | ok(aWindow.gBrowser.tabs[0]._tabViewTabItem.parent == cw.GroupItems.groupItems[0], |
michael@0 | 135 | "the tab is in the group"); |
michael@0 | 136 | let browser = aWindow.gBrowser.tabs[0].linkedBrowser; |
michael@0 | 137 | browser.addEventListener("load", function onLoad() { |
michael@0 | 138 | browser.removeEventListener("load", onLoad, true); |
michael@0 | 139 | is(browser.currentURI.spec, pbTabURL, "correct URL for private browsing"); |
michael@0 | 140 | }, true); |
michael@0 | 141 | }, aWindow); |
michael@0 | 142 | } |
michael@0 | 143 | |
michael@0 | 144 | function verifyNormal(aWindow) { |
michael@0 | 145 | let contentWindow = aWindow.TabView.getContentWindow(); |
michael@0 | 146 | let prefix = "verify normal " + normalIteration + ": "; |
michael@0 | 147 | normalIteration++; |
michael@0 | 148 | |
michael@0 | 149 | ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix + "private browsing off"); |
michael@0 | 150 | |
michael@0 | 151 | let tabCount = aWindow.gBrowser.tabs.length; |
michael@0 | 152 | let groupCount = contentWindow.GroupItems.groupItems.length; |
michael@0 | 153 | is(tabCount, 2, prefix + "we have 2 tabs"); |
michael@0 | 154 | is(groupCount, 2, prefix + "we have 2 groups"); |
michael@0 | 155 | ok(tabCount == groupCount, prefix + "same number of tabs as groups"); |
michael@0 | 156 | for (let a = 0; a < tabCount; a++) { |
michael@0 | 157 | let tab = aWindow.gBrowser.tabs[a]; |
michael@0 | 158 | is(tab.linkedBrowser.currentURI.spec, normalURLs[a], |
michael@0 | 159 | prefix + "correct URL"); |
michael@0 | 160 | |
michael@0 | 161 | let groupItem = contentWindow.GroupItems.groupItems[a]; |
michael@0 | 162 | is(groupItem.getTitle(), groupTitles[a], prefix + "correct group title"); |
michael@0 | 163 | |
michael@0 | 164 | ok(tab._tabViewTabItem.parent == groupItem, |
michael@0 | 165 | prefix + "tab " + a + " is in group " + a); |
michael@0 | 166 | } |
michael@0 | 167 | } |