BrowserCaptureMediaStreamTrack-cropTo.https.html (2279B)
1 <!doctype html> 2 <html> 3 4 <head> 5 <title>BrowserCaptureMediaStreamTrack cropTo()</title> 6 <link rel="help" href="https://github.com/w3c/mediacapture-region/"> 7 <meta charset="utf-8" /> 8 <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 9 <meta name="viewport" content="width=device-width, initial-scale=1" /> 10 </head> 11 12 <body> 13 <p class="instructions"> 14 When prompted, accept to give permission to use your audio, video devices. 15 </p> 16 <h1 class="instructions">Description</h1> 17 <p class="instructions"> 18 This test checks that BrowserCaptureMediaStreamTrack cropping works as 19 expected. 20 </p> 21 22 <button id="button">Start test</button> 23 <div id='test-div' width="500px" height="600px"></div> 24 25 <script src=/resources/testharness.js></script> 26 <script src=/resources/testharnessreport.js></script> 27 <script src=/resources/testdriver.js></script> 28 <script src=/resources/testdriver-vendor.js></script> 29 <script src=permission-helper.js></script> 30 31 <script> 32 "use strict"; 33 34 async function getDisplayMedia() { 35 const p = new Promise(r => button.onclick = r); 36 await test_driver.click(button); 37 await p; 38 return navigator.mediaDevices.getDisplayMedia( 39 {video:{displaySurface:"browser"}, selfBrowserSurface:"include"}); 40 } 41 42 promise_test(async t => { 43 const stream = await getDisplayMedia(); 44 assert_true(stream.active, "stream should be active."); 45 46 assert_equals(stream.getVideoTracks().length, 1); 47 const [videoTrack] = stream.getVideoTracks(); 48 assert_true(videoTrack instanceof MediaStreamTrack, 49 "track should be either MediaStreamTrack or a subclass thereof."); 50 assert_equals(videoTrack.readyState, "live"); 51 52 const div = document.getElementById('test-div'); 53 const cropTarget = await CropTarget.fromElement(div); 54 assert_true(!!videoTrack.cropTo, "cropTo exposed."); 55 assert_true(typeof videoTrack.cropTo === 'function', 56 "cropTo is a function."); 57 await videoTrack.cropTo(cropTarget); 58 59 assert_true(stream.active, "stream should be active."); 60 assert_false(videoTrack.muted, "track should not be muted."); 61 }, "Tests that cropping MediaStreamTrack objects works as expected"); 62 63 </script> 64 </body> 65 66 </html>