Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/peerconnection/RTCPeerConnection-getReceivers.html

Issue 2803693002: RTCRtpReceiver.getContributingSources() added. (Closed)
Patch Set: Rebase with dependent CL, timestamp in ms, not s Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 verifyContributingSourcesAreCached(receiver);
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 |contributingSource0| to the next "then".
147 return postTask(contributingSource0);
148 }).then(function(prevContributingSource) {
149 verifyContributingSourcesAreCached(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, 5000.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 verifyContributingSourcesAreCached(receiver);
164
165 let contributingSources = receiver.getContributingSources();
166 assert_equals(contributingSources.length, 2);
167 assert_equals(contributingSources[0], prevContributingSource);
168 assertContributingSourceEquals(contributingSources[0], 1, 5000.0);
169 assertContributingSourceEquals(contributingSources[1], 2, 10000.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 verifyContributingSourcesAreCached(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, 15000.0);
184
185 let contributingSources = receiver.getContributingSources();
186 assert_equals(contributingSources.length, 2);
187 assertContributingSourceEquals(contributingSources[0], 2, 10000.0);
188 assertContributingSourceEquals(contributingSources[1], 0, 15000.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.
foolip 2017/04/06 10:07:23 Promise.resolve().then(callback) is invoked at the
hbos_chromium 2017/04/06 11:10:15 Done.
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 });
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 verifyContributingSourcesAreCached(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|. Since the mock
314 // always produces a new set of sources, this would not be true if caching was
315 // not enabled.
316 assert_array_equals(receiver.getContributingSources(),
317 receiver.getContributingSources());
318 }
319
320 function assertContributingSourceEquals(contributingSource, source, timestamp) {
321 assert_equals(contributingSource.source, source);
322 assert_equals(contributingSource.timestamp, timestamp);
323 }
214 </script> 324 </script>
215 </body> 325 </body>
216 </html> 326 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698