1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_privatebrowsing_perwindowpb.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,167 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +let normalURLs = []; 1.8 +let pbTabURL = "about:privatebrowsing"; 1.9 +let groupTitles = []; 1.10 +let normalIteration = 0; 1.11 + 1.12 +function test() { 1.13 + waitForExplicitFinish(); 1.14 + 1.15 + testOnWindow(false, function(win) { 1.16 + showTabView(function() { 1.17 + onTabViewLoadedAndShown(win); 1.18 + }, win); 1.19 + }); 1.20 +} 1.21 + 1.22 +function testOnWindow(aIsPrivate, aCallback) { 1.23 + let win = OpenBrowserWindow({private: aIsPrivate}); 1.24 + win.addEventListener("load", function onLoad() { 1.25 + win.removeEventListener("load", onLoad, false); 1.26 + executeSoon(function() { aCallback(win); }); 1.27 + }, false); 1.28 +} 1.29 + 1.30 +function onTabViewLoadedAndShown(aWindow) { 1.31 + ok(aWindow.TabView.isVisible(), "Tab View is visible"); 1.32 + 1.33 + // Establish initial state 1.34 + let contentWindow = aWindow.TabView.getContentWindow(); 1.35 + verifyCleanState(aWindow, "start", contentWindow); 1.36 + 1.37 + // create a group 1.38 + let box = new contentWindow.Rect(20, 20, 180, 180); 1.39 + let groupItem = new contentWindow.GroupItem([], {bounds: box, title: "test1"}); 1.40 + let id = groupItem.id; 1.41 + is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups"); 1.42 + registerCleanupFunction(function() { 1.43 + contentWindow.GroupItems.groupItem(id).close(); 1.44 + }); 1.45 + 1.46 + // make it the active group so new tabs will be added to it 1.47 + contentWindow.UI.setActive(groupItem); 1.48 + 1.49 + // collect the group titles 1.50 + let count = contentWindow.GroupItems.groupItems.length; 1.51 + for (let a = 0; a < count; a++) { 1.52 + let gi = contentWindow.GroupItems.groupItems[a]; 1.53 + groupTitles[a] = gi.getTitle(); 1.54 + } 1.55 + 1.56 + contentWindow.gPrefBranch.setBoolPref("animate_zoom", false); 1.57 + 1.58 + // Create a second tab 1.59 + aWindow.gBrowser.addTab("about:mozilla"); 1.60 + is(aWindow.gBrowser.tabs.length, 2, "we now have 2 tabs"); 1.61 + 1.62 + registerCleanupFunction(function() { 1.63 + aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]); 1.64 + contentWindow.gPrefBranch.clearUserPref("animate_zoom"); 1.65 + }); 1.66 + 1.67 + afterAllTabsLoaded(function() { 1.68 + // Get normal tab urls 1.69 + for (let a = 0; a < aWindow.gBrowser.tabs.length; a++) 1.70 + normalURLs.push(aWindow.gBrowser.tabs[a].linkedBrowser.currentURI.spec); 1.71 + 1.72 + // verify that we're all set up for our test 1.73 + verifyNormal(aWindow); 1.74 + 1.75 + // Open private window and make sure Tab View becomes hidden 1.76 + testOnWindow(true, function(privateWin) { 1.77 + whenTabViewIsHidden(function() { 1.78 + ok(!privateWin.TabView.isVisible(), "Tab View is no longer visible"); 1.79 + verifyPB(privateWin); 1.80 + // Close private window 1.81 + privateWin.close(); 1.82 + // Get back to normal window, make sure Tab View is shown again 1.83 + whenTabViewIsShown(function() { 1.84 + ok(aWindow.TabView.isVisible(), "Tab View is visible again"); 1.85 + verifyNormal(aWindow); 1.86 + 1.87 + hideTabView(function() { 1.88 + onTabViewHidden(aWindow, contentWindow); 1.89 + }, aWindow); 1.90 + }, aWindow); 1.91 + }, privateWin); 1.92 + }); 1.93 + }, aWindow); 1.94 +} 1.95 + 1.96 +function onTabViewHidden(aWindow, aContentWindow) { 1.97 + ok(!aWindow.TabView.isVisible(), "Tab View is not visible"); 1.98 + 1.99 + // Open private window and make sure Tab View is hidden 1.100 + testOnWindow(true, function(privateWin) { 1.101 + ok(!privateWin.TabView.isVisible(), "Tab View is still not visible"); 1.102 + verifyPB(privateWin); 1.103 + // Close private window 1.104 + privateWin.close(); 1.105 + 1.106 + // Get back to normal window 1.107 + verifyNormal(aWindow); 1.108 + 1.109 + // end game 1.110 + ok(!aWindow.TabView.isVisible(), "we finish with Tab View not visible"); 1.111 + 1.112 + // verify after all cleanups 1.113 + registerCleanupFunction(function() { 1.114 + verifyCleanState(aWindow, "finish", aContentWindow); 1.115 + aWindow.close(); 1.116 + }); 1.117 + 1.118 + finish(); 1.119 + }); 1.120 +} 1.121 + 1.122 +function verifyCleanState(aWindow, aMode, aContentWindow) { 1.123 + let prefix = "we " + aMode + " with "; 1.124 + is(aWindow.gBrowser.tabs.length, 1, prefix + "one tab"); 1.125 + is(aContentWindow.GroupItems.groupItems.length, 1, prefix + "1 group"); 1.126 + ok(aWindow.gBrowser.tabs[0]._tabViewTabItem.parent == aContentWindow.GroupItems.groupItems[0], 1.127 + "the tab is in the group"); 1.128 + ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix + "private browsing off"); 1.129 +} 1.130 + 1.131 +function verifyPB(aWindow) { 1.132 + showTabView(function() { 1.133 + let cw = aWindow.TabView.getContentWindow(); 1.134 + ok(PrivateBrowsingUtils.isWindowPrivate(aWindow), "window is private"); 1.135 + is(aWindow.gBrowser.tabs.length, 1, "we have 1 tab in private window"); 1.136 + is(cw.GroupItems.groupItems.length, 1, "we have 1 group in private window"); 1.137 + ok(aWindow.gBrowser.tabs[0]._tabViewTabItem.parent == cw.GroupItems.groupItems[0], 1.138 + "the tab is in the group"); 1.139 + let browser = aWindow.gBrowser.tabs[0].linkedBrowser; 1.140 + browser.addEventListener("load", function onLoad() { 1.141 + browser.removeEventListener("load", onLoad, true); 1.142 + is(browser.currentURI.spec, pbTabURL, "correct URL for private browsing"); 1.143 + }, true); 1.144 + }, aWindow); 1.145 +} 1.146 + 1.147 +function verifyNormal(aWindow) { 1.148 + let contentWindow = aWindow.TabView.getContentWindow(); 1.149 + let prefix = "verify normal " + normalIteration + ": "; 1.150 + normalIteration++; 1.151 + 1.152 + ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix + "private browsing off"); 1.153 + 1.154 + let tabCount = aWindow.gBrowser.tabs.length; 1.155 + let groupCount = contentWindow.GroupItems.groupItems.length; 1.156 + is(tabCount, 2, prefix + "we have 2 tabs"); 1.157 + is(groupCount, 2, prefix + "we have 2 groups"); 1.158 + ok(tabCount == groupCount, prefix + "same number of tabs as groups"); 1.159 + for (let a = 0; a < tabCount; a++) { 1.160 + let tab = aWindow.gBrowser.tabs[a]; 1.161 + is(tab.linkedBrowser.currentURI.spec, normalURLs[a], 1.162 + prefix + "correct URL"); 1.163 + 1.164 + let groupItem = contentWindow.GroupItems.groupItems[a]; 1.165 + is(groupItem.getTitle(), groupTitles[a], prefix + "correct group title"); 1.166 + 1.167 + ok(tab._tabViewTabItem.parent == groupItem, 1.168 + prefix + "tab " + a + " is in group " + a); 1.169 + } 1.170 +}