browser/base/content/test/general/browser_bug406216.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 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 /*
     6  * "TabClose" event is possibly used for closing related tabs of the current.
     7  * "removeTab" method should work correctly even if the number of tabs are
     8  * changed while "TabClose" event.
     9  */
    11 var count = 0;
    12 const URIS = ["about:config",
    13               "about:plugins",
    14               "about:buildconfig",
    15               "data:text/html,<title>OK</title>"];
    17 function test() {
    18   waitForExplicitFinish();
    19   URIS.forEach(addTab);
    20 }
    22 function addTab(aURI, aIndex) {
    23   var tab = gBrowser.addTab(aURI);
    24   if (aIndex == 0)
    25     gBrowser.removeTab(gBrowser.tabs[0]);
    27   tab.linkedBrowser.addEventListener("load", function (event) {
    28     event.currentTarget.removeEventListener("load", arguments.callee, true);
    29     if (++count == URIS.length)
    30       executeSoon(doTabsTest);
    31   }, true);
    32 }
    34 function doTabsTest() {
    35   is(gBrowser.tabs.length, URIS.length, "Correctly opened all expected tabs");
    37   // sample of "close related tabs" feature
    38   gBrowser.tabContainer.addEventListener("TabClose", function (event) {
    39     event.currentTarget.removeEventListener("TabClose", arguments.callee, true);
    40     var closedTab = event.originalTarget;
    41     var scheme = closedTab.linkedBrowser.currentURI.scheme;
    42     Array.slice(gBrowser.tabs).forEach(function (aTab) {
    43       if (aTab != closedTab && aTab.linkedBrowser.currentURI.scheme == scheme)
    44         gBrowser.removeTab(aTab);
    45     });
    46   }, true);
    48   gBrowser.removeTab(gBrowser.tabs[0]);
    49   is(gBrowser.tabs.length, 1, "Related tabs are not closed unexpectedly");
    51   gBrowser.addTab("about:blank");
    52   gBrowser.removeTab(gBrowser.tabs[0]);
    53   finish();
    54 }

mercurial