tor-browser

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

test_streams_individual_pause.html (2504B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for bug 1073406. Pausing a video element should not pause another playing the same stream.</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      7  <script type="text/javascript" src="manifest.js"></script>
      8  <script type="text/javascript" src="gUM_support.js"></script>
      9 </head>
     10 <body>
     11 <video id="video1" autoplay></video>
     12 <video id="video2" autoplay></video>
     13 <script class="testbody" type="text/javascript">
     14 function getVideoImagePixelData(v) {
     15  const canvas = document.createElement("canvas");
     16  const ctx = canvas.getContext("2d");
     17  ctx.drawImage(v, 0, 0);
     18  const imgData = ctx.getImageData(canvas.width/2, canvas.height/2, 1, 1).data;
     19  return "r" + imgData[0] +
     20         "g" + imgData[1] +
     21         "b" + imgData[2] +
     22         "a" + imgData[3];
     23 }
     24 
     25 async function startTest() {
     26  // This test expects fake devices so that the video color will change
     27  // over time, explicitly request fakes.
     28  await pushGetUserMediaTestPrefs({fakeAudio: true, fakeVideo: true});
     29  const stream = await navigator.mediaDevices.getUserMedia({video: true});
     30  const video1 = document.getElementById('video1');
     31  const video2 = document.getElementById('video2');
     32 
     33  video1.srcObject = stream;
     34  video2.srcObject = stream;
     35 
     36  await new Promise(r => video1.onplaying = r);
     37  video1.pause();
     38  await new Promise(r => video1.onpause = r);
     39 
     40  const v1PausedImageData = getVideoImagePixelData(video1);
     41  const v2PausedImageData = getVideoImagePixelData(video2);
     42 
     43  while (getVideoImagePixelData(video2) == v2PausedImageData) {
     44    info("video2 has not progressed. Waiting.");
     45    await new Promise(r => video2.ontimeupdate = r);
     46  }
     47 
     48  // Wait for a while to be sure video1 would have gotten a frame
     49  // if it is playing.
     50  for (let i = 3; i != 0; i--) {
     51    await new Promise(r => video2.ontimeupdate = r);
     52  }
     53  info("video2 progressed OK");
     54 
     55  isnot(video1.currentTime, video2.currentTime,
     56        "v1 and v2 should not be at the same currentTime");
     57  is(getVideoImagePixelData(video1), v1PausedImageData,
     58     "video1 video frame should not have updated since video1 paused");
     59 
     60  for (const t of stream.getTracks()) {
     61    t.stop();
     62  }
     63 }
     64 
     65 SimpleTest.waitForExplicitFinish();
     66 (async function() {
     67  try {
     68    await startTest();
     69  } catch(error) {
     70    ok(false, "getUserMedia should not fail, got " + error.name);
     71  } finally {
     72    SimpleTest.finish();
     73  }
     74 })();
     75 </script>
     76 </body>
     77 </html>