diff options
Diffstat (limited to 'testing/web-platform/tests/device-posture')
4 files changed, 104 insertions, 0 deletions
diff --git a/testing/web-platform/tests/device-posture/device-posture-change-event.https.html b/testing/web-platform/tests/device-posture/device-posture-change-event.https.html new file mode 100644 index 0000000000..eb2fc2d96f --- /dev/null +++ b/testing/web-platform/tests/device-posture/device-posture-change-event.https.html @@ -0,0 +1,23 @@ +<!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> +'use strict'; + +promise_test(async (t) => { + t.add_cleanup(async () => { + await test_driver.clear_device_posture(); + }); + const watcher = new EventWatcher(t, navigator.devicePosture, ['change']); + const postures = ['folded', 'continuous', 'folded']; + for (const posture of postures) { + await Promise.all([ + watcher.wait_for('change'), + test_driver.set_device_posture(posture) + ]); + assert_equals(posture, navigator.devicePosture.type); + } +}, 'Tests the Device Posture API change event handler.'); +</script> diff --git a/testing/web-platform/tests/device-posture/device-posture-clear.https.html b/testing/web-platform/tests/device-posture/device-posture-clear.https.html new file mode 100644 index 0000000000..319cd7266a --- /dev/null +++ b/testing/web-platform/tests/device-posture/device-posture-clear.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> +'use strict'; + +promise_test(async (t) => { + t.add_cleanup(async () => { + await test_driver.clear_device_posture(); + }); + const originalPosture = navigator.devicePosture.type; + const posture = originalPosture ? 'folded' : 'continuous'; + + const watcher = new EventWatcher(t, navigator.devicePosture, ['change']); + await Promise.all([ + watcher.wait_for('change'), + test_driver.set_device_posture(posture) + ]); + assert_equals(navigator.devicePosture.type, posture); + + await Promise.all([ + watcher.wait_for('change'), + test_driver.clear_device_posture() + ]); + assert_equals(navigator.devicePosture.type, originalPosture); +}, 'Tests that device posture override can be removed.'); +</script> diff --git a/testing/web-platform/tests/device-posture/device-posture-event-listener.https.html b/testing/web-platform/tests/device-posture/device-posture-event-listener.https.html new file mode 100644 index 0000000000..f4e21c89cc --- /dev/null +++ b/testing/web-platform/tests/device-posture/device-posture-event-listener.https.html @@ -0,0 +1,25 @@ +<!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> +'use strict'; + +promise_test(async (t) => { + t.add_cleanup(async () => { + await test_driver.clear_device_posture(); + }); + assert_equals(navigator.devicePosture.type, 'continuous'); + + const promise = new Promise(resolve => { + navigator.devicePosture.addEventListener( + 'change', + () => { resolve(navigator.devicePosture.type); }, + { once: true } + ); + }); + await test_driver.set_device_posture('folded'); + assert_equals(await promise, 'folded'); +}, 'Tests the Device Posture API addEventListener change event handler.'); +</script> diff --git a/testing/web-platform/tests/device-posture/device-posture-media-queries.https.html b/testing/web-platform/tests/device-posture/device-posture-media-queries.https.html new file mode 100644 index 0000000000..e4dbd2e7d8 --- /dev/null +++ b/testing/web-platform/tests/device-posture/device-posture-media-queries.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> +'use strict'; + +promise_test(async (t) => { + t.add_cleanup(async () => { + await test_driver.clear_device_posture(); + }); + assert_equals(navigator.devicePosture.type, 'continuous'); + assert_true(matchMedia('(device-posture: continuous)').matches); + + const foldedMQL = window.matchMedia('(device-posture: folded)'); + const promise = new Promise(resolve => { + foldedMQL.addEventListener( + 'change', + () => { resolve(foldedMQL.matches); }, + { once: true } + ); + }); + await test_driver.set_device_posture('folded'); + assert_true(await promise); +}, 'Tests the Device Posture API Media Query change event handler.'); +</script> |