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

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3 "use strict";
michael@0 4
michael@0 5 let tiltOpened = false;
michael@0 6
michael@0 7 function test() {
michael@0 8 if (!isTiltEnabled()) {
michael@0 9 info("Skipping part of the arcball test because Tilt isn't enabled.");
michael@0 10 return;
michael@0 11 }
michael@0 12 if (!isWebGLSupported()) {
michael@0 13 info("Skipping part of the arcball test because WebGL isn't supported.");
michael@0 14 return;
michael@0 15 }
michael@0 16
michael@0 17 requestLongerTimeout(10);
michael@0 18 waitForExplicitFinish();
michael@0 19
michael@0 20 createTab(function() {
michael@0 21 createTilt({
michael@0 22 onTiltOpen: function(instance)
michael@0 23 {
michael@0 24 tiltOpened = true;
michael@0 25
michael@0 26 performTest(instance.presenter.canvas,
michael@0 27 instance.controller.arcball, function() {
michael@0 28
michael@0 29 info("Killing arcball reset test.");
michael@0 30
michael@0 31 Services.obs.addObserver(cleanup, DESTROYED, false);
michael@0 32 Tilt.destroy(Tilt.currentWindowId);
michael@0 33 });
michael@0 34 }
michael@0 35 }, false, function suddenDeath()
michael@0 36 {
michael@0 37 info("Tilt could not be initialized properly.");
michael@0 38 cleanup();
michael@0 39 });
michael@0 40 });
michael@0 41 }
michael@0 42
michael@0 43 function performTest(canvas, arcball, callback) {
michael@0 44 is(document.activeElement, canvas,
michael@0 45 "The visualizer canvas should be focused when performing this test.");
michael@0 46
michael@0 47
michael@0 48 info("Starting arcball reset test.");
michael@0 49
michael@0 50 // start translating and rotating sometime at random
michael@0 51
michael@0 52 window.setTimeout(function() {
michael@0 53 info("Synthesizing key down events.");
michael@0 54
michael@0 55 EventUtils.synthesizeKey("VK_W", { type: "keydown" });
michael@0 56 EventUtils.synthesizeKey("VK_LEFT", { type: "keydown" });
michael@0 57
michael@0 58 // wait for some arcball translations and rotations to happen
michael@0 59
michael@0 60 window.setTimeout(function() {
michael@0 61 info("Synthesizing key up events.");
michael@0 62
michael@0 63 EventUtils.synthesizeKey("VK_W", { type: "keyup" });
michael@0 64 EventUtils.synthesizeKey("VK_LEFT", { type: "keyup" });
michael@0 65
michael@0 66 // ok, transformations finished, we can now try to reset the model view
michael@0 67
michael@0 68 window.setTimeout(function() {
michael@0 69 info("Synthesizing arcball reset key press.");
michael@0 70
michael@0 71 arcball._onResetStart = function() {
michael@0 72 info("Starting arcball reset animation.");
michael@0 73 };
michael@0 74
michael@0 75 arcball._onResetStep = function() {
michael@0 76 info("\nlastRot: " + quat4.str(arcball._lastRot) +
michael@0 77 "\ndeltaRot: " + quat4.str(arcball._deltaRot) +
michael@0 78 "\ncurrentRot: " + quat4.str(arcball._currentRot) +
michael@0 79 "\nlastTrans: " + vec3.str(arcball._lastTrans) +
michael@0 80 "\ndeltaTrans: " + vec3.str(arcball._deltaTrans) +
michael@0 81 "\ncurrentTrans: " + vec3.str(arcball._currentTrans) +
michael@0 82 "\nadditionalRot: " + vec3.str(arcball._additionalRot) +
michael@0 83 "\nadditionalTrans: " + vec3.str(arcball._additionalTrans) +
michael@0 84 "\nzoomAmount: " + arcball._zoomAmount);
michael@0 85 };
michael@0 86
michael@0 87 arcball._onResetFinish = function() {
michael@0 88 ok(isApproxVec(arcball._lastRot, [0, 0, 0, 1]),
michael@0 89 "The arcball _lastRot field wasn't reset correctly.");
michael@0 90 ok(isApproxVec(arcball._deltaRot, [0, 0, 0, 1]),
michael@0 91 "The arcball _deltaRot field wasn't reset correctly.");
michael@0 92 ok(isApproxVec(arcball._currentRot, [0, 0, 0, 1]),
michael@0 93 "The arcball _currentRot field wasn't reset correctly.");
michael@0 94
michael@0 95 ok(isApproxVec(arcball._lastTrans, [0, 0, 0]),
michael@0 96 "The arcball _lastTrans field wasn't reset correctly.");
michael@0 97 ok(isApproxVec(arcball._deltaTrans, [0, 0, 0]),
michael@0 98 "The arcball _deltaTrans field wasn't reset correctly.");
michael@0 99 ok(isApproxVec(arcball._currentTrans, [0, 0, 0]),
michael@0 100 "The arcball _currentTrans field wasn't reset correctly.");
michael@0 101
michael@0 102 ok(isApproxVec(arcball._additionalRot, [0, 0, 0]),
michael@0 103 "The arcball _additionalRot field wasn't reset correctly.");
michael@0 104 ok(isApproxVec(arcball._additionalTrans, [0, 0, 0]),
michael@0 105 "The arcball _additionalTrans field wasn't reset correctly.");
michael@0 106
michael@0 107 ok(isApproxVec([arcball._zoomAmount], [0]),
michael@0 108 "The arcball _zoomAmount field wasn't reset correctly.");
michael@0 109
michael@0 110 executeSoon(function() {
michael@0 111 info("Finishing arcball reset test.");
michael@0 112 callback();
michael@0 113 });
michael@0 114 };
michael@0 115
michael@0 116 EventUtils.synthesizeKey("VK_R", { type: "keydown" });
michael@0 117
michael@0 118 }, Math.random() * 1000); // leave enough time for transforms to happen
michael@0 119 }, Math.random() * 1000);
michael@0 120 }, Math.random() * 1000);
michael@0 121 }
michael@0 122
michael@0 123 function cleanup() {
michael@0 124 info("Cleaning up arcball reset test.");
michael@0 125
michael@0 126 if (tiltOpened) { Services.obs.removeObserver(cleanup, DESTROYED); }
michael@0 127 gBrowser.removeCurrentTab();
michael@0 128 finish();
michael@0 129 }

mercurial