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