summaryrefslogtreecommitdiffstats
path: root/dom/events/test/marionette/test_sensor_orientation.js
blob: 70df0ccd315022e9c885e4e09687a12ef26cd4a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

MARIONETTE_TIMEOUT = 120000;
MARIONETTE_HEAD_JS = 'head.js';

function doTest(aAzimuth, aPitch, aRoll) {
  log("Testing [azimuth, pitch, roll] = " + Array.slice(arguments));

  return setEmulatorOrientationValues(aAzimuth, aPitch, aRoll)
    .then(() => waitForWindowEvent("deviceorientation"))
    .then(function(aEvent) {
      is(aEvent.alpha, aAzimuth, "azimuth");
      is(aEvent.beta,  aPitch, "pitch");
      is(aEvent.gamma, aRoll, "roll");
    });
}

function testAllPermutations() {
  const angles = [-180, -90, 0, 90, 180];
  let promise = Promise.resolve();
  for (let i = 0; i < angles.length; i++) {
    for (let j = 0; j < angles.length; j++) {
      for (let k = 0; k < angles.length; k++) {
        promise =
          promise.then(doTest.bind(null, angles[i], angles[j], angles[k]));
      }
    }
  }
  return promise;
}

startTestBase(function() {
  let origValues;

  return Promise.resolve()

    // Retrieve original status.
    .then(() => getEmulatorOrientationValues())
    .then(function(aValues) {
      origValues = aValues;
      is(typeof origValues, "object", "typeof origValues");
      is(origValues.length, 3, "origValues.length");
    })

    // Test original status
    .then(() => doTest.apply(null, origValues))

    .then(testAllPermutations)

    // Restore original status.
    .then(() => setEmulatorOrientationValues.apply(null, origValues));
});