browser/devtools/tilt/test/browser_tilt_arcball-reset.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/tilt/test/browser_tilt_arcball-reset.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +"use strict";
     1.7 +
     1.8 +let tiltOpened = false;
     1.9 +
    1.10 +function test() {
    1.11 +  if (!isTiltEnabled()) {
    1.12 +    info("Skipping part of the arcball test because Tilt isn't enabled.");
    1.13 +    return;
    1.14 +  }
    1.15 +  if (!isWebGLSupported()) {
    1.16 +    info("Skipping part of the arcball test because WebGL isn't supported.");
    1.17 +    return;
    1.18 +  }
    1.19 +
    1.20 +  requestLongerTimeout(10);
    1.21 +  waitForExplicitFinish();
    1.22 +
    1.23 +  createTab(function() {
    1.24 +    createTilt({
    1.25 +      onTiltOpen: function(instance)
    1.26 +      {
    1.27 +        tiltOpened = true;
    1.28 +
    1.29 +        performTest(instance.presenter.canvas,
    1.30 +                    instance.controller.arcball, function() {
    1.31 +
    1.32 +          info("Killing arcball reset test.");
    1.33 +
    1.34 +          Services.obs.addObserver(cleanup, DESTROYED, false);
    1.35 +          Tilt.destroy(Tilt.currentWindowId);
    1.36 +        });
    1.37 +      }
    1.38 +    }, false, function suddenDeath()
    1.39 +    {
    1.40 +      info("Tilt could not be initialized properly.");
    1.41 +      cleanup();
    1.42 +    });
    1.43 +  });
    1.44 +}
    1.45 +
    1.46 +function performTest(canvas, arcball, callback) {
    1.47 +  is(document.activeElement, canvas,
    1.48 +    "The visualizer canvas should be focused when performing this test.");
    1.49 +
    1.50 +
    1.51 +  info("Starting arcball reset test.");
    1.52 +
    1.53 +  // start translating and rotating sometime at random
    1.54 +
    1.55 +  window.setTimeout(function() {
    1.56 +    info("Synthesizing key down events.");
    1.57 +
    1.58 +    EventUtils.synthesizeKey("VK_W", { type: "keydown" });
    1.59 +    EventUtils.synthesizeKey("VK_LEFT", { type: "keydown" });
    1.60 +
    1.61 +    // wait for some arcball translations and rotations to happen
    1.62 +
    1.63 +    window.setTimeout(function() {
    1.64 +      info("Synthesizing key up events.");
    1.65 +
    1.66 +      EventUtils.synthesizeKey("VK_W", { type: "keyup" });
    1.67 +      EventUtils.synthesizeKey("VK_LEFT", { type: "keyup" });
    1.68 +
    1.69 +      // ok, transformations finished, we can now try to reset the model view
    1.70 +
    1.71 +      window.setTimeout(function() {
    1.72 +        info("Synthesizing arcball reset key press.");
    1.73 +
    1.74 +        arcball._onResetStart = function() {
    1.75 +          info("Starting arcball reset animation.");
    1.76 +        };
    1.77 +
    1.78 +        arcball._onResetStep = function() {
    1.79 +          info("\nlastRot: " + quat4.str(arcball._lastRot) +
    1.80 +               "\ndeltaRot: " + quat4.str(arcball._deltaRot) +
    1.81 +               "\ncurrentRot: " + quat4.str(arcball._currentRot) +
    1.82 +               "\nlastTrans: " + vec3.str(arcball._lastTrans) +
    1.83 +               "\ndeltaTrans: " + vec3.str(arcball._deltaTrans) +
    1.84 +               "\ncurrentTrans: " + vec3.str(arcball._currentTrans) +
    1.85 +               "\nadditionalRot: " + vec3.str(arcball._additionalRot) +
    1.86 +               "\nadditionalTrans: " + vec3.str(arcball._additionalTrans) +
    1.87 +               "\nzoomAmount: " + arcball._zoomAmount);
    1.88 +        };
    1.89 +
    1.90 +        arcball._onResetFinish = function() {
    1.91 +          ok(isApproxVec(arcball._lastRot, [0, 0, 0, 1]),
    1.92 +            "The arcball _lastRot field wasn't reset correctly.");
    1.93 +          ok(isApproxVec(arcball._deltaRot, [0, 0, 0, 1]),
    1.94 +            "The arcball _deltaRot field wasn't reset correctly.");
    1.95 +          ok(isApproxVec(arcball._currentRot, [0, 0, 0, 1]),
    1.96 +            "The arcball _currentRot field wasn't reset correctly.");
    1.97 +
    1.98 +          ok(isApproxVec(arcball._lastTrans, [0, 0, 0]),
    1.99 +            "The arcball _lastTrans field wasn't reset correctly.");
   1.100 +          ok(isApproxVec(arcball._deltaTrans, [0, 0, 0]),
   1.101 +            "The arcball _deltaTrans field wasn't reset correctly.");
   1.102 +          ok(isApproxVec(arcball._currentTrans, [0, 0, 0]),
   1.103 +            "The arcball _currentTrans field wasn't reset correctly.");
   1.104 +
   1.105 +          ok(isApproxVec(arcball._additionalRot, [0, 0, 0]),
   1.106 +            "The arcball _additionalRot field wasn't reset correctly.");
   1.107 +          ok(isApproxVec(arcball._additionalTrans, [0, 0, 0]),
   1.108 +            "The arcball _additionalTrans field wasn't reset correctly.");
   1.109 +
   1.110 +          ok(isApproxVec([arcball._zoomAmount], [0]),
   1.111 +            "The arcball _zoomAmount field wasn't reset correctly.");
   1.112 +
   1.113 +          executeSoon(function() {
   1.114 +            info("Finishing arcball reset test.");
   1.115 +            callback();
   1.116 +          });
   1.117 +        };
   1.118 +
   1.119 +        EventUtils.synthesizeKey("VK_R", { type: "keydown" });
   1.120 +
   1.121 +      }, Math.random() * 1000); // leave enough time for transforms to happen
   1.122 +    }, Math.random() * 1000);
   1.123 +  }, Math.random() * 1000);
   1.124 +}
   1.125 +
   1.126 +function cleanup() {
   1.127 +  info("Cleaning up arcball reset test.");
   1.128 +
   1.129 +  if (tiltOpened) { Services.obs.removeObserver(cleanup, DESTROYED); }
   1.130 +  gBrowser.removeCurrentTab();
   1.131 +  finish();
   1.132 +}

mercurial