dom/events/test/marionette/test_sensor_orientation.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/marionette/test_sensor_orientation.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,53 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +MARIONETTE_TIMEOUT = 120000;
     1.8 +MARIONETTE_HEAD_JS = 'head.js';
     1.9 +
    1.10 +function doTest(aAzimuth, aPitch, aRoll) {
    1.11 +  log("Testing [azimuth, pitch, roll] = " + Array.slice(arguments));
    1.12 +
    1.13 +  return setEmulatorOrientationValues(aAzimuth, aPitch, aRoll)
    1.14 +    .then(() => waitForWindowEvent("deviceorientation"))
    1.15 +    .then(function(aEvent) {
    1.16 +      is(aEvent.alpha, aAzimuth, "azimuth");
    1.17 +      is(aEvent.beta,  aPitch, "pitch");
    1.18 +      is(aEvent.gamma, aRoll, "roll");
    1.19 +    });
    1.20 +}
    1.21 +
    1.22 +function testAllPermutations() {
    1.23 +  const angles = [-180, -90, 0, 90, 180];
    1.24 +  let promise = Promise.resolve();
    1.25 +  for (let i = 0; i < angles.length; i++) {
    1.26 +    for (let j = 0; j < angles.length; j++) {
    1.27 +      for (let k = 0; k < angles.length; k++) {
    1.28 +        promise =
    1.29 +          promise.then(doTest.bind(null, angles[i], angles[j], angles[k]));
    1.30 +      }
    1.31 +    }
    1.32 +  }
    1.33 +  return promise;
    1.34 +}
    1.35 +
    1.36 +startTestBase(function() {
    1.37 +  let origValues;
    1.38 +
    1.39 +  return Promise.resolve()
    1.40 +
    1.41 +    // Retrieve original status.
    1.42 +    .then(() => getEmulatorOrientationValues())
    1.43 +    .then(function(aValues) {
    1.44 +      origValues = aValues;
    1.45 +      is(typeof origValues, "object", "typeof origValues");
    1.46 +      is(origValues.length, 3, "origValues.length");
    1.47 +    })
    1.48 +
    1.49 +    // Test original status
    1.50 +    .then(() => doTest.apply(null, origValues))
    1.51 +
    1.52 +    .then(testAllPermutations)
    1.53 +
    1.54 +    // Restore original status.
    1.55 +    .then(() => setEmulatorOrientationValues.apply(null, origValues));
    1.56 +});

mercurial