getdisplaymedia-framerate.https.html (1647B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>getDisplayMedia</title> 4 <meta name="timeout" content="long"> 5 <button id="button">User gesture</button> 6 <script src="/resources/testharness.js"></script> 7 <script src="/resources/testharnessreport.js"></script> 8 <script src="/resources/testdriver.js"></script> 9 <script src="/resources/testdriver-vendor.js"></script> 10 <video id="display"></video> 11 <script> 12 'use strict'; 13 14 const stopTracks = stream => stream.getTracks().forEach(track => track.stop()); 15 16 async function getDisplayMedia(constraints) { 17 const p = new Promise(r => button.onclick = r); 18 await test_driver.click(button); 19 await p; 20 return navigator.mediaDevices.getDisplayMedia(constraints); 21 } 22 23 promise_test( async t => { 24 const v = document.getElementById('display'); 25 v.autoplay = true; 26 // work around firefox bug 1586505, orthogonal to what's being tested 27 const frames = () => v.mozPaintedFrames ?? v.getVideoPlaybackQuality()?.totalVideoFrames; 28 const target_rate = 5; 29 const stream = await getDisplayMedia({video: {width:160, frameRate: target_rate}}); 30 t.add_cleanup(() => stopTracks(stream)); 31 v.srcObject = stream; 32 const intitial_time = v.currentTime; 33 const initial_frame_count = frames(); 34 await new Promise(r => t.step_timeout(r, 10000)); 35 const total_elapsed_frames = frames() - initial_frame_count; 36 const total_elapsed_time = v.currentTime - intitial_time; 37 const average_fps = total_elapsed_frames / total_elapsed_time; 38 assert_greater_than_equal(average_fps, target_rate * 0.50); 39 assert_less_than_equal(average_fps, target_rate * 1.75); 40 }, "getDisplayMedia() must adhere to frameRate if set"); 41 42 </script>