tor-browser

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

test_streams_capture_origin.html (2871B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Test for Bug 1189506</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 </head>
      9 <body>
     10 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1189506">Mozilla Bug 1189506</a>
     11 <p id="display"></p>
     12 <video id="vin"></video>
     13 <video id="vout"></video>
     14 <video id="vout_cors" crossorigin></video>
     15 <canvas id="cin" width="40" height="30"></canvas>
     16 <canvas id="cout" width="40" height="30"></canvas>
     17 <canvas id="cout_cors" width="40" height="30"></canvas>
     18 <div id="content" style="display: none">
     19 </div>
     20 <pre id="test">
     21 <script type="application/javascript">
     22 /* global vin, vout, vout_cors, cin, cout, cout_cors */
     23 
     24 /** Test for Bug 1189506 */
     25 
     26 SimpleTest.waitForExplicitFinish();
     27 
     28 async function start() {
     29  const resource = getPlayableVideo(gSmallTests).name;
     30  vin.src = "http://example.org:8000/tests/dom/media/test/" + resource;
     31  vin.preload = "metadata";
     32 
     33  await new Promise(r => vin.onloadedmetadata = r);
     34  vout.srcObject = vin.mozCaptureStreamUntilEnded();
     35  vout_cors.srcObject = vin.mozCaptureStreamUntilEnded();
     36  vin.play();
     37  vout.play();
     38  vout_cors.play();
     39 
     40  await new Promise(r => vout.onended = r);
     41  is(vin.ended, vout.ended, "Source media element ends first");
     42 
     43  const ctxin = SpecialPowers.wrap(cin.getContext("2d"));
     44  ctxin.drawImage(vin, 0, 0);
     45 
     46  {
     47    info("Testing that the last frame is rendered");
     48    const powerCtx = SpecialPowers.wrap(cout.getContext("2d"));
     49    powerCtx.drawImage(vout, 0, 0);
     50    const datain = ctxin.getImageData(0, 0, cin.width, cin.height);
     51    const dataout = powerCtx.getImageData(0, 0, cout.width, cout.height);
     52    for (let i = 0; i < datain.data.length; i += 4) {
     53      const pixelin = datain.data.slice(i, i + 4).join(',');
     54      const pixelout = dataout.data.slice(i, i + 4).join(',');
     55      if (pixelin != pixelout) {
     56        is(pixelout, pixelin, `Pixel #${i/4} is rendered as expected`);
     57        break;
     58      }
     59    }
     60    is(datain.data.length / 4, cin.width * cin.height,
     61      "Checked expected number of pixels");
     62  }
     63 
     64  {
     65    info("Testing that the principal is set");
     66    const ctx = cout.getContext("2d");
     67    ctx.drawImage(vout, 0, 0);
     68    SimpleTest.doesThrow(() => ctx.getImageData(0, 0, cout.width, cout.height),
     69      "SecurityError");
     70  }
     71 
     72  {
     73    info("Testing that the crossorigin attribute is ignored for MediaStreams");
     74    const ctx = cout_cors.getContext("2d");
     75    ctx.drawImage(vout_cors, 0, 0);
     76    SimpleTest.doesThrow(
     77      () => ctx.getImageData(0, 0, cout_cors.width, cout_cors.height),
     78      "SecurityError");
     79  }
     80 }
     81 
     82 (async () => {
     83  try { await start(); }
     84  catch(e) { ok(false, `Rejected with ${e}`); }
     85  finally { SimpleTest.finish(); }
     86 })();
     87 </script>
     88 </pre>
     89 </body>
     90 </html>