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

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

mercurial