1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/components/tabview/test/browser_tabview_bug626455.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,100 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + * 1.8 + * Contributor(s): 1.9 + * Mihai Sucan <mihai.sucan@gmail.com> 1.10 + * Raymond Lee <raymond@appcoast.com> 1.11 + */ 1.12 + 1.13 +"use strict"; 1.14 + 1.15 +const TEST_URL = 'data:text/html,<script>window.onbeforeunload=' + 1.16 + 'function(e){e.returnValue="?"}</script>'; 1.17 + 1.18 +let contentWindow; 1.19 +let activeGroup; 1.20 + 1.21 +function test() { 1.22 + waitForExplicitFinish(); 1.23 + 1.24 + newWindowWithTabView(win => { 1.25 + contentWindow = win.TabView.getContentWindow(); 1.26 + activeGroup = contentWindow.GroupItems.getActiveGroupItem(); 1.27 + 1.28 + win.gBrowser.browsers[0].loadURI("data:text/html,<p>test for bug 626455, tab1"); 1.29 + 1.30 + let tab = win.gBrowser.addTab(TEST_URL); 1.31 + afterAllTabsLoaded(() => testStayOnPage(win, tab)); 1.32 + }); 1.33 +} 1.34 + 1.35 +function testStayOnPage(win, blockingTab) { 1.36 + let browser = blockingTab.linkedBrowser; 1.37 + waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { 1.38 + // stay on page 1.39 + btnStay.click(); 1.40 + 1.41 + executeSoon(function () { 1.42 + showTabView(function () { 1.43 + is(win.gBrowser.tabs.length, 1, 1.44 + "The total number of tab is 1 when staying on the page"); 1.45 + 1.46 + // The other initial tab has been closed when trying to close the tab 1.47 + // group. The only tab left is the one with the onbeforeunload dialog. 1.48 + let url = win.gBrowser.browsers[0].currentURI.spec; 1.49 + ok(url.contains("onbeforeunload"), "The open tab is the expected one"); 1.50 + 1.51 + is(contentWindow.GroupItems.getActiveGroupItem(), activeGroup, 1.52 + "Active group is still the same"); 1.53 + 1.54 + is(contentWindow.GroupItems.groupItems.length, 1, 1.55 + "Only one group is open"); 1.56 + 1.57 + // start the next test 1.58 + testLeavePage(win, win.gBrowser.tabs[0]); 1.59 + }, win); 1.60 + }); 1.61 + }); 1.62 + 1.63 + closeGroupItem(activeGroup); 1.64 +} 1.65 + 1.66 +function testLeavePage(win, blockingTab) { 1.67 + let browser = blockingTab.linkedBrowser; 1.68 + waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) { 1.69 + // Leave page 1.70 + btnLeave.click(); 1.71 + }); 1.72 + 1.73 + whenGroupClosed(activeGroup, () => finishTest(win)); 1.74 + closeGroupItem(activeGroup); 1.75 +} 1.76 + 1.77 +function finishTest(win) { 1.78 + is(win.gBrowser.tabs.length, 1, 1.79 + "The total number of tab is 1 after leaving the page"); 1.80 + is(contentWindow.TabItems.getItems().length, 1, 1.81 + "The total number of tab items is 1 after leaving the page"); 1.82 + 1.83 + let location = win.gBrowser.browsers[0].currentURI.spec; 1.84 + is(location, BROWSER_NEW_TAB_URL, "The open tab is the expected one"); 1.85 + 1.86 + isnot(contentWindow.GroupItems.getActiveGroupItem(), activeGroup, 1.87 + "Active group is no longer the same"); 1.88 + 1.89 + is(contentWindow.GroupItems.groupItems.length, 1, 1.90 + "Only one group is open"); 1.91 + 1.92 + contentWindow = null; 1.93 + activeGroup = null; 1.94 + promiseWindowClosed(win).then(finish); 1.95 +} 1.96 + 1.97 +// ---------- 1.98 +function whenGroupClosed(group, callback) { 1.99 + group.addSubscriber("close", function onClose() { 1.100 + group.removeSubscriber("close", onClose); 1.101 + callback(); 1.102 + }); 1.103 +}