summaryrefslogtreecommitdiffstats
path: root/dom/events/test/marionette
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/events/test/marionette
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/events/test/marionette')
-rw-r--r--dom/events/test/marionette/head.js142
-rw-r--r--dom/events/test/marionette/manifest.ini4
-rw-r--r--dom/events/test/marionette/test_sensor_orientation.js53
3 files changed, 199 insertions, 0 deletions
diff --git a/dom/events/test/marionette/head.js b/dom/events/test/marionette/head.js
new file mode 100644
index 000000000..c2357f898
--- /dev/null
+++ b/dom/events/test/marionette/head.js
@@ -0,0 +1,142 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+const {Cc: Cc, Ci: Ci, Cr: Cr, Cu: Cu} = SpecialPowers;
+
+var Promise = Cu.import("resource://gre/modules/Promise.jsm").Promise;
+
+var _pendingEmulatorCmdCount = 0;
+
+/**
+ * Send emulator command with safe guard.
+ *
+ * We should only call |finish()| after all emulator command transactions
+ * end, so here comes with the pending counter. Resolve when the emulator
+ * gives positive response, and reject otherwise.
+ *
+ * Fulfill params:
+ * result -- an array of emulator response lines.
+ * Reject params:
+ * result -- an array of emulator response lines.
+ *
+ * @return A deferred promise.
+ */
+function runEmulatorCmdSafe(aCommand) {
+ let deferred = Promise.defer();
+
+ ++_pendingEmulatorCmdCount;
+ runEmulatorCmd(aCommand, function(aResult) {
+ --_pendingEmulatorCmdCount;
+
+ ok(true, "Emulator response: " + JSON.stringify(aResult));
+ if (Array.isArray(aResult) &&
+ aResult[aResult.length - 1] === "OK") {
+ deferred.resolve(aResult);
+ } else {
+ deferred.reject(aResult);
+ }
+ });
+
+ return deferred.promise;
+}
+
+/**
+ * Get emulator sensor values of a named sensor.
+ *
+ * Fulfill params:
+ * result -- an array of emulator sensor values.
+ * Reject params: (none)
+ *
+ * @param aSensorName
+ * A string name of the sensor. Availables are: "acceleration"
+ * "magnetic-field", "orientation", "temperature", "proximity".
+ *
+ * @return A deferred promise.
+ */
+function getEmulatorSensorValues(aSensorName) {
+ return runEmulatorCmdSafe("sensor get " + aSensorName)
+ .then(function(aResult) {
+ // aResult = ["orientation = 0:0:0", "OK"]
+ return aResult[0].split(" ")[2].split(":").map(function(aElement) {
+ return parseInt(aElement, 10);
+ });
+ });
+}
+
+/**
+ * Convenient alias function for getting orientation sensor values.
+ */
+function getEmulatorOrientationValues() {
+ return getEmulatorSensorValues("orientation");
+}
+
+/**
+ * Set emulator orientation sensor values.
+ *
+ * Fulfill params: (none)
+ * Reject params: (none)
+ *
+ * @param aAzimuth
+ * @param aPitch
+ * @param aRoll
+ *
+ * @return A deferred promise.
+ */
+function setEmulatorOrientationValues(aAzimuth, aPitch, aRoll) {
+ let cmd = "sensor set orientation " + aAzimuth + ":" + aPitch + ":" + aRoll;
+ return runEmulatorCmdSafe(cmd);
+}
+
+/**
+ * Wait for a named window event.
+ *
+ * Resolve if that named event occurs. Never reject.
+ *
+ * Forfill params: the DOMEvent passed.
+ *
+ * @param aEventName
+ * A string event name.
+ *
+ * @return A deferred promise.
+ */
+function waitForWindowEvent(aEventName) {
+ let deferred = Promise.defer();
+
+ window.addEventListener(aEventName, function onevent(aEvent) {
+ window.removeEventListener(aEventName, onevent);
+
+ ok(true, "Window event '" + aEventName + "' got.");
+ deferred.resolve(aEvent);
+ });
+
+ return deferred.promise;
+}
+
+/**
+ * Wait for pending emulator transactions and call |finish()|.
+ */
+function cleanUp() {
+ // Use ok here so that we have at least one test run.
+ ok(true, ":: CLEANING UP ::");
+
+ waitFor(finish, function() {
+ return _pendingEmulatorCmdCount === 0;
+ });
+}
+
+/**
+ * Basic test routine helper.
+ *
+ * This helper does nothing but clean-ups.
+ *
+ * @param aTestCaseMain
+ * A function that takes no parameter.
+ */
+function startTestBase(aTestCaseMain) {
+ Promise.resolve()
+ .then(aTestCaseMain)
+ .then(cleanUp, function() {
+ ok(false, 'promise rejects during test.');
+ cleanUp();
+ });
+}
diff --git a/dom/events/test/marionette/manifest.ini b/dom/events/test/marionette/manifest.ini
new file mode 100644
index 000000000..b0ec98d99
--- /dev/null
+++ b/dom/events/test/marionette/manifest.ini
@@ -0,0 +1,4 @@
+[DEFAULT]
+run-if = buildapp == 'b2g'
+
+[test_sensor_orientation.js]
diff --git a/dom/events/test/marionette/test_sensor_orientation.js b/dom/events/test/marionette/test_sensor_orientation.js
new file mode 100644
index 000000000..70df0ccd3
--- /dev/null
+++ b/dom/events/test/marionette/test_sensor_orientation.js
@@ -0,0 +1,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));
+});