| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 /** | 
|  | 2  * Copyright 2017 The Chromium Authors. All rights reserved. | 
|  | 3  * Use of this source code is governed by a BSD-style license that can be | 
|  | 4  * found in the LICENSE file. | 
|  | 5  */ | 
|  | 6 | 
|  | 7 // Public interface to tests. These are expected to be called with | 
|  | 8 // ExecuteJavascript invocations from the browser tests and will return answers | 
|  | 9 // through the DOM automation controller. | 
|  | 10 | 
|  | 11 /** | 
|  | 12  * Adds |count| streams to the peer connection, with one audio and one video | 
|  | 13  * track per stream. | 
|  | 14  * | 
|  | 15  * Returns "ok-streams-created-and-added" on success. | 
|  | 16  */ | 
|  | 17 function createAndAddStreams(count) { | 
|  | 18   if (count > 0) { | 
|  | 19     getUserMedia({ audio: true, video: true }, | 
|  | 20         function(stream) { | 
|  | 21           peerConnection_().addStream(stream); | 
|  | 22           createAndAddStreams(count - 1); | 
|  | 23         }, | 
|  | 24         function(error) { | 
|  | 25           throw failTest('getUserMedia failed: ' + error); | 
|  | 26         }); | 
|  | 27   } else { | 
|  | 28     returnToTest('ok-streams-created-and-added'); | 
|  | 29   } | 
|  | 30 } | 
|  | 31 | 
|  | 32 /** | 
|  | 33  * Verifies that the peer connection's getReceivers() returns one receiver per | 
|  | 34  * remote track, that there are no duplicates and that object identity is | 
|  | 35  * preserved. | 
|  | 36  * | 
|  | 37  * Returns "ok-receivers-verified" on success. | 
|  | 38  */ | 
|  | 39 function verifyRtpReceivers(expectedNumTracks = null) { | 
|  | 40   if (peerConnection_().getReceivers() == null) | 
|  | 41     throw failTest('getReceivers() returns null or undefined.'); | 
|  | 42   if (expectedNumTracks != null && | 
|  | 43       peerConnection_().getReceivers().length != expectedNumTracks) { | 
|  | 44     throw failTest('getReceivers().length != expectedNumTracks'); | 
|  | 45   } | 
|  | 46   if (!arrayEquals_(peerConnection_().getReceivers(), | 
|  | 47                     peerConnection_().getReceivers())) { | 
|  | 48     throw failTest('One getReceivers() call is not equal to the next.'); | 
|  | 49   } | 
|  | 50 | 
|  | 51   let remoteTracks = new Set(); | 
|  | 52   peerConnection_().getRemoteStreams().forEach(function(stream) { | 
|  | 53     stream.getTracks().forEach(function(track) { | 
|  | 54       remoteTracks.add(track); | 
|  | 55     }); | 
|  | 56   }); | 
|  | 57   if (peerConnection_().getReceivers().length != remoteTracks.size) | 
|  | 58     throw failTest('The number of receivers and tracks are not the same.'); | 
|  | 59 | 
|  | 60   let receivers = new Set(); | 
|  | 61   let receiverTracks = new Set(); | 
|  | 62   peerConnection_().getReceivers().forEach(function(receiver) { | 
|  | 63     if (receiver == null) | 
|  | 64       throw failTest('receiver is null or undefined.'); | 
|  | 65     if (receiver.track == null) | 
|  | 66       throw failTest('receiver.track is null or undefined.'); | 
|  | 67     receivers.add(receiver); | 
|  | 68     receiverTracks.add(receiver.track); | 
|  | 69   }); | 
|  | 70   if (receiverTracks.size != receivers.size) | 
|  | 71     throw failTest('receiverTracks.size != receivers.size'); | 
|  | 72 | 
|  | 73   if (!setEquals_(receiverTracks, remoteTracks)) { | 
|  | 74     throw failTest('The set of receiver tracks is not equal to the set of ' + | 
|  | 75                    'stream tracks.'); | 
|  | 76   } | 
|  | 77   returnToTest('ok-receivers-verified'); | 
|  | 78 } | 
|  | 79 | 
|  | 80 // Internals. | 
|  | 81 | 
|  | 82 /** @private */ | 
|  | 83 function arrayEquals_(a, b) { | 
|  | 84   if (a == null) | 
|  | 85     return b == null; | 
|  | 86   if (a.length != b.length) | 
|  | 87     return false; | 
|  | 88   for (let i = 0; i < a.length; ++i) { | 
|  | 89     if (a[i] !== b[i]) | 
|  | 90       return false; | 
|  | 91   } | 
|  | 92   return true; | 
|  | 93 } | 
|  | 94 | 
|  | 95 /** @private */ | 
|  | 96 function setEquals_(a, b) { | 
|  | 97   if (a == null) | 
|  | 98     return b == null; | 
|  | 99   if (a.size != b.size) | 
|  | 100     return false; | 
|  | 101   a.forEach(function(value) { | 
|  | 102     if (!b.has(value)) | 
|  | 103       return false; | 
|  | 104   }); | 
|  | 105   return true; | 
|  | 106 } | 
| OLD | NEW | 
|---|