| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include <memory> | |
| 12 #include <sstream> | |
| 13 #include <string> | |
| 14 #include <utility> | |
| 15 | |
| 16 #include "webrtc/api/audiotrack.h" | |
| 17 #include "webrtc/api/jsepsessiondescription.h" | |
| 18 #include "webrtc/api/mediastream.h" | |
| 19 #include "webrtc/api/mediastreaminterface.h" | |
| 20 #include "webrtc/api/peerconnection.h" | |
| 21 #include "webrtc/api/peerconnectioninterface.h" | |
| 22 #include "webrtc/api/rtpreceiverinterface.h" | |
| 23 #include "webrtc/api/rtpsenderinterface.h" | |
| 24 #include "webrtc/api/streamcollection.h" | |
| 25 #include "webrtc/api/test/fakeconstraints.h" | |
| 26 #include "webrtc/api/test/fakertccertificategenerator.h" | |
| 27 #include "webrtc/api/test/fakevideotracksource.h" | |
| 28 #include "webrtc/api/test/mockpeerconnectionobservers.h" | |
| 29 #include "webrtc/api/test/testsdpstrings.h" | |
| 30 #include "webrtc/api/videocapturertracksource.h" | |
| 31 #include "webrtc/api/videotrack.h" | |
| 32 #include "webrtc/base/gunit.h" | |
| 33 #include "webrtc/base/ssladapter.h" | |
| 34 #include "webrtc/base/sslstreamadapter.h" | |
| 35 #include "webrtc/base/stringutils.h" | |
| 36 #include "webrtc/base/thread.h" | |
| 37 #include "webrtc/media/base/fakevideocapturer.h" | |
| 38 #include "webrtc/media/sctp/sctptransportinternal.h" | |
| 39 #include "webrtc/p2p/base/fakeportallocator.h" | |
| 40 #include "webrtc/p2p/base/faketransportcontroller.h" | |
| 41 #include "webrtc/pc/mediasession.h" | |
| 42 #include "webrtc/test/gmock.h" | |
| 43 | |
| 44 #ifdef WEBRTC_ANDROID | |
| 45 #include "webrtc/api/test/androidtestinitializer.h" | |
| 46 #endif | |
| 47 | |
| 48 static const char kStreamLabel1[] = "local_stream_1"; | |
| 49 static const char kStreamLabel2[] = "local_stream_2"; | |
| 50 static const char kStreamLabel3[] = "local_stream_3"; | |
| 51 static const int kDefaultStunPort = 3478; | |
| 52 static const char kStunAddressOnly[] = "stun:address"; | |
| 53 static const char kStunInvalidPort[] = "stun:address:-1"; | |
| 54 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; | |
| 55 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; | |
| 56 static const char kTurnIceServerUri[] = "turn:user@turn.example.org"; | |
| 57 static const char kTurnUsername[] = "user"; | |
| 58 static const char kTurnPassword[] = "password"; | |
| 59 static const char kTurnHostname[] = "turn.example.org"; | |
| 60 static const uint32_t kTimeout = 10000U; | |
| 61 | |
| 62 static const char kStreams[][8] = {"stream1", "stream2"}; | |
| 63 static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"}; | |
| 64 static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"}; | |
| 65 | |
| 66 static const char kRecvonly[] = "recvonly"; | |
| 67 static const char kSendrecv[] = "sendrecv"; | |
| 68 | |
| 69 // Reference SDP with a MediaStream with label "stream1" and audio track with | |
| 70 // id "audio_1" and a video track with id "video_1; | |
| 71 static const char kSdpStringWithStream1[] = | |
| 72 "v=0\r\n" | |
| 73 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 74 "s=-\r\n" | |
| 75 "t=0 0\r\n" | |
| 76 "m=audio 1 RTP/AVPF 103\r\n" | |
| 77 "a=ice-ufrag:e5785931\r\n" | |
| 78 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 79 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 80 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 81 "a=mid:audio\r\n" | |
| 82 "a=sendrecv\r\n" | |
| 83 "a=rtcp-mux\r\n" | |
| 84 "a=rtpmap:103 ISAC/16000\r\n" | |
| 85 "a=ssrc:1 cname:stream1\r\n" | |
| 86 "a=ssrc:1 mslabel:stream1\r\n" | |
| 87 "a=ssrc:1 label:audiotrack0\r\n" | |
| 88 "m=video 1 RTP/AVPF 120\r\n" | |
| 89 "a=ice-ufrag:e5785931\r\n" | |
| 90 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 91 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 92 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 93 "a=mid:video\r\n" | |
| 94 "a=sendrecv\r\n" | |
| 95 "a=rtcp-mux\r\n" | |
| 96 "a=rtpmap:120 VP8/90000\r\n" | |
| 97 "a=ssrc:2 cname:stream1\r\n" | |
| 98 "a=ssrc:2 mslabel:stream1\r\n" | |
| 99 "a=ssrc:2 label:videotrack0\r\n"; | |
| 100 | |
| 101 // Reference SDP with a MediaStream with label "stream1" and audio track with | |
| 102 // id "audio_1"; | |
| 103 static const char kSdpStringWithStream1AudioTrackOnly[] = | |
| 104 "v=0\r\n" | |
| 105 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 106 "s=-\r\n" | |
| 107 "t=0 0\r\n" | |
| 108 "m=audio 1 RTP/AVPF 103\r\n" | |
| 109 "a=ice-ufrag:e5785931\r\n" | |
| 110 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 111 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 112 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 113 "a=mid:audio\r\n" | |
| 114 "a=sendrecv\r\n" | |
| 115 "a=rtpmap:103 ISAC/16000\r\n" | |
| 116 "a=ssrc:1 cname:stream1\r\n" | |
| 117 "a=ssrc:1 mslabel:stream1\r\n" | |
| 118 "a=ssrc:1 label:audiotrack0\r\n" | |
| 119 "a=rtcp-mux\r\n"; | |
| 120 | |
| 121 // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each | |
| 122 // MediaStreams have one audio track and one video track. | |
| 123 // This uses MSID. | |
| 124 static const char kSdpStringWithStream1And2[] = | |
| 125 "v=0\r\n" | |
| 126 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 127 "s=-\r\n" | |
| 128 "t=0 0\r\n" | |
| 129 "a=msid-semantic: WMS stream1 stream2\r\n" | |
| 130 "m=audio 1 RTP/AVPF 103\r\n" | |
| 131 "a=ice-ufrag:e5785931\r\n" | |
| 132 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 133 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 134 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 135 "a=mid:audio\r\n" | |
| 136 "a=sendrecv\r\n" | |
| 137 "a=rtcp-mux\r\n" | |
| 138 "a=rtpmap:103 ISAC/16000\r\n" | |
| 139 "a=ssrc:1 cname:stream1\r\n" | |
| 140 "a=ssrc:1 msid:stream1 audiotrack0\r\n" | |
| 141 "a=ssrc:3 cname:stream2\r\n" | |
| 142 "a=ssrc:3 msid:stream2 audiotrack1\r\n" | |
| 143 "m=video 1 RTP/AVPF 120\r\n" | |
| 144 "a=ice-ufrag:e5785931\r\n" | |
| 145 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 146 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 147 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 148 "a=mid:video\r\n" | |
| 149 "a=sendrecv\r\n" | |
| 150 "a=rtcp-mux\r\n" | |
| 151 "a=rtpmap:120 VP8/0\r\n" | |
| 152 "a=ssrc:2 cname:stream1\r\n" | |
| 153 "a=ssrc:2 msid:stream1 videotrack0\r\n" | |
| 154 "a=ssrc:4 cname:stream2\r\n" | |
| 155 "a=ssrc:4 msid:stream2 videotrack1\r\n"; | |
| 156 | |
| 157 // Reference SDP without MediaStreams. Msid is not supported. | |
| 158 static const char kSdpStringWithoutStreams[] = | |
| 159 "v=0\r\n" | |
| 160 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 161 "s=-\r\n" | |
| 162 "t=0 0\r\n" | |
| 163 "m=audio 1 RTP/AVPF 103\r\n" | |
| 164 "a=ice-ufrag:e5785931\r\n" | |
| 165 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 166 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 167 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 168 "a=mid:audio\r\n" | |
| 169 "a=sendrecv\r\n" | |
| 170 "a=rtcp-mux\r\n" | |
| 171 "a=rtpmap:103 ISAC/16000\r\n" | |
| 172 "m=video 1 RTP/AVPF 120\r\n" | |
| 173 "a=ice-ufrag:e5785931\r\n" | |
| 174 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 175 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 176 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 177 "a=mid:video\r\n" | |
| 178 "a=sendrecv\r\n" | |
| 179 "a=rtcp-mux\r\n" | |
| 180 "a=rtpmap:120 VP8/90000\r\n"; | |
| 181 | |
| 182 // Reference SDP without MediaStreams. Msid is supported. | |
| 183 static const char kSdpStringWithMsidWithoutStreams[] = | |
| 184 "v=0\r\n" | |
| 185 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 186 "s=-\r\n" | |
| 187 "t=0 0\r\n" | |
| 188 "a=msid-semantic: WMS\r\n" | |
| 189 "m=audio 1 RTP/AVPF 103\r\n" | |
| 190 "a=ice-ufrag:e5785931\r\n" | |
| 191 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 192 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 193 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 194 "a=mid:audio\r\n" | |
| 195 "a=sendrecv\r\n" | |
| 196 "a=rtcp-mux\r\n" | |
| 197 "a=rtpmap:103 ISAC/16000\r\n" | |
| 198 "m=video 1 RTP/AVPF 120\r\n" | |
| 199 "a=ice-ufrag:e5785931\r\n" | |
| 200 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 201 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 202 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 203 "a=mid:video\r\n" | |
| 204 "a=sendrecv\r\n" | |
| 205 "a=rtcp-mux\r\n" | |
| 206 "a=rtpmap:120 VP8/90000\r\n"; | |
| 207 | |
| 208 // Reference SDP without MediaStreams and audio only. | |
| 209 static const char kSdpStringWithoutStreamsAudioOnly[] = | |
| 210 "v=0\r\n" | |
| 211 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 212 "s=-\r\n" | |
| 213 "t=0 0\r\n" | |
| 214 "m=audio 1 RTP/AVPF 103\r\n" | |
| 215 "a=ice-ufrag:e5785931\r\n" | |
| 216 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 217 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 218 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 219 "a=mid:audio\r\n" | |
| 220 "a=sendrecv\r\n" | |
| 221 "a=rtcp-mux\r\n" | |
| 222 "a=rtpmap:103 ISAC/16000\r\n"; | |
| 223 | |
| 224 // Reference SENDONLY SDP without MediaStreams. Msid is not supported. | |
| 225 static const char kSdpStringSendOnlyWithoutStreams[] = | |
| 226 "v=0\r\n" | |
| 227 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 228 "s=-\r\n" | |
| 229 "t=0 0\r\n" | |
| 230 "m=audio 1 RTP/AVPF 103\r\n" | |
| 231 "a=ice-ufrag:e5785931\r\n" | |
| 232 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 233 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 234 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 235 "a=mid:audio\r\n" | |
| 236 "a=sendrecv\r\n" | |
| 237 "a=sendonly\r\n" | |
| 238 "a=rtcp-mux\r\n" | |
| 239 "a=rtpmap:103 ISAC/16000\r\n" | |
| 240 "m=video 1 RTP/AVPF 120\r\n" | |
| 241 "a=ice-ufrag:e5785931\r\n" | |
| 242 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 243 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 244 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 245 "a=mid:video\r\n" | |
| 246 "a=sendrecv\r\n" | |
| 247 "a=sendonly\r\n" | |
| 248 "a=rtcp-mux\r\n" | |
| 249 "a=rtpmap:120 VP8/90000\r\n"; | |
| 250 | |
| 251 static const char kSdpStringInit[] = | |
| 252 "v=0\r\n" | |
| 253 "o=- 0 0 IN IP4 127.0.0.1\r\n" | |
| 254 "s=-\r\n" | |
| 255 "t=0 0\r\n" | |
| 256 "a=msid-semantic: WMS\r\n"; | |
| 257 | |
| 258 static const char kSdpStringAudio[] = | |
| 259 "m=audio 1 RTP/AVPF 103\r\n" | |
| 260 "a=ice-ufrag:e5785931\r\n" | |
| 261 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 262 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 263 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 264 "a=mid:audio\r\n" | |
| 265 "a=sendrecv\r\n" | |
| 266 "a=rtcp-mux\r\n" | |
| 267 "a=rtpmap:103 ISAC/16000\r\n"; | |
| 268 | |
| 269 static const char kSdpStringVideo[] = | |
| 270 "m=video 1 RTP/AVPF 120\r\n" | |
| 271 "a=ice-ufrag:e5785931\r\n" | |
| 272 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 273 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" | |
| 274 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" | |
| 275 "a=mid:video\r\n" | |
| 276 "a=sendrecv\r\n" | |
| 277 "a=rtcp-mux\r\n" | |
| 278 "a=rtpmap:120 VP8/90000\r\n"; | |
| 279 | |
| 280 static const char kSdpStringMs1Audio0[] = | |
| 281 "a=ssrc:1 cname:stream1\r\n" | |
| 282 "a=ssrc:1 msid:stream1 audiotrack0\r\n"; | |
| 283 | |
| 284 static const char kSdpStringMs1Video0[] = | |
| 285 "a=ssrc:2 cname:stream1\r\n" | |
| 286 "a=ssrc:2 msid:stream1 videotrack0\r\n"; | |
| 287 | |
| 288 static const char kSdpStringMs1Audio1[] = | |
| 289 "a=ssrc:3 cname:stream1\r\n" | |
| 290 "a=ssrc:3 msid:stream1 audiotrack1\r\n"; | |
| 291 | |
| 292 static const char kSdpStringMs1Video1[] = | |
| 293 "a=ssrc:4 cname:stream1\r\n" | |
| 294 "a=ssrc:4 msid:stream1 videotrack1\r\n"; | |
| 295 | |
| 296 static const char kDtlsSdesFallbackSdp[] = | |
| 297 "v=0\r\n" | |
| 298 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n" | |
| 299 "s=-\r\n" | |
| 300 "c=IN IP4 0.0.0.0\r\n" | |
| 301 "t=0 0\r\n" | |
| 302 "a=group:BUNDLE audio\r\n" | |
| 303 "a=msid-semantic: WMS\r\n" | |
| 304 "m=audio 1 RTP/SAVPF 0\r\n" | |
| 305 "a=sendrecv\r\n" | |
| 306 "a=rtcp-mux\r\n" | |
| 307 "a=mid:audio\r\n" | |
| 308 "a=ssrc:1 cname:stream1\r\n" | |
| 309 "a=ssrc:1 mslabel:stream1\r\n" | |
| 310 "a=ssrc:1 label:audiotrack0\r\n" | |
| 311 "a=ice-ufrag:e5785931\r\n" | |
| 312 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" | |
| 313 "a=rtpmap:0 pcmu/8000\r\n" | |
| 314 "a=fingerprint:sha-1 " | |
| 315 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n" | |
| 316 "a=setup:actpass\r\n" | |
| 317 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " | |
| 318 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " | |
| 319 "dummy_session_params\r\n"; | |
| 320 | |
| 321 #define MAYBE_SKIP_TEST(feature) \ | |
| 322 if (!(feature())) { \ | |
| 323 LOG(LS_INFO) << "Feature disabled... skipping"; \ | |
| 324 return; \ | |
| 325 } | |
| 326 | |
| 327 using ::testing::Exactly; | |
| 328 using cricket::StreamParams; | |
| 329 using webrtc::AudioSourceInterface; | |
| 330 using webrtc::AudioTrack; | |
| 331 using webrtc::AudioTrackInterface; | |
| 332 using webrtc::DataBuffer; | |
| 333 using webrtc::DataChannelInterface; | |
| 334 using webrtc::FakeConstraints; | |
| 335 using webrtc::IceCandidateInterface; | |
| 336 using webrtc::JsepSessionDescription; | |
| 337 using webrtc::MediaConstraintsInterface; | |
| 338 using webrtc::MediaStream; | |
| 339 using webrtc::MediaStreamInterface; | |
| 340 using webrtc::MediaStreamTrackInterface; | |
| 341 using webrtc::MockCreateSessionDescriptionObserver; | |
| 342 using webrtc::MockDataChannelObserver; | |
| 343 using webrtc::MockSetSessionDescriptionObserver; | |
| 344 using webrtc::MockStatsObserver; | |
| 345 using webrtc::NotifierInterface; | |
| 346 using webrtc::ObserverInterface; | |
| 347 using webrtc::PeerConnectionInterface; | |
| 348 using webrtc::PeerConnectionObserver; | |
| 349 using webrtc::RTCError; | |
| 350 using webrtc::RTCErrorType; | |
| 351 using webrtc::RtpReceiverInterface; | |
| 352 using webrtc::RtpSenderInterface; | |
| 353 using webrtc::SdpParseError; | |
| 354 using webrtc::SessionDescriptionInterface; | |
| 355 using webrtc::StreamCollection; | |
| 356 using webrtc::StreamCollectionInterface; | |
| 357 using webrtc::VideoTrackSourceInterface; | |
| 358 using webrtc::VideoTrack; | |
| 359 using webrtc::VideoTrackInterface; | |
| 360 | |
| 361 typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; | |
| 362 | |
| 363 namespace { | |
| 364 | |
| 365 // Gets the first ssrc of given content type from the ContentInfo. | |
| 366 bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) { | |
| 367 if (!content_info || !ssrc) { | |
| 368 return false; | |
| 369 } | |
| 370 const cricket::MediaContentDescription* media_desc = | |
| 371 static_cast<const cricket::MediaContentDescription*>( | |
| 372 content_info->description); | |
| 373 if (!media_desc || media_desc->streams().empty()) { | |
| 374 return false; | |
| 375 } | |
| 376 *ssrc = media_desc->streams().begin()->first_ssrc(); | |
| 377 return true; | |
| 378 } | |
| 379 | |
| 380 // Get the ufrags out of an SDP blob. Useful for testing ICE restart | |
| 381 // behavior. | |
| 382 std::vector<std::string> GetUfrags( | |
| 383 const webrtc::SessionDescriptionInterface* desc) { | |
| 384 std::vector<std::string> ufrags; | |
| 385 for (const cricket::TransportInfo& info : | |
| 386 desc->description()->transport_infos()) { | |
| 387 ufrags.push_back(info.description.ice_ufrag); | |
| 388 } | |
| 389 return ufrags; | |
| 390 } | |
| 391 | |
| 392 void SetSsrcToZero(std::string* sdp) { | |
| 393 const char kSdpSsrcAtribute[] = "a=ssrc:"; | |
| 394 const char kSdpSsrcAtributeZero[] = "a=ssrc:0"; | |
| 395 size_t ssrc_pos = 0; | |
| 396 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) != | |
| 397 std::string::npos) { | |
| 398 size_t end_ssrc = sdp->find(" ", ssrc_pos); | |
| 399 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero); | |
| 400 ssrc_pos = end_ssrc; | |
| 401 } | |
| 402 } | |
| 403 | |
| 404 // Check if |streams| contains the specified track. | |
| 405 bool ContainsTrack(const std::vector<cricket::StreamParams>& streams, | |
| 406 const std::string& stream_label, | |
| 407 const std::string& track_id) { | |
| 408 for (const cricket::StreamParams& params : streams) { | |
| 409 if (params.sync_label == stream_label && params.id == track_id) { | |
| 410 return true; | |
| 411 } | |
| 412 } | |
| 413 return false; | |
| 414 } | |
| 415 | |
| 416 // Check if |senders| contains the specified sender, by id. | |
| 417 bool ContainsSender( | |
| 418 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, | |
| 419 const std::string& id) { | |
| 420 for (const auto& sender : senders) { | |
| 421 if (sender->id() == id) { | |
| 422 return true; | |
| 423 } | |
| 424 } | |
| 425 return false; | |
| 426 } | |
| 427 | |
| 428 // Check if |senders| contains the specified sender, by id and stream id. | |
| 429 bool ContainsSender( | |
| 430 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, | |
| 431 const std::string& id, | |
| 432 const std::string& stream_id) { | |
| 433 for (const auto& sender : senders) { | |
| 434 if (sender->id() == id && sender->stream_ids()[0] == stream_id) { | |
| 435 return true; | |
| 436 } | |
| 437 } | |
| 438 return false; | |
| 439 } | |
| 440 | |
| 441 // Create a collection of streams. | |
| 442 // CreateStreamCollection(1) creates a collection that | |
| 443 // correspond to kSdpStringWithStream1. | |
| 444 // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2. | |
| 445 rtc::scoped_refptr<StreamCollection> CreateStreamCollection( | |
| 446 int number_of_streams, | |
| 447 int tracks_per_stream) { | |
| 448 rtc::scoped_refptr<StreamCollection> local_collection( | |
| 449 StreamCollection::Create()); | |
| 450 | |
| 451 for (int i = 0; i < number_of_streams; ++i) { | |
| 452 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( | |
| 453 webrtc::MediaStream::Create(kStreams[i])); | |
| 454 | |
| 455 for (int j = 0; j < tracks_per_stream; ++j) { | |
| 456 // Add a local audio track. | |
| 457 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | |
| 458 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j], | |
| 459 nullptr)); | |
| 460 stream->AddTrack(audio_track); | |
| 461 | |
| 462 // Add a local video track. | |
| 463 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( | |
| 464 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j], | |
| 465 webrtc::FakeVideoTrackSource::Create())); | |
| 466 stream->AddTrack(video_track); | |
| 467 } | |
| 468 | |
| 469 local_collection->AddStream(stream); | |
| 470 } | |
| 471 return local_collection; | |
| 472 } | |
| 473 | |
| 474 // Check equality of StreamCollections. | |
| 475 bool CompareStreamCollections(StreamCollectionInterface* s1, | |
| 476 StreamCollectionInterface* s2) { | |
| 477 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) { | |
| 478 return false; | |
| 479 } | |
| 480 | |
| 481 for (size_t i = 0; i != s1->count(); ++i) { | |
| 482 if (s1->at(i)->label() != s2->at(i)->label()) { | |
| 483 return false; | |
| 484 } | |
| 485 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks(); | |
| 486 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks(); | |
| 487 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks(); | |
| 488 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks(); | |
| 489 | |
| 490 if (audio_tracks1.size() != audio_tracks2.size()) { | |
| 491 return false; | |
| 492 } | |
| 493 for (size_t j = 0; j != audio_tracks1.size(); ++j) { | |
| 494 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) { | |
| 495 return false; | |
| 496 } | |
| 497 } | |
| 498 if (video_tracks1.size() != video_tracks2.size()) { | |
| 499 return false; | |
| 500 } | |
| 501 for (size_t j = 0; j != video_tracks1.size(); ++j) { | |
| 502 if (video_tracks1[j]->id() != video_tracks2[j]->id()) { | |
| 503 return false; | |
| 504 } | |
| 505 } | |
| 506 } | |
| 507 return true; | |
| 508 } | |
| 509 | |
| 510 // Helper class to test Observer. | |
| 511 class MockTrackObserver : public ObserverInterface { | |
| 512 public: | |
| 513 explicit MockTrackObserver(NotifierInterface* notifier) | |
| 514 : notifier_(notifier) { | |
| 515 notifier_->RegisterObserver(this); | |
| 516 } | |
| 517 | |
| 518 ~MockTrackObserver() { Unregister(); } | |
| 519 | |
| 520 void Unregister() { | |
| 521 if (notifier_) { | |
| 522 notifier_->UnregisterObserver(this); | |
| 523 notifier_ = nullptr; | |
| 524 } | |
| 525 } | |
| 526 | |
| 527 MOCK_METHOD0(OnChanged, void()); | |
| 528 | |
| 529 private: | |
| 530 NotifierInterface* notifier_; | |
| 531 }; | |
| 532 | |
| 533 class MockPeerConnectionObserver : public PeerConnectionObserver { | |
| 534 public: | |
| 535 // We need these using declarations because there are two versions of each of | |
| 536 // the below methods and we only override one of them. | |
| 537 // TODO(deadbeef): Remove once there's only one version of the methods. | |
| 538 using PeerConnectionObserver::OnAddStream; | |
| 539 using PeerConnectionObserver::OnRemoveStream; | |
| 540 using PeerConnectionObserver::OnDataChannel; | |
| 541 | |
| 542 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {} | |
| 543 virtual ~MockPeerConnectionObserver() { | |
| 544 } | |
| 545 void SetPeerConnectionInterface(PeerConnectionInterface* pc) { | |
| 546 pc_ = pc; | |
| 547 if (pc) { | |
| 548 state_ = pc_->signaling_state(); | |
| 549 } | |
| 550 } | |
| 551 void OnSignalingChange( | |
| 552 PeerConnectionInterface::SignalingState new_state) override { | |
| 553 EXPECT_EQ(pc_->signaling_state(), new_state); | |
| 554 state_ = new_state; | |
| 555 } | |
| 556 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange. | |
| 557 virtual void OnStateChange(StateType state_changed) { | |
| 558 if (pc_.get() == NULL) | |
| 559 return; | |
| 560 switch (state_changed) { | |
| 561 case kSignalingState: | |
| 562 // OnSignalingChange and OnStateChange(kSignalingState) should always | |
| 563 // be called approximately simultaneously. To ease testing, we require | |
| 564 // that they always be called in that order. This check verifies | |
| 565 // that OnSignalingChange has just been called. | |
| 566 EXPECT_EQ(pc_->signaling_state(), state_); | |
| 567 break; | |
| 568 case kIceState: | |
| 569 ADD_FAILURE(); | |
| 570 break; | |
| 571 default: | |
| 572 ADD_FAILURE(); | |
| 573 break; | |
| 574 } | |
| 575 } | |
| 576 | |
| 577 MediaStreamInterface* RemoteStream(const std::string& label) { | |
| 578 return remote_streams_->find(label); | |
| 579 } | |
| 580 StreamCollectionInterface* remote_streams() const { return remote_streams_; } | |
| 581 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override { | |
| 582 last_added_stream_ = stream; | |
| 583 remote_streams_->AddStream(stream); | |
| 584 } | |
| 585 void OnRemoveStream( | |
| 586 rtc::scoped_refptr<MediaStreamInterface> stream) override { | |
| 587 last_removed_stream_ = stream; | |
| 588 remote_streams_->RemoveStream(stream); | |
| 589 } | |
| 590 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; } | |
| 591 void OnDataChannel( | |
| 592 rtc::scoped_refptr<DataChannelInterface> data_channel) override { | |
| 593 last_datachannel_ = data_channel; | |
| 594 } | |
| 595 | |
| 596 void OnIceConnectionChange( | |
| 597 PeerConnectionInterface::IceConnectionState new_state) override { | |
| 598 EXPECT_EQ(pc_->ice_connection_state(), new_state); | |
| 599 callback_triggered_ = true; | |
| 600 } | |
| 601 void OnIceGatheringChange( | |
| 602 PeerConnectionInterface::IceGatheringState new_state) override { | |
| 603 EXPECT_EQ(pc_->ice_gathering_state(), new_state); | |
| 604 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete; | |
| 605 callback_triggered_ = true; | |
| 606 } | |
| 607 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { | |
| 608 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, | |
| 609 pc_->ice_gathering_state()); | |
| 610 | |
| 611 std::string sdp; | |
| 612 EXPECT_TRUE(candidate->ToString(&sdp)); | |
| 613 EXPECT_LT(0u, sdp.size()); | |
| 614 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(), | |
| 615 candidate->sdp_mline_index(), sdp, NULL)); | |
| 616 EXPECT_TRUE(last_candidate_.get() != NULL); | |
| 617 callback_triggered_ = true; | |
| 618 } | |
| 619 | |
| 620 void OnIceCandidatesRemoved( | |
| 621 const std::vector<cricket::Candidate>& candidates) override { | |
| 622 callback_triggered_ = true; | |
| 623 } | |
| 624 | |
| 625 void OnIceConnectionReceivingChange(bool receiving) override { | |
| 626 callback_triggered_ = true; | |
| 627 } | |
| 628 | |
| 629 void OnAddTrack( | |
| 630 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver, | |
| 631 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& | |
| 632 streams) override { | |
| 633 EXPECT_TRUE(receiver != nullptr); | |
| 634 num_added_tracks_++; | |
| 635 last_added_track_label_ = receiver->id(); | |
| 636 } | |
| 637 | |
| 638 // Returns the label of the last added stream. | |
| 639 // Empty string if no stream have been added. | |
| 640 std::string GetLastAddedStreamLabel() { | |
| 641 if (last_added_stream_.get()) | |
| 642 return last_added_stream_->label(); | |
| 643 return ""; | |
| 644 } | |
| 645 std::string GetLastRemovedStreamLabel() { | |
| 646 if (last_removed_stream_.get()) | |
| 647 return last_removed_stream_->label(); | |
| 648 return ""; | |
| 649 } | |
| 650 | |
| 651 rtc::scoped_refptr<PeerConnectionInterface> pc_; | |
| 652 PeerConnectionInterface::SignalingState state_; | |
| 653 std::unique_ptr<IceCandidateInterface> last_candidate_; | |
| 654 rtc::scoped_refptr<DataChannelInterface> last_datachannel_; | |
| 655 rtc::scoped_refptr<StreamCollection> remote_streams_; | |
| 656 bool renegotiation_needed_ = false; | |
| 657 bool ice_complete_ = false; | |
| 658 bool callback_triggered_ = false; | |
| 659 int num_added_tracks_ = 0; | |
| 660 std::string last_added_track_label_; | |
| 661 | |
| 662 private: | |
| 663 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_; | |
| 664 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_; | |
| 665 }; | |
| 666 | |
| 667 } // namespace | |
| 668 | |
| 669 // The PeerConnectionMediaConfig tests below verify that configuration | |
| 670 // and constraints are propagated into the MediaConfig passed to | |
| 671 // CreateMediaController. These settings are intended for MediaChannel | |
| 672 // constructors, but that is not exercised by these unittest. | |
| 673 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { | |
| 674 public: | |
| 675 webrtc::MediaControllerInterface* CreateMediaController( | |
| 676 const cricket::MediaConfig& config, | |
| 677 webrtc::RtcEventLog* event_log) const override { | |
| 678 create_media_controller_called_ = true; | |
| 679 create_media_controller_config_ = config; | |
| 680 | |
| 681 webrtc::MediaControllerInterface* mc = | |
| 682 PeerConnectionFactory::CreateMediaController(config, event_log); | |
| 683 EXPECT_TRUE(mc != nullptr); | |
| 684 return mc; | |
| 685 } | |
| 686 | |
| 687 cricket::TransportController* CreateTransportController( | |
| 688 cricket::PortAllocator* port_allocator, | |
| 689 bool redetermine_role_on_ice_restart) override { | |
| 690 transport_controller = new cricket::TransportController( | |
| 691 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator, | |
| 692 redetermine_role_on_ice_restart); | |
| 693 return transport_controller; | |
| 694 } | |
| 695 | |
| 696 cricket::TransportController* transport_controller; | |
| 697 // Mutable, so they can be modified in the above const-declared method. | |
| 698 mutable bool create_media_controller_called_ = false; | |
| 699 mutable cricket::MediaConfig create_media_controller_config_; | |
| 700 }; | |
| 701 | |
| 702 class PeerConnectionInterfaceTest : public testing::Test { | |
| 703 protected: | |
| 704 PeerConnectionInterfaceTest() { | |
| 705 #ifdef WEBRTC_ANDROID | |
| 706 webrtc::InitializeAndroidObjects(); | |
| 707 #endif | |
| 708 } | |
| 709 | |
| 710 virtual void SetUp() { | |
| 711 pc_factory_ = webrtc::CreatePeerConnectionFactory( | |
| 712 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), | |
| 713 nullptr, nullptr, nullptr); | |
| 714 ASSERT_TRUE(pc_factory_); | |
| 715 pc_factory_for_test_ = | |
| 716 new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); | |
| 717 pc_factory_for_test_->Initialize(); | |
| 718 } | |
| 719 | |
| 720 void CreatePeerConnection() { | |
| 721 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr); | |
| 722 } | |
| 723 | |
| 724 // DTLS does not work in a loopback call, so is disabled for most of the | |
| 725 // tests in this file. | |
| 726 void CreatePeerConnectionWithoutDtls() { | |
| 727 FakeConstraints no_dtls_constraints; | |
| 728 no_dtls_constraints.AddMandatory( | |
| 729 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); | |
| 730 | |
| 731 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), | |
| 732 &no_dtls_constraints); | |
| 733 } | |
| 734 | |
| 735 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { | |
| 736 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), | |
| 737 constraints); | |
| 738 } | |
| 739 | |
| 740 void CreatePeerConnectionWithIceTransportsType( | |
| 741 PeerConnectionInterface::IceTransportsType type) { | |
| 742 PeerConnectionInterface::RTCConfiguration config; | |
| 743 config.type = type; | |
| 744 return CreatePeerConnection(config, nullptr); | |
| 745 } | |
| 746 | |
| 747 void CreatePeerConnectionWithIceServer(const std::string& uri, | |
| 748 const std::string& password) { | |
| 749 PeerConnectionInterface::RTCConfiguration config; | |
| 750 PeerConnectionInterface::IceServer server; | |
| 751 server.uri = uri; | |
| 752 server.password = password; | |
| 753 config.servers.push_back(server); | |
| 754 CreatePeerConnection(config, nullptr); | |
| 755 } | |
| 756 | |
| 757 void CreatePeerConnection(PeerConnectionInterface::RTCConfiguration config, | |
| 758 webrtc::MediaConstraintsInterface* constraints) { | |
| 759 std::unique_ptr<cricket::FakePortAllocator> port_allocator( | |
| 760 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); | |
| 761 port_allocator_ = port_allocator.get(); | |
| 762 | |
| 763 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator; | |
| 764 bool dtls; | |
| 765 if (FindConstraint(constraints, | |
| 766 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 767 &dtls, | |
| 768 nullptr) && dtls) { | |
| 769 fake_certificate_generator_ = new FakeRTCCertificateGenerator(); | |
| 770 cert_generator.reset(fake_certificate_generator_); | |
| 771 } | |
| 772 pc_ = pc_factory_->CreatePeerConnection( | |
| 773 config, constraints, std::move(port_allocator), | |
| 774 std::move(cert_generator), &observer_); | |
| 775 ASSERT_TRUE(pc_.get() != NULL); | |
| 776 observer_.SetPeerConnectionInterface(pc_.get()); | |
| 777 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | |
| 778 } | |
| 779 | |
| 780 void CreatePeerConnectionExpectFail(const std::string& uri) { | |
| 781 PeerConnectionInterface::RTCConfiguration config; | |
| 782 PeerConnectionInterface::IceServer server; | |
| 783 server.uri = uri; | |
| 784 config.servers.push_back(server); | |
| 785 | |
| 786 rtc::scoped_refptr<PeerConnectionInterface> pc; | |
| 787 pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr, | |
| 788 &observer_); | |
| 789 EXPECT_EQ(nullptr, pc); | |
| 790 } | |
| 791 | |
| 792 void CreatePeerConnectionWithDifferentConfigurations() { | |
| 793 CreatePeerConnectionWithIceServer(kStunAddressOnly, ""); | |
| 794 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); | |
| 795 EXPECT_EQ(0u, port_allocator_->turn_servers().size()); | |
| 796 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); | |
| 797 EXPECT_EQ(kDefaultStunPort, | |
| 798 port_allocator_->stun_servers().begin()->port()); | |
| 799 | |
| 800 CreatePeerConnectionExpectFail(kStunInvalidPort); | |
| 801 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); | |
| 802 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); | |
| 803 | |
| 804 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword); | |
| 805 EXPECT_EQ(0u, port_allocator_->stun_servers().size()); | |
| 806 EXPECT_EQ(1u, port_allocator_->turn_servers().size()); | |
| 807 EXPECT_EQ(kTurnUsername, | |
| 808 port_allocator_->turn_servers()[0].credentials.username); | |
| 809 EXPECT_EQ(kTurnPassword, | |
| 810 port_allocator_->turn_servers()[0].credentials.password); | |
| 811 EXPECT_EQ(kTurnHostname, | |
| 812 port_allocator_->turn_servers()[0].ports[0].address.hostname()); | |
| 813 } | |
| 814 | |
| 815 void ReleasePeerConnection() { | |
| 816 pc_ = NULL; | |
| 817 observer_.SetPeerConnectionInterface(NULL); | |
| 818 } | |
| 819 | |
| 820 void AddVideoStream(const std::string& label) { | |
| 821 // Create a local stream. | |
| 822 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 823 pc_factory_->CreateLocalMediaStream(label)); | |
| 824 rtc::scoped_refptr<VideoTrackSourceInterface> video_source( | |
| 825 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL)); | |
| 826 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 827 pc_factory_->CreateVideoTrack(label + "v0", video_source)); | |
| 828 stream->AddTrack(video_track.get()); | |
| 829 EXPECT_TRUE(pc_->AddStream(stream)); | |
| 830 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); | |
| 831 observer_.renegotiation_needed_ = false; | |
| 832 } | |
| 833 | |
| 834 void AddVoiceStream(const std::string& label) { | |
| 835 // Create a local stream. | |
| 836 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 837 pc_factory_->CreateLocalMediaStream(label)); | |
| 838 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 839 pc_factory_->CreateAudioTrack(label + "a0", NULL)); | |
| 840 stream->AddTrack(audio_track.get()); | |
| 841 EXPECT_TRUE(pc_->AddStream(stream)); | |
| 842 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); | |
| 843 observer_.renegotiation_needed_ = false; | |
| 844 } | |
| 845 | |
| 846 void AddAudioVideoStream(const std::string& stream_label, | |
| 847 const std::string& audio_track_label, | |
| 848 const std::string& video_track_label) { | |
| 849 // Create a local stream. | |
| 850 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 851 pc_factory_->CreateLocalMediaStream(stream_label)); | |
| 852 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 853 pc_factory_->CreateAudioTrack( | |
| 854 audio_track_label, static_cast<AudioSourceInterface*>(NULL))); | |
| 855 stream->AddTrack(audio_track.get()); | |
| 856 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 857 pc_factory_->CreateVideoTrack( | |
| 858 video_track_label, | |
| 859 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); | |
| 860 stream->AddTrack(video_track.get()); | |
| 861 EXPECT_TRUE(pc_->AddStream(stream)); | |
| 862 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); | |
| 863 observer_.renegotiation_needed_ = false; | |
| 864 } | |
| 865 | |
| 866 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, | |
| 867 bool offer, | |
| 868 MediaConstraintsInterface* constraints) { | |
| 869 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> | |
| 870 observer(new rtc::RefCountedObject< | |
| 871 MockCreateSessionDescriptionObserver>()); | |
| 872 if (offer) { | |
| 873 pc_->CreateOffer(observer, constraints); | |
| 874 } else { | |
| 875 pc_->CreateAnswer(observer, constraints); | |
| 876 } | |
| 877 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); | |
| 878 desc->reset(observer->release_desc()); | |
| 879 return observer->result(); | |
| 880 } | |
| 881 | |
| 882 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc, | |
| 883 MediaConstraintsInterface* constraints) { | |
| 884 return DoCreateOfferAnswer(desc, true, constraints); | |
| 885 } | |
| 886 | |
| 887 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, | |
| 888 MediaConstraintsInterface* constraints) { | |
| 889 return DoCreateOfferAnswer(desc, false, constraints); | |
| 890 } | |
| 891 | |
| 892 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) { | |
| 893 rtc::scoped_refptr<MockSetSessionDescriptionObserver> | |
| 894 observer(new rtc::RefCountedObject< | |
| 895 MockSetSessionDescriptionObserver>()); | |
| 896 if (local) { | |
| 897 pc_->SetLocalDescription(observer, desc); | |
| 898 } else { | |
| 899 pc_->SetRemoteDescription(observer, desc); | |
| 900 } | |
| 901 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) { | |
| 902 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); | |
| 903 } | |
| 904 return observer->result(); | |
| 905 } | |
| 906 | |
| 907 bool DoSetLocalDescription(SessionDescriptionInterface* desc) { | |
| 908 return DoSetSessionDescription(desc, true); | |
| 909 } | |
| 910 | |
| 911 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { | |
| 912 return DoSetSessionDescription(desc, false); | |
| 913 } | |
| 914 | |
| 915 // Calls PeerConnection::GetStats and check the return value. | |
| 916 // It does not verify the values in the StatReports since a RTCP packet might | |
| 917 // be required. | |
| 918 bool DoGetStats(MediaStreamTrackInterface* track) { | |
| 919 rtc::scoped_refptr<MockStatsObserver> observer( | |
| 920 new rtc::RefCountedObject<MockStatsObserver>()); | |
| 921 if (!pc_->GetStats( | |
| 922 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)) | |
| 923 return false; | |
| 924 EXPECT_TRUE_WAIT(observer->called(), kTimeout); | |
| 925 return observer->called(); | |
| 926 } | |
| 927 | |
| 928 void InitiateCall() { | |
| 929 CreatePeerConnectionWithoutDtls(); | |
| 930 // Create a local stream with audio&video tracks. | |
| 931 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 932 CreateOfferReceiveAnswer(); | |
| 933 } | |
| 934 | |
| 935 // Verify that RTP Header extensions has been negotiated for audio and video. | |
| 936 void VerifyRemoteRtpHeaderExtensions() { | |
| 937 const cricket::MediaContentDescription* desc = | |
| 938 cricket::GetFirstAudioContentDescription( | |
| 939 pc_->remote_description()->description()); | |
| 940 ASSERT_TRUE(desc != NULL); | |
| 941 EXPECT_GT(desc->rtp_header_extensions().size(), 0u); | |
| 942 | |
| 943 desc = cricket::GetFirstVideoContentDescription( | |
| 944 pc_->remote_description()->description()); | |
| 945 ASSERT_TRUE(desc != NULL); | |
| 946 EXPECT_GT(desc->rtp_header_extensions().size(), 0u); | |
| 947 } | |
| 948 | |
| 949 void CreateOfferAsRemoteDescription() { | |
| 950 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 951 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 952 std::string sdp; | |
| 953 EXPECT_TRUE(offer->ToString(&sdp)); | |
| 954 SessionDescriptionInterface* remote_offer = | |
| 955 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 956 sdp, NULL); | |
| 957 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); | |
| 958 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); | |
| 959 } | |
| 960 | |
| 961 void CreateAndSetRemoteOffer(const std::string& sdp) { | |
| 962 SessionDescriptionInterface* remote_offer = | |
| 963 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 964 sdp, nullptr); | |
| 965 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); | |
| 966 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); | |
| 967 } | |
| 968 | |
| 969 void CreateAnswerAsLocalDescription() { | |
| 970 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 971 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 972 | |
| 973 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an | |
| 974 // audio codec change, even if the parameter has nothing to do with | |
| 975 // receiving. Not all parameters are serialized to SDP. | |
| 976 // Since CreatePrAnswerAsLocalDescription serialize/deserialize | |
| 977 // the SessionDescription, it is necessary to do that here to in order to | |
| 978 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. | |
| 979 // https://code.google.com/p/webrtc/issues/detail?id=1356 | |
| 980 std::string sdp; | |
| 981 EXPECT_TRUE(answer->ToString(&sdp)); | |
| 982 SessionDescriptionInterface* new_answer = | |
| 983 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, | |
| 984 sdp, NULL); | |
| 985 EXPECT_TRUE(DoSetLocalDescription(new_answer)); | |
| 986 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | |
| 987 } | |
| 988 | |
| 989 void CreatePrAnswerAsLocalDescription() { | |
| 990 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 991 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 992 | |
| 993 std::string sdp; | |
| 994 EXPECT_TRUE(answer->ToString(&sdp)); | |
| 995 SessionDescriptionInterface* pr_answer = | |
| 996 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer, | |
| 997 sdp, NULL); | |
| 998 EXPECT_TRUE(DoSetLocalDescription(pr_answer)); | |
| 999 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_); | |
| 1000 } | |
| 1001 | |
| 1002 void CreateOfferReceiveAnswer() { | |
| 1003 CreateOfferAsLocalDescription(); | |
| 1004 std::string sdp; | |
| 1005 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 1006 CreateAnswerAsRemoteDescription(sdp); | |
| 1007 } | |
| 1008 | |
| 1009 void CreateOfferAsLocalDescription() { | |
| 1010 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1011 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1012 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an | |
| 1013 // audio codec change, even if the parameter has nothing to do with | |
| 1014 // receiving. Not all parameters are serialized to SDP. | |
| 1015 // Since CreatePrAnswerAsLocalDescription serialize/deserialize | |
| 1016 // the SessionDescription, it is necessary to do that here to in order to | |
| 1017 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. | |
| 1018 // https://code.google.com/p/webrtc/issues/detail?id=1356 | |
| 1019 std::string sdp; | |
| 1020 EXPECT_TRUE(offer->ToString(&sdp)); | |
| 1021 SessionDescriptionInterface* new_offer = | |
| 1022 webrtc::CreateSessionDescription( | |
| 1023 SessionDescriptionInterface::kOffer, | |
| 1024 sdp, NULL); | |
| 1025 | |
| 1026 EXPECT_TRUE(DoSetLocalDescription(new_offer)); | |
| 1027 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); | |
| 1028 // Wait for the ice_complete message, so that SDP will have candidates. | |
| 1029 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); | |
| 1030 } | |
| 1031 | |
| 1032 void CreateAnswerAsRemoteDescription(const std::string& sdp) { | |
| 1033 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription( | |
| 1034 SessionDescriptionInterface::kAnswer); | |
| 1035 EXPECT_TRUE(answer->Initialize(sdp, NULL)); | |
| 1036 EXPECT_TRUE(DoSetRemoteDescription(answer)); | |
| 1037 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | |
| 1038 } | |
| 1039 | |
| 1040 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) { | |
| 1041 webrtc::JsepSessionDescription* pr_answer = | |
| 1042 new webrtc::JsepSessionDescription( | |
| 1043 SessionDescriptionInterface::kPrAnswer); | |
| 1044 EXPECT_TRUE(pr_answer->Initialize(sdp, NULL)); | |
| 1045 EXPECT_TRUE(DoSetRemoteDescription(pr_answer)); | |
| 1046 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_); | |
| 1047 webrtc::JsepSessionDescription* answer = | |
| 1048 new webrtc::JsepSessionDescription( | |
| 1049 SessionDescriptionInterface::kAnswer); | |
| 1050 EXPECT_TRUE(answer->Initialize(sdp, NULL)); | |
| 1051 EXPECT_TRUE(DoSetRemoteDescription(answer)); | |
| 1052 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); | |
| 1053 } | |
| 1054 | |
| 1055 // Help function used for waiting until a the last signaled remote stream has | |
| 1056 // the same label as |stream_label|. In a few of the tests in this file we | |
| 1057 // answer with the same session description as we offer and thus we can | |
| 1058 // check if OnAddStream have been called with the same stream as we offer to | |
| 1059 // send. | |
| 1060 void WaitAndVerifyOnAddStream(const std::string& stream_label) { | |
| 1061 EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout); | |
| 1062 } | |
| 1063 | |
| 1064 // Creates an offer and applies it as a local session description. | |
| 1065 // Creates an answer with the same SDP an the offer but removes all lines | |
| 1066 // that start with a:ssrc" | |
| 1067 void CreateOfferReceiveAnswerWithoutSsrc() { | |
| 1068 CreateOfferAsLocalDescription(); | |
| 1069 std::string sdp; | |
| 1070 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 1071 SetSsrcToZero(&sdp); | |
| 1072 CreateAnswerAsRemoteDescription(sdp); | |
| 1073 } | |
| 1074 | |
| 1075 // This function creates a MediaStream with label kStreams[0] and | |
| 1076 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the | |
| 1077 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface | |
| 1078 // is returned and the MediaStream is stored in | |
| 1079 // |reference_collection_| | |
| 1080 std::unique_ptr<SessionDescriptionInterface> | |
| 1081 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks, | |
| 1082 size_t number_of_video_tracks) { | |
| 1083 EXPECT_LE(number_of_audio_tracks, 2u); | |
| 1084 EXPECT_LE(number_of_video_tracks, 2u); | |
| 1085 | |
| 1086 reference_collection_ = StreamCollection::Create(); | |
| 1087 std::string sdp_ms1 = std::string(kSdpStringInit); | |
| 1088 | |
| 1089 std::string mediastream_label = kStreams[0]; | |
| 1090 | |
| 1091 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( | |
| 1092 webrtc::MediaStream::Create(mediastream_label)); | |
| 1093 reference_collection_->AddStream(stream); | |
| 1094 | |
| 1095 if (number_of_audio_tracks > 0) { | |
| 1096 sdp_ms1 += std::string(kSdpStringAudio); | |
| 1097 sdp_ms1 += std::string(kSdpStringMs1Audio0); | |
| 1098 AddAudioTrack(kAudioTracks[0], stream); | |
| 1099 } | |
| 1100 if (number_of_audio_tracks > 1) { | |
| 1101 sdp_ms1 += kSdpStringMs1Audio1; | |
| 1102 AddAudioTrack(kAudioTracks[1], stream); | |
| 1103 } | |
| 1104 | |
| 1105 if (number_of_video_tracks > 0) { | |
| 1106 sdp_ms1 += std::string(kSdpStringVideo); | |
| 1107 sdp_ms1 += std::string(kSdpStringMs1Video0); | |
| 1108 AddVideoTrack(kVideoTracks[0], stream); | |
| 1109 } | |
| 1110 if (number_of_video_tracks > 1) { | |
| 1111 sdp_ms1 += kSdpStringMs1Video1; | |
| 1112 AddVideoTrack(kVideoTracks[1], stream); | |
| 1113 } | |
| 1114 | |
| 1115 return std::unique_ptr<SessionDescriptionInterface>( | |
| 1116 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 1117 sdp_ms1, nullptr)); | |
| 1118 } | |
| 1119 | |
| 1120 void AddAudioTrack(const std::string& track_id, | |
| 1121 MediaStreamInterface* stream) { | |
| 1122 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( | |
| 1123 webrtc::AudioTrack::Create(track_id, nullptr)); | |
| 1124 ASSERT_TRUE(stream->AddTrack(audio_track)); | |
| 1125 } | |
| 1126 | |
| 1127 void AddVideoTrack(const std::string& track_id, | |
| 1128 MediaStreamInterface* stream) { | |
| 1129 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( | |
| 1130 webrtc::VideoTrack::Create(track_id, | |
| 1131 webrtc::FakeVideoTrackSource::Create())); | |
| 1132 ASSERT_TRUE(stream->AddTrack(video_track)); | |
| 1133 } | |
| 1134 | |
| 1135 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() { | |
| 1136 CreatePeerConnectionWithoutDtls(); | |
| 1137 AddVoiceStream(kStreamLabel1); | |
| 1138 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1139 EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1140 return offer; | |
| 1141 } | |
| 1142 | |
| 1143 std::unique_ptr<SessionDescriptionInterface> | |
| 1144 CreateAnswerWithOneAudioStream() { | |
| 1145 std::unique_ptr<SessionDescriptionInterface> offer = | |
| 1146 CreateOfferWithOneAudioStream(); | |
| 1147 EXPECT_TRUE(DoSetRemoteDescription(offer.release())); | |
| 1148 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 1149 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 1150 return answer; | |
| 1151 } | |
| 1152 | |
| 1153 const std::string& GetFirstAudioStreamCname( | |
| 1154 const SessionDescriptionInterface* desc) { | |
| 1155 const cricket::ContentInfo* audio_content = | |
| 1156 cricket::GetFirstAudioContent(desc->description()); | |
| 1157 const cricket::AudioContentDescription* audio_desc = | |
| 1158 static_cast<const cricket::AudioContentDescription*>( | |
| 1159 audio_content->description); | |
| 1160 return audio_desc->streams()[0].cname; | |
| 1161 } | |
| 1162 | |
| 1163 cricket::FakePortAllocator* port_allocator_ = nullptr; | |
| 1164 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr; | |
| 1165 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | |
| 1166 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_; | |
| 1167 rtc::scoped_refptr<PeerConnectionInterface> pc_; | |
| 1168 MockPeerConnectionObserver observer_; | |
| 1169 rtc::scoped_refptr<StreamCollection> reference_collection_; | |
| 1170 }; | |
| 1171 | |
| 1172 // Test that no callbacks on the PeerConnectionObserver are called after the | |
| 1173 // PeerConnection is closed. | |
| 1174 TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) { | |
| 1175 rtc::scoped_refptr<PeerConnectionInterface> pc( | |
| 1176 pc_factory_for_test_->CreatePeerConnection( | |
| 1177 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr, | |
| 1178 nullptr, &observer_)); | |
| 1179 observer_.SetPeerConnectionInterface(pc.get()); | |
| 1180 pc->Close(); | |
| 1181 | |
| 1182 // No callbacks is expected to be called. | |
| 1183 observer_.callback_triggered_ = false; | |
| 1184 std::vector<cricket::Candidate> candidates; | |
| 1185 pc_factory_for_test_->transport_controller->SignalGatheringState( | |
| 1186 cricket::IceGatheringState{}); | |
| 1187 pc_factory_for_test_->transport_controller->SignalCandidatesGathered( | |
| 1188 "", candidates); | |
| 1189 pc_factory_for_test_->transport_controller->SignalConnectionState( | |
| 1190 cricket::IceConnectionState{}); | |
| 1191 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved( | |
| 1192 candidates); | |
| 1193 pc_factory_for_test_->transport_controller->SignalReceiving(false); | |
| 1194 EXPECT_FALSE(observer_.callback_triggered_); | |
| 1195 } | |
| 1196 | |
| 1197 // Generate different CNAMEs when PeerConnections are created. | |
| 1198 // The CNAMEs are expected to be generated randomly. It is possible | |
| 1199 // that the test fails, though the possibility is very low. | |
| 1200 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { | |
| 1201 std::unique_ptr<SessionDescriptionInterface> offer1 = | |
| 1202 CreateOfferWithOneAudioStream(); | |
| 1203 std::unique_ptr<SessionDescriptionInterface> offer2 = | |
| 1204 CreateOfferWithOneAudioStream(); | |
| 1205 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), | |
| 1206 GetFirstAudioStreamCname(offer2.get())); | |
| 1207 } | |
| 1208 | |
| 1209 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInAnswer) { | |
| 1210 std::unique_ptr<SessionDescriptionInterface> answer1 = | |
| 1211 CreateAnswerWithOneAudioStream(); | |
| 1212 std::unique_ptr<SessionDescriptionInterface> answer2 = | |
| 1213 CreateAnswerWithOneAudioStream(); | |
| 1214 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()), | |
| 1215 GetFirstAudioStreamCname(answer2.get())); | |
| 1216 } | |
| 1217 | |
| 1218 TEST_F(PeerConnectionInterfaceTest, | |
| 1219 CreatePeerConnectionWithDifferentConfigurations) { | |
| 1220 CreatePeerConnectionWithDifferentConfigurations(); | |
| 1221 } | |
| 1222 | |
| 1223 TEST_F(PeerConnectionInterfaceTest, | |
| 1224 CreatePeerConnectionWithDifferentIceTransportsTypes) { | |
| 1225 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone); | |
| 1226 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter()); | |
| 1227 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay); | |
| 1228 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); | |
| 1229 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost); | |
| 1230 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST, | |
| 1231 port_allocator_->candidate_filter()); | |
| 1232 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll); | |
| 1233 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter()); | |
| 1234 } | |
| 1235 | |
| 1236 // Test that when a PeerConnection is created with a nonzero candidate pool | |
| 1237 // size, the pooled PortAllocatorSession is created with all the attributes | |
| 1238 // in the RTCConfiguration. | |
| 1239 TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { | |
| 1240 PeerConnectionInterface::RTCConfiguration config; | |
| 1241 PeerConnectionInterface::IceServer server; | |
| 1242 server.uri = kStunAddressOnly; | |
| 1243 config.servers.push_back(server); | |
| 1244 config.type = PeerConnectionInterface::kRelay; | |
| 1245 config.disable_ipv6 = true; | |
| 1246 config.tcp_candidate_policy = | |
| 1247 PeerConnectionInterface::kTcpCandidatePolicyDisabled; | |
| 1248 config.candidate_network_policy = | |
| 1249 PeerConnectionInterface::kCandidateNetworkPolicyLowCost; | |
| 1250 config.ice_candidate_pool_size = 1; | |
| 1251 CreatePeerConnection(config, nullptr); | |
| 1252 | |
| 1253 const cricket::FakePortAllocatorSession* session = | |
| 1254 static_cast<const cricket::FakePortAllocatorSession*>( | |
| 1255 port_allocator_->GetPooledSession()); | |
| 1256 ASSERT_NE(nullptr, session); | |
| 1257 EXPECT_EQ(1UL, session->stun_servers().size()); | |
| 1258 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6); | |
| 1259 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP); | |
| 1260 EXPECT_LT(0U, | |
| 1261 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); | |
| 1262 } | |
| 1263 | |
| 1264 // Test that the PeerConnection initializes the port allocator passed into it, | |
| 1265 // and on the correct thread. | |
| 1266 TEST_F(PeerConnectionInterfaceTest, | |
| 1267 CreatePeerConnectionInitializesPortAllocator) { | |
| 1268 rtc::Thread network_thread; | |
| 1269 network_thread.Start(); | |
| 1270 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory( | |
| 1271 webrtc::CreatePeerConnectionFactory( | |
| 1272 &network_thread, rtc::Thread::Current(), rtc::Thread::Current(), | |
| 1273 nullptr, nullptr, nullptr)); | |
| 1274 std::unique_ptr<cricket::FakePortAllocator> port_allocator( | |
| 1275 new cricket::FakePortAllocator(&network_thread, nullptr)); | |
| 1276 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get(); | |
| 1277 PeerConnectionInterface::RTCConfiguration config; | |
| 1278 rtc::scoped_refptr<PeerConnectionInterface> pc( | |
| 1279 pc_factory->CreatePeerConnection( | |
| 1280 config, nullptr, std::move(port_allocator), nullptr, &observer_)); | |
| 1281 // FakePortAllocator RTC_CHECKs that it's initialized on the right thread, | |
| 1282 // so all we have to do here is check that it's initialized. | |
| 1283 EXPECT_TRUE(raw_port_allocator->initialized()); | |
| 1284 } | |
| 1285 | |
| 1286 // Check that GetConfiguration returns the configuration the PeerConnection was | |
| 1287 // constructed with, before SetConfiguration is called. | |
| 1288 TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) { | |
| 1289 PeerConnectionInterface::RTCConfiguration config; | |
| 1290 config.type = PeerConnectionInterface::kRelay; | |
| 1291 CreatePeerConnection(config, nullptr); | |
| 1292 | |
| 1293 PeerConnectionInterface::RTCConfiguration returned_config = | |
| 1294 pc_->GetConfiguration(); | |
| 1295 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); | |
| 1296 } | |
| 1297 | |
| 1298 // Check that GetConfiguration returns the last configuration passed into | |
| 1299 // SetConfiguration. | |
| 1300 TEST_F(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) { | |
| 1301 CreatePeerConnection(); | |
| 1302 | |
| 1303 PeerConnectionInterface::RTCConfiguration config; | |
| 1304 config.type = PeerConnectionInterface::kRelay; | |
| 1305 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 1306 | |
| 1307 PeerConnectionInterface::RTCConfiguration returned_config = | |
| 1308 pc_->GetConfiguration(); | |
| 1309 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type); | |
| 1310 } | |
| 1311 | |
| 1312 TEST_F(PeerConnectionInterfaceTest, AddStreams) { | |
| 1313 CreatePeerConnectionWithoutDtls(); | |
| 1314 AddVideoStream(kStreamLabel1); | |
| 1315 AddVoiceStream(kStreamLabel2); | |
| 1316 ASSERT_EQ(2u, pc_->local_streams()->count()); | |
| 1317 | |
| 1318 // Test we can add multiple local streams to one peerconnection. | |
| 1319 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 1320 pc_factory_->CreateLocalMediaStream(kStreamLabel3)); | |
| 1321 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 1322 pc_factory_->CreateAudioTrack(kStreamLabel3, | |
| 1323 static_cast<AudioSourceInterface*>(NULL))); | |
| 1324 stream->AddTrack(audio_track.get()); | |
| 1325 EXPECT_TRUE(pc_->AddStream(stream)); | |
| 1326 EXPECT_EQ(3u, pc_->local_streams()->count()); | |
| 1327 | |
| 1328 // Remove the third stream. | |
| 1329 pc_->RemoveStream(pc_->local_streams()->at(2)); | |
| 1330 EXPECT_EQ(2u, pc_->local_streams()->count()); | |
| 1331 | |
| 1332 // Remove the second stream. | |
| 1333 pc_->RemoveStream(pc_->local_streams()->at(1)); | |
| 1334 EXPECT_EQ(1u, pc_->local_streams()->count()); | |
| 1335 | |
| 1336 // Remove the first stream. | |
| 1337 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1338 EXPECT_EQ(0u, pc_->local_streams()->count()); | |
| 1339 } | |
| 1340 | |
| 1341 // Test that the created offer includes streams we added. | |
| 1342 TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) { | |
| 1343 CreatePeerConnectionWithoutDtls(); | |
| 1344 AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track"); | |
| 1345 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1346 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1347 | |
| 1348 const cricket::ContentInfo* audio_content = | |
| 1349 cricket::GetFirstAudioContent(offer->description()); | |
| 1350 const cricket::AudioContentDescription* audio_desc = | |
| 1351 static_cast<const cricket::AudioContentDescription*>( | |
| 1352 audio_content->description); | |
| 1353 EXPECT_TRUE( | |
| 1354 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); | |
| 1355 | |
| 1356 const cricket::ContentInfo* video_content = | |
| 1357 cricket::GetFirstVideoContent(offer->description()); | |
| 1358 const cricket::VideoContentDescription* video_desc = | |
| 1359 static_cast<const cricket::VideoContentDescription*>( | |
| 1360 video_content->description); | |
| 1361 EXPECT_TRUE( | |
| 1362 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); | |
| 1363 | |
| 1364 // Add another stream and ensure the offer includes both the old and new | |
| 1365 // streams. | |
| 1366 AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2"); | |
| 1367 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1368 | |
| 1369 audio_content = cricket::GetFirstAudioContent(offer->description()); | |
| 1370 audio_desc = static_cast<const cricket::AudioContentDescription*>( | |
| 1371 audio_content->description); | |
| 1372 EXPECT_TRUE( | |
| 1373 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); | |
| 1374 EXPECT_TRUE( | |
| 1375 ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2")); | |
| 1376 | |
| 1377 video_content = cricket::GetFirstVideoContent(offer->description()); | |
| 1378 video_desc = static_cast<const cricket::VideoContentDescription*>( | |
| 1379 video_content->description); | |
| 1380 EXPECT_TRUE( | |
| 1381 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); | |
| 1382 EXPECT_TRUE( | |
| 1383 ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2")); | |
| 1384 } | |
| 1385 | |
| 1386 TEST_F(PeerConnectionInterfaceTest, RemoveStream) { | |
| 1387 CreatePeerConnectionWithoutDtls(); | |
| 1388 AddVideoStream(kStreamLabel1); | |
| 1389 ASSERT_EQ(1u, pc_->local_streams()->count()); | |
| 1390 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1391 EXPECT_EQ(0u, pc_->local_streams()->count()); | |
| 1392 } | |
| 1393 | |
| 1394 // Test for AddTrack and RemoveTrack methods. | |
| 1395 // Tests that the created offer includes tracks we added, | |
| 1396 // and that the RtpSenders are created correctly. | |
| 1397 // Also tests that RemoveTrack removes the tracks from subsequent offers. | |
| 1398 TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) { | |
| 1399 CreatePeerConnectionWithoutDtls(); | |
| 1400 // Create a dummy stream, so tracks share a stream label. | |
| 1401 rtc::scoped_refptr<MediaStreamInterface> stream( | |
| 1402 pc_factory_->CreateLocalMediaStream(kStreamLabel1)); | |
| 1403 std::vector<MediaStreamInterface*> stream_list; | |
| 1404 stream_list.push_back(stream.get()); | |
| 1405 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 1406 pc_factory_->CreateAudioTrack("audio_track", nullptr)); | |
| 1407 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 1408 pc_factory_->CreateVideoTrack( | |
| 1409 "video_track", | |
| 1410 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); | |
| 1411 auto audio_sender = pc_->AddTrack(audio_track, stream_list); | |
| 1412 auto video_sender = pc_->AddTrack(video_track, stream_list); | |
| 1413 EXPECT_EQ(1UL, audio_sender->stream_ids().size()); | |
| 1414 EXPECT_EQ(kStreamLabel1, audio_sender->stream_ids()[0]); | |
| 1415 EXPECT_EQ("audio_track", audio_sender->id()); | |
| 1416 EXPECT_EQ(audio_track, audio_sender->track()); | |
| 1417 EXPECT_EQ(1UL, video_sender->stream_ids().size()); | |
| 1418 EXPECT_EQ(kStreamLabel1, video_sender->stream_ids()[0]); | |
| 1419 EXPECT_EQ("video_track", video_sender->id()); | |
| 1420 EXPECT_EQ(video_track, video_sender->track()); | |
| 1421 | |
| 1422 // Now create an offer and check for the senders. | |
| 1423 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1424 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1425 | |
| 1426 const cricket::ContentInfo* audio_content = | |
| 1427 cricket::GetFirstAudioContent(offer->description()); | |
| 1428 const cricket::AudioContentDescription* audio_desc = | |
| 1429 static_cast<const cricket::AudioContentDescription*>( | |
| 1430 audio_content->description); | |
| 1431 EXPECT_TRUE( | |
| 1432 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); | |
| 1433 | |
| 1434 const cricket::ContentInfo* video_content = | |
| 1435 cricket::GetFirstVideoContent(offer->description()); | |
| 1436 const cricket::VideoContentDescription* video_desc = | |
| 1437 static_cast<const cricket::VideoContentDescription*>( | |
| 1438 video_content->description); | |
| 1439 EXPECT_TRUE( | |
| 1440 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); | |
| 1441 | |
| 1442 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 1443 | |
| 1444 // Now try removing the tracks. | |
| 1445 EXPECT_TRUE(pc_->RemoveTrack(audio_sender)); | |
| 1446 EXPECT_TRUE(pc_->RemoveTrack(video_sender)); | |
| 1447 | |
| 1448 // Create a new offer and ensure it doesn't contain the removed senders. | |
| 1449 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1450 | |
| 1451 audio_content = cricket::GetFirstAudioContent(offer->description()); | |
| 1452 audio_desc = static_cast<const cricket::AudioContentDescription*>( | |
| 1453 audio_content->description); | |
| 1454 EXPECT_FALSE( | |
| 1455 ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); | |
| 1456 | |
| 1457 video_content = cricket::GetFirstVideoContent(offer->description()); | |
| 1458 video_desc = static_cast<const cricket::VideoContentDescription*>( | |
| 1459 video_content->description); | |
| 1460 EXPECT_FALSE( | |
| 1461 ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); | |
| 1462 | |
| 1463 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 1464 | |
| 1465 // Calling RemoveTrack on a sender no longer attached to a PeerConnection | |
| 1466 // should return false. | |
| 1467 EXPECT_FALSE(pc_->RemoveTrack(audio_sender)); | |
| 1468 EXPECT_FALSE(pc_->RemoveTrack(video_sender)); | |
| 1469 } | |
| 1470 | |
| 1471 // Test creating senders without a stream specified, | |
| 1472 // expecting a random stream ID to be generated. | |
| 1473 TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) { | |
| 1474 CreatePeerConnectionWithoutDtls(); | |
| 1475 // Create a dummy stream, so tracks share a stream label. | |
| 1476 rtc::scoped_refptr<AudioTrackInterface> audio_track( | |
| 1477 pc_factory_->CreateAudioTrack("audio_track", nullptr)); | |
| 1478 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 1479 pc_factory_->CreateVideoTrack( | |
| 1480 "video_track", | |
| 1481 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); | |
| 1482 auto audio_sender = | |
| 1483 pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>()); | |
| 1484 auto video_sender = | |
| 1485 pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>()); | |
| 1486 EXPECT_EQ("audio_track", audio_sender->id()); | |
| 1487 EXPECT_EQ(audio_track, audio_sender->track()); | |
| 1488 EXPECT_EQ("video_track", video_sender->id()); | |
| 1489 EXPECT_EQ(video_track, video_sender->track()); | |
| 1490 // If the ID is truly a random GUID, it should be infinitely unlikely they | |
| 1491 // will be the same. | |
| 1492 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids()); | |
| 1493 } | |
| 1494 | |
| 1495 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) { | |
| 1496 InitiateCall(); | |
| 1497 WaitAndVerifyOnAddStream(kStreamLabel1); | |
| 1498 VerifyRemoteRtpHeaderExtensions(); | |
| 1499 } | |
| 1500 | |
| 1501 TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) { | |
| 1502 CreatePeerConnectionWithoutDtls(); | |
| 1503 AddVideoStream(kStreamLabel1); | |
| 1504 CreateOfferAsLocalDescription(); | |
| 1505 std::string offer; | |
| 1506 EXPECT_TRUE(pc_->local_description()->ToString(&offer)); | |
| 1507 CreatePrAnswerAndAnswerAsRemoteDescription(offer); | |
| 1508 WaitAndVerifyOnAddStream(kStreamLabel1); | |
| 1509 } | |
| 1510 | |
| 1511 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) { | |
| 1512 CreatePeerConnectionWithoutDtls(); | |
| 1513 AddVideoStream(kStreamLabel1); | |
| 1514 | |
| 1515 CreateOfferAsRemoteDescription(); | |
| 1516 CreateAnswerAsLocalDescription(); | |
| 1517 | |
| 1518 WaitAndVerifyOnAddStream(kStreamLabel1); | |
| 1519 } | |
| 1520 | |
| 1521 TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) { | |
| 1522 CreatePeerConnectionWithoutDtls(); | |
| 1523 AddVideoStream(kStreamLabel1); | |
| 1524 | |
| 1525 CreateOfferAsRemoteDescription(); | |
| 1526 CreatePrAnswerAsLocalDescription(); | |
| 1527 CreateAnswerAsLocalDescription(); | |
| 1528 | |
| 1529 WaitAndVerifyOnAddStream(kStreamLabel1); | |
| 1530 } | |
| 1531 | |
| 1532 TEST_F(PeerConnectionInterfaceTest, Renegotiate) { | |
| 1533 InitiateCall(); | |
| 1534 ASSERT_EQ(1u, pc_->remote_streams()->count()); | |
| 1535 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1536 CreateOfferReceiveAnswer(); | |
| 1537 EXPECT_EQ(0u, pc_->remote_streams()->count()); | |
| 1538 AddVideoStream(kStreamLabel1); | |
| 1539 CreateOfferReceiveAnswer(); | |
| 1540 } | |
| 1541 | |
| 1542 // Tests that after negotiating an audio only call, the respondent can perform a | |
| 1543 // renegotiation that removes the audio stream. | |
| 1544 TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) { | |
| 1545 CreatePeerConnectionWithoutDtls(); | |
| 1546 AddVoiceStream(kStreamLabel1); | |
| 1547 CreateOfferAsRemoteDescription(); | |
| 1548 CreateAnswerAsLocalDescription(); | |
| 1549 | |
| 1550 ASSERT_EQ(1u, pc_->remote_streams()->count()); | |
| 1551 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1552 CreateOfferReceiveAnswer(); | |
| 1553 EXPECT_EQ(0u, pc_->remote_streams()->count()); | |
| 1554 } | |
| 1555 | |
| 1556 // Test that candidates are generated and that we can parse our own candidates. | |
| 1557 TEST_F(PeerConnectionInterfaceTest, IceCandidates) { | |
| 1558 CreatePeerConnectionWithoutDtls(); | |
| 1559 | |
| 1560 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get())); | |
| 1561 // SetRemoteDescription takes ownership of offer. | |
| 1562 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1563 AddVideoStream(kStreamLabel1); | |
| 1564 EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1565 EXPECT_TRUE(DoSetRemoteDescription(offer.release())); | |
| 1566 | |
| 1567 // SetLocalDescription takes ownership of answer. | |
| 1568 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 1569 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 1570 EXPECT_TRUE(DoSetLocalDescription(answer.release())); | |
| 1571 | |
| 1572 EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout); | |
| 1573 EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); | |
| 1574 | |
| 1575 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get())); | |
| 1576 } | |
| 1577 | |
| 1578 // Test that CreateOffer and CreateAnswer will fail if the track labels are | |
| 1579 // not unique. | |
| 1580 TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) { | |
| 1581 CreatePeerConnectionWithoutDtls(); | |
| 1582 // Create a regular offer for the CreateAnswer test later. | |
| 1583 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1584 EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1585 EXPECT_TRUE(offer); | |
| 1586 offer.reset(); | |
| 1587 | |
| 1588 // Create a local stream with audio&video tracks having same label. | |
| 1589 AddAudioVideoStream(kStreamLabel1, "track_label", "track_label"); | |
| 1590 | |
| 1591 // Test CreateOffer | |
| 1592 EXPECT_FALSE(DoCreateOffer(&offer, nullptr)); | |
| 1593 | |
| 1594 // Test CreateAnswer | |
| 1595 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 1596 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr)); | |
| 1597 } | |
| 1598 | |
| 1599 // Test that we will get different SSRCs for each tracks in the offer and answer | |
| 1600 // we created. | |
| 1601 TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) { | |
| 1602 CreatePeerConnectionWithoutDtls(); | |
| 1603 // Create a local stream with audio&video tracks having different labels. | |
| 1604 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 1605 | |
| 1606 // Test CreateOffer | |
| 1607 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1608 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1609 int audio_ssrc = 0; | |
| 1610 int video_ssrc = 0; | |
| 1611 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()), | |
| 1612 &audio_ssrc)); | |
| 1613 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()), | |
| 1614 &video_ssrc)); | |
| 1615 EXPECT_NE(audio_ssrc, video_ssrc); | |
| 1616 | |
| 1617 // Test CreateAnswer | |
| 1618 EXPECT_TRUE(DoSetRemoteDescription(offer.release())); | |
| 1619 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 1620 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 1621 audio_ssrc = 0; | |
| 1622 video_ssrc = 0; | |
| 1623 EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()), | |
| 1624 &audio_ssrc)); | |
| 1625 EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()), | |
| 1626 &video_ssrc)); | |
| 1627 EXPECT_NE(audio_ssrc, video_ssrc); | |
| 1628 } | |
| 1629 | |
| 1630 // Test that it's possible to call AddTrack on a MediaStream after adding | |
| 1631 // the stream to a PeerConnection. | |
| 1632 // TODO(deadbeef): Remove this test once this behavior is no longer supported. | |
| 1633 TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) { | |
| 1634 CreatePeerConnectionWithoutDtls(); | |
| 1635 // Create audio stream and add to PeerConnection. | |
| 1636 AddVoiceStream(kStreamLabel1); | |
| 1637 MediaStreamInterface* stream = pc_->local_streams()->at(0); | |
| 1638 | |
| 1639 // Add video track to the audio-only stream. | |
| 1640 rtc::scoped_refptr<VideoTrackInterface> video_track( | |
| 1641 pc_factory_->CreateVideoTrack( | |
| 1642 "video_label", | |
| 1643 pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer()))); | |
| 1644 stream->AddTrack(video_track.get()); | |
| 1645 | |
| 1646 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1647 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1648 | |
| 1649 const cricket::MediaContentDescription* video_desc = | |
| 1650 cricket::GetFirstVideoContentDescription(offer->description()); | |
| 1651 EXPECT_TRUE(video_desc != nullptr); | |
| 1652 } | |
| 1653 | |
| 1654 // Test that it's possible to call RemoveTrack on a MediaStream after adding | |
| 1655 // the stream to a PeerConnection. | |
| 1656 // TODO(deadbeef): Remove this test once this behavior is no longer supported. | |
| 1657 TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) { | |
| 1658 CreatePeerConnectionWithoutDtls(); | |
| 1659 // Create audio/video stream and add to PeerConnection. | |
| 1660 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 1661 MediaStreamInterface* stream = pc_->local_streams()->at(0); | |
| 1662 | |
| 1663 // Remove the video track. | |
| 1664 stream->RemoveTrack(stream->GetVideoTracks()[0]); | |
| 1665 | |
| 1666 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1667 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1668 | |
| 1669 const cricket::MediaContentDescription* video_desc = | |
| 1670 cricket::GetFirstVideoContentDescription(offer->description()); | |
| 1671 EXPECT_TRUE(video_desc == nullptr); | |
| 1672 } | |
| 1673 | |
| 1674 // Test creating a sender with a stream ID, and ensure the ID is populated | |
| 1675 // in the offer. | |
| 1676 TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) { | |
| 1677 CreatePeerConnectionWithoutDtls(); | |
| 1678 pc_->CreateSender("video", kStreamLabel1); | |
| 1679 | |
| 1680 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 1681 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 1682 | |
| 1683 const cricket::MediaContentDescription* video_desc = | |
| 1684 cricket::GetFirstVideoContentDescription(offer->description()); | |
| 1685 ASSERT_TRUE(video_desc != nullptr); | |
| 1686 ASSERT_EQ(1u, video_desc->streams().size()); | |
| 1687 EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label); | |
| 1688 } | |
| 1689 | |
| 1690 // Test that we can specify a certain track that we want statistics about. | |
| 1691 TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) { | |
| 1692 InitiateCall(); | |
| 1693 ASSERT_LT(0u, pc_->remote_streams()->count()); | |
| 1694 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size()); | |
| 1695 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio = | |
| 1696 pc_->remote_streams()->at(0)->GetAudioTracks()[0]; | |
| 1697 EXPECT_TRUE(DoGetStats(remote_audio)); | |
| 1698 | |
| 1699 // Remove the stream. Since we are sending to our selves the local | |
| 1700 // and the remote stream is the same. | |
| 1701 pc_->RemoveStream(pc_->local_streams()->at(0)); | |
| 1702 // Do a re-negotiation. | |
| 1703 CreateOfferReceiveAnswer(); | |
| 1704 | |
| 1705 ASSERT_EQ(0u, pc_->remote_streams()->count()); | |
| 1706 | |
| 1707 // Test that we still can get statistics for the old track. Even if it is not | |
| 1708 // sent any longer. | |
| 1709 EXPECT_TRUE(DoGetStats(remote_audio)); | |
| 1710 } | |
| 1711 | |
| 1712 // Test that we can get stats on a video track. | |
| 1713 TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) { | |
| 1714 InitiateCall(); | |
| 1715 ASSERT_LT(0u, pc_->remote_streams()->count()); | |
| 1716 ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size()); | |
| 1717 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video = | |
| 1718 pc_->remote_streams()->at(0)->GetVideoTracks()[0]; | |
| 1719 EXPECT_TRUE(DoGetStats(remote_video)); | |
| 1720 } | |
| 1721 | |
| 1722 // Test that we don't get statistics for an invalid track. | |
| 1723 TEST_F(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) { | |
| 1724 InitiateCall(); | |
| 1725 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track( | |
| 1726 pc_factory_->CreateAudioTrack("unknown track", NULL)); | |
| 1727 EXPECT_FALSE(DoGetStats(unknown_audio_track)); | |
| 1728 } | |
| 1729 | |
| 1730 // This test setup two RTP data channels in loop back. | |
| 1731 TEST_F(PeerConnectionInterfaceTest, TestDataChannel) { | |
| 1732 FakeConstraints constraints; | |
| 1733 constraints.SetAllowRtpDataChannels(); | |
| 1734 CreatePeerConnection(&constraints); | |
| 1735 rtc::scoped_refptr<DataChannelInterface> data1 = | |
| 1736 pc_->CreateDataChannel("test1", NULL); | |
| 1737 rtc::scoped_refptr<DataChannelInterface> data2 = | |
| 1738 pc_->CreateDataChannel("test2", NULL); | |
| 1739 ASSERT_TRUE(data1 != NULL); | |
| 1740 std::unique_ptr<MockDataChannelObserver> observer1( | |
| 1741 new MockDataChannelObserver(data1)); | |
| 1742 std::unique_ptr<MockDataChannelObserver> observer2( | |
| 1743 new MockDataChannelObserver(data2)); | |
| 1744 | |
| 1745 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); | |
| 1746 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); | |
| 1747 std::string data_to_send1 = "testing testing"; | |
| 1748 std::string data_to_send2 = "testing something else"; | |
| 1749 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1))); | |
| 1750 | |
| 1751 CreateOfferReceiveAnswer(); | |
| 1752 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); | |
| 1753 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); | |
| 1754 | |
| 1755 EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); | |
| 1756 EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); | |
| 1757 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1))); | |
| 1758 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); | |
| 1759 | |
| 1760 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout); | |
| 1761 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); | |
| 1762 | |
| 1763 data1->Close(); | |
| 1764 EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); | |
| 1765 CreateOfferReceiveAnswer(); | |
| 1766 EXPECT_FALSE(observer1->IsOpen()); | |
| 1767 EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); | |
| 1768 EXPECT_TRUE(observer2->IsOpen()); | |
| 1769 | |
| 1770 data_to_send2 = "testing something else again"; | |
| 1771 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); | |
| 1772 | |
| 1773 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); | |
| 1774 } | |
| 1775 | |
| 1776 // This test verifies that sendnig binary data over RTP data channels should | |
| 1777 // fail. | |
| 1778 TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) { | |
| 1779 FakeConstraints constraints; | |
| 1780 constraints.SetAllowRtpDataChannels(); | |
| 1781 CreatePeerConnection(&constraints); | |
| 1782 rtc::scoped_refptr<DataChannelInterface> data1 = | |
| 1783 pc_->CreateDataChannel("test1", NULL); | |
| 1784 rtc::scoped_refptr<DataChannelInterface> data2 = | |
| 1785 pc_->CreateDataChannel("test2", NULL); | |
| 1786 ASSERT_TRUE(data1 != NULL); | |
| 1787 std::unique_ptr<MockDataChannelObserver> observer1( | |
| 1788 new MockDataChannelObserver(data1)); | |
| 1789 std::unique_ptr<MockDataChannelObserver> observer2( | |
| 1790 new MockDataChannelObserver(data2)); | |
| 1791 | |
| 1792 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); | |
| 1793 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); | |
| 1794 | |
| 1795 CreateOfferReceiveAnswer(); | |
| 1796 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); | |
| 1797 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); | |
| 1798 | |
| 1799 EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); | |
| 1800 EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); | |
| 1801 | |
| 1802 rtc::CopyOnWriteBuffer buffer("test", 4); | |
| 1803 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true))); | |
| 1804 } | |
| 1805 | |
| 1806 // This test setup a RTP data channels in loop back and test that a channel is | |
| 1807 // opened even if the remote end answer with a zero SSRC. | |
| 1808 TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) { | |
| 1809 FakeConstraints constraints; | |
| 1810 constraints.SetAllowRtpDataChannels(); | |
| 1811 CreatePeerConnection(&constraints); | |
| 1812 rtc::scoped_refptr<DataChannelInterface> data1 = | |
| 1813 pc_->CreateDataChannel("test1", NULL); | |
| 1814 std::unique_ptr<MockDataChannelObserver> observer1( | |
| 1815 new MockDataChannelObserver(data1)); | |
| 1816 | |
| 1817 CreateOfferReceiveAnswerWithoutSsrc(); | |
| 1818 | |
| 1819 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); | |
| 1820 | |
| 1821 data1->Close(); | |
| 1822 EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); | |
| 1823 CreateOfferReceiveAnswerWithoutSsrc(); | |
| 1824 EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); | |
| 1825 EXPECT_FALSE(observer1->IsOpen()); | |
| 1826 } | |
| 1827 | |
| 1828 // This test that if a data channel is added in an answer a receive only channel | |
| 1829 // channel is created. | |
| 1830 TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) { | |
| 1831 FakeConstraints constraints; | |
| 1832 constraints.SetAllowRtpDataChannels(); | |
| 1833 CreatePeerConnection(&constraints); | |
| 1834 | |
| 1835 std::string offer_label = "offer_channel"; | |
| 1836 rtc::scoped_refptr<DataChannelInterface> offer_channel = | |
| 1837 pc_->CreateDataChannel(offer_label, NULL); | |
| 1838 | |
| 1839 CreateOfferAsLocalDescription(); | |
| 1840 | |
| 1841 // Replace the data channel label in the offer and apply it as an answer. | |
| 1842 std::string receive_label = "answer_channel"; | |
| 1843 std::string sdp; | |
| 1844 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 1845 rtc::replace_substrs(offer_label.c_str(), offer_label.length(), | |
| 1846 receive_label.c_str(), receive_label.length(), | |
| 1847 &sdp); | |
| 1848 CreateAnswerAsRemoteDescription(sdp); | |
| 1849 | |
| 1850 // Verify that a new incoming data channel has been created and that | |
| 1851 // it is open but can't we written to. | |
| 1852 ASSERT_TRUE(observer_.last_datachannel_ != NULL); | |
| 1853 DataChannelInterface* received_channel = observer_.last_datachannel_; | |
| 1854 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state()); | |
| 1855 EXPECT_EQ(receive_label, received_channel->label()); | |
| 1856 EXPECT_FALSE(received_channel->Send(DataBuffer("something"))); | |
| 1857 | |
| 1858 // Verify that the channel we initially offered has been rejected. | |
| 1859 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); | |
| 1860 | |
| 1861 // Do another offer / answer exchange and verify that the data channel is | |
| 1862 // opened. | |
| 1863 CreateOfferReceiveAnswer(); | |
| 1864 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(), | |
| 1865 kTimeout); | |
| 1866 } | |
| 1867 | |
| 1868 // This test that no data channel is returned if a reliable channel is | |
| 1869 // requested. | |
| 1870 // TODO(perkj): Remove this test once reliable channels are implemented. | |
| 1871 TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) { | |
| 1872 FakeConstraints constraints; | |
| 1873 constraints.SetAllowRtpDataChannels(); | |
| 1874 CreatePeerConnection(&constraints); | |
| 1875 | |
| 1876 std::string label = "test"; | |
| 1877 webrtc::DataChannelInit config; | |
| 1878 config.reliable = true; | |
| 1879 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1880 pc_->CreateDataChannel(label, &config); | |
| 1881 EXPECT_TRUE(channel == NULL); | |
| 1882 } | |
| 1883 | |
| 1884 // Verifies that duplicated label is not allowed for RTP data channel. | |
| 1885 TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) { | |
| 1886 FakeConstraints constraints; | |
| 1887 constraints.SetAllowRtpDataChannels(); | |
| 1888 CreatePeerConnection(&constraints); | |
| 1889 | |
| 1890 std::string label = "test"; | |
| 1891 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1892 pc_->CreateDataChannel(label, nullptr); | |
| 1893 EXPECT_NE(channel, nullptr); | |
| 1894 | |
| 1895 rtc::scoped_refptr<DataChannelInterface> dup_channel = | |
| 1896 pc_->CreateDataChannel(label, nullptr); | |
| 1897 EXPECT_EQ(dup_channel, nullptr); | |
| 1898 } | |
| 1899 | |
| 1900 // This tests that a SCTP data channel is returned using different | |
| 1901 // DataChannelInit configurations. | |
| 1902 TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) { | |
| 1903 FakeConstraints constraints; | |
| 1904 constraints.SetAllowDtlsSctpDataChannels(); | |
| 1905 CreatePeerConnection(&constraints); | |
| 1906 | |
| 1907 webrtc::DataChannelInit config; | |
| 1908 | |
| 1909 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1910 pc_->CreateDataChannel("1", &config); | |
| 1911 EXPECT_TRUE(channel != NULL); | |
| 1912 EXPECT_TRUE(channel->reliable()); | |
| 1913 EXPECT_TRUE(observer_.renegotiation_needed_); | |
| 1914 observer_.renegotiation_needed_ = false; | |
| 1915 | |
| 1916 config.ordered = false; | |
| 1917 channel = pc_->CreateDataChannel("2", &config); | |
| 1918 EXPECT_TRUE(channel != NULL); | |
| 1919 EXPECT_TRUE(channel->reliable()); | |
| 1920 EXPECT_FALSE(observer_.renegotiation_needed_); | |
| 1921 | |
| 1922 config.ordered = true; | |
| 1923 config.maxRetransmits = 0; | |
| 1924 channel = pc_->CreateDataChannel("3", &config); | |
| 1925 EXPECT_TRUE(channel != NULL); | |
| 1926 EXPECT_FALSE(channel->reliable()); | |
| 1927 EXPECT_FALSE(observer_.renegotiation_needed_); | |
| 1928 | |
| 1929 config.maxRetransmits = -1; | |
| 1930 config.maxRetransmitTime = 0; | |
| 1931 channel = pc_->CreateDataChannel("4", &config); | |
| 1932 EXPECT_TRUE(channel != NULL); | |
| 1933 EXPECT_FALSE(channel->reliable()); | |
| 1934 EXPECT_FALSE(observer_.renegotiation_needed_); | |
| 1935 } | |
| 1936 | |
| 1937 // This tests that no data channel is returned if both maxRetransmits and | |
| 1938 // maxRetransmitTime are set for SCTP data channels. | |
| 1939 TEST_F(PeerConnectionInterfaceTest, | |
| 1940 CreateSctpDataChannelShouldFailForInvalidConfig) { | |
| 1941 FakeConstraints constraints; | |
| 1942 constraints.SetAllowDtlsSctpDataChannels(); | |
| 1943 CreatePeerConnection(&constraints); | |
| 1944 | |
| 1945 std::string label = "test"; | |
| 1946 webrtc::DataChannelInit config; | |
| 1947 config.maxRetransmits = 0; | |
| 1948 config.maxRetransmitTime = 0; | |
| 1949 | |
| 1950 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1951 pc_->CreateDataChannel(label, &config); | |
| 1952 EXPECT_TRUE(channel == NULL); | |
| 1953 } | |
| 1954 | |
| 1955 // The test verifies that creating a SCTP data channel with an id already in use | |
| 1956 // or out of range should fail. | |
| 1957 TEST_F(PeerConnectionInterfaceTest, | |
| 1958 CreateSctpDataChannelWithInvalidIdShouldFail) { | |
| 1959 FakeConstraints constraints; | |
| 1960 constraints.SetAllowDtlsSctpDataChannels(); | |
| 1961 CreatePeerConnection(&constraints); | |
| 1962 | |
| 1963 webrtc::DataChannelInit config; | |
| 1964 rtc::scoped_refptr<DataChannelInterface> channel; | |
| 1965 | |
| 1966 config.id = 1; | |
| 1967 channel = pc_->CreateDataChannel("1", &config); | |
| 1968 EXPECT_TRUE(channel != NULL); | |
| 1969 EXPECT_EQ(1, channel->id()); | |
| 1970 | |
| 1971 channel = pc_->CreateDataChannel("x", &config); | |
| 1972 EXPECT_TRUE(channel == NULL); | |
| 1973 | |
| 1974 config.id = cricket::kMaxSctpSid; | |
| 1975 channel = pc_->CreateDataChannel("max", &config); | |
| 1976 EXPECT_TRUE(channel != NULL); | |
| 1977 EXPECT_EQ(config.id, channel->id()); | |
| 1978 | |
| 1979 config.id = cricket::kMaxSctpSid + 1; | |
| 1980 channel = pc_->CreateDataChannel("x", &config); | |
| 1981 EXPECT_TRUE(channel == NULL); | |
| 1982 } | |
| 1983 | |
| 1984 // Verifies that duplicated label is allowed for SCTP data channel. | |
| 1985 TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) { | |
| 1986 FakeConstraints constraints; | |
| 1987 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 1988 true); | |
| 1989 CreatePeerConnection(&constraints); | |
| 1990 | |
| 1991 std::string label = "test"; | |
| 1992 rtc::scoped_refptr<DataChannelInterface> channel = | |
| 1993 pc_->CreateDataChannel(label, nullptr); | |
| 1994 EXPECT_NE(channel, nullptr); | |
| 1995 | |
| 1996 rtc::scoped_refptr<DataChannelInterface> dup_channel = | |
| 1997 pc_->CreateDataChannel(label, nullptr); | |
| 1998 EXPECT_NE(dup_channel, nullptr); | |
| 1999 } | |
| 2000 | |
| 2001 // This test verifies that OnRenegotiationNeeded is fired for every new RTP | |
| 2002 // DataChannel. | |
| 2003 TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) { | |
| 2004 FakeConstraints constraints; | |
| 2005 constraints.SetAllowRtpDataChannels(); | |
| 2006 CreatePeerConnection(&constraints); | |
| 2007 | |
| 2008 rtc::scoped_refptr<DataChannelInterface> dc1 = | |
| 2009 pc_->CreateDataChannel("test1", NULL); | |
| 2010 EXPECT_TRUE(observer_.renegotiation_needed_); | |
| 2011 observer_.renegotiation_needed_ = false; | |
| 2012 | |
| 2013 rtc::scoped_refptr<DataChannelInterface> dc2 = | |
| 2014 pc_->CreateDataChannel("test2", NULL); | |
| 2015 EXPECT_TRUE(observer_.renegotiation_needed_); | |
| 2016 } | |
| 2017 | |
| 2018 // This test that a data channel closes when a PeerConnection is deleted/closed. | |
| 2019 TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) { | |
| 2020 FakeConstraints constraints; | |
| 2021 constraints.SetAllowRtpDataChannels(); | |
| 2022 CreatePeerConnection(&constraints); | |
| 2023 | |
| 2024 rtc::scoped_refptr<DataChannelInterface> data1 = | |
| 2025 pc_->CreateDataChannel("test1", NULL); | |
| 2026 rtc::scoped_refptr<DataChannelInterface> data2 = | |
| 2027 pc_->CreateDataChannel("test2", NULL); | |
| 2028 ASSERT_TRUE(data1 != NULL); | |
| 2029 std::unique_ptr<MockDataChannelObserver> observer1( | |
| 2030 new MockDataChannelObserver(data1)); | |
| 2031 std::unique_ptr<MockDataChannelObserver> observer2( | |
| 2032 new MockDataChannelObserver(data2)); | |
| 2033 | |
| 2034 CreateOfferReceiveAnswer(); | |
| 2035 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); | |
| 2036 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); | |
| 2037 | |
| 2038 ReleasePeerConnection(); | |
| 2039 EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); | |
| 2040 EXPECT_EQ(DataChannelInterface::kClosed, data2->state()); | |
| 2041 } | |
| 2042 | |
| 2043 // This test that data channels can be rejected in an answer. | |
| 2044 TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) { | |
| 2045 FakeConstraints constraints; | |
| 2046 constraints.SetAllowRtpDataChannels(); | |
| 2047 CreatePeerConnection(&constraints); | |
| 2048 | |
| 2049 rtc::scoped_refptr<DataChannelInterface> offer_channel( | |
| 2050 pc_->CreateDataChannel("offer_channel", NULL)); | |
| 2051 | |
| 2052 CreateOfferAsLocalDescription(); | |
| 2053 | |
| 2054 // Create an answer where the m-line for data channels are rejected. | |
| 2055 std::string sdp; | |
| 2056 EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 2057 webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription( | |
| 2058 SessionDescriptionInterface::kAnswer); | |
| 2059 EXPECT_TRUE(answer->Initialize(sdp, NULL)); | |
| 2060 cricket::ContentInfo* data_info = | |
| 2061 answer->description()->GetContentByName("data"); | |
| 2062 data_info->rejected = true; | |
| 2063 | |
| 2064 DoSetRemoteDescription(answer); | |
| 2065 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); | |
| 2066 } | |
| 2067 | |
| 2068 // Test that we can create a session description from an SDP string from | |
| 2069 // FireFox, use it as a remote session description, generate an answer and use | |
| 2070 // the answer as a local description. | |
| 2071 TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) { | |
| 2072 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
| 2073 FakeConstraints constraints; | |
| 2074 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2075 true); | |
| 2076 CreatePeerConnection(&constraints); | |
| 2077 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 2078 SessionDescriptionInterface* desc = | |
| 2079 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 2080 webrtc::kFireFoxSdpOffer, nullptr); | |
| 2081 EXPECT_TRUE(DoSetSessionDescription(desc, false)); | |
| 2082 CreateAnswerAsLocalDescription(); | |
| 2083 ASSERT_TRUE(pc_->local_description() != NULL); | |
| 2084 ASSERT_TRUE(pc_->remote_description() != NULL); | |
| 2085 | |
| 2086 const cricket::ContentInfo* content = | |
| 2087 cricket::GetFirstAudioContent(pc_->local_description()->description()); | |
| 2088 ASSERT_TRUE(content != NULL); | |
| 2089 EXPECT_FALSE(content->rejected); | |
| 2090 | |
| 2091 content = | |
| 2092 cricket::GetFirstVideoContent(pc_->local_description()->description()); | |
| 2093 ASSERT_TRUE(content != NULL); | |
| 2094 EXPECT_FALSE(content->rejected); | |
| 2095 #ifdef HAVE_SCTP | |
| 2096 content = | |
| 2097 cricket::GetFirstDataContent(pc_->local_description()->description()); | |
| 2098 ASSERT_TRUE(content != NULL); | |
| 2099 EXPECT_TRUE(content->rejected); | |
| 2100 #endif | |
| 2101 } | |
| 2102 | |
| 2103 // Test that an offer can be received which offers DTLS with SDES fallback. | |
| 2104 // Regression test for issue: | |
| 2105 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6972 | |
| 2106 TEST_F(PeerConnectionInterfaceTest, ReceiveDtlsSdesFallbackOffer) { | |
| 2107 FakeConstraints constraints; | |
| 2108 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2109 true); | |
| 2110 CreatePeerConnection(&constraints); | |
| 2111 // Wait for fake certificate to be generated. Previously, this is what caused | |
| 2112 // the "a=crypto" lines to be rejected. | |
| 2113 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 2114 ASSERT_NE(nullptr, fake_certificate_generator_); | |
| 2115 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(), | |
| 2116 kTimeout); | |
| 2117 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription( | |
| 2118 SessionDescriptionInterface::kOffer, kDtlsSdesFallbackSdp, nullptr); | |
| 2119 EXPECT_TRUE(DoSetSessionDescription(desc, false)); | |
| 2120 CreateAnswerAsLocalDescription(); | |
| 2121 } | |
| 2122 | |
| 2123 // Test that we can create an audio only offer and receive an answer with a | |
| 2124 // limited set of audio codecs and receive an updated offer with more audio | |
| 2125 // codecs, where the added codecs are not supported. | |
| 2126 TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) { | |
| 2127 CreatePeerConnectionWithoutDtls(); | |
| 2128 AddVoiceStream("audio_label"); | |
| 2129 CreateOfferAsLocalDescription(); | |
| 2130 | |
| 2131 SessionDescriptionInterface* answer = | |
| 2132 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, | |
| 2133 webrtc::kAudioSdp, nullptr); | |
| 2134 EXPECT_TRUE(DoSetSessionDescription(answer, false)); | |
| 2135 | |
| 2136 SessionDescriptionInterface* updated_offer = | |
| 2137 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 2138 webrtc::kAudioSdpWithUnsupportedCodecs, | |
| 2139 nullptr); | |
| 2140 EXPECT_TRUE(DoSetSessionDescription(updated_offer, false)); | |
| 2141 CreateAnswerAsLocalDescription(); | |
| 2142 } | |
| 2143 | |
| 2144 // Test that if we're receiving (but not sending) a track, subsequent offers | |
| 2145 // will have m-lines with a=recvonly. | |
| 2146 TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) { | |
| 2147 FakeConstraints constraints; | |
| 2148 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2149 true); | |
| 2150 CreatePeerConnection(&constraints); | |
| 2151 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2152 CreateAnswerAsLocalDescription(); | |
| 2153 | |
| 2154 // At this point we should be receiving stream 1, but not sending anything. | |
| 2155 // A new offer should be recvonly. | |
| 2156 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2157 DoCreateOffer(&offer, nullptr); | |
| 2158 | |
| 2159 const cricket::ContentInfo* video_content = | |
| 2160 cricket::GetFirstVideoContent(offer->description()); | |
| 2161 const cricket::VideoContentDescription* video_desc = | |
| 2162 static_cast<const cricket::VideoContentDescription*>( | |
| 2163 video_content->description); | |
| 2164 ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction()); | |
| 2165 | |
| 2166 const cricket::ContentInfo* audio_content = | |
| 2167 cricket::GetFirstAudioContent(offer->description()); | |
| 2168 const cricket::AudioContentDescription* audio_desc = | |
| 2169 static_cast<const cricket::AudioContentDescription*>( | |
| 2170 audio_content->description); | |
| 2171 ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction()); | |
| 2172 } | |
| 2173 | |
| 2174 // Test that if we're receiving (but not sending) a track, and the | |
| 2175 // offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to | |
| 2176 // false, the generated m-lines will be a=inactive. | |
| 2177 TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) { | |
| 2178 FakeConstraints constraints; | |
| 2179 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2180 true); | |
| 2181 CreatePeerConnection(&constraints); | |
| 2182 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2183 CreateAnswerAsLocalDescription(); | |
| 2184 | |
| 2185 // At this point we should be receiving stream 1, but not sending anything. | |
| 2186 // A new offer would be recvonly, but we'll set the "no receive" constraints | |
| 2187 // to make it inactive. | |
| 2188 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2189 FakeConstraints offer_constraints; | |
| 2190 offer_constraints.AddMandatory( | |
| 2191 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false); | |
| 2192 offer_constraints.AddMandatory( | |
| 2193 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false); | |
| 2194 DoCreateOffer(&offer, &offer_constraints); | |
| 2195 | |
| 2196 const cricket::ContentInfo* video_content = | |
| 2197 cricket::GetFirstVideoContent(offer->description()); | |
| 2198 const cricket::VideoContentDescription* video_desc = | |
| 2199 static_cast<const cricket::VideoContentDescription*>( | |
| 2200 video_content->description); | |
| 2201 ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction()); | |
| 2202 | |
| 2203 const cricket::ContentInfo* audio_content = | |
| 2204 cricket::GetFirstAudioContent(offer->description()); | |
| 2205 const cricket::AudioContentDescription* audio_desc = | |
| 2206 static_cast<const cricket::AudioContentDescription*>( | |
| 2207 audio_content->description); | |
| 2208 ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction()); | |
| 2209 } | |
| 2210 | |
| 2211 // Test that we can use SetConfiguration to change the ICE servers of the | |
| 2212 // PortAllocator. | |
| 2213 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) { | |
| 2214 CreatePeerConnection(); | |
| 2215 | |
| 2216 PeerConnectionInterface::RTCConfiguration config; | |
| 2217 PeerConnectionInterface::IceServer server; | |
| 2218 server.uri = "stun:test_hostname"; | |
| 2219 config.servers.push_back(server); | |
| 2220 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2221 | |
| 2222 EXPECT_EQ(1u, port_allocator_->stun_servers().size()); | |
| 2223 EXPECT_EQ("test_hostname", | |
| 2224 port_allocator_->stun_servers().begin()->hostname()); | |
| 2225 } | |
| 2226 | |
| 2227 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) { | |
| 2228 CreatePeerConnection(); | |
| 2229 PeerConnectionInterface::RTCConfiguration config; | |
| 2230 config.type = PeerConnectionInterface::kRelay; | |
| 2231 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2232 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); | |
| 2233 } | |
| 2234 | |
| 2235 TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) { | |
| 2236 PeerConnectionInterface::RTCConfiguration config; | |
| 2237 config.prune_turn_ports = false; | |
| 2238 CreatePeerConnection(config, nullptr); | |
| 2239 EXPECT_FALSE(port_allocator_->prune_turn_ports()); | |
| 2240 | |
| 2241 config.prune_turn_ports = true; | |
| 2242 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2243 EXPECT_TRUE(port_allocator_->prune_turn_ports()); | |
| 2244 } | |
| 2245 | |
| 2246 // Test that when SetConfiguration changes both the pool size and other | |
| 2247 // attributes, the pooled session is created with the updated attributes. | |
| 2248 TEST_F(PeerConnectionInterfaceTest, | |
| 2249 SetConfigurationCreatesPooledSessionCorrectly) { | |
| 2250 CreatePeerConnection(); | |
| 2251 PeerConnectionInterface::RTCConfiguration config; | |
| 2252 config.ice_candidate_pool_size = 1; | |
| 2253 PeerConnectionInterface::IceServer server; | |
| 2254 server.uri = kStunAddressOnly; | |
| 2255 config.servers.push_back(server); | |
| 2256 config.type = PeerConnectionInterface::kRelay; | |
| 2257 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2258 | |
| 2259 const cricket::FakePortAllocatorSession* session = | |
| 2260 static_cast<const cricket::FakePortAllocatorSession*>( | |
| 2261 port_allocator_->GetPooledSession()); | |
| 2262 ASSERT_NE(nullptr, session); | |
| 2263 EXPECT_EQ(1UL, session->stun_servers().size()); | |
| 2264 } | |
| 2265 | |
| 2266 // Test that after SetLocalDescription, changing the pool size is not allowed, | |
| 2267 // and an invalid modification error is returned. | |
| 2268 TEST_F(PeerConnectionInterfaceTest, | |
| 2269 CantChangePoolSizeAfterSetLocalDescription) { | |
| 2270 CreatePeerConnection(); | |
| 2271 // Start by setting a size of 1. | |
| 2272 PeerConnectionInterface::RTCConfiguration config; | |
| 2273 config.ice_candidate_pool_size = 1; | |
| 2274 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2275 | |
| 2276 // Set remote offer; can still change pool size at this point. | |
| 2277 CreateOfferAsRemoteDescription(); | |
| 2278 config.ice_candidate_pool_size = 2; | |
| 2279 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2280 | |
| 2281 // Set local answer; now it's too late. | |
| 2282 CreateAnswerAsLocalDescription(); | |
| 2283 config.ice_candidate_pool_size = 3; | |
| 2284 RTCError error; | |
| 2285 EXPECT_FALSE(pc_->SetConfiguration(config, &error)); | |
| 2286 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); | |
| 2287 } | |
| 2288 | |
| 2289 // Test that SetConfiguration returns an invalid modification error if | |
| 2290 // modifying a field in the configuration that isn't allowed to be modified. | |
| 2291 TEST_F(PeerConnectionInterfaceTest, | |
| 2292 SetConfigurationReturnsInvalidModificationError) { | |
| 2293 PeerConnectionInterface::RTCConfiguration config; | |
| 2294 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced; | |
| 2295 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate; | |
| 2296 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE; | |
| 2297 CreatePeerConnection(config, nullptr); | |
| 2298 | |
| 2299 PeerConnectionInterface::RTCConfiguration modified_config = config; | |
| 2300 modified_config.bundle_policy = | |
| 2301 PeerConnectionInterface::kBundlePolicyMaxBundle; | |
| 2302 RTCError error; | |
| 2303 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error)); | |
| 2304 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); | |
| 2305 | |
| 2306 modified_config = config; | |
| 2307 modified_config.rtcp_mux_policy = | |
| 2308 PeerConnectionInterface::kRtcpMuxPolicyRequire; | |
| 2309 error.set_type(RTCErrorType::NONE); | |
| 2310 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error)); | |
| 2311 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); | |
| 2312 | |
| 2313 modified_config = config; | |
| 2314 modified_config.continual_gathering_policy = | |
| 2315 PeerConnectionInterface::GATHER_CONTINUALLY; | |
| 2316 error.set_type(RTCErrorType::NONE); | |
| 2317 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error)); | |
| 2318 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); | |
| 2319 } | |
| 2320 | |
| 2321 // Test that SetConfiguration returns a range error if the candidate pool size | |
| 2322 // is negative or larger than allowed by the spec. | |
| 2323 TEST_F(PeerConnectionInterfaceTest, | |
| 2324 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) { | |
| 2325 PeerConnectionInterface::RTCConfiguration config; | |
| 2326 CreatePeerConnection(config, nullptr); | |
| 2327 | |
| 2328 config.ice_candidate_pool_size = -1; | |
| 2329 RTCError error; | |
| 2330 EXPECT_FALSE(pc_->SetConfiguration(config, &error)); | |
| 2331 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type()); | |
| 2332 | |
| 2333 config.ice_candidate_pool_size = INT_MAX; | |
| 2334 error.set_type(RTCErrorType::NONE); | |
| 2335 EXPECT_FALSE(pc_->SetConfiguration(config, &error)); | |
| 2336 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type()); | |
| 2337 } | |
| 2338 | |
| 2339 // Test that SetConfiguration returns a syntax error if parsing an ICE server | |
| 2340 // URL failed. | |
| 2341 TEST_F(PeerConnectionInterfaceTest, | |
| 2342 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) { | |
| 2343 PeerConnectionInterface::RTCConfiguration config; | |
| 2344 CreatePeerConnection(config, nullptr); | |
| 2345 | |
| 2346 PeerConnectionInterface::IceServer bad_server; | |
| 2347 bad_server.uri = "stunn:www.example.com"; | |
| 2348 config.servers.push_back(bad_server); | |
| 2349 RTCError error; | |
| 2350 EXPECT_FALSE(pc_->SetConfiguration(config, &error)); | |
| 2351 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type()); | |
| 2352 } | |
| 2353 | |
| 2354 // Test that SetConfiguration returns an invalid parameter error if a TURN | |
| 2355 // IceServer is missing a username or password. | |
| 2356 TEST_F(PeerConnectionInterfaceTest, | |
| 2357 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) { | |
| 2358 PeerConnectionInterface::RTCConfiguration config; | |
| 2359 CreatePeerConnection(config, nullptr); | |
| 2360 | |
| 2361 PeerConnectionInterface::IceServer bad_server; | |
| 2362 bad_server.uri = "turn:www.example.com"; | |
| 2363 // Missing password. | |
| 2364 bad_server.username = "foo"; | |
| 2365 config.servers.push_back(bad_server); | |
| 2366 RTCError error; | |
| 2367 EXPECT_FALSE(pc_->SetConfiguration(config, &error)); | |
| 2368 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type()); | |
| 2369 } | |
| 2370 | |
| 2371 // Test that PeerConnection::Close changes the states to closed and all remote | |
| 2372 // tracks change state to ended. | |
| 2373 TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { | |
| 2374 // Initialize a PeerConnection and negotiate local and remote session | |
| 2375 // description. | |
| 2376 InitiateCall(); | |
| 2377 ASSERT_EQ(1u, pc_->local_streams()->count()); | |
| 2378 ASSERT_EQ(1u, pc_->remote_streams()->count()); | |
| 2379 | |
| 2380 pc_->Close(); | |
| 2381 | |
| 2382 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state()); | |
| 2383 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed, | |
| 2384 pc_->ice_connection_state()); | |
| 2385 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete, | |
| 2386 pc_->ice_gathering_state()); | |
| 2387 | |
| 2388 EXPECT_EQ(1u, pc_->local_streams()->count()); | |
| 2389 EXPECT_EQ(1u, pc_->remote_streams()->count()); | |
| 2390 | |
| 2391 rtc::scoped_refptr<MediaStreamInterface> remote_stream = | |
| 2392 pc_->remote_streams()->at(0); | |
| 2393 // Track state may be updated asynchronously. | |
| 2394 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, | |
| 2395 remote_stream->GetAudioTracks()[0]->state(), kTimeout); | |
| 2396 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, | |
| 2397 remote_stream->GetVideoTracks()[0]->state(), kTimeout); | |
| 2398 } | |
| 2399 | |
| 2400 // Test that PeerConnection methods fails gracefully after | |
| 2401 // PeerConnection::Close has been called. | |
| 2402 TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) { | |
| 2403 CreatePeerConnectionWithoutDtls(); | |
| 2404 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 2405 CreateOfferAsRemoteDescription(); | |
| 2406 CreateAnswerAsLocalDescription(); | |
| 2407 | |
| 2408 ASSERT_EQ(1u, pc_->local_streams()->count()); | |
| 2409 rtc::scoped_refptr<MediaStreamInterface> local_stream = | |
| 2410 pc_->local_streams()->at(0); | |
| 2411 | |
| 2412 pc_->Close(); | |
| 2413 | |
| 2414 pc_->RemoveStream(local_stream); | |
| 2415 EXPECT_FALSE(pc_->AddStream(local_stream)); | |
| 2416 | |
| 2417 ASSERT_FALSE(local_stream->GetAudioTracks().empty()); | |
| 2418 rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender( | |
| 2419 pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0])); | |
| 2420 EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed. | |
| 2421 | |
| 2422 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL); | |
| 2423 | |
| 2424 EXPECT_TRUE(pc_->local_description() != NULL); | |
| 2425 EXPECT_TRUE(pc_->remote_description() != NULL); | |
| 2426 | |
| 2427 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2428 EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2429 std::unique_ptr<SessionDescriptionInterface> answer; | |
| 2430 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); | |
| 2431 | |
| 2432 std::string sdp; | |
| 2433 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp)); | |
| 2434 SessionDescriptionInterface* remote_offer = | |
| 2435 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 2436 sdp, NULL); | |
| 2437 EXPECT_FALSE(DoSetRemoteDescription(remote_offer)); | |
| 2438 | |
| 2439 ASSERT_TRUE(pc_->local_description()->ToString(&sdp)); | |
| 2440 SessionDescriptionInterface* local_offer = | |
| 2441 webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, | |
| 2442 sdp, NULL); | |
| 2443 EXPECT_FALSE(DoSetLocalDescription(local_offer)); | |
| 2444 } | |
| 2445 | |
| 2446 // Test that GetStats can still be called after PeerConnection::Close. | |
| 2447 TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) { | |
| 2448 InitiateCall(); | |
| 2449 pc_->Close(); | |
| 2450 DoGetStats(NULL); | |
| 2451 } | |
| 2452 | |
| 2453 // NOTE: The series of tests below come from what used to be | |
| 2454 // mediastreamsignaling_unittest.cc, and are mostly aimed at testing that | |
| 2455 // setting a remote or local description has the expected effects. | |
| 2456 | |
| 2457 // This test verifies that the remote MediaStreams corresponding to a received | |
| 2458 // SDP string is created. In this test the two separate MediaStreams are | |
| 2459 // signaled. | |
| 2460 TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) { | |
| 2461 FakeConstraints constraints; | |
| 2462 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2463 true); | |
| 2464 CreatePeerConnection(&constraints); | |
| 2465 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2466 | |
| 2467 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); | |
| 2468 EXPECT_TRUE( | |
| 2469 CompareStreamCollections(observer_.remote_streams(), reference.get())); | |
| 2470 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2471 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr); | |
| 2472 | |
| 2473 // Create a session description based on another SDP with another | |
| 2474 // MediaStream. | |
| 2475 CreateAndSetRemoteOffer(kSdpStringWithStream1And2); | |
| 2476 | |
| 2477 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1)); | |
| 2478 EXPECT_TRUE( | |
| 2479 CompareStreamCollections(observer_.remote_streams(), reference2.get())); | |
| 2480 } | |
| 2481 | |
| 2482 // This test verifies that when remote tracks are added/removed from SDP, the | |
| 2483 // created remote streams are updated appropriately. | |
| 2484 TEST_F(PeerConnectionInterfaceTest, | |
| 2485 AddRemoveTrackFromExistingRemoteMediaStream) { | |
| 2486 FakeConstraints constraints; | |
| 2487 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2488 true); | |
| 2489 CreatePeerConnection(&constraints); | |
| 2490 std::unique_ptr<SessionDescriptionInterface> desc_ms1 = | |
| 2491 CreateSessionDescriptionAndReference(1, 1); | |
| 2492 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release())); | |
| 2493 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), | |
| 2494 reference_collection_)); | |
| 2495 | |
| 2496 // Add extra audio and video tracks to the same MediaStream. | |
| 2497 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks = | |
| 2498 CreateSessionDescriptionAndReference(2, 2); | |
| 2499 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release())); | |
| 2500 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), | |
| 2501 reference_collection_)); | |
| 2502 rtc::scoped_refptr<AudioTrackInterface> audio_track2 = | |
| 2503 observer_.remote_streams()->at(0)->GetAudioTracks()[1]; | |
| 2504 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state()); | |
| 2505 rtc::scoped_refptr<VideoTrackInterface> video_track2 = | |
| 2506 observer_.remote_streams()->at(0)->GetVideoTracks()[1]; | |
| 2507 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state()); | |
| 2508 | |
| 2509 // Remove the extra audio and video tracks. | |
| 2510 std::unique_ptr<SessionDescriptionInterface> desc_ms2 = | |
| 2511 CreateSessionDescriptionAndReference(1, 1); | |
| 2512 MockTrackObserver audio_track_observer(audio_track2); | |
| 2513 MockTrackObserver video_track_observer(video_track2); | |
| 2514 | |
| 2515 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1)); | |
| 2516 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1)); | |
| 2517 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release())); | |
| 2518 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), | |
| 2519 reference_collection_)); | |
| 2520 // Track state may be updated asynchronously. | |
| 2521 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, | |
| 2522 audio_track2->state(), kTimeout); | |
| 2523 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, | |
| 2524 video_track2->state(), kTimeout); | |
| 2525 } | |
| 2526 | |
| 2527 // This tests that remote tracks are ended if a local session description is set | |
| 2528 // that rejects the media content type. | |
| 2529 TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) { | |
| 2530 FakeConstraints constraints; | |
| 2531 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2532 true); | |
| 2533 CreatePeerConnection(&constraints); | |
| 2534 // First create and set a remote offer, then reject its video content in our | |
| 2535 // answer. | |
| 2536 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2537 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2538 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2539 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); | |
| 2540 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2541 | |
| 2542 rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video = | |
| 2543 remote_stream->GetVideoTracks()[0]; | |
| 2544 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state()); | |
| 2545 rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio = | |
| 2546 remote_stream->GetAudioTracks()[0]; | |
| 2547 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); | |
| 2548 | |
| 2549 std::unique_ptr<SessionDescriptionInterface> local_answer; | |
| 2550 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr)); | |
| 2551 cricket::ContentInfo* video_info = | |
| 2552 local_answer->description()->GetContentByName("video"); | |
| 2553 video_info->rejected = true; | |
| 2554 EXPECT_TRUE(DoSetLocalDescription(local_answer.release())); | |
| 2555 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state()); | |
| 2556 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); | |
| 2557 | |
| 2558 // Now create an offer where we reject both video and audio. | |
| 2559 std::unique_ptr<SessionDescriptionInterface> local_offer; | |
| 2560 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr)); | |
| 2561 video_info = local_offer->description()->GetContentByName("video"); | |
| 2562 ASSERT_TRUE(video_info != nullptr); | |
| 2563 video_info->rejected = true; | |
| 2564 cricket::ContentInfo* audio_info = | |
| 2565 local_offer->description()->GetContentByName("audio"); | |
| 2566 ASSERT_TRUE(audio_info != nullptr); | |
| 2567 audio_info->rejected = true; | |
| 2568 EXPECT_TRUE(DoSetLocalDescription(local_offer.release())); | |
| 2569 // Track state may be updated asynchronously. | |
| 2570 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, | |
| 2571 remote_audio->state(), kTimeout); | |
| 2572 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, | |
| 2573 remote_video->state(), kTimeout); | |
| 2574 } | |
| 2575 | |
| 2576 // This tests that we won't crash if the remote track has been removed outside | |
| 2577 // of PeerConnection and then PeerConnection tries to reject the track. | |
| 2578 TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) { | |
| 2579 FakeConstraints constraints; | |
| 2580 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2581 true); | |
| 2582 CreatePeerConnection(&constraints); | |
| 2583 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2584 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2585 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); | |
| 2586 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); | |
| 2587 | |
| 2588 std::unique_ptr<SessionDescriptionInterface> local_answer( | |
| 2589 webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, | |
| 2590 kSdpStringWithStream1, nullptr)); | |
| 2591 cricket::ContentInfo* video_info = | |
| 2592 local_answer->description()->GetContentByName("video"); | |
| 2593 video_info->rejected = true; | |
| 2594 cricket::ContentInfo* audio_info = | |
| 2595 local_answer->description()->GetContentByName("audio"); | |
| 2596 audio_info->rejected = true; | |
| 2597 EXPECT_TRUE(DoSetLocalDescription(local_answer.release())); | |
| 2598 | |
| 2599 // No crash is a pass. | |
| 2600 } | |
| 2601 | |
| 2602 // This tests that if a recvonly remote description is set, no remote streams | |
| 2603 // will be created, even if the description contains SSRCs/MSIDs. | |
| 2604 // See: https://code.google.com/p/webrtc/issues/detail?id=5054 | |
| 2605 TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) { | |
| 2606 FakeConstraints constraints; | |
| 2607 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2608 true); | |
| 2609 CreatePeerConnection(&constraints); | |
| 2610 | |
| 2611 std::string recvonly_offer = kSdpStringWithStream1; | |
| 2612 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly, | |
| 2613 strlen(kRecvonly), &recvonly_offer); | |
| 2614 CreateAndSetRemoteOffer(recvonly_offer); | |
| 2615 | |
| 2616 EXPECT_EQ(0u, observer_.remote_streams()->count()); | |
| 2617 } | |
| 2618 | |
| 2619 // This tests that a default MediaStream is created if a remote session | |
| 2620 // description doesn't contain any streams and no MSID support. | |
| 2621 // It also tests that the default stream is updated if a video m-line is added | |
| 2622 // in a subsequent session description. | |
| 2623 TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) { | |
| 2624 FakeConstraints constraints; | |
| 2625 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2626 true); | |
| 2627 CreatePeerConnection(&constraints); | |
| 2628 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); | |
| 2629 | |
| 2630 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2631 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2632 | |
| 2633 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2634 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size()); | |
| 2635 EXPECT_EQ("default", remote_stream->label()); | |
| 2636 | |
| 2637 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); | |
| 2638 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2639 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2640 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id()); | |
| 2641 EXPECT_EQ(MediaStreamTrackInterface::kLive, | |
| 2642 remote_stream->GetAudioTracks()[0]->state()); | |
| 2643 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); | |
| 2644 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id()); | |
| 2645 EXPECT_EQ(MediaStreamTrackInterface::kLive, | |
| 2646 remote_stream->GetVideoTracks()[0]->state()); | |
| 2647 } | |
| 2648 | |
| 2649 // This tests that a default MediaStream is created if a remote session | |
| 2650 // description doesn't contain any streams and media direction is send only. | |
| 2651 TEST_F(PeerConnectionInterfaceTest, | |
| 2652 SendOnlySdpWithoutMsidCreatesDefaultStream) { | |
| 2653 FakeConstraints constraints; | |
| 2654 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2655 true); | |
| 2656 CreatePeerConnection(&constraints); | |
| 2657 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams); | |
| 2658 | |
| 2659 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2660 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2661 | |
| 2662 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2663 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); | |
| 2664 EXPECT_EQ("default", remote_stream->label()); | |
| 2665 } | |
| 2666 | |
| 2667 // This tests that it won't crash when PeerConnection tries to remove | |
| 2668 // a remote track that as already been removed from the MediaStream. | |
| 2669 TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) { | |
| 2670 FakeConstraints constraints; | |
| 2671 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2672 true); | |
| 2673 CreatePeerConnection(&constraints); | |
| 2674 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2675 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2676 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); | |
| 2677 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); | |
| 2678 | |
| 2679 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); | |
| 2680 | |
| 2681 // No crash is a pass. | |
| 2682 } | |
| 2683 | |
| 2684 // This tests that a default MediaStream is created if the remote session | |
| 2685 // description doesn't contain any streams and don't contain an indication if | |
| 2686 // MSID is supported. | |
| 2687 TEST_F(PeerConnectionInterfaceTest, | |
| 2688 SdpWithoutMsidAndStreamsCreatesDefaultStream) { | |
| 2689 FakeConstraints constraints; | |
| 2690 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2691 true); | |
| 2692 CreatePeerConnection(&constraints); | |
| 2693 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); | |
| 2694 | |
| 2695 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2696 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2697 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2698 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); | |
| 2699 } | |
| 2700 | |
| 2701 // This tests that a default MediaStream is not created if the remote session | |
| 2702 // description doesn't contain any streams but does support MSID. | |
| 2703 TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) { | |
| 2704 FakeConstraints constraints; | |
| 2705 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2706 true); | |
| 2707 CreatePeerConnection(&constraints); | |
| 2708 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams); | |
| 2709 EXPECT_EQ(0u, observer_.remote_streams()->count()); | |
| 2710 } | |
| 2711 | |
| 2712 // This tests that when setting a new description, the old default tracks are | |
| 2713 // not destroyed and recreated. | |
| 2714 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250 | |
| 2715 TEST_F(PeerConnectionInterfaceTest, | |
| 2716 DefaultTracksNotDestroyedAndRecreated) { | |
| 2717 FakeConstraints constraints; | |
| 2718 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2719 true); | |
| 2720 CreatePeerConnection(&constraints); | |
| 2721 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); | |
| 2722 | |
| 2723 ASSERT_EQ(1u, observer_.remote_streams()->count()); | |
| 2724 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); | |
| 2725 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2726 | |
| 2727 // Set the track to "disabled", then set a new description and ensure the | |
| 2728 // track is still disabled, which ensures it hasn't been recreated. | |
| 2729 remote_stream->GetAudioTracks()[0]->set_enabled(false); | |
| 2730 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); | |
| 2731 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); | |
| 2732 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled()); | |
| 2733 } | |
| 2734 | |
| 2735 // This tests that a default MediaStream is not created if a remote session | |
| 2736 // description is updated to not have any MediaStreams. | |
| 2737 TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) { | |
| 2738 FakeConstraints constraints; | |
| 2739 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2740 true); | |
| 2741 CreatePeerConnection(&constraints); | |
| 2742 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2743 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); | |
| 2744 EXPECT_TRUE( | |
| 2745 CompareStreamCollections(observer_.remote_streams(), reference.get())); | |
| 2746 | |
| 2747 CreateAndSetRemoteOffer(kSdpStringWithoutStreams); | |
| 2748 EXPECT_EQ(0u, observer_.remote_streams()->count()); | |
| 2749 } | |
| 2750 | |
| 2751 // This tests that an RtpSender is created when the local description is set | |
| 2752 // after adding a local stream. | |
| 2753 // TODO(deadbeef): This test and the one below it need to be updated when | |
| 2754 // an RtpSender's lifetime isn't determined by when a local description is set. | |
| 2755 TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) { | |
| 2756 FakeConstraints constraints; | |
| 2757 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2758 true); | |
| 2759 CreatePeerConnection(&constraints); | |
| 2760 | |
| 2761 // Create an offer with 1 stream with 2 tracks of each type. | |
| 2762 rtc::scoped_refptr<StreamCollection> stream_collection = | |
| 2763 CreateStreamCollection(1, 2); | |
| 2764 pc_->AddStream(stream_collection->at(0)); | |
| 2765 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2766 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2767 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2768 | |
| 2769 auto senders = pc_->GetSenders(); | |
| 2770 EXPECT_EQ(4u, senders.size()); | |
| 2771 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2772 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2773 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); | |
| 2774 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); | |
| 2775 | |
| 2776 // Remove an audio and video track. | |
| 2777 pc_->RemoveStream(stream_collection->at(0)); | |
| 2778 stream_collection = CreateStreamCollection(1, 1); | |
| 2779 pc_->AddStream(stream_collection->at(0)); | |
| 2780 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2781 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2782 | |
| 2783 senders = pc_->GetSenders(); | |
| 2784 EXPECT_EQ(2u, senders.size()); | |
| 2785 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2786 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2787 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1])); | |
| 2788 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1])); | |
| 2789 } | |
| 2790 | |
| 2791 // This tests that an RtpSender is created when the local description is set | |
| 2792 // before adding a local stream. | |
| 2793 TEST_F(PeerConnectionInterfaceTest, | |
| 2794 AddLocalStreamAfterLocalDescriptionChanged) { | |
| 2795 FakeConstraints constraints; | |
| 2796 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2797 true); | |
| 2798 CreatePeerConnection(&constraints); | |
| 2799 | |
| 2800 rtc::scoped_refptr<StreamCollection> stream_collection = | |
| 2801 CreateStreamCollection(1, 2); | |
| 2802 // Add a stream to create the offer, but remove it afterwards. | |
| 2803 pc_->AddStream(stream_collection->at(0)); | |
| 2804 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2805 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2806 pc_->RemoveStream(stream_collection->at(0)); | |
| 2807 | |
| 2808 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2809 auto senders = pc_->GetSenders(); | |
| 2810 EXPECT_EQ(0u, senders.size()); | |
| 2811 | |
| 2812 pc_->AddStream(stream_collection->at(0)); | |
| 2813 senders = pc_->GetSenders(); | |
| 2814 EXPECT_EQ(4u, senders.size()); | |
| 2815 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2816 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2817 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); | |
| 2818 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); | |
| 2819 } | |
| 2820 | |
| 2821 // This tests that the expected behavior occurs if the SSRC on a local track is | |
| 2822 // changed when SetLocalDescription is called. | |
| 2823 TEST_F(PeerConnectionInterfaceTest, | |
| 2824 ChangeSsrcOnTrackInLocalSessionDescription) { | |
| 2825 FakeConstraints constraints; | |
| 2826 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2827 true); | |
| 2828 CreatePeerConnection(&constraints); | |
| 2829 | |
| 2830 rtc::scoped_refptr<StreamCollection> stream_collection = | |
| 2831 CreateStreamCollection(2, 1); | |
| 2832 pc_->AddStream(stream_collection->at(0)); | |
| 2833 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2834 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2835 // Grab a copy of the offer before it gets passed into the PC. | |
| 2836 std::unique_ptr<JsepSessionDescription> modified_offer( | |
| 2837 new JsepSessionDescription(JsepSessionDescription::kOffer)); | |
| 2838 modified_offer->Initialize(offer->description()->Copy(), offer->session_id(), | |
| 2839 offer->session_version()); | |
| 2840 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2841 | |
| 2842 auto senders = pc_->GetSenders(); | |
| 2843 EXPECT_EQ(2u, senders.size()); | |
| 2844 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2845 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2846 | |
| 2847 // Change the ssrc of the audio and video track. | |
| 2848 cricket::MediaContentDescription* desc = | |
| 2849 cricket::GetFirstAudioContentDescription(modified_offer->description()); | |
| 2850 ASSERT_TRUE(desc != NULL); | |
| 2851 for (StreamParams& stream : desc->mutable_streams()) { | |
| 2852 for (unsigned int& ssrc : stream.ssrcs) { | |
| 2853 ++ssrc; | |
| 2854 } | |
| 2855 } | |
| 2856 | |
| 2857 desc = | |
| 2858 cricket::GetFirstVideoContentDescription(modified_offer->description()); | |
| 2859 ASSERT_TRUE(desc != NULL); | |
| 2860 for (StreamParams& stream : desc->mutable_streams()) { | |
| 2861 for (unsigned int& ssrc : stream.ssrcs) { | |
| 2862 ++ssrc; | |
| 2863 } | |
| 2864 } | |
| 2865 | |
| 2866 EXPECT_TRUE(DoSetLocalDescription(modified_offer.release())); | |
| 2867 senders = pc_->GetSenders(); | |
| 2868 EXPECT_EQ(2u, senders.size()); | |
| 2869 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); | |
| 2870 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); | |
| 2871 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC | |
| 2872 // changed. | |
| 2873 } | |
| 2874 | |
| 2875 // This tests that the expected behavior occurs if a new session description is | |
| 2876 // set with the same tracks, but on a different MediaStream. | |
| 2877 TEST_F(PeerConnectionInterfaceTest, | |
| 2878 SignalSameTracksInSeparateMediaStream) { | |
| 2879 FakeConstraints constraints; | |
| 2880 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2881 true); | |
| 2882 CreatePeerConnection(&constraints); | |
| 2883 | |
| 2884 rtc::scoped_refptr<StreamCollection> stream_collection = | |
| 2885 CreateStreamCollection(2, 1); | |
| 2886 pc_->AddStream(stream_collection->at(0)); | |
| 2887 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 2888 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2889 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2890 | |
| 2891 auto senders = pc_->GetSenders(); | |
| 2892 EXPECT_EQ(2u, senders.size()); | |
| 2893 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0])); | |
| 2894 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0])); | |
| 2895 | |
| 2896 // Add a new MediaStream but with the same tracks as in the first stream. | |
| 2897 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1( | |
| 2898 webrtc::MediaStream::Create(kStreams[1])); | |
| 2899 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]); | |
| 2900 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]); | |
| 2901 pc_->AddStream(stream_1); | |
| 2902 | |
| 2903 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 2904 EXPECT_TRUE(DoSetLocalDescription(offer.release())); | |
| 2905 | |
| 2906 auto new_senders = pc_->GetSenders(); | |
| 2907 // Should be the same senders as before, but with updated stream id. | |
| 2908 // Note that this behavior is subject to change in the future. | |
| 2909 // We may decide the PC should ignore existing tracks in AddStream. | |
| 2910 EXPECT_EQ(senders, new_senders); | |
| 2911 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); | |
| 2912 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); | |
| 2913 } | |
| 2914 | |
| 2915 // This tests that PeerConnectionObserver::OnAddTrack is correctly called. | |
| 2916 TEST_F(PeerConnectionInterfaceTest, OnAddTrackCallback) { | |
| 2917 FakeConstraints constraints; | |
| 2918 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, | |
| 2919 true); | |
| 2920 CreatePeerConnection(&constraints); | |
| 2921 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly); | |
| 2922 EXPECT_EQ(observer_.num_added_tracks_, 1); | |
| 2923 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]); | |
| 2924 | |
| 2925 // Create and set the updated remote SDP. | |
| 2926 CreateAndSetRemoteOffer(kSdpStringWithStream1); | |
| 2927 EXPECT_EQ(observer_.num_added_tracks_, 2); | |
| 2928 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]); | |
| 2929 } | |
| 2930 | |
| 2931 // Test that when SetConfiguration is called and the configuration is | |
| 2932 // changing, the next offer causes an ICE restart. | |
| 2933 TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingIceRetart) { | |
| 2934 PeerConnectionInterface::RTCConfiguration config; | |
| 2935 config.type = PeerConnectionInterface::kRelay; | |
| 2936 // Need to pass default constraints to prevent disabling of DTLS... | |
| 2937 FakeConstraints default_constraints; | |
| 2938 CreatePeerConnection(config, &default_constraints); | |
| 2939 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 2940 | |
| 2941 // Do initial offer/answer so there's something to restart. | |
| 2942 CreateOfferAsLocalDescription(); | |
| 2943 CreateAnswerAsRemoteDescription(kSdpStringWithStream1); | |
| 2944 | |
| 2945 // Grab the ufrags. | |
| 2946 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); | |
| 2947 | |
| 2948 // Change ICE policy, which should trigger an ICE restart on the next offer. | |
| 2949 config.type = PeerConnectionInterface::kAll; | |
| 2950 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2951 CreateOfferAsLocalDescription(); | |
| 2952 | |
| 2953 // Grab the new ufrags. | |
| 2954 std::vector<std::string> subsequent_ufrags = | |
| 2955 GetUfrags(pc_->local_description()); | |
| 2956 | |
| 2957 // Sanity check. | |
| 2958 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size()); | |
| 2959 // Check that each ufrag is different. | |
| 2960 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) { | |
| 2961 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]); | |
| 2962 } | |
| 2963 } | |
| 2964 | |
| 2965 // Test that when SetConfiguration is called and the configuration *isn't* | |
| 2966 // changing, the next offer does *not* cause an ICE restart. | |
| 2967 TEST_F(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRetart) { | |
| 2968 PeerConnectionInterface::RTCConfiguration config; | |
| 2969 config.type = PeerConnectionInterface::kRelay; | |
| 2970 // Need to pass default constraints to prevent disabling of DTLS... | |
| 2971 FakeConstraints default_constraints; | |
| 2972 CreatePeerConnection(config, &default_constraints); | |
| 2973 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 2974 | |
| 2975 // Do initial offer/answer so there's something to restart. | |
| 2976 CreateOfferAsLocalDescription(); | |
| 2977 CreateAnswerAsRemoteDescription(kSdpStringWithStream1); | |
| 2978 | |
| 2979 // Grab the ufrags. | |
| 2980 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); | |
| 2981 | |
| 2982 // Call SetConfiguration with a config identical to what the PC was | |
| 2983 // constructed with. | |
| 2984 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 2985 CreateOfferAsLocalDescription(); | |
| 2986 | |
| 2987 // Grab the new ufrags. | |
| 2988 std::vector<std::string> subsequent_ufrags = | |
| 2989 GetUfrags(pc_->local_description()); | |
| 2990 | |
| 2991 EXPECT_EQ(initial_ufrags, subsequent_ufrags); | |
| 2992 } | |
| 2993 | |
| 2994 // Test for a weird corner case scenario: | |
| 2995 // 1. Audio/video session established. | |
| 2996 // 2. SetConfiguration changes ICE config; ICE restart needed. | |
| 2997 // 3. ICE restart initiated by remote peer, but only for one m= section. | |
| 2998 // 4. Next createOffer should initiate an ICE restart, but only for the other | |
| 2999 // m= section; it would be pointless to do an ICE restart for the m= section | |
| 3000 // that was already restarted. | |
| 3001 TEST_F(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) { | |
| 3002 PeerConnectionInterface::RTCConfiguration config; | |
| 3003 config.type = PeerConnectionInterface::kRelay; | |
| 3004 // Need to pass default constraints to prevent disabling of DTLS... | |
| 3005 FakeConstraints default_constraints; | |
| 3006 CreatePeerConnection(config, &default_constraints); | |
| 3007 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); | |
| 3008 | |
| 3009 // Do initial offer/answer so there's something to restart. | |
| 3010 CreateOfferAsLocalDescription(); | |
| 3011 CreateAnswerAsRemoteDescription(kSdpStringWithStream1); | |
| 3012 | |
| 3013 // Change ICE policy, which should set the "needs-ice-restart" flag. | |
| 3014 config.type = PeerConnectionInterface::kAll; | |
| 3015 EXPECT_TRUE(pc_->SetConfiguration(config)); | |
| 3016 | |
| 3017 // Do ICE restart for the first m= section, initiated by remote peer. | |
| 3018 webrtc::JsepSessionDescription* remote_offer = | |
| 3019 new webrtc::JsepSessionDescription(SessionDescriptionInterface::kOffer); | |
| 3020 EXPECT_TRUE(remote_offer->Initialize(kSdpStringWithStream1, nullptr)); | |
| 3021 remote_offer->description()->transport_infos()[0].description.ice_ufrag = | |
| 3022 "modified"; | |
| 3023 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); | |
| 3024 CreateAnswerAsLocalDescription(); | |
| 3025 | |
| 3026 // Grab the ufrags. | |
| 3027 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); | |
| 3028 ASSERT_EQ(2, initial_ufrags.size()); | |
| 3029 | |
| 3030 // Create offer and grab the new ufrags. | |
| 3031 CreateOfferAsLocalDescription(); | |
| 3032 std::vector<std::string> subsequent_ufrags = | |
| 3033 GetUfrags(pc_->local_description()); | |
| 3034 ASSERT_EQ(2, subsequent_ufrags.size()); | |
| 3035 | |
| 3036 // Ensure that only the ufrag for the second m= section changed. | |
| 3037 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]); | |
| 3038 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]); | |
| 3039 } | |
| 3040 | |
| 3041 // Tests that the methods to return current/pending descriptions work as | |
| 3042 // expected at different points in the offer/answer exchange. This test does | |
| 3043 // one offer/answer exchange as the offerer, then another as the answerer. | |
| 3044 TEST_F(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) { | |
| 3045 // This disables DTLS so we can apply an answer to ourselves. | |
| 3046 CreatePeerConnection(); | |
| 3047 | |
| 3048 // Create initial local offer and get SDP (which will also be used as | |
| 3049 // answer/pranswer); | |
| 3050 std::unique_ptr<SessionDescriptionInterface> offer; | |
| 3051 ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); | |
| 3052 std::string sdp; | |
| 3053 EXPECT_TRUE(offer->ToString(&sdp)); | |
| 3054 | |
| 3055 // Set local offer. | |
| 3056 SessionDescriptionInterface* local_offer = offer.release(); | |
| 3057 EXPECT_TRUE(DoSetLocalDescription(local_offer)); | |
| 3058 EXPECT_EQ(local_offer, pc_->pending_local_description()); | |
| 3059 EXPECT_EQ(nullptr, pc_->pending_remote_description()); | |
| 3060 EXPECT_EQ(nullptr, pc_->current_local_description()); | |
| 3061 EXPECT_EQ(nullptr, pc_->current_remote_description()); | |
| 3062 | |
| 3063 // Set remote pranswer. | |
| 3064 SessionDescriptionInterface* remote_pranswer = | |
| 3065 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer, | |
| 3066 sdp, nullptr); | |
| 3067 EXPECT_TRUE(DoSetRemoteDescription(remote_pranswer)); | |
| 3068 EXPECT_EQ(local_offer, pc_->pending_local_description()); | |
| 3069 EXPECT_EQ(remote_pranswer, pc_->pending_remote_description()); | |
| 3070 EXPECT_EQ(nullptr, pc_->current_local_description()); | |
| 3071 EXPECT_EQ(nullptr, pc_->current_remote_description()); | |
| 3072 | |
| 3073 // Set remote answer. | |
| 3074 SessionDescriptionInterface* remote_answer = webrtc::CreateSessionDescription( | |
| 3075 SessionDescriptionInterface::kAnswer, sdp, nullptr); | |
| 3076 EXPECT_TRUE(DoSetRemoteDescription(remote_answer)); | |
| 3077 EXPECT_EQ(nullptr, pc_->pending_local_description()); | |
| 3078 EXPECT_EQ(nullptr, pc_->pending_remote_description()); | |
| 3079 EXPECT_EQ(local_offer, pc_->current_local_description()); | |
| 3080 EXPECT_EQ(remote_answer, pc_->current_remote_description()); | |
| 3081 | |
| 3082 // Set remote offer. | |
| 3083 SessionDescriptionInterface* remote_offer = webrtc::CreateSessionDescription( | |
| 3084 SessionDescriptionInterface::kOffer, sdp, nullptr); | |
| 3085 EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); | |
| 3086 EXPECT_EQ(remote_offer, pc_->pending_remote_description()); | |
| 3087 EXPECT_EQ(nullptr, pc_->pending_local_description()); | |
| 3088 EXPECT_EQ(local_offer, pc_->current_local_description()); | |
| 3089 EXPECT_EQ(remote_answer, pc_->current_remote_description()); | |
| 3090 | |
| 3091 // Set local pranswer. | |
| 3092 SessionDescriptionInterface* local_pranswer = | |
| 3093 webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer, | |
| 3094 sdp, nullptr); | |
| 3095 EXPECT_TRUE(DoSetLocalDescription(local_pranswer)); | |
| 3096 EXPECT_EQ(remote_offer, pc_->pending_remote_description()); | |
| 3097 EXPECT_EQ(local_pranswer, pc_->pending_local_description()); | |
| 3098 EXPECT_EQ(local_offer, pc_->current_local_description()); | |
| 3099 EXPECT_EQ(remote_answer, pc_->current_remote_description()); | |
| 3100 | |
| 3101 // Set local answer. | |
| 3102 SessionDescriptionInterface* local_answer = webrtc::CreateSessionDescription( | |
| 3103 SessionDescriptionInterface::kAnswer, sdp, nullptr); | |
| 3104 EXPECT_TRUE(DoSetLocalDescription(local_answer)); | |
| 3105 EXPECT_EQ(nullptr, pc_->pending_remote_description()); | |
| 3106 EXPECT_EQ(nullptr, pc_->pending_local_description()); | |
| 3107 EXPECT_EQ(remote_offer, pc_->current_remote_description()); | |
| 3108 EXPECT_EQ(local_answer, pc_->current_local_description()); | |
| 3109 } | |
| 3110 | |
| 3111 class PeerConnectionMediaConfigTest : public testing::Test { | |
| 3112 protected: | |
| 3113 void SetUp() override { | |
| 3114 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); | |
| 3115 pcf_->Initialize(); | |
| 3116 } | |
| 3117 const cricket::MediaConfig& TestCreatePeerConnection( | |
| 3118 const PeerConnectionInterface::RTCConfiguration& config, | |
| 3119 const MediaConstraintsInterface *constraints) { | |
| 3120 pcf_->create_media_controller_called_ = false; | |
| 3121 | |
| 3122 rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection( | |
| 3123 config, constraints, nullptr, nullptr, &observer_)); | |
| 3124 EXPECT_TRUE(pc.get()); | |
| 3125 EXPECT_TRUE(pcf_->create_media_controller_called_); | |
| 3126 return pcf_->create_media_controller_config_; | |
| 3127 } | |
| 3128 | |
| 3129 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_; | |
| 3130 MockPeerConnectionObserver observer_; | |
| 3131 }; | |
| 3132 | |
| 3133 // This test verifies the default behaviour with no constraints and a | |
| 3134 // default RTCConfiguration. | |
| 3135 TEST_F(PeerConnectionMediaConfigTest, TestDefaults) { | |
| 3136 PeerConnectionInterface::RTCConfiguration config; | |
| 3137 FakeConstraints constraints; | |
| 3138 | |
| 3139 const cricket::MediaConfig& media_config = | |
| 3140 TestCreatePeerConnection(config, &constraints); | |
| 3141 | |
| 3142 EXPECT_FALSE(media_config.enable_dscp); | |
| 3143 EXPECT_TRUE(media_config.video.enable_cpu_overuse_detection); | |
| 3144 EXPECT_FALSE(media_config.video.disable_prerenderer_smoothing); | |
| 3145 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate); | |
| 3146 } | |
| 3147 | |
| 3148 // This test verifies the DSCP constraint is recognized and passed to | |
| 3149 // the CreateMediaController call. | |
| 3150 TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) { | |
| 3151 PeerConnectionInterface::RTCConfiguration config; | |
| 3152 FakeConstraints constraints; | |
| 3153 | |
| 3154 constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true); | |
| 3155 const cricket::MediaConfig& media_config = | |
| 3156 TestCreatePeerConnection(config, &constraints); | |
| 3157 | |
| 3158 EXPECT_TRUE(media_config.enable_dscp); | |
| 3159 } | |
| 3160 | |
| 3161 // This test verifies the cpu overuse detection constraint is | |
| 3162 // recognized and passed to the CreateMediaController call. | |
| 3163 TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) { | |
| 3164 PeerConnectionInterface::RTCConfiguration config; | |
| 3165 FakeConstraints constraints; | |
| 3166 | |
| 3167 constraints.AddOptional( | |
| 3168 webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false); | |
| 3169 const cricket::MediaConfig media_config = | |
| 3170 TestCreatePeerConnection(config, &constraints); | |
| 3171 | |
| 3172 EXPECT_FALSE(media_config.video.enable_cpu_overuse_detection); | |
| 3173 } | |
| 3174 | |
| 3175 // This test verifies that the disable_prerenderer_smoothing flag is | |
| 3176 // propagated from RTCConfiguration to the CreateMediaController call. | |
| 3177 TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) { | |
| 3178 PeerConnectionInterface::RTCConfiguration config; | |
| 3179 FakeConstraints constraints; | |
| 3180 | |
| 3181 config.set_prerenderer_smoothing(false); | |
| 3182 const cricket::MediaConfig& media_config = | |
| 3183 TestCreatePeerConnection(config, &constraints); | |
| 3184 | |
| 3185 EXPECT_TRUE(media_config.video.disable_prerenderer_smoothing); | |
| 3186 } | |
| 3187 | |
| 3188 // This test verifies the suspend below min bitrate constraint is | |
| 3189 // recognized and passed to the CreateMediaController call. | |
| 3190 TEST_F(PeerConnectionMediaConfigTest, | |
| 3191 TestSuspendBelowMinBitrateConstraintTrue) { | |
| 3192 PeerConnectionInterface::RTCConfiguration config; | |
| 3193 FakeConstraints constraints; | |
| 3194 | |
| 3195 constraints.AddOptional( | |
| 3196 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, | |
| 3197 true); | |
| 3198 const cricket::MediaConfig media_config = | |
| 3199 TestCreatePeerConnection(config, &constraints); | |
| 3200 | |
| 3201 EXPECT_TRUE(media_config.video.suspend_below_min_bitrate); | |
| 3202 } | |
| 3203 | |
| 3204 // The following tests verify that session options are created correctly. | |
| 3205 // TODO(deadbeef): Convert these tests to be more end-to-end. Instead of | |
| 3206 // "verify options are converted correctly", should be "pass options into | |
| 3207 // CreateOffer and verify the correct offer is produced." | |
| 3208 | |
| 3209 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) { | |
| 3210 RTCOfferAnswerOptions rtc_options; | |
| 3211 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1; | |
| 3212 | |
| 3213 cricket::MediaSessionOptions options; | |
| 3214 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3215 | |
| 3216 rtc_options.offer_to_receive_audio = | |
| 3217 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; | |
| 3218 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3219 } | |
| 3220 | |
| 3221 TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) { | |
| 3222 RTCOfferAnswerOptions rtc_options; | |
| 3223 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1; | |
| 3224 | |
| 3225 cricket::MediaSessionOptions options; | |
| 3226 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3227 | |
| 3228 rtc_options.offer_to_receive_video = | |
| 3229 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; | |
| 3230 EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3231 } | |
| 3232 | |
| 3233 // Test that a MediaSessionOptions is created for an offer if | |
| 3234 // OfferToReceiveAudio and OfferToReceiveVideo options are set. | |
| 3235 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) { | |
| 3236 RTCOfferAnswerOptions rtc_options; | |
| 3237 rtc_options.offer_to_receive_audio = 1; | |
| 3238 rtc_options.offer_to_receive_video = 1; | |
| 3239 | |
| 3240 cricket::MediaSessionOptions options; | |
| 3241 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3242 EXPECT_TRUE(options.has_audio()); | |
| 3243 EXPECT_TRUE(options.has_video()); | |
| 3244 EXPECT_TRUE(options.bundle_enabled); | |
| 3245 } | |
| 3246 | |
| 3247 // Test that a correct MediaSessionOptions is created for an offer if | |
| 3248 // OfferToReceiveAudio is set. | |
| 3249 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) { | |
| 3250 RTCOfferAnswerOptions rtc_options; | |
| 3251 rtc_options.offer_to_receive_audio = 1; | |
| 3252 | |
| 3253 cricket::MediaSessionOptions options; | |
| 3254 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3255 EXPECT_TRUE(options.has_audio()); | |
| 3256 EXPECT_FALSE(options.has_video()); | |
| 3257 EXPECT_TRUE(options.bundle_enabled); | |
| 3258 } | |
| 3259 | |
| 3260 // Test that a correct MediaSessionOptions is created for an offer if | |
| 3261 // the default OfferOptions are used. | |
| 3262 TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) { | |
| 3263 RTCOfferAnswerOptions rtc_options; | |
| 3264 | |
| 3265 cricket::MediaSessionOptions options; | |
| 3266 options.transport_options["audio"] = cricket::TransportOptions(); | |
| 3267 options.transport_options["video"] = cricket::TransportOptions(); | |
| 3268 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3269 EXPECT_TRUE(options.has_audio()); | |
| 3270 EXPECT_FALSE(options.has_video()); | |
| 3271 EXPECT_TRUE(options.bundle_enabled); | |
| 3272 EXPECT_TRUE(options.vad_enabled); | |
| 3273 EXPECT_FALSE(options.transport_options["audio"].ice_restart); | |
| 3274 EXPECT_FALSE(options.transport_options["video"].ice_restart); | |
| 3275 } | |
| 3276 | |
| 3277 // Test that a correct MediaSessionOptions is created for an offer if | |
| 3278 // OfferToReceiveVideo is set. | |
| 3279 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) { | |
| 3280 RTCOfferAnswerOptions rtc_options; | |
| 3281 rtc_options.offer_to_receive_audio = 0; | |
| 3282 rtc_options.offer_to_receive_video = 1; | |
| 3283 | |
| 3284 cricket::MediaSessionOptions options; | |
| 3285 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3286 EXPECT_FALSE(options.has_audio()); | |
| 3287 EXPECT_TRUE(options.has_video()); | |
| 3288 EXPECT_TRUE(options.bundle_enabled); | |
| 3289 } | |
| 3290 | |
| 3291 // Test that a correct MediaSessionOptions is created for an offer if | |
| 3292 // UseRtpMux is set to false. | |
| 3293 TEST(CreateSessionOptionsTest, | |
| 3294 GetMediaSessionOptionsForOfferWithBundleDisabled) { | |
| 3295 RTCOfferAnswerOptions rtc_options; | |
| 3296 rtc_options.offer_to_receive_audio = 1; | |
| 3297 rtc_options.offer_to_receive_video = 1; | |
| 3298 rtc_options.use_rtp_mux = false; | |
| 3299 | |
| 3300 cricket::MediaSessionOptions options; | |
| 3301 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3302 EXPECT_TRUE(options.has_audio()); | |
| 3303 EXPECT_TRUE(options.has_video()); | |
| 3304 EXPECT_FALSE(options.bundle_enabled); | |
| 3305 } | |
| 3306 | |
| 3307 // Test that a correct MediaSessionOptions is created to restart ice if | |
| 3308 // IceRestart is set. It also tests that subsequent MediaSessionOptions don't | |
| 3309 // have |audio_transport_options.ice_restart| etc. set. | |
| 3310 TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) { | |
| 3311 RTCOfferAnswerOptions rtc_options; | |
| 3312 rtc_options.ice_restart = true; | |
| 3313 | |
| 3314 cricket::MediaSessionOptions options; | |
| 3315 options.transport_options["audio"] = cricket::TransportOptions(); | |
| 3316 options.transport_options["video"] = cricket::TransportOptions(); | |
| 3317 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3318 EXPECT_TRUE(options.transport_options["audio"].ice_restart); | |
| 3319 EXPECT_TRUE(options.transport_options["video"].ice_restart); | |
| 3320 | |
| 3321 rtc_options = RTCOfferAnswerOptions(); | |
| 3322 EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, true, &options)); | |
| 3323 EXPECT_FALSE(options.transport_options["audio"].ice_restart); | |
| 3324 EXPECT_FALSE(options.transport_options["video"].ice_restart); | |
| 3325 } | |
| 3326 | |
| 3327 // Test that the MediaConstraints in an answer don't affect if audio and video | |
| 3328 // is offered in an offer but that if kOfferToReceiveAudio or | |
| 3329 // kOfferToReceiveVideo constraints are true in an offer, the media type will be | |
| 3330 // included in subsequent answers. | |
| 3331 TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) { | |
| 3332 FakeConstraints answer_c; | |
| 3333 answer_c.SetMandatoryReceiveAudio(true); | |
| 3334 answer_c.SetMandatoryReceiveVideo(true); | |
| 3335 | |
| 3336 cricket::MediaSessionOptions answer_options; | |
| 3337 EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options)); | |
| 3338 EXPECT_TRUE(answer_options.has_audio()); | |
| 3339 EXPECT_TRUE(answer_options.has_video()); | |
| 3340 | |
| 3341 RTCOfferAnswerOptions rtc_offer_options; | |
| 3342 | |
| 3343 cricket::MediaSessionOptions offer_options; | |
| 3344 EXPECT_TRUE( | |
| 3345 ExtractMediaSessionOptions(rtc_offer_options, false, &offer_options)); | |
| 3346 EXPECT_TRUE(offer_options.has_audio()); | |
| 3347 EXPECT_TRUE(offer_options.has_video()); | |
| 3348 | |
| 3349 RTCOfferAnswerOptions updated_rtc_offer_options; | |
| 3350 updated_rtc_offer_options.offer_to_receive_audio = 1; | |
| 3351 updated_rtc_offer_options.offer_to_receive_video = 1; | |
| 3352 | |
| 3353 cricket::MediaSessionOptions updated_offer_options; | |
| 3354 EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, false, | |
| 3355 &updated_offer_options)); | |
| 3356 EXPECT_TRUE(updated_offer_options.has_audio()); | |
| 3357 EXPECT_TRUE(updated_offer_options.has_video()); | |
| 3358 | |
| 3359 // Since an offer has been created with both audio and video, subsequent | |
| 3360 // offers and answers should contain both audio and video. | |
| 3361 // Answers will only contain the media types that exist in the offer | |
| 3362 // regardless of the value of |updated_answer_options.has_audio| and | |
| 3363 // |updated_answer_options.has_video|. | |
| 3364 FakeConstraints updated_answer_c; | |
| 3365 answer_c.SetMandatoryReceiveAudio(false); | |
| 3366 answer_c.SetMandatoryReceiveVideo(false); | |
| 3367 | |
| 3368 cricket::MediaSessionOptions updated_answer_options; | |
| 3369 EXPECT_TRUE( | |
| 3370 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | |
| 3371 EXPECT_TRUE(updated_answer_options.has_audio()); | |
| 3372 EXPECT_TRUE(updated_answer_options.has_video()); | |
| 3373 } | |
| 3374 | |
| 3375 TEST(RTCErrorTypeTest, OstreamOperator) { | |
| 3376 std::ostringstream oss; | |
| 3377 oss << webrtc::RTCErrorType::NONE << ' ' | |
| 3378 << webrtc::RTCErrorType::INVALID_PARAMETER << ' ' | |
| 3379 << webrtc::RTCErrorType::INTERNAL_ERROR; | |
| 3380 EXPECT_EQ("NONE INVALID_PARAMETER INTERNAL_ERROR", oss.str()); | |
| 3381 } | |
| 3382 | |
| 3383 // Tests a few random fields being different. | |
| 3384 TEST(RTCConfigurationTest, ComparisonOperators) { | |
| 3385 PeerConnectionInterface::RTCConfiguration a; | |
| 3386 PeerConnectionInterface::RTCConfiguration b; | |
| 3387 EXPECT_EQ(a, b); | |
| 3388 | |
| 3389 PeerConnectionInterface::RTCConfiguration c; | |
| 3390 c.servers.push_back(PeerConnectionInterface::IceServer()); | |
| 3391 EXPECT_NE(a, c); | |
| 3392 | |
| 3393 PeerConnectionInterface::RTCConfiguration d; | |
| 3394 d.type = PeerConnectionInterface::kRelay; | |
| 3395 EXPECT_NE(a, d); | |
| 3396 | |
| 3397 PeerConnectionInterface::RTCConfiguration e; | |
| 3398 e.audio_jitter_buffer_max_packets = 5; | |
| 3399 EXPECT_NE(a, e); | |
| 3400 | |
| 3401 PeerConnectionInterface::RTCConfiguration f; | |
| 3402 f.ice_connection_receiving_timeout = 1337; | |
| 3403 EXPECT_NE(a, f); | |
| 3404 | |
| 3405 PeerConnectionInterface::RTCConfiguration g; | |
| 3406 g.disable_ipv6 = true; | |
| 3407 EXPECT_NE(a, g); | |
| 3408 | |
| 3409 PeerConnectionInterface::RTCConfiguration h( | |
| 3410 PeerConnectionInterface::RTCConfigurationType::kAggressive); | |
| 3411 EXPECT_NE(a, h); | |
| 3412 } | |
| OLD | NEW |