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