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

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

Issue 2803693002: RTCRtpReceiver.getContributingSources() added. (Closed)
Patch Set: Addressed guidou's comments 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". By resolving a promise
147 // we get an asynchronous callback, i.e. the "then" happens in the next
148 // iteration of the event loop. This should invalidate the contributing
149 // sources cache.
150 return Promise.resolve(contributingSource0);
151 }).then(function(prevContributingSource) {
152 verifyContributingSourcesAreCached(receiver);
153
154 let contributingSources = receiver.getContributingSources();
155 assert_equals(contributingSources.length, 2);
156 assertContributingSourceEquals(contributingSources[0], 0, 0.0);
157 assertContributingSourceEquals(contributingSources[1], 1, 5000.0);
158
159 // Make sure object identities are preserved between event loop task
160 // executions (between asynchronous calls and contributing sources
161 // updates).
162 assert_equals(contributingSources[0], prevContributingSource);
163
164 return Promise.resolve(contributingSources[1]);
165 }).then(function(prevContributingSource) {
166 verifyContributingSourcesAreCached(receiver);
167
168 let contributingSources = receiver.getContributingSources();
169 assert_equals(contributingSources.length, 2);
170 assert_equals(contributingSources[0], prevContributingSource);
171 assertContributingSourceEquals(contributingSources[0], 1, 5000.0);
172 assertContributingSourceEquals(contributingSources[1], 2, 10000.0);
173
174 // Make sure object identities are preserved between event loop task
175 // executions (between asynchronous calls and contributing sources
176 // updates).
177 assert_equals(contributingSources[0], prevContributingSource);
178
179 return Promise.resolve(contributingSources[1]);
180 }).then(function(prevContributingSource) {
181 verifyContributingSourcesAreCached(receiver);
182
183 // It's source 0's turn to be updated. A contributing source should be
184 // kept up-to-date in a new event loop task execution without having to
185 // explicitly call |getContributingSources|.
186 assertContributingSourceEquals(contributingSource0, 0, 15000.0);
187
188 let contributingSources = receiver.getContributingSources();
189 assert_equals(contributingSources.length, 2);
190 assertContributingSourceEquals(contributingSources[0], 2, 10000.0);
191 assertContributingSourceEquals(contributingSources[1], 0, 15000.0);
192 assert_equals(contributingSources[0], prevContributingSource);
193 assert_equals(contributingSources[1], contributingSource0);
194
195 return Promise.resolve();
196 });
197 }, 'receiver.getContributingSources()');
117 198
118 /** 199 /**
119 * Helper functions to tests. 200 * Helper functions to tests.
120 */ 201 */
121 202
122 function createStreams(constraints, numStreams, streamsSoFar = []) { 203 function createStreams(constraints, numStreams, streamsSoFar = []) {
123 if (numStreams == 0) { 204 if (numStreams == 0) {
124 return Promise.resolve(streamsSoFar);; 205 return Promise.resolve(streamsSoFar);;
125 } 206 }
126 return navigator.mediaDevices.getUserMedia(constraints) 207 return navigator.mediaDevices.getUserMedia(constraints)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 let receivers = pc.getReceivers(); 285 let receivers = pc.getReceivers();
205 for (let i = 0; i < receivers.length; ++i) { 286 for (let i = 0; i < receivers.length; ++i) {
206 assert_true(receivers[i] != null); 287 assert_true(receivers[i] != null);
207 assert_true(receivers[i].track != null); 288 assert_true(receivers[i].track != null);
208 assert_true(remoteTracks.has(receivers[i].track)); 289 assert_true(remoteTracks.has(receivers[i].track));
209 assert_false(receiverTracks.has(receivers[i].track)); 290 assert_false(receiverTracks.has(receivers[i].track));
210 receiverTracks.add(receivers[i].track); 291 receiverTracks.add(receivers[i].track);
211 } 292 }
212 assert_equals(receiverTracks.size, remoteTracks.size); 293 assert_equals(receiverTracks.size, remoteTracks.size);
213 } 294 }
295
296 /**
297 * The |MockWebRTCRtpReceiver::getContributingSources| produces a new set of
298 * contributing sources every call. The |RTCRtpReceiver| has a cache to make
299 * sure its |getContributingSources| does not change during the same event loop
300 * task execution.
301 */
302 function verifyContributingSourcesAreCached(receiver) {
303 // If caching is working as intended, this is always true. It should only be
304 // able to change between asynchronous calls, e.g. |Promise.resolve().then()|.
305 // Since the mock always produces a new set of sources, this would not be true
306 // if caching was not enabled.
307 assert_array_equals(receiver.getContributingSources(),
308 receiver.getContributingSources());
309 }
310
311 function assertContributingSourceEquals(contributingSource, source, timestamp) {
312 assert_equals(contributingSource.source, source);
313 assert_equals(contributingSource.timestamp, timestamp);
314 }
214 </script> 315 </script>
215 </body> 316 </body>
216 </html> 317 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698