summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_addAudioTrackToExistingVideoStream.html
blob: b0a60ee46b8752abeef1619a38571fb100fae130 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1246310",
    title: "Renegotiation: add audio track to existing video-only stream",
  });

  runNetworkTest(function (options) {
    SimpleTest.requestCompleteLog();

    const audioContext = new AudioContext();
    // Start a tone so that the gUM call will record something even with
    // --use-test-media-devices.  TEST_AUDIO_FREQ matches the frequency of the
    // tone in fake microphone devices.
    const tone = new LoopbackTone(audioContext, TEST_AUDIO_FREQ);
    tone.start();

    const test = new PeerConnectionTest(options);
    test.chain.replace("PC_LOCAL_GUM",
      [
        function PC_LOCAL_GUM_ATTACH_VIDEO_ONLY(test) {
          var localConstraints = {audio: true, video: true};
          test.setMediaConstraints([{video: true}], []);
          return getUserMedia(localConstraints)
            .then(s => test.originalGumStream = s)
            .then(() => is(test.originalGumStream.getAudioTracks().length, 1,
                           "Should have 1 audio track"))
            .then(() => is(test.originalGumStream.getVideoTracks().length, 1,
                           "Should have 1 video track"))
            .then(() => test.pcLocal.attachLocalTrack(
                          test.originalGumStream.getVideoTracks()[0],
                          test.originalGumStream));
        },
      ]
    );
    addRenegotiation(test.chain,
      [
        function PC_LOCAL_ATTACH_SECOND_TRACK_AUDIO(test) {
          test.setMediaConstraints([{audio: true, video: true}], []);
          return test.pcLocal.attachLocalTrack(
                   test.originalGumStream.getAudioTracks()[0],
                   test.originalGumStream);
        },
      ],
      [
        function PC_CHECK_REMOTE_AUDIO_FLOW(test) {
          return test.pcRemote.checkReceivingToneFrom(audioContext, test.pcLocal);
        }
      ]
    );

    return test.run()
      .finally(() => tone.stop());
  });
</script>
</pre>
</body>
</html>