tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

video-test-helper.js (1520B)


      1 // Helper functions checking video flow using HTMLVideoElement.
      2 
      3 async function test_resolution_equals(t, track, width, height) {
      4  const video = document.createElement("video");
      5  const timeout = new Promise(r => t.step_timeout(r, 1000));
      6  const waitForResize = () => Promise.race([
      7        new Promise(r => video.onresize = r),
      8        timeout.then(() => { throw new Error("Timeout waiting for resize"); }),
      9      ]);
     10  video.srcObject = new MediaStream([track]);
     11  video.play();
     12  // Wait for the first frame.
     13  await waitForResize();
     14  // There's a potential race with applyConstraints, where a frame of the old
     15  // resolution is in flight and renders after applyConstraints has resolved.
     16  // In that case, wait for another frame.
     17  if (video.videoWidth != width || video.videoHeight != height) {
     18    await waitForResize();
     19  }
     20 
     21  assert_equals(video.videoWidth, width, "videoWidth");
     22  assert_equals(video.videoHeight, height, "videoHeight");
     23 }
     24 
     25 async function test_framerate_between_exclusive(t, track, lower, upper) {
     26  const video = document.createElement("video");
     27  document.body.appendChild(video);
     28  video.style = "width:320px;height:240px;"
     29  t.add_cleanup(async () => document.body.removeChild(video));
     30 
     31  video.srcObject = new MediaStream([track]);
     32  await video.play();
     33 
     34  const numSeconds = 2;
     35  await new Promise(r => setTimeout(r, numSeconds * 1000));
     36  const totalVideoFrames = video.mozPaintedFrames;
     37  assert_between_exclusive(totalVideoFrames / numSeconds, lower, upper, "totalVideoFrames");
     38 }