dom/events/test/marionette/test_sensor_orientation.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 MARIONETTE_TIMEOUT = 120000;
     5 MARIONETTE_HEAD_JS = 'head.js';
     7 function doTest(aAzimuth, aPitch, aRoll) {
     8   log("Testing [azimuth, pitch, roll] = " + Array.slice(arguments));
    10   return setEmulatorOrientationValues(aAzimuth, aPitch, aRoll)
    11     .then(() => waitForWindowEvent("deviceorientation"))
    12     .then(function(aEvent) {
    13       is(aEvent.alpha, aAzimuth, "azimuth");
    14       is(aEvent.beta,  aPitch, "pitch");
    15       is(aEvent.gamma, aRoll, "roll");
    16     });
    17 }
    19 function testAllPermutations() {
    20   const angles = [-180, -90, 0, 90, 180];
    21   let promise = Promise.resolve();
    22   for (let i = 0; i < angles.length; i++) {
    23     for (let j = 0; j < angles.length; j++) {
    24       for (let k = 0; k < angles.length; k++) {
    25         promise =
    26           promise.then(doTest.bind(null, angles[i], angles[j], angles[k]));
    27       }
    28     }
    29   }
    30   return promise;
    31 }
    33 startTestBase(function() {
    34   let origValues;
    36   return Promise.resolve()
    38     // Retrieve original status.
    39     .then(() => getEmulatorOrientationValues())
    40     .then(function(aValues) {
    41       origValues = aValues;
    42       is(typeof origValues, "object", "typeof origValues");
    43       is(origValues.length, 3, "origValues.length");
    44     })
    46     // Test original status
    47     .then(() => doTest.apply(null, origValues))
    49     .then(testAllPermutations)
    51     // Restore original status.
    52     .then(() => setEmulatorOrientationValues.apply(null, origValues));
    53 });

mercurial