|
1 function test() { |
|
2 gBrowser.tabContainer.addEventListener("TabOpen", tabAdded, false); |
|
3 |
|
4 var tab = gBrowser.addTab("about:blank", { skipAnimation: true }); |
|
5 gBrowser.removeTab(tab); |
|
6 is(tab.parentNode, null, "tab removed immediately"); |
|
7 |
|
8 tab = gBrowser.addTab("about:blank", { skipAnimation: true }); |
|
9 gBrowser.removeTab(tab, { animate: true }); |
|
10 gBrowser.removeTab(tab); |
|
11 is(tab.parentNode, null, "tab removed immediately when calling removeTab again after the animation was kicked off"); |
|
12 |
|
13 waitForExplicitFinish(); |
|
14 |
|
15 Services.prefs.setBoolPref("browser.tabs.animate", true); |
|
16 |
|
17 // preperForNextText(); |
|
18 todo(false, "async tests disabled because of intermittent failures (bug 585361)"); |
|
19 cleanup(); |
|
20 } |
|
21 |
|
22 function tabAdded() { |
|
23 info("tab added"); |
|
24 } |
|
25 |
|
26 function cleanup() { |
|
27 if (Services.prefs.prefHasUserValue("browser.tabs.animate")) |
|
28 Services.prefs.clearUserPref("browser.tabs.animate"); |
|
29 gBrowser.tabContainer.removeEventListener("TabOpen", tabAdded, false); |
|
30 finish(); |
|
31 } |
|
32 |
|
33 var asyncTests = [ |
|
34 function (tab) { |
|
35 info("closing tab with middle click"); |
|
36 EventUtils.synthesizeMouse(tab, 2, 2, { button: 1 }); |
|
37 }, |
|
38 function (tab) { |
|
39 info("closing tab with accel+w"); |
|
40 gBrowser.selectedTab = tab; |
|
41 gBrowser.selectedBrowser.focus(); |
|
42 EventUtils.synthesizeKey("w", { accelKey: true }); |
|
43 }, |
|
44 function (tab) { |
|
45 info("closing tab by clicking the tab close button"); |
|
46 gBrowser.selectedTab = tab; |
|
47 var button = document.getAnonymousElementByAttribute(tab, "anonid", "close-button"); |
|
48 EventUtils.synthesizeMouse(button, 2, 2, {}); |
|
49 } |
|
50 ]; |
|
51 |
|
52 function preperForNextText() { |
|
53 info("tests left: " + asyncTests.length + "; starting next"); |
|
54 var tab = gBrowser.addTab("about:blank", { skipAnimation: true }); |
|
55 executeSoon(function () { |
|
56 nextAsyncText(tab); |
|
57 }); |
|
58 } |
|
59 |
|
60 function nextAsyncText(tab) { |
|
61 var gotCloseEvent = false; |
|
62 |
|
63 tab.addEventListener("TabClose", function () { |
|
64 tab.removeEventListener("TabClose", arguments.callee, false); |
|
65 info("got TabClose event"); |
|
66 gotCloseEvent = true; |
|
67 |
|
68 const DEFAULT_ANIMATION_LENGTH = 250; |
|
69 const MAX_WAIT_TIME = DEFAULT_ANIMATION_LENGTH * 7; |
|
70 var polls = Math.ceil(MAX_WAIT_TIME / DEFAULT_ANIMATION_LENGTH); |
|
71 var pollTabRemoved = setInterval(function () { |
|
72 --polls; |
|
73 if (tab.parentNode && polls > 0) |
|
74 return; |
|
75 clearInterval(pollTabRemoved); |
|
76 |
|
77 is(tab.parentNode, null, "tab removed after at most " + MAX_WAIT_TIME + " ms"); |
|
78 |
|
79 if (asyncTests.length) |
|
80 preperForNextText(); |
|
81 else |
|
82 cleanup(); |
|
83 }, DEFAULT_ANIMATION_LENGTH); |
|
84 }, false); |
|
85 |
|
86 asyncTests.shift()(tab); |
|
87 |
|
88 ok(gotCloseEvent, "got the close event syncronously"); |
|
89 |
|
90 is(tab.parentNode, gBrowser.tabContainer, "tab still exists when it's about to be removed asynchronously"); |
|
91 } |