|
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 = ["about:config", |
|
13 "about:plugins", |
|
14 "about:buildconfig", |
|
15 "data:text/html,<title>OK</title>"]; |
|
16 |
|
17 function test() { |
|
18 waitForExplicitFinish(); |
|
19 URIS.forEach(addTab); |
|
20 } |
|
21 |
|
22 function addTab(aURI, aIndex) { |
|
23 var tab = gBrowser.addTab(aURI); |
|
24 if (aIndex == 0) |
|
25 gBrowser.removeTab(gBrowser.tabs[0]); |
|
26 |
|
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 } |
|
33 |
|
34 function doTabsTest() { |
|
35 is(gBrowser.tabs.length, URIS.length, "Correctly opened all expected tabs"); |
|
36 |
|
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); |
|
47 |
|
48 gBrowser.removeTab(gBrowser.tabs[0]); |
|
49 is(gBrowser.tabs.length, 1, "Related tabs are not closed unexpectedly"); |
|
50 |
|
51 gBrowser.addTab("about:blank"); |
|
52 gBrowser.removeTab(gBrowser.tabs[0]); |
|
53 finish(); |
|
54 } |