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