File: RTCIceCandidate-constructor.html

package info (click to toggle)
thunderbird 1%3A140.4.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,609,432 kB
  • sloc: cpp: 7,672,442; javascript: 5,901,613; ansic: 3,898,954; python: 1,413,343; xml: 653,997; asm: 462,286; java: 180,927; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (265 lines) | stat: -rw-r--r-- 10,840 bytes parent folder | download | duplicates (12)
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<!doctype html>
<title>RTCIceCandidate constructor</title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
  'use strict';

  const candidateString = 'candidate:1905690388 1 udp 2113937151 192.168.0.1 58041 typ host generation 0 ufrag thC8 network-cost 50';
  const candidateString2 = 'candidate:435653019 2 tcp 1845501695 192.168.0.196 4444 typ srflx raddr www.example.com rport 22222 tcptype active';
  const arbitraryString = '<arbitrary string[0] content>;';

  test(t => {
    // The argument for RTCIceCandidateInit is optional (w3c/webrtc-pc #1153 #1166),
    // but the constructor throws because both sdpMid and sdpMLineIndex are null by default.
    // Note that current browsers pass this test but may throw TypeError for
    // different reason, i.e. they don't accept empty argument.
    // Further tests below are used to differentiate the errors.
    assert_throws_js(TypeError, () => new RTCIceCandidate());
  }, 'new RTCIceCandidate()');

  test(t => {
    // All fields in RTCIceCandidateInit are optional,
    // but the constructor throws because both sdpMid and sdpMLineIndex are null by default.
    // Note that current browsers pass this test but may throw TypeError for
    // different reason, i.e. they don't allow undefined candidate string.
    // Further tests below are used to differentiate the errors.
    assert_throws_js(TypeError, () => new RTCIceCandidate({}));
  }, 'new RTCIceCandidate({})');

  test(t => {
    // Checks that manually filling the default values for RTCIceCandidateInit
    // still throws because both sdpMid and sdpMLineIndex are null
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        candidate: '',
        sdpMid: null,
        sdpMLineIndex: null,
        usernameFragment: undefined
      }));
  }, 'new RTCIceCandidate({ ... }) with manually filled default values');

  test(t => {
    // Checks that explicitly setting both sdpMid and sdpMLineIndex null should throw
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        sdpMid: null,
        sdpMLineIndex: null
      }));
  }, 'new RTCIceCandidate({ sdpMid: null, sdpMLineIndex: null })');

  test(t => {
    // Throws because both sdpMid and sdpMLineIndex are null by default
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        candidate: ''
      }));
  }, `new RTCIceCandidate({ candidate: '' })`);

  test(t => {
    // Throws because both sdpMid and sdpMLineIndex are null by default
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        candidate: null
      }));
  }, `new RTCIceCandidate({ candidate: null })`);

  test(t => {
    // Throws because both sdpMid and sdpMLineIndex are null by default
    assert_throws_js(TypeError,
      () => new RTCIceCandidate({
        candidate: candidateString
      }));
  }, 'new RTCIceCandidate({ ... }) with valid candidate string only');

  test(t => {
    const candidate = new RTCIceCandidate({ sdpMid: 'audio' });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, `new RTCIceCandidate({ sdpMid: 'audio' })`);

  test(t => {
    const candidate = new RTCIceCandidate({ sdpMLineIndex: 0 });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, null, 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 0, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ sdpMLineIndex: 0 })');

  test(t => {
    const candidate = new RTCIceCandidate({
      sdpMid: 'audio',
      sdpMLineIndex: 0
    });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 0, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, `new RTCIceCandidate({ sdpMid: 'audio', sdpMLineIndex: 0 })`);

  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: '',
      sdpMid: 'audio'
    });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, `new RTCIceCandidate({ candidate: '', sdpMid: 'audio' }`);

  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: null,
      sdpMLineIndex: 0
    });

    assert_equals(candidate.candidate, 'null', 'candidate');
    assert_equals(candidate.sdpMid, null, 'sdpMid', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 0, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, `new RTCIceCandidate({ candidate: null, sdpMLineIndex: 0 }`);

  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: candidateString,
      sdpMid: 'audio'
    });

    assert_equals(candidate.candidate, candidateString, 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ ... }) with valid candidate string and sdpMid');

  test(t => {
    // candidate string is not validated in RTCIceCandidate
    const candidate = new RTCIceCandidate({
      candidate: arbitraryString,
      sdpMid: 'audio'
    });

    assert_equals(candidate.candidate, arbitraryString, 'candidate');
    assert_equals(candidate.sdpMid, 'audio', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ ... }) with invalid candidate string and sdpMid');

["most", "all"].forEach(howMany => {
  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: candidateString,
      sdpMid: 'video',
      sdpMLineIndex: 1,
      usernameFragment: 'test',
      relayProtocol: 'udp',
      url: 'stun:stun.example.org'
    });

    assert_equals(candidate.candidate, candidateString, 'candidate');
    assert_equals(candidate.sdpMid, 'video', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 1, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, 'test', 'usernameFragment');

    // The following fields should match those in the candidate field
    assert_equals(candidate.foundation, '1905690388', 'foundation');
    assert_equals(candidate.component, 'rtp', 'component');
    assert_equals(candidate.priority, 2113937151, 'priority');
    assert_equals(candidate.address, '192.168.0.1', 'address');
    assert_equals(candidate.protocol, 'udp', 'protocol');
    assert_equals(candidate.port, 58041, 'port');
    assert_equals(candidate.type, 'host', 'type');
    assert_equals(candidate.tcpType, null, 'tcpType');
    assert_equals(candidate.relatedAddress, null, 'relatedAddress');
    assert_equals(candidate.relatedPort, null, 'relatedPort');
    // The remaining fields are newer, so test them seperately
    if (howMany != "most") {
      assert_equals(candidate.relayProtocol, 'udp', 'relayProtocol');
      assert_equals(candidate.url, 'stun:stun.example.org', 'url');
    }
  }, `new RTCIceCandidate({ ... }) with nondefault values for ${howMany} fields`);

  test(t => {
    const candidate = new RTCIceCandidate({
      candidate: candidateString2,
      sdpMid: 'video',
      sdpMLineIndex: 1,
      usernameFragment: 'user1',
      relayProtocol: 'tcp',
      url: 'turn:turn.example.net'
    });

    assert_equals(candidate.candidate, candidateString2, 'candidate');
    assert_equals(candidate.sdpMid, 'video', 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 1, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, 'user1', 'usernameFragment');

    // The following fields should match those in the candidate field
    assert_equals(candidate.foundation, '435653019', 'foundation');
    assert_equals(candidate.component, 'rtcp', 'component');
    assert_equals(candidate.priority, 1845501695, 'priority');
    assert_equals(candidate.address, '192.168.0.196', 'address');
    assert_equals(candidate.protocol, 'tcp', 'protocol');
    assert_equals(candidate.port, 4444, 'port');
    assert_equals(candidate.type, 'srflx', 'type');
    assert_equals(candidate.tcpType, 'active', 'tcpType');
    assert_equals(candidate.relatedAddress, 'www.example.com', 'relatedAddress');
    assert_equals(candidate.relatedPort, 22222, 'relatedPort');
    // The remaining fields are newer, so test them seperately
    if (howMany != "most") {
      assert_equals(candidate.url, 'turn:turn.example.net', 'url');
      assert_equals(candidate.relayProtocol, 'tcp', 'relayProtocol');
    }
  }, `new RTCIceCandidate({ ... }) with nondefault values for ${howMany} fields, tcp candidate`);
});

  test(t => {
    let candidate = new RTCIceCandidate(new RTCIceCandidate({
      sdpMid: 'video',
      relayProtocol: 'tls',
      url: 'turn:turn.example.net'
    }));

    assert_equals(candidate.relayProtocol, 'tls', 'relayProtocol cloned');
    assert_equals(candidate.url, 'turn:turn.example.net', 'url cloned');

    candidate = new RTCIceCandidate(JSON.parse(JSON.stringify(candidate)));
    assert_equals(candidate.relayProtocol, null, 'relayProtocol not signaled');
    assert_equals(candidate.url, null, 'url not signaled');
  }, `new RTCIceCandidate({ relayProtocol, url }) cloned vs signaled`);

  test(t => {
    // sdpMid is not validated in RTCIceCandidate
    const candidate = new RTCIceCandidate({
      sdpMid: arbitraryString
    });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, arbitraryString, 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, null, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ ... }) with invalid sdpMid');


  test(t => {
    // Some arbitrary large out of bound line index that practically
    // do not reference any m= line in SDP.
    // However sdpMLineIndex is not validated in RTCIceCandidate
    // and it has no knowledge of the SDP it is associated with.
    const candidate = new RTCIceCandidate({
      sdpMLineIndex: 65535
    });

    assert_equals(candidate.candidate, '', 'candidate');
    assert_equals(candidate.sdpMid, null, 'sdpMid');
    assert_equals(candidate.sdpMLineIndex, 65535, 'sdpMLineIndex');
    assert_equals(candidate.usernameFragment, null, 'usernameFragment');
  }, 'new RTCIceCandidate({ ... }) with invalid sdpMLineIndex');

</script>