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