-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathRTCConfiguration-bundlePolicy.html
201 lines (174 loc) · 8.8 KB
/
RTCConfiguration-bundlePolicy.html
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
<!doctype html>
<meta charset=utf-8>
<title>RTCConfiguration bundlePolicy</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="RTCPeerConnection-helper.js"></script>
<script src="./third_party/sdp/sdp.js"></script>
<script>
'use strict';
// Test is based on the following editor draft:
// https://w3c.github.io/webrtc-pc/archives/20170605/webrtc.html
/*
4.3.2. Interface Definition
[Constructor(optional RTCConfiguration configuration)]
interface RTCPeerConnection : EventTarget {
...
RTCConfiguration getConfiguration();
void setConfiguration(RTCConfiguration configuration);
};
4.2.1. RTCConfiguration Dictionary
dictionary RTCConfiguration {
RTCBundlePolicy bundlePolicy = "balanced";
...
};
4.2.6. RTCBundlePolicy Enum
enum RTCBundlePolicy {
"balanced",
"max-compat",
"max-bundle"
};
*/
test(() => {
const pc = new RTCPeerConnection();
assert_equals(pc.getConfiguration().bundlePolicy, 'balanced');
}, 'Default bundlePolicy should be balanced');
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: undefined });
assert_equals(pc.getConfiguration().bundlePolicy, 'balanced');
}, `new RTCPeerConnection({ bundlePolicy: undefined }) should have bundlePolicy balanced`);
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: 'balanced' });
assert_equals(pc.getConfiguration().bundlePolicy, 'balanced');
}, `new RTCPeerConnection({ bundlePolicy: 'balanced' }) should succeed`);
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: 'max-compat' });
assert_equals(pc.getConfiguration().bundlePolicy, 'max-compat');
}, `new RTCPeerConnection({ bundlePolicy: 'max-compat' }) should succeed`);
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' });
assert_equals(pc.getConfiguration().bundlePolicy, 'max-bundle');
}, `new RTCPeerConnection({ bundlePolicy: 'max-bundle' }) should succeed`);
test(() => {
const pc = new RTCPeerConnection();
pc.setConfiguration({});
}, 'setConfiguration({}) with initial default bundlePolicy balanced should succeed');
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: 'balanced' });
pc.setConfiguration({});
}, 'setConfiguration({}) with initial bundlePolicy balanced should succeed');
test(() => {
const pc = new RTCPeerConnection();
pc.setConfiguration({ bundlePolicy: 'balanced' });
}, 'setConfiguration({ bundlePolicy: balanced }) with initial default bundlePolicy balanced should succeed');
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: 'balanced' });
pc.setConfiguration({ bundlePolicy: 'balanced' });
}, `setConfiguration({ bundlePolicy: 'balanced' }) with initial bundlePolicy balanced should succeed`);
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: 'max-compat' });
pc.setConfiguration({ bundlePolicy: 'max-compat' });
}, `setConfiguration({ bundlePolicy: 'max-compat' }) with initial bundlePolicy max-compat should succeed`);
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' });
pc.setConfiguration({ bundlePolicy: 'max-bundle' });
}, `setConfiguration({ bundlePolicy: 'max-bundle' }) with initial bundlePolicy max-bundle should succeed`);
test(() => {
assert_throws_js(TypeError, () =>
new RTCPeerConnection({ bundlePolicy: null }));
}, `new RTCPeerConnection({ bundlePolicy: null }) should throw TypeError`);
test(() => {
assert_throws_js(TypeError, () =>
new RTCPeerConnection({ bundlePolicy: 'invalid' }));
}, `new RTCPeerConnection({ bundlePolicy: 'invalid' }) should throw TypeError`);
/*
4.3.2. Interface Definition
To set a configuration
5. If configuration.bundlePolicy is set and its value differs from the
connection's bundle policy, throw an InvalidModificationError.
*/
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' });
assert_idl_attribute(pc, 'setConfiguration');
assert_throws_dom('InvalidModificationError', () =>
pc.setConfiguration({ bundlePolicy: 'max-compat' }));
}, `setConfiguration({ bundlePolicy: 'max-compat' }) with initial bundlePolicy max-bundle should throw InvalidModificationError`);
test(() => {
const pc = new RTCPeerConnection({ bundlePolicy: 'max-bundle' });
assert_idl_attribute(pc, 'setConfiguration');
// the default value for bundlePolicy is balanced
assert_throws_dom('InvalidModificationError', () =>
pc.setConfiguration({}));
}, `setConfiguration({}) with initial bundlePolicy max-bundle should throw InvalidModificationError`);
/*
Coverage Report
Tested 2
Total 2
*/
promise_test(async t => {
// balanced: Gather ICE candidates for each media type in use (audio, video, and data).
const pc = new RTCPeerConnection({bundlePolicy: 'balanced'});
t.add_cleanup(() => pc.close());
pc.addTransceiver('audio');
pc.addTransceiver('audio'); // This should not gather candidates.
pc.addTransceiver('video');
pc.createDataChannel('channel');
await pc.setLocalDescription();
await waitForIceGatheringState(pc, ['complete']);
const sections = SDPUtils.splitSections(pc.localDescription.sdp);
sections.shift();
assert_equals(sections.length, 4);
const candidatesA1 = SDPUtils.matchPrefix(sections[0], 'a=candidate:');
assert_greater_than(candidatesA1.length, 0, 'First audio m-line should have candidates');
const candidatesA2 = SDPUtils.matchPrefix(sections[1], 'a=candidate:');
assert_equals(candidatesA2.length, 0, 'Second audio m-line should have no candidates');
const candidatesV = SDPUtils.matchPrefix(sections[2], 'a=candidate:');
assert_greater_than(candidatesV.length, 0, 'First video m-line should have candidates');
const candidatesD = SDPUtils.matchPrefix(sections[3], 'a=candidate:');
assert_greater_than(candidatesD.length, 0, 'First data m-line should have candidates');
}, '"balanced" bundle policy should gather ICE candidates for each media type in use');
promise_test(async t => {
// max-compat: Gather ICE candidates for each track.
const pc = new RTCPeerConnection({bundlePolicy: 'max-compat'});
t.add_cleanup(() => pc.close());
pc.addTransceiver('audio');
pc.addTransceiver('audio'); // This should gather candidates.
pc.addTransceiver('video');
pc.createDataChannel('channel');
await pc.setLocalDescription();
await waitForIceGatheringState(pc, ['complete']);
const sections = SDPUtils.splitSections(pc.localDescription.sdp);
sections.shift();
assert_equals(sections.length, 4);
const candidatesA1 = SDPUtils.matchPrefix(sections[0], 'a=candidate:');
assert_greater_than(candidatesA1.length, 0, 'First audio m-line should have candidates');
const candidatesA2 = SDPUtils.matchPrefix(sections[1], 'a=candidate:');
assert_greater_than(candidatesA2.length, 0, 'Second audio m-line should have candidates');
const candidatesV = SDPUtils.matchPrefix(sections[2], 'a=candidate:');
assert_greater_than(candidatesV.length, 0, 'First video m-lne should have candidates');
const candidatesD = SDPUtils.matchPrefix(sections[3], 'a=candidate:');
assert_greater_than(candidatesD.length, 0, 'First data m-line should have candiates');
}, '"max-compat" bundle policy should gather ICE candidates for each track');
promise_test(async t => {
// max-bundle: Gather ICE candidates for only one track.
const pc = new RTCPeerConnection({bundlePolicy: 'max-bundle'});
t.add_cleanup(() => pc.close());
pc.addTransceiver('audio'); // Only first m-line gathers candidates.
pc.addTransceiver('audio');
pc.addTransceiver('video');
pc.createDataChannel('channel');
await pc.setLocalDescription();
await waitForIceGatheringState(pc, ['complete']);
const sections = SDPUtils.splitSections(pc.localDescription.sdp);
sections.shift();
assert_equals(sections.length, 4);
const candidatesA1 = SDPUtils.matchPrefix(sections[0], 'a=candidate:');
assert_greater_than(candidatesA1.length, 0, 'First audio m-line should have candidates');
const candidatesA2 = SDPUtils.matchPrefix(sections[1], 'a=candidate:');
assert_equals(candidatesA2.length, 0, 'Second audio m-line shoud have no candidates');
const candidatesV = SDPUtils.matchPrefix(sections[2], 'a=candidate:');
assert_equals(candidatesV.length, 0, 'Firt video m-line should have no candidates');
const candidatesD = SDPUtils.matchPrefix(sections[3], 'a=candidate:');
assert_equals(candidatesD.length, 0, 'First data m-line should have no candidates');
}, '"max-bundle" bundle policy should gather ICE candidates for one track');
</script>