diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /testing/web-platform/tests/keyboard-lock | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.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/keyboard-lock')
9 files changed, 167 insertions, 0 deletions
diff --git a/testing/web-platform/tests/keyboard-lock/META.yml b/testing/web-platform/tests/keyboard-lock/META.yml new file mode 100644 index 0000000000..06c48b4045 --- /dev/null +++ b/testing/web-platform/tests/keyboard-lock/META.yml @@ -0,0 +1,4 @@ +spec: https://wicg.github.io/keyboard-lock/ +suggested_reviewers: + - garykac + - joedow-42 diff --git a/testing/web-platform/tests/keyboard-lock/idlharness.https.window.js b/testing/web-platform/tests/keyboard-lock/idlharness.https.window.js new file mode 100644 index 0000000000..66bb7b9bc8 --- /dev/null +++ b/testing/web-platform/tests/keyboard-lock/idlharness.https.window.js @@ -0,0 +1,18 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: timeout=long + +// https://w3c.github.io/keyboard-lock/ + +'use strict'; + +idl_test( + ['keyboard-lock'], + ['html', 'dom'], + idl_array => { + idl_array.add_objects({ + Navigator: ['navigator'], + Keyboard: ['navigator.keyboard'], + }); + } +); diff --git a/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-blocked-from-cross-origin-iframe.https.html b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-blocked-from-cross-origin-iframe.https.html new file mode 100644 index 0000000000..ef79c0c80a --- /dev/null +++ b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-blocked-from-cross-origin-iframe.https.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script src="/cors/support.js?pipe=sub"></script> +<body> +<script> +'use strict'; + +promise_test(() => { + let iframe = document.createElement('iframe'); + iframe.src = CROSSDOMAIN + 'resources/iframe-lock-helper.html'; + iframe.onload = () => { + iframe.contentWindow.postMessage('Ready', '*'); + } + + document.body.appendChild(iframe); + + return new Promise((resolve,reject) => { + window.onmessage = message => { + if (message.data == 'Success') { + resolve(); + } else if (message.data == 'Failure') { + reject(); + } + } + }); +}, '[Keyboard Lock] lock method call blocked from within cross-origin iframe'); + +</script> diff --git a/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-blocked-from-iframe.https.html b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-blocked-from-iframe.https.html new file mode 100644 index 0000000000..a01f6a2fc7 --- /dev/null +++ b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-blocked-from-iframe.https.html @@ -0,0 +1,28 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<body> +<script> +'use strict'; + +promise_test(() => { + let iframe = document.createElement('iframe'); + iframe.src = 'resources/iframe-lock-helper.html'; + iframe.onload = () => { + iframe.contentWindow.postMessage('Ready', '*'); + } + + document.body.appendChild(iframe); + + return new Promise((resolve,reject) => { + window.onmessage = message => { + if (message.data == 'Success') { + resolve(); + } else if (message.data == 'Failure') { + reject(); + } + } + }); +}, '[Keyboard Lock] navigator.keyboard.lock blocked from within iframe'); + +</script> diff --git a/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-two-parallel-requests.https.html b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-two-parallel-requests.https.html new file mode 100644 index 0000000000..c01b106992 --- /dev/null +++ b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-two-parallel-requests.https.html @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +'use strict'; + +promise_test((t) => { + const p1 = navigator.keyboard.lock(["KeyA", "KeyB"]); + const p2 = navigator.keyboard.lock(["KeyC", "KeyD"]); + return Promise.all([promise_rejects_dom(t, "AbortError", p1), p2]); +}, '[Keyboard Lock] keyboard.lock twice in parallel'); + +</script> diff --git a/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-two-sequential-requests.https.html b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-two-sequential-requests.https.html new file mode 100644 index 0000000000..520da36dfb --- /dev/null +++ b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock-two-sequential-requests.https.html @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +'use strict'; + +promise_test(() => { + return navigator.keyboard.lock(["KeyA", "KeyB"]) + .then(() => { + return navigator.keyboard.lock(["KeyC", "KeyD"]); + }); +}, '[Keyboard Lock] keyboard.lock called twice sequentially'); + +</script> diff --git a/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock.https.html b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock.https.html new file mode 100644 index 0000000000..674c336459 --- /dev/null +++ b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-lock.https.html @@ -0,0 +1,29 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +'use strict'; + +test(function() { + assert_true(navigator.keyboard instanceof Keyboard); +}, "navigator.keyboard instanceof Keyboard"); + +test(function() { + assert_equals(navigator.keyboard, navigator.keyboard); +}, "navigator.keyboard SameObject"); + +test(function() { + assert_true(navigator.keyboard.lock instanceof Function); +}, "navigator.keyboard.lock instanceof Function"); + +test(function() { + assert_true(navigator.keyboard.unlock instanceof Function); +}, "navigator.keyboard.unlock instanceof Function"); + +promise_test(() => { + const p = navigator.keyboard.lock(["KeyA", "KeyB"]); + assert_true(p instanceof Promise); + return p; +}, '[Keyboard Lock] keyboard.lock'); + +</script> diff --git a/testing/web-platform/tests/keyboard-lock/navigator-keyboard-unlock.https.html b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-unlock.https.html new file mode 100644 index 0000000000..87b10ee49a --- /dev/null +++ b/testing/web-platform/tests/keyboard-lock/navigator-keyboard-unlock.https.html @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +'use strict'; + +test(() => { + assert_equals(navigator.keyboard.unlock(), + undefined); +}, '[Keyboard Lock] keyboard.unlock'); + +</script> diff --git a/testing/web-platform/tests/keyboard-lock/resources/iframe-lock-helper.html b/testing/web-platform/tests/keyboard-lock/resources/iframe-lock-helper.html new file mode 100644 index 0000000000..3950802f8e --- /dev/null +++ b/testing/web-platform/tests/keyboard-lock/resources/iframe-lock-helper.html @@ -0,0 +1,20 @@ +<!DOCTYPE html> +<script> +'use strict'; + +window.onmessage = message => { + if (message.data === 'Ready') { + let onSuccess = () => { parent.postMessage('Failure', '*'); }; + let onError = error => { + if (error.name == 'InvalidStateError') { + parent.postMessage('Success', '*'); + } else { + parent.postMessage('Failure', '*'); + } + }; + + navigator.keyboard.lock().then(onSuccess, onError); + } +}; + +</script> |