-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1919972 [wpt PR 48244] - WebHID: Add support for dedicated worker…
…s, a=testonly Automatic update from web-platform-tests WebHID: Add support for dedicated workers This CL exposes the WebHID API to dedicated workers behind the blink runtime feature WebHIDOnDedicatedWorkers. Intent to prototype: https://groups.google.com/a/chromium.org/g/blink-dev/c/y__BOYfZWzI Spec PR: WICG/webhid#121 Spec issue: WICG/webhid#120 Demo: https://webhid-worker.glitch.me/ Change-Id: If145f34faf9211a54c8b4a15fbe7e903411b8d1d Bug: 365932453 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5841991 Reviewed-by: Arthur Sonzogni <arthursonzogni@chromium.org> Reviewed-by: Yoav Weiss (@Shopify) <yoavweiss@chromium.org> Reviewed-by: Matt Reynolds <mattreynolds@chromium.org> Commit-Queue: Fr <beaufort.francois@gmail.com> Cr-Commit-Position: refs/heads/main@{#1357046} -- wpt-commits: f3a05bb7fe21b6e6d8fbf5923d53abfc7c04fd66 wpt-pr: 48244
- Loading branch information
1 parent
b323897
commit 7f2dadf
Showing
11 changed files
with
212 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
testing/web-platform/tests/permissions-policy/resources/permissions-policy-hid-worker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script> | ||
'use strict'; | ||
|
||
let worker = new Worker('permissions-policy-hid-worker.js'); | ||
|
||
worker.onmessage = event => { | ||
window.parent.postMessage(event.data, '*'); | ||
}; | ||
worker.postMessage({ type: 'ready' }); | ||
</script> |
14 changes: 14 additions & 0 deletions
14
testing/web-platform/tests/permissions-policy/resources/permissions-policy-hid-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
// Dedicated worker | ||
if (typeof postMessage === 'function') { | ||
onmessage = event => { | ||
switch(event.data.type) { | ||
case 'ready': | ||
navigator.hid.getDevices().then( | ||
() => postMessage({ type: 'availability-result', enabled: true }), | ||
error => postMessage ({ type: 'availability-result', enabled: false })); | ||
break; | ||
} | ||
}; | ||
} |
9 changes: 9 additions & 0 deletions
9
testing/web-platform/tests/permissions-policy/resources/permissions-policy-hid.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script> | ||
'use strict'; | ||
|
||
Promise.resolve().then(() => navigator.hid.getDevices()).then(devices => { | ||
window.parent.postMessage({ type: 'availability-result', enabled: true }, '*'); | ||
}, error => { | ||
window.parent.postMessage({ type: 'availability-result', enabled: false }, '*'); | ||
}); | ||
</script> |
44 changes: 44 additions & 0 deletions
44
.../tests/webhid/hid-allowed-by-permissions-policy-attribute-redirect-on-load.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/permissions-policy/resources/permissions-policy.js></script> | ||
<script> | ||
'use strict'; | ||
const relative_path = '/permissions-policy/resources/permissions-policy-hid.html'; | ||
const base_src = '/permissions-policy/resources/redirect-on-load.html#'; | ||
const relative_worker_frame_path = | ||
'/permissions-policy/resources/permissions-policy-hid-worker.html'; | ||
const sub = 'https://{{domains[www]}}:{{ports[https][0]}}'; | ||
const same_origin_src = base_src + relative_path; | ||
const cross_origin_src = base_src + sub + relative_path; | ||
const same_origin_worker_frame_src = base_src + relative_worker_frame_path; | ||
const cross_origin_worker_frame_src = base_src + sub + | ||
relative_worker_frame_path; | ||
const header = 'Permissions-Policy allow="hid"'; | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
'hid.getDevices()', t, same_origin_src, | ||
expect_feature_available_default, 'hid'); | ||
}, header + ' allows same-origin relocation.'); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
'hid.getDevices()', t, same_origin_worker_frame_src, | ||
expect_feature_available_default, 'hid'); | ||
}, header + ' allows workers in same-origin relocation.'); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
'hid.getDevices()', t, cross_origin_src, | ||
expect_feature_unavailable_default, 'hid'); | ||
}, header + ' disallows cross-origin relocation.'); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
'hid.getDevices()', t, cross_origin_worker_frame_src, | ||
expect_feature_unavailable_default, 'hid'); | ||
}, header + ' disallows workers in cross-origin relocation.'); | ||
</script> | ||
</body> |
46 changes: 46 additions & 0 deletions
46
testing/web-platform/tests/webhid/hid-allowed-by-permissions-policy-attribute.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/permissions-policy/resources/permissions-policy.js></script> | ||
<script> | ||
'use strict'; | ||
const sub = 'https://{{domains[www]}}:{{ports[https][0]}}'; | ||
const same_origin_src = '/permissions-policy/resources/permissions-policy-hid.html'; | ||
const cross_origin_src = sub + same_origin_src; | ||
const same_origin_worker_frame_src = | ||
'/permissions-policy/resources/permissions-policy-hid-worker.html'; | ||
const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src; | ||
const feature_name = 'Permissions policy "hid"'; | ||
const header = 'allow="hid" attribute'; | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
'hid.getDevices()', t, same_origin_src, | ||
expect_feature_available_default, 'hid'); | ||
}, feature_name + ' can be enabled in same-origin iframe using ' + header); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
'hid.getDevices()', t, same_origin_worker_frame_src, | ||
expect_feature_available_default, 'hid'); | ||
}, feature_name + ' can be enabled in a worker in same-origin iframe using ' + | ||
header); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
'hid.getDevices()', t, cross_origin_src, | ||
expect_feature_available_default, 'hid'); | ||
}, feature_name + ' can be enabled in cross-origin iframe using ' + header); | ||
|
||
async_test(t => { | ||
test_feature_availability( | ||
'hid.getDevices()', t, cross_origin_worker_frame_src, | ||
expect_feature_available_default, 'hid'); | ||
}, feature_name + ' can be enabled in a worker in cross-origin iframe using ' + | ||
header); | ||
|
||
fetch_tests_from_worker(new Worker( | ||
'/webhid/resources/hid-allowed-by-permissions-policy-worker.js')); | ||
</script> | ||
</body> |
46 changes: 46 additions & 0 deletions
46
testing/web-platform/tests/webhid/hid-allowed-by-permissions-policy.https.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<body> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/permissions-policy/resources/permissions-policy.js></script> | ||
<script> | ||
'use strict'; | ||
const sub = 'https://{{domains[www]}}:{{ports[https][0]}}'; | ||
const same_origin_src = '/permissions-policy/resources/permissions-policy-hid.html'; | ||
const cross_origin_src = sub + same_origin_src; | ||
const same_origin_worker_frame_src = | ||
'/permissions-policy/resources/permissions-policy-hid-worker.html'; | ||
const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src; | ||
const header = 'Permissions-Policy header hid=*'; | ||
|
||
promise_test( | ||
() => navigator.hid.getDevices(), | ||
header + ' allows the top-level document.'); | ||
|
||
async_test(t => { | ||
test_feature_availability('hid.getDevices()', t, same_origin_src, | ||
expect_feature_available_default); | ||
}, header + ' allows same-origin iframes.'); | ||
|
||
async_test(t => { | ||
test_feature_availability('hid.getDevices()', t, same_origin_worker_frame_src, | ||
expect_feature_available_default); | ||
}, header + ' allows workers in same-origin iframes.'); | ||
|
||
// Set allow="hid" on iframe element to delegate 'hid' to cross origin subframe. | ||
async_test(t => { | ||
test_feature_availability('hid.getDevices()', t, cross_origin_src, | ||
expect_feature_available_default, 'hid'); | ||
}, header + ' allows cross-origin iframes.'); | ||
|
||
// Set allow="hid" on iframe element to delegate 'hid' to cross origin subframe. | ||
async_test(t => { | ||
test_feature_availability('hid.getDevices()', t, | ||
cross_origin_worker_frame_src, | ||
expect_feature_available_default, 'hid'); | ||
}, header + ' allows workers in cross-origin iframes.'); | ||
|
||
fetch_tests_from_worker(new Worker( | ||
'/webhid/resources/hid-allowed-by-permissions-policy-worker.js')); | ||
</script> | ||
</body> |
1 change: 1 addition & 0 deletions
1
testing/web-platform/tests/webhid/hid-allowed-by-permissions-policy.https.sub.html.headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Permissions-Policy: hid=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
testing/web-platform/tests/webhid/resources/hid-allowed-by-permissions-policy-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use strict'; | ||
|
||
importScripts('/resources/testharness.js'); | ||
|
||
let workerType; | ||
|
||
if (typeof postMessage === 'function') { | ||
workerType = 'dedicated'; | ||
} | ||
|
||
promise_test(() => navigator.hid.getDevices(), | ||
`Inherited header permissions policy allows ${workerType} workers.`); | ||
|
||
done(); |
17 changes: 17 additions & 0 deletions
17
testing/web-platform/tests/webhid/resources/hid-disabled-by-permissions-policy-worker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
importScripts('/resources/testharness.js'); | ||
|
||
const header = 'Permissions-Policy header hid=()'; | ||
let workerType; | ||
|
||
if (typeof postMessage === 'function') { | ||
workerType = 'dedicated'; | ||
} | ||
|
||
promise_test(() => navigator.hid.getDevices().then( | ||
() => assert_unreached('expected promise to reject with SecurityError'), | ||
error => assert_equals(error.name, 'SecurityError')), | ||
`Inherited ${header} disallows ${workerType} workers.`); | ||
|
||
done(); |