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