browser/devtools/tilt/test/browser_tilt_controller.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 function test() {
michael@0 6 if (!isTiltEnabled()) {
michael@0 7 info("Skipping controller test because Tilt isn't enabled.");
michael@0 8 return;
michael@0 9 }
michael@0 10 if (!isWebGLSupported()) {
michael@0 11 info("Skipping controller test because WebGL isn't supported.");
michael@0 12 return;
michael@0 13 }
michael@0 14
michael@0 15 waitForExplicitFinish();
michael@0 16
michael@0 17 createTab(function() {
michael@0 18 createTilt({
michael@0 19 onTiltOpen: function(instance)
michael@0 20 {
michael@0 21 let canvas = instance.presenter.canvas;
michael@0 22 let prev_tran = vec3.create([0, 0, 0]);
michael@0 23 let prev_rot = quat4.create([0, 0, 0, 1]);
michael@0 24
michael@0 25 function tran() {
michael@0 26 return instance.presenter.transforms.translation;
michael@0 27 }
michael@0 28
michael@0 29 function rot() {
michael@0 30 return instance.presenter.transforms.rotation;
michael@0 31 }
michael@0 32
michael@0 33 function save() {
michael@0 34 prev_tran = vec3.create(tran());
michael@0 35 prev_rot = quat4.create(rot());
michael@0 36 }
michael@0 37
michael@0 38 ok(isEqualVec(tran(), prev_tran),
michael@0 39 "At init, the translation should be zero.");
michael@0 40 ok(isEqualVec(rot(), prev_rot),
michael@0 41 "At init, the rotation should be zero.");
michael@0 42
michael@0 43
michael@0 44 function testEventCancel(cancellingEvent) {
michael@0 45 is(document.activeElement, canvas,
michael@0 46 "The visualizer canvas should be focused when performing this test.");
michael@0 47
michael@0 48 EventUtils.synthesizeKey("VK_A", { type: "keydown" });
michael@0 49 EventUtils.synthesizeKey("VK_LEFT", { type: "keydown" });
michael@0 50 instance.controller._update();
michael@0 51
michael@0 52 ok(!isEqualVec(tran(), prev_tran),
michael@0 53 "After a translation key is pressed, the vector should change.");
michael@0 54 ok(!isEqualVec(rot(), prev_rot),
michael@0 55 "After a rotation key is pressed, the quaternion should change.");
michael@0 56
michael@0 57 save();
michael@0 58
michael@0 59
michael@0 60 cancellingEvent();
michael@0 61 instance.controller._update();
michael@0 62
michael@0 63 ok(!isEqualVec(tran(), prev_tran),
michael@0 64 "Even if the canvas lost focus, the vector has some inertia.");
michael@0 65 ok(!isEqualVec(rot(), prev_rot),
michael@0 66 "Even if the canvas lost focus, the quaternion has some inertia.");
michael@0 67
michael@0 68 save();
michael@0 69
michael@0 70
michael@0 71 while (!isEqualVec(tran(), prev_tran) ||
michael@0 72 !isEqualVec(rot(), prev_rot)) {
michael@0 73 instance.controller._update();
michael@0 74 save();
michael@0 75 }
michael@0 76
michael@0 77 ok(isEqualVec(tran(), prev_tran) && isEqualVec(rot(), prev_rot),
michael@0 78 "After focus lost, the transforms inertia eventually stops.");
michael@0 79 }
michael@0 80
michael@0 81 info("Setting typeaheadfind to true.");
michael@0 82
michael@0 83 Services.prefs.setBoolPref("accessibility.typeaheadfind", true);
michael@0 84 testEventCancel(function() {
michael@0 85 EventUtils.synthesizeKey("T", { type: "keydown", altKey: 1 });
michael@0 86 });
michael@0 87 testEventCancel(function() {
michael@0 88 EventUtils.synthesizeKey("I", { type: "keydown", ctrlKey: 1 });
michael@0 89 });
michael@0 90 testEventCancel(function() {
michael@0 91 EventUtils.synthesizeKey("L", { type: "keydown", metaKey: 1 });
michael@0 92 });
michael@0 93 testEventCancel(function() {
michael@0 94 EventUtils.synthesizeKey("T", { type: "keydown", shiftKey: 1 });
michael@0 95 });
michael@0 96
michael@0 97 info("Setting typeaheadfind to false.");
michael@0 98
michael@0 99 Services.prefs.setBoolPref("accessibility.typeaheadfind", false);
michael@0 100 testEventCancel(function() {
michael@0 101 EventUtils.synthesizeKey("T", { type: "keydown", altKey: 1 });
michael@0 102 });
michael@0 103 testEventCancel(function() {
michael@0 104 EventUtils.synthesizeKey("I", { type: "keydown", ctrlKey: 1 });
michael@0 105 });
michael@0 106 testEventCancel(function() {
michael@0 107 EventUtils.synthesizeKey("L", { type: "keydown", metaKey: 1 });
michael@0 108 });
michael@0 109 testEventCancel(function() {
michael@0 110 EventUtils.synthesizeKey("T", { type: "keydown", shiftKey: 1 });
michael@0 111 });
michael@0 112
michael@0 113 info("Testing if loosing focus halts any stacked arcball animations.");
michael@0 114
michael@0 115 testEventCancel(function() {
michael@0 116 gBrowser.selectedBrowser.contentWindow.focus();
michael@0 117 });
michael@0 118 },
michael@0 119 onEnd: function()
michael@0 120 {
michael@0 121 cleanup();
michael@0 122 }
michael@0 123 }, true, function suddenDeath()
michael@0 124 {
michael@0 125 info("Tilt could not be initialized properly.");
michael@0 126 cleanup();
michael@0 127 });
michael@0 128 });
michael@0 129 }
michael@0 130
michael@0 131 function cleanup() {
michael@0 132 gBrowser.removeCurrentTab();
michael@0 133 finish();
michael@0 134 }

mercurial