summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/webrtc-extensions/RTCRtpTransceiver-headerExtensionControl.html
blob: e823bd830c6e34c159dc511c05721a40b69586b1 (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<!doctype html>
<meta charset=utf-8>
<title>RTCRtpParameters encodings</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webrtc/dictionary-helper.js"></script>
<script src="/webrtc/RTCRtpParameters-helper.js"></script>
<script>
'use strict';

async function negotiate(pc1, pc2) {
  const offer = await pc1.createOffer();
  await pc1.setLocalDescription(offer);
  await pc2.setRemoteDescription(offer);
  const answer = await pc2.createAnswer();
  await pc2.setLocalDescription(answer);
  await pc1.setRemoteDescription(answer);
}

test(function(t) {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const transceiver = pc.addTransceiver('video');
  const capabilities = transceiver.headerExtensionsToOffer;
  let capability = capabilities.find((capability) => {
      return capability.uri == "urn:ietf:params:rtp-hdrext:sdes:mid" &&
             capability.direction != "stopped";
  });
  assert_not_equals(capability, undefined);
  capability = capabilities.find((capability) => {
      return capability.uri == "urn:3gpp:video-orientation" &&
             capability.direction != "stopped";
  });
  assert_not_equals(capability, undefined);
}, `the video transceiver.headerExtensionsToOffer() includes mandatory extensions`);

test(function(t) {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const transceiver = pc.addTransceiver('audio');
  const capabilities = transceiver.headerExtensionsToOffer;
  let capability = capabilities.find((capability) => {
      return capability.uri == "urn:ietf:params:rtp-hdrext:sdes:mid" &&
             capability.direction != "stopped";
  });
  assert_not_equals(capability, undefined);
}, `the audio transceiver.headerExtensionsToOffer() includes mandatory extensions`);

test(function(t) {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const transceiver = pc.addTransceiver('audio');
  const capabilities = transceiver.headerExtensionsToOffer;
  capabilities[0].uri = "";
  assert_throws_js(TypeError, () => {
    transceiver.setOfferedRtpHeaderExtensions(capabilities);
  }, 'transceiver should throw TypeError when setting an empty URI');
}, `setOfferedRtpHeaderExtensions throws TypeError on encountering missing URI`);

test(function(t) {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const transceiver = pc.addTransceiver('audio');
  const capabilities = transceiver.headerExtensionsToOffer;
  capabilities[0].uri = "4711";
  assert_throws_dom("NotSupportedError", () => {
    transceiver.setOfferedRtpHeaderExtensions(capabilities);
  }, 'transceiver should throw NotSupported when setting an unknown URI');
}, `setOfferedRtpHeaderExtensions throws NotSupported on encountering unknown URI`);

test(function(t) {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const transceiver = pc.addTransceiver('audio');
  const capabilities = transceiver.headerExtensionsToOffer;
  let capability = capabilities.find((capability) => {
      return capability.uri == "urn:ietf:params:rtp-hdrext:sdes:mid";
  });
  ["sendonly", "recvonly", "inactive", "stopped"].map(direction => {
    capability.direction = direction;
    assert_throws_dom("InvalidModificationError", () => {
      transceiver.setOfferedRtpHeaderExtensions(capabilities);
    }, `transceiver should throw InvalidModificationError when setting a mandatory header extension\'s direction to ${direction}`);
  });
}, `setOfferedRtpHeaderExtensions throws InvalidModificationError when setting a mandatory header extension\'s direction to something else than "sendrecv"`);

test(function(t) {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const transceiver = pc.addTransceiver('audio');
  let capabilities = transceiver.headerExtensionsToOffer;
  let selected_capability = capabilities.find((capability) => {
      return capability.direction == "sendrecv" &&
             capability.uri != "urn:ietf:params:rtp-hdrext:sdes:mid";
  });
  selected_capability.direction = "stopped";
  const offered_capabilities = transceiver.headerExtensionsToOffer;
  let altered_capability = capabilities.find((capability) => {
      return capability.uri == selected_capability.uri &&
             capability.direction == "stopped";
  });
  assert_not_equals(altered_capability, undefined);
}, `modified direction set by setOfferedRtpHeaderExtensions is visible in headerExtensionsOffered`);

promise_test(async t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const transceiver = pc.addTransceiver('video');
  const capabilities = transceiver.headerExtensionsToOffer;
  const offer = await pc.createOffer();
  const extmaps = offer
                      .sdp
                      .split("\n")
                      .filter(line => { return line.includes("a=extmap"); })
                      .join("\n");
  for (const capability of capabilities) {
    if (capability.direction == "stopped") {
      assert_false(extmaps.includes(capability.uri));
    } else {
      assert_true(extmaps.includes(capability.uri));
    }
  }
}, `unstopped extensions turn up in offer`);

promise_test(async t => {
  const pc = new RTCPeerConnection();
  t.add_cleanup(() => pc.close());
  const transceiver = pc.addTransceiver('video');
  const capabilities = transceiver.headerExtensionsToOffer;
  const selected_capability = capabilities.find((capability) => {
      return capability.direction == "sendrecv" &&
             capability.uri != "urn:ietf:params:rtp-hdrext:sdes:mid" &&
             capability.uri != "urn:3gpp:video-orientation";
  });
  selected_capability.direction = "stopped";
  transceiver.setOfferedRtpHeaderExtensions(capabilities);
  const offer = await pc.createOffer();
  const extmaps = offer
                      .sdp
                      .split("\n")
                      .filter(line => { return line.includes("a=extmap"); })
                      .join("\n");
  for (const capability of capabilities) {
    if (capability.direction == "stopped") {
      assert_false(extmaps.includes(capability.uri));
    } else {
      assert_true(extmaps.includes(capability.uri));
    }
  }
}, `stopped extensions do not turn up in offers`);

promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());

  // Disable a non-mandatory extension before first negotiation.
  const transceiver = pc1.addTransceiver('video');
  const capabilities = transceiver.headerExtensionsToOffer;
  const selected_capability = capabilities.find((capability) => {
      return capability.direction == "sendrecv" &&
             capability.uri != "urn:ietf:params:rtp-hdrext:sdes:mid" &&
             capability.uri != "urn:3gpp:video-orientation";
  });
  selected_capability.direction = "stopped";
  transceiver.setOfferedRtpHeaderExtensions(capabilities);

  await negotiate(pc1, pc2);
  const negotiated_capabilites = transceiver.headerExtensionsNegotiated;

  // Attempt enabling the extension.
  selected_capability.direction = "sendrecv";

  // The enabled extension should not be part of the negotiated set.
  transceiver.setOfferedRtpHeaderExtensions(capabilities);
  await negotiate(pc1, pc2);
  assert_not_equals(
      transceiver.headerExtensionsNegotiated.find(capability => {
        return capability.uri == selected_capability.uri &&
               capability.direction == "sendrecv";
      }), undefined);
}, `the set of negotiated extensions grows with subsequent offers`);

promise_test(async t => {
  const pc1 = new RTCPeerConnection();
  t.add_cleanup(() => pc1.close());
  const pc2 = new RTCPeerConnection();
  t.add_cleanup(() => pc2.close());

  // Disable a non-mandatory extension before first negotiation.
  const transceiver = pc1.addTransceiver('video');
  const capabilities = transceiver.headerExtensionsToOffer;
  const selected_capability = capabilities.find((capability) => {
      return capability.direction == "sendrecv" &&
             capability.uri != "urn:ietf:params:rtp-hdrext:sdes:mid" &&
             capability.uri != "urn:3gpp:video-orientation";
  });
  selected_capability.direction = "stopped";
  transceiver.setOfferedRtpHeaderExtensions(capabilities);

  await negotiate(pc1, pc2);
  const negotiated_capabilites = transceiver.headerExtensionsNegotiated;

  for (const capability of negotiated_capabilites) {
    assert_not_equals(capabilities.find((cap) => {
      return cap.uri == capability.uri && cap.direction != "stopped";
    }), undefined);
  }
  for (const capability of capabilities) {
    if (capability.direction != "stopped") {
      assert_not_equals(negotiated_capabilites.find((cap) => {
        return cap.uri == capability.uri;
      }), undefined);
    }
  }
}, `the set of negotiated extensions is the set of unstopped extensions`);

</script>