michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: function test() { michael@0: let createGroupItem = function (aWindow) { michael@0: let cw = aWindow.TabView.getContentWindow(); michael@0: let bounds = new cw.Rect(20, 20, 400, 200); michael@0: let groupItem = new cw.GroupItem([], {bounds: bounds, immediately: true}); michael@0: cw.UI.setActive(groupItem); michael@0: michael@0: let groupItemId = groupItem.id; michael@0: registerCleanupFunction(function() { michael@0: let groupItem = cw.GroupItems.groupItem(groupItemId); michael@0: if (groupItem) michael@0: groupItem.close(); michael@0: }); michael@0: michael@0: for (let i=0; i<3; i++) michael@0: aWindow.gBrowser.addTab('about:blank'); michael@0: } michael@0: michael@0: let assertTabViewIsHidden = function (aWindow, prefix) { michael@0: ok(!aWindow.TabView.isVisible(), prefix + ': tabview is hidden'); michael@0: } michael@0: michael@0: let assertNumberOfTabs = function (aWindow, prefix, num) { michael@0: is(aWindow.gBrowser.tabs.length, num, prefix + ': there are ' + num + ' tabs'); michael@0: } michael@0: michael@0: let assertNumberOfPinnedTabs = function (aWindow, prefix, num) { michael@0: is(aWindow.gBrowser._numPinnedTabs, num, prefix + ': there are ' + num + ' pinned tabs'); michael@0: } michael@0: michael@0: let assertNumberOfGroups = function (aCW, prefix, num) { michael@0: is(aCW.GroupItems.groupItems.length, num, prefix + ': there are ' + num + ' groups'); michael@0: } michael@0: michael@0: let assertOneTabInGroup = function (prefix, groupItem) { michael@0: is(groupItem.getChildren().length, 1, prefix + ': group contains one tab'); michael@0: } michael@0: michael@0: let assertValidPrerequisites = function (aWindow, prefix) { michael@0: assertNumberOfTabs(aWindow, prefix, 1); michael@0: assertNumberOfPinnedTabs(aWindow, prefix, 0); michael@0: assertTabViewIsHidden(aWindow, prefix); michael@0: } michael@0: michael@0: let assertValidSetup = function (aWindow, prefix) { michael@0: let cw = aWindow.TabView.getContentWindow(); michael@0: assertNumberOfGroups(cw, prefix, 2); michael@0: assertNumberOfTabs(aWindow, prefix, 4); michael@0: assertNumberOfPinnedTabs(aWindow, prefix, 2); michael@0: michael@0: let [group1, group2] = cw.GroupItems.groupItems; michael@0: assertOneTabInGroup(prefix, group1); michael@0: assertOneTabInGroup(prefix, group2); michael@0: } michael@0: michael@0: let testStateAfterEnteringPB = function (aWindow, aCallback) { michael@0: let prefix = 'window is private'; michael@0: ok(PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix); michael@0: michael@0: assertTabViewIsHidden(aWindow, prefix); michael@0: michael@0: showTabView(function () { michael@0: let cw = aWindow.TabView.getContentWindow(); michael@0: michael@0: assertNumberOfGroups(cw, prefix, 1); michael@0: assertNumberOfTabs(aWindow, prefix, 1); michael@0: assertOneTabInGroup(prefix, cw.GroupItems.groupItems[0]); michael@0: aCallback(); michael@0: }, aWindow); michael@0: } michael@0: michael@0: let testStateAfterLeavingPB = function (aWindow) { michael@0: let prefix = 'window is not private'; michael@0: ok(!PrivateBrowsingUtils.isWindowPrivate(aWindow), prefix); michael@0: michael@0: assertTabViewIsHidden(aWindow, prefix); michael@0: michael@0: showTabView(function () { michael@0: assertValidSetup(aWindow, prefix); michael@0: finishTest(aWindow); michael@0: }, aWindow); michael@0: } michael@0: michael@0: let finishTest = function (aWindow) { michael@0: let cw = aWindow.TabView.getContentWindow(); michael@0: michael@0: // Remove pinned tabs michael@0: aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[0]); michael@0: aWindow.gBrowser.removeTab(aWindow.gBrowser.tabs[0]); michael@0: michael@0: cw.GroupItems.groupItems[1].closeAll(); michael@0: michael@0: hideTabView(function () { michael@0: assertValidPrerequisites(aWindow, 'exit'); michael@0: assertNumberOfGroups(cw, 'exit', 1); michael@0: aWindow.close(); michael@0: finish(); michael@0: }, aWindow); michael@0: } michael@0: michael@0: let testOnWindow = function(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: waitForExplicitFinish(); michael@0: testOnWindow(false, function(publicWindow) { michael@0: registerCleanupFunction(function () publicWindow.TabView.hide()); michael@0: assertValidPrerequisites(publicWindow, 'start'); michael@0: michael@0: showTabView(function () { michael@0: let cw = publicWindow.TabView.getContentWindow(); michael@0: assertNumberOfGroups(cw, 'start', 1); michael@0: createGroupItem(publicWindow); michael@0: michael@0: afterAllTabsLoaded(function () { michael@0: // Setup michael@0: let groupItems = cw.GroupItems.groupItems; michael@0: let [tabItem1, tabItem2, ] = groupItems[1].getChildren(); michael@0: publicWindow.gBrowser.pinTab(tabItem1.tab); michael@0: publicWindow.gBrowser.pinTab(tabItem2.tab); michael@0: michael@0: assertValidSetup(publicWindow, 'setup'); michael@0: hideTabView(function() { michael@0: testOnWindow(true, function(privateWindow) { michael@0: testStateAfterEnteringPB(privateWindow, function() { michael@0: privateWindow.close(); michael@0: hideTabView(function() { michael@0: testStateAfterLeavingPB(publicWindow); michael@0: }, publicWindow); michael@0: }); michael@0: }); michael@0: }, publicWindow); michael@0: }); michael@0: }, publicWindow); michael@0: }); michael@0: }