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