tor-browser

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

test_peerConnection_removeThenAddVideoTrack.html (3661B)


      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: "1017888",
     12    title: "Renegotiation: remove then add video track"
     13  });
     14 
     15  runNetworkTest(async function (options) {
     16    // Use fake video here since the native fake device on linux doesn't
     17    // change color as needed by checkVideoPlaying() below.
     18    await pushPrefs(
     19      ['media.video_loopback_dev', ''],
     20      ['media.navigator.streams.fake', true]);
     21    // [TODO] re-enable HW decoder after bug 1526207 is fixed.
     22    if (navigator.userAgent.includes("Android")) {
     23      await pushPrefs(["media.navigator.mediadatadecoder_vpx_enabled", false],
     24                      ["media.webrtc.hw.h264.enabled", false]);
     25    }
     26 
     27    const test = new PeerConnectionTest(options);
     28    const helper = new VideoStreamHelper();
     29    var originalTrack;
     30    let haveMuteEvent = new Promise(() => {});
     31    let haveUnmuteEvent = new Promise(() => {});
     32    addRenegotiation(test.chain,
     33      [
     34        function PC_REMOTE_FIND_RECEIVER(test) {
     35          is(test.pcRemote._pc.getReceivers().length, 1,
     36             "pcRemote should have one receiver");
     37          originalTrack = test.pcRemote._pc.getReceivers()[0].track;
     38        },
     39        function PC_LOCAL_REMOVE_VIDEO_TRACK(test) {
     40          // The new track's pipeline will start with a packet count of
     41          // 0, but the remote side will keep its old pipeline and packet
     42          // count.
     43          test.pcLocal.disableRtpCountChecking = true;
     44          return test.pcLocal.removeSender(0);
     45        },
     46        function PC_LOCAL_ADD_VIDEO_TRACK(test) {
     47          return test.pcLocal.getAllUserMediaAndAddStreams([{video: true}]);
     48        },
     49      ],
     50      [
     51        function PC_REMOTE_WAIT_FOR_UNMUTE() {
     52          return haveUnmuteEvent;
     53        },
     54        function PC_REMOTE_CHECK_ADDED_TRACK(test) {
     55          is(test.pcRemote._pc.getTransceivers().length, 2,
     56              "pcRemote should have two transceivers");
     57          const track = test.pcRemote._pc.getTransceivers()[1].receiver.track;
     58 
     59          const vAdded = test.pcRemote.remoteMediaElements.find(
     60              elem => elem.id.includes(track.id));
     61          return helper.checkVideoPlaying(vAdded);
     62        },
     63        function PC_REMOTE_WAIT_FOR_MUTE() {
     64          return haveMuteEvent;
     65        },
     66        function PC_REMOTE_CHECK_REMOVED_TRACK(test) {
     67          is(test.pcRemote._pc.getTransceivers().length, 2,
     68              "pcRemote should have two transceivers");
     69          const track = test.pcRemote._pc.getTransceivers()[0].receiver.track;
     70 
     71          const vAdded = test.pcRemote.remoteMediaElements.find(
     72              elem => elem.id.includes(track.id));
     73          return helper.checkVideoPaused(vAdded, 10, 10, 16, 5000);
     74        }
     75      ]
     76    );
     77 
     78    // The first track should mute when the connection is closed.
     79    test.chain.insertBefore("PC_REMOTE_SET_REMOTE_DESCRIPTION", [
     80      function PC_REMOTE_SETUP_ONMUTE(test) {
     81        haveMuteEvent = haveEvent(test.pcRemote._pc.getReceivers()[0].track, "mute");
     82      }
     83    ]);
     84 
     85    // Second negotiation should cause the second track to unmute.
     86    test.chain.insertAfter("PC_REMOTE_SET_REMOTE_DESCRIPTION", [
     87      function PC_REMOTE_SETUP_ONUNMUTE(test) {
     88        haveUnmuteEvent = haveEvent(test.pcRemote._pc.getReceivers()[1].track, "unmute");
     89      }
     90    ], false, 1);
     91 
     92    test.setMediaConstraints([{video: true}], [{video: true}]);
     93    await test.run();
     94  });
     95 </script>
     96 </pre>
     97 </body>
     98 </html>