Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3 "use strict";
5 let tiltOpened = false;
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 }
17 requestLongerTimeout(10);
18 waitForExplicitFinish();
20 createTab(function() {
21 createTilt({
22 onTiltOpen: function(instance)
23 {
24 tiltOpened = true;
26 performTest(instance.presenter.canvas,
27 instance.controller.arcball, function() {
29 info("Killing arcball reset test.");
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 }
43 function performTest(canvas, arcball, callback) {
44 is(document.activeElement, canvas,
45 "The visualizer canvas should be focused when performing this test.");
48 info("Starting arcball reset test.");
50 // start translating and rotating sometime at random
52 window.setTimeout(function() {
53 info("Synthesizing key down events.");
55 EventUtils.synthesizeKey("VK_W", { type: "keydown" });
56 EventUtils.synthesizeKey("VK_LEFT", { type: "keydown" });
58 // wait for some arcball translations and rotations to happen
60 window.setTimeout(function() {
61 info("Synthesizing key up events.");
63 EventUtils.synthesizeKey("VK_W", { type: "keyup" });
64 EventUtils.synthesizeKey("VK_LEFT", { type: "keyup" });
66 // ok, transformations finished, we can now try to reset the model view
68 window.setTimeout(function() {
69 info("Synthesizing arcball reset key press.");
71 arcball._onResetStart = function() {
72 info("Starting arcball reset animation.");
73 };
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 };
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.");
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.");
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.");
107 ok(isApproxVec([arcball._zoomAmount], [0]),
108 "The arcball _zoomAmount field wasn't reset correctly.");
110 executeSoon(function() {
111 info("Finishing arcball reset test.");
112 callback();
113 });
114 };
116 EventUtils.synthesizeKey("VK_R", { type: "keydown" });
118 }, Math.random() * 1000); // leave enough time for transforms to happen
119 }, Math.random() * 1000);
120 }, Math.random() * 1000);
121 }
123 function cleanup() {
124 info("Cleaning up arcball reset test.");
126 if (tiltOpened) { Services.obs.removeObserver(cleanup, DESTROYED); }
127 gBrowser.removeCurrentTab();
128 finish();
129 }