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