tor-browser

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

test_peerConnection_removeThenAddAudioTrackNoBundle.html (2986B)


      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 then add audio track"
     12  });
     13 
     14  runNetworkTest(function (options) {
     15    options = options || { };
     16    options.bundle = false;
     17    const test = new PeerConnectionTest(options);
     18    const audioContext = new AudioContext();
     19     // Start a tone so that the gUM call will record something even with
     20    // --use-test-media-devices.
     21    const tone = new LoopbackTone(audioContext, TEST_AUDIO_FREQ);
     22    tone.start();
     23    let originalTrack;
     24    addRenegotiation(test.chain,
     25      [
     26        function PC_REMOTE_FIND_RECEIVER(test) {
     27          is(test.pcRemote._pc.getReceivers().length, 1,
     28             "pcRemote should have one receiver");
     29          originalTrack = test.pcRemote._pc.getReceivers()[0].track;
     30        },
     31        function PC_LOCAL_REMOVE_AUDIO_TRACK(test) {
     32          // The new track's pipeline will start with a packet count of
     33          // 0, but the remote side will keep its old pipeline and packet
     34          // count.
     35          test.pcLocal.disableRtpCountChecking = true;
     36          return test.pcLocal.removeSender(0);
     37        },
     38        function PC_LOCAL_ADD_AUDIO_TRACK(test) {
     39          return test.pcLocal.getAllUserMediaAndAddStreams([{audio: true}]);
     40        },
     41        function PC_LOCAL_EXPECT_ICE_CHECKING(test) {
     42          test.pcLocal.expectIceChecking();
     43        },
     44        function PC_REMOTE_EXPECT_ICE_CHECKING(test) {
     45          test.pcRemote.expectIceChecking();
     46        },
     47      ],
     48      [
     49        function PC_REMOTE_CHECK_ADDED_TRACK(test) {
     50          is(test.pcRemote._pc.getTransceivers().length, 2,
     51              "pcRemote should have two transceivers");
     52          const track = test.pcRemote._pc.getTransceivers()[1].receiver.track;
     53 
     54          const analyser = new AudioStreamAnalyser(
     55              new AudioContext(), new MediaStream([track]));
     56          const freq = analyser.binIndexForFrequency(TEST_AUDIO_FREQ);
     57          return analyser.waitForAnalysisSuccess(arr => arr[freq] > 200);
     58        },
     59        function PC_REMOTE_CHECK_REMOVED_TRACK(test) {
     60          is(test.pcRemote._pc.getTransceivers().length, 2,
     61              "pcRemote should have two transceivers");
     62          const track = test.pcRemote._pc.getTransceivers()[0].receiver.track;
     63 
     64          const analyser = new AudioStreamAnalyser(
     65              new AudioContext(), new MediaStream([track]));
     66          const freq = analyser.binIndexForFrequency(TEST_AUDIO_FREQ);
     67          return analyser.waitForAnalysisSuccess(arr => arr[freq] < 50);
     68        }
     69      ]
     70    );
     71 
     72    test.chain.insertAfterEach('PC_LOCAL_CREATE_OFFER',
     73                               PC_LOCAL_REMOVE_BUNDLE_FROM_OFFER);
     74 
     75    test.setMediaConstraints([{audio: true}], [{audio: true}]);
     76    return test.run()
     77      .finally(() => tone.stop());
     78  });
     79 </script>
     80 </pre>
     81 </body>
     82 </html>