blob: 2ea3e8680bcffe14de37c65865d696acc39e6bd3 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <limits.h>
12#include <stdint.h>
13#include <string.h>
kwibergd1fe2812016-04-27 06:47:29 -070014#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080016#include <utility>
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
Karl Wiberg918f50c2018-07-05 11:40:33 +020019#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080020#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "absl/types/optional.h"
22#include "api/audio/audio_mixer.h"
23#include "api/audio_codecs/audio_decoder_factory.h"
24#include "api/audio_codecs/audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "api/audio_codecs/builtin_audio_decoder_factory.h"
26#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "api/call/call_factory_interface.h"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010028#include "api/create_peerconnection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "api/data_channel_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010030#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "api/jsep_session_description.h"
32#include "api/media_stream_interface.h"
33#include "api/media_types.h"
34#include "api/peer_connection_interface.h"
35#include "api/rtc_error.h"
36#include "api/rtc_event_log_output.h"
Niels Möllerd8b9ed72019-05-08 13:53:51 +020037#include "api/rtc_event_log_output_file.h"
Steve Anton10542f22019-01-11 09:11:00 -080038#include "api/rtp_receiver_interface.h"
39#include "api/rtp_sender_interface.h"
40#include "api/rtp_transceiver_interface.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010041#include "api/scoped_refptr.h"
Anders Carlsson67537952018-05-03 11:28:29 +020042#include "api/video_codecs/builtin_video_decoder_factory.h"
43#include "api/video_codecs/builtin_video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010044#include "api/video_codecs/video_decoder_factory.h"
45#include "api/video_codecs/video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010046#include "logging/rtc_event_log/rtc_event_log.h"
Bjorn Tereliusb8b3c992019-01-09 11:15:34 +010047#include "logging/rtc_event_log/rtc_event_log_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010048#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
49#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080050#include "media/base/media_config.h"
51#include "media/base/media_engine.h"
52#include "media/base/stream_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080053#include "media/engine/webrtc_media_engine.h"
54#include "media/sctp/sctp_transport_internal.h"
Yves Gerey3e707812018-11-28 16:47:49 +010055#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020056#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080057#include "p2p/base/fake_port_allocator.h"
58#include "p2p/base/p2p_constants.h"
Yves Gerey3e707812018-11-28 16:47:49 +010059#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080060#include "p2p/base/port_allocator.h"
61#include "p2p/base/transport_description.h"
62#include "p2p/base/transport_info.h"
63#include "pc/audio_track.h"
64#include "pc/media_session.h"
65#include "pc/media_stream.h"
66#include "pc/peer_connection.h"
67#include "pc/peer_connection_factory.h"
68#include "pc/rtc_stats_collector.h"
69#include "pc/rtp_sender.h"
70#include "pc/session_description.h"
71#include "pc/stream_collection.h"
72#include "pc/test/fake_audio_capture_module.h"
73#include "pc/test/fake_rtc_certificate_generator.h"
74#include "pc/test/fake_video_track_source.h"
75#include "pc/test/mock_peer_connection_observers.h"
76#include "pc/test/test_sdp_strings.h"
77#include "pc/video_track.h"
Yves Gerey3e707812018-11-28 16:47:49 +010078#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080079#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020080#include "rtc_base/gunit.h"
Yves Gerey3e707812018-11-28 16:47:49 +010081#include "rtc_base/platform_file.h"
Steve Anton10542f22019-01-11 09:11:00 -080082#include "rtc_base/ref_counted_object.h"
83#include "rtc_base/rtc_certificate_generator.h"
Steve Anton10542f22019-01-11 09:11:00 -080084#include "rtc_base/socket_address.h"
Yves Gerey3e707812018-11-28 16:47:49 +010085#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080086#include "rtc_base/time_utils.h"
87#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020088#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010089#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080090#include "test/testsupport/file_utils.h"
kwibergac9f8762016-09-30 22:29:43 -070091
92#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080093#include "pc/test/android_test_initializer.h"
kwibergac9f8762016-09-30 22:29:43 -070094#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010096namespace webrtc {
97namespace {
98
Seth Hampson845e8782018-03-02 11:34:10 -080099static const char kStreamId1[] = "local_stream_1";
100static const char kStreamId2[] = "local_stream_2";
101static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102static const int kDefaultStunPort = 3478;
103static const char kStunAddressOnly[] = "stun:address";
104static const char kStunInvalidPort[] = "stun:address:-1";
105static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
106static const char kStunAddressPortAndMore2[] = "stun:address:port more";
Niels Möllerdb4def92019-03-18 16:53:59 +0100107static const char kTurnIceServerUri[] = "turn:turn.example.org";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108static const char kTurnUsername[] = "user";
109static const char kTurnPassword[] = "password";
110static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200111static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112
deadbeefab9b2d12015-10-14 11:33:11 -0700113static const char kStreams[][8] = {"stream1", "stream2"};
114static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
115static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
116
deadbeef5e97fb52015-10-15 12:49:08 -0700117static const char kRecvonly[] = "recvonly";
118static const char kSendrecv[] = "sendrecv";
119
deadbeefab9b2d12015-10-14 11:33:11 -0700120// Reference SDP with a MediaStream with label "stream1" and audio track with
121// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800122static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700123 "v=0\r\n"
124 "o=- 0 0 IN IP4 127.0.0.1\r\n"
125 "s=-\r\n"
126 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800127 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700128 "a=ice-ufrag:e5785931\r\n"
129 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
130 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
131 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700132 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700133 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800134 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700135 "a=rtpmap:103 ISAC/16000\r\n"
136 "a=ssrc:1 cname:stream1\r\n"
137 "a=ssrc:1 mslabel:stream1\r\n"
138 "a=ssrc:1 label:audiotrack0\r\n"
139 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800140 "a=ice-ufrag:e5785931\r\n"
141 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
142 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
143 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700144 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700145 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800146 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700147 "a=rtpmap:120 VP8/90000\r\n"
148 "a=ssrc:2 cname:stream1\r\n"
149 "a=ssrc:2 mslabel:stream1\r\n"
150 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800151// Same string as above but with the MID changed to the Unified Plan default.
152// This is needed so that this SDP can be used as an answer for a Unified Plan
153// offer.
154static const char kSdpStringWithStream1UnifiedPlan[] =
155 "v=0\r\n"
156 "o=- 0 0 IN IP4 127.0.0.1\r\n"
157 "s=-\r\n"
158 "t=0 0\r\n"
159 "m=audio 1 RTP/AVPF 103\r\n"
160 "a=ice-ufrag:e5785931\r\n"
161 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
162 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
163 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
164 "a=mid:0\r\n"
165 "a=sendrecv\r\n"
166 "a=rtcp-mux\r\n"
167 "a=rtpmap:103 ISAC/16000\r\n"
168 "a=ssrc:1 cname:stream1\r\n"
169 "a=ssrc:1 mslabel:stream1\r\n"
170 "a=ssrc:1 label:audiotrack0\r\n"
171 "m=video 1 RTP/AVPF 120\r\n"
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"
176 "a=mid:1\r\n"
177 "a=sendrecv\r\n"
178 "a=rtcp-mux\r\n"
179 "a=rtpmap:120 VP8/90000\r\n"
180 "a=ssrc:2 cname:stream1\r\n"
181 "a=ssrc:2 mslabel:stream1\r\n"
182 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700183
zhihuang81c3a032016-11-17 12:06:24 -0800184// Reference SDP with a MediaStream with label "stream1" and audio track with
185// id "audio_1";
186static const char kSdpStringWithStream1AudioTrackOnly[] =
187 "v=0\r\n"
188 "o=- 0 0 IN IP4 127.0.0.1\r\n"
189 "s=-\r\n"
190 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800191 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800192 "a=ice-ufrag:e5785931\r\n"
193 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
194 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
195 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800196 "a=mid:audio\r\n"
197 "a=sendrecv\r\n"
198 "a=rtpmap:103 ISAC/16000\r\n"
199 "a=ssrc:1 cname:stream1\r\n"
200 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800201 "a=ssrc:1 label:audiotrack0\r\n"
202 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800203
deadbeefab9b2d12015-10-14 11:33:11 -0700204// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
205// MediaStreams have one audio track and one video track.
206// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800207static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700208 "v=0\r\n"
209 "o=- 0 0 IN IP4 127.0.0.1\r\n"
210 "s=-\r\n"
211 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800212 "a=msid-semantic: WMS stream1 stream2\r\n"
213 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700214 "a=ice-ufrag:e5785931\r\n"
215 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
216 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
217 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700218 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700219 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800220 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700221 "a=rtpmap:103 ISAC/16000\r\n"
222 "a=ssrc:1 cname:stream1\r\n"
223 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
224 "a=ssrc:3 cname:stream2\r\n"
225 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
226 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800227 "a=ice-ufrag:e5785931\r\n"
228 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
229 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
230 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700231 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700232 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800233 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700234 "a=rtpmap:120 VP8/0\r\n"
235 "a=ssrc:2 cname:stream1\r\n"
236 "a=ssrc:2 msid:stream1 videotrack0\r\n"
237 "a=ssrc:4 cname:stream2\r\n"
238 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800239static const char kSdpStringWithStream1And2UnifiedPlan[] =
240 "v=0\r\n"
241 "o=- 0 0 IN IP4 127.0.0.1\r\n"
242 "s=-\r\n"
243 "t=0 0\r\n"
244 "a=msid-semantic: WMS stream1 stream2\r\n"
245 "m=audio 1 RTP/AVPF 103\r\n"
246 "a=ice-ufrag:e5785931\r\n"
247 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
248 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
249 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
250 "a=mid:0\r\n"
251 "a=sendrecv\r\n"
252 "a=rtcp-mux\r\n"
253 "a=rtpmap:103 ISAC/16000\r\n"
254 "a=ssrc:1 cname:stream1\r\n"
255 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
256 "m=video 1 RTP/AVPF 120\r\n"
257 "a=ice-ufrag:e5785931\r\n"
258 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
259 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
260 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
261 "a=mid:1\r\n"
262 "a=sendrecv\r\n"
263 "a=rtcp-mux\r\n"
264 "a=rtpmap:120 VP8/0\r\n"
265 "a=ssrc:2 cname:stream1\r\n"
266 "a=ssrc:2 msid:stream1 videotrack0\r\n"
267 "m=audio 1 RTP/AVPF 103\r\n"
268 "a=ice-ufrag:e5785931\r\n"
269 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
270 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
271 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
272 "a=mid:2\r\n"
273 "a=sendrecv\r\n"
274 "a=rtcp-mux\r\n"
275 "a=rtpmap:103 ISAC/16000\r\n"
276 "a=ssrc:3 cname:stream2\r\n"
277 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
278 "m=video 1 RTP/AVPF 120\r\n"
279 "a=ice-ufrag:e5785931\r\n"
280 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
281 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
282 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
283 "a=mid:3\r\n"
284 "a=sendrecv\r\n"
285 "a=rtcp-mux\r\n"
286 "a=rtpmap:120 VP8/0\r\n"
287 "a=ssrc:4 cname:stream2\r\n"
288 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700289
290// Reference SDP without MediaStreams. Msid is not supported.
291static const char kSdpStringWithoutStreams[] =
292 "v=0\r\n"
293 "o=- 0 0 IN IP4 127.0.0.1\r\n"
294 "s=-\r\n"
295 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800296 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700297 "a=ice-ufrag:e5785931\r\n"
298 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
299 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
300 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700301 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700302 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800303 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700304 "a=rtpmap:103 ISAC/16000\r\n"
305 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800306 "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"
deadbeefab9b2d12015-10-14 11:33:11 -0700310 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700311 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800312 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700313 "a=rtpmap:120 VP8/90000\r\n";
314
315// Reference SDP without MediaStreams. Msid is supported.
316static const char kSdpStringWithMsidWithoutStreams[] =
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"
deadbeefd1a38b52016-12-10 13:15:33 -0800321 "a=msid-semantic: WMS\r\n"
322 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700323 "a=ice-ufrag:e5785931\r\n"
324 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
325 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
326 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700327 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700328 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800329 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700330 "a=rtpmap:103 ISAC/16000\r\n"
331 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800332 "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"
deadbeefab9b2d12015-10-14 11:33:11 -0700336 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700337 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800338 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700339 "a=rtpmap:120 VP8/90000\r\n";
340
341// Reference SDP without MediaStreams and audio only.
342static const char kSdpStringWithoutStreamsAudioOnly[] =
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"
deadbeefd1a38b52016-12-10 13:15:33 -0800347 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700348 "a=ice-ufrag:e5785931\r\n"
349 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
350 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
351 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700352 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700353 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800354 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700355 "a=rtpmap:103 ISAC/16000\r\n";
356
357// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
358static const char kSdpStringSendOnlyWithoutStreams[] =
359 "v=0\r\n"
360 "o=- 0 0 IN IP4 127.0.0.1\r\n"
361 "s=-\r\n"
362 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800363 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700364 "a=ice-ufrag:e5785931\r\n"
365 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
366 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
367 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700368 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700369 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700370 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800371 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700372 "a=rtpmap:103 ISAC/16000\r\n"
373 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800374 "a=ice-ufrag:e5785931\r\n"
375 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
376 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
377 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700378 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700379 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700380 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800381 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700382 "a=rtpmap:120 VP8/90000\r\n";
383
384static const char kSdpStringInit[] =
385 "v=0\r\n"
386 "o=- 0 0 IN IP4 127.0.0.1\r\n"
387 "s=-\r\n"
388 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700389 "a=msid-semantic: WMS\r\n";
390
391static const char kSdpStringAudio[] =
392 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800393 "a=ice-ufrag:e5785931\r\n"
394 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
395 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
396 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700397 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700398 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800399 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700400 "a=rtpmap:103 ISAC/16000\r\n";
401
402static const char kSdpStringVideo[] =
403 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800404 "a=ice-ufrag:e5785931\r\n"
405 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
406 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
407 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700408 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700409 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800410 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700411 "a=rtpmap:120 VP8/90000\r\n";
412
413static const char kSdpStringMs1Audio0[] =
414 "a=ssrc:1 cname:stream1\r\n"
415 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
416
417static const char kSdpStringMs1Video0[] =
418 "a=ssrc:2 cname:stream1\r\n"
419 "a=ssrc:2 msid:stream1 videotrack0\r\n";
420
421static const char kSdpStringMs1Audio1[] =
422 "a=ssrc:3 cname:stream1\r\n"
423 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
424
425static const char kSdpStringMs1Video1[] =
426 "a=ssrc:4 cname:stream1\r\n"
427 "a=ssrc:4 msid:stream1 videotrack1\r\n";
428
deadbeef8662f942017-01-20 21:20:51 -0800429static const char kDtlsSdesFallbackSdp[] =
430 "v=0\r\n"
431 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
432 "s=-\r\n"
433 "c=IN IP4 0.0.0.0\r\n"
434 "t=0 0\r\n"
435 "a=group:BUNDLE audio\r\n"
436 "a=msid-semantic: WMS\r\n"
437 "m=audio 1 RTP/SAVPF 0\r\n"
438 "a=sendrecv\r\n"
439 "a=rtcp-mux\r\n"
440 "a=mid:audio\r\n"
441 "a=ssrc:1 cname:stream1\r\n"
442 "a=ssrc:1 mslabel:stream1\r\n"
443 "a=ssrc:1 label:audiotrack0\r\n"
444 "a=ice-ufrag:e5785931\r\n"
445 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
446 "a=rtpmap:0 pcmu/8000\r\n"
447 "a=fingerprint:sha-1 "
448 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
449 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700450 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800451 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
452 "dummy_session_params\r\n";
453
Niels Möllerdec9f742019-06-03 15:25:20 +0200454class RtcEventLogOutputNull final : public RtcEventLogOutput {
455 public:
456 bool IsActive() const override { return true; }
457 bool Write(const std::string& output) override { return true; }
458};
459
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100460using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700461using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800462using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463
Steve Anton36da6ff2018-02-16 16:04:20 -0800464using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
465using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700466
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467// Gets the first ssrc of given content type from the ContentInfo.
468bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
469 if (!content_info || !ssrc) {
470 return false;
471 }
472 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800473 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 if (!media_desc || media_desc->streams().empty()) {
475 return false;
476 }
477 *ssrc = media_desc->streams().begin()->first_ssrc();
478 return true;
479}
480
deadbeefd1a38b52016-12-10 13:15:33 -0800481// Get the ufrags out of an SDP blob. Useful for testing ICE restart
482// behavior.
483std::vector<std::string> GetUfrags(
484 const webrtc::SessionDescriptionInterface* desc) {
485 std::vector<std::string> ufrags;
486 for (const cricket::TransportInfo& info :
487 desc->description()->transport_infos()) {
488 ufrags.push_back(info.description.ice_ufrag);
489 }
490 return ufrags;
491}
492
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493void SetSsrcToZero(std::string* sdp) {
494 const char kSdpSsrcAtribute[] = "a=ssrc:";
495 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
496 size_t ssrc_pos = 0;
497 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200498 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 size_t end_ssrc = sdp->find(" ", ssrc_pos);
500 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
501 ssrc_pos = end_ssrc;
502 }
503}
504
deadbeefab9b2d12015-10-14 11:33:11 -0700505// Check if |streams| contains the specified track.
506bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800507 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700508 const std::string& track_id) {
509 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800510 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700511 return true;
512 }
513 }
514 return false;
515}
516
517// Check if |senders| contains the specified sender, by id.
518bool ContainsSender(
519 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
520 const std::string& id) {
521 for (const auto& sender : senders) {
522 if (sender->id() == id) {
523 return true;
524 }
525 }
526 return false;
527}
528
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700529// Check if |senders| contains the specified sender, by id and stream id.
530bool ContainsSender(
531 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
532 const std::string& id,
533 const std::string& stream_id) {
534 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700535 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700536 return true;
537 }
538 }
539 return false;
540}
541
deadbeefab9b2d12015-10-14 11:33:11 -0700542// Create a collection of streams.
543// CreateStreamCollection(1) creates a collection that
544// correspond to kSdpStringWithStream1.
545// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
546rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700547 int number_of_streams,
548 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700549 rtc::scoped_refptr<StreamCollection> local_collection(
550 StreamCollection::Create());
551
552 for (int i = 0; i < number_of_streams; ++i) {
553 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
554 webrtc::MediaStream::Create(kStreams[i]));
555
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700556 for (int j = 0; j < tracks_per_stream; ++j) {
557 // Add a local audio track.
558 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
559 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
560 nullptr));
561 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700562
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700563 // Add a local video track.
564 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
565 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700566 webrtc::FakeVideoTrackSource::Create(),
567 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700568 stream->AddTrack(video_track);
569 }
deadbeefab9b2d12015-10-14 11:33:11 -0700570
571 local_collection->AddStream(stream);
572 }
573 return local_collection;
574}
575
576// Check equality of StreamCollections.
577bool CompareStreamCollections(StreamCollectionInterface* s1,
578 StreamCollectionInterface* s2) {
579 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
580 return false;
581 }
582
583 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700584 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700585 return false;
586 }
587 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
588 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
589 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
590 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
591
592 if (audio_tracks1.size() != audio_tracks2.size()) {
593 return false;
594 }
595 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
596 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
597 return false;
598 }
599 }
600 if (video_tracks1.size() != video_tracks2.size()) {
601 return false;
602 }
603 for (size_t j = 0; j != video_tracks1.size(); ++j) {
604 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
605 return false;
606 }
607 }
608 }
609 return true;
610}
611
perkjd61bf802016-03-24 03:16:19 -0700612// Helper class to test Observer.
613class MockTrackObserver : public ObserverInterface {
614 public:
615 explicit MockTrackObserver(NotifierInterface* notifier)
616 : notifier_(notifier) {
617 notifier_->RegisterObserver(this);
618 }
619
620 ~MockTrackObserver() { Unregister(); }
621
622 void Unregister() {
623 if (notifier_) {
624 notifier_->UnregisterObserver(this);
625 notifier_ = nullptr;
626 }
627 }
628
629 MOCK_METHOD0(OnChanged, void());
630
631 private:
632 NotifierInterface* notifier_;
633};
634
nisse528b7932017-05-08 03:21:43 -0700635// The PeerConnectionMediaConfig tests below verify that configuration and
636// constraints are propagated into the PeerConnection's MediaConfig. These
637// settings are intended for MediaChannel constructors, but that is not
638// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700639class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
640 public:
zhihuang38ede132017-06-15 12:52:32 -0700641 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
642 CreatePeerConnectionFactoryForTest() {
643 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
644 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200645 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
646 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 12:52:32 -0700647
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100648 PeerConnectionFactoryDependencies dependencies;
649 dependencies.worker_thread = rtc::Thread::Current();
650 dependencies.network_thread = rtc::Thread::Current();
651 dependencies.signaling_thread = rtc::Thread::Current();
652
henrika919dc2e2017-10-12 14:24:55 +0200653 // Use fake audio device module since we're only testing the interface
654 // level, and using a real one could make tests flaky when run in parallel.
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100655 dependencies.media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
zhihuang38ede132017-06-15 12:52:32 -0700656 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200657 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200658 audio_decoder_factory, std::move(video_encoder_factory),
Qingsi Wang59844ce2018-11-01 04:45:53 +0000659 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100660 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700661
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100662 dependencies.call_factory = webrtc::CreateCallFactory();
663 dependencies.event_log_factory = webrtc::CreateRtcEventLogFactory();
zhihuang38ede132017-06-15 12:52:32 -0700664
665 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100666 std::move(dependencies));
zhihuang38ede132017-06-15 12:52:32 -0700667 }
668
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100669 using PeerConnectionFactory::PeerConnectionFactory;
kwiberg1e4e8cb2017-01-31 01:48:08 -0800670
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100671 private:
deadbeefd7850b22017-08-23 10:59:19 -0700672 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700673};
674
Steve Anton36da6ff2018-02-16 16:04:20 -0800675// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200676class PeerConnectionInterfaceBaseTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000677 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800678 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
679 : vss_(new rtc::VirtualSocketServer()),
680 main_(vss_.get()),
681 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800682#ifdef WEBRTC_ANDROID
683 webrtc::InitializeAndroidObjects();
684#endif
685 }
686
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700688 // Use fake audio capture module since we're only testing the interface
689 // level, and using a real one could make tests flaky when run in parallel.
690 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700692 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200693 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
694 fake_audio_capture_module_),
695 webrtc::CreateBuiltinAudioEncoderFactory(),
696 webrtc::CreateBuiltinAudioDecoderFactory(),
697 webrtc::CreateBuiltinVideoEncoderFactory(),
698 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
699 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700700 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700701 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700702 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700703 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 }
705
706 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200707 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000708 }
709
deadbeef293e9262017-01-11 12:28:30 -0800710 // DTLS does not work in a loopback call, so is disabled for most of the
711 // tests in this file.
712 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200713 RTCConfiguration config;
714 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800715
Niels Möllerf06f9232018-08-07 12:32:18 +0200716 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 }
718
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700719 void CreatePeerConnectionWithIceTransportsType(
720 PeerConnectionInterface::IceTransportsType type) {
721 PeerConnectionInterface::RTCConfiguration config;
722 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200723 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700724 }
725
726 void CreatePeerConnectionWithIceServer(const std::string& uri,
Niels Möllerdb4def92019-03-18 16:53:59 +0100727 const std::string& username,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700728 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800729 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700731 server.uri = uri;
Niels Möllerdb4def92019-03-18 16:53:59 +0100732 server.username = username;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700733 server.password = password;
734 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200735 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700736 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737
Niels Möllerf06f9232018-08-07 12:32:18 +0200738 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700739 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800740 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
741 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000742
deadbeef1dcb1642017-03-29 21:08:16 -0700743 // Create certificate generator unless DTLS constraint is explicitly set to
744 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200745 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200746
747 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800748 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
749 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000750 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800751 RTCConfiguration modified_config = config;
752 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200753 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200754 modified_config, std::move(port_allocator), std::move(cert_generator),
755 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 ASSERT_TRUE(pc_.get() != NULL);
757 observer_.SetPeerConnectionInterface(pc_.get());
758 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
759 }
760
deadbeef0a6c4ca2015-10-06 11:38:28 -0700761 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800762 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700763 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700764 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800765 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800766 config.sdp_semantics = sdp_semantics_;
767 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200768 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800769 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700770 }
771
Steve Anton038834f2017-07-14 15:59:59 -0700772 void CreatePeerConnectionExpectFail(
773 PeerConnectionInterface::RTCConfiguration config) {
774 PeerConnectionInterface::IceServer server;
775 server.uri = kTurnIceServerUri;
776 server.password = kTurnPassword;
777 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800778 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700779 rtc::scoped_refptr<PeerConnectionInterface> pc =
780 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
781 EXPECT_EQ(nullptr, pc);
782 }
783
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 16:53:59 +0100785 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800786 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
787 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
788 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800790 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791
deadbeef0a6c4ca2015-10-06 11:38:28 -0700792 CreatePeerConnectionExpectFail(kStunInvalidPort);
793 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
794 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795
Niels Möllerdb4def92019-03-18 16:53:59 +0100796 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
797 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800798 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
799 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800803 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800805 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 }
807
808 void ReleasePeerConnection() {
809 pc_ = NULL;
810 observer_.SetPeerConnectionInterface(NULL);
811 }
812
Steve Anton36da6ff2018-02-16 16:04:20 -0800813 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
814 const std::string& label) {
Niels Möller215ba602019-01-18 13:59:45 +0100815 return pc_factory_->CreateVideoTrack(label, FakeVideoTrackSource::Create());
Steve Anton36da6ff2018-02-16 16:04:20 -0800816 }
817
818 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800819 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800820 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800821 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800822 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 }
824
Steve Anton36da6ff2018-02-16 16:04:20 -0800825 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700826 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800828 stream->AddTrack(CreateVideoTrack(label + "v0"));
829 ASSERT_TRUE(pc_->AddStream(stream));
Steve Anton36da6ff2018-02-16 16:04:20 -0800830 }
831
832 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
833 const std::string& label) {
834 return pc_factory_->CreateAudioTrack(label, nullptr);
835 }
836
837 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800838 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800839 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800840 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800841 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-16 16:04:20 -0800842 }
843
844 void AddAudioStream(const std::string& label) {
845 rtc::scoped_refptr<MediaStreamInterface> stream(
846 pc_factory_->CreateLocalMediaStream(label));
847 stream->AddTrack(CreateAudioTrack(label + "a0"));
848 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 }
850
Seth Hampson845e8782018-03-02 11:34:10 -0800851 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 const std::string& audio_track_label,
853 const std::string& video_track_label) {
854 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700855 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800856 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800857 stream->AddTrack(CreateAudioTrack(audio_track_label));
858 stream->AddTrack(CreateVideoTrack(video_track_label));
859 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 }
861
Steve Anton36da6ff2018-02-16 16:04:20 -0800862 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
863 cricket::MediaType media_type) {
864 for (auto receiver : pc_->GetReceivers()) {
865 if (receiver->media_type() == media_type) {
866 return receiver;
867 }
868 }
869 return nullptr;
870 }
871
kwibergd1fe2812016-04-27 06:47:29 -0700872 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200873 const RTCOfferAnswerOptions* options,
874 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200875 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
876 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200878 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200880 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 }
882 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700883 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 return observer->result();
885 }
886
kwibergd1fe2812016-04-27 06:47:29 -0700887 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200888 const RTCOfferAnswerOptions* options) {
889 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891
kwibergd1fe2812016-04-27 06:47:29 -0700892 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200893 const RTCOfferAnswerOptions* options) {
894 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 }
896
Steve Antondb45ca82017-09-11 18:27:34 -0700897 bool DoSetSessionDescription(
898 std::unique_ptr<SessionDescriptionInterface> desc,
899 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200900 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
901 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700903 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700905 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 }
zhihuang29ff8442016-07-27 11:07:25 -0700907 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
908 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
909 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 return observer->result();
911 }
912
Steve Antondb45ca82017-09-11 18:27:34 -0700913 bool DoSetLocalDescription(
914 std::unique_ptr<SessionDescriptionInterface> desc) {
915 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 }
917
Steve Antondb45ca82017-09-11 18:27:34 -0700918 bool DoSetRemoteDescription(
919 std::unique_ptr<SessionDescriptionInterface> desc) {
920 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 }
922
923 // Calls PeerConnection::GetStats and check the return value.
924 // It does not verify the values in the StatReports since a RTCP packet might
925 // be required.
926 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000927 rtc::scoped_refptr<MockStatsObserver> observer(
928 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200929 if (!pc_->GetStats(observer, track,
930 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 return false;
932 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
933 return observer->called();
934 }
935
Harald Alvestrand89061872018-01-02 14:08:34 +0100936 // Call the standards-compliant GetStats function.
937 bool DoGetRTCStats() {
938 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
939 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
940 pc_->GetStats(callback);
941 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
942 return callback->called();
943 }
944
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800946 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800948 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800949 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800950 } else {
951 // Unified Plan does not support AddStream, so just add an audio and video
952 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800953 AddAudioTrack(kAudioTracks[0], {kStreamId1});
954 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800955 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 CreateOfferReceiveAnswer();
957 }
958
959 // Verify that RTP Header extensions has been negotiated for audio and video.
960 void VerifyRemoteRtpHeaderExtensions() {
961 const cricket::MediaContentDescription* desc =
962 cricket::GetFirstAudioContentDescription(
963 pc_->remote_description()->description());
964 ASSERT_TRUE(desc != NULL);
965 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
966
967 desc = cricket::GetFirstVideoContentDescription(
968 pc_->remote_description()->description());
969 ASSERT_TRUE(desc != NULL);
970 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
971 }
972
973 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700974 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700975 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 std::string sdp;
977 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700978 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800979 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700980 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
982 }
983
deadbeefab9b2d12015-10-14 11:33:11 -0700984 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700985 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800986 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700987 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700988 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
989 }
990
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700992 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700993 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994
995 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
996 // audio codec change, even if the parameter has nothing to do with
997 // receiving. Not all parameters are serialized to SDP.
998 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
999 // the SessionDescription, it is necessary to do that here to in order to
1000 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1001 // https://code.google.com/p/webrtc/issues/detail?id=1356
1002 std::string sdp;
1003 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001004 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001005 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001006 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1008 }
1009
1010 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001011 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001012 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013
1014 std::string sdp;
1015 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001016 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001017 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001018 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1020 }
1021
1022 void CreateOfferReceiveAnswer() {
1023 CreateOfferAsLocalDescription();
1024 std::string sdp;
1025 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1026 CreateAnswerAsRemoteDescription(sdp);
1027 }
1028
1029 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001030 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001031 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1033 // audio codec change, even if the parameter has nothing to do with
1034 // receiving. Not all parameters are serialized to SDP.
1035 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1036 // the SessionDescription, it is necessary to do that here to in order to
1037 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1038 // https://code.google.com/p/webrtc/issues/detail?id=1356
1039 std::string sdp;
1040 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001041 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001042 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043
Steve Antondb45ca82017-09-11 18:27:34 -07001044 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001046 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001047 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 }
1049
deadbeefab9b2d12015-10-14 11:33:11 -07001050 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001051 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001052 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001053 ASSERT_TRUE(answer);
1054 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1056 }
1057
deadbeefab9b2d12015-10-14 11:33:11 -07001058 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001059 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001060 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001061 ASSERT_TRUE(pr_answer);
1062 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001064 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001065 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001066 ASSERT_TRUE(answer);
1067 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1069 }
1070
Seth Hampson845e8782018-03-02 11:34:10 -08001071 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001072 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001073 // called with the given stream id and expected number of tracks.
1074 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001075 int expected_num_tracks) {
1076 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001077 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001078 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001079 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 }
1081
1082 // Creates an offer and applies it as a local session description.
1083 // Creates an answer with the same SDP an the offer but removes all lines
1084 // that start with a:ssrc"
1085 void CreateOfferReceiveAnswerWithoutSsrc() {
1086 CreateOfferAsLocalDescription();
1087 std::string sdp;
1088 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1089 SetSsrcToZero(&sdp);
1090 CreateAnswerAsRemoteDescription(sdp);
1091 }
1092
deadbeefab9b2d12015-10-14 11:33:11 -07001093 // This function creates a MediaStream with label kStreams[0] and
1094 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1095 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001096 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001097 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001098 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001099 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1100 size_t number_of_video_tracks) {
1101 EXPECT_LE(number_of_audio_tracks, 2u);
1102 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001103
1104 reference_collection_ = StreamCollection::Create();
1105 std::string sdp_ms1 = std::string(kSdpStringInit);
1106
Seth Hampson845e8782018-03-02 11:34:10 -08001107 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001108
1109 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001110 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001111 reference_collection_->AddStream(stream);
1112
1113 if (number_of_audio_tracks > 0) {
1114 sdp_ms1 += std::string(kSdpStringAudio);
1115 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1116 AddAudioTrack(kAudioTracks[0], stream);
1117 }
1118 if (number_of_audio_tracks > 1) {
1119 sdp_ms1 += kSdpStringMs1Audio1;
1120 AddAudioTrack(kAudioTracks[1], stream);
1121 }
1122
1123 if (number_of_video_tracks > 0) {
1124 sdp_ms1 += std::string(kSdpStringVideo);
1125 sdp_ms1 += std::string(kSdpStringMs1Video0);
1126 AddVideoTrack(kVideoTracks[0], stream);
1127 }
1128 if (number_of_video_tracks > 1) {
1129 sdp_ms1 += kSdpStringMs1Video1;
1130 AddVideoTrack(kVideoTracks[1], stream);
1131 }
1132
kwibergd1fe2812016-04-27 06:47:29 -07001133 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001134 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001135 }
1136
1137 void AddAudioTrack(const std::string& track_id,
1138 MediaStreamInterface* stream) {
1139 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1140 webrtc::AudioTrack::Create(track_id, nullptr));
1141 ASSERT_TRUE(stream->AddTrack(audio_track));
1142 }
1143
1144 void AddVideoTrack(const std::string& track_id,
1145 MediaStreamInterface* stream) {
1146 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001147 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001148 webrtc::FakeVideoTrackSource::Create(),
1149 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001150 ASSERT_TRUE(stream->AddTrack(video_track));
1151 }
1152
Steve Anton36da6ff2018-02-16 16:04:20 -08001153 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001154 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001155 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001156 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001157 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1158 return offer;
1159 }
1160
Steve Anton36da6ff2018-02-16 16:04:20 -08001161 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1162 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001163 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001164 std::unique_ptr<SessionDescriptionInterface> offer;
1165 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1166 return offer;
1167 }
1168
1169 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1170 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1171 std::unique_ptr<SessionDescriptionInterface> answer;
1172 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1173 return answer;
1174 }
1175
kwibergfd8be342016-05-14 19:44:11 -07001176 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001177 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001178 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001179 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001180 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1181 return answer;
1182 }
1183
1184 const std::string& GetFirstAudioStreamCname(
1185 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001186 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001187 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001188 return audio_desc->streams()[0].cname;
1189 }
1190
zhihuang1c378ed2017-08-17 14:10:50 -07001191 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1192 const RTCOfferAnswerOptions& offer_answer_options) {
1193 RTC_DCHECK(pc_);
1194 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1195 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1196 pc_->CreateOffer(observer, offer_answer_options);
1197 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1198 return observer->MoveDescription();
1199 }
1200
1201 void CreateOfferWithOptionsAsRemoteDescription(
1202 std::unique_ptr<SessionDescriptionInterface>* desc,
1203 const RTCOfferAnswerOptions& offer_answer_options) {
1204 *desc = CreateOfferWithOptions(offer_answer_options);
1205 ASSERT_TRUE(desc != nullptr);
1206 std::string sdp;
1207 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001208 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001209 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001210 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001211 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1212 }
1213
1214 void CreateOfferWithOptionsAsLocalDescription(
1215 std::unique_ptr<SessionDescriptionInterface>* desc,
1216 const RTCOfferAnswerOptions& offer_answer_options) {
1217 *desc = CreateOfferWithOptions(offer_answer_options);
1218 ASSERT_TRUE(desc != nullptr);
1219 std::string sdp;
1220 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001221 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001222 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001223
Steve Antondb45ca82017-09-11 18:27:34 -07001224 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001225 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1226 }
1227
1228 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001229 RTC_DCHECK(content);
1230 RTC_DCHECK(content->media_description());
1231 for (const cricket::AudioCodec& codec :
1232 content->media_description()->as_audio()->codecs()) {
1233 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001234 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001235 }
zhihuang1c378ed2017-08-17 14:10:50 -07001236 }
1237 return false;
1238 }
1239
Steve Anton36da6ff2018-02-16 16:04:20 -08001240 const char* GetSdpStringWithStream1() const {
1241 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1242 return kSdpStringWithStream1PlanB;
1243 } else {
1244 return kSdpStringWithStream1UnifiedPlan;
1245 }
1246 }
1247
1248 const char* GetSdpStringWithStream1And2() const {
1249 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1250 return kSdpStringWithStream1And2PlanB;
1251 } else {
1252 return kSdpStringWithStream1And2UnifiedPlan;
1253 }
1254 }
1255
deadbeef9a6f4d42017-05-15 19:43:33 -07001256 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1257 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001258 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001259 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001260 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001261 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1262 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1263 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001265 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001266 const SdpSemantics sdp_semantics_;
1267};
1268
1269class PeerConnectionInterfaceTest
1270 : public PeerConnectionInterfaceBaseTest,
1271 public ::testing::WithParamInterface<SdpSemantics> {
1272 protected:
1273 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1274};
1275
1276class PeerConnectionInterfaceTestPlanB
1277 : public PeerConnectionInterfaceBaseTest {
1278 protected:
1279 PeerConnectionInterfaceTestPlanB()
1280 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281};
1282
zhihuang8f65cdf2016-05-06 18:40:30 -07001283// Generate different CNAMEs when PeerConnections are created.
1284// The CNAMEs are expected to be generated randomly. It is possible
1285// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001286TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001287 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001288 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001289 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001290 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001291 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1292 GetFirstAudioStreamCname(offer2.get()));
1293}
1294
Steve Anton36da6ff2018-02-16 16:04:20 -08001295TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001296 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001297 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001298 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001299 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001300 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1301 GetFirstAudioStreamCname(answer2.get()));
1302}
1303
Steve Anton36da6ff2018-02-16 16:04:20 -08001304TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 CreatePeerConnectionWithDifferentConfigurations) {
1306 CreatePeerConnectionWithDifferentConfigurations();
1307}
1308
Steve Anton36da6ff2018-02-16 16:04:20 -08001309TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001310 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1311 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1312 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1313 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1314 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1315 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1316 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1317 port_allocator_->candidate_filter());
1318 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1319 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1320}
1321
1322// Test that when a PeerConnection is created with a nonzero candidate pool
1323// size, the pooled PortAllocatorSession is created with all the attributes
1324// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001325TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001326 PeerConnectionInterface::RTCConfiguration config;
1327 PeerConnectionInterface::IceServer server;
1328 server.uri = kStunAddressOnly;
1329 config.servers.push_back(server);
1330 config.type = PeerConnectionInterface::kRelay;
1331 config.disable_ipv6 = true;
1332 config.tcp_candidate_policy =
1333 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001334 config.candidate_network_policy =
1335 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001336 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001337 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001338
1339 const cricket::FakePortAllocatorSession* session =
1340 static_cast<const cricket::FakePortAllocatorSession*>(
1341 port_allocator_->GetPooledSession());
1342 ASSERT_NE(nullptr, session);
1343 EXPECT_EQ(1UL, session->stun_servers().size());
1344 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1345 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001346 EXPECT_LT(0U,
1347 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001348}
1349
deadbeefd21eab32017-07-26 16:50:11 -07001350// Test that network-related RTCConfiguration members are applied to the
1351// PortAllocator when CreatePeerConnection is called. Specifically:
1352// - disable_ipv6_on_wifi
1353// - max_ipv6_networks
1354// - tcp_candidate_policy
1355// - candidate_network_policy
1356// - prune_turn_ports
1357//
1358// Note that the candidate filter (RTCConfiguration::type) is already tested
1359// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001360TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001361 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1362 // Create fake port allocator.
1363 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1364 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1365 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1366
1367 // Create RTCConfiguration with some network-related fields relevant to
1368 // PortAllocator populated.
1369 PeerConnectionInterface::RTCConfiguration config;
1370 config.disable_ipv6_on_wifi = true;
1371 config.max_ipv6_networks = 10;
1372 config.tcp_candidate_policy =
1373 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1374 config.candidate_network_policy =
1375 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1376 config.prune_turn_ports = true;
1377
1378 // Create the PC factory and PC with the above config.
1379 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1380 webrtc::CreatePeerConnectionFactory(
1381 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001382 rtc::Thread::Current(), fake_audio_capture_module_,
1383 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001384 webrtc::CreateBuiltinAudioDecoderFactory(),
1385 webrtc::CreateBuiltinVideoEncoderFactory(),
1386 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1387 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001388 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001389 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1390 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001391 EXPECT_TRUE(pc.get());
1392 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001393
1394 // Now validate that the config fields set above were applied to the
1395 // PortAllocator, as flags or otherwise.
1396 EXPECT_FALSE(raw_port_allocator->flags() &
1397 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1398 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1399 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1400 EXPECT_TRUE(raw_port_allocator->flags() &
1401 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1402 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1403}
1404
deadbeef46c73892016-11-16 19:42:04 -08001405// Check that GetConfiguration returns the configuration the PeerConnection was
1406// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001407TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001408 PeerConnectionInterface::RTCConfiguration config;
1409 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001410 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001411
1412 PeerConnectionInterface::RTCConfiguration returned_config =
1413 pc_->GetConfiguration();
1414 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1415}
1416
1417// Check that GetConfiguration returns the last configuration passed into
1418// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001419TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001420 PeerConnectionInterface::RTCConfiguration starting_config;
1421 starting_config.bundle_policy =
1422 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1423 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001424
Steve Anton36da6ff2018-02-16 16:04:20 -08001425 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001426 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001427 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001428 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001429 EXPECT_TRUE(pc_->SetConfiguration(config));
1430
1431 PeerConnectionInterface::RTCConfiguration returned_config =
1432 pc_->GetConfiguration();
1433 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001434 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001435 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001436}
1437
Steve Antonc79268f2018-04-24 09:54:10 -07001438TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1439 CreatePeerConnection();
1440
1441 pc_->Close();
1442
1443 EXPECT_FALSE(
1444 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1445}
1446
Steve Anton36da6ff2018-02-16 16:04:20 -08001447TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001448 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001449 AddVideoStream(kStreamId1);
1450 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 ASSERT_EQ(2u, pc_->local_streams()->count());
1452
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001453 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001454 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001455 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001456 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001457 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001458 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001460 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001461 EXPECT_EQ(3u, pc_->local_streams()->count());
1462
1463 // Remove the third stream.
1464 pc_->RemoveStream(pc_->local_streams()->at(2));
1465 EXPECT_EQ(2u, pc_->local_streams()->count());
1466
1467 // Remove the second stream.
1468 pc_->RemoveStream(pc_->local_streams()->at(1));
1469 EXPECT_EQ(1u, pc_->local_streams()->count());
1470
1471 // Remove the first stream.
1472 pc_->RemoveStream(pc_->local_streams()->at(0));
1473 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474}
1475
deadbeefab9b2d12015-10-14 11:33:11 -07001476// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001477// Don't run under Unified Plan since the stream API is not available.
1478TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001479 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001480 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001481 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001482 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001483
deadbeefab9b2d12015-10-14 11:33:11 -07001484 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001485 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001486 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001487
deadbeefab9b2d12015-10-14 11:33:11 -07001488 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001489 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001490 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001491
1492 // Add another stream and ensure the offer includes both the old and new
1493 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001494 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001495 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001496
Steve Antonb1c1de12017-12-21 15:14:30 -08001497 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001498 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1499 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001500
Steve Antonb1c1de12017-12-21 15:14:30 -08001501 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001502 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1503 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001504}
1505
Steve Anton36da6ff2018-02-16 16:04:20 -08001506// Don't run under Unified Plan since the stream API is not available.
1507TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001508 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001509 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 ASSERT_EQ(1u, pc_->local_streams()->count());
1511 pc_->RemoveStream(pc_->local_streams()->at(0));
1512 EXPECT_EQ(0u, pc_->local_streams()->count());
1513}
1514
deadbeefe1f9d832016-01-14 15:35:42 -08001515// Test for AddTrack and RemoveTrack methods.
1516// Tests that the created offer includes tracks we added,
1517// and that the RtpSenders are created correctly.
1518// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001519// Only tested with Plan B since Unified Plan is covered in more detail by tests
1520// in peerconnection_jsep_unittests.cc
1521TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001522 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001523 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001524 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001525 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001526 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001527 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1528 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001529 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001530 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001531 EXPECT_EQ("audio_track", audio_sender->id());
1532 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001533 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001534 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001535 EXPECT_EQ("video_track", video_sender->id());
1536 EXPECT_EQ(video_track, video_sender->track());
1537
1538 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001539 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001540 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001541
1542 const cricket::ContentInfo* audio_content =
1543 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001544 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001545 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001546
1547 const cricket::ContentInfo* video_content =
1548 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001549 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001550 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001551
Steve Antondb45ca82017-09-11 18:27:34 -07001552 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001553
1554 // Now try removing the tracks.
1555 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1556 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1557
1558 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001559 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001560
1561 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001562 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001563 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001564
1565 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001566 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001567 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001568
Steve Antondb45ca82017-09-11 18:27:34 -07001569 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001570
1571 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1572 // should return false.
1573 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1574 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1575}
1576
1577// Test creating senders without a stream specified,
1578// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001579TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001580 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001581 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001582 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001583 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001584 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001585 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001586 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001587 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001588 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001589 EXPECT_EQ("audio_track", audio_sender->id());
1590 EXPECT_EQ(audio_track, audio_sender->track());
1591 EXPECT_EQ("video_track", video_sender->id());
1592 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001593 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1594 // If the ID is truly a random GUID, it should be infinitely unlikely they
1595 // will be the same.
1596 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1597 } else {
1598 // We allows creating tracks without stream ids under Unified Plan
1599 // semantics.
1600 EXPECT_EQ(0u, video_sender->stream_ids().size());
1601 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1602 }
deadbeefe1f9d832016-01-14 15:35:42 -08001603}
1604
Harald Alvestrand89061872018-01-02 14:08:34 +01001605// Test that we can call GetStats() after AddTrack but before connecting
1606// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001607TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001608 CreatePeerConnectionWithoutDtls();
1609 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001610 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001611 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001612 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001613 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1614 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001615 EXPECT_TRUE(DoGetStats(nullptr));
1616}
1617
Steve Anton36da6ff2018-02-16 16:04:20 -08001618TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001619 CreatePeerConnectionWithoutDtls();
1620 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001621 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001622 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001623 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001624 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001625 ASSERT_TRUE(audio_sender.ok());
1626 auto* audio_sender_proxy =
1627 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1628 audio_sender.value().get());
1629 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1630
Harald Alvestrandc72af932018-01-11 17:18:19 +01001631 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001632 ASSERT_TRUE(video_sender.ok());
1633 auto* video_sender_proxy =
1634 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1635 video_sender.value().get());
1636 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001637}
1638
Steve Anton36da6ff2018-02-16 16:04:20 -08001639// Don't run under Unified Plan since the stream API is not available.
1640TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001641 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001642 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001643 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001644 ASSERT_EQ(1u, senders.size());
1645 auto* sender_proxy =
1646 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1647 senders[0].get());
1648 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001649}
1650
Steve Anton36da6ff2018-02-16 16:04:20 -08001651TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001653 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 VerifyRemoteRtpHeaderExtensions();
1655}
1656
Steve Anton36da6ff2018-02-16 16:04:20 -08001657TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001658 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001659 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 CreateOfferAsLocalDescription();
1661 std::string offer;
1662 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1663 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001664 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665}
1666
Steve Anton36da6ff2018-02-16 16:04:20 -08001667TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001668 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001669 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670
1671 CreateOfferAsRemoteDescription();
1672 CreateAnswerAsLocalDescription();
1673
Seth Hampson845e8782018-03-02 11:34:10 -08001674 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675}
1676
Steve Anton36da6ff2018-02-16 16:04:20 -08001677TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001678 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001679 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680
1681 CreateOfferAsRemoteDescription();
1682 CreatePrAnswerAsLocalDescription();
1683 CreateAnswerAsLocalDescription();
1684
Seth Hampson845e8782018-03-02 11:34:10 -08001685 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686}
1687
Steve Anton36da6ff2018-02-16 16:04:20 -08001688// Don't run under Unified Plan since the stream API is not available.
1689TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 InitiateCall();
1691 ASSERT_EQ(1u, pc_->remote_streams()->count());
1692 pc_->RemoveStream(pc_->local_streams()->at(0));
1693 CreateOfferReceiveAnswer();
1694 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001695 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 CreateOfferReceiveAnswer();
1697}
1698
1699// Tests that after negotiating an audio only call, the respondent can perform a
1700// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001701TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001702 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001703 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 CreateOfferAsRemoteDescription();
1705 CreateAnswerAsLocalDescription();
1706
1707 ASSERT_EQ(1u, pc_->remote_streams()->count());
1708 pc_->RemoveStream(pc_->local_streams()->at(0));
1709 CreateOfferReceiveAnswer();
1710 EXPECT_EQ(0u, pc_->remote_streams()->count());
1711}
1712
1713// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001714TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001715 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716
Steve Antonf1c6db12017-10-13 11:13:35 -07001717 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001719 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001720 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001721 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001722 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723
1724 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001725 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001726 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001727 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728
Steve Antonf1c6db12017-10-13 11:13:35 -07001729 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001730 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731
Steve Antonf1c6db12017-10-13 11:13:35 -07001732 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733}
1734
deadbeefab9b2d12015-10-14 11:33:11 -07001735// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001737TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001738 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001740 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001741 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001742 EXPECT_TRUE(offer);
1743 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744
1745 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001746 AddAudioTrack("track_label", {kStreamId1});
1747 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748
1749 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001750 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
1752 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001753 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001754 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755}
1756
1757// Test that we will get different SSRCs for each tracks in the offer and answer
1758// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001759TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001760 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001762 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1763 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764
1765 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001766 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001767 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 int audio_ssrc = 0;
1769 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001770 EXPECT_TRUE(
1771 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1772 EXPECT_TRUE(
1773 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 EXPECT_NE(audio_ssrc, video_ssrc);
1775
1776 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001777 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001778 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001779 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 audio_ssrc = 0;
1781 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001782 EXPECT_TRUE(
1783 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1784 EXPECT_TRUE(
1785 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 EXPECT_NE(audio_ssrc, video_ssrc);
1787}
1788
deadbeefeb459812015-12-15 19:24:43 -08001789// Test that it's possible to call AddTrack on a MediaStream after adding
1790// the stream to a PeerConnection.
1791// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001792// Don't run under Unified Plan since the stream API is not available.
1793TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001794 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001795 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001796 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001797 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1798
1799 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001800 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001801 CreateVideoTrack("video_label"));
deadbeefeb459812015-12-15 19:24:43 -08001802 stream->AddTrack(video_track.get());
1803
kwibergd1fe2812016-04-27 06:47:29 -07001804 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001805 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001806
1807 const cricket::MediaContentDescription* video_desc =
1808 cricket::GetFirstVideoContentDescription(offer->description());
1809 EXPECT_TRUE(video_desc != nullptr);
1810}
1811
1812// Test that it's possible to call RemoveTrack on a MediaStream after adding
1813// the stream to a PeerConnection.
1814// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001815// Don't run under Unified Plan since the stream API is not available.
1816TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001817 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001818 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001819 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001820 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1821
1822 // Remove the video track.
1823 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1824
kwibergd1fe2812016-04-27 06:47:29 -07001825 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001826 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001827
1828 const cricket::MediaContentDescription* video_desc =
1829 cricket::GetFirstVideoContentDescription(offer->description());
1830 EXPECT_TRUE(video_desc == nullptr);
1831}
1832
deadbeefbd7d8f72015-12-18 16:58:44 -08001833// Test creating a sender with a stream ID, and ensure the ID is populated
1834// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001835// Don't run under Unified Plan since the stream API is not available.
1836TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001837 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001838 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001839
kwibergd1fe2812016-04-27 06:47:29 -07001840 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001841 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001842
1843 const cricket::MediaContentDescription* video_desc =
1844 cricket::GetFirstVideoContentDescription(offer->description());
1845 ASSERT_TRUE(video_desc != nullptr);
1846 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001847 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001848}
1849
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001851TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001853 ASSERT_LT(0u, pc_->GetSenders().size());
1854 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001855 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001856 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 EXPECT_TRUE(DoGetStats(remote_audio));
1858
1859 // Remove the stream. Since we are sending to our selves the local
1860 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001861 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 // Do a re-negotiation.
1863 CreateOfferReceiveAnswer();
1864
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 // Test that we still can get statistics for the old track. Even if it is not
1866 // sent any longer.
1867 EXPECT_TRUE(DoGetStats(remote_audio));
1868}
1869
1870// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001871TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001873 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1874 ASSERT_TRUE(video_receiver);
1875 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876}
1877
1878// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001879TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001881 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 pc_factory_->CreateAudioTrack("unknown track", NULL));
1883 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1884}
1885
Steve Anton36da6ff2018-02-16 16:04:20 -08001886TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001887 CreatePeerConnectionWithoutDtls();
1888 EXPECT_TRUE(DoGetRTCStats());
1889 // Clearing stats cache is needed now, but should be temporary.
1890 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1891 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001892 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1893 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001894 EXPECT_TRUE(DoGetRTCStats());
1895 pc_->ClearStatsCache();
1896 CreateOfferReceiveAnswer();
1897 EXPECT_TRUE(DoGetRTCStats());
1898}
1899
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001901TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001902 RTCConfiguration config;
1903 config.enable_rtp_data_channel = true;
1904 config.enable_dtls_srtp = false;
1905 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001906 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001908 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 pc_->CreateDataChannel("test2", NULL);
1910 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001911 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001913 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 new MockDataChannelObserver(data2));
1915
1916 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1917 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1918 std::string data_to_send1 = "testing testing";
1919 std::string data_to_send2 = "testing something else";
1920 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1921
1922 CreateOfferReceiveAnswer();
1923 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1924 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1925
1926 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1927 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1928 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1929 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1930
1931 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1932 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1933
1934 data1->Close();
1935 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1936 CreateOfferReceiveAnswer();
1937 EXPECT_FALSE(observer1->IsOpen());
1938 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1939 EXPECT_TRUE(observer2->IsOpen());
1940
1941 data_to_send2 = "testing something else again";
1942 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1943
1944 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1945}
1946
1947// This test verifies that sendnig binary data over RTP data channels should
1948// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001949TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001950 RTCConfiguration config;
1951 config.enable_rtp_data_channel = true;
1952 config.enable_dtls_srtp = false;
1953 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001954 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001956 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 pc_->CreateDataChannel("test2", NULL);
1958 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001959 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001961 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 new MockDataChannelObserver(data2));
1963
1964 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1965 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1966
1967 CreateOfferReceiveAnswer();
1968 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1969 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1970
1971 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1972 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1973
jbaucheec21bd2016-03-20 06:15:43 -07001974 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1976}
1977
1978// This test setup a RTP data channels in loop back and test that a channel is
1979// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08001980TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001981 RTCConfiguration config;
1982 config.enable_rtp_data_channel = true;
1983 config.enable_dtls_srtp = false;
1984 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001985 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001987 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 new MockDataChannelObserver(data1));
1989
1990 CreateOfferReceiveAnswerWithoutSsrc();
1991
1992 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1993
1994 data1->Close();
1995 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1996 CreateOfferReceiveAnswerWithoutSsrc();
1997 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1998 EXPECT_FALSE(observer1->IsOpen());
1999}
2000
2001// This test that if a data channel is added in an answer a receive only channel
2002// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002003TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002004 RTCConfiguration config;
2005 config.enable_rtp_data_channel = true;
2006 config.enable_dtls_srtp = false;
2007
2008 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009
2010 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002011 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012 pc_->CreateDataChannel(offer_label, NULL);
2013
2014 CreateOfferAsLocalDescription();
2015
2016 // Replace the data channel label in the offer and apply it as an answer.
2017 std::string receive_label = "answer_channel";
2018 std::string sdp;
2019 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002020 absl::StrReplaceAll({{offer_label, receive_label}}, &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021 CreateAnswerAsRemoteDescription(sdp);
2022
2023 // Verify that a new incoming data channel has been created and that
2024 // it is open but can't we written to.
2025 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2026 DataChannelInterface* received_channel = observer_.last_datachannel_;
2027 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2028 EXPECT_EQ(receive_label, received_channel->label());
2029 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2030
2031 // Verify that the channel we initially offered has been rejected.
2032 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2033
2034 // Do another offer / answer exchange and verify that the data channel is
2035 // opened.
2036 CreateOfferReceiveAnswer();
2037 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2038 kTimeout);
2039}
2040
2041// This test that no data channel is returned if a reliable channel is
2042// requested.
2043// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002044TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002045 RTCConfiguration rtc_config;
2046 rtc_config.enable_rtp_data_channel = true;
2047 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
2049 std::string label = "test";
2050 webrtc::DataChannelInit config;
2051 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002052 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 pc_->CreateDataChannel(label, &config);
2054 EXPECT_TRUE(channel == NULL);
2055}
2056
deadbeefab9b2d12015-10-14 11:33:11 -07002057// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002058TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002059 RTCConfiguration config;
2060 config.enable_rtp_data_channel = true;
2061 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002062
2063 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002064 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002065 pc_->CreateDataChannel(label, nullptr);
2066 EXPECT_NE(channel, nullptr);
2067
zhihuang9763d562016-08-05 11:14:50 -07002068 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002069 pc_->CreateDataChannel(label, nullptr);
2070 EXPECT_EQ(dup_channel, nullptr);
2071}
2072
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073// This tests that a SCTP data channel is returned using different
2074// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002075TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002076 RTCConfiguration rtc_config;
2077 rtc_config.enable_dtls_srtp = true;
2078 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079
2080 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002081 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 pc_->CreateDataChannel("1", &config);
2083 EXPECT_TRUE(channel != NULL);
2084 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002085 EXPECT_TRUE(observer_.renegotiation_needed_);
2086 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087
2088 config.ordered = false;
2089 channel = pc_->CreateDataChannel("2", &config);
2090 EXPECT_TRUE(channel != NULL);
2091 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002092 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093
2094 config.ordered = true;
2095 config.maxRetransmits = 0;
2096 channel = pc_->CreateDataChannel("3", &config);
2097 EXPECT_TRUE(channel != NULL);
2098 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002099 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02002101 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 config.maxRetransmitTime = 0;
2103 channel = pc_->CreateDataChannel("4", &config);
2104 EXPECT_TRUE(channel != NULL);
2105 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002106 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107}
2108
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02002109// For backwards compatibility, we want people who "unset" maxRetransmits
2110// and maxRetransmitTime by setting them to -1 to get what they want.
2111TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
2112 RTCConfiguration rtc_config;
2113 rtc_config.enable_dtls_srtp = true;
2114 CreatePeerConnection(rtc_config);
2115
2116 webrtc::DataChannelInit config;
2117 config.maxRetransmitTime = -1;
2118 config.maxRetransmits = -1;
2119 rtc::scoped_refptr<DataChannelInterface> channel =
2120 pc_->CreateDataChannel("1", &config);
2121 EXPECT_TRUE(channel != NULL);
2122}
2123
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124// This tests that no data channel is returned if both maxRetransmits and
2125// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002126TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002128 RTCConfiguration rtc_config;
2129 rtc_config.enable_dtls_srtp = true;
2130 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131
2132 std::string label = "test";
2133 webrtc::DataChannelInit config;
2134 config.maxRetransmits = 0;
2135 config.maxRetransmitTime = 0;
2136
zhihuang9763d562016-08-05 11:14:50 -07002137 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 pc_->CreateDataChannel(label, &config);
2139 EXPECT_TRUE(channel == NULL);
2140}
2141
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142// The test verifies that creating a SCTP data channel with an id already in use
2143// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002144TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002146 RTCConfiguration rtc_config;
2147 rtc_config.enable_dtls_srtp = true;
2148 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149
2150 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002151 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002153 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002154 config.negotiated = true;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002155 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 EXPECT_TRUE(channel != NULL);
2157 EXPECT_EQ(1, channel->id());
2158
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 channel = pc_->CreateDataChannel("x", &config);
2160 EXPECT_TRUE(channel == NULL);
2161
2162 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002163 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 channel = pc_->CreateDataChannel("max", &config);
2165 EXPECT_TRUE(channel != NULL);
2166 EXPECT_EQ(config.id, channel->id());
2167
2168 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002169 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 channel = pc_->CreateDataChannel("x", &config);
2171 EXPECT_TRUE(channel == NULL);
2172}
2173
deadbeefab9b2d12015-10-14 11:33:11 -07002174// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002175TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002176 RTCConfiguration rtc_config;
2177 rtc_config.enable_dtls_srtp = true;
2178 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002179
2180 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002181 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002182 pc_->CreateDataChannel(label, nullptr);
2183 EXPECT_NE(channel, nullptr);
2184
zhihuang9763d562016-08-05 11:14:50 -07002185 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002186 pc_->CreateDataChannel(label, nullptr);
2187 EXPECT_NE(dup_channel, nullptr);
2188}
2189
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002190// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2191// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002192TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002193 RTCConfiguration rtc_config;
2194 rtc_config.enable_rtp_data_channel = true;
2195 rtc_config.enable_dtls_srtp = false;
2196 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002197
zhihuang9763d562016-08-05 11:14:50 -07002198 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002199 pc_->CreateDataChannel("test1", NULL);
2200 EXPECT_TRUE(observer_.renegotiation_needed_);
2201 observer_.renegotiation_needed_ = false;
2202
Guido Urdaneta70c2db12019-04-16 12:24:14 +02002203 CreateOfferReceiveAnswer();
2204
zhihuang9763d562016-08-05 11:14:50 -07002205 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002206 pc_->CreateDataChannel("test2", NULL);
Guido Urdaneta70c2db12019-04-16 12:24:14 +02002207 EXPECT_EQ(observer_.renegotiation_needed_,
2208 GetParam() == SdpSemantics::kPlanB);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002209}
2210
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002212TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002213 RTCConfiguration rtc_config;
2214 rtc_config.enable_rtp_data_channel = true;
2215 rtc_config.enable_dtls_srtp = false;
2216 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217
zhihuang9763d562016-08-05 11:14:50 -07002218 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002220 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 pc_->CreateDataChannel("test2", NULL);
2222 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002223 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002225 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 new MockDataChannelObserver(data2));
2227
2228 CreateOfferReceiveAnswer();
2229 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2230 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2231
2232 ReleasePeerConnection();
2233 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2234 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2235}
2236
Zhi Huang644fde42018-04-02 19:16:26 -07002237// This tests that RTP data channels can be rejected in an answer.
2238TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002239 RTCConfiguration rtc_config;
2240 rtc_config.enable_rtp_data_channel = true;
2241 rtc_config.enable_dtls_srtp = false;
2242 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243
zhihuang9763d562016-08-05 11:14:50 -07002244 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 pc_->CreateDataChannel("offer_channel", NULL));
2246
2247 CreateOfferAsLocalDescription();
2248
2249 // Create an answer where the m-line for data channels are rejected.
2250 std::string sdp;
2251 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002252 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002253 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002254 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002256 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 data_info->rejected = true;
2258
Steve Antondb45ca82017-09-11 18:27:34 -07002259 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2261}
2262
Zhi Huang644fde42018-04-02 19:16:26 -07002263#ifdef HAVE_SCTP
2264// This tests that SCTP data channels can be rejected in an answer.
2265TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2266#else
2267TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2268#endif
2269{
Niels Möllerf06f9232018-08-07 12:32:18 +02002270 RTCConfiguration rtc_config;
2271 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002272
2273 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2274 pc_->CreateDataChannel("offer_channel", NULL));
2275
2276 CreateOfferAsLocalDescription();
2277
2278 // Create an answer where the m-line for data channels are rejected.
2279 std::string sdp;
2280 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2281 std::unique_ptr<SessionDescriptionInterface> answer(
2282 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2283 ASSERT_TRUE(answer);
2284 cricket::ContentInfo* data_info =
2285 cricket::GetFirstDataContent(answer->description());
2286 data_info->rejected = true;
2287
2288 DoSetRemoteDescription(std::move(answer));
2289 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2290}
2291
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292// Test that we can create a session description from an SDP string from
2293// FireFox, use it as a remote session description, generate an answer and use
2294// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002295TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002296 RTCConfiguration rtc_config;
2297 rtc_config.enable_dtls_srtp = true;
2298 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002299 AddAudioTrack("audio_label");
2300 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002301 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002302 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002303 webrtc::kFireFoxSdpOffer, nullptr));
2304 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 CreateAnswerAsLocalDescription();
2306 ASSERT_TRUE(pc_->local_description() != NULL);
2307 ASSERT_TRUE(pc_->remote_description() != NULL);
2308
2309 const cricket::ContentInfo* content =
2310 cricket::GetFirstAudioContent(pc_->local_description()->description());
2311 ASSERT_TRUE(content != NULL);
2312 EXPECT_FALSE(content->rejected);
2313
2314 content =
2315 cricket::GetFirstVideoContent(pc_->local_description()->description());
2316 ASSERT_TRUE(content != NULL);
2317 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002318#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 content =
2320 cricket::GetFirstDataContent(pc_->local_description()->description());
2321 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002322 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002323#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324}
2325
zhihuangb19012e2017-09-19 13:47:59 -07002326// Test that fallback from DTLS to SDES is not supported.
2327// The fallback was previously supported but was removed to simplify the code
2328// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002329TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002330 RTCConfiguration rtc_config;
2331 rtc_config.enable_dtls_srtp = true;
2332 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002333 // Wait for fake certificate to be generated. Previously, this is what caused
2334 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002335 AddAudioTrack("audio_label");
2336 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002337 ASSERT_NE(nullptr, fake_certificate_generator_);
2338 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2339 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002340 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002341 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2342 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002343 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002344}
2345
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346// Test that we can create an audio only offer and receive an answer with a
2347// limited set of audio codecs and receive an updated offer with more audio
2348// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002349TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002350 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002351 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 CreateOfferAsLocalDescription();
2353
Steve Anton36da6ff2018-02-16 16:04:20 -08002354 const char* answer_sdp =
2355 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2356 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002357 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002358 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002359 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360
Steve Anton36da6ff2018-02-16 16:04:20 -08002361 const char* reoffer_sdp =
2362 (sdp_semantics_ == SdpSemantics::kPlanB
2363 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2364 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002365 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002366 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002367 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 CreateAnswerAsLocalDescription();
2369}
2370
deadbeefc80741f2015-10-22 13:14:45 -07002371// Test that if we're receiving (but not sending) a track, subsequent offers
2372// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002373TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002374 RTCConfiguration rtc_config;
2375 rtc_config.enable_dtls_srtp = true;
2376 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002377 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002378 CreateAnswerAsLocalDescription();
2379
2380 // At this point we should be receiving stream 1, but not sending anything.
2381 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002382 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002383 DoCreateOffer(&offer, nullptr);
2384
2385 const cricket::ContentInfo* video_content =
2386 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002387 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2388 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002389
2390 const cricket::ContentInfo* audio_content =
2391 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002392 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2393 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002394}
2395
2396// Test that if we're receiving (but not sending) a track, and the
2397// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2398// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002399TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002400 RTCConfiguration rtc_config;
2401 rtc_config.enable_dtls_srtp = true;
2402 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002403 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002404 CreateAnswerAsLocalDescription();
2405
2406 // At this point we should be receiving stream 1, but not sending anything.
2407 // A new offer would be recvonly, but we'll set the "no receive" constraints
2408 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002409 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002410 RTCOfferAnswerOptions options;
2411 options.offer_to_receive_audio = 0;
2412 options.offer_to_receive_video = 0;
2413 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002414
2415 const cricket::ContentInfo* video_content =
2416 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002417 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2418 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002419
2420 const cricket::ContentInfo* audio_content =
2421 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002422 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2423 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002424}
2425
deadbeef653b8e02015-11-11 12:55:10 -08002426// Test that we can use SetConfiguration to change the ICE servers of the
2427// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002428TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002429 CreatePeerConnection();
2430
Steve Anton36da6ff2018-02-16 16:04:20 -08002431 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002432 PeerConnectionInterface::IceServer server;
2433 server.uri = "stun:test_hostname";
2434 config.servers.push_back(server);
2435 EXPECT_TRUE(pc_->SetConfiguration(config));
2436
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002437 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2438 EXPECT_EQ("test_hostname",
2439 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002440}
2441
Steve Anton36da6ff2018-02-16 16:04:20 -08002442TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002443 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002444 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002445 config.type = PeerConnectionInterface::kRelay;
2446 EXPECT_TRUE(pc_->SetConfiguration(config));
2447 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2448}
2449
Steve Anton36da6ff2018-02-16 16:04:20 -08002450TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002451 PeerConnectionInterface::RTCConfiguration config;
2452 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002453 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002454 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002455 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2456
2457 config.prune_turn_ports = true;
2458 EXPECT_TRUE(pc_->SetConfiguration(config));
2459 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2460}
2461
skvladd1f5fda2017-02-03 16:54:05 -08002462// Test that the ice check interval can be changed. This does not verify that
2463// the setting makes it all the way to P2PTransportChannel, as that would
2464// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002465TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002466 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002467 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002468 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002469 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002470 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002471 EXPECT_TRUE(pc_->SetConfiguration(config));
2472 PeerConnectionInterface::RTCConfiguration new_config =
2473 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002474 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002475}
2476
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002477// Test that when SetConfiguration changes both the pool size and other
2478// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002479TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002480 SetConfigurationCreatesPooledSessionCorrectly) {
2481 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002482 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002483 config.ice_candidate_pool_size = 1;
2484 PeerConnectionInterface::IceServer server;
2485 server.uri = kStunAddressOnly;
2486 config.servers.push_back(server);
2487 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002488 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002489
2490 const cricket::FakePortAllocatorSession* session =
2491 static_cast<const cricket::FakePortAllocatorSession*>(
2492 port_allocator_->GetPooledSession());
2493 ASSERT_NE(nullptr, session);
2494 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002495}
2496
deadbeef293e9262017-01-11 12:28:30 -08002497// Test that after SetLocalDescription, changing the pool size is not allowed,
2498// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002499TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002500 CantChangePoolSizeAfterSetLocalDescription) {
2501 CreatePeerConnection();
2502 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002503 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002504 config.ice_candidate_pool_size = 1;
2505 EXPECT_TRUE(pc_->SetConfiguration(config));
2506
2507 // Set remote offer; can still change pool size at this point.
2508 CreateOfferAsRemoteDescription();
2509 config.ice_candidate_pool_size = 2;
2510 EXPECT_TRUE(pc_->SetConfiguration(config));
2511
2512 // Set local answer; now it's too late.
2513 CreateAnswerAsLocalDescription();
2514 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002515 RTCError error;
2516 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2517 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2518}
2519
deadbeef42a42632017-03-10 15:18:00 -08002520// Test that after setting an answer, extra pooled sessions are discarded. The
2521// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002522TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002523 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2524 CreatePeerConnection();
2525
2526 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002527 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002528 config.ice_candidate_pool_size = 4;
2529 EXPECT_TRUE(pc_->SetConfiguration(config));
2530
2531 // Do offer/answer.
2532 CreateOfferAsRemoteDescription();
2533 CreateAnswerAsLocalDescription();
2534
2535 // Expect no pooled sessions to be left.
2536 const cricket::PortAllocatorSession* session =
2537 port_allocator_->GetPooledSession();
2538 EXPECT_EQ(nullptr, session);
2539}
2540
2541// After Close is called, pooled candidates should be discarded so as to not
2542// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002543TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002544 CreatePeerConnection();
2545
Steve Anton36da6ff2018-02-16 16:04:20 -08002546 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002547 config.ice_candidate_pool_size = 3;
2548 EXPECT_TRUE(pc_->SetConfiguration(config));
2549 pc_->Close();
2550
2551 // Expect no pooled sessions to be left.
2552 const cricket::PortAllocatorSession* session =
2553 port_allocator_->GetPooledSession();
2554 EXPECT_EQ(nullptr, session);
2555}
2556
deadbeef293e9262017-01-11 12:28:30 -08002557// Test that SetConfiguration returns an invalid modification error if
2558// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002559TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002560 SetConfigurationReturnsInvalidModificationError) {
2561 PeerConnectionInterface::RTCConfiguration config;
2562 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2563 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2564 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002565 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002566
Steve Anton36da6ff2018-02-16 16:04:20 -08002567 PeerConnectionInterface::RTCConfiguration modified_config =
2568 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002569 modified_config.bundle_policy =
2570 PeerConnectionInterface::kBundlePolicyMaxBundle;
2571 RTCError error;
2572 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2573 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2574
Steve Anton36da6ff2018-02-16 16:04:20 -08002575 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002576 modified_config.rtcp_mux_policy =
2577 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2578 error.set_type(RTCErrorType::NONE);
2579 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2580 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2581
Steve Anton36da6ff2018-02-16 16:04:20 -08002582 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002583 modified_config.continual_gathering_policy =
2584 PeerConnectionInterface::GATHER_CONTINUALLY;
2585 error.set_type(RTCErrorType::NONE);
2586 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2587 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2588}
2589
2590// Test that SetConfiguration returns a range error if the candidate pool size
2591// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002592TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002593 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2594 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002595 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002596 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002597
2598 config.ice_candidate_pool_size = -1;
2599 RTCError error;
2600 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2601 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2602
2603 config.ice_candidate_pool_size = INT_MAX;
2604 error.set_type(RTCErrorType::NONE);
2605 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2606 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2607}
2608
2609// Test that SetConfiguration returns a syntax error if parsing an ICE server
2610// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002611TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002612 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2613 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002614 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002615 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002616
2617 PeerConnectionInterface::IceServer bad_server;
2618 bad_server.uri = "stunn:www.example.com";
2619 config.servers.push_back(bad_server);
2620 RTCError error;
2621 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2622 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2623}
2624
2625// Test that SetConfiguration returns an invalid parameter error if a TURN
2626// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002627TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002628 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2629 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002630 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002631 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002632
2633 PeerConnectionInterface::IceServer bad_server;
2634 bad_server.uri = "turn:www.example.com";
2635 // Missing password.
2636 bad_server.username = "foo";
2637 config.servers.push_back(bad_server);
2638 RTCError error;
2639 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2640 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002641}
2642
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643// Test that PeerConnection::Close changes the states to closed and all remote
2644// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002645TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646 // Initialize a PeerConnection and negotiate local and remote session
2647 // description.
2648 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002649
2650 // With Plan B, verify the stream count. The analog with Unified Plan is the
2651 // RtpTransceiver count.
2652 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2653 ASSERT_EQ(1u, pc_->local_streams()->count());
2654 ASSERT_EQ(1u, pc_->remote_streams()->count());
2655 } else {
2656 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2657 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002658
2659 pc_->Close();
2660
2661 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2662 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2663 pc_->ice_connection_state());
2664 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2665 pc_->ice_gathering_state());
2666
Steve Anton36da6ff2018-02-16 16:04:20 -08002667 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2668 EXPECT_EQ(1u, pc_->local_streams()->count());
2669 EXPECT_EQ(1u, pc_->remote_streams()->count());
2670 } else {
2671 // Verify that the RtpTransceivers are still present but all stopped.
2672 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Mirko Bonadei739baf02019-01-27 17:29:42 +01002673 for (const auto& transceiver : pc_->GetTransceivers()) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002674 EXPECT_TRUE(transceiver->stopped());
2675 }
2676 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677
Steve Anton36da6ff2018-02-16 16:04:20 -08002678 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2679 ASSERT_TRUE(audio_receiver);
2680 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2681 ASSERT_TRUE(video_receiver);
2682
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002683 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002684 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002685 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002686 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002687 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688}
2689
2690// Test that PeerConnection methods fails gracefully after
2691// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002692// Don't run under Unified Plan since the stream API is not available.
2693TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002694 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002695 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696 CreateOfferAsRemoteDescription();
2697 CreateAnswerAsLocalDescription();
2698
2699 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002700 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701 pc_->local_streams()->at(0);
2702
2703 pc_->Close();
2704
2705 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002706 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2709
2710 EXPECT_TRUE(pc_->local_description() != NULL);
2711 EXPECT_TRUE(pc_->remote_description() != NULL);
2712
kwibergd1fe2812016-04-27 06:47:29 -07002713 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002714 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002715 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002716 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717
2718 std::string sdp;
2719 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002720 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002721 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002722 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723
2724 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002725 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002726 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002727 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728}
2729
2730// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002731TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732 InitiateCall();
2733 pc_->Close();
2734 DoGetStats(NULL);
2735}
deadbeefab9b2d12015-10-14 11:33:11 -07002736
2737// NOTE: The series of tests below come from what used to be
2738// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2739// setting a remote or local description has the expected effects.
2740
2741// This test verifies that the remote MediaStreams corresponding to a received
2742// SDP string is created. In this test the two separate MediaStreams are
2743// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002744TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002745 RTCConfiguration config;
2746 config.enable_dtls_srtp = true;
2747 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002748 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002749
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002750 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002751 EXPECT_TRUE(
2752 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2753 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2754 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2755
2756 // Create a session description based on another SDP with another
2757 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002758 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002759
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002760 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002761 EXPECT_TRUE(
2762 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2763}
2764
2765// This test verifies that when remote tracks are added/removed from SDP, the
2766// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002767// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2768// specific behavior.
2769TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002770 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002771 RTCConfiguration config;
2772 config.enable_dtls_srtp = true;
2773 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002774 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002775 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002776 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002777 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2778 reference_collection_));
2779
2780 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002781 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002782 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002783 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002784 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2785 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002786 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002787 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2788 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002789 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002790 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2791 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002792
2793 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002794 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002795 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002796 MockTrackObserver audio_track_observer(audio_track2);
2797 MockTrackObserver video_track_observer(video_track2);
2798
2799 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2800 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002801 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002802 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2803 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002804 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002805 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002806 audio_track2->state(), kTimeout);
2807 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2808 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002809}
2810
2811// This tests that remote tracks are ended if a local session description is set
2812// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002813TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002814 RTCConfiguration config;
2815 config.enable_dtls_srtp = true;
2816 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002817 // First create and set a remote offer, then reject its video content in our
2818 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002819 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2820 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2821 ASSERT_TRUE(audio_receiver);
2822 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2823 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002824
Steve Anton36da6ff2018-02-16 16:04:20 -08002825 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2826 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002827 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002828 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2829 video_receiver->track();
2830 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002831
kwibergd1fe2812016-04-27 06:47:29 -07002832 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002833 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002834 cricket::ContentInfo* video_info =
2835 local_answer->description()->GetContentByName("video");
2836 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002837 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002838 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2839 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002840
2841 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002842 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002843 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002844 video_info = local_offer->description()->GetContentByName("video");
2845 ASSERT_TRUE(video_info != nullptr);
2846 video_info->rejected = true;
2847 cricket::ContentInfo* audio_info =
2848 local_offer->description()->GetContentByName("audio");
2849 ASSERT_TRUE(audio_info != nullptr);
2850 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002851 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002852 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002853 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2854 kTimeout);
2855 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2856 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002857}
2858
2859// This tests that we won't crash if the remote track has been removed outside
2860// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002861// Don't run under Unified Plan since the stream API is not available.
2862TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002863 RTCConfiguration config;
2864 config.enable_dtls_srtp = true;
2865 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002866 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002867 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2868 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2869 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2870
kwibergd1fe2812016-04-27 06:47:29 -07002871 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002872 webrtc::CreateSessionDescription(SdpType::kAnswer,
2873 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002874 cricket::ContentInfo* video_info =
2875 local_answer->description()->GetContentByName("video");
2876 video_info->rejected = true;
2877 cricket::ContentInfo* audio_info =
2878 local_answer->description()->GetContentByName("audio");
2879 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002880 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002881
2882 // No crash is a pass.
2883}
2884
deadbeef5e97fb52015-10-15 12:49:08 -07002885// This tests that if a recvonly remote description is set, no remote streams
2886// will be created, even if the description contains SSRCs/MSIDs.
2887// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002888TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002889 RTCConfiguration config;
2890 config.enable_dtls_srtp = true;
2891 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002892
Steve Anton36da6ff2018-02-16 16:04:20 -08002893 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002894 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 12:49:08 -07002895 CreateAndSetRemoteOffer(recvonly_offer);
2896
2897 EXPECT_EQ(0u, observer_.remote_streams()->count());
2898}
2899
deadbeefab9b2d12015-10-14 11:33:11 -07002900// This tests that a default MediaStream is created if a remote session
2901// description doesn't contain any streams and no MSID support.
2902// It also tests that the default stream is updated if a video m-line is added
2903// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002904// Don't run under Unified Plan since this behavior is Plan B specific.
2905TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002906 RTCConfiguration config;
2907 config.enable_dtls_srtp = true;
2908 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002909 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2910
2911 ASSERT_EQ(1u, observer_.remote_streams()->count());
2912 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2913
2914 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2915 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002916 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002917
2918 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2919 ASSERT_EQ(1u, observer_.remote_streams()->count());
2920 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2921 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002922 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2923 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002924 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2925 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002926 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2927 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002928}
2929
2930// This tests that a default MediaStream is created if a remote session
2931// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002932// Don't run under Unified Plan since this behavior is Plan B specific.
2933TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002934 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002935 RTCConfiguration config;
2936 config.enable_dtls_srtp = true;
2937 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002938 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2939
2940 ASSERT_EQ(1u, observer_.remote_streams()->count());
2941 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2942
2943 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2944 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002945 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002946}
2947
2948// This tests that it won't crash when PeerConnection tries to remove
2949// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002950// Don't run under Unified Plan since this behavior is Plan B specific.
2951TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002952 RTCConfiguration config;
2953 config.enable_dtls_srtp = true;
2954 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002955 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002956 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2957 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2958 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2959
2960 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2961
2962 // No crash is a pass.
2963}
2964
2965// This tests that a default MediaStream is created if the remote session
2966// description doesn't contain any streams and don't contain an indication if
2967// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002968// Don't run under Unified Plan since this behavior is Plan B specific.
2969TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002970 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002971 RTCConfiguration config;
2972 config.enable_dtls_srtp = true;
2973 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002974 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2975
2976 ASSERT_EQ(1u, observer_.remote_streams()->count());
2977 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2978 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2979 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2980}
2981
2982// This tests that a default MediaStream is not created if the remote session
2983// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002984// Don't run under Unified Plan since this behavior is Plan B specific.
2985TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002986 RTCConfiguration config;
2987 config.enable_dtls_srtp = true;
2988 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002989 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2990 EXPECT_EQ(0u, observer_.remote_streams()->count());
2991}
2992
deadbeefbda7e0b2015-12-08 17:13:40 -08002993// This tests that when setting a new description, the old default tracks are
2994// not destroyed and recreated.
2995// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002996// Don't run under Unified Plan since this behavior is Plan B specific.
2997TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002998 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002999 RTCConfiguration config;
3000 config.enable_dtls_srtp = true;
3001 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08003002 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3003
3004 ASSERT_EQ(1u, observer_.remote_streams()->count());
3005 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3006 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3007
3008 // Set the track to "disabled", then set a new description and ensure the
3009 // track is still disabled, which ensures it hasn't been recreated.
3010 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3011 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3012 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3013 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3014}
3015
deadbeefab9b2d12015-10-14 11:33:11 -07003016// This tests that a default MediaStream is not created if a remote session
3017// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003018// Don't run under Unified Plan since this behavior is Plan B specific.
3019TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003020 RTCConfiguration config;
3021 config.enable_dtls_srtp = true;
3022 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003023 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003024 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003025 EXPECT_TRUE(
3026 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3027
3028 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3029 EXPECT_EQ(0u, observer_.remote_streams()->count());
3030}
3031
Seth Hampson5897a6e2018-04-03 11:16:33 -07003032// This tests that a default MediaStream is created if a remote SDP comes from
3033// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3034TEST_F(PeerConnectionInterfaceTestPlanB,
3035 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003036 RTCConfiguration config;
3037 config.enable_dtls_srtp = true;
3038 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003039 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3040 // Add a=msid lines to simulate a Unified Plan endpoint that only
3041 // signals stream IDs with a=msid lines.
3042 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3043
3044 CreateAndSetRemoteOffer(sdp_string);
3045
3046 ASSERT_EQ(1u, observer_.remote_streams()->count());
3047 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3048 EXPECT_EQ("default", remote_stream->id());
3049 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3050}
3051
Seth Hampson5b4f0752018-04-02 16:31:36 -07003052// This tests that when a Plan B endpoint receives an SDP that signals no media
3053// stream IDs indicated by the special character "-" in the a=msid line, that
3054// a default stream ID will be used for the MediaStream ID. This can occur
3055// when a Unified Plan endpoint signals no media stream IDs, but signals both
3056// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3057TEST_F(PeerConnectionInterfaceTestPlanB,
3058 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003059 RTCConfiguration config;
3060 config.enable_dtls_srtp = true;
3061 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003062 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3063 // the sender's stream ID will be interpreted as no stream IDs.
3064 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3065 sdp_string.append("a=msid:- audiotrack0\n");
3066
3067 CreateAndSetRemoteOffer(sdp_string);
3068
3069 ASSERT_EQ(1u, observer_.remote_streams()->count());
3070 // Because SSRCs are signaled the track ID will be what was signaled in the
3071 // a=msid line.
3072 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3073 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3074 EXPECT_EQ("default", remote_stream->id());
3075 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003076
3077 // Previously a bug ocurred when setting the remote description a second time.
3078 // This is because we checked equality of the remote StreamParams stream ID
3079 // (empty), and the previously set stream ID for the remote sender
3080 // ("default"). This cause a track to be removed, then added, when really
3081 // nothing should occur because it is the same track.
3082 CreateAndSetRemoteOffer(sdp_string);
3083 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3084 EXPECT_EQ(1u, observer_.add_track_events_.size());
3085 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3086 remote_stream = observer_.remote_streams()->at(0);
3087 EXPECT_EQ("default", remote_stream->id());
3088 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003089}
3090
deadbeefab9b2d12015-10-14 11:33:11 -07003091// This tests that an RtpSender is created when the local description is set
3092// after adding a local stream.
3093// TODO(deadbeef): This test and the one below it need to be updated when
3094// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003095// Don't run under Unified Plan since this behavior is Plan B specific.
3096TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003097 RTCConfiguration config;
3098 config.enable_dtls_srtp = true;
3099 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003100
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003101 // Create an offer with 1 stream with 2 tracks of each type.
3102 rtc::scoped_refptr<StreamCollection> stream_collection =
3103 CreateStreamCollection(1, 2);
3104 pc_->AddStream(stream_collection->at(0));
3105 std::unique_ptr<SessionDescriptionInterface> offer;
3106 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003107 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003108
deadbeefab9b2d12015-10-14 11:33:11 -07003109 auto senders = pc_->GetSenders();
3110 EXPECT_EQ(4u, senders.size());
3111 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3112 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3113 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3114 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3115
3116 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003117 pc_->RemoveStream(stream_collection->at(0));
3118 stream_collection = CreateStreamCollection(1, 1);
3119 pc_->AddStream(stream_collection->at(0));
3120 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003121 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003122
deadbeefab9b2d12015-10-14 11:33:11 -07003123 senders = pc_->GetSenders();
3124 EXPECT_EQ(2u, senders.size());
3125 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3126 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3127 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3128 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3129}
3130
3131// This tests that an RtpSender is created when the local description is set
3132// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003133// Don't run under Unified Plan since this behavior is Plan B specific.
3134TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003135 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003136 RTCConfiguration config;
3137 config.enable_dtls_srtp = true;
3138 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003139
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003140 rtc::scoped_refptr<StreamCollection> stream_collection =
3141 CreateStreamCollection(1, 2);
3142 // Add a stream to create the offer, but remove it afterwards.
3143 pc_->AddStream(stream_collection->at(0));
3144 std::unique_ptr<SessionDescriptionInterface> offer;
3145 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3146 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003147
Steve Antondb45ca82017-09-11 18:27:34 -07003148 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003149 auto senders = pc_->GetSenders();
3150 EXPECT_EQ(0u, senders.size());
3151
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003152 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003153 senders = pc_->GetSenders();
3154 EXPECT_EQ(4u, senders.size());
3155 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3156 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3157 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3158 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3159}
3160
3161// This tests that the expected behavior occurs if the SSRC on a local track is
3162// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003163TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003164 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003165 RTCConfiguration config;
3166 config.enable_dtls_srtp = true;
3167 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003168
Steve Anton36da6ff2018-02-16 16:04:20 -08003169 AddAudioTrack(kAudioTracks[0]);
3170 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003171 std::unique_ptr<SessionDescriptionInterface> offer;
3172 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3173 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003174 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3175 webrtc::CreateSessionDescription(
3176 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003177 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-11 18:27:34 -07003178 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003179
deadbeefab9b2d12015-10-14 11:33:11 -07003180 auto senders = pc_->GetSenders();
3181 EXPECT_EQ(2u, senders.size());
3182 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3183 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3184
3185 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003186 cricket::MediaContentDescription* desc =
3187 cricket::GetFirstAudioContentDescription(modified_offer->description());
3188 ASSERT_TRUE(desc != NULL);
3189 for (StreamParams& stream : desc->mutable_streams()) {
3190 for (unsigned int& ssrc : stream.ssrcs) {
3191 ++ssrc;
3192 }
3193 }
deadbeefab9b2d12015-10-14 11:33:11 -07003194
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003195 desc =
3196 cricket::GetFirstVideoContentDescription(modified_offer->description());
3197 ASSERT_TRUE(desc != NULL);
3198 for (StreamParams& stream : desc->mutable_streams()) {
3199 for (unsigned int& ssrc : stream.ssrcs) {
3200 ++ssrc;
3201 }
3202 }
3203
Steve Antondb45ca82017-09-11 18:27:34 -07003204 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003205 senders = pc_->GetSenders();
3206 EXPECT_EQ(2u, senders.size());
3207 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3208 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3209 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3210 // changed.
3211}
3212
3213// This tests that the expected behavior occurs if a new session description is
3214// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003215// Don't run under Unified Plan since the stream API is not available.
3216TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003217 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003218 RTCConfiguration config;
3219 config.enable_dtls_srtp = true;
3220 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003221
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003222 rtc::scoped_refptr<StreamCollection> stream_collection =
3223 CreateStreamCollection(2, 1);
3224 pc_->AddStream(stream_collection->at(0));
3225 std::unique_ptr<SessionDescriptionInterface> offer;
3226 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003227 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003228
deadbeefab9b2d12015-10-14 11:33:11 -07003229 auto senders = pc_->GetSenders();
3230 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003231 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3232 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003233
3234 // Add a new MediaStream but with the same tracks as in the first stream.
3235 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3236 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003237 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3238 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003239 pc_->AddStream(stream_1);
3240
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003241 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003242 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003243
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003244 auto new_senders = pc_->GetSenders();
3245 // Should be the same senders as before, but with updated stream id.
3246 // Note that this behavior is subject to change in the future.
3247 // We may decide the PC should ignore existing tracks in AddStream.
3248 EXPECT_EQ(senders, new_senders);
3249 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3250 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003251}
3252
zhihuang81c3a032016-11-17 12:06:24 -08003253// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003254TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003255 RTCConfiguration config;
3256 config.enable_dtls_srtp = true;
3257 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003258 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3259 EXPECT_EQ(observer_.num_added_tracks_, 1);
3260 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3261
3262 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003263 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003264 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003265 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3266}
3267
deadbeefd1a38b52016-12-10 13:15:33 -08003268// Test that when SetConfiguration is called and the configuration is
3269// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003270TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003271 PeerConnectionInterface::RTCConfiguration config;
3272 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003273 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003274 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003275 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3276 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003277
3278 // Do initial offer/answer so there's something to restart.
3279 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003280 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003281
3282 // Grab the ufrags.
3283 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3284
3285 // Change ICE policy, which should trigger an ICE restart on the next offer.
3286 config.type = PeerConnectionInterface::kAll;
3287 EXPECT_TRUE(pc_->SetConfiguration(config));
3288 CreateOfferAsLocalDescription();
3289
3290 // Grab the new ufrags.
3291 std::vector<std::string> subsequent_ufrags =
3292 GetUfrags(pc_->local_description());
3293
3294 // Sanity check.
3295 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3296 // Check that each ufrag is different.
3297 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3298 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3299 }
3300}
3301
3302// Test that when SetConfiguration is called and the configuration *isn't*
3303// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003304TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003305 PeerConnectionInterface::RTCConfiguration config;
3306 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003307 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003308 config = pc_->GetConfiguration();
3309 AddAudioTrack(kAudioTracks[0]);
3310 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003311
3312 // Do initial offer/answer so there's something to restart.
3313 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003314 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003315
3316 // Grab the ufrags.
3317 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3318
3319 // Call SetConfiguration with a config identical to what the PC was
3320 // constructed with.
3321 EXPECT_TRUE(pc_->SetConfiguration(config));
3322 CreateOfferAsLocalDescription();
3323
3324 // Grab the new ufrags.
3325 std::vector<std::string> subsequent_ufrags =
3326 GetUfrags(pc_->local_description());
3327
3328 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3329}
3330
3331// Test for a weird corner case scenario:
3332// 1. Audio/video session established.
3333// 2. SetConfiguration changes ICE config; ICE restart needed.
3334// 3. ICE restart initiated by remote peer, but only for one m= section.
3335// 4. Next createOffer should initiate an ICE restart, but only for the other
3336// m= section; it would be pointless to do an ICE restart for the m= section
3337// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003338TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003339 PeerConnectionInterface::RTCConfiguration config;
3340 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003341 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003342 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003343 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3344 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003345
3346 // Do initial offer/answer so there's something to restart.
3347 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003348 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003349
3350 // Change ICE policy, which should set the "needs-ice-restart" flag.
3351 config.type = PeerConnectionInterface::kAll;
3352 EXPECT_TRUE(pc_->SetConfiguration(config));
3353
3354 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003355 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003356 webrtc::CreateSessionDescription(SdpType::kOffer,
3357 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003358 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003359 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3360 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003361 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003362 CreateAnswerAsLocalDescription();
3363
3364 // Grab the ufrags.
3365 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003366 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003367
3368 // Create offer and grab the new ufrags.
3369 CreateOfferAsLocalDescription();
3370 std::vector<std::string> subsequent_ufrags =
3371 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003372 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003373
3374 // Ensure that only the ufrag for the second m= section changed.
3375 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3376 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3377}
3378
deadbeeffe4a8a42016-12-20 17:56:17 -08003379// Tests that the methods to return current/pending descriptions work as
3380// expected at different points in the offer/answer exchange. This test does
3381// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003382TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003383 // This disables DTLS so we can apply an answer to ourselves.
3384 CreatePeerConnection();
3385
3386 // Create initial local offer and get SDP (which will also be used as
3387 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003388 std::unique_ptr<SessionDescriptionInterface> local_offer;
3389 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003390 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003391 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003392
3393 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003394 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3395 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3396 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003397 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3398 EXPECT_EQ(nullptr, pc_->current_local_description());
3399 EXPECT_EQ(nullptr, pc_->current_remote_description());
3400
3401 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003402 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003403 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003404 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3405 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3406 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3407 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003408 EXPECT_EQ(nullptr, pc_->current_local_description());
3409 EXPECT_EQ(nullptr, pc_->current_remote_description());
3410
3411 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003412 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003413 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003414 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3415 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003416 EXPECT_EQ(nullptr, pc_->pending_local_description());
3417 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003418 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3419 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003420
3421 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003422 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003423 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003424 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3425 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3426 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003427 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003428 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3429 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003430
3431 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003432 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003433 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003434 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3435 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3436 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3437 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3438 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3439 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003440
3441 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003442 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003443 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003444 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3445 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003446 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3447 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003448 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3449 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003450}
3451
zhihuang77985012017-02-07 15:45:16 -08003452// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3453// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003454// This version tests the StartRtcEventLog version that receives an object
3455// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003456TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003457 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3458 CreatePeerConnection();
3459 // The RtcEventLog will be reset when the PeerConnection is closed.
3460 pc_->Close();
3461
Niels Möllerdec9f742019-06-03 15:25:20 +02003462 EXPECT_FALSE(
3463 pc_->StartRtcEventLog(absl::make_unique<webrtc::RtcEventLogOutputNull>(),
3464 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003465 pc_->StopRtcEventLog();
3466}
3467
deadbeef30952b42017-04-21 02:41:29 -07003468// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003469TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003470 CreatePeerConnection();
3471
3472 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003473 RTCOfferAnswerOptions options;
3474 options.offer_to_receive_audio = 1;
3475 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003476 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003477 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003478 cricket::SessionDescription* desc = offer->description();
3479 ASSERT_EQ(2u, desc->transport_infos().size());
3480 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3481 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3482
3483 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003484 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003485 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003486 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003487 desc = answer->description();
3488 ASSERT_EQ(2u, desc->transport_infos().size());
3489 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3490 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3491}
3492
deadbeef1dcb1642017-03-29 21:08:16 -07003493// Test that ICE renomination isn't offered if it's not enabled in the PC's
3494// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003495TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003496 PeerConnectionInterface::RTCConfiguration config;
3497 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003498 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003499 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003500
3501 std::unique_ptr<SessionDescriptionInterface> offer;
3502 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3503 cricket::SessionDescription* desc = offer->description();
3504 EXPECT_EQ(1u, desc->transport_infos().size());
3505 EXPECT_FALSE(
3506 desc->transport_infos()[0].description.GetIceParameters().renomination);
3507}
3508
3509// Test that the ICE renomination option is present in generated offers/answers
3510// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003511TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003512 PeerConnectionInterface::RTCConfiguration config;
3513 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003514 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003515 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003516
3517 std::unique_ptr<SessionDescriptionInterface> offer;
3518 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3519 cricket::SessionDescription* desc = offer->description();
3520 EXPECT_EQ(1u, desc->transport_infos().size());
3521 EXPECT_TRUE(
3522 desc->transport_infos()[0].description.GetIceParameters().renomination);
3523
3524 // Set the offer as a remote description, then create an answer and ensure it
3525 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003526 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003527 std::unique_ptr<SessionDescriptionInterface> answer;
3528 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3529 desc = answer->description();
3530 EXPECT_EQ(1u, desc->transport_infos().size());
3531 EXPECT_TRUE(
3532 desc->transport_infos()[0].description.GetIceParameters().renomination);
3533}
3534
3535// Test that if CreateOffer is called with the deprecated "offer to receive
3536// audio/video" constraints, they're processed and result in an offer with
3537// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003538TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003539 CreatePeerConnection();
3540
Niels Möllerf06f9232018-08-07 12:32:18 +02003541 RTCOfferAnswerOptions options;
3542 options.offer_to_receive_audio = 1;
3543 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003544 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003545 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003546
3547 cricket::SessionDescription* desc = offer->description();
3548 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3549 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3550 ASSERT_NE(nullptr, audio);
3551 ASSERT_NE(nullptr, video);
3552 EXPECT_FALSE(audio->rejected);
3553 EXPECT_FALSE(video->rejected);
3554}
3555
3556// Test that if CreateAnswer is called with the deprecated "offer to receive
3557// audio/video" constraints, they're processed and can be used to reject an
3558// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003559// Don't run under Unified Plan since this behavior is not supported.
3560TEST_F(PeerConnectionInterfaceTestPlanB,
3561 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003562 CreatePeerConnection();
3563
3564 // First, create an offer with audio/video and apply it as a remote
3565 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003566 RTCOfferAnswerOptions options;
3567 options.offer_to_receive_audio = 1;
3568 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003569 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003570 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003571 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003572
3573 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003574 options.offer_to_receive_audio = 0;
3575 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003576 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003577 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003578
3579 cricket::SessionDescription* desc = answer->description();
3580 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3581 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3582 ASSERT_NE(nullptr, audio);
3583 ASSERT_NE(nullptr, video);
3584 EXPECT_TRUE(audio->rejected);
3585 EXPECT_TRUE(video->rejected);
3586}
3587
deadbeef1dcb1642017-03-29 21:08:16 -07003588// Test that negotiation can succeed with a data channel only, and with the max
3589// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003590#ifdef HAVE_SCTP
3591TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3592#else
3593TEST_P(PeerConnectionInterfaceTest,
3594 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3595#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003596 PeerConnectionInterface::RTCConfiguration config;
3597 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003598 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003599
3600 // First, create an offer with only a data channel and apply it as a remote
3601 // description.
3602 pc_->CreateDataChannel("test", nullptr);
3603 std::unique_ptr<SessionDescriptionInterface> offer;
3604 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003605 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003606
3607 // Create and set answer as well.
3608 std::unique_ptr<SessionDescriptionInterface> answer;
3609 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003610 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003611}
3612
Steve Anton36da6ff2018-02-16 16:04:20 -08003613TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003614 CreatePeerConnection();
3615 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003616 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003617 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3618}
3619
Steve Anton36da6ff2018-02-16 16:04:20 -08003620TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003621 CreatePeerConnection();
3622 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003623 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003624 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3625}
3626
Steve Anton36da6ff2018-02-16 16:04:20 -08003627TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003628 CreatePeerConnection();
3629 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003630 bitrate.min_bitrate_bps = 5;
3631 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003632 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3633}
3634
Steve Anton36da6ff2018-02-16 16:04:20 -08003635TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003636 CreatePeerConnection();
3637 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003638 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003639 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3640}
3641
Steve Anton36da6ff2018-02-16 16:04:20 -08003642TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003643 CreatePeerConnection();
3644 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003645 bitrate.current_bitrate_bps = 10;
3646 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003647 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3648}
3649
Steve Anton36da6ff2018-02-16 16:04:20 -08003650TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003651 CreatePeerConnection();
3652 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003653 bitrate.min_bitrate_bps = 10;
3654 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003655 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3656}
3657
Steve Anton36da6ff2018-02-16 16:04:20 -08003658TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003659 CreatePeerConnection();
3660 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003661 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003662 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3663}
3664
Steve Anton038834f2017-07-14 15:59:59 -07003665// ice_regather_interval_range requires WebRTC to be configured for continual
3666// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003667TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003668 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3669 PeerConnectionInterface::RTCConfiguration config;
3670 config.ice_regather_interval_range.emplace(1000, 2000);
3671 config.continual_gathering_policy =
3672 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3673 CreatePeerConnectionExpectFail(config);
3674}
3675
3676// Ensures that there is no error when ice_regather_interval_range is set with
3677// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003678TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003679 SetIceRegatherIntervalRangeWithContinualGathering) {
3680 PeerConnectionInterface::RTCConfiguration config;
3681 config.ice_regather_interval_range.emplace(1000, 2000);
3682 config.continual_gathering_policy =
3683 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003684 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003685}
3686
Niels Möller0c4f7be2018-05-07 14:01:37 +02003687// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003688// by Call's BitrateConstraints, which comes from the SDP or a default value.
3689// This test checks that a call to SetBitrate with a current bitrate that will
3690// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003691TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003692 CreatePeerConnection();
3693 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003694 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003695 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3696}
3697
zhihuang1c378ed2017-08-17 14:10:50 -07003698// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003699TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003700 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3701 RTCOfferAnswerOptions rtc_options;
3702
3703 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3704 // than kMaxOfferToReceiveMedia should be treated as invalid.
3705 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3706 CreatePeerConnection();
3707 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3708
3709 rtc_options.offer_to_receive_audio =
3710 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3711 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3712}
3713
Steve Anton36da6ff2018-02-16 16:04:20 -08003714TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003715 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3716 RTCOfferAnswerOptions rtc_options;
3717
3718 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3719 // than kMaxOfferToReceiveMedia should be treated as invalid.
3720 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3721 CreatePeerConnection();
3722 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3723
3724 rtc_options.offer_to_receive_video =
3725 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3726 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3727}
3728
3729// Test that the audio and video content will be added to an offer if both
3730// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003731TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003732 RTCOfferAnswerOptions rtc_options;
3733 rtc_options.offer_to_receive_audio = 1;
3734 rtc_options.offer_to_receive_video = 1;
3735
3736 std::unique_ptr<SessionDescriptionInterface> offer;
3737 CreatePeerConnection();
3738 offer = CreateOfferWithOptions(rtc_options);
3739 ASSERT_TRUE(offer);
3740 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3741 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3742}
3743
3744// Test that only audio content will be added to the offer if only
3745// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003746TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003747 RTCOfferAnswerOptions rtc_options;
3748 rtc_options.offer_to_receive_audio = 1;
3749 rtc_options.offer_to_receive_video = 0;
3750
3751 std::unique_ptr<SessionDescriptionInterface> offer;
3752 CreatePeerConnection();
3753 offer = CreateOfferWithOptions(rtc_options);
3754 ASSERT_TRUE(offer);
3755 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3756 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3757}
3758
3759// Test that only video content will be added if only |offer_to_receive_video|
3760// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003761TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003762 RTCOfferAnswerOptions rtc_options;
3763 rtc_options.offer_to_receive_audio = 0;
3764 rtc_options.offer_to_receive_video = 1;
3765
3766 std::unique_ptr<SessionDescriptionInterface> offer;
3767 CreatePeerConnection();
3768 offer = CreateOfferWithOptions(rtc_options);
3769 ASSERT_TRUE(offer);
3770 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3771 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3772}
3773
zhihuang1c378ed2017-08-17 14:10:50 -07003774// Test that no media content will be added to the offer if using default
3775// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003776TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003777 RTCOfferAnswerOptions rtc_options;
3778
3779 std::unique_ptr<SessionDescriptionInterface> offer;
3780 CreatePeerConnection();
3781 offer = CreateOfferWithOptions(rtc_options);
3782 ASSERT_TRUE(offer);
3783 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3784 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3785}
3786
3787// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3788// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003789TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3790 CreatePeerConnection();
3791
zhihuang1c378ed2017-08-17 14:10:50 -07003792 RTCOfferAnswerOptions rtc_options;
3793 rtc_options.ice_restart = false;
3794 rtc_options.offer_to_receive_audio = 1;
3795
3796 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003797 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003798 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3799 auto ufrag1 =
3800 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3801 auto pwd1 =
3802 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003803
3804 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3805 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003806 auto ufrag2 =
3807 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3808 auto pwd2 =
3809 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003810
3811 // |ice_restart| is true, the ufrag/pwd should change.
3812 rtc_options.ice_restart = true;
3813 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003814 auto ufrag3 =
3815 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3816 auto pwd3 =
3817 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003818
3819 EXPECT_EQ(ufrag1, ufrag2);
3820 EXPECT_EQ(pwd1, pwd2);
3821 EXPECT_NE(ufrag2, ufrag3);
3822 EXPECT_NE(pwd2, pwd3);
3823}
3824
3825// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3826// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003827TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003828 RTCOfferAnswerOptions rtc_options;
3829 rtc_options.offer_to_receive_audio = 1;
3830 rtc_options.offer_to_receive_video = 1;
3831
3832 std::unique_ptr<SessionDescriptionInterface> offer;
3833 CreatePeerConnection();
3834
3835 rtc_options.use_rtp_mux = true;
3836 offer = CreateOfferWithOptions(rtc_options);
3837 ASSERT_TRUE(offer);
3838 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3839 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3840 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3841
3842 rtc_options.use_rtp_mux = false;
3843 offer = CreateOfferWithOptions(rtc_options);
3844 ASSERT_TRUE(offer);
3845 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3846 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3847 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3848}
3849
zhihuang141aacb2017-08-29 13:23:53 -07003850// This test ensures OnRenegotiationNeeded is called when we add track with
3851// MediaStream -> AddTrack in the same way it is called when we add track with
3852// PeerConnection -> AddTrack.
3853// The test can be removed once addStream is rewritten in terms of addTrack
3854// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003855// Don't run under Unified Plan since the stream API is not available.
3856TEST_F(PeerConnectionInterfaceTestPlanB,
3857 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003858 CreatePeerConnectionWithoutDtls();
3859 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003860 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003861 pc_->AddStream(stream);
3862 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003863 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003864 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003865 CreateVideoTrack("video_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003866 stream->AddTrack(audio_track);
3867 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3868 observer_.renegotiation_needed_ = false;
3869
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003870 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003871 stream->AddTrack(video_track);
3872 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3873 observer_.renegotiation_needed_ = false;
3874
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003875 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003876 stream->RemoveTrack(audio_track);
3877 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3878 observer_.renegotiation_needed_ = false;
3879
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003880 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003881 stream->RemoveTrack(video_track);
3882 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3883 observer_.renegotiation_needed_ = false;
3884}
3885
Zhi Huangb2d355e2017-10-26 17:26:37 -07003886// Tests that an error is returned if a description is applied that has fewer
3887// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003888TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003889 MediaSectionCountEnforcedForSubsequentOffer) {
3890 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003891 AddAudioTrack("audio_label");
3892 AddVideoTrack("video_label");
3893
Zhi Huangb2d355e2017-10-26 17:26:37 -07003894 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003895 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003896 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3897
3898 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003899 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003900 offer->description()->contents().pop_back();
3901 offer->description()->contents().pop_back();
3902 ASSERT_TRUE(offer->description()->contents().empty());
3903 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3904
3905 std::unique_ptr<SessionDescriptionInterface> answer;
3906 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3907 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3908
3909 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003910 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003911 offer->description()->contents().pop_back();
3912 offer->description()->contents().pop_back();
3913 ASSERT_TRUE(offer->description()->contents().empty());
3914 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3915}
3916
Johannes Kron89f874e2018-11-12 10:25:48 +01003917TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3918 RTCConfiguration config;
3919 // Default behavior is false.
3920 CreatePeerConnection(config);
3921 std::unique_ptr<SessionDescriptionInterface> offer;
3922 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3923 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3924 // Possible to set to true.
3925 config.offer_extmap_allow_mixed = true;
3926 CreatePeerConnection(config);
3927 offer.release();
3928 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3929 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3930}
3931
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003932INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3933 PeerConnectionInterfaceTest,
3934 Values(SdpSemantics::kPlanB,
3935 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003936
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003937class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 02:27:06 -08003938 protected:
3939 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003940 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003941 pcf_->Initialize();
3942 }
nisseeaabdf62017-05-05 02:23:02 -07003943 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003944 const RTCConfiguration& config) {
3945 rtc::scoped_refptr<PeerConnectionInterface> pc(
3946 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003947 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003948 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003949 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003950 }
3951
zhihuang9763d562016-08-05 11:14:50 -07003952 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003953 MockPeerConnectionObserver observer_;
3954};
3955
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003956// This sanity check validates the test infrastructure itself.
3957TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3958 PeerConnectionInterface::RTCConfiguration config;
3959 rtc::scoped_refptr<PeerConnectionInterface> pc(
3960 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3961 EXPECT_TRUE(pc.get());
3962 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3963 pc->Close(); // No abort -> ok.
3964 SUCCEED();
3965}
3966
nisse51542be2016-02-12 02:27:06 -08003967// This test verifies the default behaviour with no constraints and a
3968// default RTCConfiguration.
3969TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3970 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003971
Niels Möllerf06f9232018-08-07 12:32:18 +02003972 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003973
3974 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003975 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3976 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003977 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003978 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003979}
3980
Niels Möller1d7ecd22018-01-18 15:25:12 +01003981// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003982// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003983TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3984 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003985
Niels Möller71bdda02016-03-31 12:59:59 +02003986 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02003987 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003988
Niels Möller1d7ecd22018-01-18 15:25:12 +01003989 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003990}
3991
Niels Möller6539f692018-01-18 08:58:50 +01003992// This test verifies that the experiment_cpu_load_estimator flag is
3993// propagated from RTCConfiguration to the PeerConnection.
3994TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
3995 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01003996
3997 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02003998 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01003999
4000 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4001}
4002
deadbeef293e9262017-01-11 12:28:30 -08004003// Tests a few random fields being different.
4004TEST(RTCConfigurationTest, ComparisonOperators) {
4005 PeerConnectionInterface::RTCConfiguration a;
4006 PeerConnectionInterface::RTCConfiguration b;
4007 EXPECT_EQ(a, b);
4008
4009 PeerConnectionInterface::RTCConfiguration c;
4010 c.servers.push_back(PeerConnectionInterface::IceServer());
4011 EXPECT_NE(a, c);
4012
4013 PeerConnectionInterface::RTCConfiguration d;
4014 d.type = PeerConnectionInterface::kRelay;
4015 EXPECT_NE(a, d);
4016
4017 PeerConnectionInterface::RTCConfiguration e;
4018 e.audio_jitter_buffer_max_packets = 5;
4019 EXPECT_NE(a, e);
4020
4021 PeerConnectionInterface::RTCConfiguration f;
4022 f.ice_connection_receiving_timeout = 1337;
4023 EXPECT_NE(a, f);
4024
4025 PeerConnectionInterface::RTCConfiguration g;
4026 g.disable_ipv6 = true;
4027 EXPECT_NE(a, g);
4028
4029 PeerConnectionInterface::RTCConfiguration h(
4030 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4031 EXPECT_NE(a, h);
4032}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01004033
4034} // namespace
4035} // namespace webrtc