michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: "use strict"; michael@0: michael@0: let tiltOpened = false; michael@0: michael@0: function test() { michael@0: if (!isTiltEnabled()) { michael@0: info("Skipping part of the arcball test because Tilt isn't enabled."); michael@0: return; michael@0: } michael@0: if (!isWebGLSupported()) { michael@0: info("Skipping part of the arcball test because WebGL isn't supported."); michael@0: return; michael@0: } michael@0: michael@0: requestLongerTimeout(10); michael@0: waitForExplicitFinish(); michael@0: michael@0: createTab(function() { michael@0: createTilt({ michael@0: onTiltOpen: function(instance) michael@0: { michael@0: tiltOpened = true; michael@0: michael@0: performTest(instance.presenter.canvas, michael@0: instance.controller.arcball, function() { michael@0: michael@0: info("Killing arcball reset test."); michael@0: michael@0: Services.obs.addObserver(cleanup, DESTROYED, false); michael@0: Tilt.destroy(Tilt.currentWindowId); michael@0: }); michael@0: } michael@0: }, false, function suddenDeath() michael@0: { michael@0: info("Tilt could not be initialized properly."); michael@0: cleanup(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function performTest(canvas, arcball, callback) { michael@0: is(document.activeElement, canvas, michael@0: "The visualizer canvas should be focused when performing this test."); michael@0: michael@0: michael@0: info("Starting arcball reset test."); michael@0: michael@0: // start translating and rotating sometime at random michael@0: michael@0: window.setTimeout(function() { michael@0: info("Synthesizing key down events."); michael@0: michael@0: EventUtils.synthesizeKey("VK_W", { type: "keydown" }); michael@0: EventUtils.synthesizeKey("VK_LEFT", { type: "keydown" }); michael@0: michael@0: // wait for some arcball translations and rotations to happen michael@0: michael@0: window.setTimeout(function() { michael@0: info("Synthesizing key up events."); michael@0: michael@0: EventUtils.synthesizeKey("VK_W", { type: "keyup" }); michael@0: EventUtils.synthesizeKey("VK_LEFT", { type: "keyup" }); michael@0: michael@0: // ok, transformations finished, we can now try to reset the model view michael@0: michael@0: window.setTimeout(function() { michael@0: info("Synthesizing arcball reset key press."); michael@0: michael@0: arcball._onResetStart = function() { michael@0: info("Starting arcball reset animation."); michael@0: }; michael@0: michael@0: arcball._onResetStep = function() { michael@0: info("\nlastRot: " + quat4.str(arcball._lastRot) + michael@0: "\ndeltaRot: " + quat4.str(arcball._deltaRot) + michael@0: "\ncurrentRot: " + quat4.str(arcball._currentRot) + michael@0: "\nlastTrans: " + vec3.str(arcball._lastTrans) + michael@0: "\ndeltaTrans: " + vec3.str(arcball._deltaTrans) + michael@0: "\ncurrentTrans: " + vec3.str(arcball._currentTrans) + michael@0: "\nadditionalRot: " + vec3.str(arcball._additionalRot) + michael@0: "\nadditionalTrans: " + vec3.str(arcball._additionalTrans) + michael@0: "\nzoomAmount: " + arcball._zoomAmount); michael@0: }; michael@0: michael@0: arcball._onResetFinish = function() { michael@0: ok(isApproxVec(arcball._lastRot, [0, 0, 0, 1]), michael@0: "The arcball _lastRot field wasn't reset correctly."); michael@0: ok(isApproxVec(arcball._deltaRot, [0, 0, 0, 1]), michael@0: "The arcball _deltaRot field wasn't reset correctly."); michael@0: ok(isApproxVec(arcball._currentRot, [0, 0, 0, 1]), michael@0: "The arcball _currentRot field wasn't reset correctly."); michael@0: michael@0: ok(isApproxVec(arcball._lastTrans, [0, 0, 0]), michael@0: "The arcball _lastTrans field wasn't reset correctly."); michael@0: ok(isApproxVec(arcball._deltaTrans, [0, 0, 0]), michael@0: "The arcball _deltaTrans field wasn't reset correctly."); michael@0: ok(isApproxVec(arcball._currentTrans, [0, 0, 0]), michael@0: "The arcball _currentTrans field wasn't reset correctly."); michael@0: michael@0: ok(isApproxVec(arcball._additionalRot, [0, 0, 0]), michael@0: "The arcball _additionalRot field wasn't reset correctly."); michael@0: ok(isApproxVec(arcball._additionalTrans, [0, 0, 0]), michael@0: "The arcball _additionalTrans field wasn't reset correctly."); michael@0: michael@0: ok(isApproxVec([arcball._zoomAmount], [0]), michael@0: "The arcball _zoomAmount field wasn't reset correctly."); michael@0: michael@0: executeSoon(function() { michael@0: info("Finishing arcball reset test."); michael@0: callback(); michael@0: }); michael@0: }; michael@0: michael@0: EventUtils.synthesizeKey("VK_R", { type: "keydown" }); michael@0: michael@0: }, Math.random() * 1000); // leave enough time for transforms to happen michael@0: }, Math.random() * 1000); michael@0: }, Math.random() * 1000); michael@0: } michael@0: michael@0: function cleanup() { michael@0: info("Cleaning up arcball reset test."); michael@0: michael@0: if (tiltOpened) { Services.obs.removeObserver(cleanup, DESTROYED); } michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }