summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_codecNegotiationFailure.html
blob: 819e13fe1b35904b203016b4ebe722678e2c37b1 (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
  <script type="application/javascript" src="iceTestUtils.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    bug: "1683934",
    title: "RTCPeerConnection check codec negotiation failure"
  });

  function makeWeirdCodecs(sdp) {
    return sdp
      .replaceAll('VP8', 'VEEEEEEEEP8')
      .replaceAll('VP9', 'VEEEEEEEEP9')
      .replaceAll('H264', 'HERP264');
  }

  const tests = [
    async function offererWeirdCodecs() {
      const pc1 = new RTCPeerConnection();
      const pc2 = new RTCPeerConnection();

      const stream = await navigator.mediaDevices.getUserMedia({video: true});
      pc1.addTrack(stream.getTracks()[0]);
      pc2.addTrack(stream.getTracks()[0]);

      const offer = await pc1.createOffer();
      offer.sdp = makeWeirdCodecs(offer.sdp);
      // It is not an error to receive an offer with no codecs we support
      await pc2.setRemoteDescription(offer);
      await pc2.setLocalDescription();
      await wait(2000);
    },

    async function answererWeirdCodecs() {
      const pc1 = new RTCPeerConnection();
      const pc2 = new RTCPeerConnection();

      const stream = await navigator.mediaDevices.getUserMedia({video: true});
      pc1.addTrack(stream.getTracks()[0]);
      pc2.addTrack(stream.getTracks()[0]);

      await pc1.setLocalDescription();
      await pc2.setRemoteDescription(pc1.localDescription);
      const answer = await pc2.createAnswer();
      answer.sdp = makeWeirdCodecs(answer.sdp);
      try {
        await pc1.setRemoteDescription(answer);
        ok(false, "Should have thrown");
      } catch (e) {
        ok(true, "Should have thrown");
      }
    },

    async function reoffererWeirdCodecs() {
      const pc1 = new RTCPeerConnection();
      const pc2 = new RTCPeerConnection();

      const stream = await navigator.mediaDevices.getUserMedia({video: true});
      pc1.addTrack(stream.getTracks()[0]);
      pc2.addTrack(stream.getTracks()[0]);

      await connect(pc1, pc2, 32000, "Initial connection");

      const offer = await pc1.createOffer();
      offer.sdp = makeWeirdCodecs(offer.sdp);
      // It is not an error to receive an offer with no codecs we support
      await pc2.setRemoteDescription(offer);
      await pc2.setLocalDescription();
      await wait(2000);
    },

    async function reanswererWeirdCodecs() {
      const pc1 = new RTCPeerConnection();
      const pc2 = new RTCPeerConnection();

      const stream = await navigator.mediaDevices.getUserMedia({video: true});
      pc1.addTrack(stream.getTracks()[0]);
      pc2.addTrack(stream.getTracks()[0]);

      await connect(pc1, pc2, 32000, "Initial connection");
      await pc1.setLocalDescription();
      await pc2.setRemoteDescription(pc1.localDescription);
      const answer = await pc2.createAnswer();
      answer.sdp = makeWeirdCodecs(answer.sdp);
      try {
        await pc1.setRemoteDescription(answer);
        ok(false, "Should have thrown");
      } catch (e) {
        ok(true, "Should have thrown");
      }
    },

  ];

  runNetworkTest(async () => {
    for (const test of tests) {
      info(`Running test: ${test.name}`);
      await test();
      info(`Done running test: ${test.name}`);
    }
  });

</script>
</pre>
</body>
</html>