diff options
Diffstat (limited to 'testing/web-platform/tests/keyboard-map')
11 files changed, 239 insertions, 0 deletions
diff --git a/testing/web-platform/tests/keyboard-map/META.yml b/testing/web-platform/tests/keyboard-map/META.yml new file mode 100644 index 0000000000..4efb479ffe --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/META.yml @@ -0,0 +1,3 @@ +spec: https://wicg.github.io/keyboard-map/ +suggested_reviewers: + - garykac diff --git a/testing/web-platform/tests/keyboard-map/idlharness.https.window.js b/testing/web-platform/tests/keyboard-map/idlharness.https.window.js new file mode 100644 index 0000000000..07083f7034 --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/idlharness.https.window.js @@ -0,0 +1,20 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js + +// https://wicg.github.io/keyboard-map/ + +'use strict'; + +idl_test( + ['keyboard-map'], + ['keyboard-lock', 'html', 'dom'], + async idl_array => { + idl_array.add_objects({ + Navigator: ['navigator'], + Keyboard: ['navigator.keyboard'], + KeyboardLayoutMap: ['layout_map'], + }); + + self.layout_map = await navigator.keyboard.getLayoutMap(); + } +); diff --git a/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-allowed-from-cross-origin-iframe.https.html b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-allowed-from-cross-origin-iframe.https.html new file mode 100644 index 0000000000..04a8c85fd9 --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-allowed-from-cross-origin-iframe.https.html @@ -0,0 +1,30 @@ +<!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-keyboard-map-allow-helper.html'; + iframe.allow = "keyboard-map"; + 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 Map] getLayoutMap() allowed from within cross-origin iframe'); + +</script> diff --git a/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-allowed-from-iframe.https.html b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-allowed-from-iframe.https.html new file mode 100644 index 0000000000..6e0cd7de4b --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-allowed-from-iframe.https.html @@ -0,0 +1,29 @@ +<!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-keyboard-map-allow-helper.html'; + iframe.allow = "keyboard-map"; + 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 Map] getLayoutMap() allowed from within iframe'); + +</script> diff --git a/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-blocked-from-cross-origin-iframe.https.html b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-blocked-from-cross-origin-iframe.https.html new file mode 100644 index 0000000000..a38d4197f0 --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-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-keyboard-map-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 Map] getLayoutMap() blocked from within cross-origin iframe'); + +</script> diff --git a/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-blocked-from-iframe.https.html b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-blocked-from-iframe.https.html new file mode 100644 index 0000000000..a94082edf0 --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-blocked-from-iframe.https.html @@ -0,0 +1,29 @@ +<!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-keyboard-map-helper.html'; + iframe.allow = "keyboard-map 'none'"; + 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 Map] getLayoutMap() blocked from within iframe'); + +</script> diff --git a/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-two-parallel-requests.https.html b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-two-parallel-requests.https.html new file mode 100644 index 0000000000..875b9cc51e --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-two-parallel-requests.https.html @@ -0,0 +1,15 @@ +<!DOCTYPE html> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> +'use strict'; + +promise_test((t) => { + const p1 = navigator.keyboard.getLayoutMap(); + const p2 = navigator.keyboard.getLayoutMap(); + // p1 and p2 should be the same promise instance. + assert_equals(p1, p2); + return Promise.all([p1, p2]); +}, '[Keyboard Map] getLayoutMap() twice in parallel'); + +</script> diff --git a/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-two-sequential-requests.https.html b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-two-sequential-requests.https.html new file mode 100644 index 0000000000..c7f6b9d770 --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map-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.getLayoutMap() + .then(() => { + return navigator.keyboard.getLayoutMap(); + }); +}, '[Keyboard Map] getLayoutMap() called twice sequentially'); + +</script> diff --git a/testing/web-platform/tests/keyboard-map/navigator-keyboard-map.https.html b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map.https.html new file mode 100644 index 0000000000..b3ff14f362 --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/navigator-keyboard-map.https.html @@ -0,0 +1,34 @@ +<!DOCTYPE html> +<meta charset="utf-8"> +<title>Keyboard Map basic tests</title> +<script src="/resources/testharness.js"></script> +<script src="/resources/testharnessreport.js"></script> +<script> + +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.getLayoutMap instanceof Function); +}, "navigator.keyboard.getLayoutMap instanceof Function"); + +promise_test(() => { + const p = navigator.keyboard.getLayoutMap(); + assert_true(p instanceof Promise); + return p.then(function(map) { + assert_true(map instanceof KeyboardLayoutMap); + for (var [k,v] of map) { + assert_equals(typeof k, 'string'); + assert_not_equals(k.length, 0); + assert_equals(typeof v, 'string'); + assert_not_equals(v.length, 0); + } + }); +}, "navigator.keyboard.getLayoutMap() returns a Promise<KeyboardLayoutMap> when successful"); + +</script> diff --git a/testing/web-platform/tests/keyboard-map/resources/iframe-keyboard-map-allow-helper.html b/testing/web-platform/tests/keyboard-map/resources/iframe-keyboard-map-allow-helper.html new file mode 100644 index 0000000000..88b2fbff5d --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/resources/iframe-keyboard-map-allow-helper.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<script> +'use strict'; + +window.onmessage = message => { + if (message.data === 'Ready') { + let onSuccess = () => { parent.postMessage('Success', '*'); }; + let onError = error => { + parent.postMessage('Failure', '*'); + }; + + navigator.keyboard.getLayoutMap().then(onSuccess, onError).catch(onError); + } +}; + +</script> diff --git a/testing/web-platform/tests/keyboard-map/resources/iframe-keyboard-map-helper.html b/testing/web-platform/tests/keyboard-map/resources/iframe-keyboard-map-helper.html new file mode 100644 index 0000000000..7438029a19 --- /dev/null +++ b/testing/web-platform/tests/keyboard-map/resources/iframe-keyboard-map-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 == 'SecurityError') { + parent.postMessage('Success', '*'); + } else { + parent.postMessage('Failure', '*'); + } + }; + + navigator.keyboard.getLayoutMap().then(onSuccess, onError).catch(onError); + } +}; + +</script> |