tor-browser

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

test_peerConnection_captureStream_canvas_2d.html (2610B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="pc.js"></script>
      5  <script type="application/javascript" src="/tests/dom/canvas/test/captureStream_common.js"></script>
      6 </head>
      7 <body>
      8 <pre id="test">
      9 <script type="application/javascript">
     10 createHTML({
     11  bug: "1032848",
     12  title: "Canvas(2D)::CaptureStream as video-only input to peerconnection",
     13  visible: true
     14 });
     15 
     16 runNetworkTest(async () => {
     17  // [TODO] re-enable HW decoder after bug 1526207 is fixed.
     18  if (navigator.userAgent.includes("Android")) {
     19    await pushPrefs(["media.navigator.mediadatadecoder_vpx_enabled", false],
     20                    ["media.webrtc.hw.h264.enabled", false]);
     21  }
     22 
     23  var test = new PeerConnectionTest();
     24  var mediaElement;
     25  var h = new CaptureStreamTestHelper2D();
     26  var canvas = document.createElement('canvas');
     27  var stream;
     28  canvas.id = 'source_canvas';
     29  canvas.width = canvas.height = 16;
     30  document.getElementById('content').appendChild(canvas);
     31 
     32  test.setMediaConstraints([{video: true}], []);
     33  test.chain.replace("PC_LOCAL_GUM", [
     34    function PC_LOCAL_CANVAS_CAPTURESTREAM(test) {
     35      h.drawColor(canvas, h.green);
     36      stream = canvas.captureStream(0);
     37      test.pcLocal.attachLocalStream(stream);
     38      stream.requestFrame();
     39      var i = 0;
     40      return setInterval(function() {
     41        try {
     42          info("draw " + i ? "green" : "red");
     43          h.drawColor(canvas, i ? h.green : h.red);
     44          i = 1 - i;
     45          stream.requestFrame();
     46        } catch (e) {
     47          // ignore; stream might have shut down, and we don't bother clearing
     48          // the setInterval.
     49        }
     50      }, 500);
     51    }
     52  ]);
     53  test.chain.append([
     54    function PC_REMOTE_WAIT_FOR_REMOTE_GREEN() {
     55      mediaElement = test.pcRemote.remoteMediaElements[0];
     56      ok(!!mediaElement, "Should have remote video element for pcRemote");
     57      return h.pixelMustBecome(mediaElement, h.green, {
     58        threshold: 128,
     59        infoString: "pcRemote's remote should become green",
     60      });
     61    },
     62    function PC_LOCAL_DRAW_LOCAL_RED() {
     63      // After requesting a frame it will be captured at the time of next render.
     64      // Next render will happen at next stable state, at the earliest,
     65      // i.e., this order of `requestFrame(); draw();` should work.
     66      stream.requestFrame();
     67      h.drawColor(canvas, h.red);
     68    },
     69    function PC_REMOTE_WAIT_FOR_REMOTE_RED() {
     70      return h.pixelMustBecome(mediaElement, h.red, {
     71        threshold: 128,
     72        infoString: "pcRemote's remote should become red",
     73      });
     74    }
     75  ]);
     76  await test.run();
     77 });
     78 </script>
     79 </pre>
     80 </body>
     81 </html>