michael@0: /* michael@0: * Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: * michael@0: * Contributor(s): michael@0: * Mihai Sucan michael@0: * Raymond Lee michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: const TEST_URL = 'data:text/html,'; michael@0: michael@0: let contentWindow; michael@0: let activeGroup; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: newWindowWithTabView(win => { michael@0: contentWindow = win.TabView.getContentWindow(); michael@0: activeGroup = contentWindow.GroupItems.getActiveGroupItem(); michael@0: michael@0: win.gBrowser.browsers[0].loadURI("data:text/html,

test for bug 626455, tab1"); michael@0: michael@0: let tab = win.gBrowser.addTab(TEST_URL); michael@0: afterAllTabsLoaded(() => testStayOnPage(win, tab)); michael@0: }); michael@0: } michael@0: michael@0: function testStayOnPage(win, blockingTab) { michael@0: let browser = blockingTab.linkedBrowser; michael@0: waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { michael@0: // stay on page michael@0: btnStay.click(); michael@0: michael@0: executeSoon(function () { michael@0: showTabView(function () { michael@0: is(win.gBrowser.tabs.length, 1, michael@0: "The total number of tab is 1 when staying on the page"); michael@0: michael@0: // The other initial tab has been closed when trying to close the tab michael@0: // group. The only tab left is the one with the onbeforeunload dialog. michael@0: let url = win.gBrowser.browsers[0].currentURI.spec; michael@0: ok(url.contains("onbeforeunload"), "The open tab is the expected one"); michael@0: michael@0: is(contentWindow.GroupItems.getActiveGroupItem(), activeGroup, michael@0: "Active group is still the same"); michael@0: michael@0: is(contentWindow.GroupItems.groupItems.length, 1, michael@0: "Only one group is open"); michael@0: michael@0: // start the next test michael@0: testLeavePage(win, win.gBrowser.tabs[0]); michael@0: }, win); michael@0: }); michael@0: }); michael@0: michael@0: closeGroupItem(activeGroup); michael@0: } michael@0: michael@0: function testLeavePage(win, blockingTab) { michael@0: let browser = blockingTab.linkedBrowser; michael@0: waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { michael@0: // Leave page michael@0: btnLeave.click(); michael@0: }); michael@0: michael@0: whenGroupClosed(activeGroup, () => finishTest(win)); michael@0: closeGroupItem(activeGroup); michael@0: } michael@0: michael@0: function finishTest(win) { michael@0: is(win.gBrowser.tabs.length, 1, michael@0: "The total number of tab is 1 after leaving the page"); michael@0: is(contentWindow.TabItems.getItems().length, 1, michael@0: "The total number of tab items is 1 after leaving the page"); michael@0: michael@0: let location = win.gBrowser.browsers[0].currentURI.spec; michael@0: is(location, BROWSER_NEW_TAB_URL, "The open tab is the expected one"); michael@0: michael@0: isnot(contentWindow.GroupItems.getActiveGroupItem(), activeGroup, michael@0: "Active group is no longer the same"); michael@0: michael@0: is(contentWindow.GroupItems.groupItems.length, 1, michael@0: "Only one group is open"); michael@0: michael@0: contentWindow = null; michael@0: activeGroup = null; michael@0: promiseWindowClosed(win).then(finish); michael@0: } michael@0: michael@0: // ---------- michael@0: function whenGroupClosed(group, callback) { michael@0: group.addSubscriber("close", function onClose() { michael@0: group.removeSubscriber("close", onClose); michael@0: callback(); michael@0: }); michael@0: }