browser/components/tabview/test/browser_tabview_bug595804.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/tabview/test/browser_tabview_bug595804.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +var prefsBranch = Cc["@mozilla.org/preferences-service;1"].
     1.8 +                  getService(Ci.nsIPrefService).
     1.9 +                  getBranch("browser.panorama.");
    1.10 +
    1.11 +function animateZoom() prefsBranch.getBoolPref("animate_zoom");
    1.12 +
    1.13 +let contentWindow = null;
    1.14 +
    1.15 +registerCleanupFunction(function() {
    1.16 +  // reset to default: true
    1.17 +  prefsBranch.setBoolPref("animate_zoom", true);
    1.18 +});
    1.19 +
    1.20 +function test() {
    1.21 +  requestLongerTimeout(2);
    1.22 +  waitForExplicitFinish();
    1.23 +  
    1.24 +  ok(!TabView.isVisible(), "Tab View is not visible");
    1.25 +  
    1.26 +  window.addEventListener("tabviewshown", startTesting, false);
    1.27 +  TabView.toggle();
    1.28 +}
    1.29 +
    1.30 +function startTesting() {
    1.31 +  window.removeEventListener("tabviewshown", startTesting, false);
    1.32 +  
    1.33 +  contentWindow = document.getElementById("tab-view").contentWindow;
    1.34 +  
    1.35 +  ok(TabView.isVisible(), "Tab View is visible");
    1.36 +  
    1.37 +  ok(animateZoom(), "By default, we want to animate");
    1.38 +  
    1.39 +  function finishOnHidden() {
    1.40 +    contentWindow.removeEventListener("tabviewhidden", finishOnHidden, false);
    1.41 +    ok(!TabView.isVisible(), "Tab View is not visible");
    1.42 +    finish();
    1.43 +  }
    1.44 +  
    1.45 +  function wrapup() {
    1.46 +    contentWindow.addEventListener("tabviewhidden", finishOnHidden, false);
    1.47 +    TabView.hide();
    1.48 +  }
    1.49 +
    1.50 +  function part2() {
    1.51 +    prefsBranch.setBoolPref("animate_zoom", false);
    1.52 +    ok(!animateZoom(), "animate_zoom = false");
    1.53 +    zoomInAndOut(false, wrapup);
    1.54 +  }
    1.55 +
    1.56 +  function part1() {
    1.57 +    prefsBranch.setBoolPref("animate_zoom",true);
    1.58 +    ok(animateZoom(), "animate_zoom = true");
    1.59 +    zoomInAndOut(true, part2);
    1.60 +  }
    1.61 +    
    1.62 +  // start it up!
    1.63 +  part1();
    1.64 +}
    1.65 +  
    1.66 +function zoomInAndOut(transitionsExpected, callback) {
    1.67 +  let transitioned = 0;
    1.68 +
    1.69 +  contentWindow.document.addEventListener("transitionend", onTransitionEnd, false);
    1.70 +  function onTransitionEnd(event) {
    1.71 +    transitioned++;
    1.72 +  }
    1.73 +
    1.74 +  let onHidden = function() {
    1.75 +    contentWindow.removeEventListener("tabviewhidden", onHidden, false);
    1.76 +    if (transitionsExpected)
    1.77 +      ok(transitioned >= 0, "There can be transitions");
    1.78 +    else
    1.79 +      ok(!transitioned, "There should have been no transitions");
    1.80 +    TabView.toggle();
    1.81 +  };
    1.82 +  
    1.83 +  let onShownAgain = function() {
    1.84 +    contentWindow.removeEventListener("tabviewshown", onShownAgain, false);
    1.85 +    if (transitionsExpected)
    1.86 +      ok(transitioned >= 0, "There can be transitions");
    1.87 +    else
    1.88 +      ok(!transitioned, "There should have been no transitions");
    1.89 +
    1.90 +    contentWindow.document.removeEventListener("transitionend", onTransitionEnd, false);
    1.91 +    callback();
    1.92 +  };
    1.93 +  
    1.94 +  contentWindow.addEventListener("tabviewhidden", onHidden, false);
    1.95 +  contentWindow.addEventListener("tabviewshown", onShownAgain, false);
    1.96 +  
    1.97 +  // get this party started by hiding tab view
    1.98 +  TabView.toggle();
    1.99 +}

mercurial