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.

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

mercurial