1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug599626.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,70 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +"use strict"; 1.8 + 1.9 +const TEST_URL = 'data:text/html,<script>window.onbeforeunload=' + 1.10 + 'function(e){e.returnValue="?"}</script>'; 1.11 + 1.12 +function test() { 1.13 + waitForExplicitFinish(); 1.14 + showTabView(onTabViewShown); 1.15 +} 1.16 + 1.17 +function onTabViewShown() { 1.18 + let contentWindow = TabView.getContentWindow(); 1.19 + let groupItemOne = contentWindow.GroupItems.getActiveGroupItem(); 1.20 + let groupItemTwo = createGroupItemWithTabs(window, 300, 300, 10, [TEST_URL]); 1.21 + 1.22 + afterAllTabsLoaded(function () { 1.23 + testStayOnPage(contentWindow, groupItemOne, groupItemTwo); 1.24 + }); 1.25 +} 1.26 + 1.27 +function testStayOnPage(contentWindow, groupItemOne, groupItemTwo) { 1.28 + // We created a new tab group with a second tab above, so let's 1.29 + // pick that second tab here and wait for its onbeforeunload dialog. 1.30 + let browser = gBrowser.browsers[1]; 1.31 + waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { 1.32 + executeSoon(function () { 1.33 + is(gBrowser.tabs.length, 2, 1.34 + "The total number of tab is 2 when staying on the page"); 1.35 + is(contentWindow.TabItems.getItems().length, 2, 1.36 + "The total number of tab items is 2 when staying on the page"); 1.37 + 1.38 + showTabView(function () { 1.39 + // start the next test 1.40 + testLeavePage(contentWindow, groupItemOne, groupItemTwo); 1.41 + }); 1.42 + }); 1.43 + 1.44 + // stay on page 1.45 + btnStay.click(); 1.46 + }); 1.47 + 1.48 + closeGroupItem(groupItemTwo); 1.49 +} 1.50 + 1.51 +function testLeavePage(contentWindow, groupItemOne, groupItemTwo) { 1.52 + // The second tab hasn't been closed yet because we chose to stay. Wait 1.53 + // for the onbeforeunload dialog again and leave the page this time. 1.54 + let browser = gBrowser.browsers[1]; 1.55 + waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { 1.56 + // clean up and finish the test 1.57 + groupItemTwo.addSubscriber("close", function onClose() { 1.58 + groupItemTwo.removeSubscriber("close", onClose); 1.59 + 1.60 + is(gBrowser.tabs.length, 1, 1.61 + "The total number of tab is 1 after leaving the page"); 1.62 + is(contentWindow.TabItems.getItems().length, 1, 1.63 + "The total number of tab items is 1 after leaving the page"); 1.64 + 1.65 + hideTabView(finish); 1.66 + }); 1.67 + 1.68 + // Leave page 1.69 + btnLeave.click(); 1.70 + }); 1.71 + 1.72 + closeGroupItem(groupItemTwo); 1.73 +}