usb-disabled-by-permissions-policy.https.sub.html (2131B)
1 <!DOCTYPE html> 2 <body> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/permissions-policy/resources/permissions-policy.js"></script> 6 <script> 7 'use strict'; 8 const sub = 'https://{{domains[www]}}:{{ports[https][0]}}'; 9 const same_origin_src = '/permissions-policy/resources/permissions-policy-usb.html'; 10 const cross_origin_src = sub + same_origin_src; 11 const same_origin_worker_frame_src = 12 '/permissions-policy/resources/permissions-policy-usb-worker.html'; 13 const cross_origin_worker_frame_src = sub + same_origin_worker_frame_src; 14 const header = 'Permissions-Policy header usb=()'; 15 16 promise_test(() => { 17 return navigator.usb.getDevices().then(() => { 18 assert_unreached('expected promise to reject with SecurityError'); 19 }, error => { 20 assert_equals(error.name, 'SecurityError'); 21 }); 22 }, header + ' disallows getDevices in the top-level document.'); 23 24 promise_test(async () => { 25 try { 26 await navigator.usb.requestDevice({ filters: [] }); 27 assert_unreached('expected promise to reject with SecurityError'); 28 } catch(error) { 29 assert_equals(error.name, 'SecurityError'); 30 } 31 }, header + ' disallows requestDevice in the top-level document.'); 32 33 async_test(t => { 34 test_feature_availability('usb.getDevices()', t, same_origin_src, 35 expect_feature_unavailable_default); 36 }, header + ' disallows same-origin iframes.'); 37 38 async_test(t => { 39 test_feature_availability('usb.getDevices()', t, same_origin_worker_frame_src, 40 expect_feature_unavailable_default); 41 }, header + ' disallows workers in same-origin iframes.'); 42 43 async_test(t => { 44 test_feature_availability('usb.getDevices()', t, cross_origin_src, 45 expect_feature_unavailable_default); 46 }, header + ' disallows cross-origin iframes.'); 47 48 async_test(t => { 49 test_feature_availability('usb.getDevices()', t, 50 cross_origin_worker_frame_src, 51 expect_feature_unavailable_default); 52 }, header + ' disallows workers in cross-origin iframes.'); 53 54 fetch_tests_from_worker(new Worker( 55 '/webusb/resources/usb-disabled-by-permissions-policy-worker.js')); 56 </script> 57 </body>