MediaStream-default-feature-policy.https.html (2370B)
1 <!DOCTYPE html> 2 <body> 3 <script src=/resources/testharness.js></script> 4 <script src=/resources/testharnessreport.js></script> 5 <script src=/resources/testdriver.js></script> 6 <script src=/resources/testdriver-vendor.js></script> 7 <script src=permission-helper.js></script> 8 <script src=/common/get-host-info.sub.js></script> 9 <script src=/feature-policy/resources/featurepolicy.js></script> 10 <script> 11 'use strict'; 12 async function gUM({audio, video}) { 13 let stream; 14 if (!page_loaded_in_iframe()) { 15 await setMediaPermission(); 16 } 17 try { 18 stream = await navigator.mediaDevices.getUserMedia({audio, video}); 19 // getUserMedia must guarantee the number of tracks requested or fail. 20 if ((audio && stream.getAudioTracks().length == 0) || 21 (video && stream.getVideoTracks().length == 0)) { 22 throw {name: `All requested devices must be present with ` + 23 `audio ${audio} and video ${video}, or fail`}; 24 } 25 } finally { 26 if (stream) { 27 stream.getTracks().forEach(track => track.stop()); 28 } 29 } 30 } 31 32 async function must_disallow_gUM({audio, video}) { 33 try { 34 await gUM({audio, video}); 35 } catch (e) { 36 if (e.name == 'NotAllowedError') { 37 return; 38 } 39 throw e; 40 } 41 throw {name: `audio ${audio} and video ${video} constraints must not be ` + 42 `allowed.`}; 43 } 44 45 const cross_domain = get_host_info().HTTPS_REMOTE_ORIGIN; 46 run_all_fp_tests_allow_self( 47 cross_domain, 48 'microphone', 49 'NotAllowedError', 50 async () => { 51 await gUM({audio: true}); 52 if (window.location.href.includes(cross_domain)) { 53 await must_disallow_gUM({video: true}); 54 await must_disallow_gUM({audio: true, video: true}); 55 } 56 } 57 ); 58 59 run_all_fp_tests_allow_self( 60 cross_domain, 61 'camera', 62 'NotAllowedError', 63 async () => { 64 await gUM({video: true}); 65 if (window.location.href.includes(cross_domain)) { 66 await must_disallow_gUM({audio: true}); 67 await must_disallow_gUM({audio: true, video: true}); 68 } 69 } 70 ); 71 72 run_all_fp_tests_allow_self( 73 cross_domain, 74 'camera;microphone', 75 'NotAllowedError', 76 async () => { 77 await gUM({audio: true, video: true}); 78 await gUM({audio: true}); 79 await gUM({video: true}); 80 } 81 ); 82 </script> 83 </body>