michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0:
michael@0: /*
michael@0: * "TabClose" event is possibly used for closing related tabs of the current.
michael@0: * "removeTab" method should work correctly even if the number of tabs are
michael@0: * changed while "TabClose" event.
michael@0: */
michael@0:
michael@0: var count = 0;
michael@0: const URIS = ["about:config",
michael@0: "about:plugins",
michael@0: "about:buildconfig",
michael@0: "data:text/html,
OK"];
michael@0:
michael@0: function test() {
michael@0: waitForExplicitFinish();
michael@0: URIS.forEach(addTab);
michael@0: }
michael@0:
michael@0: function addTab(aURI, aIndex) {
michael@0: var tab = gBrowser.addTab(aURI);
michael@0: if (aIndex == 0)
michael@0: gBrowser.removeTab(gBrowser.tabs[0]);
michael@0:
michael@0: tab.linkedBrowser.addEventListener("load", function (event) {
michael@0: event.currentTarget.removeEventListener("load", arguments.callee, true);
michael@0: if (++count == URIS.length)
michael@0: executeSoon(doTabsTest);
michael@0: }, true);
michael@0: }
michael@0:
michael@0: function doTabsTest() {
michael@0: is(gBrowser.tabs.length, URIS.length, "Correctly opened all expected tabs");
michael@0:
michael@0: // sample of "close related tabs" feature
michael@0: gBrowser.tabContainer.addEventListener("TabClose", function (event) {
michael@0: event.currentTarget.removeEventListener("TabClose", arguments.callee, true);
michael@0: var closedTab = event.originalTarget;
michael@0: var scheme = closedTab.linkedBrowser.currentURI.scheme;
michael@0: Array.slice(gBrowser.tabs).forEach(function (aTab) {
michael@0: if (aTab != closedTab && aTab.linkedBrowser.currentURI.scheme == scheme)
michael@0: gBrowser.removeTab(aTab);
michael@0: });
michael@0: }, true);
michael@0:
michael@0: gBrowser.removeTab(gBrowser.tabs[0]);
michael@0: is(gBrowser.tabs.length, 1, "Related tabs are not closed unexpectedly");
michael@0:
michael@0: gBrowser.addTab("about:blank");
michael@0: gBrowser.removeTab(gBrowser.tabs[0]);
michael@0: finish();
michael@0: }