michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: const TEST_URL = 'data:text/html,'; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: showTabView(onTabViewShown); michael@0: } michael@0: michael@0: function onTabViewShown() { michael@0: let contentWindow = TabView.getContentWindow(); michael@0: let groupItemOne = contentWindow.GroupItems.getActiveGroupItem(); michael@0: let groupItemTwo = createGroupItemWithTabs(window, 300, 300, 10, [TEST_URL]); michael@0: michael@0: afterAllTabsLoaded(function () { michael@0: testStayOnPage(contentWindow, groupItemOne, groupItemTwo); michael@0: }); michael@0: } michael@0: michael@0: function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) { michael@0: // We created a new tab group with a second tab above, so let's michael@0: // pick that second tab here and wait for its onbeforeunload dialog. michael@0: let browser = gBrowser.browsers[1]; michael@0: waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { michael@0: executeSoon(function () { michael@0: is(gBrowser.tabs.length, 2, michael@0: "The total number of tab is 2 when staying on the page"); michael@0: is(contentWindow.TabItems.getItems().length, 2, michael@0: "The total number of tab items is 2 when staying on the page"); michael@0: michael@0: showTabView(function () { michael@0: // start the next test michael@0: testLeavePage(contentWindow, groupItemOne, groupItemTwo); michael@0: }); michael@0: }); michael@0: michael@0: // stay on page michael@0: btnStay.click(); michael@0: }); michael@0: michael@0: closeGroupItem(groupItemTwo); michael@0: } michael@0: michael@0: function testLeavePage(contentWindow, groupItemOne, groupItemTwo) { michael@0: // The second tab hasn't been closed yet because we chose to stay. Wait michael@0: // for the onbeforeunload dialog again and leave the page this time. michael@0: let browser = gBrowser.browsers[1]; michael@0: waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { michael@0: // clean up and finish the test michael@0: groupItemTwo.addSubscriber("close", function onClose() { michael@0: groupItemTwo.removeSubscriber("close", onClose); michael@0: michael@0: is(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: hideTabView(finish); michael@0: }); michael@0: michael@0: // Leave page michael@0: btnLeave.click(); michael@0: }); michael@0: michael@0: closeGroupItem(groupItemTwo); michael@0: }