michael@0: function test() { michael@0: gBrowser.tabContainer.addEventListener("TabOpen", tabAdded, false); michael@0: michael@0: var tab = gBrowser.addTab("about:blank", { skipAnimation: true }); michael@0: gBrowser.removeTab(tab); michael@0: is(tab.parentNode, null, "tab removed immediately"); michael@0: michael@0: tab = gBrowser.addTab("about:blank", { skipAnimation: true }); michael@0: gBrowser.removeTab(tab, { animate: true }); michael@0: gBrowser.removeTab(tab); michael@0: is(tab.parentNode, null, "tab removed immediately when calling removeTab again after the animation was kicked off"); michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: Services.prefs.setBoolPref("browser.tabs.animate", true); michael@0: michael@0: // preperForNextText(); michael@0: todo(false, "async tests disabled because of intermittent failures (bug 585361)"); michael@0: cleanup(); michael@0: } michael@0: michael@0: function tabAdded() { michael@0: info("tab added"); michael@0: } michael@0: michael@0: function cleanup() { michael@0: if (Services.prefs.prefHasUserValue("browser.tabs.animate")) michael@0: Services.prefs.clearUserPref("browser.tabs.animate"); michael@0: gBrowser.tabContainer.removeEventListener("TabOpen", tabAdded, false); michael@0: finish(); michael@0: } michael@0: michael@0: var asyncTests = [ michael@0: function (tab) { michael@0: info("closing tab with middle click"); michael@0: EventUtils.synthesizeMouse(tab, 2, 2, { button: 1 }); michael@0: }, michael@0: function (tab) { michael@0: info("closing tab with accel+w"); michael@0: gBrowser.selectedTab = tab; michael@0: gBrowser.selectedBrowser.focus(); michael@0: EventUtils.synthesizeKey("w", { accelKey: true }); michael@0: }, michael@0: function (tab) { michael@0: info("closing tab by clicking the tab close button"); michael@0: gBrowser.selectedTab = tab; michael@0: var button = document.getAnonymousElementByAttribute(tab, "anonid", "close-button"); michael@0: EventUtils.synthesizeMouse(button, 2, 2, {}); michael@0: } michael@0: ]; michael@0: michael@0: function preperForNextText() { michael@0: info("tests left: " + asyncTests.length + "; starting next"); michael@0: var tab = gBrowser.addTab("about:blank", { skipAnimation: true }); michael@0: executeSoon(function () { michael@0: nextAsyncText(tab); michael@0: }); michael@0: } michael@0: michael@0: function nextAsyncText(tab) { michael@0: var gotCloseEvent = false; michael@0: michael@0: tab.addEventListener("TabClose", function () { michael@0: tab.removeEventListener("TabClose", arguments.callee, false); michael@0: info("got TabClose event"); michael@0: gotCloseEvent = true; michael@0: michael@0: const DEFAULT_ANIMATION_LENGTH = 250; michael@0: const MAX_WAIT_TIME = DEFAULT_ANIMATION_LENGTH * 7; michael@0: var polls = Math.ceil(MAX_WAIT_TIME / DEFAULT_ANIMATION_LENGTH); michael@0: var pollTabRemoved = setInterval(function () { michael@0: --polls; michael@0: if (tab.parentNode && polls > 0) michael@0: return; michael@0: clearInterval(pollTabRemoved); michael@0: michael@0: is(tab.parentNode, null, "tab removed after at most " + MAX_WAIT_TIME + " ms"); michael@0: michael@0: if (asyncTests.length) michael@0: preperForNextText(); michael@0: else michael@0: cleanup(); michael@0: }, DEFAULT_ANIMATION_LENGTH); michael@0: }, false); michael@0: michael@0: asyncTests.shift()(tab); michael@0: michael@0: ok(gotCloseEvent, "got the close event syncronously"); michael@0: michael@0: is(tab.parentNode, gBrowser.tabContainer, "tab still exists when it's about to be removed asynchronously"); michael@0: }