1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/tilt/test/browser_tilt_controller.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,134 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 +"use strict"; 1.7 + 1.8 +function test() { 1.9 + if (!isTiltEnabled()) { 1.10 + info("Skipping controller test because Tilt isn't enabled."); 1.11 + return; 1.12 + } 1.13 + if (!isWebGLSupported()) { 1.14 + info("Skipping controller test because WebGL isn't supported."); 1.15 + return; 1.16 + } 1.17 + 1.18 + waitForExplicitFinish(); 1.19 + 1.20 + createTab(function() { 1.21 + createTilt({ 1.22 + onTiltOpen: function(instance) 1.23 + { 1.24 + let canvas = instance.presenter.canvas; 1.25 + let prev_tran = vec3.create([0, 0, 0]); 1.26 + let prev_rot = quat4.create([0, 0, 0, 1]); 1.27 + 1.28 + function tran() { 1.29 + return instance.presenter.transforms.translation; 1.30 + } 1.31 + 1.32 + function rot() { 1.33 + return instance.presenter.transforms.rotation; 1.34 + } 1.35 + 1.36 + function save() { 1.37 + prev_tran = vec3.create(tran()); 1.38 + prev_rot = quat4.create(rot()); 1.39 + } 1.40 + 1.41 + ok(isEqualVec(tran(), prev_tran), 1.42 + "At init, the translation should be zero."); 1.43 + ok(isEqualVec(rot(), prev_rot), 1.44 + "At init, the rotation should be zero."); 1.45 + 1.46 + 1.47 + function testEventCancel(cancellingEvent) { 1.48 + is(document.activeElement, canvas, 1.49 + "The visualizer canvas should be focused when performing this test."); 1.50 + 1.51 + EventUtils.synthesizeKey("VK_A", { type: "keydown" }); 1.52 + EventUtils.synthesizeKey("VK_LEFT", { type: "keydown" }); 1.53 + instance.controller._update(); 1.54 + 1.55 + ok(!isEqualVec(tran(), prev_tran), 1.56 + "After a translation key is pressed, the vector should change."); 1.57 + ok(!isEqualVec(rot(), prev_rot), 1.58 + "After a rotation key is pressed, the quaternion should change."); 1.59 + 1.60 + save(); 1.61 + 1.62 + 1.63 + cancellingEvent(); 1.64 + instance.controller._update(); 1.65 + 1.66 + ok(!isEqualVec(tran(), prev_tran), 1.67 + "Even if the canvas lost focus, the vector has some inertia."); 1.68 + ok(!isEqualVec(rot(), prev_rot), 1.69 + "Even if the canvas lost focus, the quaternion has some inertia."); 1.70 + 1.71 + save(); 1.72 + 1.73 + 1.74 + while (!isEqualVec(tran(), prev_tran) || 1.75 + !isEqualVec(rot(), prev_rot)) { 1.76 + instance.controller._update(); 1.77 + save(); 1.78 + } 1.79 + 1.80 + ok(isEqualVec(tran(), prev_tran) && isEqualVec(rot(), prev_rot), 1.81 + "After focus lost, the transforms inertia eventually stops."); 1.82 + } 1.83 + 1.84 + info("Setting typeaheadfind to true."); 1.85 + 1.86 + Services.prefs.setBoolPref("accessibility.typeaheadfind", true); 1.87 + testEventCancel(function() { 1.88 + EventUtils.synthesizeKey("T", { type: "keydown", altKey: 1 }); 1.89 + }); 1.90 + testEventCancel(function() { 1.91 + EventUtils.synthesizeKey("I", { type: "keydown", ctrlKey: 1 }); 1.92 + }); 1.93 + testEventCancel(function() { 1.94 + EventUtils.synthesizeKey("L", { type: "keydown", metaKey: 1 }); 1.95 + }); 1.96 + testEventCancel(function() { 1.97 + EventUtils.synthesizeKey("T", { type: "keydown", shiftKey: 1 }); 1.98 + }); 1.99 + 1.100 + info("Setting typeaheadfind to false."); 1.101 + 1.102 + Services.prefs.setBoolPref("accessibility.typeaheadfind", false); 1.103 + testEventCancel(function() { 1.104 + EventUtils.synthesizeKey("T", { type: "keydown", altKey: 1 }); 1.105 + }); 1.106 + testEventCancel(function() { 1.107 + EventUtils.synthesizeKey("I", { type: "keydown", ctrlKey: 1 }); 1.108 + }); 1.109 + testEventCancel(function() { 1.110 + EventUtils.synthesizeKey("L", { type: "keydown", metaKey: 1 }); 1.111 + }); 1.112 + testEventCancel(function() { 1.113 + EventUtils.synthesizeKey("T", { type: "keydown", shiftKey: 1 }); 1.114 + }); 1.115 + 1.116 + info("Testing if loosing focus halts any stacked arcball animations."); 1.117 + 1.118 + testEventCancel(function() { 1.119 + gBrowser.selectedBrowser.contentWindow.focus(); 1.120 + }); 1.121 + }, 1.122 + onEnd: function() 1.123 + { 1.124 + cleanup(); 1.125 + } 1.126 + }, true, function suddenDeath() 1.127 + { 1.128 + info("Tilt could not be initialized properly."); 1.129 + cleanup(); 1.130 + }); 1.131 + }); 1.132 +} 1.133 + 1.134 +function cleanup() { 1.135 + gBrowser.removeCurrentTab(); 1.136 + finish(); 1.137 +}