diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/orientation-event/motion | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/orientation-event/motion')
13 files changed, 793 insertions, 0 deletions
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..262715ce55 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/add-during-dispatch.https.html @@ -0,0 +1,36 @@ +<!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'; + +promise_test(async (t) => { + const helper = new SensorTestHelper(t, 'devicemotion'); + await helper.grantSensorsPermissions(); + await helper.initializeSensors(); + + const motionData = generateMotionData(1, 2, 3, + 4, 5, 6, + 7, 8, 9); + await helper.setData(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 called until the outer function returns. + assertEventEquals(event2, getExpectedMotionEvent(motionData)); + result(); + }, {once: true}); + + result = resolve; + }, {once: true}); + }); +}, '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..1f8cca86b2 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/add-listener-from-callback.https.html @@ -0,0 +1,53 @@ +<!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'; + +promise_test(async (t) => { + const helper = new SensorTestHelper(t, 'devicemotion'); + await helper.grantSensorsPermissions(); + await helper.initializeSensors(); + + 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); + }; + }); + + await helper.setData(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..f94c9d136e --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/multiple-event-listeners.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'; + +promise_test(async (t) => { + const helper = new SensorTestHelper(t, 'devicemotion'); + await helper.grantSensorsPermissions(); + await helper.initializeSensors(); + + const motionData1 = generateMotionData(1, 2, 3, + 4, 5, 6, + 7, 8, 9); + await helper.setData(motionData1); + await Promise.all([ + waitForEvent(getExpectedMotionEvent(motionData1)), + waitForEvent(getExpectedMotionEvent(motionData1)) + ]); + + const motionData2 = generateMotionData(11, 12, 13, + 14, 15, 16, + 17, 18, 19); + await helper.setData(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..f875afcd64 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/null-values.https.html @@ -0,0 +1,53 @@ +<!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'; + +promise_test(async (t) => { + const helper = new SensorTestHelper(t, 'devicemotion'); + await helper.grantSensorsPermissions(); + + 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); + + await helper.initializeSensors({disabledSensors: ['accelerometer','gyroscope']}); + await helper.setData(motionData1); + await waitForEvent(getExpectedMotionEvent(motionData1)); + // If test needs to change virtual sensor state from connected to not + // connected or vise versa, reset needs to be called. It removes created + // virtual sensors and creating them with different connection state is then + // possible. + await helper.reset(); + + await helper.initializeSensors({disabledSensors: ['linear-acceleration','gyroscope']}); + await helper.setData(motionData2); + await waitForEvent(getExpectedMotionEvent(motionData2)); + await helper.reset(); + + await helper.initializeSensors({disabledSensors: ['accelerometer','linear-acceleration']}); + await helper.setData(motionData3); + await waitForEvent(getExpectedMotionEvent(motionData3)); + await helper.reset(); + + await helper.initializeSensors({disabledSensors: ['accelerometer','linear-acceleration','gyroscope']}); + await helper.setData(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.https.html b/testing/web-platform/tests/orientation-event/motion/page-visibility.https.html new file mode 100644 index 0000000000..2925af9331 --- /dev/null +++ b/testing/web-platform/tests/orientation-event/motion/page-visibility.https.html @@ -0,0 +1,52 @@ +<!DOCTYPE html> +<html> +<body> +<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="/page-visibility/resources/window_state_context.js"></script> +<script src="../resources/orientation-event-helpers.js"></script> +<script> +'use strict'; + +promise_test(async (t) => { + const helper = new SensorTestHelper(t, 'devicemotion'); + await helper.grantSensorsPermissions(); + await helper.initializeSensors(); + + const motionData = generateMotionData(0, 0, 0, + 0, 0, 0, + 0, 0, 0); + + await helper.setData(motionData); + const event = getExpectedMotionEvent(motionData); + await waitForEvent(event); + + const {minimize, restore} = window_state_context(t); + await minimize(); + assert_true(document.hidden); + + let hiddenEventPromise = new Promise((resolve, reject) => { + window.addEventListener( + 'devicemotion', + event => { + if (document.hidden) { + reject(); + } else { + resolve(); + } + }, + { once: true }); + }); + + // devicemotion events fire every 16ms when active, so we sleep for a while + // here to make sure we're not actually getting any events. + await new Promise(resolve => { t.step_timeout(resolve, 100); }); + await restore(); + assert_false(document.hidden); + return Promise.all([hiddenEventPromise, waitForEvent(event)]); +}, 'Tests to check that devicemotion events are not fired when the page is not visible.'); +</script> +</body> +</html> 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> + |