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