summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/orientation-event
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/orientation-event
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/orientation-event')
-rw-r--r--testing/web-platform/tests/orientation-event/META.yml4
-rw-r--r--testing/web-platform/tests/orientation-event/README.md8
-rw-r--r--testing/web-platform/tests/orientation-event/device-orientation-events-of-detached-documents.https.html33
-rw-r--r--testing/web-platform/tests/orientation-event/device-orientation-events-unavailable-on-insecure-origins.html55
-rw-r--r--testing/web-platform/tests/orientation-event/idlharness.https.window.js19
-rw-r--r--testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html30
-rw-r--r--testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html49
-rw-r--r--testing/web-platform/tests/orientation-event/motion/create-event.https.html41
-rw-r--r--testing/web-platform/tests/orientation-event/motion/free-fall-manual.https.html48
-rw-r--r--testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.https.html26
-rw-r--r--testing/web-platform/tests/orientation-event/motion/null-values.https.html39
-rw-r--r--testing/web-platform/tests/orientation-event/motion/optional-event-properties.https.html257
-rw-r--r--testing/web-platform/tests/orientation-event/motion/page-visibility-manual.https.html28
-rw-r--r--testing/web-platform/tests/orientation-event/motion/requestPermission.https.window.js48
-rw-r--r--testing/web-platform/tests/orientation-event/motion/screen-upmost-manual.https.html51
-rw-r--r--testing/web-platform/tests/orientation-event/motion/screen-upright-manual.https.html50
-rw-r--r--testing/web-platform/tests/orientation-event/motion/t025-manual.https.html38
-rw-r--r--testing/web-platform/tests/orientation-event/motion/t028-manual.https.html36
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/absolute-fallback.https.html19
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/add-listener-from-callback.https.html47
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/basic-operation-absolute.https.html28
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/basic-operation.https.html29
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/create-event.https.html40
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/horizontal-surface-manual.https.html34
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/multiple-event-listeners.https.html22
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/no-synchronous-events.https.html27
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/null-values.https.html30
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/optional-event-properties.https.html73
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/page-visibility-manual.https.html28
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/requestPermission.https.window.js48
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/t006-manual.https.html30
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/t009-manual.https.html30
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/t010-manual.https.html30
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/t012-manual.https.html41
-rw-r--r--testing/web-platform/tests/orientation-event/orientation/updates.https.html19
-rw-r--r--testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js188
36 files changed, 1623 insertions, 0 deletions
diff --git a/testing/web-platform/tests/orientation-event/META.yml b/testing/web-platform/tests/orientation-event/META.yml
new file mode 100644
index 0000000000..88014849d0
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/META.yml
@@ -0,0 +1,4 @@
+spec: https://w3c.github.io/deviceorientation/
+suggested_reviewers:
+ - reillyeon
+ - timvolodine
diff --git a/testing/web-platform/tests/orientation-event/README.md b/testing/web-platform/tests/orientation-event/README.md
new file mode 100644
index 0000000000..14ea2f5117
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/README.md
@@ -0,0 +1,8 @@
+The `resources/orientation-event-helpers.js` tests depend on the implementation of
+the `GenericSensorTest` interface which is defined in [README.md](../generic-sensor/README.md).
+
+The Chromium implementation of the `GenericSensorTest` interface is located in
+[generic_sensor_mocks.js](../resources/chromium/generic_sensor_mocks.js).
+
+Other browser vendors should provide their own implementations of
+the `GenericSensorTest` interface.
diff --git a/testing/web-platform/tests/orientation-event/device-orientation-events-of-detached-documents.https.html b/testing/web-platform/tests/orientation-event/device-orientation-events-of-detached-documents.https.html
new file mode 100644
index 0000000000..c7ad5ecaef
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/device-orientation-events-of-detached-documents.https.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<title>Device sensor event listeners for `window` of detached documents.</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="resources/orientation-event-helpers.js"></script>
+<script>
+
+sensor_test(async t => {
+ const childFrame = document.createElement('iframe');
+ childFrame.src = "/common/blank.html";
+ document.body.append(childFrame);
+
+ const childLoadWatcher = new EventWatcher(t, childFrame, ["load"]);
+ await childLoadWatcher.wait_for("load");
+
+ const contentWindow = childFrame.contentWindow;
+ const contentDocument = childFrame.contentDocument;
+
+ document.body.remove(childFrame);
+
+ assert_not_equals(contentWindow, null);
+ assert_not_equals(contentDocument, null);
+ assert_equals(contentDocument.defaultView, null);
+
+ contentWindow.addEventListener("devicemotion", () => {});
+ contentWindow.addEventListener("deviceorientation", () => {});
+ contentWindow.addEventListener("deviceorientationabsolute", () => {});
+
+}, 'Adding an event listener on the window of a detached document does not crash.');
+
+</script>
diff --git a/testing/web-platform/tests/orientation-event/device-orientation-events-unavailable-on-insecure-origins.html b/testing/web-platform/tests/orientation-event/device-orientation-events-unavailable-on-insecure-origins.html
new file mode 100644
index 0000000000..571a388f64
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/device-orientation-events-unavailable-on-insecure-origins.html
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<title>Device Sensor Events not exposed to insecure origins</title>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/common/get-host-info.sub.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="resources/orientation-event-helpers.js"></script>
+<script>
+
+if (window.location.origin != get_host_info().HTTP_ORIGIN) {
+ window.location = get_host_info().HTTP_ORIGIN + window.location.pathname;
+ promise_test(_ => new Promise(_ => {}), "Stall tests on the wrong host.");
+} else {
+ test(() => {
+ assert_false('DeviceMotionEvent' in window);
+ assert_false('DeviceOrientationEvent' in window);
+ assert_false('DeviceOrientationAbsoluteEvent' in window);
+ assert_false('DeviceMotionEventAcceleration' in window);
+ assert_false('DeviceMotionEventRotationRate' in window);
+ assert_false('ondevicemotion' in window);
+ assert_false('ondeviceorientation' in window);
+ assert_false('ondeviceorientationabsolute' in window);
+ }, 'Event interfaces and event handlers are not exposed on `window`.');
+
+ sensor_test(async (t, sensorProvider) => {
+ const FAKE_ACCELERATION_DATA = [1, 2, 3];
+ const FAKE_LINEAR_ACCELERATION_DATA = [4, 5, 6];
+ const FAKE_GYROSCOPE_DATA = [7, 8, 9];
+
+ window.ondevicemotion = t.unreached_func("devicemotion event should not be fired.");
+ setMockSensorDataForType(sensorProvider, 'Accelerometer', FAKE_ACCELERATION_DATA);
+ setMockSensorDataForType(sensorProvider, 'LinearAccelerationSensor', FAKE_LINEAR_ACCELERATION_DATA);
+ setMockSensorDataForType(sensorProvider, 'Gyroscope', FAKE_GYROSCOPE_DATA);
+
+ await new Promise(r => t.step_timeout(r, 1000));
+ }, 'addEventListener() for `devicemotion` does not crash but the handler never fires.');
+
+ sensor_test(async (t, sensorProvider) => {
+ const FAKE_ORIENTATION_DATA = [1.1, 2.2, 3.3];
+ window.ondeviceorientation = t.unreached_func("deviceorientation event should not be fired.");
+ setMockSensorDataForType(sensorProvider, 'RelativeOrientationEulerAngles', FAKE_ORIENTATION_DATA);
+
+ await new Promise(r => t.step_timeout(r, 1000));
+ }, 'addEventListener() for `deviceorientation` does not crash but the handler never fires.');
+
+ sensor_test(async (t, sensorProvider) => {
+ const FAKE_ORIENTATION_DATA = [1.1, 2.2, 3.3];
+ window.ondeviceorientationabsolute = t.unreached_func("deviceorientationabsolute event should not be fired.");
+ setMockSensorDataForType(sensorProvider, 'AbsoluteOrientationEulerAngles', FAKE_ORIENTATION_DATA);
+
+ await new Promise(r => t.step_timeout(r, 1000));
+ }, 'addEventListener() for `deviceorientationabsolute` does not crash but the handler never fires.');
+}
+</script>
diff --git a/testing/web-platform/tests/orientation-event/idlharness.https.window.js b/testing/web-platform/tests/orientation-event/idlharness.https.window.js
new file mode 100644
index 0000000000..ba816bb87c
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/idlharness.https.window.js
@@ -0,0 +1,19 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+// META: timeout=long
+
+// https://w3c.github.io/deviceorientation/spec-source-orientation.html
+
+'use strict';
+
+idl_test(
+ ['orientation-event'],
+ ['html', 'dom'],
+ idl_array => {
+ idl_array.add_objects({
+ Window: ['window'],
+ DeviceOrientationEvent: ['new DeviceOrientationEvent("foo")'],
+ DeviceMotionEvent: ['new DeviceMotionEvent("foo")'],
+ });
+ }
+);
diff --git a/testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html b/testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html
new file mode 100644
index 0000000000..3a895b9d09
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const motionData = generateMotionData(1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9);
+ setMockMotionData(sensorProvider, motionData);
+
+ return new Promise((resolve, reject) => {
+ let result = reject;
+ window.addEventListener('devicemotion', event1 => {
+ // Now we are in event dispatch.
+ assertEventEquals(event1, getExpectedMotionEvent(motionData));
+ window.addEventListener('devicemotion', event2 => {
+ // Not call until the outer function returns.
+ assertEventEquals(event2, getExpectedMotionEvent(motionData));
+ result();
+ });
+ });
+ result = resolve;
+ });
+}, 'Test no fire listeners added during event dispatch.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html b/testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html
new file mode 100644
index 0000000000..0803d7cc9b
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const motionData = generateMotionData(1.1, 2.1, 3.1,
+ 1.2, 2.2, 3.2,
+ 1.3, 2.3, 3.3);
+
+ let firstListener = null;
+ let secondListener = null;
+ let firstEventCount = 0;
+ let firstPromise = new Promise(resolve => {
+ firstListener = (event) => {
+ assert_true(event instanceof DeviceMotionEvent, 'event is DeviceMotionEvent');
+ assert_equals(event.type, 'devicemotion', 'event.type is devicemotion');
+ assert_true(event.target instanceof Window, 'event is fired on the window object');
+ assertEventEquals(event, getExpectedMotionEvent(motionData));
+ window.removeEventListener('devicemotion', firstListener);
+ if (++firstEventCount == 1) {
+ window.addEventListener('devicemotion', secondListener);
+ }
+ resolve(event);
+ };
+ });
+
+ let secondEventCount = 0;
+ let secondPromise = new Promise(resolve => {
+ secondListener = (event) => {
+ assertEventEquals(event, getExpectedMotionEvent(motionData));
+ window.removeEventListener('devicemotion', secondListener);
+ ++secondEventCount;
+ resolve(event);
+ };
+ });
+
+ setMockMotionData(sensorProvider, motionData);
+ window.addEventListener('devicemotion', firstListener);
+ await firstPromise;
+ await secondPromise;
+ assert_equals(firstEventCount, 1, "Too many events fired for the first listener");
+ assert_equals(secondEventCount, 1, "Too many events fired for the second listener");
+}, 'Tests that adding a new devicemotion event listener from a callback works as expected.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/motion/create-event.https.html b/testing/web-platform/tests/orientation-event/motion/create-event.https.html
new file mode 100644
index 0000000000..e8a2c469b1
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/create-event.https.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+'use strict';
+
+test(test => {
+ const event = document.createEvent('DeviceMotionEvent');
+ const newEvent = new CustomEvent("devicemotion", {
+ bubbles: false, cancelable: false,
+ acceleration: {x:1.5,y:2.5,z:3.5},
+ accelerationIncludingGravity: {x:4.5,y:5.5,z:6.5},
+ rotationRate: {alpha:7.5,beta:8.5,gamma:9.5},
+ interval: 0.5
+ });
+
+ assert_equals(typeof event, 'object');
+ assert_equals(Object.getPrototypeOf(event), DeviceMotionEvent.prototype);
+
+ assert_true('type' in event);
+ assert_true('bubbles' in event);
+ assert_true('cancelable' in event);
+ assert_true('acceleration' in event);
+ assert_true('accelerationIncludingGravity' in event);
+ assert_true('rotationRate' in event);
+ assert_true('interval' in event);
+
+ assert_equals(typeof newEvent.type, 'string');
+ assert_equals(newEvent.type, "devicemotion");
+ assert_equals(typeof newEvent.bubbles, 'boolean');
+ assert_false(event.bubbles);
+ assert_false(newEvent.bubbles);
+ assert_equals(typeof newEvent.cancelable, 'boolean');
+ assert_false(event.cancelable);
+ assert_false(newEvent.cancelable);
+ assert_equals(typeof event.acceleration, 'object');
+ assert_equals(typeof event.accelerationIncludingGravity, 'object');
+ assert_equals(typeof event.rotationRate, 'object');
+ assert_equals(typeof event.interval, 'number');
+}, 'Tests that document.createEvent() works with DeviceMotionEvent.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/motion/free-fall-manual.https.html b/testing/web-platform/tests/orientation-event/motion/free-fall-manual.https.html
new file mode 100644
index 0000000000..c71f61fa69
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/free-fall-manual.https.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>DeviceMotionEvent: A device in free-fall, with the screen horizontal and upmost</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author' title='Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-14 -->
+ </head>
+ <body>
+ <p>Free fall the device to run the test, with the screen horizontal and upmost.</p>
+ <div id="log"></div>
+ <script>
+ var t = async_test();
+ var run = false;
+
+ /*
+ * A device in free-fall, with the screen horizontal and upmost,
+ * has an accelerationIncludingGravity of zero and
+ * the following value for acceleration:
+ * {
+ * x: 0,
+ * y: 0,
+ * z: -9.81
+ * };
+ */
+ window.addEventListener("devicemotion", function(e) {
+ if (!run) {
+ run = true;
+ t.step(function() {
+ var gvt = e.accelerationIncludingGravity;
+ var acc = e.acceleration;
+
+ assert_approx_equals(gvt.x, 0, 1);
+ assert_approx_equals(gvt.y, 0, 1);
+ assert_approx_equals(gvt.z, 0, 1);
+
+ assert_approx_equals(acc.x, 0, 1);
+ assert_approx_equals(acc.y, 0, 1);
+ assert_approx_equals(acc.z, -9.81, 1.5);
+ });
+ t.done();
+ }
+ }, false);
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.https.html b/testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.https.html
new file mode 100644
index 0000000000..3b13d632ac
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.https.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const motionData1 = generateMotionData(1, 2, 3,
+ 4, 5, 6,
+ 7, 8, 9);
+ setMockMotionData(sensorProvider, motionData1);
+ await Promise.all([
+ waitForEvent(getExpectedMotionEvent(motionData1)),
+ waitForEvent(getExpectedMotionEvent(motionData1))
+ ]);
+
+ const motionData2 = generateMotionData(11, 12, 13,
+ 14, 15, 16,
+ 17, 18, 19);
+ setMockMotionData(sensorProvider, motionData2);
+ await waitForEvent(getExpectedMotionEvent(motionData2));
+}, 'Tests using multiple event handlers for the Device Motion API.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/motion/null-values.https.html b/testing/web-platform/tests/orientation-event/motion/null-values.https.html
new file mode 100644
index 0000000000..b6a2a1622f
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/null-values.https.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const motionData1 = generateMotionData(1, 2, 3,
+ null, null, null,
+ null, null, null);
+
+ const motionData2 = generateMotionData(null, null, null,
+ 1, 2, 3,
+ null, null, null);
+
+ const motionData3 = generateMotionData(null, null, null,
+ null, null, null,
+ 1, 2, 3);
+
+ const motionData4 = generateMotionData(null, null, null,
+ null, null, null,
+ null, null, null);
+
+ setMockMotionData(sensorProvider, motionData1);
+ await waitForEvent(getExpectedMotionEvent(motionData1));
+
+ setMockMotionData(sensorProvider, motionData2);
+ await waitForEvent(getExpectedMotionEvent(motionData2));
+
+ setMockMotionData(sensorProvider, motionData3);
+ await waitForEvent(getExpectedMotionEvent(motionData3));
+
+ setMockMotionData(sensorProvider, motionData4);
+ await waitForEvent(getExpectedMotionEvent(motionData4));
+}, 'Tests using null values for some or all of the event properties.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/motion/optional-event-properties.https.html b/testing/web-platform/tests/orientation-event/motion/optional-event-properties.https.html
new file mode 100644
index 0000000000..0a73721cb9
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/optional-event-properties.https.html
@@ -0,0 +1,257 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+'use strict';
+
+function ObjectThrowingException() {};
+ObjectThrowingException.prototype.valueOf = () => { throw new Error('valueOf threw exception'); }
+ObjectThrowingException.prototype.__defineGetter__("x", () => { throw new Error('x getter exception'); });
+ObjectThrowingException.prototype.__defineGetter__("alpha", () => { throw new Error('alpha getter exception'); });
+const objectThrowingException = new ObjectThrowingException();
+
+test(test => {
+ event = document.createEvent('DeviceMotionEvent');
+ assert_equals(event.type, "");
+ assert_equals(event.acceleration, null);
+ assert_equals(event.accelerationIncludingGravity, null);
+ assert_equals(event.rotationRate, null);
+ assert_equals(event.interval, 0);
+}, 'Tests creating a DeviceMotionEvent.');
+
+test(test => {
+ event = new DeviceMotionEvent('foo', {acceleration: {x: 0, y: 1, z: 2},
+ accelerationIncludingGravity: {x: 3, y: 4, z: 5},
+ rotationRate: {alpha: 6, beta: 7, gamma: 8},
+ interval: 9});
+ assert_equals(event.type, "foo");
+ assert_equals(event.acceleration.x, 0);
+ assert_equals(event.acceleration.y, 1);
+ assert_equals(event.acceleration.z, 2);
+ assert_equals(event.accelerationIncludingGravity.x, 3);
+ assert_equals(event.accelerationIncludingGravity.y, 4);
+ assert_equals(event.accelerationIncludingGravity.z, 5);
+ assert_equals(event.rotationRate.alpha, 6);
+ assert_equals(event.rotationRate.beta, 7);
+ assert_equals(event.rotationRate.gamma, 8);
+ assert_equals(event.interval, 9);
+}, 'Tests no missing value.');
+
+test(test => {
+ try {
+ event = new DeviceMotionEvent('', {acceleration: objectThrowingException,
+ accelerationIncludingGravity: {x: 3, z: 5},
+ rotationRate: {gamma: 8, beta: 7},
+ interval: 9});
+ assert_unreached("Invalid acceleration, must throw an Error exception");
+ } catch (e) {
+ assert_equals(e.name, "Error");
+ assert_equals(e.message, "x getter exception");
+ }
+}, 'Tests invalid acceleration.');
+
+test(test => {
+ try {
+ event = new DeviceMotionEvent('', {acceleration: {x: 0, y: 1, z: 2},
+ accelerationIncludingGravity: objectThrowingException,
+ rotationRate: {gamma: 8, beta: 7},
+ interval: 9});
+ assert_unreached("Invalid acelerationIncludingGravity, must throw an Error exception");
+ } catch (e) {
+ assert_equals(e.name, "Error");
+ assert_equals(e.message, "x getter exception");
+ }
+}, 'Tests invalid acelerationIncludingGravity.');
+
+test(test => {
+ try {
+ event = new DeviceMotionEvent('', {acceleration: {x: 0, y: 1, z: 2},
+ accelerationIncludingGravity: {x: 3, z: 5},
+ rotationRate: objectThrowingException,
+ interval: 9});
+ assert_unreached("Invalid rotationRate, must throw an Error exception");
+ } catch (e) {
+ assert_equals(e.name, "Error");
+ assert_equals(e.message, "alpha getter exception");
+ }
+}, 'Tests invalid rotationRate.');
+
+test(test => {
+ try {
+ event = new DeviceMotionEvent('', {acceleration: {x: objectThrowingException, y: 1, z: 2},
+ accelerationIncludingGravity: {x: 3, y: 4, z: 5},
+ rotationRate: {alpha: 6, beta: 7, gamma: 8},
+ interval: 9});
+ assert_unreached("Invalid acceleration.x, must throw an Error exception");
+ } catch (e) {
+ assert_equals(e.name, "Error");
+ assert_equals(e.message, "valueOf threw exception");
+ }
+}, 'Tests invalid acceleration.x.');
+
+test(test => {
+ try {
+ event = new DeviceMotionEvent('', {acceleration: {x: 0, y: 1, z: 2},
+ accelerationIncludingGravity: {x: 3, y: objectThrowingException, z: 5},
+ rotationRate: {alpha: 6, beta: 7, gamma: 8},
+ interval: 9});
+ assert_unreached("Invalid accelerationIncludingGravity.y, must throw an Error exception");
+ } catch (e) {
+ assert_equals(e.name, "Error");
+ assert_equals(e.message, "valueOf threw exception");
+ }
+}, 'Tests invalid accelerationIncludingGravity.y.');
+
+test(test => {
+ try {
+ event = new DeviceMotionEvent('', {acceleration: {x: 0, y: 1, z: 2},
+ accelerationIncludingGravity: {x: 3, y: 4, z: 5},
+ rotationRate: {alpha: 6, beta: 7, gamma: objectThrowingException},
+ interval: 9});
+ assert_unreached("Invalid rotationRate.gamma, must throw an Error exception");
+ } catch (e) {
+ assert_equals(e.name, "Error");
+ assert_equals(e.message, "valueOf threw exception");
+ }
+}, 'Tests invalid rotationRate.gamma.');
+
+test(test => {
+ event = new DeviceMotionEvent('', {acceleration: {y: 1, x: 0},
+ accelerationIncludingGravity: {x: 3, z: 5},
+ rotationRate: {gamma: 8, beta: 7},
+ interval: 9});
+ assert_equals(event.acceleration.x, 0);
+ assert_equals(event.acceleration.y, 1);
+ assert_equals(event.acceleration.z, null);
+ assert_equals(event.accelerationIncludingGravity.x, 3);
+ assert_equals(event.accelerationIncludingGravity.y, null);
+ assert_equals(event.accelerationIncludingGravity.z, 5);
+ assert_equals(event.rotationRate.alpha, null);
+ assert_equals(event.rotationRate.beta, 7);
+ assert_equals(event.rotationRate.gamma, 8);
+ assert_equals(event.interval, 9);
+}, 'Tests missing fields should be null.');
+
+test(test => {
+ event = new DeviceMotionEvent('');
+ assert_equals(event.acceleration, null);
+ assert_equals(event.accelerationIncludingGravity, null);
+ assert_equals(event.rotationRate, null);
+ assert_equals(event.interval, 0);
+}, 'Tests DeviceMotionEvent default constructor.');
+
+test(test => {
+ event = new DeviceMotionEvent('', {acceleration: [],
+ accelerationIncludingGravity: [],
+ rotationRate: [],
+ interval: []});
+ assert_equals(event.acceleration.x, null);
+ assert_equals(event.acceleration.y, null);
+ assert_equals(event.acceleration.z, null);
+ assert_equals(event.accelerationIncludingGravity.x, null);
+ assert_equals(event.accelerationIncludingGravity.y, null);
+ assert_equals(event.accelerationIncludingGravity.z, null);
+ assert_equals(event.rotationRate.alpha, null);
+ assert_equals(event.rotationRate.beta, null);
+ assert_equals(event.rotationRate.gamma, null);
+ assert_equals(event.interval, 0);
+}, 'Tests all values are empty array.');
+
+test(test => {
+ event = new DeviceMotionEvent('', {acceleration: [],
+ accelerationIncludingGravity: undefined,
+ rotationRate: undefined,
+ interval: undefined});
+ assert_equals(event.acceleration.x, null);
+ assert_equals(event.acceleration.y, null);
+ assert_equals(event.acceleration.z, null);
+ assert_equals(event.accelerationIncludingGravity, null);
+ assert_equals(event.rotationRate, null);
+ assert_equals(event.interval, 0);
+}, 'Tests some values are empty array and some values are undefined.');
+
+test(test => {
+ event = new DeviceMotionEvent('', {acceleration: null,
+ accelerationIncludingGravity: null,
+ rotationRate: null,
+ interval: null});
+ assert_equals(event.acceleration.x, null);
+ assert_equals(event.acceleration.y, null);
+ assert_equals(event.acceleration.z, null);
+ assert_equals(event.accelerationIncludingGravity.x, null);
+ assert_equals(event.accelerationIncludingGravity.y, null);
+ assert_equals(event.accelerationIncludingGravity.z, null);
+ assert_equals(event.rotationRate.alpha, null);
+ assert_equals(event.rotationRate.beta, null);
+ assert_equals(event.rotationRate.gamma, null);
+ assert_equals(event.interval, 0);
+}, "Tests all values are null.");
+
+test(test => {
+ event = new DeviceMotionEvent('', {acceleration: {x: null, y: null, z: null},
+ accelerationIncludingGravity: {x: null, y: null, z: null},
+ rotationRate: {alpha: null, beta: null, gamma: null},
+ interval: null});
+ assert_equals(event.acceleration.x, null);
+ assert_equals(event.acceleration.y, null);
+ assert_equals(event.acceleration.z, null);
+ assert_equals(event.accelerationIncludingGravity.x, null);
+ assert_equals(event.accelerationIncludingGravity.y, null);
+ assert_equals(event.accelerationIncludingGravity.z, null);
+ assert_equals(event.rotationRate.alpha, null);
+ assert_equals(event.rotationRate.beta, null);
+ assert_equals(event.rotationRate.gamma, null);
+ assert_equals(event.interval, 0);
+}, 'Tests all fields are null.');
+
+test(test => {
+ event = new DeviceMotionEvent('', {acceleration: {x: null, y: null, z: 1},
+ accelerationIncludingGravity: {x: null, y: null, z: 2},
+ rotationRate: {alpha: null, beta: null, gamma: 3},
+ interval: null});
+ assert_equals(event.acceleration.x, null);
+ assert_equals(event.acceleration.y, null);
+ assert_equals(event.acceleration.z, 1);
+ assert_equals(event.accelerationIncludingGravity.x, null);
+ assert_equals(event.accelerationIncludingGravity.y, null);
+ assert_equals(event.accelerationIncludingGravity.z, 2);
+ assert_equals(event.rotationRate.alpha, null);
+ assert_equals(event.rotationRate.beta, null);
+ assert_equals(event.rotationRate.gamma, 3);
+ assert_equals(event.interval, 0);
+}, 'Tests some fields are null.');
+
+test(test => {
+ event = new DeviceMotionEvent('', {acceleration: {x: undefined, y: undefined, z: undefined},
+ accelerationIncludingGravity: {x: undefined, y: undefined, z: undefined},
+ rotationRate: {alpha: undefined, beta: undefined, gamma: undefined},
+ interval: undefined});
+ assert_equals(event.acceleration.x, null);
+ assert_equals(event.acceleration.y, null);
+ assert_equals(event.acceleration.z, null);
+ assert_equals(event.accelerationIncludingGravity.x, null);
+ assert_equals(event.accelerationIncludingGravity.y, null);
+ assert_equals(event.accelerationIncludingGravity.z, null);
+ assert_equals(event.rotationRate.alpha, null);
+ assert_equals(event.rotationRate.beta, null);
+ assert_equals(event.rotationRate.gamma, null);
+ assert_equals(event.interval, 0);
+}, 'Tests all fields are undefined.');
+
+test(test => {
+ event = new DeviceMotionEvent('', {acceleration: {x: undefined, y: undefined, z: 1},
+ accelerationIncludingGravity: {x: undefined, y: undefined, z: 2},
+ rotationRate: {alpha: undefined, beta: undefined, gamma: 3},
+ interval: undefined});
+ assert_equals(event.acceleration.x, null);
+ assert_equals(event.acceleration.y, null);
+ assert_equals(event.acceleration.z, 1);
+ assert_equals(event.accelerationIncludingGravity.x, null);
+ assert_equals(event.accelerationIncludingGravity.y, null);
+ assert_equals(event.accelerationIncludingGravity.z, 2);
+ assert_equals(event.rotationRate.alpha, null);
+ assert_equals(event.rotationRate.beta, null);
+ assert_equals(event.rotationRate.gamma, 3);
+ assert_equals(event.interval, 0);
+}, 'Tests some fields are undefined.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/motion/page-visibility-manual.https.html b/testing/web-platform/tests/orientation-event/motion/page-visibility-manual.https.html
new file mode 100644
index 0000000000..37e48ce979
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/page-visibility-manual.https.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+'use strict';
+
+promise_test(t => {
+ return new Promise((resolve, reject) => {
+ document.addEventListener("visibilitychange", () => {
+ assert_true(document.hidden, "document is hidden");
+ window.addEventListener(
+ 'devicemotion',
+ event => {
+ if (document.hidden) {
+ reject();
+ } else {
+ resolve();
+ }
+ },
+ { once: true });
+ }, { once: true });
+ });
+}, 'Tests to check that devicemotion events are not fired when the page is not visible.');
+</script>
+
+<p>Switch the page to the background, then switch back to it.</p>
diff --git a/testing/web-platform/tests/orientation-event/motion/requestPermission.https.window.js b/testing/web-platform/tests/orientation-event/motion/requestPermission.https.window.js
new file mode 100644
index 0000000000..2c96d26d10
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/requestPermission.https.window.js
@@ -0,0 +1,48 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+
+'use strict';
+
+// The Device Orientation spec does not fully integrate with the Permissions
+// spec and does not list the permissions that are expected for
+// requestPermission() to work. The list below was based on the permission
+// tokens corresponding to the sensors used to implement support for motion
+// events. They also match the feature policy tokens required by both Blink and
+// WebKit.
+const permissionDescriptorNames = ['accelerometer', 'gyroscope'];
+
+promise_test(async (t) => {
+ await Promise.all(permissionDescriptorNames.map(
+ name => test_driver.set_permission({name}, 'granted')));
+
+ const permission = await DeviceMotionEvent.requestPermission();
+ assert_equals(permission, 'granted');
+}, 'requestPermission() returns "granted" for granted permissions without user activation');
+
+promise_test(async (t) => {
+ await Promise.all(permissionDescriptorNames.map(
+ name => test_driver.set_permission({name}, 'granted')));
+
+ return test_driver.bless('enable user activation', async () => {
+ const permission = await DeviceMotionEvent.requestPermission();
+ assert_equals(permission, 'granted');
+ });
+}, 'requestPermission() returns "granted" for granted permissions with user activation');
+
+promise_test(async (t) => {
+ await Promise.all(permissionDescriptorNames.map(
+ name => test_driver.set_permission({name}, 'denied')));
+
+ const permission = await DeviceMotionEvent.requestPermission();
+ assert_equals(permission, 'denied');
+}, 'requestPermission() returns "denied" for denied permissions without user activation');
+
+promise_test(async (t) => {
+ await Promise.all(permissionDescriptorNames.map(
+ name => test_driver.set_permission({name}, 'denied')));
+
+ return test_driver.bless('enable user activation', async () => {
+ const permission = await DeviceMotionEvent.requestPermission();
+ assert_equals(permission, 'denied');
+ });
+}, 'requestPermission() returns "denied" for denied permissions with user activation');
diff --git a/testing/web-platform/tests/orientation-event/motion/screen-upmost-manual.https.html b/testing/web-platform/tests/orientation-event/motion/screen-upmost-manual.https.html
new file mode 100644
index 0000000000..560c3e3a1f
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/screen-upmost-manual.https.html
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>DeviceMotionEvent: A device lying flat on a horizontal surface with the screen upmost</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author' title='Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-14 -->
+ </head>
+ <body>
+ <p>Put the device on a horizontal surface with the screen upmost.</p>
+ <div id="log"></div>
+ <script>
+ var t = async_test();
+ var run = false;
+
+ /*
+ * A device lying flat on a horizontal surface with the screen upmost
+ * has an acceleration of zero and the following value for
+ * accelerationIncludingGravity:
+ * {
+ * x: 0,
+ * y: 0,
+ * z: 9.81
+ * };
+ */
+ window.addEventListener("devicemotion", function(e) {
+ if (!run) {
+ run = true;
+ t.step(function() {
+ var gvt = e.accelerationIncludingGravity;
+ var acc = e.acceleration;
+ var rot = e.rotationRate;
+
+ assert_approx_equals(gvt.x, 0, 1);
+ assert_approx_equals(gvt.y, 0, 1);
+ assert_approx_equals(gvt.z, 9.81, 1.5);
+
+ assert_approx_equals(acc.x, 0, 1);
+ assert_approx_equals(acc.y, 0, 1);
+ assert_approx_equals(acc.z, 0, 1);
+
+ assert_equals(rot, null);
+ });
+ t.done();
+ }
+ }, false);
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/motion/screen-upright-manual.https.html b/testing/web-platform/tests/orientation-event/motion/screen-upright-manual.https.html
new file mode 100644
index 0000000000..8a1b6d27da
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/screen-upright-manual.https.html
@@ -0,0 +1,50 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>DeviceMotionEvent: A device with the screen upright</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author' title='Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-14 -->
+ </head>
+ <body>
+ <p>Put the device with the screen upright.</p>
+ <div id="log"></div>
+ <script>
+ var t = async_test();
+ var run = false;
+
+ /*
+ * A device with the screen upright has an acceleration of zero
+ * and the following value for accelerationIncludingGravity:
+ * {
+ * x: 0,
+ * y: -9.81,
+ * z: 0
+ * };
+ */
+ window.addEventListener("devicemotion", function(e) {
+ if (!run) {
+ run = true;
+ t.step(function() {
+ var gvt = e.accelerationIncludingGravity;
+ var acc = e.acceleration;
+ var rot = e.rotationRate;
+
+ assert_approx_equals(gvt.x, 0, 1);
+ assert_approx_equals(gvt.y, -9.81, 1.5);
+ assert_approx_equals(gvt.z, 0, 1);
+
+ assert_approx_equals(acc.x, 0, 1);
+ assert_approx_equals(acc.y, 0, 1);
+ assert_approx_equals(acc.z, 0, 1);
+
+ assert_equals(rot, null);
+ });
+ t.done();
+ }
+ }, false);
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/motion/t025-manual.https.html b/testing/web-platform/tests/orientation-event/motion/t025-manual.https.html
new file mode 100644
index 0000000000..9489855fcd
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/t025-manual.https.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Implementations that are unable to provide acceleration data without the effect of gravity may instead supply the acceleration including the effect of gravity</title>
+ <meta name=viewport content="width=device-width, maximum-scale=1.0">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author" title="Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-14 -->
+ </head>
+ <body>
+ <p>Move the device to run the test.</p>
+ <div id="log"></div>
+ <script>
+ var t1 = async_test("Implementation is unable to provide 'acceleration' property");
+ var t2 = async_test("Implementation is able to provide 'acceleration IncludingGravity' property");
+ var run = false;
+ window.ondevicemotion = function(e) {
+ if (!run) {
+ run = true;
+ t1.step(function() {
+ assert_equals(e.acceleration, null);
+ });
+ t1.done();
+ t2.step(function() {
+ var eaccgvt = e.accelerationIncludingGravity;
+ assert_equals(typeof eaccgvt, "object");
+ assert_not_equals(eaccgvt.x, 0);
+ assert_not_equals(eaccgvt.y, 0);
+ assert_not_equals(eaccgvt.z, 0);
+ });
+ t2.done();
+ }
+ };
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/motion/t028-manual.https.html b/testing/web-platform/tests/orientation-event/motion/t028-manual.https.html
new file mode 100644
index 0000000000..669c4e47e0
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/motion/t028-manual.https.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>The interval property must be expressed in milliseconds. It must be a constant, to simplify filtering of the data by the Web application</title>
+ <meta name=viewport content="width=device-width, maximum-scale=1.0">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author" title="Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-14 -->
+ </head>
+ <body>
+ <p>Move the device to run the test.</p>
+ <div id="log"></div>
+ <script>
+ var t = async_test("The interval property must be different to zero and must be a constant");
+ var inter1 = 0;
+ var inter2 = 0;
+ var run = false;
+ window.addEventListener("devicemotion", function(e) {
+ if (!run) {
+ run = true;
+ t.step(function() {
+ if (inter1 == 0) {
+ inter2 = e.interval;
+ }
+ inter1 = e.interval;
+ assert_not_equals(inter1, 0);
+ assert_not_equals(inter1, inter2);
+ });
+ t.done();
+ }
+ }, false);
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/orientation/absolute-fallback.https.html b/testing/web-platform/tests/orientation-event/orientation/absolute-fallback.https.html
new file mode 100644
index 0000000000..610b1b3c56
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/absolute-fallback.https.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData = generateOrientationData(1.1, 2.2, 3.3, true);
+
+ // Make the relative orientation sensor unavailable and set mock data for
+ // the absolute one.
+ sensorProvider.setGetSensorShouldFail('RelativeOrientationEulerAngles', true);
+ setMockOrientationData(sensorProvider, orientationData);
+ return waitForEvent(getExpectedAbsoluteOrientationEvent(orientationData));
+}, 'Tests that deviceorientation falls back to using absolute orientation data if relative is unavailable.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/orientation/add-listener-from-callback.https.html b/testing/web-platform/tests/orientation-event/orientation/add-listener-from-callback.https.html
new file mode 100644
index 0000000000..8f8cfa29c4
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/add-listener-from-callback.https.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData = generateOrientationData(1.1, 2.2, 3.3, false);
+
+ let firstListener = null;
+ let secondListener = null;
+ let firstEventCount = 0;
+ let firstPromise = new Promise(resolve => {
+ firstListener = (event) => {
+ assert_true(event instanceof DeviceOrientationEvent, 'event is DeviceOrientationEvent');
+ assert_equals(event.type, 'deviceorientation', 'event.type is devicemotion');
+ assert_true(event.target instanceof Window, 'event is fired on the window object');
+ assertEventEquals(event, getExpectedOrientationEvent(orientationData));
+ window.removeEventListener('deviceorientation', firstListener);
+ if (++firstEventCount == 1) {
+ window.addEventListener('deviceorientation', secondListener);
+ }
+ resolve(event);
+ };
+ });
+
+ let secondEventCount = 0;
+ let secondPromise = new Promise(resolve => {
+ secondListener = (event) => {
+ assertEventEquals(event, getExpectedOrientationEvent(orientationData));
+ window.removeEventListener('deviceorientation', secondListener);
+ ++secondEventCount;
+ resolve(event);
+ };
+ });
+
+ setMockOrientationData(sensorProvider, orientationData);
+ window.addEventListener('deviceorientation', firstListener);
+ await firstPromise;
+ await secondPromise;
+ assert_equals(firstEventCount, 1, "Too many events fired for the first listener");
+ assert_equals(secondEventCount, 1, "Too many events fired for the second listener");
+}, 'Tests that adding a new deviceorientation event listener from a callback works as expected.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/orientation/basic-operation-absolute.https.html b/testing/web-platform/tests/orientation-event/orientation/basic-operation-absolute.https.html
new file mode 100644
index 0000000000..61fd218781
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/basic-operation-absolute.https.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData = generateOrientationData(1.1, 2.2, 3.3, true);
+ setMockOrientationData(sensorProvider, orientationData);
+ return waitForEvent(getExpectedAbsoluteOrientationEvent(orientationData));
+}, 'Tests basic operation of deviceorientationabsolute event using mock data.');
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData = generateOrientationData(null, null, null, true);
+ const watcher = new EventWatcher(t, window, ['deviceorientationabsolute']);
+
+ // Make the absolute orientation sensor unavailable
+ sensorProvider.setGetSensorShouldFail('AbsoluteOrientationEulerAngles', true);
+ const event = await watcher.wait_for('deviceorientationabsolute');
+ assert_equals(event.type, 'deviceorientationabsolute', 'type is set to \"deviceorientationabsolute\"');
+ assert_true(event instanceof DeviceOrientationEvent, 'event is DeviceOrientationEvent');
+
+ assertEventEquals(event, getExpectedAbsoluteOrientationEvent(orientationData));
+}, 'If UA can never provide absolute information, the event should be fired as a null event.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/orientation/basic-operation.https.html b/testing/web-platform/tests/orientation-event/orientation/basic-operation.https.html
new file mode 100644
index 0000000000..45fe38006e
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/basic-operation.https.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData = generateOrientationData(1.1, 2.2, 3.3, false);
+ setMockOrientationData(sensorProvider, orientationData);
+ return waitForEvent(getExpectedOrientationEvent(orientationData));
+}, 'Tests basic operation of deviceorientation event using mock data.');
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData = generateOrientationData(null, null, null, false);
+ const watcher = new EventWatcher(t, window, ['deviceorientation']);
+
+ // Make the orientation sensor unavailable
+ sensorProvider.setGetSensorShouldFail('AbsoluteOrientationEulerAngles', true);
+ sensorProvider.setGetSensorShouldFail('RelativeOrientationEulerAngles', true);
+ const event = await watcher.wait_for('deviceorientation');
+ assert_equals(event.type, 'deviceorientation', 'type is set to \"deviceorientation\"');
+ assert_true(event instanceof DeviceOrientationEvent, 'event is DeviceOrientationEvent');
+
+ assertEventEquals(event, getExpectedOrientationEvent(orientationData));
+}, 'If UA can never provide orientation information, the event should be fired as a null event.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/orientation/create-event.https.html b/testing/web-platform/tests/orientation-event/orientation/create-event.https.html
new file mode 100644
index 0000000000..a21f95655e
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/create-event.https.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+'use strict';
+
+test(test => {
+ const event = document.createEvent('DeviceOrientationEvent');
+ const newEvent = new CustomEvent("deviceorientation", {
+ bubbles: false, cancelable: false,
+ alpha: 1.0,
+ beta: 2.0,
+ gama: 3.0,
+ absolute: false
+ });
+
+ assert_equals(typeof event, 'object');
+ assert_equals(Object.getPrototypeOf(event), DeviceOrientationEvent.prototype);
+
+ assert_true('type' in event);
+ assert_true('bubbles' in event);
+ assert_true('cancelable' in event);
+ assert_true('alpha' in event);
+ assert_true('beta' in event);
+ assert_true('gamma' in event);
+ assert_true('absolute' in event);
+
+ assert_equals(typeof event.type, 'string');
+ assert_equals(typeof event.bubbles, 'boolean');
+ assert_equals(typeof event.cancelable, 'boolean');
+ assert_equals(typeof event.alpha, 'object');
+ assert_equals(typeof event.beta, 'object');
+ assert_equals(typeof event.gamma, 'object');
+ assert_equals(typeof event.absolute, 'boolean');
+
+ assert_equals(newEvent.type, "deviceorientation");
+ assert_false(newEvent.bubbles);
+ assert_false(newEvent.cancelable);
+}, 'Tests that document.createEvent() works with DeviceOrientationEvent.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/orientation/horizontal-surface-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/horizontal-surface-manual.https.html
new file mode 100644
index 0000000000..0b7302e704
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/horizontal-surface-manual.https.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>DeviceOrientationEvent: A device lying flat on a horizontal surface</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author' title='Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-12 -->
+ </head>
+ <body>
+ <p>Put the device on a horizontal surface to run the test.</p>
+ <div id="log"></div>
+ <script>
+ var gamma, beta;
+ var run = false;
+ window.addEventListener("deviceorientation", function(e) {
+ if (!run) {
+ run = true;
+ gamma = e.gamma; // Gamma : angle par rapport a x
+ beta = e.beta; // Beta : angle par rapport a y
+ }
+ }, false);
+
+ test(function() {
+ assert_approx_equals(gamma, 0, 2);
+ }, "X angle");
+
+ test(function() {
+ assert_approx_equals(beta, 0, 2);
+ }, "Y angle");
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/orientation/multiple-event-listeners.https.html b/testing/web-platform/tests/orientation-event/orientation/multiple-event-listeners.https.html
new file mode 100644
index 0000000000..473b7f8828
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/multiple-event-listeners.https.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData1 = generateOrientationData(1, 2, 3, false);
+ setMockOrientationData(sensorProvider, orientationData1);
+ await Promise.all([
+ waitForEvent(getExpectedOrientationEvent(orientationData1)),
+ waitForEvent(getExpectedOrientationEvent(orientationData1))
+ ]);
+
+ const orientationData2 = generateOrientationData(11, 12, 13, false);
+ setMockOrientationData(sensorProvider, orientationData2);
+ await waitForEvent(getExpectedOrientationEvent(orientationData2));
+}, 'Tests using multiple event handlers for the Device Orientation API.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/orientation/no-synchronous-events.https.html b/testing/web-platform/tests/orientation-event/orientation/no-synchronous-events.https.html
new file mode 100644
index 0000000000..e5d7621123
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/no-synchronous-events.https.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData = generateOrientationData(1.1, 2.2, 3.3, false);
+
+ let setMockDataPromise = setMockOrientationData(sensorProvider, orientationData);
+ // Add an empty listener to make sure the event pump is running and the mock
+ // sensor is created and configured. If the pump and fake sensor weren't set
+ // up ahead of time, then the fact that we get an asynchronous event could be
+ // due to the asynchronous set up process.
+ window.addEventListener('deviceorientation', event => {});
+ await setMockDataPromise;
+
+ return new Promise((resolve, reject) => {
+ let result = reject;
+ window.addEventListener('deviceorientation', event => result());
+ result = resolve;
+ });
+}, 'Tests that events are never fired synchronously from a call to window.addEventListener().');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/orientation/null-values.https.html b/testing/web-platform/tests/orientation-event/orientation/null-values.https.html
new file mode 100644
index 0000000000..f9e4aa6420
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/null-values.https.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData1 = generateOrientationData(1.1, null, null, false);
+ const orientationData2 = generateOrientationData(null, 2.2, null, false);
+ const orientationData3 = generateOrientationData(null, null, 3.3, false);
+ // The all null event is last because DeviceSingleWindowEventController
+ // will stop updating the sensor when it sees a null event.
+ const orientationData4 = generateOrientationData(null, null, null, false);
+
+ setMockOrientationData(sensorProvider, orientationData1);
+ await waitForEvent(getExpectedOrientationEvent(orientationData1));
+
+ setMockOrientationData(sensorProvider, orientationData2);
+ await waitForEvent(getExpectedOrientationEvent(orientationData2));
+
+ setMockOrientationData(sensorProvider, orientationData3);
+ await waitForEvent(getExpectedOrientationEvent(orientationData3));
+
+ setMockOrientationData(sensorProvider, orientationData4);
+ await waitForEvent(getExpectedOrientationEvent(orientationData4));
+}, 'Tests using null values for some of the event properties.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/orientation/optional-event-properties.https.html b/testing/web-platform/tests/orientation-event/orientation/optional-event-properties.https.html
new file mode 100644
index 0000000000..150ce5ca1d
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/optional-event-properties.https.html
@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+'use strict';
+
+test(test => {
+ event = document.createEvent('DeviceOrientationEvent');
+ assert_equals(event.type, "");
+ assert_equals(event.alpha, null);
+ assert_equals(event.beta, null);
+ assert_equals(event.gamma, null);
+ assert_false(event.absolute);
+}, 'Tests creating a DeviceOrientationEvent.');
+
+test(test => {
+ event = new DeviceOrientationEvent('foo', {alpha: 0, beta: 1, gamma: 2, absolute: false});
+ assert_equals(event.type, "foo");
+ assert_equals(event.alpha, 0);
+ assert_equals(event.beta, 1);
+ assert_equals(event.gamma, 2);
+ assert_false(event.absolute);
+}, 'Tests no missing value (absolute field is false).');
+
+test(test => {
+ event = new DeviceOrientationEvent('', {alpha: 0, beta: 1, gamma: 2, absolute: true});
+ assert_equals(event.alpha, 0);
+ assert_equals(event.beta, 1);
+ assert_equals(event.gamma, 2);
+ assert_true(event.absolute);
+}, 'Tests no missing value (absolute field is true).');
+
+test(test => {
+ event = new DeviceOrientationEvent('');
+ assert_equals(event.alpha, null);
+ assert_equals(event.beta, null);
+ assert_equals(event.gamma, null);
+ assert_false(event.absolute);
+}, 'Tests DeviceOrientationEvent default constructor.');
+
+test(test => {
+ event = new DeviceOrientationEvent('', {alpha: [], beta: [], gamma: [], absolute: []});
+ assert_equals(event.alpha, 0);
+ assert_equals(event.beta, 0);
+ assert_equals(event.gamma, 0);
+ assert_true(event.absolute);
+}, 'Tests all values are empty array.');
+
+test(test => {
+ event = new DeviceOrientationEvent('', {alpha: undefined, beta: undefined, gamma: undefined, absolute: undefined});
+ assert_equals(event.alpha, null);
+ assert_equals(event.beta, null);
+ assert_equals(event.gamma, null);
+ assert_false(event.absolute);
+}, 'Tests all values are undefined.');
+
+test(test => {
+ event = new DeviceOrientationEvent('', {alpha: '', beta: '', gamma: '', absolute: ''});
+ assert_equals(event.alpha, 0);
+ assert_equals(event.beta, 0);
+ assert_equals(event.gamma, 0);
+ assert_false(event.absolute);
+}, 'Tests all values are empty string.');
+
+
+test(test => {
+ event = new DeviceOrientationEvent('', {alpha: null, beta: null, gamma: null, absolute: null});
+ assert_equals(event.alpha, null);
+ assert_equals(event.beta, null);
+ assert_equals(event.gamma, null);
+ assert_false(event.absolute);
+}, 'Tests all values are null.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/orientation/page-visibility-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/page-visibility-manual.https.html
new file mode 100644
index 0000000000..033f17602b
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/page-visibility-manual.https.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<meta name="timeout" content="long">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+'use strict';
+
+promise_test(t => {
+ return new Promise((resolve, reject) => {
+ document.addEventListener("visibilitychange", () => {
+ assert_true(document.hidden, "document is hidden");
+ window.addEventListener(
+ 'deviceorientation',
+ event => {
+ if (document.hidden) {
+ reject();
+ } else {
+ resolve();
+ }
+ },
+ { once: true });
+ }, { once: true });
+ });
+}, 'Tests to check that deviceorientation events are not fired when the page is not visible.');
+</script>
+
+<p>Switch the page to the background, then switch back to it.</p>
diff --git a/testing/web-platform/tests/orientation-event/orientation/requestPermission.https.window.js b/testing/web-platform/tests/orientation-event/orientation/requestPermission.https.window.js
new file mode 100644
index 0000000000..4a39a238d0
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/requestPermission.https.window.js
@@ -0,0 +1,48 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+
+'use strict';
+
+// The Device Orientation spec does not fully integrate with the Permissions
+// spec and does not list the permissions that are expected for
+// requestPermission() to work. The list below was based on the permissions
+// listed in https://w3c.github.io/orientation-sensor/#model for the low-level
+// sensors that power absolute and relative orientation sensors.
+const permissionDescriptorNames =
+ ['accelerometer', 'gyroscope', 'magnetometer'];
+
+promise_test(async (t) => {
+ await Promise.all(permissionDescriptorNames.map(
+ name => test_driver.set_permission({name}, 'granted')));
+
+ const permission = await DeviceOrientationEvent.requestPermission();
+ assert_equals(permission, 'granted');
+}, 'requestPermission() returns "granted" for granted permissions without user activation');
+
+promise_test(async (t) => {
+ await Promise.all(permissionDescriptorNames.map(
+ name => test_driver.set_permission({name}, 'granted')));
+
+ return test_driver.bless('enable user activation', async () => {
+ const permission = await DeviceOrientationEvent.requestPermission();
+ assert_equals(permission, 'granted');
+ });
+}, 'requestPermission() returns "granted" for granted permissions with user activation');
+
+promise_test(async (t) => {
+ await Promise.all(permissionDescriptorNames.map(
+ name => test_driver.set_permission({name}, 'denied')));
+
+ const permission = await DeviceOrientationEvent.requestPermission();
+ assert_equals(permission, 'denied');
+}, 'requestPermission() returns "denied" for denied permissions without user activation');
+
+promise_test(async (t) => {
+ await Promise.all(permissionDescriptorNames.map(
+ name => test_driver.set_permission({name}, 'denied')));
+
+ return test_driver.bless('enable user activation', async () => {
+ const permission = await DeviceOrientationEvent.requestPermission();
+ assert_equals(permission, 'denied');
+ });
+}, 'requestPermission() returns "denied" for denied permissions with user activation');
diff --git a/testing/web-platform/tests/orientation-event/orientation/t006-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/t006-manual.https.html
new file mode 100644
index 0000000000..e41f4634e8
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/t006-manual.https.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Rotate the device frame around its z axis</title>
+ <meta name=viewport content="width=device-width, maximum-scale=1.0">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author" title="Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-12 -->
+ </head>
+ <body>
+ <p>Rotate the device frame around its z axis to run the test.</p>
+ <div id="log"></div>
+ <script>
+ var t1 = async_test("Alpha is in [0, 360)");
+ var run = false;
+ window.addEventListener("deviceorientation", function(e) {
+ if (!run && e.alpha !== null) {
+ run = true;
+ t1.step(function() {
+ assert_greater_than_equal(e.alpha, 0);
+ assert_less_than(e.alpha, 360);
+ });
+ t1.done();
+ }
+ }, false);
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/orientation/t009-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/t009-manual.https.html
new file mode 100644
index 0000000000..d00f7e71b0
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/t009-manual.https.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Rotate the device frame around its x axis</title>
+ <meta name=viewport content="width=device-width, maximum-scale=1.0">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author" title="Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-12 -->
+ </head>
+ <body>
+ <p>Rotate the device frame around its x axis to run the test.</p>
+ <div id="log"></div>
+ <script>
+ var t1 = async_test("Beta is in [-180, 180)");
+ var run = false;
+ window.addEventListener("deviceorientation", function(e) {
+ if (!run && e.beta !== null) {
+ run = true;
+ t1.step(function() {
+ assert_greater_than_equal(e.beta, -180);
+ assert_less_than(e.beta, 180);
+ });
+ t1.done();
+ }
+ }, false);
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/orientation/t010-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/t010-manual.https.html
new file mode 100644
index 0000000000..9a6e00e1f7
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/t010-manual.https.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Rotate the device frame around its y axis</title>
+ <meta name=viewport content="width=device-width, maximum-scale=1.0">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author" title="Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-12 -->
+ </head>
+ <body>
+ <p>Rotate the device frame around its y axis to run the test.</p>
+ <div id="log"></div>
+ <script>
+ var t1 = async_test("Gamma is in [-90, 90)");
+ var run = false;
+ window.addEventListener("deviceorientation", function(e) {
+ if (!run && e.gamma !== null) {
+ run = true;
+ t1.step(function() {
+ assert_greater_than_equal(e.gamma, -90);
+ assert_less_than(e.gamma, 90);
+ });
+ t1.done();
+ }
+ }, false);
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/orientation/t012-manual.https.html b/testing/web-platform/tests/orientation-event/orientation/t012-manual.https.html
new file mode 100644
index 0000000000..e5ac1c98b4
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/t012-manual.https.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Implementations that are unable to provide all three angles must set the values of the unknown angles to null</title>
+ <meta name=viewport content="width=device-width, maximum-scale=1.0">
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <link rel="author" title="Mosquito FP7">
+ <link rel="reviewer author" title="Zhiqiang Zhang" href="mailto:zhiqiang.zhang@intel.com"> <!-- 2013-10-12 -->
+ </head>
+ <body>
+ <p>Precondition: implementation is unable to provide all three angles</p>
+ <p>Rotate the device to run the test.</p>
+ <div id="log"></div>
+ <script>
+ var t1 = async_test("Alpha, Beta and Gamma are null. absolute is false.");
+ var run = false;
+ window.addEventListener("deviceorientation", function(e) {
+ if (!run) {
+ run = true;
+ t1.step(function() {
+ assert_equals(e.alpha, null, "alpha is set to null");
+ assert_equals(e.beta, null, "beta is set to null");
+ assert_equals(e.gamma, null, "gamma is set to null");
+ assert_false(e.absolute, "absolute is set to false");
+ });
+ t1.done();
+ }
+ }, false);
+
+ test(function() {
+ var evt = new DeviceOrientationEvent("foo");
+ assert_equals(evt.alpha, null, "alpha is set to null");
+ assert_equals(evt.beta, null, "beta is set to null");
+ assert_equals(evt.gamma, null, "gamma is set to null");
+ assert_false(evt.absolute, "absolute is set to false");
+ }, "User created event is initialized properly");
+ </script>
+ </body>
+</html>
+
diff --git a/testing/web-platform/tests/orientation-event/orientation/updates.https.html b/testing/web-platform/tests/orientation-event/orientation/updates.https.html
new file mode 100644
index 0000000000..c84588d598
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/orientation/updates.https.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="../resources/orientation-event-helpers.js"></script>
+<script>
+'use strict';
+
+sensor_test(async (t, sensorProvider) => {
+ const orientationData1 = generateOrientationData(1.1, 2.2, 3.3, false);
+ setMockOrientationData(sensorProvider, orientationData1);
+ await waitForEvent(getExpectedOrientationEvent(orientationData1));
+
+ const orientationData2 = generateOrientationData(11.1, 22.2, 33.3, false);
+ setMockOrientationData(sensorProvider, orientationData2);
+ await waitForEvent(getExpectedOrientationEvent(orientationData2));
+}, 'Tests that updates to the orientation causes new events to fire.');
+</script>
diff --git a/testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js b/testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js
new file mode 100644
index 0000000000..1f0deba278
--- /dev/null
+++ b/testing/web-platform/tests/orientation-event/resources/orientation-event-helpers.js
@@ -0,0 +1,188 @@
+'use strict';
+
+// These tests rely on the User Agent providing an implementation of
+// platform sensor backends.
+//
+// In Chromium-based browsers this implementation is provided by a polyfill
+// in order to reduce the amount of test-only code shipped to users. To enable
+// these tests the browser must be run with these options:
+//
+// --enable-blink-features=MojoJS,MojoJSTest
+async function loadChromiumResources() {
+ await import('/resources/chromium/generic_sensor_mocks.js');
+}
+
+async function initialize_generic_sensor_tests() {
+ if (typeof GenericSensorTest === 'undefined') {
+ const script = document.createElement('script');
+ script.src = '/resources/test-only-api.js';
+ script.async = false;
+ const p = new Promise((resolve, reject) => {
+ script.onload = () => { resolve(); };
+ script.onerror = e => { reject(e); };
+ })
+ document.head.appendChild(script);
+ await p;
+
+ if (isChromiumBased) {
+ await loadChromiumResources();
+ }
+ }
+ assert_implements(GenericSensorTest, 'GenericSensorTest is unavailable.');
+ let sensorTest = new GenericSensorTest();
+ await sensorTest.initialize();
+ return sensorTest;
+}
+
+function sensor_test(func, name, properties) {
+ promise_test(async (t) => {
+ t.add_cleanup(() => {
+ if (sensorTest)
+ return sensorTest.reset();
+ });
+
+ let sensorTest = await initialize_generic_sensor_tests();
+ return func(t, sensorTest.getSensorProvider());
+ }, name, properties);
+}
+
+const MOTION_ROTATION_EPSILON = 1e-8;
+
+function generateMotionData(accelerationX, accelerationY, accelerationZ,
+ accelerationIncludingGravityX,
+ accelerationIncludingGravityY,
+ accelerationIncludingGravityZ,
+ rotationRateAlpha, rotationRateBeta, rotationRateGamma,
+ interval = 16) {
+ const motionData = {accelerationX: accelerationX,
+ accelerationY: accelerationY,
+ accelerationZ: accelerationZ,
+ accelerationIncludingGravityX: accelerationIncludingGravityX,
+ accelerationIncludingGravityY: accelerationIncludingGravityY,
+ accelerationIncludingGravityZ: accelerationIncludingGravityZ,
+ rotationRateAlpha: rotationRateAlpha,
+ rotationRateBeta: rotationRateBeta,
+ rotationRateGamma: rotationRateGamma,
+ interval: interval};
+ return motionData;
+}
+
+function generateOrientationData(alpha, beta, gamma, absolute) {
+ const orientationData = {alpha: alpha,
+ beta: beta,
+ gamma: gamma,
+ absolute: absolute};
+ return orientationData;
+}
+
+async function setMockSensorDataForType(sensorProvider, sensorType, mockDataArray) {
+ const createdSensor = await sensorProvider.getCreatedSensor(sensorType);
+ // We call setSensorReadingAndUpdateSharedBuffer() rather than
+ // setSensorReading() to accommodate Blink's Device Orientation
+ // implementation, which uses its own timer to read the sensor's shared
+ // memory buffer rather than relying on SensorReadingChanged(). This timer
+ // may fire out of sync with the JS timer in MockSensor.startReading(), so
+ // the former might read the shared memory buffer before the latter has
+ // updated |this.buffer_|. We thus immediately update the buffer here
+ // (without consuming data from the ring buffer).
+ return createdSensor.setSensorReadingImmediately([mockDataArray]);
+}
+
+// Device[Orientation|Motion]EventPump treat NaN as a missing value.
+let nullToNan = x => (x === null ? NaN : x);
+
+function setMockMotionData(sensorProvider, motionData) {
+ const degToRad = Math.PI / 180;
+ return Promise.all([
+ setMockSensorDataForType(sensorProvider, "Accelerometer", [
+ nullToNan(motionData.accelerationIncludingGravityX),
+ nullToNan(motionData.accelerationIncludingGravityY),
+ nullToNan(motionData.accelerationIncludingGravityZ),
+ ]),
+ setMockSensorDataForType(sensorProvider, "LinearAccelerationSensor", [
+ nullToNan(motionData.accelerationX),
+ nullToNan(motionData.accelerationY),
+ nullToNan(motionData.accelerationZ),
+ ]),
+ setMockSensorDataForType(sensorProvider, "Gyroscope", [
+ nullToNan(motionData.rotationRateAlpha) * degToRad,
+ nullToNan(motionData.rotationRateBeta) * degToRad,
+ nullToNan(motionData.rotationRateGamma) * degToRad,
+ ]),
+ ]);
+}
+
+function setMockOrientationData(sensorProvider, orientationData) {
+ let sensorType = orientationData.absolute
+ ? "AbsoluteOrientationEulerAngles" : "RelativeOrientationEulerAngles";
+ return setMockSensorDataForType(sensorProvider, sensorType, [
+ nullToNan(orientationData.beta),
+ nullToNan(orientationData.gamma),
+ nullToNan(orientationData.alpha),
+ ]);
+}
+
+function assertEventEquals(actualEvent, expectedEvent) {
+ for (let key1 of Object.keys(Object.getPrototypeOf(expectedEvent))) {
+ if (typeof expectedEvent[key1] === "object" && expectedEvent[key1] !== null) {
+ for (let key2 of Object.keys(expectedEvent[key1])) {
+ assert_equals(actualEvent[key1][key2], expectedEvent[key1][key2],
+ `$[key1].$[key2]`);
+ }
+ } else {
+ assert_equals(actualEvent[key1], expectedEvent[key1], key1);
+ }
+ }
+}
+
+function getExpectedOrientationEvent(expectedOrientationData) {
+ return new DeviceOrientationEvent('deviceorientation', {
+ alpha: expectedOrientationData.alpha,
+ beta: expectedOrientationData.beta,
+ gamma: expectedOrientationData.gamma,
+ absolute: expectedOrientationData.absolute,
+ });
+}
+
+function getExpectedAbsoluteOrientationEvent(expectedOrientationData) {
+ return new DeviceOrientationEvent('deviceorientationabsolute', {
+ alpha: expectedOrientationData.alpha,
+ beta: expectedOrientationData.beta,
+ gamma: expectedOrientationData.gamma,
+ absolute: expectedOrientationData.absolute,
+ });
+}
+
+function getExpectedMotionEvent(expectedMotionData) {
+ return new DeviceMotionEvent('devicemotion', {
+ acceleration: {
+ x: expectedMotionData.accelerationX,
+ y: expectedMotionData.accelerationY,
+ z: expectedMotionData.accelerationZ,
+ },
+ accelerationIncludingGravity: {
+ x: expectedMotionData.accelerationIncludingGravityX,
+ y: expectedMotionData.accelerationIncludingGravityY,
+ z: expectedMotionData.accelerationIncludingGravityZ,
+ },
+ rotationRate: {
+ alpha: expectedMotionData.rotationRateAlpha,
+ beta: expectedMotionData.rotationRateBeta,
+ gamma: expectedMotionData.rotationRateGamma,
+ },
+ interval: expectedMotionData.interval,
+ });
+}
+
+function waitForEvent(expected_event) {
+ return new Promise((resolve, reject) => {
+ window.addEventListener(expected_event.type, (event) => {
+ try {
+ assertEventEquals(event, expected_event);
+ resolve();
+ } catch (e) {
+ reject(e);
+ }
+ }, { once: true });
+ });
+}