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) { |
| 1911 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 1912 | // TODO(bugs.webrtc.org/8764): Re-enable when stats are supported with |
| 1913 | // Unified Plan. |
| 1914 | return; |
| 1915 | } |
| 1916 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1917 | InitiateCall(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1918 | ASSERT_LT(0u, pc_->GetSenders().size()); |
| 1919 | ASSERT_LT(0u, pc_->GetReceivers().size()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1920 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1921 | pc_->GetReceivers()[0]->track(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1922 | EXPECT_TRUE(DoGetStats(remote_audio)); |
| 1923 | |
| 1924 | // Remove the stream. Since we are sending to our selves the local |
| 1925 | // and the remote stream is the same. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1926 | pc_->RemoveTrack(pc_->GetSenders()[0]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1927 | // Do a re-negotiation. |
| 1928 | CreateOfferReceiveAnswer(); |
| 1929 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1930 | // Test that we still can get statistics for the old track. Even if it is not |
| 1931 | // sent any longer. |
| 1932 | EXPECT_TRUE(DoGetStats(remote_audio)); |
| 1933 | } |
| 1934 | |
| 1935 | // Test that we can get stats on a video track. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1936 | TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) { |
| 1937 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 1938 | // TODO(bugs.webrtc.org/8764): Re-enable when stats are supported with |
| 1939 | // Unified Plan. |
| 1940 | return; |
| 1941 | } |
| 1942 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1943 | InitiateCall(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1944 | auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 1945 | ASSERT_TRUE(video_receiver); |
| 1946 | EXPECT_TRUE(DoGetStats(video_receiver->track())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | // Test that we don't get statistics for an invalid track. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1950 | TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) { |
| 1951 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 1952 | // TODO(bugs.webrtc.org/8764): Re-enable when stats are supported with |
| 1953 | // Unified Plan. |
| 1954 | return; |
| 1955 | } |
| 1956 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1957 | InitiateCall(); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1958 | rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1959 | pc_factory_->CreateAudioTrack("unknown track", NULL)); |
| 1960 | EXPECT_FALSE(DoGetStats(unknown_audio_track)); |
| 1961 | } |
| 1962 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1963 | TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) { |
| 1964 | if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) { |
| 1965 | // TODO(bugs.webrtc.org/8764): Re-enable when stats are supported with |
| 1966 | // Unified Plan. |
| 1967 | return; |
| 1968 | } |
| 1969 | |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1970 | CreatePeerConnectionWithoutDtls(); |
| 1971 | EXPECT_TRUE(DoGetRTCStats()); |
| 1972 | // Clearing stats cache is needed now, but should be temporary. |
| 1973 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693 |
| 1974 | pc_->ClearStatsCache(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1975 | AddAudioTrack(kAudioTracks[0], {kStreamLabel1}); |
| 1976 | AddVideoTrack(kVideoTracks[0], {kStreamLabel1}); |
Harald Alvestrand | 8906187 | 2018-01-02 14:08:34 +0100 | [diff] [blame] | 1977 | EXPECT_TRUE(DoGetRTCStats()); |
| 1978 | pc_->ClearStatsCache(); |
| 1979 | CreateOfferReceiveAnswer(); |
| 1980 | EXPECT_TRUE(DoGetRTCStats()); |
| 1981 | } |
| 1982 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1983 | // This test setup two RTP data channels in loop back. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 1984 | TEST_P(PeerConnectionInterfaceTest, TestDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1985 | FakeConstraints constraints; |
| 1986 | constraints.SetAllowRtpDataChannels(); |
| 1987 | CreatePeerConnection(&constraints); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1988 | rtc::scoped_refptr<DataChannelInterface> data1 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1989 | pc_->CreateDataChannel("test1", NULL); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 1990 | rtc::scoped_refptr<DataChannelInterface> data2 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1991 | pc_->CreateDataChannel("test2", NULL); |
| 1992 | ASSERT_TRUE(data1 != NULL); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1993 | std::unique_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1994 | new MockDataChannelObserver(data1)); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1995 | std::unique_ptr<MockDataChannelObserver> observer2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1996 | new MockDataChannelObserver(data2)); |
| 1997 | |
| 1998 | EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); |
| 1999 | EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); |
| 2000 | std::string data_to_send1 = "testing testing"; |
| 2001 | std::string data_to_send2 = "testing something else"; |
| 2002 | EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1))); |
| 2003 | |
| 2004 | CreateOfferReceiveAnswer(); |
| 2005 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 2006 | EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); |
| 2007 | |
| 2008 | EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); |
| 2009 | EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); |
| 2010 | EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1))); |
| 2011 | EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); |
| 2012 | |
| 2013 | EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout); |
| 2014 | EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); |
| 2015 | |
| 2016 | data1->Close(); |
| 2017 | EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); |
| 2018 | CreateOfferReceiveAnswer(); |
| 2019 | EXPECT_FALSE(observer1->IsOpen()); |
| 2020 | EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); |
| 2021 | EXPECT_TRUE(observer2->IsOpen()); |
| 2022 | |
| 2023 | data_to_send2 = "testing something else again"; |
| 2024 | EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2))); |
| 2025 | |
| 2026 | EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout); |
| 2027 | } |
| 2028 | |
| 2029 | // This test verifies that sendnig binary data over RTP data channels should |
| 2030 | // fail. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2031 | TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2032 | FakeConstraints constraints; |
| 2033 | constraints.SetAllowRtpDataChannels(); |
| 2034 | CreatePeerConnection(&constraints); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2035 | rtc::scoped_refptr<DataChannelInterface> data1 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2036 | pc_->CreateDataChannel("test1", NULL); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2037 | rtc::scoped_refptr<DataChannelInterface> data2 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2038 | pc_->CreateDataChannel("test2", NULL); |
| 2039 | ASSERT_TRUE(data1 != NULL); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2040 | std::unique_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2041 | new MockDataChannelObserver(data1)); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2042 | std::unique_ptr<MockDataChannelObserver> observer2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2043 | new MockDataChannelObserver(data2)); |
| 2044 | |
| 2045 | EXPECT_EQ(DataChannelInterface::kConnecting, data1->state()); |
| 2046 | EXPECT_EQ(DataChannelInterface::kConnecting, data2->state()); |
| 2047 | |
| 2048 | CreateOfferReceiveAnswer(); |
| 2049 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 2050 | EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); |
| 2051 | |
| 2052 | EXPECT_EQ(DataChannelInterface::kOpen, data1->state()); |
| 2053 | EXPECT_EQ(DataChannelInterface::kOpen, data2->state()); |
| 2054 | |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 2055 | rtc::CopyOnWriteBuffer buffer("test", 4); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2056 | EXPECT_FALSE(data1->Send(DataBuffer(buffer, true))); |
| 2057 | } |
| 2058 | |
| 2059 | // This test setup a RTP data channels in loop back and test that a channel is |
| 2060 | // opened even if the remote end answer with a zero SSRC. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2061 | TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2062 | FakeConstraints constraints; |
| 2063 | constraints.SetAllowRtpDataChannels(); |
| 2064 | CreatePeerConnection(&constraints); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2065 | rtc::scoped_refptr<DataChannelInterface> data1 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2066 | pc_->CreateDataChannel("test1", NULL); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2067 | std::unique_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2068 | new MockDataChannelObserver(data1)); |
| 2069 | |
| 2070 | CreateOfferReceiveAnswerWithoutSsrc(); |
| 2071 | |
| 2072 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 2073 | |
| 2074 | data1->Close(); |
| 2075 | EXPECT_EQ(DataChannelInterface::kClosing, data1->state()); |
| 2076 | CreateOfferReceiveAnswerWithoutSsrc(); |
| 2077 | EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); |
| 2078 | EXPECT_FALSE(observer1->IsOpen()); |
| 2079 | } |
| 2080 | |
| 2081 | // This test that if a data channel is added in an answer a receive only channel |
| 2082 | // channel is created. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2083 | TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2084 | FakeConstraints constraints; |
| 2085 | constraints.SetAllowRtpDataChannels(); |
| 2086 | CreatePeerConnection(&constraints); |
| 2087 | |
| 2088 | std::string offer_label = "offer_channel"; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2089 | rtc::scoped_refptr<DataChannelInterface> offer_channel = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2090 | pc_->CreateDataChannel(offer_label, NULL); |
| 2091 | |
| 2092 | CreateOfferAsLocalDescription(); |
| 2093 | |
| 2094 | // Replace the data channel label in the offer and apply it as an answer. |
| 2095 | std::string receive_label = "answer_channel"; |
| 2096 | std::string sdp; |
| 2097 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2098 | rtc::replace_substrs(offer_label.c_str(), offer_label.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2099 | receive_label.c_str(), receive_label.length(), |
| 2100 | &sdp); |
| 2101 | CreateAnswerAsRemoteDescription(sdp); |
| 2102 | |
| 2103 | // Verify that a new incoming data channel has been created and that |
| 2104 | // it is open but can't we written to. |
| 2105 | ASSERT_TRUE(observer_.last_datachannel_ != NULL); |
| 2106 | DataChannelInterface* received_channel = observer_.last_datachannel_; |
| 2107 | EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state()); |
| 2108 | EXPECT_EQ(receive_label, received_channel->label()); |
| 2109 | EXPECT_FALSE(received_channel->Send(DataBuffer("something"))); |
| 2110 | |
| 2111 | // Verify that the channel we initially offered has been rejected. |
| 2112 | EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); |
| 2113 | |
| 2114 | // Do another offer / answer exchange and verify that the data channel is |
| 2115 | // opened. |
| 2116 | CreateOfferReceiveAnswer(); |
| 2117 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(), |
| 2118 | kTimeout); |
| 2119 | } |
| 2120 | |
| 2121 | // This test that no data channel is returned if a reliable channel is |
| 2122 | // requested. |
| 2123 | // TODO(perkj): Remove this test once reliable channels are implemented. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2124 | TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2125 | FakeConstraints constraints; |
| 2126 | constraints.SetAllowRtpDataChannels(); |
| 2127 | CreatePeerConnection(&constraints); |
| 2128 | |
| 2129 | std::string label = "test"; |
| 2130 | webrtc::DataChannelInit config; |
| 2131 | config.reliable = true; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2132 | rtc::scoped_refptr<DataChannelInterface> channel = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2133 | pc_->CreateDataChannel(label, &config); |
| 2134 | EXPECT_TRUE(channel == NULL); |
| 2135 | } |
| 2136 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2137 | // Verifies that duplicated label is not allowed for RTP data channel. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2138 | TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2139 | FakeConstraints constraints; |
| 2140 | constraints.SetAllowRtpDataChannels(); |
| 2141 | CreatePeerConnection(&constraints); |
| 2142 | |
| 2143 | std::string label = "test"; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2144 | rtc::scoped_refptr<DataChannelInterface> channel = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2145 | pc_->CreateDataChannel(label, nullptr); |
| 2146 | EXPECT_NE(channel, nullptr); |
| 2147 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2148 | rtc::scoped_refptr<DataChannelInterface> dup_channel = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2149 | pc_->CreateDataChannel(label, nullptr); |
| 2150 | EXPECT_EQ(dup_channel, nullptr); |
| 2151 | } |
| 2152 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2153 | // This tests that a SCTP data channel is returned using different |
| 2154 | // DataChannelInit configurations. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2155 | TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2156 | FakeConstraints constraints; |
| 2157 | constraints.SetAllowDtlsSctpDataChannels(); |
| 2158 | CreatePeerConnection(&constraints); |
| 2159 | |
| 2160 | webrtc::DataChannelInit config; |
| 2161 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2162 | rtc::scoped_refptr<DataChannelInterface> channel = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2163 | pc_->CreateDataChannel("1", &config); |
| 2164 | EXPECT_TRUE(channel != NULL); |
| 2165 | EXPECT_TRUE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2166 | EXPECT_TRUE(observer_.renegotiation_needed_); |
| 2167 | observer_.renegotiation_needed_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2168 | |
| 2169 | config.ordered = false; |
| 2170 | channel = pc_->CreateDataChannel("2", &config); |
| 2171 | EXPECT_TRUE(channel != NULL); |
| 2172 | EXPECT_TRUE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2173 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2174 | |
| 2175 | config.ordered = true; |
| 2176 | config.maxRetransmits = 0; |
| 2177 | channel = pc_->CreateDataChannel("3", &config); |
| 2178 | EXPECT_TRUE(channel != NULL); |
| 2179 | EXPECT_FALSE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2180 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2181 | |
| 2182 | config.maxRetransmits = -1; |
| 2183 | config.maxRetransmitTime = 0; |
| 2184 | channel = pc_->CreateDataChannel("4", &config); |
| 2185 | EXPECT_TRUE(channel != NULL); |
| 2186 | EXPECT_FALSE(channel->reliable()); |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2187 | EXPECT_FALSE(observer_.renegotiation_needed_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2188 | } |
| 2189 | |
| 2190 | // This tests that no data channel is returned if both maxRetransmits and |
| 2191 | // maxRetransmitTime are set for SCTP data channels. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2192 | TEST_P(PeerConnectionInterfaceTest, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2193 | CreateSctpDataChannelShouldFailForInvalidConfig) { |
| 2194 | FakeConstraints constraints; |
| 2195 | constraints.SetAllowDtlsSctpDataChannels(); |
| 2196 | CreatePeerConnection(&constraints); |
| 2197 | |
| 2198 | std::string label = "test"; |
| 2199 | webrtc::DataChannelInit config; |
| 2200 | config.maxRetransmits = 0; |
| 2201 | config.maxRetransmitTime = 0; |
| 2202 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2203 | rtc::scoped_refptr<DataChannelInterface> channel = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2204 | pc_->CreateDataChannel(label, &config); |
| 2205 | EXPECT_TRUE(channel == NULL); |
| 2206 | } |
| 2207 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2208 | // The test verifies that creating a SCTP data channel with an id already in use |
| 2209 | // or out of range should fail. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2210 | TEST_P(PeerConnectionInterfaceTest, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2211 | CreateSctpDataChannelWithInvalidIdShouldFail) { |
| 2212 | FakeConstraints constraints; |
| 2213 | constraints.SetAllowDtlsSctpDataChannels(); |
| 2214 | CreatePeerConnection(&constraints); |
| 2215 | |
| 2216 | webrtc::DataChannelInit config; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2217 | rtc::scoped_refptr<DataChannelInterface> channel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2218 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 2219 | config.id = 1; |
| 2220 | channel = pc_->CreateDataChannel("1", &config); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2221 | EXPECT_TRUE(channel != NULL); |
| 2222 | EXPECT_EQ(1, channel->id()); |
| 2223 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2224 | channel = pc_->CreateDataChannel("x", &config); |
| 2225 | EXPECT_TRUE(channel == NULL); |
| 2226 | |
| 2227 | config.id = cricket::kMaxSctpSid; |
| 2228 | channel = pc_->CreateDataChannel("max", &config); |
| 2229 | EXPECT_TRUE(channel != NULL); |
| 2230 | EXPECT_EQ(config.id, channel->id()); |
| 2231 | |
| 2232 | config.id = cricket::kMaxSctpSid + 1; |
| 2233 | channel = pc_->CreateDataChannel("x", &config); |
| 2234 | EXPECT_TRUE(channel == NULL); |
| 2235 | } |
| 2236 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2237 | // Verifies that duplicated label is allowed for SCTP data channel. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2238 | TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2239 | FakeConstraints constraints; |
| 2240 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2241 | true); |
| 2242 | CreatePeerConnection(&constraints); |
| 2243 | |
| 2244 | std::string label = "test"; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2245 | rtc::scoped_refptr<DataChannelInterface> channel = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2246 | pc_->CreateDataChannel(label, nullptr); |
| 2247 | EXPECT_NE(channel, nullptr); |
| 2248 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2249 | rtc::scoped_refptr<DataChannelInterface> dup_channel = |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2250 | pc_->CreateDataChannel(label, nullptr); |
| 2251 | EXPECT_NE(dup_channel, nullptr); |
| 2252 | } |
| 2253 | |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2254 | // This test verifies that OnRenegotiationNeeded is fired for every new RTP |
| 2255 | // DataChannel. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2256 | TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) { |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2257 | FakeConstraints constraints; |
| 2258 | constraints.SetAllowRtpDataChannels(); |
| 2259 | CreatePeerConnection(&constraints); |
| 2260 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2261 | rtc::scoped_refptr<DataChannelInterface> dc1 = |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2262 | pc_->CreateDataChannel("test1", NULL); |
| 2263 | EXPECT_TRUE(observer_.renegotiation_needed_); |
| 2264 | observer_.renegotiation_needed_ = false; |
| 2265 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2266 | rtc::scoped_refptr<DataChannelInterface> dc2 = |
jiayl@webrtc.org | 001fd2d | 2014-05-29 15:31:11 +0000 | [diff] [blame] | 2267 | pc_->CreateDataChannel("test2", NULL); |
| 2268 | EXPECT_TRUE(observer_.renegotiation_needed_); |
| 2269 | } |
| 2270 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2271 | // 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] | 2272 | TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2273 | FakeConstraints constraints; |
| 2274 | constraints.SetAllowRtpDataChannels(); |
| 2275 | CreatePeerConnection(&constraints); |
| 2276 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2277 | rtc::scoped_refptr<DataChannelInterface> data1 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2278 | pc_->CreateDataChannel("test1", NULL); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2279 | rtc::scoped_refptr<DataChannelInterface> data2 = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2280 | pc_->CreateDataChannel("test2", NULL); |
| 2281 | ASSERT_TRUE(data1 != NULL); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2282 | std::unique_ptr<MockDataChannelObserver> observer1( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2283 | new MockDataChannelObserver(data1)); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2284 | std::unique_ptr<MockDataChannelObserver> observer2( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2285 | new MockDataChannelObserver(data2)); |
| 2286 | |
| 2287 | CreateOfferReceiveAnswer(); |
| 2288 | EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout); |
| 2289 | EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout); |
| 2290 | |
| 2291 | ReleasePeerConnection(); |
| 2292 | EXPECT_EQ(DataChannelInterface::kClosed, data1->state()); |
| 2293 | EXPECT_EQ(DataChannelInterface::kClosed, data2->state()); |
| 2294 | } |
| 2295 | |
| 2296 | // This test that data channels can be rejected in an answer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2297 | TEST_P(PeerConnectionInterfaceTest, TestRejectDataChannelInAnswer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2298 | FakeConstraints constraints; |
| 2299 | constraints.SetAllowRtpDataChannels(); |
| 2300 | CreatePeerConnection(&constraints); |
| 2301 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2302 | rtc::scoped_refptr<DataChannelInterface> offer_channel( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2303 | pc_->CreateDataChannel("offer_channel", NULL)); |
| 2304 | |
| 2305 | CreateOfferAsLocalDescription(); |
| 2306 | |
| 2307 | // Create an answer where the m-line for data channels are rejected. |
| 2308 | std::string sdp; |
| 2309 | EXPECT_TRUE(pc_->local_description()->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2310 | std::unique_ptr<SessionDescriptionInterface> answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2311 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2312 | ASSERT_TRUE(answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2313 | cricket::ContentInfo* data_info = |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2314 | cricket::GetFirstDataContent(answer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2315 | data_info->rejected = true; |
| 2316 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2317 | DoSetRemoteDescription(std::move(answer)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2318 | EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state()); |
| 2319 | } |
| 2320 | |
| 2321 | // Test that we can create a session description from an SDP string from |
| 2322 | // FireFox, use it as a remote session description, generate an answer and use |
| 2323 | // the answer as a local description. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2324 | TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2325 | FakeConstraints constraints; |
| 2326 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2327 | true); |
| 2328 | CreatePeerConnection(&constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2329 | AddAudioTrack("audio_label"); |
| 2330 | AddVideoTrack("video_label"); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2331 | std::unique_ptr<SessionDescriptionInterface> desc( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2332 | webrtc::CreateSessionDescription(SdpType::kOffer, |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2333 | webrtc::kFireFoxSdpOffer, nullptr)); |
| 2334 | EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2335 | CreateAnswerAsLocalDescription(); |
| 2336 | ASSERT_TRUE(pc_->local_description() != NULL); |
| 2337 | ASSERT_TRUE(pc_->remote_description() != NULL); |
| 2338 | |
| 2339 | const cricket::ContentInfo* content = |
| 2340 | cricket::GetFirstAudioContent(pc_->local_description()->description()); |
| 2341 | ASSERT_TRUE(content != NULL); |
| 2342 | EXPECT_FALSE(content->rejected); |
| 2343 | |
| 2344 | content = |
| 2345 | cricket::GetFirstVideoContent(pc_->local_description()->description()); |
| 2346 | ASSERT_TRUE(content != NULL); |
| 2347 | EXPECT_FALSE(content->rejected); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 2348 | #ifdef HAVE_SCTP |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2349 | content = |
| 2350 | cricket::GetFirstDataContent(pc_->local_description()->description()); |
| 2351 | ASSERT_TRUE(content != NULL); |
Taylor Brandstetter | 74cefe1 | 2017-12-14 15:38:57 -0800 | [diff] [blame] | 2352 | // Expected to fail since it's using an incompatible format. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2353 | EXPECT_TRUE(content->rejected); |
sergeyu@chromium.org | a23f0ca | 2013-11-13 22:48:52 +0000 | [diff] [blame] | 2354 | #endif |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2355 | } |
| 2356 | |
zhihuang | b19012e | 2017-09-19 13:47:59 -0700 | [diff] [blame] | 2357 | // Test that fallback from DTLS to SDES is not supported. |
| 2358 | // The fallback was previously supported but was removed to simplify the code |
| 2359 | // and because it's non-standard. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2360 | TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) { |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 2361 | FakeConstraints constraints; |
| 2362 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2363 | true); |
| 2364 | CreatePeerConnection(&constraints); |
| 2365 | // Wait for fake certificate to be generated. Previously, this is what caused |
| 2366 | // the "a=crypto" lines to be rejected. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2367 | AddAudioTrack("audio_label"); |
| 2368 | AddVideoTrack("video_label"); |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 2369 | ASSERT_NE(nullptr, fake_certificate_generator_); |
| 2370 | EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(), |
| 2371 | kTimeout); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2372 | std::unique_ptr<SessionDescriptionInterface> desc( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2373 | webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp, |
| 2374 | nullptr)); |
zhihuang | b19012e | 2017-09-19 13:47:59 -0700 | [diff] [blame] | 2375 | EXPECT_FALSE(DoSetSessionDescription(std::move(desc), false)); |
deadbeef | 8662f94 | 2017-01-20 21:20:51 -0800 | [diff] [blame] | 2376 | } |
| 2377 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2378 | // Test that we can create an audio only offer and receive an answer with a |
| 2379 | // limited set of audio codecs and receive an updated offer with more audio |
| 2380 | // codecs, where the added codecs are not supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2381 | TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2382 | CreatePeerConnectionWithoutDtls(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2383 | AddAudioTrack("audio_label"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2384 | CreateOfferAsLocalDescription(); |
| 2385 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2386 | const char* answer_sdp = |
| 2387 | (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB |
| 2388 | : webrtc::kAudioSdpUnifiedPlan); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2389 | std::unique_ptr<SessionDescriptionInterface> answer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2390 | webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2391 | EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2392 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2393 | const char* reoffer_sdp = |
| 2394 | (sdp_semantics_ == SdpSemantics::kPlanB |
| 2395 | ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB |
| 2396 | : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2397 | std::unique_ptr<SessionDescriptionInterface> updated_offer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2398 | webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2399 | EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2400 | CreateAnswerAsLocalDescription(); |
| 2401 | } |
| 2402 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2403 | // Test that if we're receiving (but not sending) a track, subsequent offers |
| 2404 | // will have m-lines with a=recvonly. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2405 | TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) { |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2406 | FakeConstraints constraints; |
| 2407 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2408 | true); |
| 2409 | CreatePeerConnection(&constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2410 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2411 | CreateAnswerAsLocalDescription(); |
| 2412 | |
| 2413 | // At this point we should be receiving stream 1, but not sending anything. |
| 2414 | // A new offer should be recvonly. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2415 | std::unique_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2416 | DoCreateOffer(&offer, nullptr); |
| 2417 | |
| 2418 | const cricket::ContentInfo* video_content = |
| 2419 | cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2420 | ASSERT_EQ(RtpTransceiverDirection::kRecvOnly, |
| 2421 | video_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2422 | |
| 2423 | const cricket::ContentInfo* audio_content = |
| 2424 | cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2425 | ASSERT_EQ(RtpTransceiverDirection::kRecvOnly, |
| 2426 | audio_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
| 2429 | // Test that if we're receiving (but not sending) a track, and the |
| 2430 | // offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to |
| 2431 | // false, the generated m-lines will be a=inactive. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2432 | TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) { |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2433 | FakeConstraints constraints; |
| 2434 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2435 | true); |
| 2436 | CreatePeerConnection(&constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2437 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2438 | CreateAnswerAsLocalDescription(); |
| 2439 | |
| 2440 | // At this point we should be receiving stream 1, but not sending anything. |
| 2441 | // A new offer would be recvonly, but we'll set the "no receive" constraints |
| 2442 | // to make it inactive. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2443 | std::unique_ptr<SessionDescriptionInterface> offer; |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2444 | FakeConstraints offer_constraints; |
| 2445 | offer_constraints.AddMandatory( |
| 2446 | webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, false); |
| 2447 | offer_constraints.AddMandatory( |
| 2448 | webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, false); |
| 2449 | DoCreateOffer(&offer, &offer_constraints); |
| 2450 | |
| 2451 | const cricket::ContentInfo* video_content = |
| 2452 | cricket::GetFirstVideoContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2453 | ASSERT_EQ(RtpTransceiverDirection::kInactive, |
| 2454 | video_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2455 | |
| 2456 | const cricket::ContentInfo* audio_content = |
| 2457 | cricket::GetFirstAudioContent(offer->description()); |
Steve Anton | b1c1de1 | 2017-12-21 15:14:30 -0800 | [diff] [blame] | 2458 | ASSERT_EQ(RtpTransceiverDirection::kInactive, |
| 2459 | audio_content->media_description()->direction()); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 2460 | } |
| 2461 | |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2462 | // Test that we can use SetConfiguration to change the ICE servers of the |
| 2463 | // PortAllocator. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2464 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) { |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2465 | CreatePeerConnection(); |
| 2466 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2467 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2468 | PeerConnectionInterface::IceServer server; |
| 2469 | server.uri = "stun:test_hostname"; |
| 2470 | config.servers.push_back(server); |
| 2471 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 2472 | |
Taylor Brandstetter | 0c7e9f5 | 2015-12-29 14:14:52 -0800 | [diff] [blame] | 2473 | EXPECT_EQ(1u, port_allocator_->stun_servers().size()); |
| 2474 | EXPECT_EQ("test_hostname", |
| 2475 | port_allocator_->stun_servers().begin()->hostname()); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 2476 | } |
| 2477 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2478 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) { |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2479 | CreatePeerConnection(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2480 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2481 | config.type = PeerConnectionInterface::kRelay; |
| 2482 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 2483 | EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter()); |
| 2484 | } |
| 2485 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2486 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2487 | PeerConnectionInterface::RTCConfiguration config; |
| 2488 | config.prune_turn_ports = false; |
| 2489 | CreatePeerConnection(config, nullptr); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2490 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2491 | EXPECT_FALSE(port_allocator_->prune_turn_ports()); |
| 2492 | |
| 2493 | config.prune_turn_ports = true; |
| 2494 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 2495 | EXPECT_TRUE(port_allocator_->prune_turn_ports()); |
| 2496 | } |
| 2497 | |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2498 | // Test that the ice check interval can be changed. This does not verify that |
| 2499 | // the setting makes it all the way to P2PTransportChannel, as that would |
| 2500 | // require a very complex set of mocks. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2501 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) { |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2502 | PeerConnectionInterface::RTCConfiguration config; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 2503 | config.ice_check_min_interval = rtc::nullopt; |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2504 | CreatePeerConnection(config, nullptr); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2505 | config = pc_->GetConfiguration(); |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 2506 | config.ice_check_min_interval = 100; |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2507 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 2508 | PeerConnectionInterface::RTCConfiguration new_config = |
| 2509 | pc_->GetConfiguration(); |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 2510 | EXPECT_EQ(new_config.ice_check_min_interval, 100); |
skvlad | d1f5fda | 2017-02-03 16:54:05 -0800 | [diff] [blame] | 2511 | } |
| 2512 | |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2513 | // Test that when SetConfiguration changes both the pool size and other |
| 2514 | // attributes, the pooled session is created with the updated attributes. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2515 | TEST_P(PeerConnectionInterfaceTest, |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2516 | SetConfigurationCreatesPooledSessionCorrectly) { |
| 2517 | CreatePeerConnection(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2518 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2519 | config.ice_candidate_pool_size = 1; |
| 2520 | PeerConnectionInterface::IceServer server; |
| 2521 | server.uri = kStunAddressOnly; |
| 2522 | config.servers.push_back(server); |
| 2523 | config.type = PeerConnectionInterface::kRelay; |
Taylor Brandstetter | 417eebe | 2016-05-23 16:02:19 -0700 | [diff] [blame] | 2524 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2525 | |
| 2526 | const cricket::FakePortAllocatorSession* session = |
| 2527 | static_cast<const cricket::FakePortAllocatorSession*>( |
| 2528 | port_allocator_->GetPooledSession()); |
| 2529 | ASSERT_NE(nullptr, session); |
| 2530 | EXPECT_EQ(1UL, session->stun_servers().size()); |
Taylor Brandstetter | a1c3035 | 2016-05-13 08:15:11 -0700 | [diff] [blame] | 2531 | } |
| 2532 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2533 | // Test that after SetLocalDescription, changing the pool size is not allowed, |
| 2534 | // and an invalid modification error is returned. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2535 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2536 | CantChangePoolSizeAfterSetLocalDescription) { |
| 2537 | CreatePeerConnection(); |
| 2538 | // Start by setting a size of 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2539 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2540 | config.ice_candidate_pool_size = 1; |
| 2541 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 2542 | |
| 2543 | // Set remote offer; can still change pool size at this point. |
| 2544 | CreateOfferAsRemoteDescription(); |
| 2545 | config.ice_candidate_pool_size = 2; |
| 2546 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 2547 | |
| 2548 | // Set local answer; now it's too late. |
| 2549 | CreateAnswerAsLocalDescription(); |
| 2550 | config.ice_candidate_pool_size = 3; |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2551 | RTCError error; |
| 2552 | EXPECT_FALSE(pc_->SetConfiguration(config, &error)); |
| 2553 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2554 | } |
| 2555 | |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2556 | // Test that after setting an answer, extra pooled sessions are discarded. The |
| 2557 | // 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] | 2558 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2559 | ExtraPooledSessionsDiscardedAfterApplyingAnswer) { |
| 2560 | CreatePeerConnection(); |
| 2561 | |
| 2562 | // Set a larger-than-necessary size. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2563 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2564 | config.ice_candidate_pool_size = 4; |
| 2565 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 2566 | |
| 2567 | // Do offer/answer. |
| 2568 | CreateOfferAsRemoteDescription(); |
| 2569 | CreateAnswerAsLocalDescription(); |
| 2570 | |
| 2571 | // Expect no pooled sessions to be left. |
| 2572 | const cricket::PortAllocatorSession* session = |
| 2573 | port_allocator_->GetPooledSession(); |
| 2574 | EXPECT_EQ(nullptr, session); |
| 2575 | } |
| 2576 | |
| 2577 | // After Close is called, pooled candidates should be discarded so as to not |
| 2578 | // waste network resources. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2579 | TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) { |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2580 | CreatePeerConnection(); |
| 2581 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2582 | PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration(); |
deadbeef | 42a4263 | 2017-03-10 15:18:00 -0800 | [diff] [blame] | 2583 | config.ice_candidate_pool_size = 3; |
| 2584 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 2585 | pc_->Close(); |
| 2586 | |
| 2587 | // Expect no pooled sessions to be left. |
| 2588 | const cricket::PortAllocatorSession* session = |
| 2589 | port_allocator_->GetPooledSession(); |
| 2590 | EXPECT_EQ(nullptr, session); |
| 2591 | } |
| 2592 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2593 | // Test that SetConfiguration returns an invalid modification error if |
| 2594 | // 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] | 2595 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2596 | SetConfigurationReturnsInvalidModificationError) { |
| 2597 | PeerConnectionInterface::RTCConfiguration config; |
| 2598 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced; |
| 2599 | config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate; |
| 2600 | config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE; |
| 2601 | CreatePeerConnection(config, nullptr); |
| 2602 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2603 | PeerConnectionInterface::RTCConfiguration modified_config = |
| 2604 | pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2605 | modified_config.bundle_policy = |
| 2606 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 2607 | RTCError error; |
| 2608 | EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error)); |
| 2609 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2610 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2611 | modified_config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2612 | modified_config.rtcp_mux_policy = |
| 2613 | PeerConnectionInterface::kRtcpMuxPolicyRequire; |
| 2614 | error.set_type(RTCErrorType::NONE); |
| 2615 | EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error)); |
| 2616 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2617 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2618 | modified_config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2619 | modified_config.continual_gathering_policy = |
| 2620 | PeerConnectionInterface::GATHER_CONTINUALLY; |
| 2621 | error.set_type(RTCErrorType::NONE); |
| 2622 | EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error)); |
| 2623 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type()); |
| 2624 | } |
| 2625 | |
| 2626 | // Test that SetConfiguration returns a range error if the candidate pool size |
| 2627 | // is negative or larger than allowed by the spec. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2628 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2629 | SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) { |
| 2630 | PeerConnectionInterface::RTCConfiguration config; |
| 2631 | CreatePeerConnection(config, nullptr); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2632 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2633 | |
| 2634 | config.ice_candidate_pool_size = -1; |
| 2635 | RTCError error; |
| 2636 | EXPECT_FALSE(pc_->SetConfiguration(config, &error)); |
| 2637 | EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type()); |
| 2638 | |
| 2639 | config.ice_candidate_pool_size = INT_MAX; |
| 2640 | error.set_type(RTCErrorType::NONE); |
| 2641 | EXPECT_FALSE(pc_->SetConfiguration(config, &error)); |
| 2642 | EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type()); |
| 2643 | } |
| 2644 | |
| 2645 | // Test that SetConfiguration returns a syntax error if parsing an ICE server |
| 2646 | // URL failed. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2647 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2648 | SetConfigurationReturnsSyntaxErrorFromBadIceUrls) { |
| 2649 | PeerConnectionInterface::RTCConfiguration config; |
| 2650 | CreatePeerConnection(config, nullptr); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2651 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2652 | |
| 2653 | PeerConnectionInterface::IceServer bad_server; |
| 2654 | bad_server.uri = "stunn:www.example.com"; |
| 2655 | config.servers.push_back(bad_server); |
| 2656 | RTCError error; |
| 2657 | EXPECT_FALSE(pc_->SetConfiguration(config, &error)); |
| 2658 | EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type()); |
| 2659 | } |
| 2660 | |
| 2661 | // Test that SetConfiguration returns an invalid parameter error if a TURN |
| 2662 | // IceServer is missing a username or password. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2663 | TEST_P(PeerConnectionInterfaceTest, |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2664 | SetConfigurationReturnsInvalidParameterIfCredentialsMissing) { |
| 2665 | PeerConnectionInterface::RTCConfiguration config; |
| 2666 | CreatePeerConnection(config, nullptr); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2667 | config = pc_->GetConfiguration(); |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2668 | |
| 2669 | PeerConnectionInterface::IceServer bad_server; |
| 2670 | bad_server.uri = "turn:www.example.com"; |
| 2671 | // Missing password. |
| 2672 | bad_server.username = "foo"; |
| 2673 | config.servers.push_back(bad_server); |
| 2674 | RTCError error; |
| 2675 | EXPECT_FALSE(pc_->SetConfiguration(config, &error)); |
| 2676 | EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type()); |
deadbeef | 6de92f9 | 2016-12-12 18:49:32 -0800 | [diff] [blame] | 2677 | } |
| 2678 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2679 | // Test that PeerConnection::Close changes the states to closed and all remote |
| 2680 | // tracks change state to ended. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2681 | TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2682 | // Initialize a PeerConnection and negotiate local and remote session |
| 2683 | // description. |
| 2684 | InitiateCall(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2685 | |
| 2686 | // With Plan B, verify the stream count. The analog with Unified Plan is the |
| 2687 | // RtpTransceiver count. |
| 2688 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2689 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
| 2690 | ASSERT_EQ(1u, pc_->remote_streams()->count()); |
| 2691 | } else { |
| 2692 | ASSERT_EQ(2u, pc_->GetTransceivers().size()); |
| 2693 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2694 | |
| 2695 | pc_->Close(); |
| 2696 | |
| 2697 | EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state()); |
| 2698 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed, |
| 2699 | pc_->ice_connection_state()); |
| 2700 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete, |
| 2701 | pc_->ice_gathering_state()); |
| 2702 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2703 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 2704 | EXPECT_EQ(1u, pc_->local_streams()->count()); |
| 2705 | EXPECT_EQ(1u, pc_->remote_streams()->count()); |
| 2706 | } else { |
| 2707 | // Verify that the RtpTransceivers are still present but all stopped. |
| 2708 | EXPECT_EQ(2u, pc_->GetTransceivers().size()); |
| 2709 | for (auto transceiver : pc_->GetTransceivers()) { |
| 2710 | EXPECT_TRUE(transceiver->stopped()); |
| 2711 | } |
| 2712 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2713 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2714 | auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO); |
| 2715 | ASSERT_TRUE(audio_receiver); |
| 2716 | auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 2717 | ASSERT_TRUE(video_receiver); |
| 2718 | |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2719 | // Track state may be updated asynchronously. |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2720 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2721 | audio_receiver->track()->state(), kTimeout); |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2722 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2723 | video_receiver->track()->state(), kTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | // Test that PeerConnection methods fails gracefully after |
| 2727 | // PeerConnection::Close has been called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2728 | // Don't run under Unified Plan since the stream API is not available. |
| 2729 | TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) { |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 2730 | CreatePeerConnectionWithoutDtls(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2731 | AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); |
| 2732 | CreateOfferAsRemoteDescription(); |
| 2733 | CreateAnswerAsLocalDescription(); |
| 2734 | |
| 2735 | ASSERT_EQ(1u, pc_->local_streams()->count()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2736 | rtc::scoped_refptr<MediaStreamInterface> local_stream = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2737 | pc_->local_streams()->at(0); |
| 2738 | |
| 2739 | pc_->Close(); |
| 2740 | |
| 2741 | pc_->RemoveStream(local_stream); |
perkj@webrtc.org | c2dd5ee | 2014-11-04 11:31:29 +0000 | [diff] [blame] | 2742 | EXPECT_FALSE(pc_->AddStream(local_stream)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2743 | |
| 2744 | ASSERT_FALSE(local_stream->GetAudioTracks().empty()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2745 | rtc::scoped_refptr<webrtc::DtmfSenderInterface> dtmf_sender( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2746 | pc_->CreateDtmfSender(local_stream->GetAudioTracks()[0])); |
wu@webrtc.org | 6603736 | 2013-08-13 00:09:35 +0000 | [diff] [blame] | 2747 | EXPECT_TRUE(NULL == dtmf_sender); // local stream has been removed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2748 | |
| 2749 | EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL); |
| 2750 | |
| 2751 | EXPECT_TRUE(pc_->local_description() != NULL); |
| 2752 | EXPECT_TRUE(pc_->remote_description() != NULL); |
| 2753 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2754 | std::unique_ptr<SessionDescriptionInterface> offer; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2755 | EXPECT_FALSE(DoCreateOffer(&offer, nullptr)); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2756 | std::unique_ptr<SessionDescriptionInterface> answer; |
Steve Anton | 8d3444d | 2017-10-20 15:30:51 -0700 | [diff] [blame] | 2757 | EXPECT_FALSE(DoCreateAnswer(&answer, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2758 | |
| 2759 | std::string sdp; |
| 2760 | ASSERT_TRUE(pc_->remote_description()->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2761 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2762 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2763 | EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2764 | |
| 2765 | ASSERT_TRUE(pc_->local_description()->ToString(&sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2766 | std::unique_ptr<SessionDescriptionInterface> local_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 2767 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2768 | EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | // Test that GetStats can still be called after PeerConnection::Close. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2772 | TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2773 | InitiateCall(); |
| 2774 | pc_->Close(); |
| 2775 | DoGetStats(NULL); |
| 2776 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2777 | |
| 2778 | // NOTE: The series of tests below come from what used to be |
| 2779 | // mediastreamsignaling_unittest.cc, and are mostly aimed at testing that |
| 2780 | // setting a remote or local description has the expected effects. |
| 2781 | |
| 2782 | // This test verifies that the remote MediaStreams corresponding to a received |
| 2783 | // SDP string is created. In this test the two separate MediaStreams are |
| 2784 | // signaled. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2785 | TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2786 | FakeConstraints constraints; |
| 2787 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2788 | true); |
| 2789 | CreatePeerConnection(&constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2790 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2791 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2792 | rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2793 | EXPECT_TRUE( |
| 2794 | CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 2795 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2796 | EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr); |
| 2797 | |
| 2798 | // Create a session description based on another SDP with another |
| 2799 | // MediaStream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2800 | CreateAndSetRemoteOffer(GetSdpStringWithStream1And2()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2801 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 2802 | rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2803 | EXPECT_TRUE( |
| 2804 | CompareStreamCollections(observer_.remote_streams(), reference2.get())); |
| 2805 | } |
| 2806 | |
| 2807 | // This test verifies that when remote tracks are added/removed from SDP, the |
| 2808 | // created remote streams are updated appropriately. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2809 | // Don't run under Unified Plan since this test uses Plan B SDP to test Plan B |
| 2810 | // specific behavior. |
| 2811 | TEST_F(PeerConnectionInterfaceTestPlanB, |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2812 | AddRemoveTrackFromExistingRemoteMediaStream) { |
| 2813 | FakeConstraints constraints; |
| 2814 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2815 | true); |
| 2816 | CreatePeerConnection(&constraints); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2817 | std::unique_ptr<SessionDescriptionInterface> desc_ms1 = |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2818 | CreateSessionDescriptionAndReference(1, 1); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2819 | EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2820 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 2821 | reference_collection_)); |
| 2822 | |
| 2823 | // Add extra audio and video tracks to the same MediaStream. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2824 | std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks = |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2825 | CreateSessionDescriptionAndReference(2, 2); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2826 | EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2827 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 2828 | reference_collection_)); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2829 | rtc::scoped_refptr<AudioTrackInterface> audio_track2 = |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2830 | observer_.remote_streams()->at(0)->GetAudioTracks()[1]; |
| 2831 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 2832 | rtc::scoped_refptr<VideoTrackInterface> video_track2 = |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2833 | observer_.remote_streams()->at(0)->GetVideoTracks()[1]; |
| 2834 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2835 | |
| 2836 | // Remove the extra audio and video tracks. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2837 | std::unique_ptr<SessionDescriptionInterface> desc_ms2 = |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2838 | CreateSessionDescriptionAndReference(1, 1); |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2839 | MockTrackObserver audio_track_observer(audio_track2); |
| 2840 | MockTrackObserver video_track_observer(video_track2); |
| 2841 | |
| 2842 | EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1)); |
| 2843 | EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2844 | EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2845 | EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), |
| 2846 | reference_collection_)); |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2847 | // Track state may be updated asynchronously. |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 2848 | EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2849 | audio_track2->state(), kTimeout); |
| 2850 | EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded, |
| 2851 | video_track2->state(), kTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | // This tests that remote tracks are ended if a local session description is set |
| 2855 | // that rejects the media content type. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2856 | TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2857 | FakeConstraints constraints; |
| 2858 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2859 | true); |
| 2860 | CreatePeerConnection(&constraints); |
| 2861 | // First create and set a remote offer, then reject its video content in our |
| 2862 | // answer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2863 | CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB); |
| 2864 | auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO); |
| 2865 | ASSERT_TRUE(audio_receiver); |
| 2866 | auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO); |
| 2867 | ASSERT_TRUE(video_receiver); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2868 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2869 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio = |
| 2870 | audio_receiver->track(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2871 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state()); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2872 | rtc::scoped_refptr<MediaStreamTrackInterface> remote_video = |
| 2873 | video_receiver->track(); |
| 2874 | EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2875 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2876 | std::unique_ptr<SessionDescriptionInterface> local_answer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2877 | EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2878 | cricket::ContentInfo* video_info = |
| 2879 | local_answer->description()->GetContentByName("video"); |
| 2880 | video_info->rejected = true; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2881 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer))); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2882 | EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state()); |
| 2883 | EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2884 | |
| 2885 | // Now create an offer where we reject both video and audio. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2886 | std::unique_ptr<SessionDescriptionInterface> local_offer; |
kwiberg | 2bbff99 | 2016-03-16 11:03:04 -0700 | [diff] [blame] | 2887 | EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2888 | video_info = local_offer->description()->GetContentByName("video"); |
| 2889 | ASSERT_TRUE(video_info != nullptr); |
| 2890 | video_info->rejected = true; |
| 2891 | cricket::ContentInfo* audio_info = |
| 2892 | local_offer->description()->GetContentByName("audio"); |
| 2893 | ASSERT_TRUE(audio_info != nullptr); |
| 2894 | audio_info->rejected = true; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2895 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer))); |
Taylor Brandstetter | d45b95c | 2016-03-29 13:16:52 -0700 | [diff] [blame] | 2896 | // Track state may be updated asynchronously. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2897 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(), |
| 2898 | kTimeout); |
| 2899 | EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(), |
| 2900 | kTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | // This tests that we won't crash if the remote track has been removed outside |
| 2904 | // of PeerConnection and then PeerConnection tries to reject the track. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2905 | // Don't run under Unified Plan since the stream API is not available. |
| 2906 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2907 | FakeConstraints constraints; |
| 2908 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2909 | true); |
| 2910 | CreatePeerConnection(&constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2911 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2912 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2913 | remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); |
| 2914 | remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); |
| 2915 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2916 | std::unique_ptr<SessionDescriptionInterface> local_answer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2917 | webrtc::CreateSessionDescription(SdpType::kAnswer, |
| 2918 | GetSdpStringWithStream1(), nullptr)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2919 | cricket::ContentInfo* video_info = |
| 2920 | local_answer->description()->GetContentByName("video"); |
| 2921 | video_info->rejected = true; |
| 2922 | cricket::ContentInfo* audio_info = |
| 2923 | local_answer->description()->GetContentByName("audio"); |
| 2924 | audio_info->rejected = true; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 2925 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2926 | |
| 2927 | // No crash is a pass. |
| 2928 | } |
| 2929 | |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2930 | // This tests that if a recvonly remote description is set, no remote streams |
| 2931 | // will be created, even if the description contains SSRCs/MSIDs. |
| 2932 | // See: https://code.google.com/p/webrtc/issues/detail?id=5054 |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2933 | TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) { |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2934 | FakeConstraints constraints; |
| 2935 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2936 | true); |
| 2937 | CreatePeerConnection(&constraints); |
| 2938 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2939 | std::string recvonly_offer = GetSdpStringWithStream1(); |
deadbeef | 5e97fb5 | 2015-10-15 12:49:08 -0700 | [diff] [blame] | 2940 | rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly, |
| 2941 | strlen(kRecvonly), &recvonly_offer); |
| 2942 | CreateAndSetRemoteOffer(recvonly_offer); |
| 2943 | |
| 2944 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 2945 | } |
| 2946 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2947 | // This tests that a default MediaStream is created if a remote session |
| 2948 | // description doesn't contain any streams and no MSID support. |
| 2949 | // It also tests that the default stream is updated if a video m-line is added |
| 2950 | // in a subsequent session description. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2951 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2952 | TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2953 | FakeConstraints constraints; |
| 2954 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2955 | true); |
| 2956 | CreatePeerConnection(&constraints); |
| 2957 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 2958 | |
| 2959 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2960 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2961 | |
| 2962 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2963 | EXPECT_EQ(0u, remote_stream->GetVideoTracks().size()); |
| 2964 | EXPECT_EQ("default", remote_stream->label()); |
| 2965 | |
| 2966 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 2967 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2968 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2969 | EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id()); |
deadbeef | 884f585 | 2016-01-15 09:20:04 -0800 | [diff] [blame] | 2970 | EXPECT_EQ(MediaStreamTrackInterface::kLive, |
| 2971 | remote_stream->GetAudioTracks()[0]->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2972 | ASSERT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 2973 | EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id()); |
deadbeef | 884f585 | 2016-01-15 09:20:04 -0800 | [diff] [blame] | 2974 | EXPECT_EQ(MediaStreamTrackInterface::kLive, |
| 2975 | remote_stream->GetVideoTracks()[0]->state()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | // This tests that a default MediaStream is created if a remote session |
| 2979 | // description doesn't contain any streams and media direction is send only. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2980 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 2981 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 2982 | SendOnlySdpWithoutMsidCreatesDefaultStream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2983 | FakeConstraints constraints; |
| 2984 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 2985 | true); |
| 2986 | CreatePeerConnection(&constraints); |
| 2987 | CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams); |
| 2988 | |
| 2989 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 2990 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 2991 | |
| 2992 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 2993 | EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 2994 | EXPECT_EQ("default", remote_stream->label()); |
| 2995 | } |
| 2996 | |
| 2997 | // This tests that it won't crash when PeerConnection tries to remove |
| 2998 | // a remote track that as already been removed from the MediaStream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 2999 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3000 | TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3001 | FakeConstraints constraints; |
| 3002 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3003 | true); |
| 3004 | CreatePeerConnection(&constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3005 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3006 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 3007 | remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]); |
| 3008 | remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]); |
| 3009 | |
| 3010 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 3011 | |
| 3012 | // No crash is a pass. |
| 3013 | } |
| 3014 | |
| 3015 | // This tests that a default MediaStream is created if the remote session |
| 3016 | // description doesn't contain any streams and don't contain an indication if |
| 3017 | // MSID is supported. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3018 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3019 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 3020 | SdpWithoutMsidAndStreamsCreatesDefaultStream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3021 | FakeConstraints constraints; |
| 3022 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3023 | true); |
| 3024 | CreatePeerConnection(&constraints); |
| 3025 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 3026 | |
| 3027 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 3028 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 3029 | EXPECT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 3030 | EXPECT_EQ(1u, remote_stream->GetVideoTracks().size()); |
| 3031 | } |
| 3032 | |
| 3033 | // This tests that a default MediaStream is not created if the remote session |
| 3034 | // description doesn't contain any streams but does support MSID. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3035 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3036 | TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3037 | FakeConstraints constraints; |
| 3038 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3039 | true); |
| 3040 | CreatePeerConnection(&constraints); |
| 3041 | CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams); |
| 3042 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 3043 | } |
| 3044 | |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 3045 | // This tests that when setting a new description, the old default tracks are |
| 3046 | // not destroyed and recreated. |
| 3047 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250 |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3048 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3049 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 3050 | DefaultTracksNotDestroyedAndRecreated) { |
deadbeef | bda7e0b | 2015-12-08 17:13:40 -0800 | [diff] [blame] | 3051 | FakeConstraints constraints; |
| 3052 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3053 | true); |
| 3054 | CreatePeerConnection(&constraints); |
| 3055 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 3056 | |
| 3057 | ASSERT_EQ(1u, observer_.remote_streams()->count()); |
| 3058 | MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0); |
| 3059 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 3060 | |
| 3061 | // Set the track to "disabled", then set a new description and ensure the |
| 3062 | // track is still disabled, which ensures it hasn't been recreated. |
| 3063 | remote_stream->GetAudioTracks()[0]->set_enabled(false); |
| 3064 | CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly); |
| 3065 | ASSERT_EQ(1u, remote_stream->GetAudioTracks().size()); |
| 3066 | EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled()); |
| 3067 | } |
| 3068 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3069 | // This tests that a default MediaStream is not created if a remote session |
| 3070 | // description is updated to not have any MediaStreams. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3071 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3072 | TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3073 | FakeConstraints constraints; |
| 3074 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3075 | true); |
| 3076 | CreatePeerConnection(&constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3077 | CreateAndSetRemoteOffer(GetSdpStringWithStream1()); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3078 | rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3079 | EXPECT_TRUE( |
| 3080 | CompareStreamCollections(observer_.remote_streams(), reference.get())); |
| 3081 | |
| 3082 | CreateAndSetRemoteOffer(kSdpStringWithoutStreams); |
| 3083 | EXPECT_EQ(0u, observer_.remote_streams()->count()); |
| 3084 | } |
| 3085 | |
| 3086 | // This tests that an RtpSender is created when the local description is set |
| 3087 | // after adding a local stream. |
| 3088 | // TODO(deadbeef): This test and the one below it need to be updated when |
| 3089 | // 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] | 3090 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3091 | TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3092 | FakeConstraints constraints; |
| 3093 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3094 | true); |
| 3095 | CreatePeerConnection(&constraints); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3096 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3097 | // Create an offer with 1 stream with 2 tracks of each type. |
| 3098 | rtc::scoped_refptr<StreamCollection> stream_collection = |
| 3099 | CreateStreamCollection(1, 2); |
| 3100 | pc_->AddStream(stream_collection->at(0)); |
| 3101 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3102 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3103 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3104 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3105 | auto senders = pc_->GetSenders(); |
| 3106 | EXPECT_EQ(4u, senders.size()); |
| 3107 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3108 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3109 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 3110 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 3111 | |
| 3112 | // Remove an audio and video track. |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3113 | pc_->RemoveStream(stream_collection->at(0)); |
| 3114 | stream_collection = CreateStreamCollection(1, 1); |
| 3115 | pc_->AddStream(stream_collection->at(0)); |
| 3116 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3117 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3118 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3119 | senders = pc_->GetSenders(); |
| 3120 | EXPECT_EQ(2u, senders.size()); |
| 3121 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3122 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3123 | EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1])); |
| 3124 | EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1])); |
| 3125 | } |
| 3126 | |
| 3127 | // This tests that an RtpSender is created when the local description is set |
| 3128 | // before adding a local stream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3129 | // Don't run under Unified Plan since this behavior is Plan B specific. |
| 3130 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 3131 | AddLocalStreamAfterLocalDescriptionChanged) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3132 | FakeConstraints constraints; |
| 3133 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3134 | true); |
| 3135 | CreatePeerConnection(&constraints); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3136 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3137 | rtc::scoped_refptr<StreamCollection> stream_collection = |
| 3138 | CreateStreamCollection(1, 2); |
| 3139 | // Add a stream to create the offer, but remove it afterwards. |
| 3140 | pc_->AddStream(stream_collection->at(0)); |
| 3141 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3142 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3143 | pc_->RemoveStream(stream_collection->at(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3144 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3145 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3146 | auto senders = pc_->GetSenders(); |
| 3147 | EXPECT_EQ(0u, senders.size()); |
| 3148 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3149 | pc_->AddStream(stream_collection->at(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3150 | senders = pc_->GetSenders(); |
| 3151 | EXPECT_EQ(4u, senders.size()); |
| 3152 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3153 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3154 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1])); |
| 3155 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1])); |
| 3156 | } |
| 3157 | |
| 3158 | // This tests that the expected behavior occurs if the SSRC on a local track is |
| 3159 | // changed when SetLocalDescription is called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3160 | TEST_P(PeerConnectionInterfaceTest, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 3161 | ChangeSsrcOnTrackInLocalSessionDescription) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3162 | FakeConstraints constraints; |
| 3163 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3164 | true); |
| 3165 | CreatePeerConnection(&constraints); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3166 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3167 | AddAudioTrack(kAudioTracks[0]); |
| 3168 | AddVideoTrack(kVideoTracks[0]); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3169 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3170 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3171 | // 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] | 3172 | auto modified_offer = |
| 3173 | rtc::MakeUnique<webrtc::JsepSessionDescription>(webrtc::SdpType::kOffer); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3174 | modified_offer->Initialize(offer->description()->Copy(), offer->session_id(), |
| 3175 | offer->session_version()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3176 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3177 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3178 | auto senders = pc_->GetSenders(); |
| 3179 | EXPECT_EQ(2u, senders.size()); |
| 3180 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3181 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3182 | |
| 3183 | // Change the ssrc of the audio and video track. |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3184 | cricket::MediaContentDescription* desc = |
| 3185 | cricket::GetFirstAudioContentDescription(modified_offer->description()); |
| 3186 | ASSERT_TRUE(desc != NULL); |
| 3187 | for (StreamParams& stream : desc->mutable_streams()) { |
| 3188 | for (unsigned int& ssrc : stream.ssrcs) { |
| 3189 | ++ssrc; |
| 3190 | } |
| 3191 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3192 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3193 | desc = |
| 3194 | cricket::GetFirstVideoContentDescription(modified_offer->description()); |
| 3195 | ASSERT_TRUE(desc != NULL); |
| 3196 | for (StreamParams& stream : desc->mutable_streams()) { |
| 3197 | for (unsigned int& ssrc : stream.ssrcs) { |
| 3198 | ++ssrc; |
| 3199 | } |
| 3200 | } |
| 3201 | |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3202 | EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3203 | senders = pc_->GetSenders(); |
| 3204 | EXPECT_EQ(2u, senders.size()); |
| 3205 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0])); |
| 3206 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0])); |
| 3207 | // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC |
| 3208 | // changed. |
| 3209 | } |
| 3210 | |
| 3211 | // This tests that the expected behavior occurs if a new session description is |
| 3212 | // set with the same tracks, but on a different MediaStream. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3213 | // Don't run under Unified Plan since the stream API is not available. |
| 3214 | TEST_F(PeerConnectionInterfaceTestPlanB, |
Taylor Brandstetter | 7ff1737 | 2016-04-01 11:50:39 -0700 | [diff] [blame] | 3215 | SignalSameTracksInSeparateMediaStream) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3216 | FakeConstraints constraints; |
| 3217 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3218 | true); |
| 3219 | CreatePeerConnection(&constraints); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3220 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3221 | rtc::scoped_refptr<StreamCollection> stream_collection = |
| 3222 | CreateStreamCollection(2, 1); |
| 3223 | pc_->AddStream(stream_collection->at(0)); |
| 3224 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3225 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3226 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3227 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3228 | auto senders = pc_->GetSenders(); |
| 3229 | EXPECT_EQ(2u, senders.size()); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3230 | EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0])); |
| 3231 | EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0])); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3232 | |
| 3233 | // Add a new MediaStream but with the same tracks as in the first stream. |
| 3234 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1( |
| 3235 | webrtc::MediaStream::Create(kStreams[1])); |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3236 | stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]); |
| 3237 | stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3238 | pc_->AddStream(stream_1); |
| 3239 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3240 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3241 | EXPECT_TRUE(DoSetLocalDescription(std::move(offer))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3242 | |
Taylor Brandstetter | dc4eb8c | 2016-05-12 08:14:50 -0700 | [diff] [blame] | 3243 | auto new_senders = pc_->GetSenders(); |
| 3244 | // Should be the same senders as before, but with updated stream id. |
| 3245 | // Note that this behavior is subject to change in the future. |
| 3246 | // We may decide the PC should ignore existing tracks in AddStream. |
| 3247 | EXPECT_EQ(senders, new_senders); |
| 3248 | EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); |
| 3249 | EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3250 | } |
| 3251 | |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 3252 | // This tests that PeerConnectionObserver::OnAddTrack is correctly called. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3253 | TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) { |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 3254 | FakeConstraints constraints; |
| 3255 | constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, |
| 3256 | true); |
| 3257 | CreatePeerConnection(&constraints); |
| 3258 | CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly); |
| 3259 | EXPECT_EQ(observer_.num_added_tracks_, 1); |
| 3260 | EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]); |
| 3261 | |
| 3262 | // Create and set the updated remote SDP. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3263 | CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB); |
| 3264 | if (sdp_semantics_ == SdpSemantics::kPlanB) { |
| 3265 | EXPECT_EQ(observer_.num_added_tracks_, 2); |
| 3266 | } else { |
| 3267 | // With Unified Plan, OnAddTrack will fire every time SetRemoteDescription |
| 3268 | // is called until the offer/answer exchange is complete. So in this case |
| 3269 | // OnAddTrack is fired twice for the first audio track plus the one time |
| 3270 | // for the video track. |
| 3271 | EXPECT_EQ(observer_.num_added_tracks_, 3); |
| 3272 | } |
zhihuang | 81c3a03 | 2016-11-17 12:06:24 -0800 | [diff] [blame] | 3273 | EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]); |
| 3274 | } |
| 3275 | |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3276 | // Test that when SetConfiguration is called and the configuration is |
| 3277 | // changing, the next offer causes an ICE restart. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3278 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) { |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3279 | PeerConnectionInterface::RTCConfiguration config; |
| 3280 | config.type = PeerConnectionInterface::kRelay; |
| 3281 | // Need to pass default constraints to prevent disabling of DTLS... |
| 3282 | FakeConstraints default_constraints; |
| 3283 | CreatePeerConnection(config, &default_constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3284 | config = pc_->GetConfiguration(); |
| 3285 | AddAudioTrack(kAudioTracks[0], {kStreamLabel1}); |
| 3286 | AddVideoTrack(kVideoTracks[0], {kStreamLabel1}); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3287 | |
| 3288 | // Do initial offer/answer so there's something to restart. |
| 3289 | CreateOfferAsLocalDescription(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3290 | CreateAnswerAsRemoteDescription(GetSdpStringWithStream1()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3291 | |
| 3292 | // Grab the ufrags. |
| 3293 | std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); |
| 3294 | |
| 3295 | // Change ICE policy, which should trigger an ICE restart on the next offer. |
| 3296 | config.type = PeerConnectionInterface::kAll; |
| 3297 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 3298 | CreateOfferAsLocalDescription(); |
| 3299 | |
| 3300 | // Grab the new ufrags. |
| 3301 | std::vector<std::string> subsequent_ufrags = |
| 3302 | GetUfrags(pc_->local_description()); |
| 3303 | |
| 3304 | // Sanity check. |
| 3305 | EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size()); |
| 3306 | // Check that each ufrag is different. |
| 3307 | for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) { |
| 3308 | EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]); |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | // Test that when SetConfiguration is called and the configuration *isn't* |
| 3313 | // changing, the next offer does *not* cause an ICE restart. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3314 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) { |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3315 | PeerConnectionInterface::RTCConfiguration config; |
| 3316 | config.type = PeerConnectionInterface::kRelay; |
| 3317 | // Need to pass default constraints to prevent disabling of DTLS... |
| 3318 | FakeConstraints default_constraints; |
| 3319 | CreatePeerConnection(config, &default_constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3320 | config = pc_->GetConfiguration(); |
| 3321 | AddAudioTrack(kAudioTracks[0]); |
| 3322 | AddVideoTrack(kVideoTracks[0]); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3323 | |
| 3324 | // Do initial offer/answer so there's something to restart. |
| 3325 | CreateOfferAsLocalDescription(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3326 | CreateAnswerAsRemoteDescription(GetSdpStringWithStream1()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3327 | |
| 3328 | // Grab the ufrags. |
| 3329 | std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); |
| 3330 | |
| 3331 | // Call SetConfiguration with a config identical to what the PC was |
| 3332 | // constructed with. |
| 3333 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 3334 | CreateOfferAsLocalDescription(); |
| 3335 | |
| 3336 | // Grab the new ufrags. |
| 3337 | std::vector<std::string> subsequent_ufrags = |
| 3338 | GetUfrags(pc_->local_description()); |
| 3339 | |
| 3340 | EXPECT_EQ(initial_ufrags, subsequent_ufrags); |
| 3341 | } |
| 3342 | |
| 3343 | // Test for a weird corner case scenario: |
| 3344 | // 1. Audio/video session established. |
| 3345 | // 2. SetConfiguration changes ICE config; ICE restart needed. |
| 3346 | // 3. ICE restart initiated by remote peer, but only for one m= section. |
| 3347 | // 4. Next createOffer should initiate an ICE restart, but only for the other |
| 3348 | // m= section; it would be pointless to do an ICE restart for the m= section |
| 3349 | // that was already restarted. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3350 | TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) { |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3351 | PeerConnectionInterface::RTCConfiguration config; |
| 3352 | config.type = PeerConnectionInterface::kRelay; |
| 3353 | // Need to pass default constraints to prevent disabling of DTLS... |
| 3354 | FakeConstraints default_constraints; |
| 3355 | CreatePeerConnection(config, &default_constraints); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3356 | config = pc_->GetConfiguration(); |
| 3357 | AddAudioTrack(kAudioTracks[0], {kStreamLabel1}); |
| 3358 | AddVideoTrack(kVideoTracks[0], {kStreamLabel1}); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3359 | |
| 3360 | // Do initial offer/answer so there's something to restart. |
| 3361 | CreateOfferAsLocalDescription(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3362 | CreateAnswerAsRemoteDescription(GetSdpStringWithStream1()); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3363 | |
| 3364 | // Change ICE policy, which should set the "needs-ice-restart" flag. |
| 3365 | config.type = PeerConnectionInterface::kAll; |
| 3366 | EXPECT_TRUE(pc_->SetConfiguration(config)); |
| 3367 | |
| 3368 | // Do ICE restart for the first m= section, initiated by remote peer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3369 | std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer( |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3370 | webrtc::CreateSessionDescription(SdpType::kOffer, |
| 3371 | GetSdpStringWithStream1(), nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3372 | ASSERT_TRUE(remote_offer); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3373 | remote_offer->description()->transport_infos()[0].description.ice_ufrag = |
| 3374 | "modified"; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3375 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
deadbeef | d1a38b5 | 2016-12-10 13:15:33 -0800 | [diff] [blame] | 3376 | CreateAnswerAsLocalDescription(); |
| 3377 | |
| 3378 | // Grab the ufrags. |
| 3379 | std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description()); |
| 3380 | ASSERT_EQ(2, initial_ufrags.size()); |
| 3381 | |
| 3382 | // Create offer and grab the new ufrags. |
| 3383 | CreateOfferAsLocalDescription(); |
| 3384 | std::vector<std::string> subsequent_ufrags = |
| 3385 | GetUfrags(pc_->local_description()); |
| 3386 | ASSERT_EQ(2, subsequent_ufrags.size()); |
| 3387 | |
| 3388 | // Ensure that only the ufrag for the second m= section changed. |
| 3389 | EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]); |
| 3390 | EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]); |
| 3391 | } |
| 3392 | |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3393 | // Tests that the methods to return current/pending descriptions work as |
| 3394 | // expected at different points in the offer/answer exchange. This test does |
| 3395 | // one offer/answer exchange as the offerer, then another as the answerer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3396 | TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) { |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3397 | // This disables DTLS so we can apply an answer to ourselves. |
| 3398 | CreatePeerConnection(); |
| 3399 | |
| 3400 | // Create initial local offer and get SDP (which will also be used as |
| 3401 | // answer/pranswer); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3402 | std::unique_ptr<SessionDescriptionInterface> local_offer; |
| 3403 | ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr)); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3404 | std::string sdp; |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3405 | EXPECT_TRUE(local_offer->ToString(&sdp)); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3406 | |
| 3407 | // Set local offer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3408 | SessionDescriptionInterface* local_offer_ptr = local_offer.get(); |
| 3409 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer))); |
| 3410 | EXPECT_EQ(local_offer_ptr, pc_->pending_local_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3411 | EXPECT_EQ(nullptr, pc_->pending_remote_description()); |
| 3412 | EXPECT_EQ(nullptr, pc_->current_local_description()); |
| 3413 | EXPECT_EQ(nullptr, pc_->current_remote_description()); |
| 3414 | |
| 3415 | // Set remote pranswer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3416 | std::unique_ptr<SessionDescriptionInterface> remote_pranswer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3417 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3418 | SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get(); |
| 3419 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer))); |
| 3420 | EXPECT_EQ(local_offer_ptr, pc_->pending_local_description()); |
| 3421 | EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3422 | EXPECT_EQ(nullptr, pc_->current_local_description()); |
| 3423 | EXPECT_EQ(nullptr, pc_->current_remote_description()); |
| 3424 | |
| 3425 | // Set remote answer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3426 | std::unique_ptr<SessionDescriptionInterface> remote_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3427 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3428 | SessionDescriptionInterface* remote_answer_ptr = remote_answer.get(); |
| 3429 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer))); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3430 | EXPECT_EQ(nullptr, pc_->pending_local_description()); |
| 3431 | EXPECT_EQ(nullptr, pc_->pending_remote_description()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3432 | EXPECT_EQ(local_offer_ptr, pc_->current_local_description()); |
| 3433 | EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3434 | |
| 3435 | // Set remote offer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3436 | std::unique_ptr<SessionDescriptionInterface> remote_offer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3437 | webrtc::CreateSessionDescription(SdpType::kOffer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3438 | SessionDescriptionInterface* remote_offer_ptr = remote_offer.get(); |
| 3439 | EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer))); |
| 3440 | EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3441 | EXPECT_EQ(nullptr, pc_->pending_local_description()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3442 | EXPECT_EQ(local_offer_ptr, pc_->current_local_description()); |
| 3443 | EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3444 | |
| 3445 | // Set local pranswer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3446 | std::unique_ptr<SessionDescriptionInterface> local_pranswer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3447 | webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3448 | SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get(); |
| 3449 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer))); |
| 3450 | EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description()); |
| 3451 | EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description()); |
| 3452 | EXPECT_EQ(local_offer_ptr, pc_->current_local_description()); |
| 3453 | EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3454 | |
| 3455 | // Set local answer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3456 | std::unique_ptr<SessionDescriptionInterface> local_answer( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 3457 | webrtc::CreateSessionDescription(SdpType::kAnswer, sdp)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3458 | SessionDescriptionInterface* local_answer_ptr = local_answer.get(); |
| 3459 | EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer))); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3460 | EXPECT_EQ(nullptr, pc_->pending_remote_description()); |
| 3461 | EXPECT_EQ(nullptr, pc_->pending_local_description()); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3462 | EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description()); |
| 3463 | EXPECT_EQ(local_answer_ptr, pc_->current_local_description()); |
deadbeef | fe4a8a4 | 2016-12-20 17:56:17 -0800 | [diff] [blame] | 3464 | } |
| 3465 | |
zhihuang | 7798501 | 2017-02-07 15:45:16 -0800 | [diff] [blame] | 3466 | // Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog |
| 3467 | // after the PeerConnection is closed. |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3468 | // This version tests the StartRtcEventLog version that receives a file. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3469 | TEST_P(PeerConnectionInterfaceTest, |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3470 | StartAndStopLoggingToFileAfterPeerConnectionClosed) { |
zhihuang | 7798501 | 2017-02-07 15:45:16 -0800 | [diff] [blame] | 3471 | CreatePeerConnection(); |
| 3472 | // The RtcEventLog will be reset when the PeerConnection is closed. |
| 3473 | pc_->Close(); |
| 3474 | |
Elad Alon | 9e6565b | 2017-10-11 16:04:13 +0200 | [diff] [blame] | 3475 | auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
| 3476 | std::string filename = webrtc::test::OutputPath() + |
| 3477 | test_info->test_case_name() + test_info->name(); |
| 3478 | rtc::PlatformFile file = rtc::CreatePlatformFile(filename); |
| 3479 | |
| 3480 | constexpr int64_t max_size_bytes = 1024; |
| 3481 | |
zhihuang | 7798501 | 2017-02-07 15:45:16 -0800 | [diff] [blame] | 3482 | EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes)); |
| 3483 | pc_->StopRtcEventLog(); |
Elad Alon | 9e6565b | 2017-10-11 16:04:13 +0200 | [diff] [blame] | 3484 | |
| 3485 | // Cleanup. |
| 3486 | rtc::ClosePlatformFile(file); |
| 3487 | rtc::RemoveFile(filename); |
zhihuang | 7798501 | 2017-02-07 15:45:16 -0800 | [diff] [blame] | 3488 | } |
| 3489 | |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3490 | // Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog |
| 3491 | // after the PeerConnection is closed. |
| 3492 | // This version tests the StartRtcEventLog version that receives an object |
| 3493 | // of type |RtcEventLogOutput|. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3494 | TEST_P(PeerConnectionInterfaceTest, |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3495 | StartAndStopLoggingToOutputAfterPeerConnectionClosed) { |
| 3496 | CreatePeerConnection(); |
| 3497 | // The RtcEventLog will be reset when the PeerConnection is closed. |
| 3498 | pc_->Close(); |
| 3499 | |
| 3500 | rtc::PlatformFile file = 0; |
| 3501 | int64_t max_size_bytes = 1024; |
| 3502 | EXPECT_FALSE(pc_->StartRtcEventLog( |
Bjorn Terelius | de93943 | 2017-11-20 17:38:14 +0100 | [diff] [blame] | 3503 | rtc::MakeUnique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes), |
| 3504 | webrtc::RtcEventLog::kImmediateOutput)); |
Elad Alon | 99c3fe5 | 2017-10-13 16:29:40 +0200 | [diff] [blame] | 3505 | pc_->StopRtcEventLog(); |
| 3506 | } |
| 3507 | |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3508 | // Test that generated offers/answers include "ice-option:trickle". |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3509 | TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) { |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3510 | CreatePeerConnection(); |
| 3511 | |
| 3512 | // First, create an offer with audio/video. |
| 3513 | FakeConstraints constraints; |
| 3514 | constraints.SetMandatoryReceiveAudio(true); |
| 3515 | constraints.SetMandatoryReceiveVideo(true); |
| 3516 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3517 | ASSERT_TRUE(DoCreateOffer(&offer, &constraints)); |
| 3518 | cricket::SessionDescription* desc = offer->description(); |
| 3519 | ASSERT_EQ(2u, desc->transport_infos().size()); |
| 3520 | EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle")); |
| 3521 | EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle")); |
| 3522 | |
| 3523 | // Apply the offer as a remote description, then create an answer. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3524 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 30952b4 | 2017-04-21 02:41:29 -0700 | [diff] [blame] | 3525 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3526 | ASSERT_TRUE(DoCreateAnswer(&answer, &constraints)); |
| 3527 | desc = answer->description(); |
| 3528 | ASSERT_EQ(2u, desc->transport_infos().size()); |
| 3529 | EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle")); |
| 3530 | EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle")); |
| 3531 | } |
| 3532 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3533 | // Test that ICE renomination isn't offered if it's not enabled in the PC's |
| 3534 | // RTCConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3535 | TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3536 | PeerConnectionInterface::RTCConfiguration config; |
| 3537 | config.enable_ice_renomination = false; |
| 3538 | CreatePeerConnection(config, nullptr); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3539 | AddAudioTrack("foo"); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3540 | |
| 3541 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3542 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3543 | cricket::SessionDescription* desc = offer->description(); |
| 3544 | EXPECT_EQ(1u, desc->transport_infos().size()); |
| 3545 | EXPECT_FALSE( |
| 3546 | desc->transport_infos()[0].description.GetIceParameters().renomination); |
| 3547 | } |
| 3548 | |
| 3549 | // Test that the ICE renomination option is present in generated offers/answers |
| 3550 | // if it's enabled in the PC's RTCConfiguration. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3551 | TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3552 | PeerConnectionInterface::RTCConfiguration config; |
| 3553 | config.enable_ice_renomination = true; |
| 3554 | CreatePeerConnection(config, nullptr); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3555 | AddAudioTrack("foo"); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3556 | |
| 3557 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3558 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
| 3559 | cricket::SessionDescription* desc = offer->description(); |
| 3560 | EXPECT_EQ(1u, desc->transport_infos().size()); |
| 3561 | EXPECT_TRUE( |
| 3562 | desc->transport_infos()[0].description.GetIceParameters().renomination); |
| 3563 | |
| 3564 | // Set the offer as a remote description, then create an answer and ensure it |
| 3565 | // has the renomination flag too. |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3566 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3567 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3568 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 3569 | desc = answer->description(); |
| 3570 | EXPECT_EQ(1u, desc->transport_infos().size()); |
| 3571 | EXPECT_TRUE( |
| 3572 | desc->transport_infos()[0].description.GetIceParameters().renomination); |
| 3573 | } |
| 3574 | |
| 3575 | // Test that if CreateOffer is called with the deprecated "offer to receive |
| 3576 | // audio/video" constraints, they're processed and result in an offer with |
| 3577 | // audio/video sections just as if RTCOfferAnswerOptions had been used. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3578 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3579 | CreatePeerConnection(); |
| 3580 | |
| 3581 | FakeConstraints constraints; |
| 3582 | constraints.SetMandatoryReceiveAudio(true); |
| 3583 | constraints.SetMandatoryReceiveVideo(true); |
| 3584 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3585 | ASSERT_TRUE(DoCreateOffer(&offer, &constraints)); |
| 3586 | |
| 3587 | cricket::SessionDescription* desc = offer->description(); |
| 3588 | const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc); |
| 3589 | const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc); |
| 3590 | ASSERT_NE(nullptr, audio); |
| 3591 | ASSERT_NE(nullptr, video); |
| 3592 | EXPECT_FALSE(audio->rejected); |
| 3593 | EXPECT_FALSE(video->rejected); |
| 3594 | } |
| 3595 | |
| 3596 | // Test that if CreateAnswer is called with the deprecated "offer to receive |
| 3597 | // audio/video" constraints, they're processed and can be used to reject an |
| 3598 | // offered m= section just as can be done with RTCOfferAnswerOptions; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3599 | // Don't run under Unified Plan since this behavior is not supported. |
| 3600 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 3601 | CreateAnswerWithOfferToReceiveConstraints) { |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3602 | CreatePeerConnection(); |
| 3603 | |
| 3604 | // First, create an offer with audio/video and apply it as a remote |
| 3605 | // description. |
| 3606 | FakeConstraints constraints; |
| 3607 | constraints.SetMandatoryReceiveAudio(true); |
| 3608 | constraints.SetMandatoryReceiveVideo(true); |
| 3609 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3610 | ASSERT_TRUE(DoCreateOffer(&offer, &constraints)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3611 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3612 | |
| 3613 | // Now create answer that rejects audio/video. |
| 3614 | constraints.SetMandatoryReceiveAudio(false); |
| 3615 | constraints.SetMandatoryReceiveVideo(false); |
| 3616 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3617 | ASSERT_TRUE(DoCreateAnswer(&answer, &constraints)); |
| 3618 | |
| 3619 | cricket::SessionDescription* desc = answer->description(); |
| 3620 | const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc); |
| 3621 | const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc); |
| 3622 | ASSERT_NE(nullptr, audio); |
| 3623 | ASSERT_NE(nullptr, video); |
| 3624 | EXPECT_TRUE(audio->rejected); |
| 3625 | EXPECT_TRUE(video->rejected); |
| 3626 | } |
| 3627 | |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3628 | // Test that negotiation can succeed with a data channel only, and with the max |
| 3629 | // bundle policy. Previously there was a bug that prevented this. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3630 | #ifdef HAVE_SCTP |
| 3631 | TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) { |
| 3632 | #else |
| 3633 | TEST_P(PeerConnectionInterfaceTest, |
| 3634 | DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) { |
| 3635 | #endif // HAVE_SCTP |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3636 | PeerConnectionInterface::RTCConfiguration config; |
| 3637 | config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3638 | CreatePeerConnection(config, nullptr); |
| 3639 | |
| 3640 | // First, create an offer with only a data channel and apply it as a remote |
| 3641 | // description. |
| 3642 | pc_->CreateDataChannel("test", nullptr); |
| 3643 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3644 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3645 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3646 | |
| 3647 | // Create and set answer as well. |
| 3648 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3649 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
Steve Anton | db45ca8 | 2017-09-11 18:27:34 -0700 | [diff] [blame] | 3650 | EXPECT_TRUE(DoSetLocalDescription(std::move(answer))); |
deadbeef | 1dcb164 | 2017-03-29 21:08:16 -0700 | [diff] [blame] | 3651 | } |
| 3652 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3653 | TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3654 | CreatePeerConnection(); |
| 3655 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3656 | bitrate.current_bitrate_bps = 100000; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3657 | EXPECT_TRUE(pc_->SetBitrate(bitrate).ok()); |
| 3658 | } |
| 3659 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3660 | TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3661 | CreatePeerConnection(); |
| 3662 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3663 | bitrate.min_bitrate_bps = -1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3664 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3665 | } |
| 3666 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3667 | TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3668 | CreatePeerConnection(); |
| 3669 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3670 | bitrate.min_bitrate_bps = 5; |
| 3671 | bitrate.current_bitrate_bps = 3; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3672 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3673 | } |
| 3674 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3675 | TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3676 | CreatePeerConnection(); |
| 3677 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3678 | bitrate.current_bitrate_bps = -1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3679 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3680 | } |
| 3681 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3682 | TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3683 | CreatePeerConnection(); |
| 3684 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3685 | bitrate.current_bitrate_bps = 10; |
| 3686 | bitrate.max_bitrate_bps = 8; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3687 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3688 | } |
| 3689 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3690 | TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3691 | CreatePeerConnection(); |
| 3692 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3693 | bitrate.min_bitrate_bps = 10; |
| 3694 | bitrate.max_bitrate_bps = 8; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3695 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3696 | } |
| 3697 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3698 | TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3699 | CreatePeerConnection(); |
| 3700 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3701 | bitrate.max_bitrate_bps = -1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3702 | EXPECT_FALSE(pc_->SetBitrate(bitrate).ok()); |
| 3703 | } |
| 3704 | |
Steve Anton | 038834f | 2017-07-14 15:59:59 -0700 | [diff] [blame] | 3705 | // ice_regather_interval_range requires WebRTC to be configured for continual |
| 3706 | // gathering already. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3707 | TEST_P(PeerConnectionInterfaceTest, |
Steve Anton | 038834f | 2017-07-14 15:59:59 -0700 | [diff] [blame] | 3708 | SetIceRegatherIntervalRangeWithoutContinualGatheringFails) { |
| 3709 | PeerConnectionInterface::RTCConfiguration config; |
| 3710 | config.ice_regather_interval_range.emplace(1000, 2000); |
| 3711 | config.continual_gathering_policy = |
| 3712 | PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE; |
| 3713 | CreatePeerConnectionExpectFail(config); |
| 3714 | } |
| 3715 | |
| 3716 | // Ensures that there is no error when ice_regather_interval_range is set with |
| 3717 | // continual gathering enabled. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3718 | TEST_P(PeerConnectionInterfaceTest, |
Steve Anton | 038834f | 2017-07-14 15:59:59 -0700 | [diff] [blame] | 3719 | SetIceRegatherIntervalRangeWithContinualGathering) { |
| 3720 | PeerConnectionInterface::RTCConfiguration config; |
| 3721 | config.ice_regather_interval_range.emplace(1000, 2000); |
| 3722 | config.continual_gathering_policy = |
| 3723 | PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY; |
| 3724 | CreatePeerConnection(config, nullptr); |
| 3725 | } |
| 3726 | |
Sebastian Jansson | 5897fe2 | 2018-02-20 17:28:20 +0100 | [diff] [blame] | 3727 | // The current bitrate from Call's BitrateConstraintsMask is currently clamped |
| 3728 | // by Call's BitrateConstraints, which comes from the SDP or a default value. |
| 3729 | // This test checks that a call to SetBitrate with a current bitrate that will |
| 3730 | // be clamped succeeds. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3731 | TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) { |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3732 | CreatePeerConnection(); |
| 3733 | PeerConnectionInterface::BitrateParameters bitrate; |
Oskar Sundbom | b95fd2c | 2017-11-16 10:54:38 +0100 | [diff] [blame] | 3734 | bitrate.current_bitrate_bps = 1; |
zstein | 4b97980 | 2017-06-02 14:37:37 -0700 | [diff] [blame] | 3735 | EXPECT_TRUE(pc_->SetBitrate(bitrate).ok()); |
| 3736 | } |
| 3737 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3738 | // The following tests verify that the offer can be created correctly. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3739 | TEST_P(PeerConnectionInterfaceTest, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3740 | CreateOfferFailsWithInvalidOfferToReceiveAudio) { |
| 3741 | RTCOfferAnswerOptions rtc_options; |
| 3742 | |
| 3743 | // Setting offer_to_receive_audio to a value lower than kUndefined or greater |
| 3744 | // than kMaxOfferToReceiveMedia should be treated as invalid. |
| 3745 | rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1; |
| 3746 | CreatePeerConnection(); |
| 3747 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3748 | |
| 3749 | rtc_options.offer_to_receive_audio = |
| 3750 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
| 3751 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3752 | } |
| 3753 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3754 | TEST_P(PeerConnectionInterfaceTest, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3755 | CreateOfferFailsWithInvalidOfferToReceiveVideo) { |
| 3756 | RTCOfferAnswerOptions rtc_options; |
| 3757 | |
| 3758 | // Setting offer_to_receive_video to a value lower than kUndefined or greater |
| 3759 | // than kMaxOfferToReceiveMedia should be treated as invalid. |
| 3760 | rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1; |
| 3761 | CreatePeerConnection(); |
| 3762 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3763 | |
| 3764 | rtc_options.offer_to_receive_video = |
| 3765 | RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1; |
| 3766 | EXPECT_FALSE(CreateOfferWithOptions(rtc_options)); |
| 3767 | } |
| 3768 | |
| 3769 | // Test that the audio and video content will be added to an offer if both |
| 3770 | // |offer_to_receive_audio| and |offer_to_receive_video| options are 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3771 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3772 | RTCOfferAnswerOptions rtc_options; |
| 3773 | rtc_options.offer_to_receive_audio = 1; |
| 3774 | rtc_options.offer_to_receive_video = 1; |
| 3775 | |
| 3776 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3777 | CreatePeerConnection(); |
| 3778 | offer = CreateOfferWithOptions(rtc_options); |
| 3779 | ASSERT_TRUE(offer); |
| 3780 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3781 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3782 | } |
| 3783 | |
| 3784 | // Test that only audio content will be added to the offer if only |
| 3785 | // |offer_to_receive_audio| options is 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3786 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3787 | RTCOfferAnswerOptions rtc_options; |
| 3788 | rtc_options.offer_to_receive_audio = 1; |
| 3789 | rtc_options.offer_to_receive_video = 0; |
| 3790 | |
| 3791 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3792 | CreatePeerConnection(); |
| 3793 | offer = CreateOfferWithOptions(rtc_options); |
| 3794 | ASSERT_TRUE(offer); |
| 3795 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3796 | EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description())); |
| 3797 | } |
| 3798 | |
| 3799 | // Test that only video content will be added if only |offer_to_receive_video| |
| 3800 | // options is 1. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3801 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3802 | RTCOfferAnswerOptions rtc_options; |
| 3803 | rtc_options.offer_to_receive_audio = 0; |
| 3804 | rtc_options.offer_to_receive_video = 1; |
| 3805 | |
| 3806 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3807 | CreatePeerConnection(); |
| 3808 | offer = CreateOfferWithOptions(rtc_options); |
| 3809 | ASSERT_TRUE(offer); |
| 3810 | EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description())); |
| 3811 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3812 | } |
| 3813 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3814 | // Test that no media content will be added to the offer if using default |
| 3815 | // RTCOfferAnswerOptions. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3816 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3817 | RTCOfferAnswerOptions rtc_options; |
| 3818 | |
| 3819 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3820 | CreatePeerConnection(); |
| 3821 | offer = CreateOfferWithOptions(rtc_options); |
| 3822 | ASSERT_TRUE(offer); |
| 3823 | EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description())); |
| 3824 | EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description())); |
| 3825 | } |
| 3826 | |
| 3827 | // Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise |
| 3828 | // ufrag/pwd will be the same in the new offer. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3829 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) { |
| 3830 | CreatePeerConnection(); |
| 3831 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3832 | RTCOfferAnswerOptions rtc_options; |
| 3833 | rtc_options.ice_restart = false; |
| 3834 | rtc_options.offer_to_receive_audio = 1; |
| 3835 | |
| 3836 | std::unique_ptr<SessionDescriptionInterface> offer; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3837 | CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3838 | std::string mid = cricket::GetFirstAudioContent(offer->description())->name; |
| 3839 | auto ufrag1 = |
| 3840 | offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag; |
| 3841 | auto pwd1 = |
| 3842 | offer->description()->GetTransportInfoByName(mid)->description.ice_pwd; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3843 | |
| 3844 | // |ice_restart| is false, the ufrag/pwd shouldn't change. |
| 3845 | CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3846 | auto ufrag2 = |
| 3847 | offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag; |
| 3848 | auto pwd2 = |
| 3849 | offer->description()->GetTransportInfoByName(mid)->description.ice_pwd; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3850 | |
| 3851 | // |ice_restart| is true, the ufrag/pwd should change. |
| 3852 | rtc_options.ice_restart = true; |
| 3853 | CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3854 | auto ufrag3 = |
| 3855 | offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag; |
| 3856 | auto pwd3 = |
| 3857 | offer->description()->GetTransportInfoByName(mid)->description.ice_pwd; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3858 | |
| 3859 | EXPECT_EQ(ufrag1, ufrag2); |
| 3860 | EXPECT_EQ(pwd1, pwd2); |
| 3861 | EXPECT_NE(ufrag2, ufrag3); |
| 3862 | EXPECT_NE(pwd2, pwd3); |
| 3863 | } |
| 3864 | |
| 3865 | // Test that if |use_rtp_mux| is true, the bundling will be enabled in the |
| 3866 | // 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] | 3867 | TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3868 | RTCOfferAnswerOptions rtc_options; |
| 3869 | rtc_options.offer_to_receive_audio = 1; |
| 3870 | rtc_options.offer_to_receive_video = 1; |
| 3871 | |
| 3872 | std::unique_ptr<SessionDescriptionInterface> offer; |
| 3873 | CreatePeerConnection(); |
| 3874 | |
| 3875 | rtc_options.use_rtp_mux = true; |
| 3876 | offer = CreateOfferWithOptions(rtc_options); |
| 3877 | ASSERT_TRUE(offer); |
| 3878 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3879 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3880 | EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE)); |
| 3881 | |
| 3882 | rtc_options.use_rtp_mux = false; |
| 3883 | offer = CreateOfferWithOptions(rtc_options); |
| 3884 | ASSERT_TRUE(offer); |
| 3885 | EXPECT_NE(nullptr, GetFirstAudioContent(offer->description())); |
| 3886 | EXPECT_NE(nullptr, GetFirstVideoContent(offer->description())); |
| 3887 | EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE)); |
| 3888 | } |
| 3889 | |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3890 | // This test ensures OnRenegotiationNeeded is called when we add track with |
| 3891 | // MediaStream -> AddTrack in the same way it is called when we add track with |
| 3892 | // PeerConnection -> AddTrack. |
| 3893 | // The test can be removed once addStream is rewritten in terms of addTrack |
| 3894 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815 |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3895 | // Don't run under Unified Plan since the stream API is not available. |
| 3896 | TEST_F(PeerConnectionInterfaceTestPlanB, |
| 3897 | MediaStreamAddTrackRemoveTrackRenegotiate) { |
zhihuang | 141aacb | 2017-08-29 13:23:53 -0700 | [diff] [blame] | 3898 | CreatePeerConnectionWithoutDtls(); |
| 3899 | rtc::scoped_refptr<MediaStreamInterface> stream( |
| 3900 | pc_factory_->CreateLocalMediaStream(kStreamLabel1)); |
| 3901 | pc_->AddStream(stream); |
| 3902 | rtc::scoped_refptr<AudioTrackInterface> audio_track( |
| 3903 | pc_factory_->CreateAudioTrack("audio_track", nullptr)); |
| 3904 | rtc::scoped_refptr<VideoTrackInterface> video_track( |
| 3905 | pc_factory_->CreateVideoTrack( |
| 3906 | "video_track", pc_factory_->CreateVideoSource( |
| 3907 | std::unique_ptr<cricket::VideoCapturer>( |
| 3908 | new cricket::FakeVideoCapturer())))); |
| 3909 | stream->AddTrack(audio_track); |
| 3910 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3911 | observer_.renegotiation_needed_ = false; |
| 3912 | |
| 3913 | stream->AddTrack(video_track); |
| 3914 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3915 | observer_.renegotiation_needed_ = false; |
| 3916 | |
| 3917 | stream->RemoveTrack(audio_track); |
| 3918 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3919 | observer_.renegotiation_needed_ = false; |
| 3920 | |
| 3921 | stream->RemoveTrack(video_track); |
| 3922 | EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); |
| 3923 | observer_.renegotiation_needed_ = false; |
| 3924 | } |
| 3925 | |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3926 | // Tests that an error is returned if a description is applied that has fewer |
| 3927 | // media sections than the existing description. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3928 | TEST_P(PeerConnectionInterfaceTest, |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3929 | MediaSectionCountEnforcedForSubsequentOffer) { |
| 3930 | CreatePeerConnection(); |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3931 | AddAudioTrack("audio_label"); |
| 3932 | AddVideoTrack("video_label"); |
| 3933 | |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3934 | std::unique_ptr<SessionDescriptionInterface> offer; |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3935 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3936 | EXPECT_TRUE(DoSetRemoteDescription(std::move(offer))); |
| 3937 | |
| 3938 | // A remote offer with fewer media sections should be rejected. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3939 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3940 | offer->description()->contents().pop_back(); |
| 3941 | offer->description()->contents().pop_back(); |
| 3942 | ASSERT_TRUE(offer->description()->contents().empty()); |
| 3943 | EXPECT_FALSE(DoSetRemoteDescription(std::move(offer))); |
| 3944 | |
| 3945 | std::unique_ptr<SessionDescriptionInterface> answer; |
| 3946 | ASSERT_TRUE(DoCreateAnswer(&answer, nullptr)); |
| 3947 | EXPECT_TRUE(DoSetLocalDescription(std::move(answer))); |
| 3948 | |
| 3949 | // A subsequent local offer with fewer media sections should be rejected. |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3950 | ASSERT_TRUE(DoCreateOffer(&offer, nullptr)); |
Zhi Huang | b2d355e | 2017-10-26 17:26:37 -0700 | [diff] [blame] | 3951 | offer->description()->contents().pop_back(); |
| 3952 | offer->description()->contents().pop_back(); |
| 3953 | ASSERT_TRUE(offer->description()->contents().empty()); |
| 3954 | EXPECT_FALSE(DoSetLocalDescription(std::move(offer))); |
| 3955 | } |
| 3956 | |
Steve Anton | 36da6ff | 2018-02-16 16:04:20 -0800 | [diff] [blame] | 3957 | INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest, |
| 3958 | PeerConnectionInterfaceTest, |
| 3959 | Values(SdpSemantics::kPlanB, |
| 3960 | SdpSemantics::kUnifiedPlan)); |
| 3961 | |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3962 | class PeerConnectionMediaConfigTest : public testing::Test { |
| 3963 | protected: |
| 3964 | void SetUp() override { |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 3965 | pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest(); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3966 | pcf_->Initialize(); |
| 3967 | } |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 3968 | const cricket::MediaConfig TestCreatePeerConnection( |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3969 | const PeerConnectionInterface::RTCConfiguration& config, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3970 | const MediaConstraintsInterface* constraints) { |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 3971 | rtc::scoped_refptr<PeerConnectionInterface> pc(pcf_->CreatePeerConnection( |
| 3972 | config, constraints, nullptr, nullptr, &observer_)); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3973 | EXPECT_TRUE(pc.get()); |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 3974 | return pc->GetConfiguration().media_config; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3975 | } |
| 3976 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 3977 | rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3978 | MockPeerConnectionObserver observer_; |
| 3979 | }; |
| 3980 | |
| 3981 | // This test verifies the default behaviour with no constraints and a |
| 3982 | // default RTCConfiguration. |
| 3983 | TEST_F(PeerConnectionMediaConfigTest, TestDefaults) { |
| 3984 | PeerConnectionInterface::RTCConfiguration config; |
| 3985 | FakeConstraints constraints; |
| 3986 | |
| 3987 | const cricket::MediaConfig& media_config = |
| 3988 | TestCreatePeerConnection(config, &constraints); |
| 3989 | |
| 3990 | EXPECT_FALSE(media_config.enable_dscp); |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3991 | EXPECT_TRUE(media_config.video.enable_cpu_adaptation); |
| 3992 | EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 3993 | EXPECT_FALSE(media_config.video.suspend_below_min_bitrate); |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 3994 | EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3995 | } |
| 3996 | |
| 3997 | // This test verifies the DSCP constraint is recognized and passed to |
nisse | 528b793 | 2017-05-08 03:21:43 -0700 | [diff] [blame] | 3998 | // the PeerConnection. |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3999 | TEST_F(PeerConnectionMediaConfigTest, TestDscpConstraintTrue) { |
| 4000 | PeerConnectionInterface::RTCConfiguration config; |
| 4001 | FakeConstraints constraints; |
| 4002 | |
| 4003 | constraints.AddOptional(webrtc::MediaConstraintsInterface::kEnableDscp, true); |
| 4004 | const cricket::MediaConfig& media_config = |
| 4005 | TestCreatePeerConnection(config, &constraints); |
| 4006 | |
| 4007 | EXPECT_TRUE(media_config.enable_dscp); |
| 4008 | } |
| 4009 | |
| 4010 | // This test verifies the cpu overuse detection constraint is |
nisse | 528b793 | 2017-05-08 03:21:43 -0700 | [diff] [blame] | 4011 | // recognized and passed to the PeerConnection. |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4012 | TEST_F(PeerConnectionMediaConfigTest, TestCpuOveruseConstraintFalse) { |
| 4013 | PeerConnectionInterface::RTCConfiguration config; |
| 4014 | FakeConstraints constraints; |
| 4015 | |
| 4016 | constraints.AddOptional( |
| 4017 | webrtc::MediaConstraintsInterface::kCpuOveruseDetection, false); |
| 4018 | const cricket::MediaConfig media_config = |
| 4019 | TestCreatePeerConnection(config, &constraints); |
| 4020 | |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 4021 | EXPECT_FALSE(media_config.video.enable_cpu_adaptation); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4022 | } |
| 4023 | |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 4024 | // This test verifies that the enable_prerenderer_smoothing flag is |
nisse | 528b793 | 2017-05-08 03:21:43 -0700 | [diff] [blame] | 4025 | // propagated from RTCConfiguration to the PeerConnection. |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4026 | TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) { |
| 4027 | PeerConnectionInterface::RTCConfiguration config; |
| 4028 | FakeConstraints constraints; |
| 4029 | |
Niels Möller | 71bdda0 | 2016-03-31 12:59:59 +0200 | [diff] [blame] | 4030 | config.set_prerenderer_smoothing(false); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4031 | const cricket::MediaConfig& media_config = |
| 4032 | TestCreatePeerConnection(config, &constraints); |
| 4033 | |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 4034 | EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 4035 | } |
| 4036 | |
Niels Möller | 6539f69 | 2018-01-18 08:58:50 +0100 | [diff] [blame] | 4037 | // This test verifies that the experiment_cpu_load_estimator flag is |
| 4038 | // propagated from RTCConfiguration to the PeerConnection. |
| 4039 | TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) { |
| 4040 | PeerConnectionInterface::RTCConfiguration config; |
| 4041 | FakeConstraints constraints; |
| 4042 | |
| 4043 | config.set_experiment_cpu_load_estimator(true); |
| 4044 | const cricket::MediaConfig& media_config = |
| 4045 | TestCreatePeerConnection(config, &constraints); |
| 4046 | |
| 4047 | EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator); |
| 4048 | } |
| 4049 | |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 4050 | // This test verifies the suspend below min bitrate constraint is |
nisse | 528b793 | 2017-05-08 03:21:43 -0700 | [diff] [blame] | 4051 | // recognized and passed to the PeerConnection. |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 4052 | TEST_F(PeerConnectionMediaConfigTest, |
| 4053 | TestSuspendBelowMinBitrateConstraintTrue) { |
| 4054 | PeerConnectionInterface::RTCConfiguration config; |
| 4055 | FakeConstraints constraints; |
| 4056 | |
| 4057 | constraints.AddOptional( |
| 4058 | webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate, |
| 4059 | true); |
| 4060 | const cricket::MediaConfig media_config = |
| 4061 | TestCreatePeerConnection(config, &constraints); |
| 4062 | |
| 4063 | EXPECT_TRUE(media_config.video.suspend_below_min_bitrate); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4064 | } |
| 4065 | |
deadbeef | 293e926 | 2017-01-11 12:28:30 -0800 | [diff] [blame] | 4066 | // Tests a few random fields being different. |
| 4067 | TEST(RTCConfigurationTest, ComparisonOperators) { |
| 4068 | PeerConnectionInterface::RTCConfiguration a; |
| 4069 | PeerConnectionInterface::RTCConfiguration b; |
| 4070 | EXPECT_EQ(a, b); |
| 4071 | |
| 4072 | PeerConnectionInterface::RTCConfiguration c; |
| 4073 | c.servers.push_back(PeerConnectionInterface::IceServer()); |
| 4074 | EXPECT_NE(a, c); |
| 4075 | |
| 4076 | PeerConnectionInterface::RTCConfiguration d; |
| 4077 | d.type = PeerConnectionInterface::kRelay; |
| 4078 | EXPECT_NE(a, d); |
| 4079 | |
| 4080 | PeerConnectionInterface::RTCConfiguration e; |
| 4081 | e.audio_jitter_buffer_max_packets = 5; |
| 4082 | EXPECT_NE(a, e); |
| 4083 | |
| 4084 | PeerConnectionInterface::RTCConfiguration f; |
| 4085 | f.ice_connection_receiving_timeout = 1337; |
| 4086 | EXPECT_NE(a, f); |
| 4087 | |
| 4088 | PeerConnectionInterface::RTCConfiguration g; |
| 4089 | g.disable_ipv6 = true; |
| 4090 | EXPECT_NE(a, g); |
| 4091 | |
| 4092 | PeerConnectionInterface::RTCConfiguration h( |
| 4093 | PeerConnectionInterface::RTCConfigurationType::kAggressive); |
| 4094 | EXPECT_NE(a, h); |
| 4095 | } |