tor-browser

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

test_peerConnection_removeAudioTrack.html (2057B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript" src="pc.js"></script>
      5 </head>
      6 <body>
      7 <pre id="test">
      8 <script type="application/javascript">
      9  createHTML({
     10    bug: "1017888",
     11    title: "Renegotiation: remove audio track"
     12  });
     13 
     14  runNetworkTest(function (options) {
     15    const test = new PeerConnectionTest(options);
     16    const audioContext = new AudioContext();
     17     // Start a tone so that the gUM call will record something even with
     18    // --use-test-media-devices.
     19    const tone = new LoopbackTone(audioContext, TEST_AUDIO_FREQ);
     20    tone.start();
     21    let receivedTrack, analyser, freq;
     22    addRenegotiation(test.chain,
     23      [
     24        function PC_REMOTE_SETUP_ANALYSER(test) {
     25          is(test.pcRemote._pc.getReceivers().length, 1,
     26             "pcRemote should have one receiver before renegotiation");
     27 
     28          receivedTrack = test.pcRemote._pc.getReceivers()[0].track;
     29          is(receivedTrack.readyState, "live",
     30             "The received track should be live");
     31 
     32          analyser = new AudioStreamAnalyser(
     33              audioContext, new MediaStream([receivedTrack]));
     34          freq = analyser.binIndexForFrequency(TEST_AUDIO_FREQ);
     35 
     36          return analyser.waitForAnalysisSuccess(arr => arr[freq] > 200);
     37        },
     38        function PC_LOCAL_REMOVE_AUDIO_TRACK(test) {
     39          test.setOfferOptions({ offerToReceiveAudio: true });
     40          return test.pcLocal.removeSender(0);
     41        },
     42      ],
     43      [
     44        function PC_REMOTE_CHECK_FLOW_STOPPED(test) {
     45          // Simply removing a track is not enough to cause it to be
     46          // signaled as ended. Spec may change though.
     47          // TODO: One last check of the spec is in order
     48          is(receivedTrack.readyState, "live",
     49             "The received track should not have ended");
     50 
     51          return analyser.waitForAnalysisSuccess(arr => arr[freq] < 50);
     52        },
     53      ]
     54    );
     55 
     56    test.setMediaConstraints([{audio: true}], [{audio: true}]);
     57    return test.run()
     58      .finally(() => tone.stop());
     59  });
     60 </script>
     61 </pre>
     62 </body>
     63 </html>