browser/components/tabview/test/browser_tabview_bug626455.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 *
michael@0 5 * Contributor(s):
michael@0 6 * Mihai Sucan <mihai.sucan@gmail.com>
michael@0 7 * Raymond Lee <raymond@appcoast.com>
michael@0 8 */
michael@0 9
michael@0 10 "use strict";
michael@0 11
michael@0 12 const TEST_URL = 'data:text/html,<script>window.onbeforeunload=' +
michael@0 13 'function(e){e.returnValue="?"}</script>';
michael@0 14
michael@0 15 let contentWindow;
michael@0 16 let activeGroup;
michael@0 17
michael@0 18 function test() {
michael@0 19 waitForExplicitFinish();
michael@0 20
michael@0 21 newWindowWithTabView(win => {
michael@0 22 contentWindow = win.TabView.getContentWindow();
michael@0 23 activeGroup = contentWindow.GroupItems.getActiveGroupItem();
michael@0 24
michael@0 25 win.gBrowser.browsers[0].loadURI("data:text/html,<p>test for bug 626455, tab1");
michael@0 26
michael@0 27 let tab = win.gBrowser.addTab(TEST_URL);
michael@0 28 afterAllTabsLoaded(() => testStayOnPage(win, tab));
michael@0 29 });
michael@0 30 }
michael@0 31
michael@0 32 function testStayOnPage(win, blockingTab) {
michael@0 33 let browser = blockingTab.linkedBrowser;
michael@0 34 waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) {
michael@0 35 // stay on page
michael@0 36 btnStay.click();
michael@0 37
michael@0 38 executeSoon(function () {
michael@0 39 showTabView(function () {
michael@0 40 is(win.gBrowser.tabs.length, 1,
michael@0 41 "The total number of tab is 1 when staying on the page");
michael@0 42
michael@0 43 // The other initial tab has been closed when trying to close the tab
michael@0 44 // group. The only tab left is the one with the onbeforeunload dialog.
michael@0 45 let url = win.gBrowser.browsers[0].currentURI.spec;
michael@0 46 ok(url.contains("onbeforeunload"), "The open tab is the expected one");
michael@0 47
michael@0 48 is(contentWindow.GroupItems.getActiveGroupItem(), activeGroup,
michael@0 49 "Active group is still the same");
michael@0 50
michael@0 51 is(contentWindow.GroupItems.groupItems.length, 1,
michael@0 52 "Only one group is open");
michael@0 53
michael@0 54 // start the next test
michael@0 55 testLeavePage(win, win.gBrowser.tabs[0]);
michael@0 56 }, win);
michael@0 57 });
michael@0 58 });
michael@0 59
michael@0 60 closeGroupItem(activeGroup);
michael@0 61 }
michael@0 62
michael@0 63 function testLeavePage(win, blockingTab) {
michael@0 64 let browser = blockingTab.linkedBrowser;
michael@0 65 waitForOnBeforeUnloadDialog(browser, function (btnLeave, btnStay) {
michael@0 66 // Leave page
michael@0 67 btnLeave.click();
michael@0 68 });
michael@0 69
michael@0 70 whenGroupClosed(activeGroup, () => finishTest(win));
michael@0 71 closeGroupItem(activeGroup);
michael@0 72 }
michael@0 73
michael@0 74 function finishTest(win) {
michael@0 75 is(win.gBrowser.tabs.length, 1,
michael@0 76 "The total number of tab is 1 after leaving the page");
michael@0 77 is(contentWindow.TabItems.getItems().length, 1,
michael@0 78 "The total number of tab items is 1 after leaving the page");
michael@0 79
michael@0 80 let location = win.gBrowser.browsers[0].currentURI.spec;
michael@0 81 is(location, BROWSER_NEW_TAB_URL, "The open tab is the expected one");
michael@0 82
michael@0 83 isnot(contentWindow.GroupItems.getActiveGroupItem(), activeGroup,
michael@0 84 "Active group is no longer the same");
michael@0 85
michael@0 86 is(contentWindow.GroupItems.groupItems.length, 1,
michael@0 87 "Only one group is open");
michael@0 88
michael@0 89 contentWindow = null;
michael@0 90 activeGroup = null;
michael@0 91 promiseWindowClosed(win).then(finish);
michael@0 92 }
michael@0 93
michael@0 94 // ----------
michael@0 95 function whenGroupClosed(group, callback) {
michael@0 96 group.addSubscriber("close", function onClose() {
michael@0 97 group.removeSubscriber("close", onClose);
michael@0 98 callback();
michael@0 99 });
michael@0 100 }

mercurial