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: function test() { michael@0: if (!isTiltEnabled()) { michael@0: info("Skipping controller test because Tilt isn't enabled."); michael@0: return; michael@0: } michael@0: if (!isWebGLSupported()) { michael@0: info("Skipping controller test because WebGL isn't supported."); michael@0: return; michael@0: } michael@0: michael@0: waitForExplicitFinish(); michael@0: michael@0: createTab(function() { michael@0: createTilt({ michael@0: onTiltOpen: function(instance) michael@0: { michael@0: let canvas = instance.presenter.canvas; michael@0: let prev_tran = vec3.create([0, 0, 0]); michael@0: let prev_rot = quat4.create([0, 0, 0, 1]); michael@0: michael@0: function tran() { michael@0: return instance.presenter.transforms.translation; michael@0: } michael@0: michael@0: function rot() { michael@0: return instance.presenter.transforms.rotation; michael@0: } michael@0: michael@0: function save() { michael@0: prev_tran = vec3.create(tran()); michael@0: prev_rot = quat4.create(rot()); michael@0: } michael@0: michael@0: ok(isEqualVec(tran(), prev_tran), michael@0: "At init, the translation should be zero."); michael@0: ok(isEqualVec(rot(), prev_rot), michael@0: "At init, the rotation should be zero."); michael@0: michael@0: michael@0: function testEventCancel(cancellingEvent) { michael@0: is(document.activeElement, canvas, michael@0: "The visualizer canvas should be focused when performing this test."); michael@0: michael@0: EventUtils.synthesizeKey("VK_A", { type: "keydown" }); michael@0: EventUtils.synthesizeKey("VK_LEFT", { type: "keydown" }); michael@0: instance.controller._update(); michael@0: michael@0: ok(!isEqualVec(tran(), prev_tran), michael@0: "After a translation key is pressed, the vector should change."); michael@0: ok(!isEqualVec(rot(), prev_rot), michael@0: "After a rotation key is pressed, the quaternion should change."); michael@0: michael@0: save(); michael@0: michael@0: michael@0: cancellingEvent(); michael@0: instance.controller._update(); michael@0: michael@0: ok(!isEqualVec(tran(), prev_tran), michael@0: "Even if the canvas lost focus, the vector has some inertia."); michael@0: ok(!isEqualVec(rot(), prev_rot), michael@0: "Even if the canvas lost focus, the quaternion has some inertia."); michael@0: michael@0: save(); michael@0: michael@0: michael@0: while (!isEqualVec(tran(), prev_tran) || michael@0: !isEqualVec(rot(), prev_rot)) { michael@0: instance.controller._update(); michael@0: save(); michael@0: } michael@0: michael@0: ok(isEqualVec(tran(), prev_tran) && isEqualVec(rot(), prev_rot), michael@0: "After focus lost, the transforms inertia eventually stops."); michael@0: } michael@0: michael@0: info("Setting typeaheadfind to true."); michael@0: michael@0: Services.prefs.setBoolPref("accessibility.typeaheadfind", true); michael@0: testEventCancel(function() { michael@0: EventUtils.synthesizeKey("T", { type: "keydown", altKey: 1 }); michael@0: }); michael@0: testEventCancel(function() { michael@0: EventUtils.synthesizeKey("I", { type: "keydown", ctrlKey: 1 }); michael@0: }); michael@0: testEventCancel(function() { michael@0: EventUtils.synthesizeKey("L", { type: "keydown", metaKey: 1 }); michael@0: }); michael@0: testEventCancel(function() { michael@0: EventUtils.synthesizeKey("T", { type: "keydown", shiftKey: 1 }); michael@0: }); michael@0: michael@0: info("Setting typeaheadfind to false."); michael@0: michael@0: Services.prefs.setBoolPref("accessibility.typeaheadfind", false); michael@0: testEventCancel(function() { michael@0: EventUtils.synthesizeKey("T", { type: "keydown", altKey: 1 }); michael@0: }); michael@0: testEventCancel(function() { michael@0: EventUtils.synthesizeKey("I", { type: "keydown", ctrlKey: 1 }); michael@0: }); michael@0: testEventCancel(function() { michael@0: EventUtils.synthesizeKey("L", { type: "keydown", metaKey: 1 }); michael@0: }); michael@0: testEventCancel(function() { michael@0: EventUtils.synthesizeKey("T", { type: "keydown", shiftKey: 1 }); michael@0: }); michael@0: michael@0: info("Testing if loosing focus halts any stacked arcball animations."); michael@0: michael@0: testEventCancel(function() { michael@0: gBrowser.selectedBrowser.contentWindow.focus(); michael@0: }); michael@0: }, michael@0: onEnd: function() michael@0: { michael@0: cleanup(); michael@0: } michael@0: }, true, 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 cleanup() { michael@0: gBrowser.removeCurrentTab(); michael@0: finish(); michael@0: }