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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug380960.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +function test() {
     1.5 +  gBrowser.tabContainer.addEventListener("TabOpen", tabAdded, false);
     1.6 +
     1.7 +  var tab = gBrowser.addTab("about:blank", { skipAnimation: true });
     1.8 +  gBrowser.removeTab(tab);
     1.9 +  is(tab.parentNode, null, "tab removed immediately");
    1.10 +
    1.11 +  tab = gBrowser.addTab("about:blank", { skipAnimation: true });
    1.12 +  gBrowser.removeTab(tab, { animate: true });
    1.13 +  gBrowser.removeTab(tab);
    1.14 +  is(tab.parentNode, null, "tab removed immediately when calling removeTab again after the animation was kicked off");
    1.15 +
    1.16 +  waitForExplicitFinish();
    1.17 +
    1.18 +  Services.prefs.setBoolPref("browser.tabs.animate", true);
    1.19 +
    1.20 +//  preperForNextText();
    1.21 +  todo(false, "async tests disabled because of intermittent failures (bug 585361)");
    1.22 +  cleanup();
    1.23 +}
    1.24 +
    1.25 +function tabAdded() {
    1.26 +  info("tab added");
    1.27 +}
    1.28 +
    1.29 +function cleanup() {
    1.30 +  if (Services.prefs.prefHasUserValue("browser.tabs.animate"))
    1.31 +    Services.prefs.clearUserPref("browser.tabs.animate");
    1.32 +  gBrowser.tabContainer.removeEventListener("TabOpen", tabAdded, false);
    1.33 +  finish();
    1.34 +}
    1.35 +
    1.36 +var asyncTests = [
    1.37 +  function (tab) {
    1.38 +    info("closing tab with middle click");
    1.39 +    EventUtils.synthesizeMouse(tab, 2, 2, { button: 1 });
    1.40 +  },
    1.41 +  function (tab) {
    1.42 +    info("closing tab with accel+w");
    1.43 +    gBrowser.selectedTab = tab;
    1.44 +    gBrowser.selectedBrowser.focus();
    1.45 +    EventUtils.synthesizeKey("w", { accelKey: true });
    1.46 +  },
    1.47 +  function (tab) {
    1.48 +    info("closing tab by clicking the tab close button");
    1.49 +    gBrowser.selectedTab = tab;
    1.50 +    var button = document.getAnonymousElementByAttribute(tab, "anonid", "close-button");
    1.51 +    EventUtils.synthesizeMouse(button, 2, 2, {});
    1.52 +  }
    1.53 +];
    1.54 +
    1.55 +function preperForNextText() {
    1.56 +  info("tests left: " + asyncTests.length + "; starting next");
    1.57 +  var tab = gBrowser.addTab("about:blank", { skipAnimation: true });
    1.58 +  executeSoon(function () {
    1.59 +    nextAsyncText(tab);
    1.60 +  });
    1.61 +}
    1.62 +
    1.63 +function nextAsyncText(tab) {
    1.64 +  var gotCloseEvent = false;
    1.65 +
    1.66 +  tab.addEventListener("TabClose", function () {
    1.67 +    tab.removeEventListener("TabClose", arguments.callee, false);
    1.68 +    info("got TabClose event");
    1.69 +    gotCloseEvent = true;
    1.70 +
    1.71 +    const DEFAULT_ANIMATION_LENGTH = 250;
    1.72 +    const MAX_WAIT_TIME = DEFAULT_ANIMATION_LENGTH * 7;
    1.73 +    var polls = Math.ceil(MAX_WAIT_TIME / DEFAULT_ANIMATION_LENGTH);
    1.74 +    var pollTabRemoved = setInterval(function () {
    1.75 +      --polls;
    1.76 +      if (tab.parentNode && polls > 0)
    1.77 +        return;
    1.78 +      clearInterval(pollTabRemoved);
    1.79 +
    1.80 +      is(tab.parentNode, null, "tab removed after at most " + MAX_WAIT_TIME + " ms");
    1.81 +
    1.82 +      if (asyncTests.length)
    1.83 +        preperForNextText();
    1.84 +      else
    1.85 +        cleanup();
    1.86 +    }, DEFAULT_ANIMATION_LENGTH);
    1.87 +  }, false);
    1.88 +
    1.89 +  asyncTests.shift()(tab);
    1.90 +
    1.91 +  ok(gotCloseEvent, "got the close event syncronously");
    1.92 +
    1.93 +  is(tab.parentNode, gBrowser.tabContainer, "tab still exists when it's about to be removed asynchronously");
    1.94 +}

mercurial