michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let normalURLs = []; michael@0: let pbTabURL = "about:privatebrowsing"; michael@0: let groupTitles = []; michael@0: let normalIteration = 0; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: testOnWindow(false, function(win) { michael@0: showTabView(function() { michael@0: onTabViewLoadedAndShown(win); michael@0: }, win); michael@0: }); michael@0: } michael@0: michael@0: function testOnWindow(aIsPrivate, aCallback) { michael@0: let win = OpenBrowserWindow({private: aIsPrivate}); michael@0: win.addEventListener("load", function onLoad() { michael@0: win.removeEventListener("load", onLoad, false); michael@0: executeSoon(function() { aCallback(win); }); michael@0: }, false); michael@0: } michael@0: michael@0: function onTabViewLoadedAndShown(aWindow) { michael@0: ok(aWindow.TabView.isVisible(), "Tab View is visible"); michael@0: michael@0: // Establish initial state michael@0: let contentWindow = aWindow.TabView.getContentWindow(); michael@0: verifyCleanState(aWindow, "start", contentWindow); michael@0: michael@0: // create a group michael@0: let box = new contentWindow.Rect(20, 20, 180, 180); michael@0: let groupItem = new contentWindow.GroupItem([], {bounds: box, title: "test1"}); michael@0: let id = groupItem.id; michael@0: is(contentWindow.GroupItems.groupItems.length, 2, "we now have two groups"); michael@0: registerCleanupFunction(function() { michael@0: contentWindow.GroupItems.groupItem(id).close(); michael@0: }); michael@0: michael@0: // make it the active group so new tabs will be added to it michael@0: contentWindow.UI.setActive(groupItem); michael@0: michael@0: // collect the group titles michael@0: let count = contentWindow.GroupItems.groupItems.length; michael@0: for (let a = 0; a < count; a++) { michael@0: let gi = contentWindow.GroupItems.groupItems[a]; michael@0: groupTitles[a] = gi.getTitle(); michael@0: } michael@0: michael@0: contentWindow.gPrefBranch.setBoolPref("animate_zoom", false); michael@0: michael@0: // Create a second tab michael@0: aWindow.gBrowser.addTab("about:mozilla"); michael@0: is(aWindow.gBrowser.tabs.length, 2, "we now have 2 tabs"); michael@0: michael@0: registerCleanupFunction(function() { michael@0: aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[1]); michael@0: contentWindow.gPrefBranch.clearUserPref("animate_zoom"); michael@0: }); michael@0: michael@0: afterAllTabsLoaded(function() { michael@0: // Get normal tab urls michael@0: for (let a = 0; a < aWindow.gBrowser.tabs.length; a++) michael@0: normalURLs.push(aWindow.gBrowser.tabs[a].linkedBrowser.currentURI.spec); michael@0: michael@0: // verify that we're all set up for our test michael@0: verifyNormal(aWindow); michael@0: michael@0: // Open private window and make sure Tab View becomes hidden michael@0: testOnWindow(true, function(privateWin) { michael@0: whenTabViewIsHidden(function() { michael@0: ok(!privateWin.TabView.isVisible(), "Tab View is no longer visible"); michael@0: verifyPB(privateWin); michael@0: // Close private window michael@0: privateWin.close(); michael@0: // Get back to normal window, make sure Tab View is shown again michael@0: whenTabViewIsShown(function() { michael@0: ok(aWindow.TabView.isVisible(), "Tab View is visible again"); michael@0: verifyNormal(aWindow); michael@0: michael@0: hideTabView(function() { michael@0: onTabViewHidden(aWindow, contentWindow); michael@0: }, aWindow); michael@0: }, aWindow); michael@0: }, privateWin); michael@0: }); michael@0: }, aWindow); michael@0: } michael@0: michael@0: function onTabViewHidden(aWindow, aContentWindow) { michael@0: ok(!aWindow.TabView.isVisible(), "Tab View is not visible"); michael@0: michael@0: // Open private window and make sure Tab View is hidden michael@0: testOnWindow(true, function(privateWin) { michael@0: ok(!privateWin.TabView.isVisible(), "Tab View is still not visible"); michael@0: verifyPB(privateWin); michael@0: // Close private window michael@0: privateWin.close(); michael@0: michael@0: // Get back to normal window michael@0: verifyNormal(aWindow); michael@0: michael@0: // end game michael@0: ok(!aWindow.TabView.isVisible(), "we finish with Tab View not visible"); michael@0: michael@0: // verify after all cleanups michael@0: registerCleanupFunction(function() { michael@0: verifyCleanState(aWindow, "finish", aContentWindow); michael@0: aWindow.close(); michael@0: }); michael@0: michael@0: finish(); michael@0: }); michael@0: } michael@0: michael@0: function verifyCleanState(aWindow, aMode, aContentWindow) { michael@0: let prefix = "we " + aMode + " with "; michael@0: is(aWindow.gBrowser.tabs.length, 1, prefix + "one tab"); michael@0: is(aContentWindow.GroupItems.groupItems.length, 1, prefix + "1 group"); michael@0: ok(aWindow.gBrowser.tabs[0]._tabViewTabItem.parent == aContentWindow.GroupItems.groupItems[0], michael@0: "the tab is in the group"); michael@0: ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix + "private browsing off"); michael@0: } michael@0: michael@0: function verifyPB(aWindow) { michael@0: showTabView(function() { michael@0: let cw = aWindow.TabView.getContentWindow(); michael@0: ok(PrivateBrowsingUtils.isWindowPrivate(aWindow), "window is private"); michael@0: is(aWindow.gBrowser.tabs.length, 1, "we have 1 tab in private window"); michael@0: is(cw.GroupItems.groupItems.length, 1, "we have 1 group in private window"); michael@0: ok(aWindow.gBrowser.tabs[0]._tabViewTabItem.parent == cw.GroupItems.groupItems[0], michael@0: "the tab is in the group"); michael@0: let browser = aWindow.gBrowser.tabs[0].linkedBrowser; michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: is(browser.currentURI.spec, pbTabURL, "correct URL for private browsing"); michael@0: }, true); michael@0: }, aWindow); michael@0: } michael@0: michael@0: function verifyNormal(aWindow) { michael@0: let contentWindow = aWindow.TabView.getContentWindow(); michael@0: let prefix = "verify normal " + normalIteration + ": "; michael@0: normalIteration++; michael@0: michael@0: ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix + "private browsing off"); michael@0: michael@0: let tabCount = aWindow.gBrowser.tabs.length; michael@0: let groupCount = contentWindow.GroupItems.groupItems.length; michael@0: is(tabCount, 2, prefix + "we have 2 tabs"); michael@0: is(groupCount, 2, prefix + "we have 2 groups"); michael@0: ok(tabCount == groupCount, prefix + "same number of tabs as groups"); michael@0: for (let a = 0; a < tabCount; a++) { michael@0: let tab = aWindow.gBrowser.tabs[a]; michael@0: is(tab.linkedBrowser.currentURI.spec, normalURLs[a], michael@0: prefix + "correct URL"); michael@0: michael@0: let groupItem = contentWindow.GroupItems.groupItems[a]; michael@0: is(groupItem.getTitle(), groupTitles[a], prefix + "correct group title"); michael@0: michael@0: ok(tab._tabViewTabItem.parent == groupItem, michael@0: prefix + "tab " + a + " is in group " + a); michael@0: } michael@0: }