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

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

Issue 2803693002: RTCRtpReceiver.getContributingSources() added. (Closed)
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/LayoutTests/fast/peerconnection/RTCPeerConnection-getReceivers.html
diff --git a/third_party/WebKit/LayoutTests/fast/peerconnection/RTCPeerConnection-getReceivers.html b/third_party/WebKit/LayoutTests/fast/peerconnection/RTCPeerConnection-getReceivers.html
index 6bfbd5410d5faa75e9910663dd5d063457099985..4d22e9a9fd2f61f3b5713358ebf5cb0658f8a8f9 100644
--- a/third_party/WebKit/LayoutTests/fast/peerconnection/RTCPeerConnection-getReceivers.html
+++ b/third_party/WebKit/LayoutTests/fast/peerconnection/RTCPeerConnection-getReceivers.html
@@ -113,12 +113,102 @@ promise_test(function() {
assert_equals(pc.getRemoteStreams().length, 0);
assert_equals(pc.getReceivers().length, 0);
});
-}, 'getReceivers() for streams being added and removed.');
+}, 'pc.getReceivers() for streams being added and removed.');
+
+// |RTCRtpReceiver::getContributingSources| is mocked to update the contributing
+// sources with a predictable pattern, see
+// |MockWebRTCRtpReceiver::getContributingSources|. This test ensures that the
+// sources are correctly cached for subsequent calls in the same event task
+// execution, that they are updated between event task execution calls and that
+// object identities of contributing sources hold.
+promise_test(function() {
+ let pc = new RTCPeerConnection();
+ let receiver = null;
+ let contributingSource0 = null;
+ return createStreams({audio:true}, 1)
+ .then(function(streams) {
+ return addRemoteStreamsFromLocalStreams(pc, streams);
+ })
+ .then(function() {
+ verifyStreamAndTrackCounts(pc.getRemoteStreams(), 1, true, false);
+ verifyRemoteTracksHaveReceivers(pc);
+
+ assert_equals(pc.getReceivers().length, 1);
+ receiver = pc.getReceivers()[0];
+ verifyContributingSourcesIsCached(receiver);
Taylor_Brandstetter 2017/04/05 19:28:28 nit: "verifyContributingSourcesAreCached"?
hbos_chromium 2017/04/06 08:59:43 Done.
+
+ let contributingSources = receiver.getContributingSources();
+ assert_equals(contributingSources.length, 1);
+ assertContributingSourceEquals(contributingSources[0], 0, 0.0);
+
+ // Remember the first contributing source for later.
+ contributingSource0 = contributingSources[0];
+ // Pass |contributingSources| to the next "then".
+ return postTask(contributingSources[0]);
+ }).then(function(prevContributingSource) {
+ verifyContributingSourcesIsCached(receiver);
+
+ let contributingSources = receiver.getContributingSources();
+ assert_equals(contributingSources.length, 2);
+ assertContributingSourceEquals(contributingSources[0], 0, 0.0);
+ assertContributingSourceEquals(contributingSources[1], 1, 5.0);
+
+ // Make sure object identities are preserved between event loop task
+ // executions (between asynchronous calls and contributing sources
+ // updates).
+ assert_equals(contributingSources[0], prevContributingSource);
+
+ return postTask(contributingSources[1]);
+ }).then(function(prevContributingSource) {
+ verifyContributingSourcesIsCached(receiver);
+
+ let contributingSources = receiver.getContributingSources();
+ assert_equals(contributingSources.length, 2);
+ assert_equals(contributingSources[0], prevContributingSource);
+ assertContributingSourceEquals(contributingSources[0], 1, 5.0);
+ assertContributingSourceEquals(contributingSources[1], 2, 10.0);
+
+ // Make sure object identities are preserved between event loop task
+ // executions (between asynchronous calls and contributing sources
+ // updates).
+ assert_equals(contributingSources[0], prevContributingSource);
+
+ return postTask(contributingSources[1]);
+ }).then(function(prevContributingSource) {
+ verifyContributingSourcesIsCached(receiver);
+
+ // It's source 0's turn to be updated. A contributing source should be
+ // kept up-to-date in a new event loop task execution without having to
+ // explicitly call |getContributingSources|.
+ assertContributingSourceEquals(contributingSource0, 0, 15.0);
+
+ let contributingSources = receiver.getContributingSources();
+ assert_equals(contributingSources.length, 2);
+ assertContributingSourceEquals(contributingSources[0], 2, 10.0);
+ assertContributingSourceEquals(contributingSources[1], 0, 15.0);
+ assert_equals(contributingSources[0], prevContributingSource);
+ assert_equals(contributingSources[1], contributingSource0);
+
+ return Promise.resolve();
+ });
+}, 'receiver.getContributingSources()');
/**
* Helper functions to tests.
*/
+/**
+ * Returns a promise that is immediately resolved asynchronously, meaning "then"
+ * is invoked in the next iteration of the event loop.
+ */
+function postTask(valuePassed = undefined) {
+ return new Promise(function(resolve, reject) {
+ setTimeout(function() {
+ resolve(valuePassed);
+ }, 0);
+ });
+}
+
function createStreams(constraints, numStreams, streamsSoFar = []) {
if (numStreams == 0) {
return Promise.resolve(streamsSoFar);;
@@ -126,8 +216,8 @@ function createStreams(constraints, numStreams, streamsSoFar = []) {
return navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
return createStreams(constraints,
- numStreams - 1,
- streamsSoFar.concat([stream]));
+ numStreams - 1,
+ streamsSoFar.concat([stream]));
});
}
@@ -211,6 +301,24 @@ function verifyRemoteTracksHaveReceivers(pc) {
}
assert_equals(receiverTracks.size, remoteTracks.size);
}
+
+/**
+ * The |MockWebRTCRtpReceiver::getContributingSources| produces a new set of
+ * contributing sources every call. The |RTCRtpReceiver| has a cache to make
+ * sure its |getContributingSources| does not change during the same event loop
+ * task execution.
+ */
+function verifyContributingSourcesIsCached(receiver) {
+ // If caching is working as intended, this is always true. It should only be
+ // able to change between asynchronous calls, e.g. |postTask|.
+ assert_array_equals(receiver.getContributingSources(),
+ receiver.getContributingSources());
+}
+
+function assertContributingSourceEquals(contributingSource, source, timestamp) {
+ assert_equals(contributingSource.source, source);
+ assert_equals(contributingSource.timestamp, timestamp);
+}
</script>
</body>
</html>

Powered by Google App Engine
This is Rietveld 408576698