OLD | NEW |
---|---|
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>RTCPeerConnection.getReceivers</title> | 4 <title>RTCPeerConnection.getReceivers</title> |
5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
7 </head> | 7 </head> |
8 <body> | 8 <body> |
9 <script> | 9 <script> |
10 promise_test(function() { | 10 promise_test(function() { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 // receivers here should only increase the size for the new stream (2 new | 106 // receivers here should only increase the size for the new stream (2 new |
107 // receivers). | 107 // receivers). |
108 for (let i = 0; i < pc.getReceivers().length; ++i) | 108 for (let i = 0; i < pc.getReceivers().length; ++i) |
109 receivers.add(pc.getReceivers()[i]); | 109 receivers.add(pc.getReceivers()[i]); |
110 assert_equals(receivers.size, 6); | 110 assert_equals(receivers.size, 6); |
111 | 111 |
112 removeRemoteStreamsFromLocalStreams(pc, pc.getLocalStreams()); | 112 removeRemoteStreamsFromLocalStreams(pc, pc.getLocalStreams()); |
113 assert_equals(pc.getRemoteStreams().length, 0); | 113 assert_equals(pc.getRemoteStreams().length, 0); |
114 assert_equals(pc.getReceivers().length, 0); | 114 assert_equals(pc.getReceivers().length, 0); |
115 }); | 115 }); |
116 }, 'getReceivers() for streams being added and removed.'); | 116 }, 'pc.getReceivers() for streams being added and removed.'); |
117 | |
118 // |RTCRtpReceiver::getContributingSources| is mocked to update the contributing | |
119 // sources with a predictable pattern, see | |
120 // |MockWebRTCRtpReceiver::getContributingSources|. This test ensures that the | |
121 // sources are correctly cached for subsequent calls in the same event task | |
122 // execution, that they are updated between event task execution calls and that | |
123 // object identities of contributing sources hold. | |
124 promise_test(function() { | |
125 let pc = new RTCPeerConnection(); | |
126 let receiver = null; | |
127 let contributingSource0 = null; | |
128 return createStreams({audio:true}, 1) | |
129 .then(function(streams) { | |
130 return addRemoteStreamsFromLocalStreams(pc, streams); | |
131 }) | |
132 .then(function() { | |
133 verifyStreamAndTrackCounts(pc.getRemoteStreams(), 1, true, false); | |
134 verifyRemoteTracksHaveReceivers(pc); | |
135 | |
136 assert_equals(pc.getReceivers().length, 1); | |
137 receiver = pc.getReceivers()[0]; | |
138 verifyContributingSourcesIsCached(receiver); | |
Taylor_Brandstetter
2017/04/05 19:28:28
nit: "verifyContributingSourcesAreCached"?
hbos_chromium
2017/04/06 08:59:43
Done.
| |
139 | |
140 let contributingSources = receiver.getContributingSources(); | |
141 assert_equals(contributingSources.length, 1); | |
142 assertContributingSourceEquals(contributingSources[0], 0, 0.0); | |
143 | |
144 // Remember the first contributing source for later. | |
145 contributingSource0 = contributingSources[0]; | |
146 // Pass |contributingSources| to the next "then". | |
147 return postTask(contributingSources[0]); | |
148 }).then(function(prevContributingSource) { | |
149 verifyContributingSourcesIsCached(receiver); | |
150 | |
151 let contributingSources = receiver.getContributingSources(); | |
152 assert_equals(contributingSources.length, 2); | |
153 assertContributingSourceEquals(contributingSources[0], 0, 0.0); | |
154 assertContributingSourceEquals(contributingSources[1], 1, 5.0); | |
155 | |
156 // Make sure object identities are preserved between event loop task | |
157 // executions (between asynchronous calls and contributing sources | |
158 // updates). | |
159 assert_equals(contributingSources[0], prevContributingSource); | |
160 | |
161 return postTask(contributingSources[1]); | |
162 }).then(function(prevContributingSource) { | |
163 verifyContributingSourcesIsCached(receiver); | |
164 | |
165 let contributingSources = receiver.getContributingSources(); | |
166 assert_equals(contributingSources.length, 2); | |
167 assert_equals(contributingSources[0], prevContributingSource); | |
168 assertContributingSourceEquals(contributingSources[0], 1, 5.0); | |
169 assertContributingSourceEquals(contributingSources[1], 2, 10.0); | |
170 | |
171 // Make sure object identities are preserved between event loop task | |
172 // executions (between asynchronous calls and contributing sources | |
173 // updates). | |
174 assert_equals(contributingSources[0], prevContributingSource); | |
175 | |
176 return postTask(contributingSources[1]); | |
177 }).then(function(prevContributingSource) { | |
178 verifyContributingSourcesIsCached(receiver); | |
179 | |
180 // It's source 0's turn to be updated. A contributing source should be | |
181 // kept up-to-date in a new event loop task execution without having to | |
182 // explicitly call |getContributingSources|. | |
183 assertContributingSourceEquals(contributingSource0, 0, 15.0); | |
184 | |
185 let contributingSources = receiver.getContributingSources(); | |
186 assert_equals(contributingSources.length, 2); | |
187 assertContributingSourceEquals(contributingSources[0], 2, 10.0); | |
188 assertContributingSourceEquals(contributingSources[1], 0, 15.0); | |
189 assert_equals(contributingSources[0], prevContributingSource); | |
190 assert_equals(contributingSources[1], contributingSource0); | |
191 | |
192 return Promise.resolve(); | |
193 }); | |
194 }, 'receiver.getContributingSources()'); | |
117 | 195 |
118 /** | 196 /** |
119 * Helper functions to tests. | 197 * Helper functions to tests. |
120 */ | 198 */ |
121 | 199 |
200 /** | |
201 * Returns a promise that is immediately resolved asynchronously, meaning "then" | |
202 * is invoked in the next iteration of the event loop. | |
203 */ | |
204 function postTask(valuePassed = undefined) { | |
205 return new Promise(function(resolve, reject) { | |
206 setTimeout(function() { | |
207 resolve(valuePassed); | |
208 }, 0); | |
209 }); | |
210 } | |
211 | |
122 function createStreams(constraints, numStreams, streamsSoFar = []) { | 212 function createStreams(constraints, numStreams, streamsSoFar = []) { |
123 if (numStreams == 0) { | 213 if (numStreams == 0) { |
124 return Promise.resolve(streamsSoFar);; | 214 return Promise.resolve(streamsSoFar);; |
125 } | 215 } |
126 return navigator.mediaDevices.getUserMedia(constraints) | 216 return navigator.mediaDevices.getUserMedia(constraints) |
127 .then(function(stream) { | 217 .then(function(stream) { |
128 return createStreams(constraints, | 218 return createStreams(constraints, |
129 numStreams - 1, | 219 numStreams - 1, |
130 streamsSoFar.concat([stream])); | 220 streamsSoFar.concat([stream])); |
131 }); | 221 }); |
132 } | 222 } |
133 | 223 |
134 /** | 224 /** |
135 * Adds |localStreams| to the peer connection and | 225 * Adds |localStreams| to the peer connection and |
136 * |makeRemoteStreamsMatchLocalStreams|. | 226 * |makeRemoteStreamsMatchLocalStreams|. |
137 * | 227 * |
138 * Returns a promise. | 228 * Returns a promise. |
139 */ | 229 */ |
140 function addRemoteStreamsFromLocalStreams(pc, localStreams) { | 230 function addRemoteStreamsFromLocalStreams(pc, localStreams) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 let receivers = pc.getReceivers(); | 294 let receivers = pc.getReceivers(); |
205 for (let i = 0; i < receivers.length; ++i) { | 295 for (let i = 0; i < receivers.length; ++i) { |
206 assert_true(receivers[i] != null); | 296 assert_true(receivers[i] != null); |
207 assert_true(receivers[i].track != null); | 297 assert_true(receivers[i].track != null); |
208 assert_true(remoteTracks.has(receivers[i].track)); | 298 assert_true(remoteTracks.has(receivers[i].track)); |
209 assert_false(receiverTracks.has(receivers[i].track)); | 299 assert_false(receiverTracks.has(receivers[i].track)); |
210 receiverTracks.add(receivers[i].track); | 300 receiverTracks.add(receivers[i].track); |
211 } | 301 } |
212 assert_equals(receiverTracks.size, remoteTracks.size); | 302 assert_equals(receiverTracks.size, remoteTracks.size); |
213 } | 303 } |
304 | |
305 /** | |
306 * The |MockWebRTCRtpReceiver::getContributingSources| produces a new set of | |
307 * contributing sources every call. The |RTCRtpReceiver| has a cache to make | |
308 * sure its |getContributingSources| does not change during the same event loop | |
309 * task execution. | |
310 */ | |
311 function verifyContributingSourcesIsCached(receiver) { | |
312 // If caching is working as intended, this is always true. It should only be | |
313 // able to change between asynchronous calls, e.g. |postTask|. | |
314 assert_array_equals(receiver.getContributingSources(), | |
315 receiver.getContributingSources()); | |
316 } | |
317 | |
318 function assertContributingSourceEquals(contributingSource, source, timestamp) { | |
319 assert_equals(contributingSource.source, source); | |
320 assert_equals(contributingSource.timestamp, timestamp); | |
321 } | |
214 </script> | 322 </script> |
215 </body> | 323 </body> |
216 </html> | 324 </html> |
OLD | NEW |