tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_bug406216.js (1846B)


      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/. */
      4 
      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 */
     10 
     11 var count = 0;
     12 const URIS = [
     13  "about:config",
     14  "about:robots",
     15  "about:buildconfig",
     16  "data:text/html,<title>OK</title>",
     17 ];
     18 
     19 function test() {
     20  waitForExplicitFinish();
     21  URIS.forEach(addTab);
     22 }
     23 
     24 function addTab(aURI, aIndex) {
     25  var tab = BrowserTestUtils.addTab(gBrowser, aURI);
     26  if (aIndex == 0) {
     27    gBrowser.removeTab(gBrowser.tabs[0], { skipPermitUnload: true });
     28  }
     29 
     30  BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => {
     31    if (++count == URIS.length) {
     32      executeSoon(doTabsTest);
     33    }
     34  });
     35 }
     36 
     37 function doTabsTest() {
     38  is(gBrowser.tabs.length, URIS.length, "Correctly opened all expected tabs");
     39 
     40  // sample of "close related tabs" feature
     41  gBrowser.tabContainer.addEventListener(
     42    "TabClose",
     43    function (event) {
     44      var closedTab = event.originalTarget;
     45      var scheme = closedTab.linkedBrowser.currentURI.scheme;
     46      Array.from(gBrowser.tabs).forEach(function (aTab) {
     47        if (
     48          aTab != closedTab &&
     49          aTab.linkedBrowser.currentURI.scheme == scheme
     50        ) {
     51          gBrowser.removeTab(aTab, { skipPermitUnload: true });
     52        }
     53      });
     54    },
     55    { capture: true, once: true }
     56  );
     57 
     58  gBrowser.removeTab(gBrowser.tabs[0], { skipPermitUnload: true });
     59  is(gBrowser.tabs.length, 1, "Related tabs are not closed unexpectedly");
     60 
     61  BrowserTestUtils.addTab(gBrowser, "about:blank");
     62  gBrowser.removeTab(gBrowser.tabs[0], { skipPermitUnload: true });
     63  finish();
     64 }