Commit 44d28534 authored by Ovidio Henriquez's avatar Ovidio Henriquez Committed by Commit Bot

Add WebUSB FeaturePolicy WPT for Workers

This change adds Feature Policy tests for Dedicated Workers.

Bug: 841510
Change-Id: I117f8a5bb61d5783b6867e7edcc9d99aff41a497
Reviewed-on: https://chromium-review.googlesource.com/1093379
Commit-Queue: Ovidio Henriquez <odejesush@chromium.org>
Reviewed-by: default avatarReilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568170}
parent aa03d3a0
<script>
'use strict';
let worker = new Worker('feature-policy-usb-worker.js');
worker.onmessage = event => {
window.parent.postMessage(event.data, '*');
};
worker.postMessage({ type: 'ready' });
</script>
\ No newline at end of file
'use strict';
// Dedicated worker
if (typeof postMessage === 'function') {
onmessage = event => {
switch(event.data.type) {
case 'ready':
navigator.usb.getDevices().then(
() => postMessage({ enabled: true }),
error => postMessage ({ enabled: false }));
break;
}
};
}
\ No newline at end of file
'use strict';
importScripts('/resources/testharness.js');
let workerType;
if (typeof postMessage === 'function') {
workerType = 'dedicated';
}
promise_test(() => navigator.usb.getDevices(),
`Inherited header feature policy allows ${workerType} workers.`);
done();
'use strict';
importScripts('/resources/testharness.js');
const header = 'Feature-Policy header {"usb" : []}';
let workerType;
if (typeof postMessage === 'function') {
workerType = 'dedicated';
}
promise_test(() => navigator.usb.getDevices().then(
() => assert_unreached('expected promise to reject with SecurityError'),
error => assert_equals(error.name, 'SecurityError')),
`Inherited ${header} disallows ${workerType} workers.`);
done();
......@@ -5,12 +5,17 @@
<script src=/feature-policy/resources/featurepolicy.js></script>
<script>
'use strict';
var relative_path = '/feature-policy/resources/feature-policy-usb.html';
var base_src = '/feature-policy/resources/redirect-on-load.html#';
var same_origin_src = base_src + relative_path;
var cross_origin_src = base_src + 'https://{{domains[www]}}:{{ports[https][0]}}' +
relative_path;
var header = 'Feature-Policy allow="usb"';
const relative_path = '/feature-policy/resources/feature-policy-usb.html';
const base_src = '/feature-policy/resources/redirect-on-load.html#';
const relative_worker_frame_path =
'/feature-policy/resources/feature-policy-usb-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 = 'Feature-Policy allow="usb"';
async_test(t => {
test_feature_availability(
......@@ -18,10 +23,22 @@ async_test(t => {
expect_feature_available_default, 'usb');
}, header + ' allows same-origin relocation.');
async_test(t => {
test_feature_availability(
'usb.getDevices()', t, same_origin_worker_frame_src,
expect_feature_available_default, 'usb');
}, header + ' allows workers in same-origin relocation.');
async_test(t => {
test_feature_availability(
'usb.getDevices()', t, cross_origin_src,
expect_feature_unavailable_default, 'usb');
}, header + ' disallows cross-origin relocation.');
async_test(t => {
test_feature_availability(
'usb.getDevices()', t, cross_origin_worker_frame_src,
expect_feature_unavailable_default, 'usb');
}, header + ' disallows workers in cross-origin relocation.');
</script>
</body>
......@@ -5,11 +5,14 @@
<script src=/feature-policy/resources/featurepolicy.js></script>
<script>
'use strict';
var same_origin_src = '/feature-policy/resources/feature-policy-usb.html';
var cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' +
same_origin_src;
var feature_name = 'Feature policy "usb"';
var header = 'allow="usb" attribute';
const sub = 'https://{{domains[www]}}:{{ports[https][0]}}';
const same_origin_src = '/feature-policy/resources/feature-policy-usb.html';
const cross_origin_src = sub + same_origin_src;
const same_origin_worker_frame_src =
'/feature-policy/resources/feature-policy-usb-worker.html';
const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src;
const feature_name = 'Feature policy "usb"';
const header = 'allow="usb" attribute';
async_test(t => {
test_feature_availability(
......@@ -17,10 +20,27 @@ async_test(t => {
expect_feature_available_default, 'usb');
}, feature_name + ' can be enabled in same-origin iframe using ' + header);
async_test(t => {
test_feature_availability(
'usb.getDevices()', t, same_origin_worker_frame_src,
expect_feature_available_default, 'usb');
}, feature_name + ' can be enabled in a worker in same-origin iframe using ' +
header);
async_test(t => {
test_feature_availability(
'usb.getDevices()', t, cross_origin_src,
expect_feature_available_default, 'usb');
}, feature_name + ' can be enabled in cross-origin iframe using ' + header);
async_test(t => {
test_feature_availability(
'usb.getDevices()', t, cross_origin_worker_frame_src,
expect_feature_available_default, 'usb');
}, feature_name + ' can be enabled in a worker in cross-origin iframe using ' +
header);
fetch_tests_from_worker(new Worker(
'/webusb/resources/usb-allowed-by-feature-policy-worker.js'));
</script>
</body>
......@@ -5,10 +5,13 @@
<script src=/feature-policy/resources/featurepolicy.js></script>
<script>
'use strict';
var same_origin_src = '/feature-policy/resources/feature-policy-usb.html';
var cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' +
same_origin_src;
var header = 'Feature-Policy header {"usb" : ["*"]}';
const sub = 'https://{{domains[www]}}:{{ports[https][0]}}';
const same_origin_src = '/feature-policy/resources/feature-policy-usb.html';
const cross_origin_src = sub + same_origin_src;
const same_origin_worker_frame_src =
'/feature-policy/resources/feature-policy-usb-worker.html';
const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src;
const header = 'Feature-Policy header {"usb" : ["*"]}';
promise_test(
() => navigator.usb.getDevices(),
......@@ -19,9 +22,23 @@ async_test(t => {
expect_feature_available_default);
}, header + ' allows same-origin iframes.');
async_test(t => {
test_feature_availability('usb.getDevices()', t, same_origin_worker_frame_src,
expect_feature_available_default);
}, header + ' allows workers in same-origin iframes.');
async_test(t => {
test_feature_availability('usb.getDevices()', t, cross_origin_src,
expect_feature_available_default);
}, header + ' allows cross-origin iframes.');
async_test(t => {
test_feature_availability('usb.getDevices()', t,
cross_origin_worker_frame_src,
expect_feature_available_default);
}, header + ' allows workers in cross-origin iframes.');
fetch_tests_from_worker(new Worker(
'/webusb/resources/usb-allowed-by-feature-policy-worker.js'));
</script>
</body>
......@@ -5,10 +5,13 @@
<script src=/feature-policy/resources/featurepolicy.js></script>
<script>
'use strict';
var same_origin_src = '/feature-policy/resources/feature-policy-usb.html';
var cross_origin_src = 'https://{{domains[www]}}:{{ports[https][0]}}' +
same_origin_src;
var header = 'Feature-Policy header {"usb" : []}';
const sub = 'https://{{domains[www]}}:{{ports[https][0]}}';
const same_origin_src = '/feature-policy/resources/feature-policy-usb.html';
const cross_origin_src = sub + same_origin_src;
const same_origin_worker_frame_src =
'/feature-policy/resources/feature-policy-usb-worker.html';
const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src;
const header = 'Feature-Policy header {"usb" : []}';
promise_test(() => {
return navigator.usb.getDevices().then(() => {
......@@ -23,9 +26,23 @@ async_test(t => {
expect_feature_unavailable_default);
}, header + ' disallows same-origin iframes.');
async_test(t => {
test_feature_availability('usb.getDevices()', t, same_origin_worker_frame_src,
expect_feature_unavailable_default);
}, header + ' disallows workers in same-origin iframes.');
async_test(t => {
test_feature_availability('usb.getDevices()', t, cross_origin_src,
expect_feature_unavailable_default);
}, header + ' disallows cross-origin iframes.');
async_test(t => {
test_feature_availability('usb.getDevices()', t,
cross_origin_worker_frame_src,
expect_feature_unavailable_default);
}, header + ' disallows workers in cross-origin iframes.');
fetch_tests_from_worker(new Worker(
'/webusb/resources/usb-disabled-by-feature-policy-worker.js'));
</script>
</body>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment