browser/devtools/tilt/test/browser_tilt_controller.js

Wed, 31 Dec 2014 06:55:46 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:46 +0100
changeset 1
ca08bd8f51b2
permissions
-rw-r--r--

Added tag TORBROWSER_REPLICA for changeset 6474c204b198

     1 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     3 "use strict";
     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   }
    15   waitForExplicitFinish();
    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]);
    25         function tran() {
    26           return instance.presenter.transforms.translation;
    27         }
    29         function rot() {
    30           return instance.presenter.transforms.rotation;
    31         }
    33         function save() {
    34           prev_tran = vec3.create(tran());
    35           prev_rot = quat4.create(rot());
    36         }
    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.");
    44         function testEventCancel(cancellingEvent) {
    45           is(document.activeElement, canvas,
    46             "The visualizer canvas should be focused when performing this test.");
    48           EventUtils.synthesizeKey("VK_A", { type: "keydown" });
    49           EventUtils.synthesizeKey("VK_LEFT", { type: "keydown" });
    50           instance.controller._update();
    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.");
    57           save();
    60           cancellingEvent();
    61           instance.controller._update();
    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.");
    68           save();
    71           while (!isEqualVec(tran(), prev_tran) ||
    72                  !isEqualVec(rot(), prev_rot)) {
    73             instance.controller._update();
    74             save();
    75           }
    77           ok(isEqualVec(tran(), prev_tran) && isEqualVec(rot(), prev_rot),
    78             "After focus lost, the transforms inertia eventually stops.");
    79         }
    81         info("Setting typeaheadfind to true.");
    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         });
    97         info("Setting typeaheadfind to false.");
    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         });
   113         info("Testing if loosing focus halts any stacked arcball animations.");
   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 }
   131 function cleanup() {
   132   gBrowser.removeCurrentTab();
   133   finish();
   134 }

mercurial