browser/base/content/test/general/browser_bug380960.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial