browser/base/content/test/general/browser_bug406216.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug406216.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,54 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +/*
     1.9 + * "TabClose" event is possibly used for closing related tabs of the current.
    1.10 + * "removeTab" method should work correctly even if the number of tabs are
    1.11 + * changed while "TabClose" event.
    1.12 + */
    1.13 +
    1.14 +var count = 0;
    1.15 +const URIS = ["about:config",
    1.16 +              "about:plugins",
    1.17 +              "about:buildconfig",
    1.18 +              "data:text/html,<title>OK</title>"];
    1.19 +
    1.20 +function test() {
    1.21 +  waitForExplicitFinish();
    1.22 +  URIS.forEach(addTab);
    1.23 +}
    1.24 +
    1.25 +function addTab(aURI, aIndex) {
    1.26 +  var tab = gBrowser.addTab(aURI);
    1.27 +  if (aIndex == 0)
    1.28 +    gBrowser.removeTab(gBrowser.tabs[0]);
    1.29 +
    1.30 +  tab.linkedBrowser.addEventListener("load", function (event) {
    1.31 +    event.currentTarget.removeEventListener("load", arguments.callee, true);
    1.32 +    if (++count == URIS.length)
    1.33 +      executeSoon(doTabsTest);
    1.34 +  }, true);
    1.35 +}
    1.36 +
    1.37 +function doTabsTest() {
    1.38 +  is(gBrowser.tabs.length, URIS.length, "Correctly opened all expected tabs");
    1.39 +
    1.40 +  // sample of "close related tabs" feature
    1.41 +  gBrowser.tabContainer.addEventListener("TabClose", function (event) {
    1.42 +    event.currentTarget.removeEventListener("TabClose", arguments.callee, true);
    1.43 +    var closedTab = event.originalTarget;
    1.44 +    var scheme = closedTab.linkedBrowser.currentURI.scheme;
    1.45 +    Array.slice(gBrowser.tabs).forEach(function (aTab) {
    1.46 +      if (aTab != closedTab && aTab.linkedBrowser.currentURI.scheme == scheme)
    1.47 +        gBrowser.removeTab(aTab);
    1.48 +    });
    1.49 +  }, true);
    1.50 +
    1.51 +  gBrowser.removeTab(gBrowser.tabs[0]);
    1.52 +  is(gBrowser.tabs.length, 1, "Related tabs are not closed unexpectedly");
    1.53 +
    1.54 +  gBrowser.addTab("about:blank");
    1.55 +  gBrowser.removeTab(gBrowser.tabs[0]);
    1.56 +  finish();
    1.57 +}

mercurial