henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <string> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 12 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 14 | #include "webrtc/api/audiotrack.h" |
| 15 | #include "webrtc/api/jsepsessiondescription.h" |
| 16 | #include "webrtc/api/mediastream.h" |
| 17 | #include "webrtc/api/mediastreaminterface.h" |
| 18 | #include "webrtc/api/peerconnection.h" |
| 19 | #include "webrtc/api/peerconnectioninterface.h" |
| 20 | #include "webrtc/api/rtpreceiverinterface.h" |
| 21 | #include "webrtc/api/rtpsenderinterface.h" |
| 22 | #include "webrtc/api/streamcollection.h" |
| 23 | #ifdef WEBRTC_ANDROID |
| 24 | #include "webrtc/api/test/androidtestinitializer.h" |
| 25 | #endif |
| 26 | #include "webrtc/api/test/fakeconstraints.h" |
| 27 | #include "webrtc/api/test/fakedtlsidentitystore.h" |
| 28 | #include "webrtc/api/test/mockpeerconnectionobservers.h" |
| 29 | #include "webrtc/api/test/testsdpstrings.h" |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame^] | 30 | #include "webrtc/api/videocapturertracksource.h" |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 31 | #include "webrtc/api/videotrack.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 32 | #include "webrtc/base/gunit.h" |
| 33 | #include "webrtc/base/scoped_ptr.h" |
| 34 | #include "webrtc/base/ssladapter.h" |
| 35 | #include "webrtc/base/sslstreamadapter.h" |
| 36 | #include "webrtc/base/stringutils.h" |
| 37 | #include "webrtc/base/thread.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 38 | #include "webrtc/media/base/fakevideocapturer.h" |
| 39 | #include "webrtc/media/sctp/sctpdataengine.h" |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 40 | #include "webrtc/p2p/client/fakeportallocator.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 41 | #include "webrtc/pc/mediasession.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 42 | |
| 43 | static const char kStreamLabel1[] = "local_stream_1"; |
| 44 | static const char kStreamLabel2[] = "local_stream_2"; |
| 45 | static const char kStreamLabel3[] = "local_stream_3"; |
| 46 | static const int kDefaultStunPort = 3478; |
| 47 | static const char kStunAddressOnly[] = "stun:address"; |
| 48 | static const char kStunInvalidPort[] = "stun:address:-1"; |
| 49 | static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; |
| 50 | static const char kStunAddressPortAndMore2[] = "stun:address:port more"; |
| 51 | static const char kTurnIceServerUri[] = "turn:user@turn.example.org"; |
| 52 | static const char kTurnUsername[] = "user"; |
| 53 | static const char kTurnPassword[] = "password"; |
| 54 | static const char kTurnHostname[] = "turn.example.org"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 55 | static const uint32_t kTimeout = 10000U; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 57 | static const char kStreams[][8] = {"stream1", "stream2"}; |
| 58 | static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"}; |
| 59 | static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"}; |
| 60 | |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 61 | static const char kRecvonly[] = "recvonly"; |
| 62 | static const char kSendrecv[] = "sendrecv"; |
| 63 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 64 | // Reference SDP with a MediaStream with label "stream1" and audio track with |
| 65 | // id "audio_1" and a video track with id "video_1; |
| 66 | static const char kSdpStringWithStream1[] = |
| 67 | "v=0\r\n" |
| 68 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 69 | "s=-\r\n" |
| 70 | "t=0 0\r\n" |
| 71 | "a=ice-ufrag:e5785931\r\n" |
| 72 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 73 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 74 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 75 | "m=audio 1 RTP/AVPF 103\r\n" |
| 76 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 77 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 78 | "a=rtpmap:103 ISAC/16000\r\n" |
| 79 | "a=ssrc:1 cname:stream1\r\n" |
| 80 | "a=ssrc:1 mslabel:stream1\r\n" |
| 81 | "a=ssrc:1 label:audiotrack0\r\n" |
| 82 | "m=video 1 RTP/AVPF 120\r\n" |
| 83 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 84 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 85 | "a=rtpmap:120 VP8/90000\r\n" |
| 86 | "a=ssrc:2 cname:stream1\r\n" |
| 87 | "a=ssrc:2 mslabel:stream1\r\n" |
| 88 | "a=ssrc:2 label:videotrack0\r\n"; |
| 89 | |
| 90 | // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each |
| 91 | // MediaStreams have one audio track and one video track. |
| 92 | // This uses MSID. |
| 93 | static const char kSdpStringWithStream1And2[] = |
| 94 | "v=0\r\n" |
| 95 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 96 | "s=-\r\n" |
| 97 | "t=0 0\r\n" |
| 98 | "a=ice-ufrag:e5785931\r\n" |
| 99 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 100 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 101 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 102 | "a=msid-semantic: WMS stream1 stream2\r\n" |
| 103 | "m=audio 1 RTP/AVPF 103\r\n" |
| 104 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 105 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 106 | "a=rtpmap:103 ISAC/16000\r\n" |
| 107 | "a=ssrc:1 cname:stream1\r\n" |
| 108 | "a=ssrc:1 msid:stream1 audiotrack0\r\n" |
| 109 | "a=ssrc:3 cname:stream2\r\n" |
| 110 | "a=ssrc:3 msid:stream2 audiotrack1\r\n" |
| 111 | "m=video 1 RTP/AVPF 120\r\n" |
| 112 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 113 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 114 | "a=rtpmap:120 VP8/0\r\n" |
| 115 | "a=ssrc:2 cname:stream1\r\n" |
| 116 | "a=ssrc:2 msid:stream1 videotrack0\r\n" |
| 117 | "a=ssrc:4 cname:stream2\r\n" |
| 118 | "a=ssrc:4 msid:stream2 videotrack1\r\n"; |
| 119 | |
| 120 | // Reference SDP without MediaStreams. Msid is not supported. |
| 121 | static const char kSdpStringWithoutStreams[] = |
| 122 | "v=0\r\n" |
| 123 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 124 | "s=-\r\n" |
| 125 | "t=0 0\r\n" |
| 126 | "a=ice-ufrag:e5785931\r\n" |
| 127 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 128 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 129 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 130 | "m=audio 1 RTP/AVPF 103\r\n" |
| 131 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 132 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 133 | "a=rtpmap:103 ISAC/16000\r\n" |
| 134 | "m=video 1 RTP/AVPF 120\r\n" |
| 135 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 136 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 137 | "a=rtpmap:120 VP8/90000\r\n"; |
| 138 | |
| 139 | // Reference SDP without MediaStreams. Msid is supported. |
| 140 | static const char kSdpStringWithMsidWithoutStreams[] = |
| 141 | "v=0\r\n" |
| 142 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 143 | "s=-\r\n" |
| 144 | "t=0 0\r\n" |
| 145 | "a=ice-ufrag:e5785931\r\n" |
| 146 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 147 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 148 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 149 | "a=msid-semantic: WMS\r\n" |
| 150 | "m=audio 1 RTP/AVPF 103\r\n" |
| 151 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 152 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 153 | "a=rtpmap:103 ISAC/16000\r\n" |
| 154 | "m=video 1 RTP/AVPF 120\r\n" |
| 155 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 156 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 157 | "a=rtpmap:120 VP8/90000\r\n"; |
| 158 | |
| 159 | // Reference SDP without MediaStreams and audio only. |
| 160 | static const char kSdpStringWithoutStreamsAudioOnly[] = |
| 161 | "v=0\r\n" |
| 162 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 163 | "s=-\r\n" |
| 164 | "t=0 0\r\n" |
| 165 | "a=ice-ufrag:e5785931\r\n" |
| 166 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 167 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 168 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 169 | "m=audio 1 RTP/AVPF 103\r\n" |
| 170 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 171 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 172 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 173 | |
| 174 | // Reference SENDONLY SDP without MediaStreams. Msid is not supported. |
| 175 | static const char kSdpStringSendOnlyWithoutStreams[] = |
| 176 | "v=0\r\n" |
| 177 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 178 | "s=-\r\n" |
| 179 | "t=0 0\r\n" |
| 180 | "a=ice-ufrag:e5785931\r\n" |
| 181 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 182 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 183 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 184 | "m=audio 1 RTP/AVPF 103\r\n" |
| 185 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 186 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 187 | "a=sendonly\r\n" |
| 188 | "a=rtpmap:103 ISAC/16000\r\n" |
| 189 | "m=video 1 RTP/AVPF 120\r\n" |
| 190 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 191 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 192 | "a=sendonly\r\n" |
| 193 | "a=rtpmap:120 VP8/90000\r\n"; |
| 194 | |
| 195 | static const char kSdpStringInit[] = |
| 196 | "v=0\r\n" |
| 197 | "o=- 0 0 IN IP4 127.0.0.1\r\n" |
| 198 | "s=-\r\n" |
| 199 | "t=0 0\r\n" |
| 200 | "a=ice-ufrag:e5785931\r\n" |
| 201 | "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n" |
| 202 | "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:" |
| 203 | "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n" |
| 204 | "a=msid-semantic: WMS\r\n"; |
| 205 | |
| 206 | static const char kSdpStringAudio[] = |
| 207 | "m=audio 1 RTP/AVPF 103\r\n" |
| 208 | "a=mid:audio\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 209 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 210 | "a=rtpmap:103 ISAC/16000\r\n"; |
| 211 | |
| 212 | static const char kSdpStringVideo[] = |
| 213 | "m=video 1 RTP/AVPF 120\r\n" |
| 214 | "a=mid:video\r\n" |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 215 | "a=sendrecv\r\n" |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 216 | "a=rtpmap:120 VP8/90000\r\n"; |
| 217 | |
| 218 | static const char kSdpStringMs1Audio0[] = |
| 219 | "a=ssrc:1 cname:stream1\r\n" |
| 220 | "a=ssrc:1 msid:stream1 audiotrack0\r\n"; |
| 221 | |
| 222 | static const char kSdpStringMs1Video0[] = |
| 223 | "a=ssrc:2 cname:stream1\r\n" |
| 224 | "a=ssrc:2 msid:stream1 videotrack0\r\n"; |
| 225 | |
| 226 | static const char kSdpStringMs1Audio1[] = |
| 227 | "a=ssrc:3 cname:stream1\r\n" |
| 228 | "a=ssrc:3 msid:stream1 audiotrack1\r\n"; |
| 229 | |
| 230 | static const char kSdpStringMs1Video1[] = |
| 231 | "a=ssrc:4 cname:stream1\r\n" |
| 232 | "a=ssrc:4 msid:stream1 videotrack1\r\n"; |
| 233 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 234 | #define MAYBE_SKIP_TEST(feature) \ |
| 235 | if (!(feature())) { \ |
| 236 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 237 | return; \ |
| 238 | } |
| 239 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 240 | using rtc::scoped_ptr; |
| 241 | using rtc::scoped_refptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 242 | using webrtc::AudioSourceInterface; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 243 | using webrtc::AudioTrack; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 244 | using webrtc::AudioTrackInterface; |
| 245 | using webrtc::DataBuffer; |
| 246 | using webrtc::DataChannelInterface; |
| 247 | using webrtc::FakeConstraints; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 248 | using webrtc::IceCandidateInterface; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 249 | using webrtc::MediaConstraintsInterface; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 250 | using webrtc::MediaStream; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 251 | using webrtc::MediaStreamInterface; |
| 252 | using webrtc::MediaStreamTrackInterface; |
| 253 | using webrtc::MockCreateSessionDescriptionObserver; |
| 254 | using webrtc::MockDataChannelObserver; |
| 255 | using webrtc::MockSetSessionDescriptionObserver; |
| 256 | using webrtc::MockStatsObserver; |
| 257 | using webrtc::PeerConnectionInterface; |
| 258 | using webrtc::PeerConnectionObserver; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 259 | using webrtc::RtpReceiverInterface; |
| 260 | using webrtc::RtpSenderInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 261 | using webrtc::SdpParseError; |
| 262 | using webrtc::SessionDescriptionInterface; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 263 | using webrtc::StreamCollection; |
| 264 | using webrtc::StreamCollectionInterface; |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame^] | 265 | using webrtc::VideoTrackSourceInterface; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 266 | using webrtc::VideoTrack; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 267 | using webrtc::VideoTrackInterface; |
| 268 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 269 | typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 270 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 271 | namespace { |
| 272 | |
| 273 | // Gets the first ssrc of given content type from the ContentInfo. |
| 274 | bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) { |
| 275 | if (!content_info || !ssrc) { |
| 276 | return false; |
| 277 | } |
| 278 | const cricket::MediaContentDescription* media_desc = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 279 | static_cast<const cricket::MediaContentDescription*>( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 280 | content_info->description); |
| 281 | if (!media_desc || media_desc->streams().empty()) { |
| 282 | return false; |
| 283 | } |
| 284 | *ssrc = media_desc->streams().begin()->first_ssrc(); |
| 285 | return true; |
| 286 | } |
| 287 | |
| 288 | void SetSsrcToZero(std::string* sdp) { |
| 289 | const char kSdpSsrcAtribute[] = "a=ssrc:"; |
| 290 | const char kSdpSsrcAtributeZero[] = "a=ssrc:0"; |
| 291 | size_t ssrc_pos = 0; |
| 292 | while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) != |
| 293 | std::string::npos) { |
| 294 | size_t end_ssrc = sdp->find(" ", ssrc_pos); |
| 295 | sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero); |
| 296 | ssrc_pos = end_ssrc; |
| 297 | } |
| 298 | } |
| 299 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 300 | // Check if |streams| contains the specified track. |
| 301 | bool ContainsTrack(const std::vector<cricket::StreamParams>& streams, |
| 302 | const std::string& stream_label, |
| 303 | const std::string& track_id) { |
| 304 | for (const cricket::StreamParams& params : streams) { |
| 305 | if (params.sync_label == stream_label && params.id == track_id) { |
| 306 | return true; |
| 307 | } |
| 308 | } |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | // Check if |senders| contains the specified sender, by id. |
| 313 | bool ContainsSender( |
| 314 | const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders, |
| 315 | const std::string& id) { |
| 316 | for (const auto& sender : senders) { |
| 317 | if (sender->id() == id) { |
| 318 | return true; |
| 319 | } |
| 320 | } |
| 321 | return false; |
| 322 | } |
| 323 | |
| 324 | // Create a collection of streams. |
| 325 | // CreateStreamCollection(1) creates a collection that |
| 326 | // correspond to kSdpStringWithStream1. |
| 327 | // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2. |
| 328 | rtc::scoped_refptr<StreamCollection> CreateStreamCollection( |
| 329 | int number_of_streams) { |
| 330 | rtc::scoped_refptr<StreamCollection> local_collection( |
| 331 | StreamCollection::Create()); |
| 332 | |
| 333 | for (int i = 0; i < number_of_streams; ++i) { |
| 334 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( |
| 335 | webrtc::MediaStream::Create(kStreams[i])); |
| 336 | |
| 337 | // Add a local audio track. |
| 338 | rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 339 | webrtc::AudioTrack::Create(kAudioTracks[i], nullptr)); |
| 340 | stream->AddTrack(audio_track); |
| 341 | |
| 342 | // Add a local video track. |
| 343 | rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 344 | webrtc::VideoTrack::Create(kVideoTracks[i], nullptr)); |
| 345 | stream->AddTrack(video_track); |
| 346 | |
| 347 | local_collection->AddStream(stream); |
| 348 | } |
| 349 | return local_collection; |
| 350 | } |
| 351 | |
| 352 | // Check equality of StreamCollections. |
| 353 | bool CompareStreamCollections(StreamCollectionInterface* s1, |
| 354 | StreamCollectionInterface* s2) { |
| 355 | if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) { |
| 356 | return false; |
| 357 | } |
| 358 | |
| 359 | for (size_t i = 0; i != s1->count(); ++i) { |
| 360 | if (s1->at(i)->label() != s2->at(i)->label()) { |
| 361 | return false; |
| 362 | } |
| 363 | webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks(); |
| 364 | webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks(); |
| 365 | webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks(); |
| 366 | webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks(); |
| 367 | |
| 368 | if (audio_tracks1.size() != audio_tracks2.size()) { |
| 369 | return false; |
| 370 | } |
| 371 | for (size_t j = 0; j != audio_tracks1.size(); ++j) { |
| 372 | if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) { |
| 373 | return false; |
| 374 | } |
| 375 | } |
| 376 | if (video_tracks1.size() != video_tracks2.size()) { |
| 377 | return false; |
| 378 | } |
| 379 | for (size_t j = 0; j != video_tracks1.size(); ++j) { |
| 380 | if (video_tracks1[j]->id() != video_tracks2[j]->id()) { |
| 381 | return false; |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | return true; |
| 386 | } |
| 387 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 388 | class MockPeerConnectionObserver : public PeerConnectionObserver { |
| 389 | public: |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 390 | MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 391 | ~MockPeerConnectionObserver() { |
| 392 | } |
| 393 | void SetPeerConnectionInterface(PeerConnectionInterface* pc) { |
| 394 | pc_ = pc; |
| 395 | if (pc) { |
| 396 | state_ = pc_->signaling_state(); |
| 397 | } |
| 398 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 399 | virtual void OnSignalingChange( |
| 400 | PeerConnectionInterface::SignalingState new_state) { |
| 401 | EXPECT_EQ(pc_->signaling_state(), new_state); |
| 402 | state_ = new_state; |
| 403 | } |
| 404 | // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange. |
| 405 | virtual void OnStateChange(StateType state_changed) { |
| 406 | if (pc_.get() == NULL) |
| 407 | return; |
| 408 | switch (state_changed) { |
| 409 | case kSignalingState: |
| 410 | // OnSignalingChange and OnStateChange(kSignalingState) should always |
| 411 | // be called approximately simultaneously. To ease testing, we require |
| 412 | // that they always be called in that order. This check verifies |
| 413 | // that OnSignalingChange has just been called. |
| 414 | EXPECT_EQ(pc_->signaling_state(), state_); |
| 415 | break; |
| 416 | case kIceState: |
| 417 | ADD_FAILURE(); |
| 418 | break; |
| 419 | default: |
| 420 | ADD_FAILURE(); |
| 421 | break; |
| 422 | } |
| 423 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 424 | |
| 425 | MediaStreamInterface* RemoteStream(const std::string& label) { |
| 426 | return remote_streams_->find(label); |
| 427 | } |
| 428 | StreamCollectionInterface* remote_streams() const { return remote_streams_; } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 429 | void OnAddStream(MediaStreamInterface* stream) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 430 | last_added_stream_ = stream; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 431 | remote_streams_->AddStream(stream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 432 | } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 433 | void OnRemoveStream(MediaStreamInterface* stream) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 434 | last_removed_stream_ = stream; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 435 | remote_streams_->RemoveStream(stream); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 436 | } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 437 | void OnRenegotiationNeeded() override { renegotiation_needed_ = true; } |
| 438 | void OnDataChannel(DataChannelInterface* data_channel) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 439 | last_datachannel_ = data_channel; |
| 440 | } |
| 441 | |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 442 | void OnIceConnectionChange( |
| 443 | PeerConnectionInterface::IceConnectionState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 444 | EXPECT_EQ(pc_->ice_connection_state(), new_state); |
| 445 | } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 446 | void OnIceGatheringChange( |
| 447 | PeerConnectionInterface::IceGatheringState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 448 | EXPECT_EQ(pc_->ice_gathering_state(), new_state); |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 449 | ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 450 | } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 451 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 452 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, |
| 453 | pc_->ice_gathering_state()); |
| 454 | |
| 455 | std::string sdp; |
| 456 | EXPECT_TRUE(candidate->ToString(&sdp)); |
| 457 | EXPECT_LT(0u, sdp.size()); |
| 458 | last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(), |
| 459 | candidate->sdp_mline_index(), sdp, NULL)); |
| 460 | EXPECT_TRUE(last_candidate_.get() != NULL); |
| 461 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 462 | |
| 463 | // Returns the label of the last added stream. |
| 464 | // Empty string if no stream have been added. |
| 465 | std::string GetLastAddedStreamLabel() { |
| 466 | if (last_added_stream_.get()) |
| 467 | return last_added_stream_->label(); |
| 468 | return ""; |
| 469 | } |
| 470 | std::string GetLastRemovedStreamLabel() { |
| 471 | if (last_removed_stream_.get()) |
| 472 | return last_removed_stream_->label(); |
| 473 | return ""; |
| 474 | } |
| 475 | |
| 476 | scoped_refptr<PeerConnectionInterface> pc_; |
| 477 | PeerConnectionInterface::SignalingState state_; |
| 478 | scoped_ptr<IceCandidateInterface> last_candidate_; |
| 479 | scoped_refptr<DataChannelInterface> last_datachannel_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 480 | rtc::scoped_refptr<StreamCollection> remote_streams_; |
| 481 | bool renegotiation_needed_ = false; |
| 482 | bool ice_complete_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 483 | |
| 484 | private: |
| 485 | scoped_refptr<MediaStreamInterface> last_added_stream_; |
| 486 | scoped_refptr<MediaStreamInterface> last_removed_stream_; |
| 487 | }; |
| 488 | |
| 489 | } // namespace |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 490 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 491 | class PeerConnectionInterfaceTest : public testing::Test { |
| 492 | protected: |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 493 | PeerConnectionInterfaceTest() { |
| 494 | #ifdef WEBRTC_ANDROID |
| 495 | webrtc::InitializeAndroidObjects(); |
| 496 | #endif |
| 497 | } |
| 498 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 499 | virtual void SetUp() { |
| 500 | pc_factory_ = webrtc::CreatePeerConnectionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 501 | rtc::Thread::Current(), rtc::Thread::Current(), NULL, NULL, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 502 | NULL); |
| 503 | ASSERT_TRUE(pc_factory_.get() != NULL); |
| 504 | } |
| 505 | |
| 506 | void CreatePeerConnection() { |
| 507 | CreatePeerConnection("", "", NULL); |
| 508 | } |
| 509 | |
| 510 | void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { |
| 511 | CreatePeerConnection("", "", constraints); |
| 512 | } |
| 513 | |
| 514 | void CreatePeerConnection(const std::string& uri, |
| 515 | const std::string& password, |
| 516 | webrtc::MediaConstraintsInterface* constraints) { |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 517 | PeerConnectionInterface::RTCConfiguration config; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 518 | PeerConnectionInterface::IceServer server; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 519 | if (!uri.empty()) { |
| 520 | server.uri = uri; |
| 521 | server.password = password; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 522 | config.servers.push_back(server); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 523 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 524 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 525 | rtc::scoped_ptr<cricket::FakePortAllocator> port_allocator( |
| 526 | new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr)); |
| 527 | port_allocator_ = port_allocator.get(); |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 528 | |
buildbot@webrtc.org | 61c1b8e | 2014-04-09 06:06:38 +0000 | [diff] [blame] | 529 | // DTLS does not work in a loopback call, so is disabled for most of the |
| 530 | // tests in this file. We only create a FakeIdentityService if the test |
| 531 | // explicitly sets the constraint. |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 532 | FakeConstraints default_constraints; |
| 533 | if (!constraints) { |
| 534 | constraints = &default_constraints; |
| 535 | |
| 536 | default_constraints.AddMandatory( |
| 537 | webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false); |
| 538 | } |
| 539 | |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 540 | scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store; |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 541 | bool dtls; |
| 542 | if (FindConstraint(constraints, |
| 543 | webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 544 | &dtls, |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 545 | nullptr) && dtls) { |
| 546 | dtls_identity_store.reset(new FakeDtlsIdentityStore()); |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 547 | } |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 548 | pc_ = pc_factory_->CreatePeerConnection( |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 549 | config, constraints, std::move(port_allocator), |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 550 | std::move(dtls_identity_store), &observer_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 551 | ASSERT_TRUE(pc_.get() != NULL); |
| 552 | observer_.SetPeerConnectionInterface(pc_.get()); |
| 553 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 554 | } |
| 555 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 556 | void CreatePeerConnectionExpectFail(const std::string& uri) { |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 557 | PeerConnectionInterface::RTCConfiguration config; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 558 | PeerConnectionInterface::IceServer server; |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 559 | server.uri = uri; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 560 | config.servers.push_back(server); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 561 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 562 | scoped_refptr<PeerConnectionInterface> pc; |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 563 | pc = pc_factory_->CreatePeerConnection(config, nullptr, nullptr, nullptr, |
| 564 | &observer_); |
| 565 | EXPECT_EQ(nullptr, pc); |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 566 | } |
| 567 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 568 | void CreatePeerConnectionWithDifferentConfigurations() { |
| 569 | CreatePeerConnection(kStunAddressOnly, "", NULL); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 570 | EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
| 571 | EXPECT_EQ(0u, port_allocator_->turn_servers().size()); |
| 572 | EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 573 | EXPECT_EQ(kDefaultStunPort, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 574 | port_allocator_->stun_servers().begin()->port()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 575 | |
deadbeef | 0a6c4ca | 2015-10-06 11:38:28 -0700 | [diff] [blame] | 576 | CreatePeerConnectionExpectFail(kStunInvalidPort); |
| 577 | CreatePeerConnectionExpectFail(kStunAddressPortAndMore1); |
| 578 | CreatePeerConnectionExpectFail(kStunAddressPortAndMore2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 579 | |
| 580 | CreatePeerConnection(kTurnIceServerUri, kTurnPassword, NULL); |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 581 | EXPECT_EQ(0u, port_allocator_->stun_servers().size()); |
| 582 | EXPECT_EQ(1u, port_allocator_->turn_servers().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 583 | EXPECT_EQ(kTurnUsername, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 584 | port_allocator_->turn_servers()[0].credentials.username); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 585 | EXPECT_EQ(kTurnPassword, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 586 | port_allocator_->turn_servers()[0].credentials.password); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 587 | EXPECT_EQ(kTurnHostname, |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 588 | port_allocator_->turn_servers()[0].ports[0].address.hostname()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | void ReleasePeerConnection() { |
| 592 | pc_ = NULL; |
| 593 | observer_.SetPeerConnectionInterface(NULL); |
| 594 | } |
| 595 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 596 | void AddVideoStream(const std::string& label) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 597 | // Create a local stream. |
| 598 | scoped_refptr<MediaStreamInterface> stream( |
| 599 | pc_factory_->CreateLocalMediaStream(label)); |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame^] | 600 | scoped_refptr<VideoTrackSourceInterface> video_source( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 601 | pc_factory_->CreateVideoSource(new cricket::FakeVideoCapturer(), NULL)); |
| 602 | scoped_refptr<VideoTrackInterface> video_track( |
| 603 | pc_factory_->CreateVideoTrack(label + "v0", video_source)); |
| 604 | stream->AddTrack(video_track.get()); |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 605 | EXPECT_TRUE(pc_->AddStream(stream)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 606 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 607 | observer_.renegotiation_needed_ = false; |
| 608 | } |
| 609 | |
| 610 | void AddVoiceStream(const std::string& label) { |
| 611 | // Create a local stream. |
| 612 | scoped_refptr<MediaStreamInterface> stream( |
| 613 | pc_factory_->CreateLocalMediaStream(label)); |
| 614 | scoped_refptr<AudioTrackInterface> audio_track( |
| 615 | pc_factory_->CreateAudioTrack(label + "a0", NULL)); |
| 616 | stream->AddTrack(audio_track.get()); |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 617 | EXPECT_TRUE(pc_->AddStream(stream)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 618 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 619 | observer_.renegotiation_needed_ = false; |
| 620 | } |
| 621 | |
| 622 | void AddAudioVideoStream(const std::string& stream_label, |
| 623 | const std::string& audio_track_label, |
| 624 | const std::string& video_track_label) { |
| 625 | // Create a local stream. |
| 626 | scoped_refptr<MediaStreamInterface> stream( |
| 627 | pc_factory_->CreateLocalMediaStream(stream_label)); |
| 628 | scoped_refptr<AudioTrackInterface> audio_track( |
| 629 | pc_factory_->CreateAudioTrack( |
| 630 | audio_track_label, static_cast<AudioSourceInterface*>(NULL))); |
| 631 | stream->AddTrack(audio_track.get()); |
| 632 | scoped_refptr<VideoTrackInterface> video_track( |
| 633 | pc_factory_->CreateVideoTrack(video_track_label, NULL)); |
| 634 | stream->AddTrack(video_track.get()); |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 635 | EXPECT_TRUE(pc_->AddStream(stream)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 636 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 637 | observer_.renegotiation_needed_ = false; |
| 638 | } |
| 639 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 640 | bool DoCreateOfferAnswer(SessionDescriptionInterface** desc, |
| 641 | bool offer, |
| 642 | MediaConstraintsInterface* constraints) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 643 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> |
| 644 | observer(new rtc::RefCountedObject< |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 645 | MockCreateSessionDescriptionObserver>()); |
| 646 | if (offer) { |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 647 | pc_->CreateOffer(observer, constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 648 | } else { |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 649 | pc_->CreateAnswer(observer, constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 650 | } |
| 651 | EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
| 652 | *desc = observer->release_desc(); |
| 653 | return observer->result(); |
| 654 | } |
| 655 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 656 | bool DoCreateOffer(SessionDescriptionInterface** desc, |
| 657 | MediaConstraintsInterface* constraints) { |
| 658 | return DoCreateOfferAnswer(desc, true, constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 659 | } |
| 660 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 661 | bool DoCreateAnswer(SessionDescriptionInterface** desc, |
| 662 | MediaConstraintsInterface* constraints) { |
| 663 | return DoCreateOfferAnswer(desc, false, constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 667 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> |
| 668 | observer(new rtc::RefCountedObject< |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 669 | MockSetSessionDescriptionObserver>()); |
| 670 | if (local) { |
| 671 | pc_->SetLocalDescription(observer, desc); |
| 672 | } else { |
| 673 | pc_->SetRemoteDescription(observer, desc); |
| 674 | } |
| 675 | EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
| 676 | return observer->result(); |
| 677 | } |
| 678 | |
| 679 | bool DoSetLocalDescription(SessionDescriptionInterface* desc) { |
| 680 | return DoSetSessionDescription(desc, true); |
| 681 | } |
| 682 | |
| 683 | bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { |
| 684 | return DoSetSessionDescription(desc, false); |
| 685 | } |
| 686 | |
| 687 | // Calls PeerConnection::GetStats and check the return value. |
| 688 | // It does not verify the values in the StatReports since a RTCP packet might |
| 689 | // be required. |
| 690 | bool DoGetStats(MediaStreamTrackInterface* track) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 691 | rtc::scoped_refptr<MockStatsObserver> observer( |
| 692 | new rtc::RefCountedObject<MockStatsObserver>()); |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 693 | if (!pc_->GetStats( |
| 694 | observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 695 | return false; |
| 696 | EXPECT_TRUE_WAIT(observer->called(), kTimeout); |
| 697 | return observer->called(); |
| 698 | } |
| 699 | |
| 700 | void InitiateCall() { |
| 701 | CreatePeerConnection(); |
| 702 | // Create a local stream with audio&video tracks. |
| 703 | AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); |
| 704 | CreateOfferReceiveAnswer(); |
| 705 | } |
| 706 | |
| 707 | // Verify that RTP Header extensions has been negotiated for audio and video. |
| 708 | void VerifyRemoteRtpHeaderExtensions() { |
| 709 | const cricket::MediaContentDescription* desc = |
| 710 | cricket::GetFirstAudioContentDescription( |
| 711 | pc_->remote_description()->description()); |
| 712 | ASSERT_TRUE(desc != NULL); |
| 713 | EXPECT_GT(desc->rtp_header_extensions().size(), 0u); |
| 714 | |
| 715 | desc = cricket::GetFirstVideoContentDescription( |
| 716 | pc_->remote_description()->description()); |
| 717 | ASSERT_TRUE(desc != NULL); |
| 718 | EXPECT_GT(desc->rtp_header_extensions().size(), 0u); |
| 719 | } |
| 720 | |
| 721 | void CreateOfferAsRemoteDescription() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 722 | rtc::scoped_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 723 | ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 724 | std::string sdp; |
| 725 | EXPECT_TRUE(offer->ToString(&sdp)); |
| 726 | SessionDescriptionInterface* remote_offer = |
| 727 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, |
| 728 | sdp, NULL); |
| 729 | EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); |
| 730 | EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
| 731 | } |
| 732 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 733 | void CreateAndSetRemoteOffer(const std::string& sdp) { |
| 734 | SessionDescriptionInterface* remote_offer = |
| 735 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, |
| 736 | sdp, nullptr); |
| 737 | EXPECT_TRUE(DoSetRemoteDescription(remote_offer)); |
| 738 | EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_); |
| 739 | } |
| 740 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 741 | void CreateAnswerAsLocalDescription() { |
| 742 | scoped_ptr<SessionDescriptionInterface> answer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 743 | ASSERT_TRUE(DoCreateAnswer(answer.use(), nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 744 | |
| 745 | // TODO(perkj): Currently SetLocalDescription fails if any parameters in an |
| 746 | // audio codec change, even if the parameter has nothing to do with |
| 747 | // receiving. Not all parameters are serialized to SDP. |
| 748 | // Since CreatePrAnswerAsLocalDescription serialize/deserialize |
| 749 | // the SessionDescription, it is necessary to do that here to in order to |
| 750 | // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. |
| 751 | // https://code.google.com/p/webrtc/issues/detail?id=1356 |
| 752 | std::string sdp; |
| 753 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 754 | SessionDescriptionInterface* new_answer = |
| 755 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, |
| 756 | sdp, NULL); |
| 757 | EXPECT_TRUE(DoSetLocalDescription(new_answer)); |
| 758 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 759 | } |
| 760 | |
| 761 | void CreatePrAnswerAsLocalDescription() { |
| 762 | scoped_ptr<SessionDescriptionInterface> answer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 763 | ASSERT_TRUE(DoCreateAnswer(answer.use(), nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 764 | |
| 765 | std::string sdp; |
| 766 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 767 | SessionDescriptionInterface* pr_answer = |
| 768 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kPrAnswer, |
| 769 | sdp, NULL); |
| 770 | EXPECT_TRUE(DoSetLocalDescription(pr_answer)); |
| 771 | EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_); |
| 772 | } |
| 773 | |
| 774 | void CreateOfferReceiveAnswer() { |
| 775 | CreateOfferAsLocalDescription(); |
| 776 | std::string sdp; |
| 777 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 778 | CreateAnswerAsRemoteDescription(sdp); |
| 779 | } |
| 780 | |
| 781 | void CreateOfferAsLocalDescription() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 782 | rtc::scoped_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 783 | ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 784 | // TODO(perkj): Currently SetLocalDescription fails if any parameters in an |
| 785 | // audio codec change, even if the parameter has nothing to do with |
| 786 | // receiving. Not all parameters are serialized to SDP. |
| 787 | // Since CreatePrAnswerAsLocalDescription serialize/deserialize |
| 788 | // the SessionDescription, it is necessary to do that here to in order to |
| 789 | // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass. |
| 790 | // https://code.google.com/p/webrtc/issues/detail?id=1356 |
| 791 | std::string sdp; |
| 792 | EXPECT_TRUE(offer->ToString(&sdp)); |
| 793 | SessionDescriptionInterface* new_offer = |
| 794 | webrtc::CreateSessionDescription( |
| 795 | SessionDescriptionInterface::kOffer, |
| 796 | sdp, NULL); |
| 797 | |
| 798 | EXPECT_TRUE(DoSetLocalDescription(new_offer)); |
| 799 | EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_); |
mallinath@webrtc.org | 68cbd01 | 2014-01-22 00:16:46 +0000 | [diff] [blame] | 800 | // Wait for the ice_complete message, so that SDP will have candidates. |
| 801 | EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 802 | } |
| 803 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 804 | void CreateAnswerAsRemoteDescription(const std::string& sdp) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 805 | webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription( |
| 806 | SessionDescriptionInterface::kAnswer); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 807 | EXPECT_TRUE(answer->Initialize(sdp, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 808 | EXPECT_TRUE(DoSetRemoteDescription(answer)); |
| 809 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 810 | } |
| 811 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 812 | void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 813 | webrtc::JsepSessionDescription* pr_answer = |
| 814 | new webrtc::JsepSessionDescription( |
| 815 | SessionDescriptionInterface::kPrAnswer); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 816 | EXPECT_TRUE(pr_answer->Initialize(sdp, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 817 | EXPECT_TRUE(DoSetRemoteDescription(pr_answer)); |
| 818 | EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_); |
| 819 | webrtc::JsepSessionDescription* answer = |
| 820 | new webrtc::JsepSessionDescription( |
| 821 | SessionDescriptionInterface::kAnswer); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 822 | EXPECT_TRUE(answer->Initialize(sdp, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 823 | EXPECT_TRUE(DoSetRemoteDescription(answer)); |
| 824 | EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_); |
| 825 | } |
| 826 | |
| 827 | // Help function used for waiting until a the last signaled remote stream has |
| 828 | // the same label as |stream_label|. In a few of the tests in this file we |
| 829 | // answer with the same session description as we offer and thus we can |
| 830 | // check if OnAddStream have been called with the same stream as we offer to |
| 831 | // send. |
| 832 | void WaitAndVerifyOnAddStream(const std::string& stream_label) { |
| 833 | EXPECT_EQ_WAIT(stream_label, observer_.GetLastAddedStreamLabel(), kTimeout); |
| 834 | } |
| 835 | |
| 836 | // Creates an offer and applies it as a local session description. |
| 837 | // Creates an answer with the same SDP an the offer but removes all lines |
| 838 | // that start with a:ssrc" |
| 839 | void CreateOfferReceiveAnswerWithoutSsrc() { |
| 840 | CreateOfferAsLocalDescription(); |
| 841 | std::string sdp; |
| 842 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 843 | SetSsrcToZero(&sdp); |
| 844 | CreateAnswerAsRemoteDescription(sdp); |
| 845 | } |
| 846 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 847 | // This function creates a MediaStream with label kStreams[0] and |
| 848 | // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the |
| 849 | // corresponding SessionDescriptionInterface. The SessionDescriptionInterface |
| 850 | // is returned in |desc| and the MediaStream is stored in |
| 851 | // |reference_collection_| |
| 852 | void CreateSessionDescriptionAndReference( |
| 853 | size_t number_of_audio_tracks, |
| 854 | size_t number_of_video_tracks, |
| 855 | SessionDescriptionInterface** desc) { |
| 856 | ASSERT_TRUE(desc != nullptr); |
| 857 | ASSERT_LE(number_of_audio_tracks, 2u); |
| 858 | ASSERT_LE(number_of_video_tracks, 2u); |
| 859 | |
| 860 | reference_collection_ = StreamCollection::Create(); |
| 861 | std::string sdp_ms1 = std::string(kSdpStringInit); |
| 862 | |
| 863 | std::string mediastream_label = kStreams[0]; |
| 864 | |
| 865 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream( |
| 866 | webrtc::MediaStream::Create(mediastream_label)); |
| 867 | reference_collection_->AddStream(stream); |
| 868 | |
| 869 | if (number_of_audio_tracks > 0) { |
| 870 | sdp_ms1 += std::string(kSdpStringAudio); |
| 871 | sdp_ms1 += std::string(kSdpStringMs1Audio0); |
| 872 | AddAudioTrack(kAudioTracks[0], stream); |
| 873 | } |
| 874 | if (number_of_audio_tracks > 1) { |
| 875 | sdp_ms1 += kSdpStringMs1Audio1; |
| 876 | AddAudioTrack(kAudioTracks[1], stream); |
| 877 | } |
| 878 | |
| 879 | if (number_of_video_tracks > 0) { |
| 880 | sdp_ms1 += std::string(kSdpStringVideo); |
| 881 | sdp_ms1 += std::string(kSdpStringMs1Video0); |
| 882 | AddVideoTrack(kVideoTracks[0], stream); |
| 883 | } |
| 884 | if (number_of_video_tracks > 1) { |
| 885 | sdp_ms1 += kSdpStringMs1Video1; |
| 886 | AddVideoTrack(kVideoTracks[1], stream); |
| 887 | } |
| 888 | |
| 889 | *desc = webrtc::CreateSessionDescription( |
| 890 | SessionDescriptionInterface::kOffer, sdp_ms1, nullptr); |
| 891 | } |
| 892 | |
| 893 | void AddAudioTrack(const std::string& track_id, |
| 894 | MediaStreamInterface* stream) { |
| 895 | rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
| 896 | webrtc::AudioTrack::Create(track_id, nullptr)); |
| 897 | ASSERT_TRUE(stream->AddTrack(audio_track)); |
| 898 | } |
| 899 | |
| 900 | void AddVideoTrack(const std::string& track_id, |
| 901 | MediaStreamInterface* stream) { |
| 902 | rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
| 903 | webrtc::VideoTrack::Create(track_id, nullptr)); |
| 904 | ASSERT_TRUE(stream->AddTrack(video_track)); |
| 905 | } |
| 906 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 907 | cricket::FakePortAllocator* port_allocator_ = nullptr; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 908 | scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
| 909 | scoped_refptr<PeerConnectionInterface> pc_; |
| 910 | MockPeerConnectionObserver observer_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 911 | rtc::scoped_refptr<StreamCollection> reference_collection_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 912 | }; |
| 913 | |
| 914 | TEST_F(PeerConnectionInterfaceTest, |
| 915 | CreatePeerConnectionWithDifferentConfigurations) { |
| 916 | CreatePeerConnectionWithDifferentConfigurations(); |
| 917 | } |
| 918 | |
| 919 | TEST_F(PeerConnectionInterfaceTest, AddStreams) { |
| 920 | CreatePeerConnection(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 921 | AddVideoStream(kStreamLabel1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 922 | AddVoiceStream(kStreamLabel2); |
| 923 | ASSERT_EQ(2u, pc_->local_streams()->count()); |
| 924 | |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 925 | // Test we can add multiple local streams to one peerconnection. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 926 | scoped_refptr<MediaStreamInterface> stream( |
| 927 | pc_factory_->CreateLocalMediaStream(kStreamLabel3)); |
| 928 | scoped_refptr<AudioTrackInterface> audio_track( |
| 929 | pc_factory_->CreateAudioTrack( |
| 930 | kStreamLabel3, static_cast<AudioSourceInterface*>(NULL))); |
| 931 | stream->AddTrack(audio_track.get()); |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 932 | EXPECT_TRUE(pc_->AddStream(stream)); |
wu@webrtc.org | 9dba525 | 2013-08-05 20:36:57 +0000 | [diff] [blame] | 933 | EXPECT_EQ(3u, pc_->local_streams()->count()); |
| 934 | |
| 935 | // Remove the third stream. |
| 936 | pc_->RemoveStream(pc_->local_streams()->at(2)); |
| 937 | EXPECT_EQ(2u, pc_->local_streams()->count()); |
| 938 | |
| 939 | // Remove the second stream. |
| 940 | pc_->RemoveStream(pc_->local_streams()->at(1)); |
| 941 | EXPECT_EQ(1u, pc_->local_streams()->count()); |
| 942 | |
| 943 | // Remove the first stream. |
| 944 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 945 | EXPECT_EQ(0u, pc_->local_streams()->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 946 | } |
| 947 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 948 | // Test that the created offer includes streams we added. |
| 949 | TEST_F(PeerConnectionInterfaceTest, AddedStreamsPresentInOffer) { |
| 950 | CreatePeerConnection(); |
| 951 | AddAudioVideoStream(kStreamLabel1, "audio_track", "video_track"); |
| 952 | scoped_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 953 | ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 954 | |
| 955 | const cricket::ContentInfo* audio_content = |
| 956 | cricket::GetFirstAudioContent(offer->description()); |
| 957 | const cricket::AudioContentDescription* audio_desc = |
| 958 | static_cast<const cricket::AudioContentDescription*>( |
| 959 | audio_content->description); |
| 960 | EXPECT_TRUE( |
| 961 | ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); |
| 962 | |
| 963 | const cricket::ContentInfo* video_content = |
| 964 | cricket::GetFirstVideoContent(offer->description()); |
| 965 | const cricket::VideoContentDescription* video_desc = |
| 966 | static_cast<const cricket::VideoContentDescription*>( |
| 967 | video_content->description); |
| 968 | EXPECT_TRUE( |
| 969 | ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); |
| 970 | |
| 971 | // Add another stream and ensure the offer includes both the old and new |
| 972 | // streams. |
| 973 | AddAudioVideoStream(kStreamLabel2, "audio_track2", "video_track2"); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 974 | ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 975 | |
| 976 | audio_content = cricket::GetFirstAudioContent(offer->description()); |
| 977 | audio_desc = static_cast<const cricket::AudioContentDescription*>( |
| 978 | audio_content->description); |
| 979 | EXPECT_TRUE( |
| 980 | ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); |
| 981 | EXPECT_TRUE( |
| 982 | ContainsTrack(audio_desc->streams(), kStreamLabel2, "audio_track2")); |
| 983 | |
| 984 | video_content = cricket::GetFirstVideoContent(offer->description()); |
| 985 | video_desc = static_cast<const cricket::VideoContentDescription*>( |
| 986 | video_content->description); |
| 987 | EXPECT_TRUE( |
| 988 | ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); |
| 989 | EXPECT_TRUE( |
| 990 | ContainsTrack(video_desc->streams(), kStreamLabel2, "video_track2")); |
| 991 | } |
| 992 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 993 | TEST_F(PeerConnectionInterfaceTest, RemoveStream) { |
| 994 | CreatePeerConnection(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 995 | AddVideoStream(kStreamLabel1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 996 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
| 997 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 998 | EXPECT_EQ(0u, pc_->local_streams()->count()); |
| 999 | } |
| 1000 | |
deadbeef | e1f9d83 | 2016-01-14 15:35:42 -0800 | [diff] [blame] | 1001 | // Test for AddTrack and RemoveTrack methods. |
| 1002 | // Tests that the created offer includes tracks we added, |
| 1003 | // and that the RtpSenders are created correctly. |
| 1004 | // Also tests that RemoveTrack removes the tracks from subsequent offers. |
| 1005 | TEST_F(PeerConnectionInterfaceTest, AddTrackRemoveTrack) { |
| 1006 | CreatePeerConnection(); |
| 1007 | // Create a dummy stream, so tracks share a stream label. |
| 1008 | scoped_refptr<MediaStreamInterface> stream( |
| 1009 | pc_factory_->CreateLocalMediaStream(kStreamLabel1)); |
| 1010 | std::vector<MediaStreamInterface*> stream_list; |
| 1011 | stream_list.push_back(stream.get()); |
| 1012 | scoped_refptr<AudioTrackInterface> audio_track( |
| 1013 | pc_factory_->CreateAudioTrack("audio_track", nullptr)); |
| 1014 | scoped_refptr<VideoTrackInterface> video_track( |
| 1015 | pc_factory_->CreateVideoTrack("video_track", nullptr)); |
| 1016 | auto audio_sender = pc_->AddTrack(audio_track, stream_list); |
| 1017 | auto video_sender = pc_->AddTrack(video_track, stream_list); |
| 1018 | EXPECT_EQ(kStreamLabel1, audio_sender->stream_id()); |
| 1019 | EXPECT_EQ("audio_track", audio_sender->id()); |
| 1020 | EXPECT_EQ(audio_track, audio_sender->track()); |
| 1021 | EXPECT_EQ(kStreamLabel1, video_sender->stream_id()); |
| 1022 | EXPECT_EQ("video_track", video_sender->id()); |
| 1023 | EXPECT_EQ(video_track, video_sender->track()); |
| 1024 | |
| 1025 | // Now create an offer and check for the senders. |
| 1026 | scoped_ptr<SessionDescriptionInterface> offer; |
| 1027 | ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr)); |
| 1028 | |
| 1029 | const cricket::ContentInfo* audio_content = |
| 1030 | cricket::GetFirstAudioContent(offer->description()); |
| 1031 | const cricket::AudioContentDescription* audio_desc = |
| 1032 | static_cast<const cricket::AudioContentDescription*>( |
| 1033 | audio_content->description); |
| 1034 | EXPECT_TRUE( |
| 1035 | ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); |
| 1036 | |
| 1037 | const cricket::ContentInfo* video_content = |
| 1038 | cricket::GetFirstVideoContent(offer->description()); |
| 1039 | const cricket::VideoContentDescription* video_desc = |
| 1040 | static_cast<const cricket::VideoContentDescription*>( |
| 1041 | video_content->description); |
| 1042 | EXPECT_TRUE( |
| 1043 | ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); |
| 1044 | |
| 1045 | EXPECT_TRUE(DoSetLocalDescription(offer.release())); |
| 1046 | |
| 1047 | // Now try removing the tracks. |
| 1048 | EXPECT_TRUE(pc_->RemoveTrack(audio_sender)); |
| 1049 | EXPECT_TRUE(pc_->RemoveTrack(video_sender)); |
| 1050 | |
| 1051 | // Create a new offer and ensure it doesn't contain the removed senders. |
| 1052 | ASSERT_TRUE(DoCreateOffer(offer.accept(), nullptr)); |
| 1053 | |
| 1054 | audio_content = cricket::GetFirstAudioContent(offer->description()); |
| 1055 | audio_desc = static_cast<const cricket::AudioContentDescription*>( |
| 1056 | audio_content->description); |
| 1057 | EXPECT_FALSE( |
| 1058 | ContainsTrack(audio_desc->streams(), kStreamLabel1, "audio_track")); |
| 1059 | |
| 1060 | video_content = cricket::GetFirstVideoContent(offer->description()); |
| 1061 | video_desc = static_cast<const cricket::VideoContentDescription*>( |
| 1062 | video_content->description); |
| 1063 | EXPECT_FALSE( |
| 1064 | ContainsTrack(video_desc->streams(), kStreamLabel1, "video_track")); |
| 1065 | |
| 1066 | EXPECT_TRUE(DoSetLocalDescription(offer.release())); |
| 1067 | |
| 1068 | // Calling RemoveTrack on a sender no longer attached to a PeerConnection |
| 1069 | // should return false. |
| 1070 | EXPECT_FALSE(pc_->RemoveTrack(audio_sender)); |
| 1071 | EXPECT_FALSE(pc_->RemoveTrack(video_sender)); |
| 1072 | } |
| 1073 | |
| 1074 | // Test creating senders without a stream specified, |
| 1075 | // expecting a random stream ID to be generated. |
| 1076 | TEST_F(PeerConnectionInterfaceTest, AddTrackWithoutStream) { |
| 1077 | CreatePeerConnection(); |
| 1078 | // Create a dummy stream, so tracks share a stream label. |
| 1079 | scoped_refptr<AudioTrackInterface> audio_track( |
| 1080 | pc_factory_->CreateAudioTrack("audio_track", nullptr)); |
| 1081 | scoped_refptr<VideoTrackInterface> video_track( |
| 1082 | pc_factory_->CreateVideoTrack("video_track", nullptr)); |
| 1083 | auto audio_sender = |
| 1084 | pc_->AddTrack(audio_track, std::vector<MediaStreamInterface*>()); |
| 1085 | auto video_sender = |
| 1086 | pc_->AddTrack(video_track, std::vector<MediaStreamInterface*>()); |
| 1087 | EXPECT_EQ("audio_track", audio_sender->id()); |
| 1088 | EXPECT_EQ(audio_track, audio_sender->track()); |
| 1089 | EXPECT_EQ("video_track", video_sender->id()); |
| 1090 | EXPECT_EQ(video_track, video_sender->track()); |
| 1091 | // If the ID is truly a random GUID, it should be infinitely unlikely they |
| 1092 | // will be the same. |
| 1093 | EXPECT_NE(video_sender->stream_id(), audio_sender->stream_id()); |
| 1094 | } |
| 1095 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1096 | TEST_F(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) { |
| 1097 | InitiateCall(); |
| 1098 | WaitAndVerifyOnAddStream(kStreamLabel1); |
| 1099 | VerifyRemoteRtpHeaderExtensions(); |
| 1100 | } |
| 1101 | |
| 1102 | TEST_F(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) { |
| 1103 | CreatePeerConnection(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1104 | AddVideoStream(kStreamLabel1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1105 | CreateOfferAsLocalDescription(); |
| 1106 | std::string offer; |
| 1107 | EXPECT_TRUE(pc_->local_description()->ToString(&offer)); |
| 1108 | CreatePrAnswerAndAnswerAsRemoteDescription(offer); |
| 1109 | WaitAndVerifyOnAddStream(kStreamLabel1); |
| 1110 | } |
| 1111 | |
| 1112 | TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) { |
| 1113 | CreatePeerConnection(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1114 | AddVideoStream(kStreamLabel1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1115 | |
| 1116 | CreateOfferAsRemoteDescription(); |
| 1117 | CreateAnswerAsLocalDescription(); |
| 1118 | |
| 1119 | WaitAndVerifyOnAddStream(kStreamLabel1); |
| 1120 | } |
| 1121 | |
| 1122 | TEST_F(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) { |
| 1123 | CreatePeerConnection(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1124 | AddVideoStream(kStreamLabel1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1125 | |
| 1126 | CreateOfferAsRemoteDescription(); |
| 1127 | CreatePrAnswerAsLocalDescription(); |
| 1128 | CreateAnswerAsLocalDescription(); |
| 1129 | |
| 1130 | WaitAndVerifyOnAddStream(kStreamLabel1); |
| 1131 | } |
| 1132 | |
| 1133 | TEST_F(PeerConnectionInterfaceTest, Renegotiate) { |
| 1134 | InitiateCall(); |
| 1135 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 1136 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1137 | CreateOfferReceiveAnswer(); |
| 1138 | EXPECT_EQ(0u, pc_->remote_streams()->count()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1139 | AddVideoStream(kStreamLabel1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1140 | CreateOfferReceiveAnswer(); |
| 1141 | } |
| 1142 | |
| 1143 | // Tests that after negotiating an audio only call, the respondent can perform a |
| 1144 | // renegotiation that removes the audio stream. |
| 1145 | TEST_F(PeerConnectionInterfaceTest, RenegotiateAudioOnly) { |
| 1146 | CreatePeerConnection(); |
| 1147 | AddVoiceStream(kStreamLabel1); |
| 1148 | CreateOfferAsRemoteDescription(); |
| 1149 | CreateAnswerAsLocalDescription(); |
| 1150 | |
| 1151 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 1152 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1153 | CreateOfferReceiveAnswer(); |
| 1154 | EXPECT_EQ(0u, pc_->remote_streams()->count()); |
| 1155 | } |
| 1156 | |
| 1157 | // Test that candidates are generated and that we can parse our own candidates. |
| 1158 | TEST_F(PeerConnectionInterfaceTest, IceCandidates) { |
| 1159 | CreatePeerConnection(); |
| 1160 | |
| 1161 | EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate_.get())); |
| 1162 | // SetRemoteDescription takes ownership of offer. |
| 1163 | SessionDescriptionInterface* offer = NULL; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1164 | AddVideoStream(kStreamLabel1); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1165 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1166 | EXPECT_TRUE(DoSetRemoteDescription(offer)); |
| 1167 | |
| 1168 | // SetLocalDescription takes ownership of answer. |
| 1169 | SessionDescriptionInterface* answer = NULL; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1170 | EXPECT_TRUE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1171 | EXPECT_TRUE(DoSetLocalDescription(answer)); |
| 1172 | |
| 1173 | EXPECT_TRUE_WAIT(observer_.last_candidate_.get() != NULL, kTimeout); |
| 1174 | EXPECT_TRUE_WAIT(observer_.ice_complete_, kTimeout); |
| 1175 | |
| 1176 | EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate_.get())); |
| 1177 | } |
| 1178 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1179 | // Test that CreateOffer and CreateAnswer will fail if the track labels are |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1180 | // not unique. |
| 1181 | TEST_F(PeerConnectionInterfaceTest, CreateOfferAnswerWithInvalidStream) { |
| 1182 | CreatePeerConnection(); |
| 1183 | // Create a regular offer for the CreateAnswer test later. |
| 1184 | SessionDescriptionInterface* offer = NULL; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1185 | EXPECT_TRUE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1186 | EXPECT_TRUE(offer != NULL); |
| 1187 | delete offer; |
| 1188 | offer = NULL; |
| 1189 | |
| 1190 | // Create a local stream with audio&video tracks having same label. |
| 1191 | AddAudioVideoStream(kStreamLabel1, "track_label", "track_label"); |
| 1192 | |
| 1193 | // Test CreateOffer |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1194 | EXPECT_FALSE(DoCreateOffer(&offer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1195 | |
| 1196 | // Test CreateAnswer |
| 1197 | SessionDescriptionInterface* answer = NULL; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1198 | EXPECT_FALSE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | // Test that we will get different SSRCs for each tracks in the offer and answer |
| 1202 | // we created. |
| 1203 | TEST_F(PeerConnectionInterfaceTest, SsrcInOfferAnswer) { |
| 1204 | CreatePeerConnection(); |
| 1205 | // Create a local stream with audio&video tracks having different labels. |
| 1206 | AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); |
| 1207 | |
| 1208 | // Test CreateOffer |
| 1209 | scoped_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1210 | ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1211 | int audio_ssrc = 0; |
| 1212 | int video_ssrc = 0; |
| 1213 | EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(offer->description()), |
| 1214 | &audio_ssrc)); |
| 1215 | EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(offer->description()), |
| 1216 | &video_ssrc)); |
| 1217 | EXPECT_NE(audio_ssrc, video_ssrc); |
| 1218 | |
| 1219 | // Test CreateAnswer |
| 1220 | EXPECT_TRUE(DoSetRemoteDescription(offer.release())); |
| 1221 | scoped_ptr<SessionDescriptionInterface> answer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1222 | ASSERT_TRUE(DoCreateAnswer(answer.use(), nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1223 | audio_ssrc = 0; |
| 1224 | video_ssrc = 0; |
| 1225 | EXPECT_TRUE(GetFirstSsrc(GetFirstAudioContent(answer->description()), |
| 1226 | &audio_ssrc)); |
| 1227 | EXPECT_TRUE(GetFirstSsrc(GetFirstVideoContent(answer->description()), |
| 1228 | &video_ssrc)); |
| 1229 | EXPECT_NE(audio_ssrc, video_ssrc); |
| 1230 | } |
| 1231 | |
deadbeef | eb45981 | 2015-12-15 19:24:43 -0800 | [diff] [blame] | 1232 | // Test that it's possible to call AddTrack on a MediaStream after adding |
| 1233 | // the stream to a PeerConnection. |
| 1234 | // TODO(deadbeef): Remove this test once this behavior is no longer supported. |
| 1235 | TEST_F(PeerConnectionInterfaceTest, AddTrackAfterAddStream) { |
| 1236 | CreatePeerConnection(); |
| 1237 | // Create audio stream and add to PeerConnection. |
| 1238 | AddVoiceStream(kStreamLabel1); |
| 1239 | MediaStreamInterface* stream = pc_->local_streams()->at(0); |
| 1240 | |
| 1241 | // Add video track to the audio-only stream. |
| 1242 | scoped_refptr<VideoTrackInterface> video_track( |
| 1243 | pc_factory_->CreateVideoTrack("video_label", nullptr)); |
| 1244 | stream->AddTrack(video_track.get()); |
| 1245 | |
| 1246 | scoped_ptr<SessionDescriptionInterface> offer; |
| 1247 | ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr)); |
| 1248 | |
| 1249 | const cricket::MediaContentDescription* video_desc = |
| 1250 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 1251 | EXPECT_TRUE(video_desc != nullptr); |
| 1252 | } |
| 1253 | |
| 1254 | // Test that it's possible to call RemoveTrack on a MediaStream after adding |
| 1255 | // the stream to a PeerConnection. |
| 1256 | // TODO(deadbeef): Remove this test once this behavior is no longer supported. |
| 1257 | TEST_F(PeerConnectionInterfaceTest, RemoveTrackAfterAddStream) { |
| 1258 | CreatePeerConnection(); |
| 1259 | // Create audio/video stream and add to PeerConnection. |
| 1260 | AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); |
| 1261 | MediaStreamInterface* stream = pc_->local_streams()->at(0); |
| 1262 | |
| 1263 | // Remove the video track. |
| 1264 | stream->RemoveTrack(stream->GetVideoTracks()[0]); |
| 1265 | |
| 1266 | scoped_ptr<SessionDescriptionInterface> offer; |
| 1267 | ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr)); |
| 1268 | |
| 1269 | const cricket::MediaContentDescription* video_desc = |
| 1270 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 1271 | EXPECT_TRUE(video_desc == nullptr); |
| 1272 | } |
| 1273 | |
deadbeef | bd7d8f7 | 2015-12-18 16:58:44 -0800 | [diff] [blame] | 1274 | // Test creating a sender with a stream ID, and ensure the ID is populated |
| 1275 | // in the offer. |
| 1276 | TEST_F(PeerConnectionInterfaceTest, CreateSenderWithStream) { |
| 1277 | CreatePeerConnection(); |
| 1278 | pc_->CreateSender("video", kStreamLabel1); |
| 1279 | |
| 1280 | scoped_ptr<SessionDescriptionInterface> offer; |
| 1281 | ASSERT_TRUE(DoCreateOffer(offer.use(), nullptr)); |
| 1282 | |
| 1283 | const cricket::MediaContentDescription* video_desc = |
| 1284 | cricket::GetFirstVideoContentDescription(offer->description()); |
| 1285 | ASSERT_TRUE(video_desc != nullptr); |
| 1286 | ASSERT_EQ(1u, video_desc->streams().size()); |
| 1287 | EXPECT_EQ(kStreamLabel1, video_desc->streams()[0].sync_label); |
| 1288 | } |
| 1289 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1290 | // Test that we can specify a certain track that we want statistics about. |
| 1291 | TEST_F(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) { |
| 1292 | InitiateCall(); |
| 1293 | ASSERT_LT(0u, pc_->remote_streams()->count()); |
| 1294 | ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetAudioTracks().size()); |
| 1295 | scoped_refptr<MediaStreamTrackInterface> remote_audio = |
| 1296 | pc_->remote_streams()->at(0)->GetAudioTracks()[0]; |
| 1297 | EXPECT_TRUE(DoGetStats(remote_audio)); |
| 1298 | |
| 1299 | // Remove the stream. Since we are sending to our selves the local |
| 1300 | // and the remote stream is the same. |
| 1301 | pc_->RemoveStream(pc_->local_streams()->at(0)); |
| 1302 | // Do a re-negotiation. |
| 1303 | CreateOfferReceiveAnswer(); |
| 1304 | |
| 1305 | ASSERT_EQ(0u, pc_->remote_streams()->count()); |
| 1306 | |
| 1307 | // Test that we still can get statistics for the old track. Even if it is not |
| 1308 | // sent any longer. |
| 1309 | EXPECT_TRUE(DoGetStats(remote_audio)); |
| 1310 | } |
| 1311 | |
| 1312 | // Test that we can get stats on a video track. |
| 1313 | TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) { |
| 1314 | InitiateCall(); |
| 1315 | ASSERT_LT(0u, pc_->remote_streams()->count()); |
| 1316 | ASSERT_LT(0u, pc_->remote_streams()->at(0)->GetVideoTracks().size()); |
| 1317 | scoped_refptr<MediaStreamTrackInterface> remote_video = |
| 1318 | pc_->remote_streams()->at(0)->GetVideoTracks()[0]; |
| 1319 | EXPECT_TRUE(DoGetStats(remote_video)); |
| 1320 | } |
| 1321 | |
| 1322 | // Test that we don't get statistics for an invalid track. |
tommi@webrtc.org | 908f57e | 2014-07-21 11:44:39 +0000 | [diff] [blame] | 1323 | // TODO(tommi): Fix this test. DoGetStats will return true |
| 1324 | // for the unknown track (since GetStats is async), but no |
| 1325 | // data is returned for the track. |
| 1326 | TEST_F(PeerConnectionInterfaceTest, DISABLED_GetStatsForInvalidTrack) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1327 | InitiateCall(); |
| 1328 | scoped_refptr<AudioTrackInterface> unknown_audio_track( |
| 1329 | pc_factory_->CreateAudioTrack("unknown track", NULL)); |
| 1330 | EXPECT_FALSE(DoGetStats(unknown_audio_track)); |
| 1331 | } |
| 1332 | |
| 1333 | // This test setup two RTP data channels in loop back. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1334 | TEST_F(PeerConnectionInterfaceTest, TestDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1335 | FakeConstraints constraints; |
| 1336 | constraints.SetAllowRtpDataChannels(); |
| 1337 | CreatePeerConnection(&constraints); |
| 1338 | scoped_refptr<DataChannelInterface> data1 = |
| 1339 | pc_->CreateDataChannel("test1", NULL); |
| 1340 | scoped_refptr<DataChannelInterface> data2 = |
| 1341 | pc_->CreateDataChannel("test2", NULL); |
| 1342 | ASSERT_TRUE(data1 != NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1343 | rtc::scoped_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1344 | new MockDataChannelObserver(data1)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1345 | rtc::scoped_ptr<MockDataChannelObserver> observer2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1346 | new MockDataChannelObserver(data2)); |
| 1347 | |
| 1348 | EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); |
| 1349 | EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); |
| 1350 | std::string data_to_send1 = "testing testing"; |
| 1351 | std::string data_to_send2 = "testing something else"; |
| 1352 | EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1))); |
| 1353 | |
| 1354 | CreateOfferReceiveAnswer(); |
| 1355 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 1356 | EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); |
| 1357 | |
| 1358 | EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); |
| 1359 | EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); |
| 1360 | EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1))); |
| 1361 | EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); |
| 1362 | |
| 1363 | EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout); |
| 1364 | EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); |
| 1365 | |
| 1366 | data1->Close(); |
| 1367 | EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); |
| 1368 | CreateOfferReceiveAnswer(); |
| 1369 | EXPECT_FALSE(observer1->IsOpen()); |
| 1370 | EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); |
| 1371 | EXPECT_TRUE(observer2->IsOpen()); |
| 1372 | |
| 1373 | data_to_send2 = "testing something else again"; |
| 1374 | EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); |
| 1375 | |
| 1376 | EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); |
| 1377 | } |
| 1378 | |
| 1379 | // This test verifies that sendnig binary data over RTP data channels should |
| 1380 | // fail. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1381 | TEST_F(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1382 | FakeConstraints constraints; |
| 1383 | constraints.SetAllowRtpDataChannels(); |
| 1384 | CreatePeerConnection(&constraints); |
| 1385 | scoped_refptr<DataChannelInterface> data1 = |
| 1386 | pc_->CreateDataChannel("test1", NULL); |
| 1387 | scoped_refptr<DataChannelInterface> data2 = |
| 1388 | pc_->CreateDataChannel("test2", NULL); |
| 1389 | ASSERT_TRUE(data1 != NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1390 | rtc::scoped_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1391 | new MockDataChannelObserver(data1)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1392 | rtc::scoped_ptr<MockDataChannelObserver> observer2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1393 | new MockDataChannelObserver(data2)); |
| 1394 | |
| 1395 | EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); |
| 1396 | EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); |
| 1397 | |
| 1398 | CreateOfferReceiveAnswer(); |
| 1399 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 1400 | EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); |
| 1401 | |
| 1402 | EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); |
| 1403 | EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); |
| 1404 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1405 | rtc::Buffer buffer("test", 4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1406 | EXPECT_FALSE(data1->Send(DataBuffer(buffer, true))); |
| 1407 | } |
| 1408 | |
| 1409 | // This test setup a RTP data channels in loop back and test that a channel is |
| 1410 | // opened even if the remote end answer with a zero SSRC. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1411 | TEST_F(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1412 | FakeConstraints constraints; |
| 1413 | constraints.SetAllowRtpDataChannels(); |
| 1414 | CreatePeerConnection(&constraints); |
| 1415 | scoped_refptr<DataChannelInterface> data1 = |
| 1416 | pc_->CreateDataChannel("test1", NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1417 | rtc::scoped_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1418 | new MockDataChannelObserver(data1)); |
| 1419 | |
| 1420 | CreateOfferReceiveAnswerWithoutSsrc(); |
| 1421 | |
| 1422 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 1423 | |
| 1424 | data1->Close(); |
| 1425 | EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); |
| 1426 | CreateOfferReceiveAnswerWithoutSsrc(); |
| 1427 | EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); |
| 1428 | EXPECT_FALSE(observer1->IsOpen()); |
| 1429 | } |
| 1430 | |
| 1431 | // This test that if a data channel is added in an answer a receive only channel |
| 1432 | // channel is created. |
| 1433 | TEST_F(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) { |
| 1434 | FakeConstraints constraints; |
| 1435 | constraints.SetAllowRtpDataChannels(); |
| 1436 | CreatePeerConnection(&constraints); |
| 1437 | |
| 1438 | std::string offer_label = "offer_channel"; |
| 1439 | scoped_refptr<DataChannelInterface> offer_channel = |
| 1440 | pc_->CreateDataChannel(offer_label, NULL); |
| 1441 | |
| 1442 | CreateOfferAsLocalDescription(); |
| 1443 | |
| 1444 | // Replace the data channel label in the offer and apply it as an answer. |
| 1445 | std::string receive_label = "answer_channel"; |
| 1446 | std::string sdp; |
| 1447 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1448 | rtc::replace_substrs(offer_label.c_str(), offer_label.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1449 | receive_label.c_str(), receive_label.length(), |
| 1450 | &sdp); |
| 1451 | CreateAnswerAsRemoteDescription(sdp); |
| 1452 | |
| 1453 | // Verify that a new incoming data channel has been created and that |
| 1454 | // it is open but can't we written to. |
| 1455 | ASSERT_TRUE(observer_.last_datachannel_ != NULL); |
| 1456 | DataChannelInterface* received_channel = observer_.last_datachannel_; |
| 1457 | EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state()); |
| 1458 | EXPECT_EQ(receive_label, received_channel->label()); |
| 1459 | EXPECT_FALSE(received_channel->Send(DataBuffer("something"))); |
| 1460 | |
| 1461 | // Verify that the channel we initially offered has been rejected. |
| 1462 | EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); |
| 1463 | |
| 1464 | // Do another offer / answer exchange and verify that the data channel is |
| 1465 | // opened. |
| 1466 | CreateOfferReceiveAnswer(); |
| 1467 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(), |
| 1468 | kTimeout); |
| 1469 | } |
| 1470 | |
| 1471 | // This test that no data channel is returned if a reliable channel is |
| 1472 | // requested. |
| 1473 | // TODO(perkj): Remove this test once reliable channels are implemented. |
| 1474 | TEST_F(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) { |
| 1475 | FakeConstraints constraints; |
| 1476 | constraints.SetAllowRtpDataChannels(); |
| 1477 | CreatePeerConnection(&constraints); |
| 1478 | |
| 1479 | std::string label = "test"; |
| 1480 | webrtc::DataChannelInit config; |
| 1481 | config.reliable = true; |
| 1482 | scoped_refptr<DataChannelInterface> channel = |
| 1483 | pc_->CreateDataChannel(label, &config); |
| 1484 | EXPECT_TRUE(channel == NULL); |
| 1485 | } |
| 1486 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1487 | // Verifies that duplicated label is not allowed for RTP data channel. |
| 1488 | TEST_F(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) { |
| 1489 | FakeConstraints constraints; |
| 1490 | constraints.SetAllowRtpDataChannels(); |
| 1491 | CreatePeerConnection(&constraints); |
| 1492 | |
| 1493 | std::string label = "test"; |
| 1494 | scoped_refptr<DataChannelInterface> channel = |
| 1495 | pc_->CreateDataChannel(label, nullptr); |
| 1496 | EXPECT_NE(channel, nullptr); |
| 1497 | |
| 1498 | scoped_refptr<DataChannelInterface> dup_channel = |
| 1499 | pc_->CreateDataChannel(label, nullptr); |
| 1500 | EXPECT_EQ(dup_channel, nullptr); |
| 1501 | } |
| 1502 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1503 | // This tests that a SCTP data channel is returned using different |
| 1504 | // DataChannelInit configurations. |
| 1505 | TEST_F(PeerConnectionInterfaceTest, CreateSctpDataChannel) { |
| 1506 | FakeConstraints constraints; |
| 1507 | constraints.SetAllowDtlsSctpDataChannels(); |
| 1508 | CreatePeerConnection(&constraints); |
| 1509 | |
| 1510 | webrtc::DataChannelInit config; |
| 1511 | |
| 1512 | scoped_refptr<DataChannelInterface> channel = |
| 1513 | pc_->CreateDataChannel("1", &config); |
| 1514 | EXPECT_TRUE(channel != NULL); |
| 1515 | EXPECT_TRUE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 1516 | EXPECT_TRUE(observer_.renegotiation_needed_); |
| 1517 | observer_.renegotiation_needed_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1518 | |
| 1519 | config.ordered = false; |
| 1520 | channel = pc_->CreateDataChannel("2", &config); |
| 1521 | EXPECT_TRUE(channel != NULL); |
| 1522 | EXPECT_TRUE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 1523 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1524 | |
| 1525 | config.ordered = true; |
| 1526 | config.maxRetransmits = 0; |
| 1527 | channel = pc_->CreateDataChannel("3", &config); |
| 1528 | EXPECT_TRUE(channel != NULL); |
| 1529 | EXPECT_FALSE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 1530 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1531 | |
| 1532 | config.maxRetransmits = -1; |
| 1533 | config.maxRetransmitTime = 0; |
| 1534 | channel = pc_->CreateDataChannel("4", &config); |
| 1535 | EXPECT_TRUE(channel != NULL); |
| 1536 | EXPECT_FALSE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 1537 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | // This tests that no data channel is returned if both maxRetransmits and |
| 1541 | // maxRetransmitTime are set for SCTP data channels. |
| 1542 | TEST_F(PeerConnectionInterfaceTest, |
| 1543 | CreateSctpDataChannelShouldFailForInvalidConfig) { |
| 1544 | FakeConstraints constraints; |
| 1545 | constraints.SetAllowDtlsSctpDataChannels(); |
| 1546 | CreatePeerConnection(&constraints); |
| 1547 | |
| 1548 | std::string label = "test"; |
| 1549 | webrtc::DataChannelInit config; |
| 1550 | config.maxRetransmits = 0; |
| 1551 | config.maxRetransmitTime = 0; |
| 1552 | |
| 1553 | scoped_refptr<DataChannelInterface> channel = |
| 1554 | pc_->CreateDataChannel(label, &config); |
| 1555 | EXPECT_TRUE(channel == NULL); |
| 1556 | } |
| 1557 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1558 | // The test verifies that creating a SCTP data channel with an id already in use |
| 1559 | // or out of range should fail. |
| 1560 | TEST_F(PeerConnectionInterfaceTest, |
| 1561 | CreateSctpDataChannelWithInvalidIdShouldFail) { |
| 1562 | FakeConstraints constraints; |
| 1563 | constraints.SetAllowDtlsSctpDataChannels(); |
| 1564 | CreatePeerConnection(&constraints); |
| 1565 | |
| 1566 | webrtc::DataChannelInit config; |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1567 | scoped_refptr<DataChannelInterface> channel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1568 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 1569 | config.id = 1; |
| 1570 | channel = pc_->CreateDataChannel("1", &config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1571 | EXPECT_TRUE(channel != NULL); |
| 1572 | EXPECT_EQ(1, channel->id()); |
| 1573 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1574 | channel = pc_->CreateDataChannel("x", &config); |
| 1575 | EXPECT_TRUE(channel == NULL); |
| 1576 | |
| 1577 | config.id = cricket::kMaxSctpSid; |
| 1578 | channel = pc_->CreateDataChannel("max", &config); |
| 1579 | EXPECT_TRUE(channel != NULL); |
| 1580 | EXPECT_EQ(config.id, channel->id()); |
| 1581 | |
| 1582 | config.id = cricket::kMaxSctpSid + 1; |
| 1583 | channel = pc_->CreateDataChannel("x", &config); |
| 1584 | EXPECT_TRUE(channel == NULL); |
| 1585 | } |
| 1586 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1587 | // Verifies that duplicated label is allowed for SCTP data channel. |
| 1588 | TEST_F(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) { |
| 1589 | FakeConstraints constraints; |
| 1590 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1591 | true); |
| 1592 | CreatePeerConnection(&constraints); |
| 1593 | |
| 1594 | std::string label = "test"; |
| 1595 | scoped_refptr<DataChannelInterface> channel = |
| 1596 | pc_->CreateDataChannel(label, nullptr); |
| 1597 | EXPECT_NE(channel, nullptr); |
| 1598 | |
| 1599 | scoped_refptr<DataChannelInterface> dup_channel = |
| 1600 | pc_->CreateDataChannel(label, nullptr); |
| 1601 | EXPECT_NE(dup_channel, nullptr); |
| 1602 | } |
| 1603 | |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 1604 | // This test verifies that OnRenegotiationNeeded is fired for every new RTP |
| 1605 | // DataChannel. |
| 1606 | TEST_F(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) { |
| 1607 | FakeConstraints constraints; |
| 1608 | constraints.SetAllowRtpDataChannels(); |
| 1609 | CreatePeerConnection(&constraints); |
| 1610 | |
| 1611 | scoped_refptr<DataChannelInterface> dc1 = |
| 1612 | pc_->CreateDataChannel("test1", NULL); |
| 1613 | EXPECT_TRUE(observer_.renegotiation_needed_); |
| 1614 | observer_.renegotiation_needed_ = false; |
| 1615 | |
| 1616 | scoped_refptr<DataChannelInterface> dc2 = |
| 1617 | pc_->CreateDataChannel("test2", NULL); |
| 1618 | EXPECT_TRUE(observer_.renegotiation_needed_); |
| 1619 | } |
| 1620 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1621 | // This test that a data channel closes when a PeerConnection is deleted/closed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1622 | TEST_F(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1623 | FakeConstraints constraints; |
| 1624 | constraints.SetAllowRtpDataChannels(); |
| 1625 | CreatePeerConnection(&constraints); |
| 1626 | |
| 1627 | scoped_refptr<DataChannelInterface> data1 = |
| 1628 | pc_->CreateDataChannel("test1", NULL); |
| 1629 | scoped_refptr<DataChannelInterface> data2 = |
| 1630 | pc_->CreateDataChannel("test2", NULL); |
| 1631 | ASSERT_TRUE(data1 != NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1632 | rtc::scoped_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1633 | new MockDataChannelObserver(data1)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1634 | rtc::scoped_ptr<MockDataChannelObserver> observer2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1635 | new MockDataChannelObserver(data2)); |
| 1636 | |
| 1637 | CreateOfferReceiveAnswer(); |
| 1638 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 1639 | EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); |
| 1640 | |
| 1641 | ReleasePeerConnection(); |
| 1642 | EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); |
| 1643 | EXPECT_EQ(DataChannelInterface::kClosed, data2->state()); |
| 1644 | } |
| 1645 | |
| 1646 | // This test that data channels can be rejected in an answer. |
| 1647 | TEST_F(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) { |
| 1648 | FakeConstraints constraints; |
| 1649 | constraints.SetAllowRtpDataChannels(); |
| 1650 | CreatePeerConnection(&constraints); |
| 1651 | |
| 1652 | scoped_refptr<DataChannelInterface> offer_channel( |
| 1653 | pc_->CreateDataChannel("offer_channel", NULL)); |
| 1654 | |
| 1655 | CreateOfferAsLocalDescription(); |
| 1656 | |
| 1657 | // Create an answer where the m-line for data channels are rejected. |
| 1658 | std::string sdp; |
| 1659 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 1660 | webrtc::JsepSessionDescription* answer = new webrtc::JsepSessionDescription( |
| 1661 | SessionDescriptionInterface::kAnswer); |
| 1662 | EXPECT_TRUE(answer->Initialize(sdp, NULL)); |
| 1663 | cricket::ContentInfo* data_info = |
| 1664 | answer->description()->GetContentByName("data"); |
| 1665 | data_info->rejected = true; |
| 1666 | |
| 1667 | DoSetRemoteDescription(answer); |
| 1668 | EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); |
| 1669 | } |
| 1670 | |
| 1671 | // Test that we can create a session description from an SDP string from |
| 1672 | // FireFox, use it as a remote session description, generate an answer and use |
| 1673 | // the answer as a local description. |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 1674 | TEST_F(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1675 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1676 | FakeConstraints constraints; |
| 1677 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1678 | true); |
| 1679 | CreatePeerConnection(&constraints); |
| 1680 | AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); |
| 1681 | SessionDescriptionInterface* desc = |
| 1682 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, |
jbauch | fabe2c9 | 2015-07-16 13:43:14 -0700 | [diff] [blame] | 1683 | webrtc::kFireFoxSdpOffer, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1684 | EXPECT_TRUE(DoSetSessionDescription(desc, false)); |
| 1685 | CreateAnswerAsLocalDescription(); |
| 1686 | ASSERT_TRUE(pc_->local_description() != NULL); |
| 1687 | ASSERT_TRUE(pc_->remote_description() != NULL); |
| 1688 | |
| 1689 | const cricket::ContentInfo* content = |
| 1690 | cricket::GetFirstAudioContent(pc_->local_description()->description()); |
| 1691 | ASSERT_TRUE(content != NULL); |
| 1692 | EXPECT_FALSE(content->rejected); |
| 1693 | |
| 1694 | content = |
| 1695 | cricket::GetFirstVideoContent(pc_->local_description()->description()); |
| 1696 | ASSERT_TRUE(content != NULL); |
| 1697 | EXPECT_FALSE(content->rejected); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 1698 | #ifdef HAVE_SCTP |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1699 | content = |
| 1700 | cricket::GetFirstDataContent(pc_->local_description()->description()); |
| 1701 | ASSERT_TRUE(content != NULL); |
| 1702 | EXPECT_TRUE(content->rejected); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 1703 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1704 | } |
| 1705 | |
| 1706 | // Test that we can create an audio only offer and receive an answer with a |
| 1707 | // limited set of audio codecs and receive an updated offer with more audio |
| 1708 | // codecs, where the added codecs are not supported. |
| 1709 | TEST_F(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) { |
| 1710 | CreatePeerConnection(); |
| 1711 | AddVoiceStream("audio_label"); |
| 1712 | CreateOfferAsLocalDescription(); |
| 1713 | |
| 1714 | SessionDescriptionInterface* answer = |
| 1715 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, |
jbauch | fabe2c9 | 2015-07-16 13:43:14 -0700 | [diff] [blame] | 1716 | webrtc::kAudioSdp, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1717 | EXPECT_TRUE(DoSetSessionDescription(answer, false)); |
| 1718 | |
| 1719 | SessionDescriptionInterface* updated_offer = |
| 1720 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, |
jbauch | fabe2c9 | 2015-07-16 13:43:14 -0700 | [diff] [blame] | 1721 | webrtc::kAudioSdpWithUnsupportedCodecs, |
| 1722 | nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1723 | EXPECT_TRUE(DoSetSessionDescription(updated_offer, false)); |
| 1724 | CreateAnswerAsLocalDescription(); |
| 1725 | } |
| 1726 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1727 | // Test that if we're receiving (but not sending) a track, subsequent offers |
| 1728 | // will have m-lines with a=recvonly. |
| 1729 | TEST_F(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) { |
| 1730 | FakeConstraints constraints; |
| 1731 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1732 | true); |
| 1733 | CreatePeerConnection(&constraints); |
| 1734 | CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1735 | CreateAnswerAsLocalDescription(); |
| 1736 | |
| 1737 | // At this point we should be receiving stream 1, but not sending anything. |
| 1738 | // A new offer should be recvonly. |
| 1739 | SessionDescriptionInterface* offer; |
| 1740 | DoCreateOffer(&offer, nullptr); |
| 1741 | |
| 1742 | const cricket::ContentInfo* video_content = |
| 1743 | cricket::GetFirstVideoContent(offer->description()); |
| 1744 | const cricket::VideoContentDescription* video_desc = |
| 1745 | static_cast<const cricket::VideoContentDescription*>( |
| 1746 | video_content->description); |
| 1747 | ASSERT_EQ(cricket::MD_RECVONLY, video_desc->direction()); |
| 1748 | |
| 1749 | const cricket::ContentInfo* audio_content = |
| 1750 | cricket::GetFirstAudioContent(offer->description()); |
| 1751 | const cricket::AudioContentDescription* audio_desc = |
| 1752 | static_cast<const cricket::AudioContentDescription*>( |
| 1753 | audio_content->description); |
| 1754 | ASSERT_EQ(cricket::MD_RECVONLY, audio_desc->direction()); |
| 1755 | } |
| 1756 | |
| 1757 | // Test that if we're receiving (but not sending) a track, and the |
| 1758 | // offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to |
| 1759 | // false, the generated m-lines will be a=inactive. |
| 1760 | TEST_F(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) { |
| 1761 | FakeConstraints constraints; |
| 1762 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1763 | true); |
| 1764 | CreatePeerConnection(&constraints); |
| 1765 | CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1766 | CreateAnswerAsLocalDescription(); |
| 1767 | |
| 1768 | // At this point we should be receiving stream 1, but not sending anything. |
| 1769 | // A new offer would be recvonly, but we'll set the "no receive" constraints |
| 1770 | // to make it inactive. |
| 1771 | SessionDescriptionInterface* offer; |
| 1772 | FakeConstraints offer_constraints; |
| 1773 | offer_constraints.AddMandatory( |
| 1774 | webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false); |
| 1775 | offer_constraints.AddMandatory( |
| 1776 | webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false); |
| 1777 | DoCreateOffer(&offer, &offer_constraints); |
| 1778 | |
| 1779 | const cricket::ContentInfo* video_content = |
| 1780 | cricket::GetFirstVideoContent(offer->description()); |
| 1781 | const cricket::VideoContentDescription* video_desc = |
| 1782 | static_cast<const cricket::VideoContentDescription*>( |
| 1783 | video_content->description); |
| 1784 | ASSERT_EQ(cricket::MD_INACTIVE, video_desc->direction()); |
| 1785 | |
| 1786 | const cricket::ContentInfo* audio_content = |
| 1787 | cricket::GetFirstAudioContent(offer->description()); |
| 1788 | const cricket::AudioContentDescription* audio_desc = |
| 1789 | static_cast<const cricket::AudioContentDescription*>( |
| 1790 | audio_content->description); |
| 1791 | ASSERT_EQ(cricket::MD_INACTIVE, audio_desc->direction()); |
| 1792 | } |
| 1793 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 1794 | // Test that we can use SetConfiguration to change the ICE servers of the |
| 1795 | // PortAllocator. |
| 1796 | TEST_F(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) { |
| 1797 | CreatePeerConnection(); |
| 1798 | |
| 1799 | PeerConnectionInterface::RTCConfiguration config; |
| 1800 | PeerConnectionInterface::IceServer server; |
| 1801 | server.uri = "stun:test_hostname"; |
| 1802 | config.servers.push_back(server); |
| 1803 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 1804 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 1805 | EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
| 1806 | EXPECT_EQ("test_hostname", |
| 1807 | port_allocator_->stun_servers().begin()->hostname()); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 1808 | } |
| 1809 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1810 | // Test that PeerConnection::Close changes the states to closed and all remote |
| 1811 | // tracks change state to ended. |
| 1812 | TEST_F(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { |
| 1813 | // Initialize a PeerConnection and negotiate local and remote session |
| 1814 | // description. |
| 1815 | InitiateCall(); |
| 1816 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
| 1817 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 1818 | |
| 1819 | pc_->Close(); |
| 1820 | |
| 1821 | EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state()); |
| 1822 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed, |
| 1823 | pc_->ice_connection_state()); |
| 1824 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete, |
| 1825 | pc_->ice_gathering_state()); |
| 1826 | |
| 1827 | EXPECT_EQ(1u, pc_->local_streams()->count()); |
| 1828 | EXPECT_EQ(1u, pc_->remote_streams()->count()); |
| 1829 | |
| 1830 | scoped_refptr<MediaStreamInterface> remote_stream = |
| 1831 | pc_->remote_streams()->at(0); |
| 1832 | EXPECT_EQ(MediaStreamTrackInterface::kEnded, |
| 1833 | remote_stream->GetVideoTracks()[0]->state()); |
| 1834 | EXPECT_EQ(MediaStreamTrackInterface::kEnded, |
| 1835 | remote_stream->GetAudioTracks()[0]->state()); |
| 1836 | } |
| 1837 | |
| 1838 | // Test that PeerConnection methods fails gracefully after |
| 1839 | // PeerConnection::Close has been called. |
| 1840 | TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) { |
| 1841 | CreatePeerConnection(); |
| 1842 | AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); |
| 1843 | CreateOfferAsRemoteDescription(); |
| 1844 | CreateAnswerAsLocalDescription(); |
| 1845 | |
| 1846 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
| 1847 | scoped_refptr<MediaStreamInterface> local_stream = |
| 1848 | pc_->local_streams()->at(0); |
| 1849 | |
| 1850 | pc_->Close(); |
| 1851 | |
| 1852 | pc_->RemoveStream(local_stream); |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 1853 | EXPECT_FALSE(pc_->AddStream(local_stream)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1854 | |
| 1855 | ASSERT_FALSE(local_stream->GetAudioTracks().empty()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1856 | rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1857 | pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0])); |
wu@webrtc.org | 6603736 | 2013-08-13 00:09:35 +0000 | [diff] [blame] | 1858 | EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1859 | |
| 1860 | EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL); |
| 1861 | |
| 1862 | EXPECT_TRUE(pc_->local_description() != NULL); |
| 1863 | EXPECT_TRUE(pc_->remote_description() != NULL); |
| 1864 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1865 | rtc::scoped_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1866 | EXPECT_TRUE(DoCreateOffer(offer.use(), nullptr)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1867 | rtc::scoped_ptr<SessionDescriptionInterface> answer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1868 | EXPECT_TRUE(DoCreateAnswer(answer.use(), nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1869 | |
| 1870 | std::string sdp; |
| 1871 | ASSERT_TRUE(pc_->remote_description()->ToString(&sdp)); |
| 1872 | SessionDescriptionInterface* remote_offer = |
| 1873 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, |
| 1874 | sdp, NULL); |
| 1875 | EXPECT_FALSE(DoSetRemoteDescription(remote_offer)); |
| 1876 | |
| 1877 | ASSERT_TRUE(pc_->local_description()->ToString(&sdp)); |
| 1878 | SessionDescriptionInterface* local_offer = |
| 1879 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, |
| 1880 | sdp, NULL); |
| 1881 | EXPECT_FALSE(DoSetLocalDescription(local_offer)); |
| 1882 | } |
| 1883 | |
| 1884 | // Test that GetStats can still be called after PeerConnection::Close. |
| 1885 | TEST_F(PeerConnectionInterfaceTest, CloseAndGetStats) { |
| 1886 | InitiateCall(); |
| 1887 | pc_->Close(); |
| 1888 | DoGetStats(NULL); |
| 1889 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1890 | |
| 1891 | // NOTE: The series of tests below come from what used to be |
| 1892 | // mediastreamsignaling_unittest.cc, and are mostly aimed at testing that |
| 1893 | // setting a remote or local description has the expected effects. |
| 1894 | |
| 1895 | // This test verifies that the remote MediaStreams corresponding to a received |
| 1896 | // SDP string is created. In this test the two separate MediaStreams are |
| 1897 | // signaled. |
| 1898 | TEST_F(PeerConnectionInterfaceTest, UpdateRemoteStreams) { |
| 1899 | FakeConstraints constraints; |
| 1900 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1901 | true); |
| 1902 | CreatePeerConnection(&constraints); |
| 1903 | CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1904 | |
| 1905 | rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1)); |
| 1906 | EXPECT_TRUE( |
| 1907 | CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 1908 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1909 | EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr); |
| 1910 | |
| 1911 | // Create a session description based on another SDP with another |
| 1912 | // MediaStream. |
| 1913 | CreateAndSetRemoteOffer(kSdpStringWithStream1And2); |
| 1914 | |
| 1915 | rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2)); |
| 1916 | EXPECT_TRUE( |
| 1917 | CompareStreamCollections(observer_.remote_streams(), reference2.get())); |
| 1918 | } |
| 1919 | |
| 1920 | // This test verifies that when remote tracks are added/removed from SDP, the |
| 1921 | // created remote streams are updated appropriately. |
| 1922 | TEST_F(PeerConnectionInterfaceTest, |
| 1923 | AddRemoveTrackFromExistingRemoteMediaStream) { |
| 1924 | FakeConstraints constraints; |
| 1925 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1926 | true); |
| 1927 | CreatePeerConnection(&constraints); |
| 1928 | rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1; |
| 1929 | CreateSessionDescriptionAndReference(1, 1, desc_ms1.accept()); |
| 1930 | EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release())); |
| 1931 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 1932 | reference_collection_)); |
| 1933 | |
| 1934 | // Add extra audio and video tracks to the same MediaStream. |
| 1935 | rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1_two_tracks; |
| 1936 | CreateSessionDescriptionAndReference(2, 2, desc_ms1_two_tracks.accept()); |
| 1937 | EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release())); |
| 1938 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 1939 | reference_collection_)); |
| 1940 | |
| 1941 | // Remove the extra audio and video tracks. |
| 1942 | rtc::scoped_ptr<SessionDescriptionInterface> desc_ms2; |
| 1943 | CreateSessionDescriptionAndReference(1, 1, desc_ms2.accept()); |
| 1944 | EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release())); |
| 1945 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 1946 | reference_collection_)); |
| 1947 | } |
| 1948 | |
| 1949 | // This tests that remote tracks are ended if a local session description is set |
| 1950 | // that rejects the media content type. |
| 1951 | TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) { |
| 1952 | FakeConstraints constraints; |
| 1953 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1954 | true); |
| 1955 | CreatePeerConnection(&constraints); |
| 1956 | // First create and set a remote offer, then reject its video content in our |
| 1957 | // answer. |
| 1958 | CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 1959 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 1960 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 1961 | ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 1962 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 1963 | |
| 1964 | rtc::scoped_refptr<webrtc::VideoTrackInterface> remote_video = |
| 1965 | remote_stream->GetVideoTracks()[0]; |
| 1966 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_video->state()); |
| 1967 | rtc::scoped_refptr<webrtc::AudioTrackInterface> remote_audio = |
| 1968 | remote_stream->GetAudioTracks()[0]; |
| 1969 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); |
| 1970 | |
| 1971 | rtc::scoped_ptr<SessionDescriptionInterface> local_answer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1972 | EXPECT_TRUE(DoCreateAnswer(local_answer.accept(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1973 | cricket::ContentInfo* video_info = |
| 1974 | local_answer->description()->GetContentByName("video"); |
| 1975 | video_info->rejected = true; |
| 1976 | EXPECT_TRUE(DoSetLocalDescription(local_answer.release())); |
| 1977 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state()); |
| 1978 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); |
| 1979 | |
| 1980 | // Now create an offer where we reject both video and audio. |
| 1981 | rtc::scoped_ptr<SessionDescriptionInterface> local_offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 1982 | EXPECT_TRUE(DoCreateOffer(local_offer.accept(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1983 | video_info = local_offer->description()->GetContentByName("video"); |
| 1984 | ASSERT_TRUE(video_info != nullptr); |
| 1985 | video_info->rejected = true; |
| 1986 | cricket::ContentInfo* audio_info = |
| 1987 | local_offer->description()->GetContentByName("audio"); |
| 1988 | ASSERT_TRUE(audio_info != nullptr); |
| 1989 | audio_info->rejected = true; |
| 1990 | EXPECT_TRUE(DoSetLocalDescription(local_offer.release())); |
| 1991 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state()); |
| 1992 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_audio->state()); |
| 1993 | } |
| 1994 | |
| 1995 | // This tests that we won't crash if the remote track has been removed outside |
| 1996 | // of PeerConnection and then PeerConnection tries to reject the track. |
| 1997 | TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) { |
| 1998 | FakeConstraints constraints; |
| 1999 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2000 | true); |
| 2001 | CreatePeerConnection(&constraints); |
| 2002 | CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 2003 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2004 | remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); |
| 2005 | remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); |
| 2006 | |
| 2007 | rtc::scoped_ptr<SessionDescriptionInterface> local_answer( |
| 2008 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kAnswer, |
| 2009 | kSdpStringWithStream1, nullptr)); |
| 2010 | cricket::ContentInfo* video_info = |
| 2011 | local_answer->description()->GetContentByName("video"); |
| 2012 | video_info->rejected = true; |
| 2013 | cricket::ContentInfo* audio_info = |
| 2014 | local_answer->description()->GetContentByName("audio"); |
| 2015 | audio_info->rejected = true; |
| 2016 | EXPECT_TRUE(DoSetLocalDescription(local_answer.release())); |
| 2017 | |
| 2018 | // No crash is a pass. |
| 2019 | } |
| 2020 | |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2021 | // This tests that if a recvonly remote description is set, no remote streams |
| 2022 | // will be created, even if the description contains SSRCs/MSIDs. |
| 2023 | // See: https://code.google.com/p/webrtc/issues/detail?id=5054 |
| 2024 | TEST_F(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) { |
| 2025 | FakeConstraints constraints; |
| 2026 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2027 | true); |
| 2028 | CreatePeerConnection(&constraints); |
| 2029 | |
| 2030 | std::string recvonly_offer = kSdpStringWithStream1; |
| 2031 | rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly, |
| 2032 | strlen(kRecvonly), &recvonly_offer); |
| 2033 | CreateAndSetRemoteOffer(recvonly_offer); |
| 2034 | |
| 2035 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2036 | } |
| 2037 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2038 | // This tests that a default MediaStream is created if a remote session |
| 2039 | // description doesn't contain any streams and no MSID support. |
| 2040 | // It also tests that the default stream is updated if a video m-line is added |
| 2041 | // in a subsequent session description. |
| 2042 | TEST_F(PeerConnectionInterfaceTest, SdpWithoutMsidCreatesDefaultStream) { |
| 2043 | FakeConstraints constraints; |
| 2044 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2045 | true); |
| 2046 | CreatePeerConnection(&constraints); |
| 2047 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 2048 | |
| 2049 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2050 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2051 | |
| 2052 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2053 | EXPECT_EQ(0u, remote_stream->GetVideoTracks().size()); |
| 2054 | EXPECT_EQ("default", remote_stream->label()); |
| 2055 | |
| 2056 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2057 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2058 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2059 | EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id()); |
deadbeef | 884f585 | 2016-01-15 09:20:04 -0800 | [diff] [blame] | 2060 | EXPECT_EQ(MediaStreamTrackInterface::kLive, |
| 2061 | remote_stream->GetAudioTracks()[0]->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2062 | ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 2063 | EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id()); |
deadbeef | 884f585 | 2016-01-15 09:20:04 -0800 | [diff] [blame] | 2064 | EXPECT_EQ(MediaStreamTrackInterface::kLive, |
| 2065 | remote_stream->GetVideoTracks()[0]->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2066 | } |
| 2067 | |
| 2068 | // This tests that a default MediaStream is created if a remote session |
| 2069 | // description doesn't contain any streams and media direction is send only. |
| 2070 | TEST_F(PeerConnectionInterfaceTest, |
| 2071 | SendOnlySdpWithoutMsidCreatesDefaultStream) { |
| 2072 | FakeConstraints constraints; |
| 2073 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2074 | true); |
| 2075 | CreatePeerConnection(&constraints); |
| 2076 | CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams); |
| 2077 | |
| 2078 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2079 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2080 | |
| 2081 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2082 | EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 2083 | EXPECT_EQ("default", remote_stream->label()); |
| 2084 | } |
| 2085 | |
| 2086 | // This tests that it won't crash when PeerConnection tries to remove |
| 2087 | // a remote track that as already been removed from the MediaStream. |
| 2088 | TEST_F(PeerConnectionInterfaceTest, RemoveAlreadyGoneRemoteStream) { |
| 2089 | FakeConstraints constraints; |
| 2090 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2091 | true); |
| 2092 | CreatePeerConnection(&constraints); |
| 2093 | CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 2094 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2095 | remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); |
| 2096 | remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); |
| 2097 | |
| 2098 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2099 | |
| 2100 | // No crash is a pass. |
| 2101 | } |
| 2102 | |
| 2103 | // This tests that a default MediaStream is created if the remote session |
| 2104 | // description doesn't contain any streams and don't contain an indication if |
| 2105 | // MSID is supported. |
| 2106 | TEST_F(PeerConnectionInterfaceTest, |
| 2107 | SdpWithoutMsidAndStreamsCreatesDefaultStream) { |
| 2108 | FakeConstraints constraints; |
| 2109 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2110 | true); |
| 2111 | CreatePeerConnection(&constraints); |
| 2112 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2113 | |
| 2114 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2115 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2116 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2117 | EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 2118 | } |
| 2119 | |
| 2120 | // This tests that a default MediaStream is not created if the remote session |
| 2121 | // description doesn't contain any streams but does support MSID. |
| 2122 | TEST_F(PeerConnectionInterfaceTest, SdpWithMsidDontCreatesDefaultStream) { |
| 2123 | FakeConstraints constraints; |
| 2124 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2125 | true); |
| 2126 | CreatePeerConnection(&constraints); |
| 2127 | CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams); |
| 2128 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2129 | } |
| 2130 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 2131 | // This tests that when setting a new description, the old default tracks are |
| 2132 | // not destroyed and recreated. |
| 2133 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250 |
| 2134 | TEST_F(PeerConnectionInterfaceTest, DefaultTracksNotDestroyedAndRecreated) { |
| 2135 | FakeConstraints constraints; |
| 2136 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2137 | true); |
| 2138 | CreatePeerConnection(&constraints); |
| 2139 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 2140 | |
| 2141 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2142 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2143 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2144 | |
| 2145 | // Set the track to "disabled", then set a new description and ensure the |
| 2146 | // track is still disabled, which ensures it hasn't been recreated. |
| 2147 | remote_stream->GetAudioTracks()[0]->set_enabled(false); |
| 2148 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 2149 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2150 | EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled()); |
| 2151 | } |
| 2152 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2153 | // This tests that a default MediaStream is not created if a remote session |
| 2154 | // description is updated to not have any MediaStreams. |
| 2155 | TEST_F(PeerConnectionInterfaceTest, VerifyDefaultStreamIsNotCreated) { |
| 2156 | FakeConstraints constraints; |
| 2157 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2158 | true); |
| 2159 | CreatePeerConnection(&constraints); |
| 2160 | CreateAndSetRemoteOffer(kSdpStringWithStream1); |
| 2161 | rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1)); |
| 2162 | EXPECT_TRUE( |
| 2163 | CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 2164 | |
| 2165 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2166 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2167 | } |
| 2168 | |
| 2169 | // This tests that an RtpSender is created when the local description is set |
| 2170 | // after adding a local stream. |
| 2171 | // TODO(deadbeef): This test and the one below it need to be updated when |
| 2172 | // an RtpSender's lifetime isn't determined by when a local description is set. |
| 2173 | TEST_F(PeerConnectionInterfaceTest, LocalDescriptionChanged) { |
| 2174 | FakeConstraints constraints; |
| 2175 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2176 | true); |
| 2177 | CreatePeerConnection(&constraints); |
| 2178 | // Create an offer just to ensure we have an identity before we manually |
| 2179 | // call SetLocalDescription. |
| 2180 | rtc::scoped_ptr<SessionDescriptionInterface> throwaway; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2181 | ASSERT_TRUE(DoCreateOffer(throwaway.accept(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2182 | |
| 2183 | rtc::scoped_ptr<SessionDescriptionInterface> desc_1; |
| 2184 | CreateSessionDescriptionAndReference(2, 2, desc_1.accept()); |
| 2185 | |
| 2186 | pc_->AddStream(reference_collection_->at(0)); |
| 2187 | EXPECT_TRUE(DoSetLocalDescription(desc_1.release())); |
| 2188 | auto senders = pc_->GetSenders(); |
| 2189 | EXPECT_EQ(4u, senders.size()); |
| 2190 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2191 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2192 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 2193 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 2194 | |
| 2195 | // Remove an audio and video track. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 2196 | pc_->RemoveStream(reference_collection_->at(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2197 | rtc::scoped_ptr<SessionDescriptionInterface> desc_2; |
| 2198 | CreateSessionDescriptionAndReference(1, 1, desc_2.accept()); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 2199 | pc_->AddStream(reference_collection_->at(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2200 | EXPECT_TRUE(DoSetLocalDescription(desc_2.release())); |
| 2201 | senders = pc_->GetSenders(); |
| 2202 | EXPECT_EQ(2u, senders.size()); |
| 2203 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2204 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2205 | EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1])); |
| 2206 | EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1])); |
| 2207 | } |
| 2208 | |
| 2209 | // This tests that an RtpSender is created when the local description is set |
| 2210 | // before adding a local stream. |
| 2211 | TEST_F(PeerConnectionInterfaceTest, |
| 2212 | AddLocalStreamAfterLocalDescriptionChanged) { |
| 2213 | FakeConstraints constraints; |
| 2214 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2215 | true); |
| 2216 | CreatePeerConnection(&constraints); |
| 2217 | // Create an offer just to ensure we have an identity before we manually |
| 2218 | // call SetLocalDescription. |
| 2219 | rtc::scoped_ptr<SessionDescriptionInterface> throwaway; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2220 | ASSERT_TRUE(DoCreateOffer(throwaway.accept(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2221 | |
| 2222 | rtc::scoped_ptr<SessionDescriptionInterface> desc_1; |
| 2223 | CreateSessionDescriptionAndReference(2, 2, desc_1.accept()); |
| 2224 | |
| 2225 | EXPECT_TRUE(DoSetLocalDescription(desc_1.release())); |
| 2226 | auto senders = pc_->GetSenders(); |
| 2227 | EXPECT_EQ(0u, senders.size()); |
| 2228 | |
| 2229 | pc_->AddStream(reference_collection_->at(0)); |
| 2230 | senders = pc_->GetSenders(); |
| 2231 | EXPECT_EQ(4u, senders.size()); |
| 2232 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2233 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2234 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 2235 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 2236 | } |
| 2237 | |
| 2238 | // This tests that the expected behavior occurs if the SSRC on a local track is |
| 2239 | // changed when SetLocalDescription is called. |
| 2240 | TEST_F(PeerConnectionInterfaceTest, |
| 2241 | ChangeSsrcOnTrackInLocalSessionDescription) { |
| 2242 | FakeConstraints constraints; |
| 2243 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2244 | true); |
| 2245 | CreatePeerConnection(&constraints); |
| 2246 | // Create an offer just to ensure we have an identity before we manually |
| 2247 | // call SetLocalDescription. |
| 2248 | rtc::scoped_ptr<SessionDescriptionInterface> throwaway; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2249 | ASSERT_TRUE(DoCreateOffer(throwaway.accept(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2250 | |
| 2251 | rtc::scoped_ptr<SessionDescriptionInterface> desc; |
| 2252 | CreateSessionDescriptionAndReference(1, 1, desc.accept()); |
| 2253 | std::string sdp; |
| 2254 | desc->ToString(&sdp); |
| 2255 | |
| 2256 | pc_->AddStream(reference_collection_->at(0)); |
| 2257 | EXPECT_TRUE(DoSetLocalDescription(desc.release())); |
| 2258 | auto senders = pc_->GetSenders(); |
| 2259 | EXPECT_EQ(2u, senders.size()); |
| 2260 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2261 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2262 | |
| 2263 | // Change the ssrc of the audio and video track. |
| 2264 | std::string ssrc_org = "a=ssrc:1"; |
| 2265 | std::string ssrc_to = "a=ssrc:97"; |
| 2266 | rtc::replace_substrs(ssrc_org.c_str(), ssrc_org.length(), ssrc_to.c_str(), |
| 2267 | ssrc_to.length(), &sdp); |
| 2268 | ssrc_org = "a=ssrc:2"; |
| 2269 | ssrc_to = "a=ssrc:98"; |
| 2270 | rtc::replace_substrs(ssrc_org.c_str(), ssrc_org.length(), ssrc_to.c_str(), |
| 2271 | ssrc_to.length(), &sdp); |
| 2272 | rtc::scoped_ptr<SessionDescriptionInterface> updated_desc( |
| 2273 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, sdp, |
| 2274 | nullptr)); |
| 2275 | |
| 2276 | EXPECT_TRUE(DoSetLocalDescription(updated_desc.release())); |
| 2277 | senders = pc_->GetSenders(); |
| 2278 | EXPECT_EQ(2u, senders.size()); |
| 2279 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2280 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2281 | // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC |
| 2282 | // changed. |
| 2283 | } |
| 2284 | |
| 2285 | // This tests that the expected behavior occurs if a new session description is |
| 2286 | // set with the same tracks, but on a different MediaStream. |
| 2287 | TEST_F(PeerConnectionInterfaceTest, SignalSameTracksInSeparateMediaStream) { |
| 2288 | FakeConstraints constraints; |
| 2289 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2290 | true); |
| 2291 | CreatePeerConnection(&constraints); |
| 2292 | // Create an offer just to ensure we have an identity before we manually |
| 2293 | // call SetLocalDescription. |
| 2294 | rtc::scoped_ptr<SessionDescriptionInterface> throwaway; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2295 | ASSERT_TRUE(DoCreateOffer(throwaway.accept(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2296 | |
| 2297 | rtc::scoped_ptr<SessionDescriptionInterface> desc; |
| 2298 | CreateSessionDescriptionAndReference(1, 1, desc.accept()); |
| 2299 | std::string sdp; |
| 2300 | desc->ToString(&sdp); |
| 2301 | |
| 2302 | pc_->AddStream(reference_collection_->at(0)); |
| 2303 | EXPECT_TRUE(DoSetLocalDescription(desc.release())); |
| 2304 | auto senders = pc_->GetSenders(); |
| 2305 | EXPECT_EQ(2u, senders.size()); |
| 2306 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2307 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2308 | |
| 2309 | // Add a new MediaStream but with the same tracks as in the first stream. |
| 2310 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1( |
| 2311 | webrtc::MediaStream::Create(kStreams[1])); |
| 2312 | stream_1->AddTrack(reference_collection_->at(0)->GetVideoTracks()[0]); |
| 2313 | stream_1->AddTrack(reference_collection_->at(0)->GetAudioTracks()[0]); |
| 2314 | pc_->AddStream(stream_1); |
| 2315 | |
| 2316 | // Replace msid in the original SDP. |
| 2317 | rtc::replace_substrs(kStreams[0], strlen(kStreams[0]), kStreams[1], |
| 2318 | strlen(kStreams[1]), &sdp); |
| 2319 | |
| 2320 | rtc::scoped_ptr<SessionDescriptionInterface> updated_desc( |
| 2321 | webrtc::CreateSessionDescription(SessionDescriptionInterface::kOffer, sdp, |
| 2322 | nullptr)); |
| 2323 | |
| 2324 | EXPECT_TRUE(DoSetLocalDescription(updated_desc.release())); |
| 2325 | senders = pc_->GetSenders(); |
| 2326 | EXPECT_EQ(2u, senders.size()); |
| 2327 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 2328 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 2329 | } |
| 2330 | |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 2331 | // The PeerConnectionMediaConfig tests below verify that configuration |
| 2332 | // and constraints are propagated into the MediaConfig passed to |
| 2333 | // CreateMediaController. These settings are intended for MediaChannel |
| 2334 | // constructors, but that is not exercised by these unittest. |
| 2335 | class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { |
| 2336 | public: |
| 2337 | webrtc::MediaControllerInterface* CreateMediaController( |
| 2338 | const cricket::MediaConfig& config) const override { |
| 2339 | create_media_controller_called_ = true; |
| 2340 | create_media_controller_config_ = config; |
| 2341 | |
| 2342 | webrtc::MediaControllerInterface* mc = |
| 2343 | PeerConnectionFactory::CreateMediaController(config); |
| 2344 | EXPECT_TRUE(mc != nullptr); |
| 2345 | return mc; |
| 2346 | } |
| 2347 | |
| 2348 | // Mutable, so they can be modified in the above const-declared method. |
| 2349 | mutable bool create_media_controller_called_ = false; |
| 2350 | mutable cricket::MediaConfig create_media_controller_config_; |
| 2351 | }; |
| 2352 | |
| 2353 | class PeerConnectionMediaConfigTest : public testing::Test { |
| 2354 | protected: |
| 2355 | void SetUp() override { |
| 2356 | pcf_= new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); |
| 2357 | pcf_->Initialize(); |
| 2358 | } |
| 2359 | const cricket::MediaConfig& TestCreatePeerConnection( |
| 2360 | const PeerConnectionInterface::RTCConfiguration& config, |
| 2361 | const MediaConstraintsInterface *constraints) { |
| 2362 | pcf_->create_media_controller_called_ = false; |
| 2363 | |
| 2364 | scoped_refptr<PeerConnectionInterface> pc( |
| 2365 | pcf_->CreatePeerConnection(config, constraints, nullptr, nullptr, |
| 2366 | &observer_)); |
| 2367 | EXPECT_TRUE(pc.get()); |
| 2368 | EXPECT_TRUE(pcf_->create_media_controller_called_); |
| 2369 | return pcf_->create_media_controller_config_; |
| 2370 | } |
| 2371 | |
| 2372 | scoped_refptr<PeerConnectionFactoryForTest> pcf_; |
| 2373 | MockPeerConnectionObserver observer_; |
| 2374 | }; |
| 2375 | |
| 2376 | // This test verifies the default behaviour with no constraints and a |
| 2377 | // default RTCConfiguration. |
| 2378 | TEST_F(PeerConnectionMediaConfigTest, TestDefaults) { |
| 2379 | PeerConnectionInterface::RTCConfiguration config; |
| 2380 | FakeConstraints constraints; |
| 2381 | |
| 2382 | const cricket::MediaConfig& media_config = |
| 2383 | TestCreatePeerConnection(config, &constraints); |
| 2384 | |
| 2385 | EXPECT_FALSE(media_config.enable_dscp); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2386 | EXPECT_TRUE(media_config.video.enable_cpu_overuse_detection); |
| 2387 | EXPECT_FALSE(media_config.video.disable_prerenderer_smoothing); |
| 2388 | EXPECT_FALSE(media_config.video.suspend_below_min_bitrate); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 2389 | } |
| 2390 | |
| 2391 | // This test verifies the DSCP constraint is recognized and passed to |
| 2392 | // the CreateMediaController call. |
| 2393 | TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) { |
| 2394 | PeerConnectionInterface::RTCConfiguration config; |
| 2395 | FakeConstraints constraints; |
| 2396 | |
| 2397 | constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true); |
| 2398 | const cricket::MediaConfig& media_config = |
| 2399 | TestCreatePeerConnection(config, &constraints); |
| 2400 | |
| 2401 | EXPECT_TRUE(media_config.enable_dscp); |
| 2402 | } |
| 2403 | |
| 2404 | // This test verifies the cpu overuse detection constraint is |
| 2405 | // recognized and passed to the CreateMediaController call. |
| 2406 | TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) { |
| 2407 | PeerConnectionInterface::RTCConfiguration config; |
| 2408 | FakeConstraints constraints; |
| 2409 | |
| 2410 | constraints.AddOptional( |
| 2411 | webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false); |
| 2412 | const cricket::MediaConfig media_config = |
| 2413 | TestCreatePeerConnection(config, &constraints); |
| 2414 | |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2415 | EXPECT_FALSE(media_config.video.enable_cpu_overuse_detection); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 2416 | } |
| 2417 | |
| 2418 | // This test verifies that the disable_prerenderer_smoothing flag is |
| 2419 | // propagated from RTCConfiguration to the CreateMediaController call. |
| 2420 | TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) { |
| 2421 | PeerConnectionInterface::RTCConfiguration config; |
| 2422 | FakeConstraints constraints; |
| 2423 | |
| 2424 | config.disable_prerenderer_smoothing = true; |
| 2425 | const cricket::MediaConfig& media_config = |
| 2426 | TestCreatePeerConnection(config, &constraints); |
| 2427 | |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2428 | EXPECT_TRUE(media_config.video.disable_prerenderer_smoothing); |
| 2429 | } |
| 2430 | |
| 2431 | // This test verifies the suspend below min bitrate constraint is |
| 2432 | // recognized and passed to the CreateMediaController call. |
| 2433 | TEST_F(PeerConnectionMediaConfigTest, |
| 2434 | TestSuspendBelowMinBitrateConstraintTrue) { |
| 2435 | PeerConnectionInterface::RTCConfiguration config; |
| 2436 | FakeConstraints constraints; |
| 2437 | |
| 2438 | constraints.AddOptional( |
| 2439 | webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, |
| 2440 | true); |
| 2441 | const cricket::MediaConfig media_config = |
| 2442 | TestCreatePeerConnection(config, &constraints); |
| 2443 | |
| 2444 | EXPECT_TRUE(media_config.video.suspend_below_min_bitrate); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 2445 | } |
| 2446 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2447 | // The following tests verify that session options are created correctly. |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2448 | // TODO(deadbeef): Convert these tests to be more end-to-end. Instead of |
| 2449 | // "verify options are converted correctly", should be "pass options into |
| 2450 | // CreateOffer and verify the correct offer is produced." |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2451 | |
| 2452 | TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidAudioOption) { |
| 2453 | RTCOfferAnswerOptions rtc_options; |
| 2454 | rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1; |
| 2455 | |
| 2456 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2457 | EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2458 | |
| 2459 | rtc_options.offer_to_receive_audio = |
| 2460 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2461 | EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | TEST(CreateSessionOptionsTest, GetOptionsForOfferWithInvalidVideoOption) { |
| 2465 | RTCOfferAnswerOptions rtc_options; |
| 2466 | rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1; |
| 2467 | |
| 2468 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2469 | EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2470 | |
| 2471 | rtc_options.offer_to_receive_video = |
| 2472 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2473 | EXPECT_FALSE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2474 | } |
| 2475 | |
| 2476 | // Test that a MediaSessionOptions is created for an offer if |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2477 | // OfferToReceiveAudio and OfferToReceiveVideo options are set. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2478 | TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudioVideo) { |
| 2479 | RTCOfferAnswerOptions rtc_options; |
| 2480 | rtc_options.offer_to_receive_audio = 1; |
| 2481 | rtc_options.offer_to_receive_video = 1; |
| 2482 | |
| 2483 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2484 | EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2485 | EXPECT_TRUE(options.has_audio()); |
| 2486 | EXPECT_TRUE(options.has_video()); |
| 2487 | EXPECT_TRUE(options.bundle_enabled); |
| 2488 | } |
| 2489 | |
| 2490 | // Test that a correct MediaSessionOptions is created for an offer if |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2491 | // OfferToReceiveAudio is set. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2492 | TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithAudio) { |
| 2493 | RTCOfferAnswerOptions rtc_options; |
| 2494 | rtc_options.offer_to_receive_audio = 1; |
| 2495 | |
| 2496 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2497 | EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2498 | EXPECT_TRUE(options.has_audio()); |
| 2499 | EXPECT_FALSE(options.has_video()); |
| 2500 | EXPECT_TRUE(options.bundle_enabled); |
| 2501 | } |
| 2502 | |
| 2503 | // Test that a correct MediaSessionOptions is created for an offer if |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2504 | // the default OfferOptions are used. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2505 | TEST(CreateSessionOptionsTest, GetDefaultMediaSessionOptionsForOffer) { |
| 2506 | RTCOfferAnswerOptions rtc_options; |
| 2507 | |
| 2508 | cricket::MediaSessionOptions options; |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2509 | options.transport_options["audio"] = cricket::TransportOptions(); |
| 2510 | options.transport_options["video"] = cricket::TransportOptions(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2511 | EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2512 | EXPECT_TRUE(options.has_audio()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2513 | EXPECT_FALSE(options.has_video()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2514 | EXPECT_TRUE(options.bundle_enabled); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2515 | EXPECT_TRUE(options.vad_enabled); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2516 | EXPECT_FALSE(options.transport_options["audio"].ice_restart); |
| 2517 | EXPECT_FALSE(options.transport_options["video"].ice_restart); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2518 | } |
| 2519 | |
| 2520 | // Test that a correct MediaSessionOptions is created for an offer if |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2521 | // OfferToReceiveVideo is set. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2522 | TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithVideo) { |
| 2523 | RTCOfferAnswerOptions rtc_options; |
| 2524 | rtc_options.offer_to_receive_audio = 0; |
| 2525 | rtc_options.offer_to_receive_video = 1; |
| 2526 | |
| 2527 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2528 | EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2529 | EXPECT_FALSE(options.has_audio()); |
| 2530 | EXPECT_TRUE(options.has_video()); |
| 2531 | EXPECT_TRUE(options.bundle_enabled); |
| 2532 | } |
| 2533 | |
| 2534 | // Test that a correct MediaSessionOptions is created for an offer if |
| 2535 | // UseRtpMux is set to false. |
| 2536 | TEST(CreateSessionOptionsTest, |
| 2537 | GetMediaSessionOptionsForOfferWithBundleDisabled) { |
| 2538 | RTCOfferAnswerOptions rtc_options; |
| 2539 | rtc_options.offer_to_receive_audio = 1; |
| 2540 | rtc_options.offer_to_receive_video = 1; |
| 2541 | rtc_options.use_rtp_mux = false; |
| 2542 | |
| 2543 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2544 | EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2545 | EXPECT_TRUE(options.has_audio()); |
| 2546 | EXPECT_TRUE(options.has_video()); |
| 2547 | EXPECT_FALSE(options.bundle_enabled); |
| 2548 | } |
| 2549 | |
| 2550 | // Test that a correct MediaSessionOptions is created to restart ice if |
| 2551 | // IceRestart is set. It also tests that subsequent MediaSessionOptions don't |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 2552 | // have |audio_transport_options.ice_restart| etc. set. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2553 | TEST(CreateSessionOptionsTest, GetMediaSessionOptionsForOfferWithIceRestart) { |
| 2554 | RTCOfferAnswerOptions rtc_options; |
| 2555 | rtc_options.ice_restart = true; |
| 2556 | |
| 2557 | cricket::MediaSessionOptions options; |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2558 | options.transport_options["audio"] = cricket::TransportOptions(); |
| 2559 | options.transport_options["video"] = cricket::TransportOptions(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2560 | EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2561 | EXPECT_TRUE(options.transport_options["audio"].ice_restart); |
| 2562 | EXPECT_TRUE(options.transport_options["video"].ice_restart); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2563 | |
| 2564 | rtc_options = RTCOfferAnswerOptions(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2565 | EXPECT_TRUE(ExtractMediaSessionOptions(rtc_options, &options)); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2566 | EXPECT_FALSE(options.transport_options["audio"].ice_restart); |
| 2567 | EXPECT_FALSE(options.transport_options["video"].ice_restart); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | // Test that the MediaConstraints in an answer don't affect if audio and video |
| 2571 | // is offered in an offer but that if kOfferToReceiveAudio or |
| 2572 | // kOfferToReceiveVideo constraints are true in an offer, the media type will be |
| 2573 | // included in subsequent answers. |
| 2574 | TEST(CreateSessionOptionsTest, MediaConstraintsInAnswer) { |
| 2575 | FakeConstraints answer_c; |
| 2576 | answer_c.SetMandatoryReceiveAudio(true); |
| 2577 | answer_c.SetMandatoryReceiveVideo(true); |
| 2578 | |
| 2579 | cricket::MediaSessionOptions answer_options; |
| 2580 | EXPECT_TRUE(ParseConstraintsForAnswer(&answer_c, &answer_options)); |
| 2581 | EXPECT_TRUE(answer_options.has_audio()); |
| 2582 | EXPECT_TRUE(answer_options.has_video()); |
| 2583 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2584 | RTCOfferAnswerOptions rtc_offer_options; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2585 | |
| 2586 | cricket::MediaSessionOptions offer_options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2587 | EXPECT_TRUE(ExtractMediaSessionOptions(rtc_offer_options, &offer_options)); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2588 | EXPECT_TRUE(offer_options.has_audio()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2589 | EXPECT_FALSE(offer_options.has_video()); |
| 2590 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2591 | RTCOfferAnswerOptions updated_rtc_offer_options; |
| 2592 | updated_rtc_offer_options.offer_to_receive_audio = 1; |
| 2593 | updated_rtc_offer_options.offer_to_receive_video = 1; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2594 | |
| 2595 | cricket::MediaSessionOptions updated_offer_options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2596 | EXPECT_TRUE(ExtractMediaSessionOptions(updated_rtc_offer_options, |
| 2597 | &updated_offer_options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2598 | EXPECT_TRUE(updated_offer_options.has_audio()); |
| 2599 | EXPECT_TRUE(updated_offer_options.has_video()); |
| 2600 | |
| 2601 | // Since an offer has been created with both audio and video, subsequent |
| 2602 | // offers and answers should contain both audio and video. |
| 2603 | // Answers will only contain the media types that exist in the offer |
| 2604 | // regardless of the value of |updated_answer_options.has_audio| and |
| 2605 | // |updated_answer_options.has_video|. |
| 2606 | FakeConstraints updated_answer_c; |
| 2607 | answer_c.SetMandatoryReceiveAudio(false); |
| 2608 | answer_c.SetMandatoryReceiveVideo(false); |
| 2609 | |
| 2610 | cricket::MediaSessionOptions updated_answer_options; |
| 2611 | EXPECT_TRUE( |
| 2612 | ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
| 2613 | EXPECT_TRUE(updated_answer_options.has_audio()); |
| 2614 | EXPECT_TRUE(updated_answer_options.has_video()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2615 | } |