tor-browser

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

test_peerConnection_verifyVideoAfterRenegotiation.html (3615B)


      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: "1166832",
     12    title: "Renegotiation: verify video after renegotiation"
     13  });
     14 
     15 runNetworkTest(async () => {
     16  // [TODO] re-enable HW decoder after bug 1526207 is fixed.
     17  if (navigator.userAgent.includes("Android")) {
     18    await pushPrefs(["media.navigator.mediadatadecoder_vpx_enabled", false],
     19                    ["media.webrtc.hw.h264.enabled", false]);
     20  }
     21 
     22  const test = new PeerConnectionTest();
     23 
     24  const h1 = new CaptureStreamTestHelper2D(50, 50);
     25  const canvas1 = h1.createAndAppendElement('canvas', 'source_canvas1');
     26  let stream1;
     27  let vremote1;
     28 
     29  const h2 = new CaptureStreamTestHelper2D(50, 50);
     30  let canvas2;
     31  let stream2;
     32  let vremote2;
     33 
     34  test.setMediaConstraints([{video: true}], []);
     35  test.chain.replace("PC_LOCAL_GUM", [
     36    function DRAW_INITIAL_LOCAL_GREEN(test) {
     37      h1.drawColor(canvas1, h1.green);
     38    },
     39    function PC_LOCAL_CANVAS_CAPTURESTREAM(test) {
     40      stream1 = canvas1.captureStream(0);
     41      test.pcLocal.attachLocalStream(stream1);
     42      let i = 0;
     43      return setInterval(function() {
     44        try {
     45          info("draw " + i ? "green" : "red");
     46          h1.drawColor(canvas1, i ? h1.green : h1.red);
     47          i = 1 - i;
     48          stream1.requestFrame();
     49          if (stream2 != null) {
     50            h2.drawColor(canvas2, i ? h2.green : h2.blue);
     51            stream2.requestFrame();
     52          }
     53        } catch (e) {
     54          // ignore; stream might have shut down, and we don't bother clearing
     55          // the setInterval.
     56        }
     57      }, 500);
     58    }
     59  ]);
     60 
     61  test.chain.append([
     62    function FIND_REMOTE_VIDEO() {
     63      vremote1 = test.pcRemote.remoteMediaElements[0];
     64      ok(!!vremote1, "Should have remote video element for pcRemote");
     65    },
     66    function WAIT_FOR_REMOTE_GREEN() {
     67      return h1.pixelMustBecome(vremote1, h1.green, {
     68        threshold: 128,
     69        infoString: "pcRemote's remote should become green",
     70      });
     71    },
     72    function WAIT_FOR_REMOTE_RED() {
     73      return h1.pixelMustBecome(vremote1, h1.red, {
     74        threshold: 128,
     75        infoString: "pcRemote's remote should become red",
     76      });
     77    }
     78  ]);
     79 
     80  addRenegotiation(test.chain,
     81    [
     82      function PC_LOCAL_ADD_SECOND_STREAM(test) {
     83        canvas2 = h2.createAndAppendElement('canvas', 'source_canvas2');
     84        h2.drawColor(canvas2, h2.blue);
     85        stream2 = canvas2.captureStream(0);
     86 
     87        // can't use test.pcLocal.getAllUserMediaAndAddStreams([{video: true}]);
     88        // because it doesn't let us substitute the capture stream
     89        test.pcLocal.attachLocalStream(stream2);
     90      }
     91    ]
     92  );
     93 
     94  test.chain.append([
     95    function FIND_REMOTE2_VIDEO() {
     96      vremote2 = test.pcRemote.remoteMediaElements[1];
     97      ok(!!vremote2, "Should have remote2 video element for pcRemote");
     98    },
     99    function WAIT_FOR_REMOTE2_BLUE() {
    100      return h2.pixelMustBecome(vremote2, h2.blue, {
    101        threshold: 128,
    102        infoString: "pcRemote's remote2 should become blue",
    103      });
    104    },
    105    function DRAW_NEW_LOCAL_GREEN(test) {
    106      stream1.requestFrame();
    107      h1.drawColor(canvas1, h1.green);
    108    },
    109    function WAIT_FOR_REMOTE1_GREEN() {
    110      return h1.pixelMustBecome(vremote1, h1.green, {
    111        threshold: 128,
    112        infoString: "pcRemote's remote1 should become green",
    113      });
    114    }
    115  ]);
    116 
    117  await test.run();
    118 });
    119 
    120 </script>
    121 </pre>
    122 </body>
    123 </html>