blob: 345c46e4f359c7fa3a33cf7ec4d50b526a56ed17 [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
Jonas Olssona4d87372019-07-05 19:08:33 +020011#include "api/peer_connection_interface.h"
12
Yves Gerey3e707812018-11-28 16:47:49 +010013#include <limits.h>
14#include <stdint.h>
15#include <string.h>
Jonas Olssona4d87372019-07-05 19:08:33 +020016
kwibergd1fe2812016-04-27 06:47:29 -070017#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080019#include <utility>
Yves Gerey3e707812018-11-28 16:47:49 +010020#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
Karl Wiberg918f50c2018-07-05 11:40:33 +020022#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080023#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010024#include "absl/types/optional.h"
25#include "api/audio/audio_mixer.h"
26#include "api/audio_codecs/audio_decoder_factory.h"
27#include "api/audio_codecs/audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "api/audio_codecs/builtin_audio_decoder_factory.h"
29#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "api/call/call_factory_interface.h"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010031#include "api/create_peerconnection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080032#include "api/data_channel_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010033#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080034#include "api/jsep_session_description.h"
35#include "api/media_stream_interface.h"
36#include "api/media_types.h"
Steve Anton10542f22019-01-11 09:11:00 -080037#include "api/rtc_error.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020038#include "api/rtc_event_log/rtc_event_log.h"
39#include "api/rtc_event_log/rtc_event_log_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080040#include "api/rtc_event_log_output.h"
Niels Möllerd8b9ed72019-05-08 13:53:51 +020041#include "api/rtc_event_log_output_file.h"
Steve Anton10542f22019-01-11 09:11:00 -080042#include "api/rtp_receiver_interface.h"
43#include "api/rtp_sender_interface.h"
44#include "api/rtp_transceiver_interface.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010045#include "api/scoped_refptr.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020046#include "api/task_queue/default_task_queue_factory.h"
Anders Carlsson67537952018-05-03 11:28:29 +020047#include "api/video_codecs/builtin_video_decoder_factory.h"
48#include "api/video_codecs/builtin_video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010049#include "api/video_codecs/video_decoder_factory.h"
50#include "api/video_codecs/video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010051#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080052#include "media/base/media_config.h"
53#include "media/base/media_engine.h"
54#include "media/base/stream_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080055#include "media/engine/webrtc_media_engine.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020056#include "media/engine/webrtc_media_engine_defaults.h"
Steve Anton10542f22019-01-11 09:11:00 -080057#include "media/sctp/sctp_transport_internal.h"
Yves Gerey3e707812018-11-28 16:47:49 +010058#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020059#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080060#include "p2p/base/fake_port_allocator.h"
61#include "p2p/base/p2p_constants.h"
Yves Gerey3e707812018-11-28 16:47:49 +010062#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080063#include "p2p/base/port_allocator.h"
64#include "p2p/base/transport_description.h"
65#include "p2p/base/transport_info.h"
66#include "pc/audio_track.h"
67#include "pc/media_session.h"
68#include "pc/media_stream.h"
69#include "pc/peer_connection.h"
70#include "pc/peer_connection_factory.h"
71#include "pc/rtc_stats_collector.h"
72#include "pc/rtp_sender.h"
73#include "pc/session_description.h"
74#include "pc/stream_collection.h"
75#include "pc/test/fake_audio_capture_module.h"
76#include "pc/test/fake_rtc_certificate_generator.h"
77#include "pc/test/fake_video_track_source.h"
78#include "pc/test/mock_peer_connection_observers.h"
79#include "pc/test/test_sdp_strings.h"
80#include "pc/video_track.h"
Yves Gerey3e707812018-11-28 16:47:49 +010081#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080082#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020083#include "rtc_base/gunit.h"
Steve Anton10542f22019-01-11 09:11:00 -080084#include "rtc_base/ref_counted_object.h"
85#include "rtc_base/rtc_certificate_generator.h"
Steve Anton10542f22019-01-11 09:11:00 -080086#include "rtc_base/socket_address.h"
Yves Gerey3e707812018-11-28 16:47:49 +010087#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080088#include "rtc_base/time_utils.h"
89#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020090#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010091#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080092#include "test/testsupport/file_utils.h"
kwibergac9f8762016-09-30 22:29:43 -070093
94#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080095#include "pc/test/android_test_initializer.h"
kwibergac9f8762016-09-30 22:29:43 -070096#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010098namespace webrtc {
99namespace {
100
Seth Hampson845e8782018-03-02 11:34:10 -0800101static const char kStreamId1[] = "local_stream_1";
102static const char kStreamId2[] = "local_stream_2";
103static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104static const int kDefaultStunPort = 3478;
105static const char kStunAddressOnly[] = "stun:address";
106static const char kStunInvalidPort[] = "stun:address:-1";
107static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
108static const char kStunAddressPortAndMore2[] = "stun:address:port more";
Niels Möllerdb4def92019-03-18 16:53:59 +0100109static const char kTurnIceServerUri[] = "turn:turn.example.org";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110static const char kTurnUsername[] = "user";
111static const char kTurnPassword[] = "password";
112static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200113static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114
deadbeefab9b2d12015-10-14 11:33:11 -0700115static const char kStreams[][8] = {"stream1", "stream2"};
116static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
117static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
118
deadbeef5e97fb52015-10-15 12:49:08 -0700119static const char kRecvonly[] = "recvonly";
120static const char kSendrecv[] = "sendrecv";
121
deadbeefab9b2d12015-10-14 11:33:11 -0700122// Reference SDP with a MediaStream with label "stream1" and audio track with
123// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800124static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700125 "v=0\r\n"
126 "o=- 0 0 IN IP4 127.0.0.1\r\n"
127 "s=-\r\n"
128 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800129 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700130 "a=ice-ufrag:e5785931\r\n"
131 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
132 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
133 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700134 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700135 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800136 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700137 "a=rtpmap:103 ISAC/16000\r\n"
138 "a=ssrc:1 cname:stream1\r\n"
139 "a=ssrc:1 mslabel:stream1\r\n"
140 "a=ssrc:1 label:audiotrack0\r\n"
141 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800142 "a=ice-ufrag:e5785931\r\n"
143 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
144 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
145 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700146 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700147 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800148 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700149 "a=rtpmap:120 VP8/90000\r\n"
150 "a=ssrc:2 cname:stream1\r\n"
151 "a=ssrc:2 mslabel:stream1\r\n"
152 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800153// Same string as above but with the MID changed to the Unified Plan default.
154// This is needed so that this SDP can be used as an answer for a Unified Plan
155// offer.
156static const char kSdpStringWithStream1UnifiedPlan[] =
157 "v=0\r\n"
158 "o=- 0 0 IN IP4 127.0.0.1\r\n"
159 "s=-\r\n"
160 "t=0 0\r\n"
161 "m=audio 1 RTP/AVPF 103\r\n"
162 "a=ice-ufrag:e5785931\r\n"
163 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
164 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
165 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
166 "a=mid:0\r\n"
167 "a=sendrecv\r\n"
168 "a=rtcp-mux\r\n"
169 "a=rtpmap:103 ISAC/16000\r\n"
170 "a=ssrc:1 cname:stream1\r\n"
171 "a=ssrc:1 mslabel:stream1\r\n"
172 "a=ssrc:1 label:audiotrack0\r\n"
173 "m=video 1 RTP/AVPF 120\r\n"
174 "a=ice-ufrag:e5785931\r\n"
175 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
176 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
177 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
178 "a=mid:1\r\n"
179 "a=sendrecv\r\n"
180 "a=rtcp-mux\r\n"
181 "a=rtpmap:120 VP8/90000\r\n"
182 "a=ssrc:2 cname:stream1\r\n"
183 "a=ssrc:2 mslabel:stream1\r\n"
184 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700185
zhihuang81c3a032016-11-17 12:06:24 -0800186// Reference SDP with a MediaStream with label "stream1" and audio track with
187// id "audio_1";
188static const char kSdpStringWithStream1AudioTrackOnly[] =
189 "v=0\r\n"
190 "o=- 0 0 IN IP4 127.0.0.1\r\n"
191 "s=-\r\n"
192 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800193 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800194 "a=ice-ufrag:e5785931\r\n"
195 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
196 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
197 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800198 "a=mid:audio\r\n"
199 "a=sendrecv\r\n"
200 "a=rtpmap:103 ISAC/16000\r\n"
201 "a=ssrc:1 cname:stream1\r\n"
202 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800203 "a=ssrc:1 label:audiotrack0\r\n"
204 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800205
deadbeefab9b2d12015-10-14 11:33:11 -0700206// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
207// MediaStreams have one audio track and one video track.
208// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800209static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700210 "v=0\r\n"
211 "o=- 0 0 IN IP4 127.0.0.1\r\n"
212 "s=-\r\n"
213 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800214 "a=msid-semantic: WMS stream1 stream2\r\n"
215 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700216 "a=ice-ufrag:e5785931\r\n"
217 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
218 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
219 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700220 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700221 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800222 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700223 "a=rtpmap:103 ISAC/16000\r\n"
224 "a=ssrc:1 cname:stream1\r\n"
225 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
226 "a=ssrc:3 cname:stream2\r\n"
227 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
228 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800229 "a=ice-ufrag:e5785931\r\n"
230 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
231 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
232 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700233 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700234 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800235 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700236 "a=rtpmap:120 VP8/0\r\n"
237 "a=ssrc:2 cname:stream1\r\n"
238 "a=ssrc:2 msid:stream1 videotrack0\r\n"
239 "a=ssrc:4 cname:stream2\r\n"
240 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800241static const char kSdpStringWithStream1And2UnifiedPlan[] =
242 "v=0\r\n"
243 "o=- 0 0 IN IP4 127.0.0.1\r\n"
244 "s=-\r\n"
245 "t=0 0\r\n"
246 "a=msid-semantic: WMS stream1 stream2\r\n"
247 "m=audio 1 RTP/AVPF 103\r\n"
248 "a=ice-ufrag:e5785931\r\n"
249 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
250 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
251 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
252 "a=mid:0\r\n"
253 "a=sendrecv\r\n"
254 "a=rtcp-mux\r\n"
255 "a=rtpmap:103 ISAC/16000\r\n"
256 "a=ssrc:1 cname:stream1\r\n"
257 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
258 "m=video 1 RTP/AVPF 120\r\n"
259 "a=ice-ufrag:e5785931\r\n"
260 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
261 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
262 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
263 "a=mid:1\r\n"
264 "a=sendrecv\r\n"
265 "a=rtcp-mux\r\n"
266 "a=rtpmap:120 VP8/0\r\n"
267 "a=ssrc:2 cname:stream1\r\n"
268 "a=ssrc:2 msid:stream1 videotrack0\r\n"
269 "m=audio 1 RTP/AVPF 103\r\n"
270 "a=ice-ufrag:e5785931\r\n"
271 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
272 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
273 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
274 "a=mid:2\r\n"
275 "a=sendrecv\r\n"
276 "a=rtcp-mux\r\n"
277 "a=rtpmap:103 ISAC/16000\r\n"
278 "a=ssrc:3 cname:stream2\r\n"
279 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
280 "m=video 1 RTP/AVPF 120\r\n"
281 "a=ice-ufrag:e5785931\r\n"
282 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
283 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
284 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
285 "a=mid:3\r\n"
286 "a=sendrecv\r\n"
287 "a=rtcp-mux\r\n"
288 "a=rtpmap:120 VP8/0\r\n"
289 "a=ssrc:4 cname:stream2\r\n"
290 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700291
292// Reference SDP without MediaStreams. Msid is not supported.
293static const char kSdpStringWithoutStreams[] =
294 "v=0\r\n"
295 "o=- 0 0 IN IP4 127.0.0.1\r\n"
296 "s=-\r\n"
297 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800298 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700299 "a=ice-ufrag:e5785931\r\n"
300 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
301 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
302 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700303 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700304 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800305 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700306 "a=rtpmap:103 ISAC/16000\r\n"
307 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800308 "a=ice-ufrag:e5785931\r\n"
309 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
310 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
311 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700312 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700313 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800314 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700315 "a=rtpmap:120 VP8/90000\r\n";
316
317// Reference SDP without MediaStreams. Msid is supported.
318static const char kSdpStringWithMsidWithoutStreams[] =
319 "v=0\r\n"
320 "o=- 0 0 IN IP4 127.0.0.1\r\n"
321 "s=-\r\n"
322 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800323 "a=msid-semantic: WMS\r\n"
324 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700325 "a=ice-ufrag:e5785931\r\n"
326 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
327 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
328 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700329 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700330 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800331 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700332 "a=rtpmap:103 ISAC/16000\r\n"
333 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800334 "a=ice-ufrag:e5785931\r\n"
335 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
336 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
337 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700338 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700339 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800340 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700341 "a=rtpmap:120 VP8/90000\r\n";
342
343// Reference SDP without MediaStreams and audio only.
344static const char kSdpStringWithoutStreamsAudioOnly[] =
345 "v=0\r\n"
346 "o=- 0 0 IN IP4 127.0.0.1\r\n"
347 "s=-\r\n"
348 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800349 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700350 "a=ice-ufrag:e5785931\r\n"
351 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
352 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
353 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700354 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700355 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800356 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700357 "a=rtpmap:103 ISAC/16000\r\n";
358
359// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
360static const char kSdpStringSendOnlyWithoutStreams[] =
361 "v=0\r\n"
362 "o=- 0 0 IN IP4 127.0.0.1\r\n"
363 "s=-\r\n"
364 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800365 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700366 "a=ice-ufrag:e5785931\r\n"
367 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
368 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
369 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700370 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700371 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700372 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800373 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700374 "a=rtpmap:103 ISAC/16000\r\n"
375 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800376 "a=ice-ufrag:e5785931\r\n"
377 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
378 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
379 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700380 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700381 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700382 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800383 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700384 "a=rtpmap:120 VP8/90000\r\n";
385
386static const char kSdpStringInit[] =
387 "v=0\r\n"
388 "o=- 0 0 IN IP4 127.0.0.1\r\n"
389 "s=-\r\n"
390 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700391 "a=msid-semantic: WMS\r\n";
392
393static const char kSdpStringAudio[] =
394 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800395 "a=ice-ufrag:e5785931\r\n"
396 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
397 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
398 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700399 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700400 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800401 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700402 "a=rtpmap:103 ISAC/16000\r\n";
403
404static const char kSdpStringVideo[] =
405 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800406 "a=ice-ufrag:e5785931\r\n"
407 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
408 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
409 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700410 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700411 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800412 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700413 "a=rtpmap:120 VP8/90000\r\n";
414
415static const char kSdpStringMs1Audio0[] =
416 "a=ssrc:1 cname:stream1\r\n"
417 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
418
419static const char kSdpStringMs1Video0[] =
420 "a=ssrc:2 cname:stream1\r\n"
421 "a=ssrc:2 msid:stream1 videotrack0\r\n";
422
423static const char kSdpStringMs1Audio1[] =
424 "a=ssrc:3 cname:stream1\r\n"
425 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
426
427static const char kSdpStringMs1Video1[] =
428 "a=ssrc:4 cname:stream1\r\n"
429 "a=ssrc:4 msid:stream1 videotrack1\r\n";
430
deadbeef8662f942017-01-20 21:20:51 -0800431static const char kDtlsSdesFallbackSdp[] =
432 "v=0\r\n"
433 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
434 "s=-\r\n"
435 "c=IN IP4 0.0.0.0\r\n"
436 "t=0 0\r\n"
437 "a=group:BUNDLE audio\r\n"
438 "a=msid-semantic: WMS\r\n"
439 "m=audio 1 RTP/SAVPF 0\r\n"
440 "a=sendrecv\r\n"
441 "a=rtcp-mux\r\n"
442 "a=mid:audio\r\n"
443 "a=ssrc:1 cname:stream1\r\n"
444 "a=ssrc:1 mslabel:stream1\r\n"
445 "a=ssrc:1 label:audiotrack0\r\n"
446 "a=ice-ufrag:e5785931\r\n"
447 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
448 "a=rtpmap:0 pcmu/8000\r\n"
449 "a=fingerprint:sha-1 "
450 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
451 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700452 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800453 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
454 "dummy_session_params\r\n";
455
Niels Möllerdec9f742019-06-03 15:25:20 +0200456class RtcEventLogOutputNull final : public RtcEventLogOutput {
457 public:
458 bool IsActive() const override { return true; }
459 bool Write(const std::string& output) override { return true; }
460};
461
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100462using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700463using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800464using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465
Steve Anton36da6ff2018-02-16 16:04:20 -0800466using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
467using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700468
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469// Gets the first ssrc of given content type from the ContentInfo.
470bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
471 if (!content_info || !ssrc) {
472 return false;
473 }
474 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800475 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 if (!media_desc || media_desc->streams().empty()) {
477 return false;
478 }
479 *ssrc = media_desc->streams().begin()->first_ssrc();
480 return true;
481}
482
deadbeefd1a38b52016-12-10 13:15:33 -0800483// Get the ufrags out of an SDP blob. Useful for testing ICE restart
484// behavior.
485std::vector<std::string> GetUfrags(
486 const webrtc::SessionDescriptionInterface* desc) {
487 std::vector<std::string> ufrags;
488 for (const cricket::TransportInfo& info :
489 desc->description()->transport_infos()) {
490 ufrags.push_back(info.description.ice_ufrag);
491 }
492 return ufrags;
493}
494
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495void SetSsrcToZero(std::string* sdp) {
496 const char kSdpSsrcAtribute[] = "a=ssrc:";
497 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
498 size_t ssrc_pos = 0;
499 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200500 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 size_t end_ssrc = sdp->find(" ", ssrc_pos);
502 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
503 ssrc_pos = end_ssrc;
504 }
505}
506
deadbeefab9b2d12015-10-14 11:33:11 -0700507// Check if |streams| contains the specified track.
508bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800509 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700510 const std::string& track_id) {
511 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800512 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700513 return true;
514 }
515 }
516 return false;
517}
518
519// Check if |senders| contains the specified sender, by id.
520bool ContainsSender(
521 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
522 const std::string& id) {
523 for (const auto& sender : senders) {
524 if (sender->id() == id) {
525 return true;
526 }
527 }
528 return false;
529}
530
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700531// Check if |senders| contains the specified sender, by id and stream id.
532bool ContainsSender(
533 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
534 const std::string& id,
535 const std::string& stream_id) {
536 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700537 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700538 return true;
539 }
540 }
541 return false;
542}
543
deadbeefab9b2d12015-10-14 11:33:11 -0700544// Create a collection of streams.
545// CreateStreamCollection(1) creates a collection that
546// correspond to kSdpStringWithStream1.
547// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
548rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700549 int number_of_streams,
550 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700551 rtc::scoped_refptr<StreamCollection> local_collection(
552 StreamCollection::Create());
553
554 for (int i = 0; i < number_of_streams; ++i) {
555 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
556 webrtc::MediaStream::Create(kStreams[i]));
557
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700558 for (int j = 0; j < tracks_per_stream; ++j) {
559 // Add a local audio track.
560 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
561 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
562 nullptr));
563 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700564
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700565 // Add a local video track.
566 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
567 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700568 webrtc::FakeVideoTrackSource::Create(),
569 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700570 stream->AddTrack(video_track);
571 }
deadbeefab9b2d12015-10-14 11:33:11 -0700572
573 local_collection->AddStream(stream);
574 }
575 return local_collection;
576}
577
578// Check equality of StreamCollections.
579bool CompareStreamCollections(StreamCollectionInterface* s1,
580 StreamCollectionInterface* s2) {
581 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
582 return false;
583 }
584
585 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700586 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700587 return false;
588 }
589 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
590 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
591 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
592 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
593
594 if (audio_tracks1.size() != audio_tracks2.size()) {
595 return false;
596 }
597 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
598 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
599 return false;
600 }
601 }
602 if (video_tracks1.size() != video_tracks2.size()) {
603 return false;
604 }
605 for (size_t j = 0; j != video_tracks1.size(); ++j) {
606 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
607 return false;
608 }
609 }
610 }
611 return true;
612}
613
perkjd61bf802016-03-24 03:16:19 -0700614// Helper class to test Observer.
615class MockTrackObserver : public ObserverInterface {
616 public:
617 explicit MockTrackObserver(NotifierInterface* notifier)
618 : notifier_(notifier) {
619 notifier_->RegisterObserver(this);
620 }
621
622 ~MockTrackObserver() { Unregister(); }
623
624 void Unregister() {
625 if (notifier_) {
626 notifier_->UnregisterObserver(this);
627 notifier_ = nullptr;
628 }
629 }
630
631 MOCK_METHOD0(OnChanged, void());
632
633 private:
634 NotifierInterface* notifier_;
635};
636
nisse528b7932017-05-08 03:21:43 -0700637// The PeerConnectionMediaConfig tests below verify that configuration and
638// constraints are propagated into the PeerConnection's MediaConfig. These
639// settings are intended for MediaChannel constructors, but that is not
640// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700641class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
642 public:
zhihuang38ede132017-06-15 12:52:32 -0700643 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
644 CreatePeerConnectionFactoryForTest() {
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100645 PeerConnectionFactoryDependencies dependencies;
646 dependencies.worker_thread = rtc::Thread::Current();
647 dependencies.network_thread = rtc::Thread::Current();
648 dependencies.signaling_thread = rtc::Thread::Current();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200649 dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
650 cricket::MediaEngineDependencies media_deps;
651 media_deps.task_queue_factory = dependencies.task_queue_factory.get();
henrika919dc2e2017-10-12 14:24:55 +0200652 // Use fake audio device module since we're only testing the interface
653 // level, and using a real one could make tests flaky when run in parallel.
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200654 media_deps.adm = FakeAudioCaptureModule::Create();
655 SetMediaEngineDefaults(&media_deps);
656 dependencies.media_engine =
657 cricket::CreateMediaEngine(std::move(media_deps));
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100658 dependencies.call_factory = webrtc::CreateCallFactory();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200659 dependencies.event_log_factory = absl::make_unique<RtcEventLogFactory>(
660 dependencies.task_queue_factory.get());
zhihuang38ede132017-06-15 12:52:32 -0700661
662 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100663 std::move(dependencies));
zhihuang38ede132017-06-15 12:52:32 -0700664 }
665
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100666 using PeerConnectionFactory::PeerConnectionFactory;
kwiberg1e4e8cb2017-01-31 01:48:08 -0800667
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100668 private:
deadbeefd7850b22017-08-23 10:59:19 -0700669 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700670};
671
Steve Anton36da6ff2018-02-16 16:04:20 -0800672// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200673class PeerConnectionInterfaceBaseTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800675 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
676 : vss_(new rtc::VirtualSocketServer()),
677 main_(vss_.get()),
678 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800679#ifdef WEBRTC_ANDROID
680 webrtc::InitializeAndroidObjects();
681#endif
682 }
683
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000684 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700685 // Use fake audio capture module since we're only testing the interface
686 // level, and using a real one could make tests flaky when run in parallel.
687 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700689 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200690 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
691 fake_audio_capture_module_),
692 webrtc::CreateBuiltinAudioEncoderFactory(),
693 webrtc::CreateBuiltinAudioDecoderFactory(),
694 webrtc::CreateBuiltinVideoEncoderFactory(),
695 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
696 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700697 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700698 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700699 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700700 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 }
702
703 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200704 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 }
706
deadbeef293e9262017-01-11 12:28:30 -0800707 // DTLS does not work in a loopback call, so is disabled for most of the
708 // tests in this file.
709 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200710 RTCConfiguration config;
711 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800712
Niels Möllerf06f9232018-08-07 12:32:18 +0200713 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 }
715
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700716 void CreatePeerConnectionWithIceTransportsType(
717 PeerConnectionInterface::IceTransportsType type) {
718 PeerConnectionInterface::RTCConfiguration config;
719 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200720 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700721 }
722
723 void CreatePeerConnectionWithIceServer(const std::string& uri,
Niels Möllerdb4def92019-03-18 16:53:59 +0100724 const std::string& username,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700725 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800726 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700728 server.uri = uri;
Niels Möllerdb4def92019-03-18 16:53:59 +0100729 server.username = username;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700730 server.password = password;
731 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200732 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700733 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734
Niels Möllerf06f9232018-08-07 12:32:18 +0200735 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700736 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800737 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
738 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000739
deadbeef1dcb1642017-03-29 21:08:16 -0700740 // Create certificate generator unless DTLS constraint is explicitly set to
741 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200742 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200743
744 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800745 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
746 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000747 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800748 RTCConfiguration modified_config = config;
749 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200750 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200751 modified_config, std::move(port_allocator), std::move(cert_generator),
752 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 ASSERT_TRUE(pc_.get() != NULL);
754 observer_.SetPeerConnectionInterface(pc_.get());
755 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
756 }
757
deadbeef0a6c4ca2015-10-06 11:38:28 -0700758 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800759 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700760 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700761 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800762 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800763 config.sdp_semantics = sdp_semantics_;
764 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200765 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800766 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700767 }
768
Steve Anton038834f2017-07-14 15:59:59 -0700769 void CreatePeerConnectionExpectFail(
770 PeerConnectionInterface::RTCConfiguration config) {
771 PeerConnectionInterface::IceServer server;
772 server.uri = kTurnIceServerUri;
773 server.password = kTurnPassword;
774 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800775 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700776 rtc::scoped_refptr<PeerConnectionInterface> pc =
777 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
778 EXPECT_EQ(nullptr, pc);
779 }
780
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 16:53:59 +0100782 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800783 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
784 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
785 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800787 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788
deadbeef0a6c4ca2015-10-06 11:38:28 -0700789 CreatePeerConnectionExpectFail(kStunInvalidPort);
790 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
791 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792
Niels Möllerdb4def92019-03-18 16:53:59 +0100793 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
794 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800795 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
796 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800798 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800800 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800802 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 }
804
805 void ReleasePeerConnection() {
806 pc_ = NULL;
807 observer_.SetPeerConnectionInterface(NULL);
808 }
809
Steve Anton36da6ff2018-02-16 16:04:20 -0800810 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
811 const std::string& label) {
Niels Möller215ba602019-01-18 13:59:45 +0100812 return pc_factory_->CreateVideoTrack(label, FakeVideoTrackSource::Create());
Steve Anton36da6ff2018-02-16 16:04:20 -0800813 }
814
815 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800816 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800817 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800818 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800819 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 }
821
Steve Anton36da6ff2018-02-16 16:04:20 -0800822 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700823 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800825 stream->AddTrack(CreateVideoTrack(label + "v0"));
826 ASSERT_TRUE(pc_->AddStream(stream));
Steve Anton36da6ff2018-02-16 16:04:20 -0800827 }
828
829 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
830 const std::string& label) {
831 return pc_factory_->CreateAudioTrack(label, nullptr);
832 }
833
834 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800835 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800836 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800837 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800838 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-16 16:04:20 -0800839 }
840
841 void AddAudioStream(const std::string& label) {
842 rtc::scoped_refptr<MediaStreamInterface> stream(
843 pc_factory_->CreateLocalMediaStream(label));
844 stream->AddTrack(CreateAudioTrack(label + "a0"));
845 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 }
847
Seth Hampson845e8782018-03-02 11:34:10 -0800848 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 const std::string& audio_track_label,
850 const std::string& video_track_label) {
851 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700852 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800853 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800854 stream->AddTrack(CreateAudioTrack(audio_track_label));
855 stream->AddTrack(CreateVideoTrack(video_track_label));
856 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 }
858
Steve Anton36da6ff2018-02-16 16:04:20 -0800859 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
860 cricket::MediaType media_type) {
861 for (auto receiver : pc_->GetReceivers()) {
862 if (receiver->media_type() == media_type) {
863 return receiver;
864 }
865 }
866 return nullptr;
867 }
868
kwibergd1fe2812016-04-27 06:47:29 -0700869 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200870 const RTCOfferAnswerOptions* options,
871 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200872 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
873 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200875 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200877 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 }
879 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700880 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 return observer->result();
882 }
883
kwibergd1fe2812016-04-27 06:47:29 -0700884 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200885 const RTCOfferAnswerOptions* options) {
886 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 }
888
kwibergd1fe2812016-04-27 06:47:29 -0700889 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200890 const RTCOfferAnswerOptions* options) {
891 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 }
893
Steve Antondb45ca82017-09-11 18:27:34 -0700894 bool DoSetSessionDescription(
895 std::unique_ptr<SessionDescriptionInterface> desc,
896 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200897 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
898 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700900 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700902 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 }
zhihuang29ff8442016-07-27 11:07:25 -0700904 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
905 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
906 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 return observer->result();
908 }
909
Steve Antondb45ca82017-09-11 18:27:34 -0700910 bool DoSetLocalDescription(
911 std::unique_ptr<SessionDescriptionInterface> desc) {
912 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 }
914
Steve Antondb45ca82017-09-11 18:27:34 -0700915 bool DoSetRemoteDescription(
916 std::unique_ptr<SessionDescriptionInterface> desc) {
917 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 }
919
920 // Calls PeerConnection::GetStats and check the return value.
921 // It does not verify the values in the StatReports since a RTCP packet might
922 // be required.
923 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000924 rtc::scoped_refptr<MockStatsObserver> observer(
925 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200926 if (!pc_->GetStats(observer, track,
927 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 return false;
929 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
930 return observer->called();
931 }
932
Harald Alvestrand89061872018-01-02 14:08:34 +0100933 // Call the standards-compliant GetStats function.
934 bool DoGetRTCStats() {
935 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
936 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
937 pc_->GetStats(callback);
938 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
939 return callback->called();
940 }
941
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800943 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800945 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800946 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800947 } else {
948 // Unified Plan does not support AddStream, so just add an audio and video
949 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800950 AddAudioTrack(kAudioTracks[0], {kStreamId1});
951 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800952 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 CreateOfferReceiveAnswer();
954 }
955
956 // Verify that RTP Header extensions has been negotiated for audio and video.
957 void VerifyRemoteRtpHeaderExtensions() {
958 const cricket::MediaContentDescription* desc =
959 cricket::GetFirstAudioContentDescription(
960 pc_->remote_description()->description());
961 ASSERT_TRUE(desc != NULL);
962 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
963
964 desc = cricket::GetFirstVideoContentDescription(
965 pc_->remote_description()->description());
966 ASSERT_TRUE(desc != NULL);
967 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
968 }
969
970 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700971 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700972 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 std::string sdp;
974 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700975 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800976 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700977 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
979 }
980
deadbeefab9b2d12015-10-14 11:33:11 -0700981 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700982 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800983 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700984 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700985 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
986 }
987
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700989 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700990 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
992 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
993 // audio codec change, even if the parameter has nothing to do with
994 // receiving. Not all parameters are serialized to SDP.
995 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
996 // the SessionDescription, it is necessary to do that here to in order to
997 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
998 // https://code.google.com/p/webrtc/issues/detail?id=1356
999 std::string sdp;
1000 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001001 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001002 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001003 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1005 }
1006
1007 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001008 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001009 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010
1011 std::string sdp;
1012 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001013 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001014 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001015 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1017 }
1018
1019 void CreateOfferReceiveAnswer() {
1020 CreateOfferAsLocalDescription();
1021 std::string sdp;
1022 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1023 CreateAnswerAsRemoteDescription(sdp);
1024 }
1025
1026 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001027 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001028 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1030 // audio codec change, even if the parameter has nothing to do with
1031 // receiving. Not all parameters are serialized to SDP.
1032 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1033 // the SessionDescription, it is necessary to do that here to in order to
1034 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1035 // https://code.google.com/p/webrtc/issues/detail?id=1356
1036 std::string sdp;
1037 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001038 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001039 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040
Steve Antondb45ca82017-09-11 18:27:34 -07001041 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001043 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001044 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 }
1046
deadbeefab9b2d12015-10-14 11:33:11 -07001047 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001048 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001049 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001050 ASSERT_TRUE(answer);
1051 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1053 }
1054
deadbeefab9b2d12015-10-14 11:33:11 -07001055 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001056 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001057 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001058 ASSERT_TRUE(pr_answer);
1059 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001061 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001062 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001063 ASSERT_TRUE(answer);
1064 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1066 }
1067
Seth Hampson845e8782018-03-02 11:34:10 -08001068 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001069 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001070 // called with the given stream id and expected number of tracks.
1071 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001072 int expected_num_tracks) {
1073 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001074 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001075 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001076 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077 }
1078
1079 // Creates an offer and applies it as a local session description.
1080 // Creates an answer with the same SDP an the offer but removes all lines
1081 // that start with a:ssrc"
1082 void CreateOfferReceiveAnswerWithoutSsrc() {
1083 CreateOfferAsLocalDescription();
1084 std::string sdp;
1085 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1086 SetSsrcToZero(&sdp);
1087 CreateAnswerAsRemoteDescription(sdp);
1088 }
1089
deadbeefab9b2d12015-10-14 11:33:11 -07001090 // This function creates a MediaStream with label kStreams[0] and
1091 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1092 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001093 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001094 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001095 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001096 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1097 size_t number_of_video_tracks) {
1098 EXPECT_LE(number_of_audio_tracks, 2u);
1099 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001100
1101 reference_collection_ = StreamCollection::Create();
1102 std::string sdp_ms1 = std::string(kSdpStringInit);
1103
Seth Hampson845e8782018-03-02 11:34:10 -08001104 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001105
1106 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001107 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001108 reference_collection_->AddStream(stream);
1109
1110 if (number_of_audio_tracks > 0) {
1111 sdp_ms1 += std::string(kSdpStringAudio);
1112 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1113 AddAudioTrack(kAudioTracks[0], stream);
1114 }
1115 if (number_of_audio_tracks > 1) {
1116 sdp_ms1 += kSdpStringMs1Audio1;
1117 AddAudioTrack(kAudioTracks[1], stream);
1118 }
1119
1120 if (number_of_video_tracks > 0) {
1121 sdp_ms1 += std::string(kSdpStringVideo);
1122 sdp_ms1 += std::string(kSdpStringMs1Video0);
1123 AddVideoTrack(kVideoTracks[0], stream);
1124 }
1125 if (number_of_video_tracks > 1) {
1126 sdp_ms1 += kSdpStringMs1Video1;
1127 AddVideoTrack(kVideoTracks[1], stream);
1128 }
1129
kwibergd1fe2812016-04-27 06:47:29 -07001130 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001131 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001132 }
1133
1134 void AddAudioTrack(const std::string& track_id,
1135 MediaStreamInterface* stream) {
1136 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1137 webrtc::AudioTrack::Create(track_id, nullptr));
1138 ASSERT_TRUE(stream->AddTrack(audio_track));
1139 }
1140
1141 void AddVideoTrack(const std::string& track_id,
1142 MediaStreamInterface* stream) {
1143 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001144 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001145 webrtc::FakeVideoTrackSource::Create(),
1146 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001147 ASSERT_TRUE(stream->AddTrack(video_track));
1148 }
1149
Steve Anton36da6ff2018-02-16 16:04:20 -08001150 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001151 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001152 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001153 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001154 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1155 return offer;
1156 }
1157
Steve Anton36da6ff2018-02-16 16:04:20 -08001158 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1159 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001160 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001161 std::unique_ptr<SessionDescriptionInterface> offer;
1162 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1163 return offer;
1164 }
1165
1166 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1167 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1168 std::unique_ptr<SessionDescriptionInterface> answer;
1169 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1170 return answer;
1171 }
1172
kwibergfd8be342016-05-14 19:44:11 -07001173 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001174 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001175 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001176 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001177 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1178 return answer;
1179 }
1180
1181 const std::string& GetFirstAudioStreamCname(
1182 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001183 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001184 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001185 return audio_desc->streams()[0].cname;
1186 }
1187
zhihuang1c378ed2017-08-17 14:10:50 -07001188 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1189 const RTCOfferAnswerOptions& offer_answer_options) {
1190 RTC_DCHECK(pc_);
1191 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1192 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1193 pc_->CreateOffer(observer, offer_answer_options);
1194 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1195 return observer->MoveDescription();
1196 }
1197
1198 void CreateOfferWithOptionsAsRemoteDescription(
1199 std::unique_ptr<SessionDescriptionInterface>* desc,
1200 const RTCOfferAnswerOptions& offer_answer_options) {
1201 *desc = CreateOfferWithOptions(offer_answer_options);
1202 ASSERT_TRUE(desc != nullptr);
1203 std::string sdp;
1204 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001205 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001206 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001207 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001208 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1209 }
1210
1211 void CreateOfferWithOptionsAsLocalDescription(
1212 std::unique_ptr<SessionDescriptionInterface>* desc,
1213 const RTCOfferAnswerOptions& offer_answer_options) {
1214 *desc = CreateOfferWithOptions(offer_answer_options);
1215 ASSERT_TRUE(desc != nullptr);
1216 std::string sdp;
1217 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001218 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001219 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001220
Steve Antondb45ca82017-09-11 18:27:34 -07001221 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001222 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1223 }
1224
1225 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001226 RTC_DCHECK(content);
1227 RTC_DCHECK(content->media_description());
1228 for (const cricket::AudioCodec& codec :
1229 content->media_description()->as_audio()->codecs()) {
1230 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001231 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001232 }
zhihuang1c378ed2017-08-17 14:10:50 -07001233 }
1234 return false;
1235 }
1236
Steve Anton36da6ff2018-02-16 16:04:20 -08001237 const char* GetSdpStringWithStream1() const {
1238 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1239 return kSdpStringWithStream1PlanB;
1240 } else {
1241 return kSdpStringWithStream1UnifiedPlan;
1242 }
1243 }
1244
1245 const char* GetSdpStringWithStream1And2() const {
1246 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1247 return kSdpStringWithStream1And2PlanB;
1248 } else {
1249 return kSdpStringWithStream1And2UnifiedPlan;
1250 }
1251 }
1252
deadbeef9a6f4d42017-05-15 19:43:33 -07001253 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1254 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001255 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001256 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001257 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001258 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1259 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1260 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001262 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001263 const SdpSemantics sdp_semantics_;
1264};
1265
1266class PeerConnectionInterfaceTest
1267 : public PeerConnectionInterfaceBaseTest,
1268 public ::testing::WithParamInterface<SdpSemantics> {
1269 protected:
1270 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1271};
1272
1273class PeerConnectionInterfaceTestPlanB
1274 : public PeerConnectionInterfaceBaseTest {
1275 protected:
1276 PeerConnectionInterfaceTestPlanB()
1277 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278};
1279
zhihuang8f65cdf2016-05-06 18:40:30 -07001280// Generate different CNAMEs when PeerConnections are created.
1281// The CNAMEs are expected to be generated randomly. It is possible
1282// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001283TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001284 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001285 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001286 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001287 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001288 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1289 GetFirstAudioStreamCname(offer2.get()));
1290}
1291
Steve Anton36da6ff2018-02-16 16:04:20 -08001292TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001293 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001294 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001295 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001296 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001297 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1298 GetFirstAudioStreamCname(answer2.get()));
1299}
1300
Steve Anton36da6ff2018-02-16 16:04:20 -08001301TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 CreatePeerConnectionWithDifferentConfigurations) {
1303 CreatePeerConnectionWithDifferentConfigurations();
1304}
1305
Steve Anton36da6ff2018-02-16 16:04:20 -08001306TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001307 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1308 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1309 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1310 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1311 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1312 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1313 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1314 port_allocator_->candidate_filter());
1315 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1316 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1317}
1318
1319// Test that when a PeerConnection is created with a nonzero candidate pool
1320// size, the pooled PortAllocatorSession is created with all the attributes
1321// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001322TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001323 PeerConnectionInterface::RTCConfiguration config;
1324 PeerConnectionInterface::IceServer server;
1325 server.uri = kStunAddressOnly;
1326 config.servers.push_back(server);
1327 config.type = PeerConnectionInterface::kRelay;
1328 config.disable_ipv6 = true;
1329 config.tcp_candidate_policy =
1330 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001331 config.candidate_network_policy =
1332 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001333 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001334 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001335
1336 const cricket::FakePortAllocatorSession* session =
1337 static_cast<const cricket::FakePortAllocatorSession*>(
1338 port_allocator_->GetPooledSession());
1339 ASSERT_NE(nullptr, session);
1340 EXPECT_EQ(1UL, session->stun_servers().size());
1341 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1342 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001343 EXPECT_LT(0U,
1344 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001345}
1346
deadbeefd21eab32017-07-26 16:50:11 -07001347// Test that network-related RTCConfiguration members are applied to the
1348// PortAllocator when CreatePeerConnection is called. Specifically:
1349// - disable_ipv6_on_wifi
1350// - max_ipv6_networks
1351// - tcp_candidate_policy
1352// - candidate_network_policy
1353// - prune_turn_ports
1354//
1355// Note that the candidate filter (RTCConfiguration::type) is already tested
1356// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001357TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001358 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1359 // Create fake port allocator.
1360 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1361 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1362 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1363
1364 // Create RTCConfiguration with some network-related fields relevant to
1365 // PortAllocator populated.
1366 PeerConnectionInterface::RTCConfiguration config;
1367 config.disable_ipv6_on_wifi = true;
1368 config.max_ipv6_networks = 10;
1369 config.tcp_candidate_policy =
1370 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1371 config.candidate_network_policy =
1372 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1373 config.prune_turn_ports = true;
1374
1375 // Create the PC factory and PC with the above config.
1376 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1377 webrtc::CreatePeerConnectionFactory(
1378 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001379 rtc::Thread::Current(), fake_audio_capture_module_,
1380 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001381 webrtc::CreateBuiltinAudioDecoderFactory(),
1382 webrtc::CreateBuiltinVideoEncoderFactory(),
1383 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1384 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001385 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001386 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1387 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001388 EXPECT_TRUE(pc.get());
1389 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001390
1391 // Now validate that the config fields set above were applied to the
1392 // PortAllocator, as flags or otherwise.
1393 EXPECT_FALSE(raw_port_allocator->flags() &
1394 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1395 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1396 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1397 EXPECT_TRUE(raw_port_allocator->flags() &
1398 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1399 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1400}
1401
deadbeef46c73892016-11-16 19:42:04 -08001402// Check that GetConfiguration returns the configuration the PeerConnection was
1403// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001404TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001405 PeerConnectionInterface::RTCConfiguration config;
1406 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001407 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001408
1409 PeerConnectionInterface::RTCConfiguration returned_config =
1410 pc_->GetConfiguration();
1411 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1412}
1413
1414// Check that GetConfiguration returns the last configuration passed into
1415// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001416TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001417 PeerConnectionInterface::RTCConfiguration starting_config;
1418 starting_config.bundle_policy =
1419 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1420 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001421
Steve Anton36da6ff2018-02-16 16:04:20 -08001422 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001423 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001424 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001425 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001426 EXPECT_TRUE(pc_->SetConfiguration(config));
1427
1428 PeerConnectionInterface::RTCConfiguration returned_config =
1429 pc_->GetConfiguration();
1430 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001431 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001432 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001433}
1434
Steve Antonc79268f2018-04-24 09:54:10 -07001435TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1436 CreatePeerConnection();
1437
1438 pc_->Close();
1439
1440 EXPECT_FALSE(
1441 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1442}
1443
Steve Anton36da6ff2018-02-16 16:04:20 -08001444TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001445 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001446 AddVideoStream(kStreamId1);
1447 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 ASSERT_EQ(2u, pc_->local_streams()->count());
1449
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001450 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001451 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001452 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001453 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001454 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001455 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001457 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001458 EXPECT_EQ(3u, pc_->local_streams()->count());
1459
1460 // Remove the third stream.
1461 pc_->RemoveStream(pc_->local_streams()->at(2));
1462 EXPECT_EQ(2u, pc_->local_streams()->count());
1463
1464 // Remove the second stream.
1465 pc_->RemoveStream(pc_->local_streams()->at(1));
1466 EXPECT_EQ(1u, pc_->local_streams()->count());
1467
1468 // Remove the first stream.
1469 pc_->RemoveStream(pc_->local_streams()->at(0));
1470 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471}
1472
deadbeefab9b2d12015-10-14 11:33:11 -07001473// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001474// Don't run under Unified Plan since the stream API is not available.
1475TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001476 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001477 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001478 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001479 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001480
deadbeefab9b2d12015-10-14 11:33:11 -07001481 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001482 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001483 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001484
deadbeefab9b2d12015-10-14 11:33:11 -07001485 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001486 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001487 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001488
1489 // Add another stream and ensure the offer includes both the old and new
1490 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001491 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001492 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001493
Steve Antonb1c1de12017-12-21 15:14:30 -08001494 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001495 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1496 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001497
Steve Antonb1c1de12017-12-21 15:14:30 -08001498 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001499 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1500 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001501}
1502
Steve Anton36da6ff2018-02-16 16:04:20 -08001503// Don't run under Unified Plan since the stream API is not available.
1504TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001505 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001506 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 ASSERT_EQ(1u, pc_->local_streams()->count());
1508 pc_->RemoveStream(pc_->local_streams()->at(0));
1509 EXPECT_EQ(0u, pc_->local_streams()->count());
1510}
1511
deadbeefe1f9d832016-01-14 15:35:42 -08001512// Test for AddTrack and RemoveTrack methods.
1513// Tests that the created offer includes tracks we added,
1514// and that the RtpSenders are created correctly.
1515// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001516// Only tested with Plan B since Unified Plan is covered in more detail by tests
1517// in peerconnection_jsep_unittests.cc
1518TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001519 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001520 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001521 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001522 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001523 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001524 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1525 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001526 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001527 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001528 EXPECT_EQ("audio_track", audio_sender->id());
1529 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001530 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001531 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001532 EXPECT_EQ("video_track", video_sender->id());
1533 EXPECT_EQ(video_track, video_sender->track());
1534
1535 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001536 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001537 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001538
1539 const cricket::ContentInfo* audio_content =
1540 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001541 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001542 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001543
1544 const cricket::ContentInfo* video_content =
1545 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001546 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001547 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001548
Steve Antondb45ca82017-09-11 18:27:34 -07001549 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001550
1551 // Now try removing the tracks.
1552 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1553 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1554
1555 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001556 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001557
1558 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001559 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001560 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001561
1562 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001563 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001564 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001565
Steve Antondb45ca82017-09-11 18:27:34 -07001566 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001567
1568 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1569 // should return false.
1570 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1571 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1572}
1573
1574// Test creating senders without a stream specified,
1575// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001576TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001577 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001578 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001579 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001580 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001581 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001582 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001583 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001584 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001585 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001586 EXPECT_EQ("audio_track", audio_sender->id());
1587 EXPECT_EQ(audio_track, audio_sender->track());
1588 EXPECT_EQ("video_track", video_sender->id());
1589 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001590 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1591 // If the ID is truly a random GUID, it should be infinitely unlikely they
1592 // will be the same.
1593 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1594 } else {
1595 // We allows creating tracks without stream ids under Unified Plan
1596 // semantics.
1597 EXPECT_EQ(0u, video_sender->stream_ids().size());
1598 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1599 }
deadbeefe1f9d832016-01-14 15:35:42 -08001600}
1601
Harald Alvestrand89061872018-01-02 14:08:34 +01001602// Test that we can call GetStats() after AddTrack but before connecting
1603// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001604TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001605 CreatePeerConnectionWithoutDtls();
1606 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001607 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001608 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001609 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001610 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1611 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001612 EXPECT_TRUE(DoGetStats(nullptr));
1613}
1614
Steve Anton36da6ff2018-02-16 16:04:20 -08001615TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001616 CreatePeerConnectionWithoutDtls();
1617 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001618 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001619 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001620 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001621 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001622 ASSERT_TRUE(audio_sender.ok());
1623 auto* audio_sender_proxy =
1624 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1625 audio_sender.value().get());
1626 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1627
Harald Alvestrandc72af932018-01-11 17:18:19 +01001628 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001629 ASSERT_TRUE(video_sender.ok());
1630 auto* video_sender_proxy =
1631 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1632 video_sender.value().get());
1633 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001634}
1635
Steve Anton36da6ff2018-02-16 16:04:20 -08001636// Don't run under Unified Plan since the stream API is not available.
1637TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001638 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001639 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001640 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001641 ASSERT_EQ(1u, senders.size());
1642 auto* sender_proxy =
1643 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1644 senders[0].get());
1645 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001646}
1647
Steve Anton36da6ff2018-02-16 16:04:20 -08001648TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001650 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 VerifyRemoteRtpHeaderExtensions();
1652}
1653
Steve Anton36da6ff2018-02-16 16:04:20 -08001654TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001655 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001656 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 CreateOfferAsLocalDescription();
1658 std::string offer;
1659 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1660 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001661 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662}
1663
Steve Anton36da6ff2018-02-16 16:04:20 -08001664TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001665 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001666 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667
1668 CreateOfferAsRemoteDescription();
1669 CreateAnswerAsLocalDescription();
1670
Seth Hampson845e8782018-03-02 11:34:10 -08001671 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672}
1673
Steve Anton36da6ff2018-02-16 16:04:20 -08001674TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001675 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001676 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677
1678 CreateOfferAsRemoteDescription();
1679 CreatePrAnswerAsLocalDescription();
1680 CreateAnswerAsLocalDescription();
1681
Seth Hampson845e8782018-03-02 11:34:10 -08001682 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683}
1684
Steve Anton36da6ff2018-02-16 16:04:20 -08001685// Don't run under Unified Plan since the stream API is not available.
1686TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 InitiateCall();
1688 ASSERT_EQ(1u, pc_->remote_streams()->count());
1689 pc_->RemoveStream(pc_->local_streams()->at(0));
1690 CreateOfferReceiveAnswer();
1691 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001692 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 CreateOfferReceiveAnswer();
1694}
1695
1696// Tests that after negotiating an audio only call, the respondent can perform a
1697// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001698TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001699 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001700 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 CreateOfferAsRemoteDescription();
1702 CreateAnswerAsLocalDescription();
1703
1704 ASSERT_EQ(1u, pc_->remote_streams()->count());
1705 pc_->RemoveStream(pc_->local_streams()->at(0));
1706 CreateOfferReceiveAnswer();
1707 EXPECT_EQ(0u, pc_->remote_streams()->count());
1708}
1709
1710// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001711TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001712 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713
Steve Antonf1c6db12017-10-13 11:13:35 -07001714 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001716 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001717 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001718 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001719 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720
1721 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001722 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001723 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001724 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725
Steve Antonf1c6db12017-10-13 11:13:35 -07001726 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001727 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728
Steve Antonf1c6db12017-10-13 11:13:35 -07001729 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730}
1731
deadbeefab9b2d12015-10-14 11:33:11 -07001732// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001734TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001735 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001737 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001738 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001739 EXPECT_TRUE(offer);
1740 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741
1742 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001743 AddAudioTrack("track_label", {kStreamId1});
1744 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745
1746 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001747 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748
1749 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001750 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001751 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752}
1753
1754// Test that we will get different SSRCs for each tracks in the offer and answer
1755// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001756TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001757 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001759 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1760 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761
1762 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001763 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001764 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 int audio_ssrc = 0;
1766 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001767 EXPECT_TRUE(
1768 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1769 EXPECT_TRUE(
1770 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771 EXPECT_NE(audio_ssrc, video_ssrc);
1772
1773 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001774 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001775 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001776 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 audio_ssrc = 0;
1778 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001779 EXPECT_TRUE(
1780 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1781 EXPECT_TRUE(
1782 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 EXPECT_NE(audio_ssrc, video_ssrc);
1784}
1785
deadbeefeb459812015-12-15 19:24:43 -08001786// Test that it's possible to call AddTrack on a MediaStream after adding
1787// the stream to a PeerConnection.
1788// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001789// Don't run under Unified Plan since the stream API is not available.
1790TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001791 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001792 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001793 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001794 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1795
1796 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001797 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001798 CreateVideoTrack("video_label"));
deadbeefeb459812015-12-15 19:24:43 -08001799 stream->AddTrack(video_track.get());
1800
kwibergd1fe2812016-04-27 06:47:29 -07001801 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001802 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001803
1804 const cricket::MediaContentDescription* video_desc =
1805 cricket::GetFirstVideoContentDescription(offer->description());
1806 EXPECT_TRUE(video_desc != nullptr);
1807}
1808
1809// Test that it's possible to call RemoveTrack on a MediaStream after adding
1810// the stream to a PeerConnection.
1811// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001812// Don't run under Unified Plan since the stream API is not available.
1813TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001814 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001815 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001816 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001817 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1818
1819 // Remove the video track.
1820 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1821
kwibergd1fe2812016-04-27 06:47:29 -07001822 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001823 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001824
1825 const cricket::MediaContentDescription* video_desc =
1826 cricket::GetFirstVideoContentDescription(offer->description());
1827 EXPECT_TRUE(video_desc == nullptr);
1828}
1829
deadbeefbd7d8f72015-12-18 16:58:44 -08001830// Test creating a sender with a stream ID, and ensure the ID is populated
1831// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001832// Don't run under Unified Plan since the stream API is not available.
1833TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001834 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001835 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001836
kwibergd1fe2812016-04-27 06:47:29 -07001837 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001838 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001839
1840 const cricket::MediaContentDescription* video_desc =
1841 cricket::GetFirstVideoContentDescription(offer->description());
1842 ASSERT_TRUE(video_desc != nullptr);
1843 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001844 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001845}
1846
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001848TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001850 ASSERT_LT(0u, pc_->GetSenders().size());
1851 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001852 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001853 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 EXPECT_TRUE(DoGetStats(remote_audio));
1855
1856 // Remove the stream. Since we are sending to our selves the local
1857 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001858 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 // Do a re-negotiation.
1860 CreateOfferReceiveAnswer();
1861
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 // Test that we still can get statistics for the old track. Even if it is not
1863 // sent any longer.
1864 EXPECT_TRUE(DoGetStats(remote_audio));
1865}
1866
1867// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001868TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001870 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1871 ASSERT_TRUE(video_receiver);
1872 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873}
1874
1875// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001876TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001878 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 pc_factory_->CreateAudioTrack("unknown track", NULL));
1880 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1881}
1882
Steve Anton36da6ff2018-02-16 16:04:20 -08001883TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001884 CreatePeerConnectionWithoutDtls();
1885 EXPECT_TRUE(DoGetRTCStats());
1886 // Clearing stats cache is needed now, but should be temporary.
1887 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1888 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001889 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1890 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001891 EXPECT_TRUE(DoGetRTCStats());
1892 pc_->ClearStatsCache();
1893 CreateOfferReceiveAnswer();
1894 EXPECT_TRUE(DoGetRTCStats());
1895}
1896
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001898TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001899 RTCConfiguration config;
1900 config.enable_rtp_data_channel = true;
1901 config.enable_dtls_srtp = false;
1902 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001903 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001905 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 pc_->CreateDataChannel("test2", NULL);
1907 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001908 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001910 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 new MockDataChannelObserver(data2));
1912
1913 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1914 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1915 std::string data_to_send1 = "testing testing";
1916 std::string data_to_send2 = "testing something else";
1917 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1918
1919 CreateOfferReceiveAnswer();
1920 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1921 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1922
1923 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1924 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1925 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1926 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1927
1928 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1929 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1930
1931 data1->Close();
1932 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1933 CreateOfferReceiveAnswer();
1934 EXPECT_FALSE(observer1->IsOpen());
1935 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1936 EXPECT_TRUE(observer2->IsOpen());
1937
1938 data_to_send2 = "testing something else again";
1939 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1940
1941 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1942}
1943
1944// This test verifies that sendnig binary data over RTP data channels should
1945// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001946TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001947 RTCConfiguration config;
1948 config.enable_rtp_data_channel = true;
1949 config.enable_dtls_srtp = false;
1950 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001951 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001953 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 pc_->CreateDataChannel("test2", NULL);
1955 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001956 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001958 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959 new MockDataChannelObserver(data2));
1960
1961 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1962 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1963
1964 CreateOfferReceiveAnswer();
1965 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1966 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1967
1968 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1969 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1970
jbaucheec21bd2016-03-20 06:15:43 -07001971 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1973}
1974
1975// This test setup a RTP data channels in loop back and test that a channel is
1976// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08001977TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001978 RTCConfiguration config;
1979 config.enable_rtp_data_channel = true;
1980 config.enable_dtls_srtp = false;
1981 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001982 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001984 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985 new MockDataChannelObserver(data1));
1986
1987 CreateOfferReceiveAnswerWithoutSsrc();
1988
1989 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1990
1991 data1->Close();
1992 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1993 CreateOfferReceiveAnswerWithoutSsrc();
1994 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1995 EXPECT_FALSE(observer1->IsOpen());
1996}
1997
1998// This test that if a data channel is added in an answer a receive only channel
1999// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002000TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002001 RTCConfiguration config;
2002 config.enable_rtp_data_channel = true;
2003 config.enable_dtls_srtp = false;
2004
2005 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006
2007 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002008 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009 pc_->CreateDataChannel(offer_label, NULL);
2010
2011 CreateOfferAsLocalDescription();
2012
2013 // Replace the data channel label in the offer and apply it as an answer.
2014 std::string receive_label = "answer_channel";
2015 std::string sdp;
2016 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002017 absl::StrReplaceAll({{offer_label, receive_label}}, &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 CreateAnswerAsRemoteDescription(sdp);
2019
2020 // Verify that a new incoming data channel has been created and that
2021 // it is open but can't we written to.
2022 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2023 DataChannelInterface* received_channel = observer_.last_datachannel_;
2024 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2025 EXPECT_EQ(receive_label, received_channel->label());
2026 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2027
2028 // Verify that the channel we initially offered has been rejected.
2029 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2030
2031 // Do another offer / answer exchange and verify that the data channel is
2032 // opened.
2033 CreateOfferReceiveAnswer();
2034 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2035 kTimeout);
2036}
2037
2038// This test that no data channel is returned if a reliable channel is
2039// requested.
2040// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002041TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002042 RTCConfiguration rtc_config;
2043 rtc_config.enable_rtp_data_channel = true;
2044 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045
2046 std::string label = "test";
2047 webrtc::DataChannelInit config;
2048 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002049 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 pc_->CreateDataChannel(label, &config);
2051 EXPECT_TRUE(channel == NULL);
2052}
2053
deadbeefab9b2d12015-10-14 11:33:11 -07002054// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002055TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002056 RTCConfiguration config;
2057 config.enable_rtp_data_channel = true;
2058 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002059
2060 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002061 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002062 pc_->CreateDataChannel(label, nullptr);
2063 EXPECT_NE(channel, nullptr);
2064
zhihuang9763d562016-08-05 11:14:50 -07002065 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002066 pc_->CreateDataChannel(label, nullptr);
2067 EXPECT_EQ(dup_channel, nullptr);
2068}
2069
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070// This tests that a SCTP data channel is returned using different
2071// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002072TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002073 RTCConfiguration rtc_config;
2074 rtc_config.enable_dtls_srtp = true;
2075 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076
2077 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002078 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 pc_->CreateDataChannel("1", &config);
2080 EXPECT_TRUE(channel != NULL);
2081 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002082 EXPECT_TRUE(observer_.renegotiation_needed_);
2083 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084
2085 config.ordered = false;
2086 channel = pc_->CreateDataChannel("2", &config);
2087 EXPECT_TRUE(channel != NULL);
2088 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002089 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090
2091 config.ordered = true;
2092 config.maxRetransmits = 0;
2093 channel = pc_->CreateDataChannel("3", &config);
2094 EXPECT_TRUE(channel != NULL);
2095 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002096 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02002098 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 config.maxRetransmitTime = 0;
2100 channel = pc_->CreateDataChannel("4", &config);
2101 EXPECT_TRUE(channel != NULL);
2102 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002103 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104}
2105
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02002106// For backwards compatibility, we want people who "unset" maxRetransmits
2107// and maxRetransmitTime by setting them to -1 to get what they want.
2108TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
2109 RTCConfiguration rtc_config;
2110 rtc_config.enable_dtls_srtp = true;
2111 CreatePeerConnection(rtc_config);
2112
2113 webrtc::DataChannelInit config;
2114 config.maxRetransmitTime = -1;
2115 config.maxRetransmits = -1;
2116 rtc::scoped_refptr<DataChannelInterface> channel =
2117 pc_->CreateDataChannel("1", &config);
2118 EXPECT_TRUE(channel != NULL);
2119}
2120
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121// This tests that no data channel is returned if both maxRetransmits and
2122// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002123TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002125 RTCConfiguration rtc_config;
2126 rtc_config.enable_dtls_srtp = true;
2127 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128
2129 std::string label = "test";
2130 webrtc::DataChannelInit config;
2131 config.maxRetransmits = 0;
2132 config.maxRetransmitTime = 0;
2133
zhihuang9763d562016-08-05 11:14:50 -07002134 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 pc_->CreateDataChannel(label, &config);
2136 EXPECT_TRUE(channel == NULL);
2137}
2138
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139// The test verifies that creating a SCTP data channel with an id already in use
2140// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002141TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002143 RTCConfiguration rtc_config;
2144 rtc_config.enable_dtls_srtp = true;
2145 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146
2147 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002148 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002150 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002151 config.negotiated = true;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002152 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 EXPECT_TRUE(channel != NULL);
2154 EXPECT_EQ(1, channel->id());
2155
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 channel = pc_->CreateDataChannel("x", &config);
2157 EXPECT_TRUE(channel == NULL);
2158
2159 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002160 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 channel = pc_->CreateDataChannel("max", &config);
2162 EXPECT_TRUE(channel != NULL);
2163 EXPECT_EQ(config.id, channel->id());
2164
2165 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002166 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 channel = pc_->CreateDataChannel("x", &config);
2168 EXPECT_TRUE(channel == NULL);
2169}
2170
deadbeefab9b2d12015-10-14 11:33:11 -07002171// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002172TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002173 RTCConfiguration rtc_config;
2174 rtc_config.enable_dtls_srtp = true;
2175 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002176
2177 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002178 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002179 pc_->CreateDataChannel(label, nullptr);
2180 EXPECT_NE(channel, nullptr);
2181
zhihuang9763d562016-08-05 11:14:50 -07002182 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002183 pc_->CreateDataChannel(label, nullptr);
2184 EXPECT_NE(dup_channel, nullptr);
2185}
2186
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002187// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2188// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002189TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002190 RTCConfiguration rtc_config;
2191 rtc_config.enable_rtp_data_channel = true;
2192 rtc_config.enable_dtls_srtp = false;
2193 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002194
zhihuang9763d562016-08-05 11:14:50 -07002195 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002196 pc_->CreateDataChannel("test1", NULL);
2197 EXPECT_TRUE(observer_.renegotiation_needed_);
2198 observer_.renegotiation_needed_ = false;
2199
Guido Urdaneta70c2db12019-04-16 12:24:14 +02002200 CreateOfferReceiveAnswer();
2201
zhihuang9763d562016-08-05 11:14:50 -07002202 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002203 pc_->CreateDataChannel("test2", NULL);
Guido Urdaneta70c2db12019-04-16 12:24:14 +02002204 EXPECT_EQ(observer_.renegotiation_needed_,
2205 GetParam() == SdpSemantics::kPlanB);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002206}
2207
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002209TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002210 RTCConfiguration rtc_config;
2211 rtc_config.enable_rtp_data_channel = true;
2212 rtc_config.enable_dtls_srtp = false;
2213 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214
zhihuang9763d562016-08-05 11:14:50 -07002215 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002217 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218 pc_->CreateDataChannel("test2", NULL);
2219 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002220 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002222 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 new MockDataChannelObserver(data2));
2224
2225 CreateOfferReceiveAnswer();
2226 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2227 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2228
2229 ReleasePeerConnection();
2230 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2231 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2232}
2233
Zhi Huang644fde42018-04-02 19:16:26 -07002234// This tests that RTP data channels can be rejected in an answer.
2235TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002236 RTCConfiguration rtc_config;
2237 rtc_config.enable_rtp_data_channel = true;
2238 rtc_config.enable_dtls_srtp = false;
2239 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240
zhihuang9763d562016-08-05 11:14:50 -07002241 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 pc_->CreateDataChannel("offer_channel", NULL));
2243
2244 CreateOfferAsLocalDescription();
2245
2246 // Create an answer where the m-line for data channels are rejected.
2247 std::string sdp;
2248 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002249 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002250 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002251 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002253 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 data_info->rejected = true;
2255
Steve Antondb45ca82017-09-11 18:27:34 -07002256 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2258}
2259
Zhi Huang644fde42018-04-02 19:16:26 -07002260#ifdef HAVE_SCTP
2261// This tests that SCTP data channels can be rejected in an answer.
2262TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2263#else
2264TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2265#endif
2266{
Niels Möllerf06f9232018-08-07 12:32:18 +02002267 RTCConfiguration rtc_config;
2268 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002269
2270 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2271 pc_->CreateDataChannel("offer_channel", NULL));
2272
2273 CreateOfferAsLocalDescription();
2274
2275 // Create an answer where the m-line for data channels are rejected.
2276 std::string sdp;
2277 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2278 std::unique_ptr<SessionDescriptionInterface> answer(
2279 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2280 ASSERT_TRUE(answer);
2281 cricket::ContentInfo* data_info =
2282 cricket::GetFirstDataContent(answer->description());
2283 data_info->rejected = true;
2284
2285 DoSetRemoteDescription(std::move(answer));
2286 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2287}
2288
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289// Test that we can create a session description from an SDP string from
2290// FireFox, use it as a remote session description, generate an answer and use
2291// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002292TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002293 RTCConfiguration rtc_config;
2294 rtc_config.enable_dtls_srtp = true;
2295 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002296 AddAudioTrack("audio_label");
2297 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002298 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002299 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002300 webrtc::kFireFoxSdpOffer, nullptr));
2301 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 CreateAnswerAsLocalDescription();
2303 ASSERT_TRUE(pc_->local_description() != NULL);
2304 ASSERT_TRUE(pc_->remote_description() != NULL);
2305
2306 const cricket::ContentInfo* content =
2307 cricket::GetFirstAudioContent(pc_->local_description()->description());
2308 ASSERT_TRUE(content != NULL);
2309 EXPECT_FALSE(content->rejected);
2310
2311 content =
2312 cricket::GetFirstVideoContent(pc_->local_description()->description());
2313 ASSERT_TRUE(content != NULL);
2314 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002315#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 content =
2317 cricket::GetFirstDataContent(pc_->local_description()->description());
2318 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002319 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002320#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321}
2322
zhihuangb19012e2017-09-19 13:47:59 -07002323// Test that fallback from DTLS to SDES is not supported.
2324// The fallback was previously supported but was removed to simplify the code
2325// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002326TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002327 RTCConfiguration rtc_config;
2328 rtc_config.enable_dtls_srtp = true;
2329 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002330 // Wait for fake certificate to be generated. Previously, this is what caused
2331 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002332 AddAudioTrack("audio_label");
2333 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002334 ASSERT_NE(nullptr, fake_certificate_generator_);
2335 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2336 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002337 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002338 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2339 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002340 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002341}
2342
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343// Test that we can create an audio only offer and receive an answer with a
2344// limited set of audio codecs and receive an updated offer with more audio
2345// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002346TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002347 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002348 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 CreateOfferAsLocalDescription();
2350
Steve Anton36da6ff2018-02-16 16:04:20 -08002351 const char* answer_sdp =
2352 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2353 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002354 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002355 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002356 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357
Steve Anton36da6ff2018-02-16 16:04:20 -08002358 const char* reoffer_sdp =
2359 (sdp_semantics_ == SdpSemantics::kPlanB
2360 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2361 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002362 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002363 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002364 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 CreateAnswerAsLocalDescription();
2366}
2367
deadbeefc80741f2015-10-22 13:14:45 -07002368// Test that if we're receiving (but not sending) a track, subsequent offers
2369// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002370TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002371 RTCConfiguration rtc_config;
2372 rtc_config.enable_dtls_srtp = true;
2373 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002374 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002375 CreateAnswerAsLocalDescription();
2376
2377 // At this point we should be receiving stream 1, but not sending anything.
2378 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002379 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002380 DoCreateOffer(&offer, nullptr);
2381
2382 const cricket::ContentInfo* video_content =
2383 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002384 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2385 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002386
2387 const cricket::ContentInfo* audio_content =
2388 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002389 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2390 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002391}
2392
2393// Test that if we're receiving (but not sending) a track, and the
2394// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2395// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002396TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002397 RTCConfiguration rtc_config;
2398 rtc_config.enable_dtls_srtp = true;
2399 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002400 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002401 CreateAnswerAsLocalDescription();
2402
2403 // At this point we should be receiving stream 1, but not sending anything.
2404 // A new offer would be recvonly, but we'll set the "no receive" constraints
2405 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002406 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002407 RTCOfferAnswerOptions options;
2408 options.offer_to_receive_audio = 0;
2409 options.offer_to_receive_video = 0;
2410 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002411
2412 const cricket::ContentInfo* video_content =
2413 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002414 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2415 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002416
2417 const cricket::ContentInfo* audio_content =
2418 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002419 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2420 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002421}
2422
deadbeef653b8e02015-11-11 12:55:10 -08002423// Test that we can use SetConfiguration to change the ICE servers of the
2424// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002425TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002426 CreatePeerConnection();
2427
Steve Anton36da6ff2018-02-16 16:04:20 -08002428 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002429 PeerConnectionInterface::IceServer server;
2430 server.uri = "stun:test_hostname";
2431 config.servers.push_back(server);
2432 EXPECT_TRUE(pc_->SetConfiguration(config));
2433
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002434 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2435 EXPECT_EQ("test_hostname",
2436 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002437}
2438
Steve Anton36da6ff2018-02-16 16:04:20 -08002439TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002440 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002441 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002442 config.type = PeerConnectionInterface::kRelay;
2443 EXPECT_TRUE(pc_->SetConfiguration(config));
2444 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2445}
2446
Steve Anton36da6ff2018-02-16 16:04:20 -08002447TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002448 PeerConnectionInterface::RTCConfiguration config;
2449 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002450 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002451 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002452 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2453
2454 config.prune_turn_ports = true;
2455 EXPECT_TRUE(pc_->SetConfiguration(config));
2456 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2457}
2458
skvladd1f5fda2017-02-03 16:54:05 -08002459// Test that the ice check interval can be changed. This does not verify that
2460// the setting makes it all the way to P2PTransportChannel, as that would
2461// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002462TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002463 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002464 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002465 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002466 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002467 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002468 EXPECT_TRUE(pc_->SetConfiguration(config));
Qingsi Wangbca14852019-06-26 14:56:02 -07002469 config = pc_->GetConfiguration();
2470 EXPECT_EQ(config.ice_check_min_interval, 100);
2471}
2472
2473TEST_P(PeerConnectionInterfaceTest,
2474 SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) {
2475 PeerConnectionInterface::RTCConfiguration config;
2476 config.surface_ice_candidates_on_ice_transport_type_changed = false;
2477 CreatePeerConnection(config);
2478 config = pc_->GetConfiguration();
2479 EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed);
2480
2481 config.surface_ice_candidates_on_ice_transport_type_changed = true;
2482 EXPECT_TRUE(pc_->SetConfiguration(config));
2483 config = pc_->GetConfiguration();
2484 EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed);
skvladd1f5fda2017-02-03 16:54:05 -08002485}
2486
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002487// Test that when SetConfiguration changes both the pool size and other
2488// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002489TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002490 SetConfigurationCreatesPooledSessionCorrectly) {
2491 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002492 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002493 config.ice_candidate_pool_size = 1;
2494 PeerConnectionInterface::IceServer server;
2495 server.uri = kStunAddressOnly;
2496 config.servers.push_back(server);
2497 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002498 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002499
2500 const cricket::FakePortAllocatorSession* session =
2501 static_cast<const cricket::FakePortAllocatorSession*>(
2502 port_allocator_->GetPooledSession());
2503 ASSERT_NE(nullptr, session);
2504 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002505}
2506
deadbeef293e9262017-01-11 12:28:30 -08002507// Test that after SetLocalDescription, changing the pool size is not allowed,
2508// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002509TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002510 CantChangePoolSizeAfterSetLocalDescription) {
2511 CreatePeerConnection();
2512 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002513 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002514 config.ice_candidate_pool_size = 1;
2515 EXPECT_TRUE(pc_->SetConfiguration(config));
2516
2517 // Set remote offer; can still change pool size at this point.
2518 CreateOfferAsRemoteDescription();
2519 config.ice_candidate_pool_size = 2;
2520 EXPECT_TRUE(pc_->SetConfiguration(config));
2521
2522 // Set local answer; now it's too late.
2523 CreateAnswerAsLocalDescription();
2524 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002525 RTCError error;
2526 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2527 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2528}
2529
deadbeef42a42632017-03-10 15:18:00 -08002530// Test that after setting an answer, extra pooled sessions are discarded. The
2531// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002532TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002533 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2534 CreatePeerConnection();
2535
2536 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002537 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002538 config.ice_candidate_pool_size = 4;
2539 EXPECT_TRUE(pc_->SetConfiguration(config));
2540
2541 // Do offer/answer.
2542 CreateOfferAsRemoteDescription();
2543 CreateAnswerAsLocalDescription();
2544
2545 // Expect no pooled sessions to be left.
2546 const cricket::PortAllocatorSession* session =
2547 port_allocator_->GetPooledSession();
2548 EXPECT_EQ(nullptr, session);
2549}
2550
2551// After Close is called, pooled candidates should be discarded so as to not
2552// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002553TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002554 CreatePeerConnection();
2555
Steve Anton36da6ff2018-02-16 16:04:20 -08002556 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002557 config.ice_candidate_pool_size = 3;
2558 EXPECT_TRUE(pc_->SetConfiguration(config));
2559 pc_->Close();
2560
2561 // Expect no pooled sessions to be left.
2562 const cricket::PortAllocatorSession* session =
2563 port_allocator_->GetPooledSession();
2564 EXPECT_EQ(nullptr, session);
2565}
2566
deadbeef293e9262017-01-11 12:28:30 -08002567// Test that SetConfiguration returns an invalid modification error if
2568// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002569TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002570 SetConfigurationReturnsInvalidModificationError) {
2571 PeerConnectionInterface::RTCConfiguration config;
2572 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2573 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2574 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002575 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002576
Steve Anton36da6ff2018-02-16 16:04:20 -08002577 PeerConnectionInterface::RTCConfiguration modified_config =
2578 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002579 modified_config.bundle_policy =
2580 PeerConnectionInterface::kBundlePolicyMaxBundle;
2581 RTCError error;
2582 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2583 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2584
Steve Anton36da6ff2018-02-16 16:04:20 -08002585 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002586 modified_config.rtcp_mux_policy =
2587 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2588 error.set_type(RTCErrorType::NONE);
2589 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2590 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2591
Steve Anton36da6ff2018-02-16 16:04:20 -08002592 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002593 modified_config.continual_gathering_policy =
2594 PeerConnectionInterface::GATHER_CONTINUALLY;
2595 error.set_type(RTCErrorType::NONE);
2596 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2597 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2598}
2599
2600// Test that SetConfiguration returns a range error if the candidate pool size
2601// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002602TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002603 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2604 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002605 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002606 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002607
2608 config.ice_candidate_pool_size = -1;
2609 RTCError error;
2610 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2611 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2612
2613 config.ice_candidate_pool_size = INT_MAX;
2614 error.set_type(RTCErrorType::NONE);
2615 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2616 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2617}
2618
2619// Test that SetConfiguration returns a syntax error if parsing an ICE server
2620// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002621TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002622 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2623 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002624 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002625 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002626
2627 PeerConnectionInterface::IceServer bad_server;
2628 bad_server.uri = "stunn:www.example.com";
2629 config.servers.push_back(bad_server);
2630 RTCError error;
2631 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2632 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2633}
2634
2635// Test that SetConfiguration returns an invalid parameter error if a TURN
2636// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002637TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002638 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2639 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002640 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002641 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002642
2643 PeerConnectionInterface::IceServer bad_server;
2644 bad_server.uri = "turn:www.example.com";
2645 // Missing password.
2646 bad_server.username = "foo";
2647 config.servers.push_back(bad_server);
2648 RTCError error;
2649 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2650 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002651}
2652
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002653// Test that PeerConnection::Close changes the states to closed and all remote
2654// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002655TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656 // Initialize a PeerConnection and negotiate local and remote session
2657 // description.
2658 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002659
2660 // With Plan B, verify the stream count. The analog with Unified Plan is the
2661 // RtpTransceiver count.
2662 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2663 ASSERT_EQ(1u, pc_->local_streams()->count());
2664 ASSERT_EQ(1u, pc_->remote_streams()->count());
2665 } else {
2666 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2667 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002668
2669 pc_->Close();
2670
2671 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2672 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2673 pc_->ice_connection_state());
2674 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2675 pc_->ice_gathering_state());
2676
Steve Anton36da6ff2018-02-16 16:04:20 -08002677 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2678 EXPECT_EQ(1u, pc_->local_streams()->count());
2679 EXPECT_EQ(1u, pc_->remote_streams()->count());
2680 } else {
2681 // Verify that the RtpTransceivers are still present but all stopped.
2682 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Mirko Bonadei739baf02019-01-27 17:29:42 +01002683 for (const auto& transceiver : pc_->GetTransceivers()) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002684 EXPECT_TRUE(transceiver->stopped());
2685 }
2686 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687
Steve Anton36da6ff2018-02-16 16:04:20 -08002688 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2689 ASSERT_TRUE(audio_receiver);
2690 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2691 ASSERT_TRUE(video_receiver);
2692
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002693 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002694 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002695 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002696 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002697 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698}
2699
2700// Test that PeerConnection methods fails gracefully after
2701// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002702// Don't run under Unified Plan since the stream API is not available.
2703TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002704 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002705 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 CreateOfferAsRemoteDescription();
2707 CreateAnswerAsLocalDescription();
2708
2709 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002710 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711 pc_->local_streams()->at(0);
2712
2713 pc_->Close();
2714
2715 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002716 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2719
2720 EXPECT_TRUE(pc_->local_description() != NULL);
2721 EXPECT_TRUE(pc_->remote_description() != NULL);
2722
kwibergd1fe2812016-04-27 06:47:29 -07002723 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002724 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002725 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002726 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727
2728 std::string sdp;
2729 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002730 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002731 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002732 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733
2734 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002735 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002736 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002737 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738}
2739
2740// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002741TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742 InitiateCall();
2743 pc_->Close();
2744 DoGetStats(NULL);
2745}
deadbeefab9b2d12015-10-14 11:33:11 -07002746
2747// NOTE: The series of tests below come from what used to be
2748// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2749// setting a remote or local description has the expected effects.
2750
2751// This test verifies that the remote MediaStreams corresponding to a received
2752// SDP string is created. In this test the two separate MediaStreams are
2753// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002754TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002755 RTCConfiguration config;
2756 config.enable_dtls_srtp = true;
2757 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002758 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002759
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002760 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002761 EXPECT_TRUE(
2762 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2763 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2764 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2765
2766 // Create a session description based on another SDP with another
2767 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002768 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002769
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002770 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002771 EXPECT_TRUE(
2772 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2773}
2774
2775// This test verifies that when remote tracks are added/removed from SDP, the
2776// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002777// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2778// specific behavior.
2779TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002780 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002781 RTCConfiguration config;
2782 config.enable_dtls_srtp = true;
2783 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002784 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002785 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002786 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002787 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2788 reference_collection_));
2789
2790 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002791 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002792 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002793 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002794 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2795 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002796 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002797 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2798 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002799 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002800 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2801 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002802
2803 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002804 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002805 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002806 MockTrackObserver audio_track_observer(audio_track2);
2807 MockTrackObserver video_track_observer(video_track2);
2808
2809 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2810 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002811 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002812 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2813 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002814 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002815 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002816 audio_track2->state(), kTimeout);
2817 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2818 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002819}
2820
2821// This tests that remote tracks are ended if a local session description is set
2822// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002823TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002824 RTCConfiguration config;
2825 config.enable_dtls_srtp = true;
2826 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002827 // First create and set a remote offer, then reject its video content in our
2828 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002829 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2830 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2831 ASSERT_TRUE(audio_receiver);
2832 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2833 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002834
Steve Anton36da6ff2018-02-16 16:04:20 -08002835 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2836 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002837 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002838 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2839 video_receiver->track();
2840 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002841
kwibergd1fe2812016-04-27 06:47:29 -07002842 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002843 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002844 cricket::ContentInfo* video_info =
2845 local_answer->description()->GetContentByName("video");
2846 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002847 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002848 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2849 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002850
2851 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002852 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002853 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002854 video_info = local_offer->description()->GetContentByName("video");
2855 ASSERT_TRUE(video_info != nullptr);
2856 video_info->rejected = true;
2857 cricket::ContentInfo* audio_info =
2858 local_offer->description()->GetContentByName("audio");
2859 ASSERT_TRUE(audio_info != nullptr);
2860 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002861 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002862 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002863 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2864 kTimeout);
2865 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2866 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002867}
2868
2869// This tests that we won't crash if the remote track has been removed outside
2870// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002871// Don't run under Unified Plan since the stream API is not available.
2872TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002873 RTCConfiguration config;
2874 config.enable_dtls_srtp = true;
2875 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002876 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002877 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2878 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2879 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2880
kwibergd1fe2812016-04-27 06:47:29 -07002881 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002882 webrtc::CreateSessionDescription(SdpType::kAnswer,
2883 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002884 cricket::ContentInfo* video_info =
2885 local_answer->description()->GetContentByName("video");
2886 video_info->rejected = true;
2887 cricket::ContentInfo* audio_info =
2888 local_answer->description()->GetContentByName("audio");
2889 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002890 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002891
2892 // No crash is a pass.
2893}
2894
deadbeef5e97fb52015-10-15 12:49:08 -07002895// This tests that if a recvonly remote description is set, no remote streams
2896// will be created, even if the description contains SSRCs/MSIDs.
2897// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002898TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002899 RTCConfiguration config;
2900 config.enable_dtls_srtp = true;
2901 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002902
Steve Anton36da6ff2018-02-16 16:04:20 -08002903 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002904 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 12:49:08 -07002905 CreateAndSetRemoteOffer(recvonly_offer);
2906
2907 EXPECT_EQ(0u, observer_.remote_streams()->count());
2908}
2909
deadbeefab9b2d12015-10-14 11:33:11 -07002910// This tests that a default MediaStream is created if a remote session
2911// description doesn't contain any streams and no MSID support.
2912// It also tests that the default stream is updated if a video m-line is added
2913// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002914// Don't run under Unified Plan since this behavior is Plan B specific.
2915TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002916 RTCConfiguration config;
2917 config.enable_dtls_srtp = true;
2918 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002919 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2920
2921 ASSERT_EQ(1u, observer_.remote_streams()->count());
2922 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2923
2924 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2925 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002926 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002927
2928 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2929 ASSERT_EQ(1u, observer_.remote_streams()->count());
2930 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2931 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002932 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2933 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002934 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2935 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002936 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2937 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002938}
2939
2940// This tests that a default MediaStream is created if a remote session
2941// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002942// Don't run under Unified Plan since this behavior is Plan B specific.
2943TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002944 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002945 RTCConfiguration config;
2946 config.enable_dtls_srtp = true;
2947 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002948 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2949
2950 ASSERT_EQ(1u, observer_.remote_streams()->count());
2951 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2952
2953 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2954 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002955 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002956}
2957
2958// This tests that it won't crash when PeerConnection tries to remove
2959// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002960// Don't run under Unified Plan since this behavior is Plan B specific.
2961TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002962 RTCConfiguration config;
2963 config.enable_dtls_srtp = true;
2964 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002965 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002966 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2967 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2968 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2969
2970 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2971
2972 // No crash is a pass.
2973}
2974
2975// This tests that a default MediaStream is created if the remote session
2976// description doesn't contain any streams and don't contain an indication if
2977// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002978// Don't run under Unified Plan since this behavior is Plan B specific.
2979TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002980 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002981 RTCConfiguration config;
2982 config.enable_dtls_srtp = true;
2983 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002984 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2985
2986 ASSERT_EQ(1u, observer_.remote_streams()->count());
2987 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2988 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2989 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2990}
2991
2992// This tests that a default MediaStream is not created if the remote session
2993// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002994// Don't run under Unified Plan since this behavior is Plan B specific.
2995TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002996 RTCConfiguration config;
2997 config.enable_dtls_srtp = true;
2998 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002999 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
3000 EXPECT_EQ(0u, observer_.remote_streams()->count());
3001}
3002
deadbeefbda7e0b2015-12-08 17:13:40 -08003003// This tests that when setting a new description, the old default tracks are
3004// not destroyed and recreated.
3005// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003006// Don't run under Unified Plan since this behavior is Plan B specific.
3007TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003008 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003009 RTCConfiguration config;
3010 config.enable_dtls_srtp = true;
3011 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08003012 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3013
3014 ASSERT_EQ(1u, observer_.remote_streams()->count());
3015 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3016 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3017
3018 // Set the track to "disabled", then set a new description and ensure the
3019 // track is still disabled, which ensures it hasn't been recreated.
3020 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3021 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3022 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3023 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3024}
3025
deadbeefab9b2d12015-10-14 11:33:11 -07003026// This tests that a default MediaStream is not created if a remote session
3027// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003028// Don't run under Unified Plan since this behavior is Plan B specific.
3029TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003030 RTCConfiguration config;
3031 config.enable_dtls_srtp = true;
3032 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003033 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003034 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003035 EXPECT_TRUE(
3036 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3037
3038 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3039 EXPECT_EQ(0u, observer_.remote_streams()->count());
3040}
3041
Seth Hampson5897a6e2018-04-03 11:16:33 -07003042// This tests that a default MediaStream is created if a remote SDP comes from
3043// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3044TEST_F(PeerConnectionInterfaceTestPlanB,
3045 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003046 RTCConfiguration config;
3047 config.enable_dtls_srtp = true;
3048 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003049 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3050 // Add a=msid lines to simulate a Unified Plan endpoint that only
3051 // signals stream IDs with a=msid lines.
3052 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3053
3054 CreateAndSetRemoteOffer(sdp_string);
3055
3056 ASSERT_EQ(1u, observer_.remote_streams()->count());
3057 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3058 EXPECT_EQ("default", remote_stream->id());
3059 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3060}
3061
Seth Hampson5b4f0752018-04-02 16:31:36 -07003062// This tests that when a Plan B endpoint receives an SDP that signals no media
3063// stream IDs indicated by the special character "-" in the a=msid line, that
3064// a default stream ID will be used for the MediaStream ID. This can occur
3065// when a Unified Plan endpoint signals no media stream IDs, but signals both
3066// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3067TEST_F(PeerConnectionInterfaceTestPlanB,
3068 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003069 RTCConfiguration config;
3070 config.enable_dtls_srtp = true;
3071 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003072 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3073 // the sender's stream ID will be interpreted as no stream IDs.
3074 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3075 sdp_string.append("a=msid:- audiotrack0\n");
3076
3077 CreateAndSetRemoteOffer(sdp_string);
3078
3079 ASSERT_EQ(1u, observer_.remote_streams()->count());
3080 // Because SSRCs are signaled the track ID will be what was signaled in the
3081 // a=msid line.
3082 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3083 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3084 EXPECT_EQ("default", remote_stream->id());
3085 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003086
3087 // Previously a bug ocurred when setting the remote description a second time.
3088 // This is because we checked equality of the remote StreamParams stream ID
3089 // (empty), and the previously set stream ID for the remote sender
3090 // ("default"). This cause a track to be removed, then added, when really
3091 // nothing should occur because it is the same track.
3092 CreateAndSetRemoteOffer(sdp_string);
3093 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3094 EXPECT_EQ(1u, observer_.add_track_events_.size());
3095 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3096 remote_stream = observer_.remote_streams()->at(0);
3097 EXPECT_EQ("default", remote_stream->id());
3098 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003099}
3100
deadbeefab9b2d12015-10-14 11:33:11 -07003101// This tests that an RtpSender is created when the local description is set
3102// after adding a local stream.
3103// TODO(deadbeef): This test and the one below it need to be updated when
3104// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003105// Don't run under Unified Plan since this behavior is Plan B specific.
3106TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003107 RTCConfiguration config;
3108 config.enable_dtls_srtp = true;
3109 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003110
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003111 // Create an offer with 1 stream with 2 tracks of each type.
3112 rtc::scoped_refptr<StreamCollection> stream_collection =
3113 CreateStreamCollection(1, 2);
3114 pc_->AddStream(stream_collection->at(0));
3115 std::unique_ptr<SessionDescriptionInterface> offer;
3116 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003117 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003118
deadbeefab9b2d12015-10-14 11:33:11 -07003119 auto senders = pc_->GetSenders();
3120 EXPECT_EQ(4u, senders.size());
3121 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3122 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3123 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3124 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3125
3126 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003127 pc_->RemoveStream(stream_collection->at(0));
3128 stream_collection = CreateStreamCollection(1, 1);
3129 pc_->AddStream(stream_collection->at(0));
3130 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003131 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003132
deadbeefab9b2d12015-10-14 11:33:11 -07003133 senders = pc_->GetSenders();
3134 EXPECT_EQ(2u, senders.size());
3135 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3136 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3137 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3138 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3139}
3140
3141// This tests that an RtpSender is created when the local description is set
3142// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003143// Don't run under Unified Plan since this behavior is Plan B specific.
3144TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003145 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003146 RTCConfiguration config;
3147 config.enable_dtls_srtp = true;
3148 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003149
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003150 rtc::scoped_refptr<StreamCollection> stream_collection =
3151 CreateStreamCollection(1, 2);
3152 // Add a stream to create the offer, but remove it afterwards.
3153 pc_->AddStream(stream_collection->at(0));
3154 std::unique_ptr<SessionDescriptionInterface> offer;
3155 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3156 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003157
Steve Antondb45ca82017-09-11 18:27:34 -07003158 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003159 auto senders = pc_->GetSenders();
3160 EXPECT_EQ(0u, senders.size());
3161
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003162 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003163 senders = pc_->GetSenders();
3164 EXPECT_EQ(4u, senders.size());
3165 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3166 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3167 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3168 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3169}
3170
3171// This tests that the expected behavior occurs if the SSRC on a local track is
3172// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003173TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003174 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003175 RTCConfiguration config;
3176 config.enable_dtls_srtp = true;
3177 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003178
Steve Anton36da6ff2018-02-16 16:04:20 -08003179 AddAudioTrack(kAudioTracks[0]);
3180 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003181 std::unique_ptr<SessionDescriptionInterface> offer;
3182 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3183 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003184 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3185 webrtc::CreateSessionDescription(
3186 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003187 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-11 18:27:34 -07003188 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003189
deadbeefab9b2d12015-10-14 11:33:11 -07003190 auto senders = pc_->GetSenders();
3191 EXPECT_EQ(2u, senders.size());
3192 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3193 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3194
3195 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003196 cricket::MediaContentDescription* desc =
3197 cricket::GetFirstAudioContentDescription(modified_offer->description());
3198 ASSERT_TRUE(desc != NULL);
3199 for (StreamParams& stream : desc->mutable_streams()) {
3200 for (unsigned int& ssrc : stream.ssrcs) {
3201 ++ssrc;
3202 }
3203 }
deadbeefab9b2d12015-10-14 11:33:11 -07003204
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003205 desc =
3206 cricket::GetFirstVideoContentDescription(modified_offer->description());
3207 ASSERT_TRUE(desc != NULL);
3208 for (StreamParams& stream : desc->mutable_streams()) {
3209 for (unsigned int& ssrc : stream.ssrcs) {
3210 ++ssrc;
3211 }
3212 }
3213
Steve Antondb45ca82017-09-11 18:27:34 -07003214 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003215 senders = pc_->GetSenders();
3216 EXPECT_EQ(2u, senders.size());
3217 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3218 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3219 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3220 // changed.
3221}
3222
3223// This tests that the expected behavior occurs if a new session description is
3224// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003225// Don't run under Unified Plan since the stream API is not available.
3226TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003227 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003228 RTCConfiguration config;
3229 config.enable_dtls_srtp = true;
3230 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003231
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003232 rtc::scoped_refptr<StreamCollection> stream_collection =
3233 CreateStreamCollection(2, 1);
3234 pc_->AddStream(stream_collection->at(0));
3235 std::unique_ptr<SessionDescriptionInterface> offer;
3236 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003237 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003238
deadbeefab9b2d12015-10-14 11:33:11 -07003239 auto senders = pc_->GetSenders();
3240 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003241 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3242 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003243
3244 // Add a new MediaStream but with the same tracks as in the first stream.
3245 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3246 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003247 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3248 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003249 pc_->AddStream(stream_1);
3250
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003251 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003252 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003253
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003254 auto new_senders = pc_->GetSenders();
3255 // Should be the same senders as before, but with updated stream id.
3256 // Note that this behavior is subject to change in the future.
3257 // We may decide the PC should ignore existing tracks in AddStream.
3258 EXPECT_EQ(senders, new_senders);
3259 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3260 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003261}
3262
zhihuang81c3a032016-11-17 12:06:24 -08003263// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003264TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003265 RTCConfiguration config;
3266 config.enable_dtls_srtp = true;
3267 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003268 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3269 EXPECT_EQ(observer_.num_added_tracks_, 1);
3270 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3271
3272 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003273 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003274 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003275 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3276}
3277
deadbeefd1a38b52016-12-10 13:15:33 -08003278// Test that when SetConfiguration is called and the configuration is
3279// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003280TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003281 PeerConnectionInterface::RTCConfiguration config;
3282 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003283 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003284 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003285 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3286 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003287
3288 // Do initial offer/answer so there's something to restart.
3289 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003290 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003291
3292 // Grab the ufrags.
3293 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3294
3295 // Change ICE policy, which should trigger an ICE restart on the next offer.
3296 config.type = PeerConnectionInterface::kAll;
3297 EXPECT_TRUE(pc_->SetConfiguration(config));
3298 CreateOfferAsLocalDescription();
3299
3300 // Grab the new ufrags.
3301 std::vector<std::string> subsequent_ufrags =
3302 GetUfrags(pc_->local_description());
3303
3304 // Sanity check.
3305 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3306 // Check that each ufrag is different.
3307 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3308 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3309 }
3310}
3311
3312// Test that when SetConfiguration is called and the configuration *isn't*
3313// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003314TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003315 PeerConnectionInterface::RTCConfiguration config;
3316 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003317 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003318 config = pc_->GetConfiguration();
3319 AddAudioTrack(kAudioTracks[0]);
3320 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003321
3322 // Do initial offer/answer so there's something to restart.
3323 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003324 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003325
3326 // Grab the ufrags.
3327 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3328
3329 // Call SetConfiguration with a config identical to what the PC was
3330 // constructed with.
3331 EXPECT_TRUE(pc_->SetConfiguration(config));
3332 CreateOfferAsLocalDescription();
3333
3334 // Grab the new ufrags.
3335 std::vector<std::string> subsequent_ufrags =
3336 GetUfrags(pc_->local_description());
3337
3338 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3339}
3340
3341// Test for a weird corner case scenario:
3342// 1. Audio/video session established.
3343// 2. SetConfiguration changes ICE config; ICE restart needed.
3344// 3. ICE restart initiated by remote peer, but only for one m= section.
3345// 4. Next createOffer should initiate an ICE restart, but only for the other
3346// m= section; it would be pointless to do an ICE restart for the m= section
3347// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003348TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003349 PeerConnectionInterface::RTCConfiguration config;
3350 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003351 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003352 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003353 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3354 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003355
3356 // Do initial offer/answer so there's something to restart.
3357 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003358 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003359
3360 // Change ICE policy, which should set the "needs-ice-restart" flag.
3361 config.type = PeerConnectionInterface::kAll;
3362 EXPECT_TRUE(pc_->SetConfiguration(config));
3363
3364 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003365 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003366 webrtc::CreateSessionDescription(SdpType::kOffer,
3367 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003368 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003369 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3370 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003371 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003372 CreateAnswerAsLocalDescription();
3373
3374 // Grab the ufrags.
3375 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003376 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003377
3378 // Create offer and grab the new ufrags.
3379 CreateOfferAsLocalDescription();
3380 std::vector<std::string> subsequent_ufrags =
3381 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003382 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003383
3384 // Ensure that only the ufrag for the second m= section changed.
3385 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3386 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3387}
3388
deadbeeffe4a8a42016-12-20 17:56:17 -08003389// Tests that the methods to return current/pending descriptions work as
3390// expected at different points in the offer/answer exchange. This test does
3391// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003392TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003393 // This disables DTLS so we can apply an answer to ourselves.
3394 CreatePeerConnection();
3395
3396 // Create initial local offer and get SDP (which will also be used as
3397 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003398 std::unique_ptr<SessionDescriptionInterface> local_offer;
3399 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003400 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003401 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003402
3403 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003404 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3405 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3406 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003407 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3408 EXPECT_EQ(nullptr, pc_->current_local_description());
3409 EXPECT_EQ(nullptr, pc_->current_remote_description());
3410
3411 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003412 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003413 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003414 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3415 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3416 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3417 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003418 EXPECT_EQ(nullptr, pc_->current_local_description());
3419 EXPECT_EQ(nullptr, pc_->current_remote_description());
3420
3421 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003422 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003423 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003424 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3425 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003426 EXPECT_EQ(nullptr, pc_->pending_local_description());
3427 EXPECT_EQ(nullptr, pc_->pending_remote_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 remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003432 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003433 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003434 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3435 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3436 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003437 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003438 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 pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003442 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003443 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003444 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3445 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3446 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3447 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3448 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3449 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003450
3451 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003452 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003453 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003454 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3455 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003456 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3457 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003458 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3459 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003460}
3461
zhihuang77985012017-02-07 15:45:16 -08003462// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3463// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003464// This version tests the StartRtcEventLog version that receives an object
3465// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003466TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003467 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3468 CreatePeerConnection();
3469 // The RtcEventLog will be reset when the PeerConnection is closed.
3470 pc_->Close();
3471
Niels Möllerdec9f742019-06-03 15:25:20 +02003472 EXPECT_FALSE(
3473 pc_->StartRtcEventLog(absl::make_unique<webrtc::RtcEventLogOutputNull>(),
3474 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003475 pc_->StopRtcEventLog();
3476}
3477
deadbeef30952b42017-04-21 02:41:29 -07003478// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003479TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003480 CreatePeerConnection();
3481
3482 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003483 RTCOfferAnswerOptions options;
3484 options.offer_to_receive_audio = 1;
3485 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003486 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003487 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003488 cricket::SessionDescription* desc = offer->description();
3489 ASSERT_EQ(2u, desc->transport_infos().size());
3490 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3491 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3492
3493 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003494 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003495 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003496 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003497 desc = answer->description();
3498 ASSERT_EQ(2u, desc->transport_infos().size());
3499 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3500 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3501}
3502
deadbeef1dcb1642017-03-29 21:08:16 -07003503// Test that ICE renomination isn't offered if it's not enabled in the PC's
3504// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003505TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003506 PeerConnectionInterface::RTCConfiguration config;
3507 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003508 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003509 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003510
3511 std::unique_ptr<SessionDescriptionInterface> offer;
3512 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3513 cricket::SessionDescription* desc = offer->description();
3514 EXPECT_EQ(1u, desc->transport_infos().size());
3515 EXPECT_FALSE(
3516 desc->transport_infos()[0].description.GetIceParameters().renomination);
3517}
3518
3519// Test that the ICE renomination option is present in generated offers/answers
3520// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003521TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003522 PeerConnectionInterface::RTCConfiguration config;
3523 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003524 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003525 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003526
3527 std::unique_ptr<SessionDescriptionInterface> offer;
3528 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3529 cricket::SessionDescription* desc = offer->description();
3530 EXPECT_EQ(1u, desc->transport_infos().size());
3531 EXPECT_TRUE(
3532 desc->transport_infos()[0].description.GetIceParameters().renomination);
3533
3534 // Set the offer as a remote description, then create an answer and ensure it
3535 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003536 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003537 std::unique_ptr<SessionDescriptionInterface> answer;
3538 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3539 desc = answer->description();
3540 EXPECT_EQ(1u, desc->transport_infos().size());
3541 EXPECT_TRUE(
3542 desc->transport_infos()[0].description.GetIceParameters().renomination);
3543}
3544
3545// Test that if CreateOffer is called with the deprecated "offer to receive
3546// audio/video" constraints, they're processed and result in an offer with
3547// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003548TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003549 CreatePeerConnection();
3550
Niels Möllerf06f9232018-08-07 12:32:18 +02003551 RTCOfferAnswerOptions options;
3552 options.offer_to_receive_audio = 1;
3553 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003554 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003555 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003556
3557 cricket::SessionDescription* desc = offer->description();
3558 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3559 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3560 ASSERT_NE(nullptr, audio);
3561 ASSERT_NE(nullptr, video);
3562 EXPECT_FALSE(audio->rejected);
3563 EXPECT_FALSE(video->rejected);
3564}
3565
3566// Test that if CreateAnswer is called with the deprecated "offer to receive
3567// audio/video" constraints, they're processed and can be used to reject an
3568// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003569// Don't run under Unified Plan since this behavior is not supported.
3570TEST_F(PeerConnectionInterfaceTestPlanB,
3571 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003572 CreatePeerConnection();
3573
3574 // First, create an offer with audio/video and apply it as a remote
3575 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003576 RTCOfferAnswerOptions options;
3577 options.offer_to_receive_audio = 1;
3578 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003579 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003580 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003581 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003582
3583 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003584 options.offer_to_receive_audio = 0;
3585 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003586 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003587 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003588
3589 cricket::SessionDescription* desc = answer->description();
3590 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3591 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3592 ASSERT_NE(nullptr, audio);
3593 ASSERT_NE(nullptr, video);
3594 EXPECT_TRUE(audio->rejected);
3595 EXPECT_TRUE(video->rejected);
3596}
3597
deadbeef1dcb1642017-03-29 21:08:16 -07003598// Test that negotiation can succeed with a data channel only, and with the max
3599// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003600#ifdef HAVE_SCTP
3601TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3602#else
3603TEST_P(PeerConnectionInterfaceTest,
3604 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3605#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003606 PeerConnectionInterface::RTCConfiguration config;
3607 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003608 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003609
3610 // First, create an offer with only a data channel and apply it as a remote
3611 // description.
3612 pc_->CreateDataChannel("test", nullptr);
3613 std::unique_ptr<SessionDescriptionInterface> offer;
3614 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003615 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003616
3617 // Create and set answer as well.
3618 std::unique_ptr<SessionDescriptionInterface> answer;
3619 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003620 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003621}
3622
Steve Anton36da6ff2018-02-16 16:04:20 -08003623TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003624 CreatePeerConnection();
3625 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003626 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003627 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3628}
3629
Steve Anton36da6ff2018-02-16 16:04:20 -08003630TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003631 CreatePeerConnection();
3632 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003633 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003634 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3635}
3636
Steve Anton36da6ff2018-02-16 16:04:20 -08003637TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003638 CreatePeerConnection();
3639 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003640 bitrate.min_bitrate_bps = 5;
3641 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003642 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3643}
3644
Steve Anton36da6ff2018-02-16 16:04:20 -08003645TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003646 CreatePeerConnection();
3647 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003648 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003649 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3650}
3651
Steve Anton36da6ff2018-02-16 16:04:20 -08003652TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003653 CreatePeerConnection();
3654 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003655 bitrate.current_bitrate_bps = 10;
3656 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003657 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3658}
3659
Steve Anton36da6ff2018-02-16 16:04:20 -08003660TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003661 CreatePeerConnection();
3662 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003663 bitrate.min_bitrate_bps = 10;
3664 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003665 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3666}
3667
Steve Anton36da6ff2018-02-16 16:04:20 -08003668TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003669 CreatePeerConnection();
3670 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003671 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003672 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3673}
3674
Steve Anton038834f2017-07-14 15:59:59 -07003675// ice_regather_interval_range requires WebRTC to be configured for continual
3676// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003677TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003678 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3679 PeerConnectionInterface::RTCConfiguration config;
3680 config.ice_regather_interval_range.emplace(1000, 2000);
3681 config.continual_gathering_policy =
3682 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3683 CreatePeerConnectionExpectFail(config);
3684}
3685
3686// Ensures that there is no error when ice_regather_interval_range is set with
3687// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003688TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003689 SetIceRegatherIntervalRangeWithContinualGathering) {
3690 PeerConnectionInterface::RTCConfiguration config;
3691 config.ice_regather_interval_range.emplace(1000, 2000);
3692 config.continual_gathering_policy =
3693 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003694 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003695}
3696
Niels Möller0c4f7be2018-05-07 14:01:37 +02003697// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003698// by Call's BitrateConstraints, which comes from the SDP or a default value.
3699// This test checks that a call to SetBitrate with a current bitrate that will
3700// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003701TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003702 CreatePeerConnection();
3703 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003704 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003705 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3706}
3707
zhihuang1c378ed2017-08-17 14:10:50 -07003708// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003709TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003710 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3711 RTCOfferAnswerOptions rtc_options;
3712
3713 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3714 // than kMaxOfferToReceiveMedia should be treated as invalid.
3715 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3716 CreatePeerConnection();
3717 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3718
3719 rtc_options.offer_to_receive_audio =
3720 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3721 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3722}
3723
Steve Anton36da6ff2018-02-16 16:04:20 -08003724TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003725 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3726 RTCOfferAnswerOptions rtc_options;
3727
3728 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3729 // than kMaxOfferToReceiveMedia should be treated as invalid.
3730 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3731 CreatePeerConnection();
3732 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3733
3734 rtc_options.offer_to_receive_video =
3735 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3736 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3737}
3738
3739// Test that the audio and video content will be added to an offer if both
3740// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003741TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003742 RTCOfferAnswerOptions rtc_options;
3743 rtc_options.offer_to_receive_audio = 1;
3744 rtc_options.offer_to_receive_video = 1;
3745
3746 std::unique_ptr<SessionDescriptionInterface> offer;
3747 CreatePeerConnection();
3748 offer = CreateOfferWithOptions(rtc_options);
3749 ASSERT_TRUE(offer);
3750 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3751 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3752}
3753
3754// Test that only audio content will be added to the offer if only
3755// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003756TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003757 RTCOfferAnswerOptions rtc_options;
3758 rtc_options.offer_to_receive_audio = 1;
3759 rtc_options.offer_to_receive_video = 0;
3760
3761 std::unique_ptr<SessionDescriptionInterface> offer;
3762 CreatePeerConnection();
3763 offer = CreateOfferWithOptions(rtc_options);
3764 ASSERT_TRUE(offer);
3765 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3766 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3767}
3768
3769// Test that only video content will be added if only |offer_to_receive_video|
3770// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003771TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003772 RTCOfferAnswerOptions rtc_options;
3773 rtc_options.offer_to_receive_audio = 0;
3774 rtc_options.offer_to_receive_video = 1;
3775
3776 std::unique_ptr<SessionDescriptionInterface> offer;
3777 CreatePeerConnection();
3778 offer = CreateOfferWithOptions(rtc_options);
3779 ASSERT_TRUE(offer);
3780 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3781 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3782}
3783
zhihuang1c378ed2017-08-17 14:10:50 -07003784// Test that no media content will be added to the offer if using default
3785// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003786TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003787 RTCOfferAnswerOptions rtc_options;
3788
3789 std::unique_ptr<SessionDescriptionInterface> offer;
3790 CreatePeerConnection();
3791 offer = CreateOfferWithOptions(rtc_options);
3792 ASSERT_TRUE(offer);
3793 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3794 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3795}
3796
3797// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3798// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003799TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3800 CreatePeerConnection();
3801
zhihuang1c378ed2017-08-17 14:10:50 -07003802 RTCOfferAnswerOptions rtc_options;
3803 rtc_options.ice_restart = false;
3804 rtc_options.offer_to_receive_audio = 1;
3805
3806 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003807 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003808 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3809 auto ufrag1 =
3810 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3811 auto pwd1 =
3812 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003813
3814 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3815 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003816 auto ufrag2 =
3817 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3818 auto pwd2 =
3819 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003820
3821 // |ice_restart| is true, the ufrag/pwd should change.
3822 rtc_options.ice_restart = true;
3823 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003824 auto ufrag3 =
3825 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3826 auto pwd3 =
3827 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003828
3829 EXPECT_EQ(ufrag1, ufrag2);
3830 EXPECT_EQ(pwd1, pwd2);
3831 EXPECT_NE(ufrag2, ufrag3);
3832 EXPECT_NE(pwd2, pwd3);
3833}
3834
3835// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3836// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003837TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003838 RTCOfferAnswerOptions rtc_options;
3839 rtc_options.offer_to_receive_audio = 1;
3840 rtc_options.offer_to_receive_video = 1;
3841
3842 std::unique_ptr<SessionDescriptionInterface> offer;
3843 CreatePeerConnection();
3844
3845 rtc_options.use_rtp_mux = true;
3846 offer = CreateOfferWithOptions(rtc_options);
3847 ASSERT_TRUE(offer);
3848 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3849 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3850 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3851
3852 rtc_options.use_rtp_mux = false;
3853 offer = CreateOfferWithOptions(rtc_options);
3854 ASSERT_TRUE(offer);
3855 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3856 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3857 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3858}
3859
zhihuang141aacb2017-08-29 13:23:53 -07003860// This test ensures OnRenegotiationNeeded is called when we add track with
3861// MediaStream -> AddTrack in the same way it is called when we add track with
3862// PeerConnection -> AddTrack.
3863// The test can be removed once addStream is rewritten in terms of addTrack
3864// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003865// Don't run under Unified Plan since the stream API is not available.
3866TEST_F(PeerConnectionInterfaceTestPlanB,
3867 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003868 CreatePeerConnectionWithoutDtls();
3869 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003870 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003871 pc_->AddStream(stream);
3872 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003873 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003874 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003875 CreateVideoTrack("video_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003876 stream->AddTrack(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->AddTrack(video_track);
3882 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3883 observer_.renegotiation_needed_ = false;
3884
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003885 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003886 stream->RemoveTrack(audio_track);
3887 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3888 observer_.renegotiation_needed_ = false;
3889
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003890 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003891 stream->RemoveTrack(video_track);
3892 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3893 observer_.renegotiation_needed_ = false;
3894}
3895
Zhi Huangb2d355e2017-10-26 17:26:37 -07003896// Tests that an error is returned if a description is applied that has fewer
3897// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003898TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003899 MediaSectionCountEnforcedForSubsequentOffer) {
3900 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003901 AddAudioTrack("audio_label");
3902 AddVideoTrack("video_label");
3903
Zhi Huangb2d355e2017-10-26 17:26:37 -07003904 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003905 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003906 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3907
3908 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003909 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003910 offer->description()->contents().pop_back();
3911 offer->description()->contents().pop_back();
3912 ASSERT_TRUE(offer->description()->contents().empty());
3913 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3914
3915 std::unique_ptr<SessionDescriptionInterface> answer;
3916 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3917 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3918
3919 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003920 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003921 offer->description()->contents().pop_back();
3922 offer->description()->contents().pop_back();
3923 ASSERT_TRUE(offer->description()->contents().empty());
3924 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3925}
3926
Johannes Kron89f874e2018-11-12 10:25:48 +01003927TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3928 RTCConfiguration config;
3929 // Default behavior is false.
3930 CreatePeerConnection(config);
3931 std::unique_ptr<SessionDescriptionInterface> offer;
3932 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3933 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3934 // Possible to set to true.
3935 config.offer_extmap_allow_mixed = true;
3936 CreatePeerConnection(config);
3937 offer.release();
3938 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3939 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3940}
3941
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003942INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3943 PeerConnectionInterfaceTest,
3944 Values(SdpSemantics::kPlanB,
3945 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003946
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003947class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 02:27:06 -08003948 protected:
3949 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003950 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003951 pcf_->Initialize();
3952 }
nisseeaabdf62017-05-05 02:23:02 -07003953 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003954 const RTCConfiguration& config) {
3955 rtc::scoped_refptr<PeerConnectionInterface> pc(
3956 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003957 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003958 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003959 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003960 }
3961
zhihuang9763d562016-08-05 11:14:50 -07003962 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003963 MockPeerConnectionObserver observer_;
3964};
3965
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003966// This sanity check validates the test infrastructure itself.
3967TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3968 PeerConnectionInterface::RTCConfiguration config;
3969 rtc::scoped_refptr<PeerConnectionInterface> pc(
3970 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3971 EXPECT_TRUE(pc.get());
3972 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3973 pc->Close(); // No abort -> ok.
3974 SUCCEED();
3975}
3976
nisse51542be2016-02-12 02:27:06 -08003977// This test verifies the default behaviour with no constraints and a
3978// default RTCConfiguration.
3979TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3980 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003981
Niels Möllerf06f9232018-08-07 12:32:18 +02003982 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003983
3984 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003985 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3986 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003987 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003988 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003989}
3990
Niels Möller1d7ecd22018-01-18 15:25:12 +01003991// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003992// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003993TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3994 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003995
Niels Möller71bdda02016-03-31 12:59:59 +02003996 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02003997 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003998
Niels Möller1d7ecd22018-01-18 15:25:12 +01003999 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004000}
4001
Niels Möller6539f692018-01-18 08:58:50 +01004002// This test verifies that the experiment_cpu_load_estimator flag is
4003// propagated from RTCConfiguration to the PeerConnection.
4004TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4005 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004006
4007 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004008 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004009
4010 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4011}
4012
deadbeef293e9262017-01-11 12:28:30 -08004013// Tests a few random fields being different.
4014TEST(RTCConfigurationTest, ComparisonOperators) {
4015 PeerConnectionInterface::RTCConfiguration a;
4016 PeerConnectionInterface::RTCConfiguration b;
4017 EXPECT_EQ(a, b);
4018
4019 PeerConnectionInterface::RTCConfiguration c;
4020 c.servers.push_back(PeerConnectionInterface::IceServer());
4021 EXPECT_NE(a, c);
4022
4023 PeerConnectionInterface::RTCConfiguration d;
4024 d.type = PeerConnectionInterface::kRelay;
4025 EXPECT_NE(a, d);
4026
4027 PeerConnectionInterface::RTCConfiguration e;
4028 e.audio_jitter_buffer_max_packets = 5;
4029 EXPECT_NE(a, e);
4030
4031 PeerConnectionInterface::RTCConfiguration f;
4032 f.ice_connection_receiving_timeout = 1337;
4033 EXPECT_NE(a, f);
4034
4035 PeerConnectionInterface::RTCConfiguration g;
4036 g.disable_ipv6 = true;
4037 EXPECT_NE(a, g);
4038
4039 PeerConnectionInterface::RTCConfiguration h(
4040 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4041 EXPECT_NE(a, h);
4042}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01004043
4044} // namespace
4045} // namespace webrtc