blob: e841399a82c187aa3ad44887d98323aeff22def9 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <limits.h>
12#include <stdint.h>
13#include <string.h>
kwibergd1fe2812016-04-27 06:47:29 -070014#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000015#include <string>
kwiberg0eb15ed2015-12-17 03:04:15 -080016#include <utility>
Yves Gerey3e707812018-11-28 16:47:49 +010017#include <vector>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
Karl Wiberg918f50c2018-07-05 11:40:33 +020019#include "absl/memory/memory.h"
Steve Anton1c9c9fc2019-02-14 15:13:09 -080020#include "absl/strings/str_replace.h"
Yves Gerey3e707812018-11-28 16:47:49 +010021#include "absl/types/optional.h"
22#include "api/audio/audio_mixer.h"
23#include "api/audio_codecs/audio_decoder_factory.h"
24#include "api/audio_codecs/audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "api/audio_codecs/builtin_audio_decoder_factory.h"
26#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080027#include "api/call/call_factory_interface.h"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010028#include "api/create_peerconnection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080029#include "api/data_channel_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010030#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080031#include "api/jsep_session_description.h"
32#include "api/media_stream_interface.h"
33#include "api/media_types.h"
34#include "api/peer_connection_interface.h"
35#include "api/rtc_error.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020036#include "api/rtc_event_log/rtc_event_log.h"
37#include "api/rtc_event_log/rtc_event_log_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080038#include "api/rtc_event_log_output.h"
Niels Möllerd8b9ed72019-05-08 13:53:51 +020039#include "api/rtc_event_log_output_file.h"
Steve Anton10542f22019-01-11 09:11:00 -080040#include "api/rtp_receiver_interface.h"
41#include "api/rtp_sender_interface.h"
42#include "api/rtp_transceiver_interface.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010043#include "api/scoped_refptr.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020044#include "api/task_queue/default_task_queue_factory.h"
Anders Carlsson67537952018-05-03 11:28:29 +020045#include "api/video_codecs/builtin_video_decoder_factory.h"
46#include "api/video_codecs/builtin_video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010047#include "api/video_codecs/video_decoder_factory.h"
48#include "api/video_codecs/video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010049#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080050#include "media/base/media_config.h"
51#include "media/base/media_engine.h"
52#include "media/base/stream_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080053#include "media/engine/webrtc_media_engine.h"
Danil Chapovalov9da25bd2019-06-20 10:19:42 +020054#include "media/engine/webrtc_media_engine_defaults.h"
Steve Anton10542f22019-01-11 09:11:00 -080055#include "media/sctp/sctp_transport_internal.h"
Yves Gerey3e707812018-11-28 16:47:49 +010056#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020057#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080058#include "p2p/base/fake_port_allocator.h"
59#include "p2p/base/p2p_constants.h"
Yves Gerey3e707812018-11-28 16:47:49 +010060#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080061#include "p2p/base/port_allocator.h"
62#include "p2p/base/transport_description.h"
63#include "p2p/base/transport_info.h"
64#include "pc/audio_track.h"
65#include "pc/media_session.h"
66#include "pc/media_stream.h"
67#include "pc/peer_connection.h"
68#include "pc/peer_connection_factory.h"
69#include "pc/rtc_stats_collector.h"
70#include "pc/rtp_sender.h"
71#include "pc/session_description.h"
72#include "pc/stream_collection.h"
73#include "pc/test/fake_audio_capture_module.h"
74#include "pc/test/fake_rtc_certificate_generator.h"
75#include "pc/test/fake_video_track_source.h"
76#include "pc/test/mock_peer_connection_observers.h"
77#include "pc/test/test_sdp_strings.h"
78#include "pc/video_track.h"
Yves Gerey3e707812018-11-28 16:47:49 +010079#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080080#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020081#include "rtc_base/gunit.h"
Steve Anton10542f22019-01-11 09:11:00 -080082#include "rtc_base/ref_counted_object.h"
83#include "rtc_base/rtc_certificate_generator.h"
Steve Anton10542f22019-01-11 09:11:00 -080084#include "rtc_base/socket_address.h"
Yves Gerey3e707812018-11-28 16:47:49 +010085#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080086#include "rtc_base/time_utils.h"
87#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020088#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010089#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080090#include "test/testsupport/file_utils.h"
kwibergac9f8762016-09-30 22:29:43 -070091
92#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080093#include "pc/test/android_test_initializer.h"
kwibergac9f8762016-09-30 22:29:43 -070094#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010096namespace webrtc {
97namespace {
98
Seth Hampson845e8782018-03-02 11:34:10 -080099static const char kStreamId1[] = "local_stream_1";
100static const char kStreamId2[] = "local_stream_2";
101static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102static const int kDefaultStunPort = 3478;
103static const char kStunAddressOnly[] = "stun:address";
104static const char kStunInvalidPort[] = "stun:address:-1";
105static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
106static const char kStunAddressPortAndMore2[] = "stun:address:port more";
Niels Möllerdb4def92019-03-18 16:53:59 +0100107static const char kTurnIceServerUri[] = "turn:turn.example.org";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108static const char kTurnUsername[] = "user";
109static const char kTurnPassword[] = "password";
110static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200111static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112
deadbeefab9b2d12015-10-14 11:33:11 -0700113static const char kStreams[][8] = {"stream1", "stream2"};
114static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
115static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
116
deadbeef5e97fb52015-10-15 12:49:08 -0700117static const char kRecvonly[] = "recvonly";
118static const char kSendrecv[] = "sendrecv";
119
deadbeefab9b2d12015-10-14 11:33:11 -0700120// Reference SDP with a MediaStream with label "stream1" and audio track with
121// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800122static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700123 "v=0\r\n"
124 "o=- 0 0 IN IP4 127.0.0.1\r\n"
125 "s=-\r\n"
126 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800127 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700128 "a=ice-ufrag:e5785931\r\n"
129 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
130 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
131 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700132 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700133 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800134 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700135 "a=rtpmap:103 ISAC/16000\r\n"
136 "a=ssrc:1 cname:stream1\r\n"
137 "a=ssrc:1 mslabel:stream1\r\n"
138 "a=ssrc:1 label:audiotrack0\r\n"
139 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800140 "a=ice-ufrag:e5785931\r\n"
141 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
142 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
143 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700144 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700145 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800146 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700147 "a=rtpmap:120 VP8/90000\r\n"
148 "a=ssrc:2 cname:stream1\r\n"
149 "a=ssrc:2 mslabel:stream1\r\n"
150 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800151// Same string as above but with the MID changed to the Unified Plan default.
152// This is needed so that this SDP can be used as an answer for a Unified Plan
153// offer.
154static const char kSdpStringWithStream1UnifiedPlan[] =
155 "v=0\r\n"
156 "o=- 0 0 IN IP4 127.0.0.1\r\n"
157 "s=-\r\n"
158 "t=0 0\r\n"
159 "m=audio 1 RTP/AVPF 103\r\n"
160 "a=ice-ufrag:e5785931\r\n"
161 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
162 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
163 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
164 "a=mid:0\r\n"
165 "a=sendrecv\r\n"
166 "a=rtcp-mux\r\n"
167 "a=rtpmap:103 ISAC/16000\r\n"
168 "a=ssrc:1 cname:stream1\r\n"
169 "a=ssrc:1 mslabel:stream1\r\n"
170 "a=ssrc:1 label:audiotrack0\r\n"
171 "m=video 1 RTP/AVPF 120\r\n"
172 "a=ice-ufrag:e5785931\r\n"
173 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
174 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
175 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
176 "a=mid:1\r\n"
177 "a=sendrecv\r\n"
178 "a=rtcp-mux\r\n"
179 "a=rtpmap:120 VP8/90000\r\n"
180 "a=ssrc:2 cname:stream1\r\n"
181 "a=ssrc:2 mslabel:stream1\r\n"
182 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700183
zhihuang81c3a032016-11-17 12:06:24 -0800184// Reference SDP with a MediaStream with label "stream1" and audio track with
185// id "audio_1";
186static const char kSdpStringWithStream1AudioTrackOnly[] =
187 "v=0\r\n"
188 "o=- 0 0 IN IP4 127.0.0.1\r\n"
189 "s=-\r\n"
190 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800191 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800192 "a=ice-ufrag:e5785931\r\n"
193 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
194 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
195 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800196 "a=mid:audio\r\n"
197 "a=sendrecv\r\n"
198 "a=rtpmap:103 ISAC/16000\r\n"
199 "a=ssrc:1 cname:stream1\r\n"
200 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800201 "a=ssrc:1 label:audiotrack0\r\n"
202 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800203
deadbeefab9b2d12015-10-14 11:33:11 -0700204// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
205// MediaStreams have one audio track and one video track.
206// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800207static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700208 "v=0\r\n"
209 "o=- 0 0 IN IP4 127.0.0.1\r\n"
210 "s=-\r\n"
211 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800212 "a=msid-semantic: WMS stream1 stream2\r\n"
213 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700214 "a=ice-ufrag:e5785931\r\n"
215 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
216 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
217 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700218 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700219 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800220 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700221 "a=rtpmap:103 ISAC/16000\r\n"
222 "a=ssrc:1 cname:stream1\r\n"
223 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
224 "a=ssrc:3 cname:stream2\r\n"
225 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
226 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800227 "a=ice-ufrag:e5785931\r\n"
228 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
229 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
230 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700231 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700232 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800233 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700234 "a=rtpmap:120 VP8/0\r\n"
235 "a=ssrc:2 cname:stream1\r\n"
236 "a=ssrc:2 msid:stream1 videotrack0\r\n"
237 "a=ssrc:4 cname:stream2\r\n"
238 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800239static const char kSdpStringWithStream1And2UnifiedPlan[] =
240 "v=0\r\n"
241 "o=- 0 0 IN IP4 127.0.0.1\r\n"
242 "s=-\r\n"
243 "t=0 0\r\n"
244 "a=msid-semantic: WMS stream1 stream2\r\n"
245 "m=audio 1 RTP/AVPF 103\r\n"
246 "a=ice-ufrag:e5785931\r\n"
247 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
248 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
249 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
250 "a=mid:0\r\n"
251 "a=sendrecv\r\n"
252 "a=rtcp-mux\r\n"
253 "a=rtpmap:103 ISAC/16000\r\n"
254 "a=ssrc:1 cname:stream1\r\n"
255 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
256 "m=video 1 RTP/AVPF 120\r\n"
257 "a=ice-ufrag:e5785931\r\n"
258 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
259 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
260 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
261 "a=mid:1\r\n"
262 "a=sendrecv\r\n"
263 "a=rtcp-mux\r\n"
264 "a=rtpmap:120 VP8/0\r\n"
265 "a=ssrc:2 cname:stream1\r\n"
266 "a=ssrc:2 msid:stream1 videotrack0\r\n"
267 "m=audio 1 RTP/AVPF 103\r\n"
268 "a=ice-ufrag:e5785931\r\n"
269 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
270 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
271 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
272 "a=mid:2\r\n"
273 "a=sendrecv\r\n"
274 "a=rtcp-mux\r\n"
275 "a=rtpmap:103 ISAC/16000\r\n"
276 "a=ssrc:3 cname:stream2\r\n"
277 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
278 "m=video 1 RTP/AVPF 120\r\n"
279 "a=ice-ufrag:e5785931\r\n"
280 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
281 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
282 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
283 "a=mid:3\r\n"
284 "a=sendrecv\r\n"
285 "a=rtcp-mux\r\n"
286 "a=rtpmap:120 VP8/0\r\n"
287 "a=ssrc:4 cname:stream2\r\n"
288 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700289
290// Reference SDP without MediaStreams. Msid is not supported.
291static const char kSdpStringWithoutStreams[] =
292 "v=0\r\n"
293 "o=- 0 0 IN IP4 127.0.0.1\r\n"
294 "s=-\r\n"
295 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800296 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700297 "a=ice-ufrag:e5785931\r\n"
298 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
299 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
300 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700301 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700302 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800303 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700304 "a=rtpmap:103 ISAC/16000\r\n"
305 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800306 "a=ice-ufrag:e5785931\r\n"
307 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
308 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
309 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700310 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700311 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800312 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700313 "a=rtpmap:120 VP8/90000\r\n";
314
315// Reference SDP without MediaStreams. Msid is supported.
316static const char kSdpStringWithMsidWithoutStreams[] =
317 "v=0\r\n"
318 "o=- 0 0 IN IP4 127.0.0.1\r\n"
319 "s=-\r\n"
320 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800321 "a=msid-semantic: WMS\r\n"
322 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700323 "a=ice-ufrag:e5785931\r\n"
324 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
325 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
326 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700327 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700328 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800329 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700330 "a=rtpmap:103 ISAC/16000\r\n"
331 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800332 "a=ice-ufrag:e5785931\r\n"
333 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
334 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
335 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700336 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700337 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800338 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700339 "a=rtpmap:120 VP8/90000\r\n";
340
341// Reference SDP without MediaStreams and audio only.
342static const char kSdpStringWithoutStreamsAudioOnly[] =
343 "v=0\r\n"
344 "o=- 0 0 IN IP4 127.0.0.1\r\n"
345 "s=-\r\n"
346 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800347 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700348 "a=ice-ufrag:e5785931\r\n"
349 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
350 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
351 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700352 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700353 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800354 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700355 "a=rtpmap:103 ISAC/16000\r\n";
356
357// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
358static const char kSdpStringSendOnlyWithoutStreams[] =
359 "v=0\r\n"
360 "o=- 0 0 IN IP4 127.0.0.1\r\n"
361 "s=-\r\n"
362 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800363 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700364 "a=ice-ufrag:e5785931\r\n"
365 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
366 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
367 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700368 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700369 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700370 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800371 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700372 "a=rtpmap:103 ISAC/16000\r\n"
373 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800374 "a=ice-ufrag:e5785931\r\n"
375 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
376 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
377 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700378 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700379 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700380 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800381 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700382 "a=rtpmap:120 VP8/90000\r\n";
383
384static const char kSdpStringInit[] =
385 "v=0\r\n"
386 "o=- 0 0 IN IP4 127.0.0.1\r\n"
387 "s=-\r\n"
388 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700389 "a=msid-semantic: WMS\r\n";
390
391static const char kSdpStringAudio[] =
392 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800393 "a=ice-ufrag:e5785931\r\n"
394 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
395 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
396 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700397 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700398 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800399 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700400 "a=rtpmap:103 ISAC/16000\r\n";
401
402static const char kSdpStringVideo[] =
403 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800404 "a=ice-ufrag:e5785931\r\n"
405 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
406 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
407 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700408 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700409 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800410 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700411 "a=rtpmap:120 VP8/90000\r\n";
412
413static const char kSdpStringMs1Audio0[] =
414 "a=ssrc:1 cname:stream1\r\n"
415 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
416
417static const char kSdpStringMs1Video0[] =
418 "a=ssrc:2 cname:stream1\r\n"
419 "a=ssrc:2 msid:stream1 videotrack0\r\n";
420
421static const char kSdpStringMs1Audio1[] =
422 "a=ssrc:3 cname:stream1\r\n"
423 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
424
425static const char kSdpStringMs1Video1[] =
426 "a=ssrc:4 cname:stream1\r\n"
427 "a=ssrc:4 msid:stream1 videotrack1\r\n";
428
deadbeef8662f942017-01-20 21:20:51 -0800429static const char kDtlsSdesFallbackSdp[] =
430 "v=0\r\n"
431 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
432 "s=-\r\n"
433 "c=IN IP4 0.0.0.0\r\n"
434 "t=0 0\r\n"
435 "a=group:BUNDLE audio\r\n"
436 "a=msid-semantic: WMS\r\n"
437 "m=audio 1 RTP/SAVPF 0\r\n"
438 "a=sendrecv\r\n"
439 "a=rtcp-mux\r\n"
440 "a=mid:audio\r\n"
441 "a=ssrc:1 cname:stream1\r\n"
442 "a=ssrc:1 mslabel:stream1\r\n"
443 "a=ssrc:1 label:audiotrack0\r\n"
444 "a=ice-ufrag:e5785931\r\n"
445 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
446 "a=rtpmap:0 pcmu/8000\r\n"
447 "a=fingerprint:sha-1 "
448 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
449 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700450 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800451 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
452 "dummy_session_params\r\n";
453
Niels Möllerdec9f742019-06-03 15:25:20 +0200454class RtcEventLogOutputNull final : public RtcEventLogOutput {
455 public:
456 bool IsActive() const override { return true; }
457 bool Write(const std::string& output) override { return true; }
458};
459
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100460using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700461using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800462using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463
Steve Anton36da6ff2018-02-16 16:04:20 -0800464using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
465using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700466
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467// Gets the first ssrc of given content type from the ContentInfo.
468bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
469 if (!content_info || !ssrc) {
470 return false;
471 }
472 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800473 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 if (!media_desc || media_desc->streams().empty()) {
475 return false;
476 }
477 *ssrc = media_desc->streams().begin()->first_ssrc();
478 return true;
479}
480
deadbeefd1a38b52016-12-10 13:15:33 -0800481// Get the ufrags out of an SDP blob. Useful for testing ICE restart
482// behavior.
483std::vector<std::string> GetUfrags(
484 const webrtc::SessionDescriptionInterface* desc) {
485 std::vector<std::string> ufrags;
486 for (const cricket::TransportInfo& info :
487 desc->description()->transport_infos()) {
488 ufrags.push_back(info.description.ice_ufrag);
489 }
490 return ufrags;
491}
492
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493void SetSsrcToZero(std::string* sdp) {
494 const char kSdpSsrcAtribute[] = "a=ssrc:";
495 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
496 size_t ssrc_pos = 0;
497 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200498 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 size_t end_ssrc = sdp->find(" ", ssrc_pos);
500 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
501 ssrc_pos = end_ssrc;
502 }
503}
504
deadbeefab9b2d12015-10-14 11:33:11 -0700505// Check if |streams| contains the specified track.
506bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800507 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700508 const std::string& track_id) {
509 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800510 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700511 return true;
512 }
513 }
514 return false;
515}
516
517// Check if |senders| contains the specified sender, by id.
518bool ContainsSender(
519 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
520 const std::string& id) {
521 for (const auto& sender : senders) {
522 if (sender->id() == id) {
523 return true;
524 }
525 }
526 return false;
527}
528
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700529// Check if |senders| contains the specified sender, by id and stream id.
530bool ContainsSender(
531 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
532 const std::string& id,
533 const std::string& stream_id) {
534 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700535 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700536 return true;
537 }
538 }
539 return false;
540}
541
deadbeefab9b2d12015-10-14 11:33:11 -0700542// Create a collection of streams.
543// CreateStreamCollection(1) creates a collection that
544// correspond to kSdpStringWithStream1.
545// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
546rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700547 int number_of_streams,
548 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700549 rtc::scoped_refptr<StreamCollection> local_collection(
550 StreamCollection::Create());
551
552 for (int i = 0; i < number_of_streams; ++i) {
553 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
554 webrtc::MediaStream::Create(kStreams[i]));
555
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700556 for (int j = 0; j < tracks_per_stream; ++j) {
557 // Add a local audio track.
558 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
559 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
560 nullptr));
561 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700562
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700563 // Add a local video track.
564 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
565 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700566 webrtc::FakeVideoTrackSource::Create(),
567 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700568 stream->AddTrack(video_track);
569 }
deadbeefab9b2d12015-10-14 11:33:11 -0700570
571 local_collection->AddStream(stream);
572 }
573 return local_collection;
574}
575
576// Check equality of StreamCollections.
577bool CompareStreamCollections(StreamCollectionInterface* s1,
578 StreamCollectionInterface* s2) {
579 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
580 return false;
581 }
582
583 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700584 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700585 return false;
586 }
587 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
588 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
589 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
590 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
591
592 if (audio_tracks1.size() != audio_tracks2.size()) {
593 return false;
594 }
595 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
596 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
597 return false;
598 }
599 }
600 if (video_tracks1.size() != video_tracks2.size()) {
601 return false;
602 }
603 for (size_t j = 0; j != video_tracks1.size(); ++j) {
604 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
605 return false;
606 }
607 }
608 }
609 return true;
610}
611
perkjd61bf802016-03-24 03:16:19 -0700612// Helper class to test Observer.
613class MockTrackObserver : public ObserverInterface {
614 public:
615 explicit MockTrackObserver(NotifierInterface* notifier)
616 : notifier_(notifier) {
617 notifier_->RegisterObserver(this);
618 }
619
620 ~MockTrackObserver() { Unregister(); }
621
622 void Unregister() {
623 if (notifier_) {
624 notifier_->UnregisterObserver(this);
625 notifier_ = nullptr;
626 }
627 }
628
629 MOCK_METHOD0(OnChanged, void());
630
631 private:
632 NotifierInterface* notifier_;
633};
634
nisse528b7932017-05-08 03:21:43 -0700635// The PeerConnectionMediaConfig tests below verify that configuration and
636// constraints are propagated into the PeerConnection's MediaConfig. These
637// settings are intended for MediaChannel constructors, but that is not
638// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700639class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
640 public:
zhihuang38ede132017-06-15 12:52:32 -0700641 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
642 CreatePeerConnectionFactoryForTest() {
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100643 PeerConnectionFactoryDependencies dependencies;
644 dependencies.worker_thread = rtc::Thread::Current();
645 dependencies.network_thread = rtc::Thread::Current();
646 dependencies.signaling_thread = rtc::Thread::Current();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200647 dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
648 cricket::MediaEngineDependencies media_deps;
649 media_deps.task_queue_factory = dependencies.task_queue_factory.get();
henrika919dc2e2017-10-12 14:24:55 +0200650 // Use fake audio device module since we're only testing the interface
651 // level, and using a real one could make tests flaky when run in parallel.
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200652 media_deps.adm = FakeAudioCaptureModule::Create();
653 SetMediaEngineDefaults(&media_deps);
654 dependencies.media_engine =
655 cricket::CreateMediaEngine(std::move(media_deps));
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100656 dependencies.call_factory = webrtc::CreateCallFactory();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200657 dependencies.event_log_factory = absl::make_unique<RtcEventLogFactory>(
658 dependencies.task_queue_factory.get());
zhihuang38ede132017-06-15 12:52:32 -0700659
660 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100661 std::move(dependencies));
zhihuang38ede132017-06-15 12:52:32 -0700662 }
663
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100664 using PeerConnectionFactory::PeerConnectionFactory;
kwiberg1e4e8cb2017-01-31 01:48:08 -0800665
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100666 private:
deadbeefd7850b22017-08-23 10:59:19 -0700667 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700668};
669
Steve Anton36da6ff2018-02-16 16:04:20 -0800670// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200671class PeerConnectionInterfaceBaseTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800673 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
674 : vss_(new rtc::VirtualSocketServer()),
675 main_(vss_.get()),
676 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800677#ifdef WEBRTC_ANDROID
678 webrtc::InitializeAndroidObjects();
679#endif
680 }
681
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700683 // Use fake audio capture module since we're only testing the interface
684 // level, and using a real one could make tests flaky when run in parallel.
685 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700687 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200688 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
689 fake_audio_capture_module_),
690 webrtc::CreateBuiltinAudioEncoderFactory(),
691 webrtc::CreateBuiltinAudioDecoderFactory(),
692 webrtc::CreateBuiltinVideoEncoderFactory(),
693 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
694 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700695 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700696 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700697 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700698 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 }
700
701 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200702 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 }
704
deadbeef293e9262017-01-11 12:28:30 -0800705 // DTLS does not work in a loopback call, so is disabled for most of the
706 // tests in this file.
707 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200708 RTCConfiguration config;
709 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800710
Niels Möllerf06f9232018-08-07 12:32:18 +0200711 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 }
713
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700714 void CreatePeerConnectionWithIceTransportsType(
715 PeerConnectionInterface::IceTransportsType type) {
716 PeerConnectionInterface::RTCConfiguration config;
717 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200718 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700719 }
720
721 void CreatePeerConnectionWithIceServer(const std::string& uri,
Niels Möllerdb4def92019-03-18 16:53:59 +0100722 const std::string& username,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700723 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800724 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700726 server.uri = uri;
Niels Möllerdb4def92019-03-18 16:53:59 +0100727 server.username = username;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700728 server.password = password;
729 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200730 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700731 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732
Niels Möllerf06f9232018-08-07 12:32:18 +0200733 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700734 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800735 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
736 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000737
deadbeef1dcb1642017-03-29 21:08:16 -0700738 // Create certificate generator unless DTLS constraint is explicitly set to
739 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200740 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200741
742 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800743 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
744 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000745 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800746 RTCConfiguration modified_config = config;
747 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200748 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200749 modified_config, std::move(port_allocator), std::move(cert_generator),
750 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 ASSERT_TRUE(pc_.get() != NULL);
752 observer_.SetPeerConnectionInterface(pc_.get());
753 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
754 }
755
deadbeef0a6c4ca2015-10-06 11:38:28 -0700756 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800757 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700758 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700759 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800760 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800761 config.sdp_semantics = sdp_semantics_;
762 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200763 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800764 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700765 }
766
Steve Anton038834f2017-07-14 15:59:59 -0700767 void CreatePeerConnectionExpectFail(
768 PeerConnectionInterface::RTCConfiguration config) {
769 PeerConnectionInterface::IceServer server;
770 server.uri = kTurnIceServerUri;
771 server.password = kTurnPassword;
772 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800773 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700774 rtc::scoped_refptr<PeerConnectionInterface> pc =
775 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
776 EXPECT_EQ(nullptr, pc);
777 }
778
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 16:53:59 +0100780 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800781 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
782 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
783 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800785 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786
deadbeef0a6c4ca2015-10-06 11:38:28 -0700787 CreatePeerConnectionExpectFail(kStunInvalidPort);
788 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
789 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790
Niels Möllerdb4def92019-03-18 16:53:59 +0100791 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
792 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800793 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
794 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800796 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800798 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800800 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 }
802
803 void ReleasePeerConnection() {
804 pc_ = NULL;
805 observer_.SetPeerConnectionInterface(NULL);
806 }
807
Steve Anton36da6ff2018-02-16 16:04:20 -0800808 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
809 const std::string& label) {
Niels Möller215ba602019-01-18 13:59:45 +0100810 return pc_factory_->CreateVideoTrack(label, FakeVideoTrackSource::Create());
Steve Anton36da6ff2018-02-16 16:04:20 -0800811 }
812
813 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800814 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800815 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800816 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800817 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 }
819
Steve Anton36da6ff2018-02-16 16:04:20 -0800820 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700821 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800823 stream->AddTrack(CreateVideoTrack(label + "v0"));
824 ASSERT_TRUE(pc_->AddStream(stream));
Steve Anton36da6ff2018-02-16 16:04:20 -0800825 }
826
827 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
828 const std::string& label) {
829 return pc_factory_->CreateAudioTrack(label, nullptr);
830 }
831
832 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800833 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800834 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800835 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800836 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-16 16:04:20 -0800837 }
838
839 void AddAudioStream(const std::string& label) {
840 rtc::scoped_refptr<MediaStreamInterface> stream(
841 pc_factory_->CreateLocalMediaStream(label));
842 stream->AddTrack(CreateAudioTrack(label + "a0"));
843 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 }
845
Seth Hampson845e8782018-03-02 11:34:10 -0800846 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 const std::string& audio_track_label,
848 const std::string& video_track_label) {
849 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700850 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800851 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800852 stream->AddTrack(CreateAudioTrack(audio_track_label));
853 stream->AddTrack(CreateVideoTrack(video_track_label));
854 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 }
856
Steve Anton36da6ff2018-02-16 16:04:20 -0800857 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
858 cricket::MediaType media_type) {
859 for (auto receiver : pc_->GetReceivers()) {
860 if (receiver->media_type() == media_type) {
861 return receiver;
862 }
863 }
864 return nullptr;
865 }
866
kwibergd1fe2812016-04-27 06:47:29 -0700867 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200868 const RTCOfferAnswerOptions* options,
869 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200870 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
871 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200873 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200875 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 }
877 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700878 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 return observer->result();
880 }
881
kwibergd1fe2812016-04-27 06:47:29 -0700882 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200883 const RTCOfferAnswerOptions* options) {
884 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 }
886
kwibergd1fe2812016-04-27 06:47:29 -0700887 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200888 const RTCOfferAnswerOptions* options) {
889 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 }
891
Steve Antondb45ca82017-09-11 18:27:34 -0700892 bool DoSetSessionDescription(
893 std::unique_ptr<SessionDescriptionInterface> desc,
894 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200895 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
896 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700898 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700900 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 }
zhihuang29ff8442016-07-27 11:07:25 -0700902 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
903 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
904 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 return observer->result();
906 }
907
Steve Antondb45ca82017-09-11 18:27:34 -0700908 bool DoSetLocalDescription(
909 std::unique_ptr<SessionDescriptionInterface> desc) {
910 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 }
912
Steve Antondb45ca82017-09-11 18:27:34 -0700913 bool DoSetRemoteDescription(
914 std::unique_ptr<SessionDescriptionInterface> desc) {
915 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 }
917
918 // Calls PeerConnection::GetStats and check the return value.
919 // It does not verify the values in the StatReports since a RTCP packet might
920 // be required.
921 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000922 rtc::scoped_refptr<MockStatsObserver> observer(
923 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200924 if (!pc_->GetStats(observer, track,
925 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 return false;
927 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
928 return observer->called();
929 }
930
Harald Alvestrand89061872018-01-02 14:08:34 +0100931 // Call the standards-compliant GetStats function.
932 bool DoGetRTCStats() {
933 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
934 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
935 pc_->GetStats(callback);
936 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
937 return callback->called();
938 }
939
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800941 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800943 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800944 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800945 } else {
946 // Unified Plan does not support AddStream, so just add an audio and video
947 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800948 AddAudioTrack(kAudioTracks[0], {kStreamId1});
949 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800950 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 CreateOfferReceiveAnswer();
952 }
953
954 // Verify that RTP Header extensions has been negotiated for audio and video.
955 void VerifyRemoteRtpHeaderExtensions() {
956 const cricket::MediaContentDescription* desc =
957 cricket::GetFirstAudioContentDescription(
958 pc_->remote_description()->description());
959 ASSERT_TRUE(desc != NULL);
960 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
961
962 desc = cricket::GetFirstVideoContentDescription(
963 pc_->remote_description()->description());
964 ASSERT_TRUE(desc != NULL);
965 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
966 }
967
968 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700969 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700970 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 std::string sdp;
972 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700973 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800974 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700975 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
977 }
978
deadbeefab9b2d12015-10-14 11:33:11 -0700979 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700980 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800981 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700982 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700983 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
984 }
985
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700987 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700988 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989
990 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
991 // audio codec change, even if the parameter has nothing to do with
992 // receiving. Not all parameters are serialized to SDP.
993 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
994 // the SessionDescription, it is necessary to do that here to in order to
995 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
996 // https://code.google.com/p/webrtc/issues/detail?id=1356
997 std::string sdp;
998 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700999 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001000 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001001 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1003 }
1004
1005 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001006 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001007 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008
1009 std::string sdp;
1010 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001011 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001012 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001013 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1015 }
1016
1017 void CreateOfferReceiveAnswer() {
1018 CreateOfferAsLocalDescription();
1019 std::string sdp;
1020 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1021 CreateAnswerAsRemoteDescription(sdp);
1022 }
1023
1024 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001025 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001026 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1028 // audio codec change, even if the parameter has nothing to do with
1029 // receiving. Not all parameters are serialized to SDP.
1030 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1031 // the SessionDescription, it is necessary to do that here to in order to
1032 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1033 // https://code.google.com/p/webrtc/issues/detail?id=1356
1034 std::string sdp;
1035 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001036 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001037 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038
Steve Antondb45ca82017-09-11 18:27:34 -07001039 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001041 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001042 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043 }
1044
deadbeefab9b2d12015-10-14 11:33:11 -07001045 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001046 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001047 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001048 ASSERT_TRUE(answer);
1049 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1051 }
1052
deadbeefab9b2d12015-10-14 11:33:11 -07001053 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001054 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001055 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001056 ASSERT_TRUE(pr_answer);
1057 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001059 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001060 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001061 ASSERT_TRUE(answer);
1062 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1064 }
1065
Seth Hampson845e8782018-03-02 11:34:10 -08001066 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001067 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001068 // called with the given stream id and expected number of tracks.
1069 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001070 int expected_num_tracks) {
1071 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001072 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001073 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001074 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 }
1076
1077 // Creates an offer and applies it as a local session description.
1078 // Creates an answer with the same SDP an the offer but removes all lines
1079 // that start with a:ssrc"
1080 void CreateOfferReceiveAnswerWithoutSsrc() {
1081 CreateOfferAsLocalDescription();
1082 std::string sdp;
1083 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1084 SetSsrcToZero(&sdp);
1085 CreateAnswerAsRemoteDescription(sdp);
1086 }
1087
deadbeefab9b2d12015-10-14 11:33:11 -07001088 // This function creates a MediaStream with label kStreams[0] and
1089 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1090 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001091 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001092 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001093 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001094 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1095 size_t number_of_video_tracks) {
1096 EXPECT_LE(number_of_audio_tracks, 2u);
1097 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001098
1099 reference_collection_ = StreamCollection::Create();
1100 std::string sdp_ms1 = std::string(kSdpStringInit);
1101
Seth Hampson845e8782018-03-02 11:34:10 -08001102 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001103
1104 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001105 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001106 reference_collection_->AddStream(stream);
1107
1108 if (number_of_audio_tracks > 0) {
1109 sdp_ms1 += std::string(kSdpStringAudio);
1110 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1111 AddAudioTrack(kAudioTracks[0], stream);
1112 }
1113 if (number_of_audio_tracks > 1) {
1114 sdp_ms1 += kSdpStringMs1Audio1;
1115 AddAudioTrack(kAudioTracks[1], stream);
1116 }
1117
1118 if (number_of_video_tracks > 0) {
1119 sdp_ms1 += std::string(kSdpStringVideo);
1120 sdp_ms1 += std::string(kSdpStringMs1Video0);
1121 AddVideoTrack(kVideoTracks[0], stream);
1122 }
1123 if (number_of_video_tracks > 1) {
1124 sdp_ms1 += kSdpStringMs1Video1;
1125 AddVideoTrack(kVideoTracks[1], stream);
1126 }
1127
kwibergd1fe2812016-04-27 06:47:29 -07001128 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001129 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001130 }
1131
1132 void AddAudioTrack(const std::string& track_id,
1133 MediaStreamInterface* stream) {
1134 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1135 webrtc::AudioTrack::Create(track_id, nullptr));
1136 ASSERT_TRUE(stream->AddTrack(audio_track));
1137 }
1138
1139 void AddVideoTrack(const std::string& track_id,
1140 MediaStreamInterface* stream) {
1141 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001142 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001143 webrtc::FakeVideoTrackSource::Create(),
1144 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001145 ASSERT_TRUE(stream->AddTrack(video_track));
1146 }
1147
Steve Anton36da6ff2018-02-16 16:04:20 -08001148 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001149 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001150 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001151 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001152 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1153 return offer;
1154 }
1155
Steve Anton36da6ff2018-02-16 16:04:20 -08001156 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1157 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001158 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001159 std::unique_ptr<SessionDescriptionInterface> offer;
1160 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1161 return offer;
1162 }
1163
1164 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1165 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1166 std::unique_ptr<SessionDescriptionInterface> answer;
1167 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1168 return answer;
1169 }
1170
kwibergfd8be342016-05-14 19:44:11 -07001171 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001172 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001173 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001174 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001175 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1176 return answer;
1177 }
1178
1179 const std::string& GetFirstAudioStreamCname(
1180 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001181 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001182 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001183 return audio_desc->streams()[0].cname;
1184 }
1185
zhihuang1c378ed2017-08-17 14:10:50 -07001186 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1187 const RTCOfferAnswerOptions& offer_answer_options) {
1188 RTC_DCHECK(pc_);
1189 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1190 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1191 pc_->CreateOffer(observer, offer_answer_options);
1192 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1193 return observer->MoveDescription();
1194 }
1195
1196 void CreateOfferWithOptionsAsRemoteDescription(
1197 std::unique_ptr<SessionDescriptionInterface>* desc,
1198 const RTCOfferAnswerOptions& offer_answer_options) {
1199 *desc = CreateOfferWithOptions(offer_answer_options);
1200 ASSERT_TRUE(desc != nullptr);
1201 std::string sdp;
1202 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001203 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001204 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001205 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001206 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1207 }
1208
1209 void CreateOfferWithOptionsAsLocalDescription(
1210 std::unique_ptr<SessionDescriptionInterface>* desc,
1211 const RTCOfferAnswerOptions& offer_answer_options) {
1212 *desc = CreateOfferWithOptions(offer_answer_options);
1213 ASSERT_TRUE(desc != nullptr);
1214 std::string sdp;
1215 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001216 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001217 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001218
Steve Antondb45ca82017-09-11 18:27:34 -07001219 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001220 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1221 }
1222
1223 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001224 RTC_DCHECK(content);
1225 RTC_DCHECK(content->media_description());
1226 for (const cricket::AudioCodec& codec :
1227 content->media_description()->as_audio()->codecs()) {
1228 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001229 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001230 }
zhihuang1c378ed2017-08-17 14:10:50 -07001231 }
1232 return false;
1233 }
1234
Steve Anton36da6ff2018-02-16 16:04:20 -08001235 const char* GetSdpStringWithStream1() const {
1236 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1237 return kSdpStringWithStream1PlanB;
1238 } else {
1239 return kSdpStringWithStream1UnifiedPlan;
1240 }
1241 }
1242
1243 const char* GetSdpStringWithStream1And2() const {
1244 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1245 return kSdpStringWithStream1And2PlanB;
1246 } else {
1247 return kSdpStringWithStream1And2UnifiedPlan;
1248 }
1249 }
1250
deadbeef9a6f4d42017-05-15 19:43:33 -07001251 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1252 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001253 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001254 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001255 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001256 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1257 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1258 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001260 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001261 const SdpSemantics sdp_semantics_;
1262};
1263
1264class PeerConnectionInterfaceTest
1265 : public PeerConnectionInterfaceBaseTest,
1266 public ::testing::WithParamInterface<SdpSemantics> {
1267 protected:
1268 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1269};
1270
1271class PeerConnectionInterfaceTestPlanB
1272 : public PeerConnectionInterfaceBaseTest {
1273 protected:
1274 PeerConnectionInterfaceTestPlanB()
1275 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276};
1277
zhihuang8f65cdf2016-05-06 18:40:30 -07001278// Generate different CNAMEs when PeerConnections are created.
1279// The CNAMEs are expected to be generated randomly. It is possible
1280// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001281TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001282 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001283 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001284 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001285 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001286 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1287 GetFirstAudioStreamCname(offer2.get()));
1288}
1289
Steve Anton36da6ff2018-02-16 16:04:20 -08001290TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001291 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001292 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001293 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001294 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001295 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1296 GetFirstAudioStreamCname(answer2.get()));
1297}
1298
Steve Anton36da6ff2018-02-16 16:04:20 -08001299TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 CreatePeerConnectionWithDifferentConfigurations) {
1301 CreatePeerConnectionWithDifferentConfigurations();
1302}
1303
Steve Anton36da6ff2018-02-16 16:04:20 -08001304TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001305 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1306 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1307 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1308 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1309 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1310 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1311 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1312 port_allocator_->candidate_filter());
1313 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1314 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1315}
1316
1317// Test that when a PeerConnection is created with a nonzero candidate pool
1318// size, the pooled PortAllocatorSession is created with all the attributes
1319// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001320TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001321 PeerConnectionInterface::RTCConfiguration config;
1322 PeerConnectionInterface::IceServer server;
1323 server.uri = kStunAddressOnly;
1324 config.servers.push_back(server);
1325 config.type = PeerConnectionInterface::kRelay;
1326 config.disable_ipv6 = true;
1327 config.tcp_candidate_policy =
1328 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001329 config.candidate_network_policy =
1330 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001331 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001332 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001333
1334 const cricket::FakePortAllocatorSession* session =
1335 static_cast<const cricket::FakePortAllocatorSession*>(
1336 port_allocator_->GetPooledSession());
1337 ASSERT_NE(nullptr, session);
1338 EXPECT_EQ(1UL, session->stun_servers().size());
1339 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1340 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001341 EXPECT_LT(0U,
1342 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001343}
1344
deadbeefd21eab32017-07-26 16:50:11 -07001345// Test that network-related RTCConfiguration members are applied to the
1346// PortAllocator when CreatePeerConnection is called. Specifically:
1347// - disable_ipv6_on_wifi
1348// - max_ipv6_networks
1349// - tcp_candidate_policy
1350// - candidate_network_policy
1351// - prune_turn_ports
1352//
1353// Note that the candidate filter (RTCConfiguration::type) is already tested
1354// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001355TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001356 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1357 // Create fake port allocator.
1358 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1359 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1360 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1361
1362 // Create RTCConfiguration with some network-related fields relevant to
1363 // PortAllocator populated.
1364 PeerConnectionInterface::RTCConfiguration config;
1365 config.disable_ipv6_on_wifi = true;
1366 config.max_ipv6_networks = 10;
1367 config.tcp_candidate_policy =
1368 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1369 config.candidate_network_policy =
1370 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1371 config.prune_turn_ports = true;
1372
1373 // Create the PC factory and PC with the above config.
1374 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1375 webrtc::CreatePeerConnectionFactory(
1376 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001377 rtc::Thread::Current(), fake_audio_capture_module_,
1378 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001379 webrtc::CreateBuiltinAudioDecoderFactory(),
1380 webrtc::CreateBuiltinVideoEncoderFactory(),
1381 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1382 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001383 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001384 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1385 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001386 EXPECT_TRUE(pc.get());
1387 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001388
1389 // Now validate that the config fields set above were applied to the
1390 // PortAllocator, as flags or otherwise.
1391 EXPECT_FALSE(raw_port_allocator->flags() &
1392 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1393 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1394 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1395 EXPECT_TRUE(raw_port_allocator->flags() &
1396 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1397 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1398}
1399
deadbeef46c73892016-11-16 19:42:04 -08001400// Check that GetConfiguration returns the configuration the PeerConnection was
1401// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001402TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001403 PeerConnectionInterface::RTCConfiguration config;
1404 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001405 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001406
1407 PeerConnectionInterface::RTCConfiguration returned_config =
1408 pc_->GetConfiguration();
1409 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1410}
1411
1412// Check that GetConfiguration returns the last configuration passed into
1413// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001414TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001415 PeerConnectionInterface::RTCConfiguration starting_config;
1416 starting_config.bundle_policy =
1417 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1418 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001419
Steve Anton36da6ff2018-02-16 16:04:20 -08001420 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001421 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001422 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001423 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001424 EXPECT_TRUE(pc_->SetConfiguration(config));
1425
1426 PeerConnectionInterface::RTCConfiguration returned_config =
1427 pc_->GetConfiguration();
1428 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001429 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001430 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001431}
1432
Steve Antonc79268f2018-04-24 09:54:10 -07001433TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1434 CreatePeerConnection();
1435
1436 pc_->Close();
1437
1438 EXPECT_FALSE(
1439 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1440}
1441
Steve Anton36da6ff2018-02-16 16:04:20 -08001442TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001443 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001444 AddVideoStream(kStreamId1);
1445 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 ASSERT_EQ(2u, pc_->local_streams()->count());
1447
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001448 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001449 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001450 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001451 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001452 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001453 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001455 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001456 EXPECT_EQ(3u, pc_->local_streams()->count());
1457
1458 // Remove the third stream.
1459 pc_->RemoveStream(pc_->local_streams()->at(2));
1460 EXPECT_EQ(2u, pc_->local_streams()->count());
1461
1462 // Remove the second stream.
1463 pc_->RemoveStream(pc_->local_streams()->at(1));
1464 EXPECT_EQ(1u, pc_->local_streams()->count());
1465
1466 // Remove the first stream.
1467 pc_->RemoveStream(pc_->local_streams()->at(0));
1468 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469}
1470
deadbeefab9b2d12015-10-14 11:33:11 -07001471// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001472// Don't run under Unified Plan since the stream API is not available.
1473TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001474 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001475 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001476 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001477 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001478
deadbeefab9b2d12015-10-14 11:33:11 -07001479 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001480 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001481 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001482
deadbeefab9b2d12015-10-14 11:33:11 -07001483 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001484 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001485 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001486
1487 // Add another stream and ensure the offer includes both the old and new
1488 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001489 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001490 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001491
Steve Antonb1c1de12017-12-21 15:14:30 -08001492 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001493 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1494 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001495
Steve Antonb1c1de12017-12-21 15:14:30 -08001496 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001497 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1498 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001499}
1500
Steve Anton36da6ff2018-02-16 16:04:20 -08001501// Don't run under Unified Plan since the stream API is not available.
1502TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001503 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001504 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 ASSERT_EQ(1u, pc_->local_streams()->count());
1506 pc_->RemoveStream(pc_->local_streams()->at(0));
1507 EXPECT_EQ(0u, pc_->local_streams()->count());
1508}
1509
deadbeefe1f9d832016-01-14 15:35:42 -08001510// Test for AddTrack and RemoveTrack methods.
1511// Tests that the created offer includes tracks we added,
1512// and that the RtpSenders are created correctly.
1513// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001514// Only tested with Plan B since Unified Plan is covered in more detail by tests
1515// in peerconnection_jsep_unittests.cc
1516TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001517 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001518 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001519 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001520 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001521 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001522 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1523 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001524 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001525 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001526 EXPECT_EQ("audio_track", audio_sender->id());
1527 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001528 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001529 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001530 EXPECT_EQ("video_track", video_sender->id());
1531 EXPECT_EQ(video_track, video_sender->track());
1532
1533 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001534 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001535 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001536
1537 const cricket::ContentInfo* audio_content =
1538 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001539 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001540 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001541
1542 const cricket::ContentInfo* video_content =
1543 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001544 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001545 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001546
Steve Antondb45ca82017-09-11 18:27:34 -07001547 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001548
1549 // Now try removing the tracks.
1550 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1551 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1552
1553 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001554 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001555
1556 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001557 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001558 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001559
1560 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001561 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001562 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001563
Steve Antondb45ca82017-09-11 18:27:34 -07001564 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001565
1566 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1567 // should return false.
1568 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1569 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1570}
1571
1572// Test creating senders without a stream specified,
1573// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001574TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001575 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001576 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001577 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001578 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001579 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001580 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001581 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001582 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001583 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001584 EXPECT_EQ("audio_track", audio_sender->id());
1585 EXPECT_EQ(audio_track, audio_sender->track());
1586 EXPECT_EQ("video_track", video_sender->id());
1587 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001588 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1589 // If the ID is truly a random GUID, it should be infinitely unlikely they
1590 // will be the same.
1591 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1592 } else {
1593 // We allows creating tracks without stream ids under Unified Plan
1594 // semantics.
1595 EXPECT_EQ(0u, video_sender->stream_ids().size());
1596 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1597 }
deadbeefe1f9d832016-01-14 15:35:42 -08001598}
1599
Harald Alvestrand89061872018-01-02 14:08:34 +01001600// Test that we can call GetStats() after AddTrack but before connecting
1601// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001602TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001603 CreatePeerConnectionWithoutDtls();
1604 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001605 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001606 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001607 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001608 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1609 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001610 EXPECT_TRUE(DoGetStats(nullptr));
1611}
1612
Steve Anton36da6ff2018-02-16 16:04:20 -08001613TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001614 CreatePeerConnectionWithoutDtls();
1615 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001616 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001617 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001618 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001619 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001620 ASSERT_TRUE(audio_sender.ok());
1621 auto* audio_sender_proxy =
1622 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1623 audio_sender.value().get());
1624 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1625
Harald Alvestrandc72af932018-01-11 17:18:19 +01001626 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001627 ASSERT_TRUE(video_sender.ok());
1628 auto* video_sender_proxy =
1629 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1630 video_sender.value().get());
1631 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001632}
1633
Steve Anton36da6ff2018-02-16 16:04:20 -08001634// Don't run under Unified Plan since the stream API is not available.
1635TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001636 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001637 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001638 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001639 ASSERT_EQ(1u, senders.size());
1640 auto* sender_proxy =
1641 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1642 senders[0].get());
1643 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001644}
1645
Steve Anton36da6ff2018-02-16 16:04:20 -08001646TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001648 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 VerifyRemoteRtpHeaderExtensions();
1650}
1651
Steve Anton36da6ff2018-02-16 16:04:20 -08001652TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001653 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001654 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 CreateOfferAsLocalDescription();
1656 std::string offer;
1657 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1658 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001659 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660}
1661
Steve Anton36da6ff2018-02-16 16:04:20 -08001662TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001663 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001664 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665
1666 CreateOfferAsRemoteDescription();
1667 CreateAnswerAsLocalDescription();
1668
Seth Hampson845e8782018-03-02 11:34:10 -08001669 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670}
1671
Steve Anton36da6ff2018-02-16 16:04:20 -08001672TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001673 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001674 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675
1676 CreateOfferAsRemoteDescription();
1677 CreatePrAnswerAsLocalDescription();
1678 CreateAnswerAsLocalDescription();
1679
Seth Hampson845e8782018-03-02 11:34:10 -08001680 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681}
1682
Steve Anton36da6ff2018-02-16 16:04:20 -08001683// Don't run under Unified Plan since the stream API is not available.
1684TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685 InitiateCall();
1686 ASSERT_EQ(1u, pc_->remote_streams()->count());
1687 pc_->RemoveStream(pc_->local_streams()->at(0));
1688 CreateOfferReceiveAnswer();
1689 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001690 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691 CreateOfferReceiveAnswer();
1692}
1693
1694// Tests that after negotiating an audio only call, the respondent can perform a
1695// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001696TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001697 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001698 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 CreateOfferAsRemoteDescription();
1700 CreateAnswerAsLocalDescription();
1701
1702 ASSERT_EQ(1u, pc_->remote_streams()->count());
1703 pc_->RemoveStream(pc_->local_streams()->at(0));
1704 CreateOfferReceiveAnswer();
1705 EXPECT_EQ(0u, pc_->remote_streams()->count());
1706}
1707
1708// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001709TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001710 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711
Steve Antonf1c6db12017-10-13 11:13:35 -07001712 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001714 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001715 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001716 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001717 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718
1719 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001720 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001721 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001722 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723
Steve Antonf1c6db12017-10-13 11:13:35 -07001724 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001725 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726
Steve Antonf1c6db12017-10-13 11:13:35 -07001727 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728}
1729
deadbeefab9b2d12015-10-14 11:33:11 -07001730// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001732TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001733 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001735 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001736 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001737 EXPECT_TRUE(offer);
1738 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739
1740 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001741 AddAudioTrack("track_label", {kStreamId1});
1742 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743
1744 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001745 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746
1747 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001748 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001749 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750}
1751
1752// Test that we will get different SSRCs for each tracks in the offer and answer
1753// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001754TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001755 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001757 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1758 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759
1760 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001761 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001762 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 int audio_ssrc = 0;
1764 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001765 EXPECT_TRUE(
1766 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1767 EXPECT_TRUE(
1768 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 EXPECT_NE(audio_ssrc, video_ssrc);
1770
1771 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001772 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001773 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001774 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 audio_ssrc = 0;
1776 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001777 EXPECT_TRUE(
1778 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1779 EXPECT_TRUE(
1780 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 EXPECT_NE(audio_ssrc, video_ssrc);
1782}
1783
deadbeefeb459812015-12-15 19:24:43 -08001784// Test that it's possible to call AddTrack on a MediaStream after adding
1785// the stream to a PeerConnection.
1786// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001787// Don't run under Unified Plan since the stream API is not available.
1788TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001789 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001790 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001791 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001792 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1793
1794 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001795 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001796 CreateVideoTrack("video_label"));
deadbeefeb459812015-12-15 19:24:43 -08001797 stream->AddTrack(video_track.get());
1798
kwibergd1fe2812016-04-27 06:47:29 -07001799 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001800 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001801
1802 const cricket::MediaContentDescription* video_desc =
1803 cricket::GetFirstVideoContentDescription(offer->description());
1804 EXPECT_TRUE(video_desc != nullptr);
1805}
1806
1807// Test that it's possible to call RemoveTrack on a MediaStream after adding
1808// the stream to a PeerConnection.
1809// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001810// Don't run under Unified Plan since the stream API is not available.
1811TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001812 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001813 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001814 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001815 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1816
1817 // Remove the video track.
1818 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1819
kwibergd1fe2812016-04-27 06:47:29 -07001820 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001821 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001822
1823 const cricket::MediaContentDescription* video_desc =
1824 cricket::GetFirstVideoContentDescription(offer->description());
1825 EXPECT_TRUE(video_desc == nullptr);
1826}
1827
deadbeefbd7d8f72015-12-18 16:58:44 -08001828// Test creating a sender with a stream ID, and ensure the ID is populated
1829// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001830// Don't run under Unified Plan since the stream API is not available.
1831TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001832 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001833 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001834
kwibergd1fe2812016-04-27 06:47:29 -07001835 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001836 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001837
1838 const cricket::MediaContentDescription* video_desc =
1839 cricket::GetFirstVideoContentDescription(offer->description());
1840 ASSERT_TRUE(video_desc != nullptr);
1841 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001842 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001843}
1844
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001846TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001848 ASSERT_LT(0u, pc_->GetSenders().size());
1849 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001850 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001851 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 EXPECT_TRUE(DoGetStats(remote_audio));
1853
1854 // Remove the stream. Since we are sending to our selves the local
1855 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001856 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 // Do a re-negotiation.
1858 CreateOfferReceiveAnswer();
1859
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860 // Test that we still can get statistics for the old track. Even if it is not
1861 // sent any longer.
1862 EXPECT_TRUE(DoGetStats(remote_audio));
1863}
1864
1865// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001866TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001868 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1869 ASSERT_TRUE(video_receiver);
1870 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871}
1872
1873// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001874TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001876 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 pc_factory_->CreateAudioTrack("unknown track", NULL));
1878 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1879}
1880
Steve Anton36da6ff2018-02-16 16:04:20 -08001881TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001882 CreatePeerConnectionWithoutDtls();
1883 EXPECT_TRUE(DoGetRTCStats());
1884 // Clearing stats cache is needed now, but should be temporary.
1885 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1886 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001887 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1888 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001889 EXPECT_TRUE(DoGetRTCStats());
1890 pc_->ClearStatsCache();
1891 CreateOfferReceiveAnswer();
1892 EXPECT_TRUE(DoGetRTCStats());
1893}
1894
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001896TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001897 RTCConfiguration config;
1898 config.enable_rtp_data_channel = true;
1899 config.enable_dtls_srtp = false;
1900 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001901 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001903 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 pc_->CreateDataChannel("test2", NULL);
1905 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001906 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001908 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 new MockDataChannelObserver(data2));
1910
1911 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1912 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1913 std::string data_to_send1 = "testing testing";
1914 std::string data_to_send2 = "testing something else";
1915 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1916
1917 CreateOfferReceiveAnswer();
1918 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1919 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1920
1921 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1922 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1923 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1924 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1925
1926 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1927 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1928
1929 data1->Close();
1930 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1931 CreateOfferReceiveAnswer();
1932 EXPECT_FALSE(observer1->IsOpen());
1933 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1934 EXPECT_TRUE(observer2->IsOpen());
1935
1936 data_to_send2 = "testing something else again";
1937 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1938
1939 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1940}
1941
1942// This test verifies that sendnig binary data over RTP data channels should
1943// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001944TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001945 RTCConfiguration config;
1946 config.enable_rtp_data_channel = true;
1947 config.enable_dtls_srtp = false;
1948 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001949 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001951 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952 pc_->CreateDataChannel("test2", NULL);
1953 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001954 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001956 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 new MockDataChannelObserver(data2));
1958
1959 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1960 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1961
1962 CreateOfferReceiveAnswer();
1963 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1964 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1965
1966 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1967 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1968
jbaucheec21bd2016-03-20 06:15:43 -07001969 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1971}
1972
1973// This test setup a RTP data channels in loop back and test that a channel is
1974// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08001975TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001976 RTCConfiguration config;
1977 config.enable_rtp_data_channel = true;
1978 config.enable_dtls_srtp = false;
1979 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001980 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001982 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 new MockDataChannelObserver(data1));
1984
1985 CreateOfferReceiveAnswerWithoutSsrc();
1986
1987 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1988
1989 data1->Close();
1990 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1991 CreateOfferReceiveAnswerWithoutSsrc();
1992 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1993 EXPECT_FALSE(observer1->IsOpen());
1994}
1995
1996// This test that if a data channel is added in an answer a receive only channel
1997// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001998TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001999 RTCConfiguration config;
2000 config.enable_rtp_data_channel = true;
2001 config.enable_dtls_srtp = false;
2002
2003 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004
2005 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002006 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 pc_->CreateDataChannel(offer_label, NULL);
2008
2009 CreateOfferAsLocalDescription();
2010
2011 // Replace the data channel label in the offer and apply it as an answer.
2012 std::string receive_label = "answer_channel";
2013 std::string sdp;
2014 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002015 absl::StrReplaceAll({{offer_label, receive_label}}, &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 CreateAnswerAsRemoteDescription(sdp);
2017
2018 // Verify that a new incoming data channel has been created and that
2019 // it is open but can't we written to.
2020 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2021 DataChannelInterface* received_channel = observer_.last_datachannel_;
2022 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2023 EXPECT_EQ(receive_label, received_channel->label());
2024 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2025
2026 // Verify that the channel we initially offered has been rejected.
2027 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2028
2029 // Do another offer / answer exchange and verify that the data channel is
2030 // opened.
2031 CreateOfferReceiveAnswer();
2032 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2033 kTimeout);
2034}
2035
2036// This test that no data channel is returned if a reliable channel is
2037// requested.
2038// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002039TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002040 RTCConfiguration rtc_config;
2041 rtc_config.enable_rtp_data_channel = true;
2042 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043
2044 std::string label = "test";
2045 webrtc::DataChannelInit config;
2046 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002047 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 pc_->CreateDataChannel(label, &config);
2049 EXPECT_TRUE(channel == NULL);
2050}
2051
deadbeefab9b2d12015-10-14 11:33:11 -07002052// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002053TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002054 RTCConfiguration config;
2055 config.enable_rtp_data_channel = true;
2056 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002057
2058 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002059 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002060 pc_->CreateDataChannel(label, nullptr);
2061 EXPECT_NE(channel, nullptr);
2062
zhihuang9763d562016-08-05 11:14:50 -07002063 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002064 pc_->CreateDataChannel(label, nullptr);
2065 EXPECT_EQ(dup_channel, nullptr);
2066}
2067
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068// This tests that a SCTP data channel is returned using different
2069// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002070TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002071 RTCConfiguration rtc_config;
2072 rtc_config.enable_dtls_srtp = true;
2073 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074
2075 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002076 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 pc_->CreateDataChannel("1", &config);
2078 EXPECT_TRUE(channel != NULL);
2079 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002080 EXPECT_TRUE(observer_.renegotiation_needed_);
2081 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082
2083 config.ordered = false;
2084 channel = pc_->CreateDataChannel("2", &config);
2085 EXPECT_TRUE(channel != NULL);
2086 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002087 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088
2089 config.ordered = true;
2090 config.maxRetransmits = 0;
2091 channel = pc_->CreateDataChannel("3", &config);
2092 EXPECT_TRUE(channel != NULL);
2093 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002094 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02002096 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 config.maxRetransmitTime = 0;
2098 channel = pc_->CreateDataChannel("4", &config);
2099 EXPECT_TRUE(channel != NULL);
2100 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002101 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102}
2103
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02002104// For backwards compatibility, we want people who "unset" maxRetransmits
2105// and maxRetransmitTime by setting them to -1 to get what they want.
2106TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
2107 RTCConfiguration rtc_config;
2108 rtc_config.enable_dtls_srtp = true;
2109 CreatePeerConnection(rtc_config);
2110
2111 webrtc::DataChannelInit config;
2112 config.maxRetransmitTime = -1;
2113 config.maxRetransmits = -1;
2114 rtc::scoped_refptr<DataChannelInterface> channel =
2115 pc_->CreateDataChannel("1", &config);
2116 EXPECT_TRUE(channel != NULL);
2117}
2118
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119// This tests that no data channel is returned if both maxRetransmits and
2120// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002121TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002123 RTCConfiguration rtc_config;
2124 rtc_config.enable_dtls_srtp = true;
2125 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126
2127 std::string label = "test";
2128 webrtc::DataChannelInit config;
2129 config.maxRetransmits = 0;
2130 config.maxRetransmitTime = 0;
2131
zhihuang9763d562016-08-05 11:14:50 -07002132 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 pc_->CreateDataChannel(label, &config);
2134 EXPECT_TRUE(channel == NULL);
2135}
2136
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137// The test verifies that creating a SCTP data channel with an id already in use
2138// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002139TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002141 RTCConfiguration rtc_config;
2142 rtc_config.enable_dtls_srtp = true;
2143 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144
2145 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002146 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002148 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002149 config.negotiated = true;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002150 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 EXPECT_TRUE(channel != NULL);
2152 EXPECT_EQ(1, channel->id());
2153
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 channel = pc_->CreateDataChannel("x", &config);
2155 EXPECT_TRUE(channel == NULL);
2156
2157 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002158 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 channel = pc_->CreateDataChannel("max", &config);
2160 EXPECT_TRUE(channel != NULL);
2161 EXPECT_EQ(config.id, channel->id());
2162
2163 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002164 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 channel = pc_->CreateDataChannel("x", &config);
2166 EXPECT_TRUE(channel == NULL);
2167}
2168
deadbeefab9b2d12015-10-14 11:33:11 -07002169// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002170TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002171 RTCConfiguration rtc_config;
2172 rtc_config.enable_dtls_srtp = true;
2173 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002174
2175 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002176 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002177 pc_->CreateDataChannel(label, nullptr);
2178 EXPECT_NE(channel, nullptr);
2179
zhihuang9763d562016-08-05 11:14:50 -07002180 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002181 pc_->CreateDataChannel(label, nullptr);
2182 EXPECT_NE(dup_channel, nullptr);
2183}
2184
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002185// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2186// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002187TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002188 RTCConfiguration rtc_config;
2189 rtc_config.enable_rtp_data_channel = true;
2190 rtc_config.enable_dtls_srtp = false;
2191 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002192
zhihuang9763d562016-08-05 11:14:50 -07002193 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002194 pc_->CreateDataChannel("test1", NULL);
2195 EXPECT_TRUE(observer_.renegotiation_needed_);
2196 observer_.renegotiation_needed_ = false;
2197
Guido Urdaneta70c2db12019-04-16 12:24:14 +02002198 CreateOfferReceiveAnswer();
2199
zhihuang9763d562016-08-05 11:14:50 -07002200 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002201 pc_->CreateDataChannel("test2", NULL);
Guido Urdaneta70c2db12019-04-16 12:24:14 +02002202 EXPECT_EQ(observer_.renegotiation_needed_,
2203 GetParam() == SdpSemantics::kPlanB);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002204}
2205
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002207TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002208 RTCConfiguration rtc_config;
2209 rtc_config.enable_rtp_data_channel = true;
2210 rtc_config.enable_dtls_srtp = false;
2211 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212
zhihuang9763d562016-08-05 11:14:50 -07002213 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002215 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216 pc_->CreateDataChannel("test2", NULL);
2217 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002218 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002220 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 new MockDataChannelObserver(data2));
2222
2223 CreateOfferReceiveAnswer();
2224 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2225 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2226
2227 ReleasePeerConnection();
2228 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2229 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2230}
2231
Zhi Huang644fde42018-04-02 19:16:26 -07002232// This tests that RTP data channels can be rejected in an answer.
2233TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002234 RTCConfiguration rtc_config;
2235 rtc_config.enable_rtp_data_channel = true;
2236 rtc_config.enable_dtls_srtp = false;
2237 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238
zhihuang9763d562016-08-05 11:14:50 -07002239 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240 pc_->CreateDataChannel("offer_channel", NULL));
2241
2242 CreateOfferAsLocalDescription();
2243
2244 // Create an answer where the m-line for data channels are rejected.
2245 std::string sdp;
2246 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002247 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002248 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002249 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002251 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 data_info->rejected = true;
2253
Steve Antondb45ca82017-09-11 18:27:34 -07002254 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2256}
2257
Zhi Huang644fde42018-04-02 19:16:26 -07002258#ifdef HAVE_SCTP
2259// This tests that SCTP data channels can be rejected in an answer.
2260TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2261#else
2262TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2263#endif
2264{
Niels Möllerf06f9232018-08-07 12:32:18 +02002265 RTCConfiguration rtc_config;
2266 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002267
2268 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2269 pc_->CreateDataChannel("offer_channel", NULL));
2270
2271 CreateOfferAsLocalDescription();
2272
2273 // Create an answer where the m-line for data channels are rejected.
2274 std::string sdp;
2275 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2276 std::unique_ptr<SessionDescriptionInterface> answer(
2277 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2278 ASSERT_TRUE(answer);
2279 cricket::ContentInfo* data_info =
2280 cricket::GetFirstDataContent(answer->description());
2281 data_info->rejected = true;
2282
2283 DoSetRemoteDescription(std::move(answer));
2284 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2285}
2286
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287// Test that we can create a session description from an SDP string from
2288// FireFox, use it as a remote session description, generate an answer and use
2289// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002290TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002291 RTCConfiguration rtc_config;
2292 rtc_config.enable_dtls_srtp = true;
2293 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002294 AddAudioTrack("audio_label");
2295 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002296 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002297 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002298 webrtc::kFireFoxSdpOffer, nullptr));
2299 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300 CreateAnswerAsLocalDescription();
2301 ASSERT_TRUE(pc_->local_description() != NULL);
2302 ASSERT_TRUE(pc_->remote_description() != NULL);
2303
2304 const cricket::ContentInfo* content =
2305 cricket::GetFirstAudioContent(pc_->local_description()->description());
2306 ASSERT_TRUE(content != NULL);
2307 EXPECT_FALSE(content->rejected);
2308
2309 content =
2310 cricket::GetFirstVideoContent(pc_->local_description()->description());
2311 ASSERT_TRUE(content != NULL);
2312 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002313#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 content =
2315 cricket::GetFirstDataContent(pc_->local_description()->description());
2316 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002317 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002318#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319}
2320
zhihuangb19012e2017-09-19 13:47:59 -07002321// Test that fallback from DTLS to SDES is not supported.
2322// The fallback was previously supported but was removed to simplify the code
2323// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002324TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002325 RTCConfiguration rtc_config;
2326 rtc_config.enable_dtls_srtp = true;
2327 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002328 // Wait for fake certificate to be generated. Previously, this is what caused
2329 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002330 AddAudioTrack("audio_label");
2331 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002332 ASSERT_NE(nullptr, fake_certificate_generator_);
2333 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2334 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002335 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002336 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2337 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002338 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002339}
2340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341// Test that we can create an audio only offer and receive an answer with a
2342// limited set of audio codecs and receive an updated offer with more audio
2343// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002344TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002345 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002346 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 CreateOfferAsLocalDescription();
2348
Steve Anton36da6ff2018-02-16 16:04:20 -08002349 const char* answer_sdp =
2350 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2351 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002352 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002353 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002354 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355
Steve Anton36da6ff2018-02-16 16:04:20 -08002356 const char* reoffer_sdp =
2357 (sdp_semantics_ == SdpSemantics::kPlanB
2358 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2359 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002360 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002361 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002362 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 CreateAnswerAsLocalDescription();
2364}
2365
deadbeefc80741f2015-10-22 13:14:45 -07002366// Test that if we're receiving (but not sending) a track, subsequent offers
2367// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002368TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002369 RTCConfiguration rtc_config;
2370 rtc_config.enable_dtls_srtp = true;
2371 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002372 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002373 CreateAnswerAsLocalDescription();
2374
2375 // At this point we should be receiving stream 1, but not sending anything.
2376 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002377 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002378 DoCreateOffer(&offer, nullptr);
2379
2380 const cricket::ContentInfo* video_content =
2381 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002382 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2383 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002384
2385 const cricket::ContentInfo* audio_content =
2386 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002387 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2388 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002389}
2390
2391// Test that if we're receiving (but not sending) a track, and the
2392// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2393// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002394TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002395 RTCConfiguration rtc_config;
2396 rtc_config.enable_dtls_srtp = true;
2397 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002398 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002399 CreateAnswerAsLocalDescription();
2400
2401 // At this point we should be receiving stream 1, but not sending anything.
2402 // A new offer would be recvonly, but we'll set the "no receive" constraints
2403 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002404 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002405 RTCOfferAnswerOptions options;
2406 options.offer_to_receive_audio = 0;
2407 options.offer_to_receive_video = 0;
2408 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002409
2410 const cricket::ContentInfo* video_content =
2411 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002412 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2413 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002414
2415 const cricket::ContentInfo* audio_content =
2416 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002417 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2418 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002419}
2420
deadbeef653b8e02015-11-11 12:55:10 -08002421// Test that we can use SetConfiguration to change the ICE servers of the
2422// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002423TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002424 CreatePeerConnection();
2425
Steve Anton36da6ff2018-02-16 16:04:20 -08002426 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002427 PeerConnectionInterface::IceServer server;
2428 server.uri = "stun:test_hostname";
2429 config.servers.push_back(server);
2430 EXPECT_TRUE(pc_->SetConfiguration(config));
2431
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002432 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2433 EXPECT_EQ("test_hostname",
2434 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002435}
2436
Steve Anton36da6ff2018-02-16 16:04:20 -08002437TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002438 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002439 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002440 config.type = PeerConnectionInterface::kRelay;
2441 EXPECT_TRUE(pc_->SetConfiguration(config));
2442 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2443}
2444
Steve Anton36da6ff2018-02-16 16:04:20 -08002445TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002446 PeerConnectionInterface::RTCConfiguration config;
2447 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002448 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002449 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002450 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2451
2452 config.prune_turn_ports = true;
2453 EXPECT_TRUE(pc_->SetConfiguration(config));
2454 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2455}
2456
skvladd1f5fda2017-02-03 16:54:05 -08002457// Test that the ice check interval can be changed. This does not verify that
2458// the setting makes it all the way to P2PTransportChannel, as that would
2459// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002460TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002461 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002462 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002463 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002464 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002465 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002466 EXPECT_TRUE(pc_->SetConfiguration(config));
Qingsi Wangbca14852019-06-26 14:56:02 -07002467 config = pc_->GetConfiguration();
2468 EXPECT_EQ(config.ice_check_min_interval, 100);
2469}
2470
2471TEST_P(PeerConnectionInterfaceTest,
2472 SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) {
2473 PeerConnectionInterface::RTCConfiguration config;
2474 config.surface_ice_candidates_on_ice_transport_type_changed = false;
2475 CreatePeerConnection(config);
2476 config = pc_->GetConfiguration();
2477 EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed);
2478
2479 config.surface_ice_candidates_on_ice_transport_type_changed = true;
2480 EXPECT_TRUE(pc_->SetConfiguration(config));
2481 config = pc_->GetConfiguration();
2482 EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed);
skvladd1f5fda2017-02-03 16:54:05 -08002483}
2484
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002485// Test that when SetConfiguration changes both the pool size and other
2486// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002487TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002488 SetConfigurationCreatesPooledSessionCorrectly) {
2489 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002490 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002491 config.ice_candidate_pool_size = 1;
2492 PeerConnectionInterface::IceServer server;
2493 server.uri = kStunAddressOnly;
2494 config.servers.push_back(server);
2495 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002496 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002497
2498 const cricket::FakePortAllocatorSession* session =
2499 static_cast<const cricket::FakePortAllocatorSession*>(
2500 port_allocator_->GetPooledSession());
2501 ASSERT_NE(nullptr, session);
2502 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002503}
2504
deadbeef293e9262017-01-11 12:28:30 -08002505// Test that after SetLocalDescription, changing the pool size is not allowed,
2506// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002507TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002508 CantChangePoolSizeAfterSetLocalDescription) {
2509 CreatePeerConnection();
2510 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002511 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002512 config.ice_candidate_pool_size = 1;
2513 EXPECT_TRUE(pc_->SetConfiguration(config));
2514
2515 // Set remote offer; can still change pool size at this point.
2516 CreateOfferAsRemoteDescription();
2517 config.ice_candidate_pool_size = 2;
2518 EXPECT_TRUE(pc_->SetConfiguration(config));
2519
2520 // Set local answer; now it's too late.
2521 CreateAnswerAsLocalDescription();
2522 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002523 RTCError error;
2524 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2525 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2526}
2527
deadbeef42a42632017-03-10 15:18:00 -08002528// Test that after setting an answer, extra pooled sessions are discarded. The
2529// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002530TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002531 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2532 CreatePeerConnection();
2533
2534 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002535 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002536 config.ice_candidate_pool_size = 4;
2537 EXPECT_TRUE(pc_->SetConfiguration(config));
2538
2539 // Do offer/answer.
2540 CreateOfferAsRemoteDescription();
2541 CreateAnswerAsLocalDescription();
2542
2543 // Expect no pooled sessions to be left.
2544 const cricket::PortAllocatorSession* session =
2545 port_allocator_->GetPooledSession();
2546 EXPECT_EQ(nullptr, session);
2547}
2548
2549// After Close is called, pooled candidates should be discarded so as to not
2550// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002551TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002552 CreatePeerConnection();
2553
Steve Anton36da6ff2018-02-16 16:04:20 -08002554 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002555 config.ice_candidate_pool_size = 3;
2556 EXPECT_TRUE(pc_->SetConfiguration(config));
2557 pc_->Close();
2558
2559 // Expect no pooled sessions to be left.
2560 const cricket::PortAllocatorSession* session =
2561 port_allocator_->GetPooledSession();
2562 EXPECT_EQ(nullptr, session);
2563}
2564
deadbeef293e9262017-01-11 12:28:30 -08002565// Test that SetConfiguration returns an invalid modification error if
2566// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002567TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002568 SetConfigurationReturnsInvalidModificationError) {
2569 PeerConnectionInterface::RTCConfiguration config;
2570 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2571 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2572 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002573 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002574
Steve Anton36da6ff2018-02-16 16:04:20 -08002575 PeerConnectionInterface::RTCConfiguration modified_config =
2576 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002577 modified_config.bundle_policy =
2578 PeerConnectionInterface::kBundlePolicyMaxBundle;
2579 RTCError error;
2580 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2581 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2582
Steve Anton36da6ff2018-02-16 16:04:20 -08002583 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002584 modified_config.rtcp_mux_policy =
2585 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2586 error.set_type(RTCErrorType::NONE);
2587 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2588 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2589
Steve Anton36da6ff2018-02-16 16:04:20 -08002590 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002591 modified_config.continual_gathering_policy =
2592 PeerConnectionInterface::GATHER_CONTINUALLY;
2593 error.set_type(RTCErrorType::NONE);
2594 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2595 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2596}
2597
2598// Test that SetConfiguration returns a range error if the candidate pool size
2599// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002600TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002601 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2602 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002603 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002604 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002605
2606 config.ice_candidate_pool_size = -1;
2607 RTCError error;
2608 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2609 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2610
2611 config.ice_candidate_pool_size = INT_MAX;
2612 error.set_type(RTCErrorType::NONE);
2613 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2614 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2615}
2616
2617// Test that SetConfiguration returns a syntax error if parsing an ICE server
2618// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002619TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002620 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2621 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002622 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002623 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002624
2625 PeerConnectionInterface::IceServer bad_server;
2626 bad_server.uri = "stunn:www.example.com";
2627 config.servers.push_back(bad_server);
2628 RTCError error;
2629 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2630 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2631}
2632
2633// Test that SetConfiguration returns an invalid parameter error if a TURN
2634// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002635TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002636 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2637 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002638 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002639 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002640
2641 PeerConnectionInterface::IceServer bad_server;
2642 bad_server.uri = "turn:www.example.com";
2643 // Missing password.
2644 bad_server.username = "foo";
2645 config.servers.push_back(bad_server);
2646 RTCError error;
2647 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2648 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002649}
2650
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651// Test that PeerConnection::Close changes the states to closed and all remote
2652// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002653TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 // Initialize a PeerConnection and negotiate local and remote session
2655 // description.
2656 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002657
2658 // With Plan B, verify the stream count. The analog with Unified Plan is the
2659 // RtpTransceiver count.
2660 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2661 ASSERT_EQ(1u, pc_->local_streams()->count());
2662 ASSERT_EQ(1u, pc_->remote_streams()->count());
2663 } else {
2664 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2665 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002666
2667 pc_->Close();
2668
2669 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2670 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2671 pc_->ice_connection_state());
2672 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2673 pc_->ice_gathering_state());
2674
Steve Anton36da6ff2018-02-16 16:04:20 -08002675 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2676 EXPECT_EQ(1u, pc_->local_streams()->count());
2677 EXPECT_EQ(1u, pc_->remote_streams()->count());
2678 } else {
2679 // Verify that the RtpTransceivers are still present but all stopped.
2680 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Mirko Bonadei739baf02019-01-27 17:29:42 +01002681 for (const auto& transceiver : pc_->GetTransceivers()) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002682 EXPECT_TRUE(transceiver->stopped());
2683 }
2684 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685
Steve Anton36da6ff2018-02-16 16:04:20 -08002686 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2687 ASSERT_TRUE(audio_receiver);
2688 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2689 ASSERT_TRUE(video_receiver);
2690
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002691 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002692 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002693 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002694 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002695 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696}
2697
2698// Test that PeerConnection methods fails gracefully after
2699// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002700// Don't run under Unified Plan since the stream API is not available.
2701TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002702 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002703 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704 CreateOfferAsRemoteDescription();
2705 CreateAnswerAsLocalDescription();
2706
2707 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002708 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709 pc_->local_streams()->at(0);
2710
2711 pc_->Close();
2712
2713 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002714 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2717
2718 EXPECT_TRUE(pc_->local_description() != NULL);
2719 EXPECT_TRUE(pc_->remote_description() != NULL);
2720
kwibergd1fe2812016-04-27 06:47:29 -07002721 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002722 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002723 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002724 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725
2726 std::string sdp;
2727 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002728 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002729 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002730 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002731
2732 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002733 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002734 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002735 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736}
2737
2738// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002739TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 InitiateCall();
2741 pc_->Close();
2742 DoGetStats(NULL);
2743}
deadbeefab9b2d12015-10-14 11:33:11 -07002744
2745// NOTE: The series of tests below come from what used to be
2746// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2747// setting a remote or local description has the expected effects.
2748
2749// This test verifies that the remote MediaStreams corresponding to a received
2750// SDP string is created. In this test the two separate MediaStreams are
2751// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002752TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002753 RTCConfiguration config;
2754 config.enable_dtls_srtp = true;
2755 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002756 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002757
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002758 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002759 EXPECT_TRUE(
2760 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2761 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2762 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2763
2764 // Create a session description based on another SDP with another
2765 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002766 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002767
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002768 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002769 EXPECT_TRUE(
2770 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2771}
2772
2773// This test verifies that when remote tracks are added/removed from SDP, the
2774// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002775// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2776// specific behavior.
2777TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002778 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002779 RTCConfiguration config;
2780 config.enable_dtls_srtp = true;
2781 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002782 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002783 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002784 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002785 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2786 reference_collection_));
2787
2788 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002789 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002790 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002791 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002792 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2793 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002794 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002795 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2796 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002797 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002798 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2799 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002800
2801 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002802 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002803 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002804 MockTrackObserver audio_track_observer(audio_track2);
2805 MockTrackObserver video_track_observer(video_track2);
2806
2807 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2808 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002809 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002810 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2811 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002812 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002813 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002814 audio_track2->state(), kTimeout);
2815 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2816 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002817}
2818
2819// This tests that remote tracks are ended if a local session description is set
2820// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002821TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002822 RTCConfiguration config;
2823 config.enable_dtls_srtp = true;
2824 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002825 // First create and set a remote offer, then reject its video content in our
2826 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002827 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2828 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2829 ASSERT_TRUE(audio_receiver);
2830 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2831 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002832
Steve Anton36da6ff2018-02-16 16:04:20 -08002833 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2834 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002835 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002836 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2837 video_receiver->track();
2838 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002839
kwibergd1fe2812016-04-27 06:47:29 -07002840 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002841 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002842 cricket::ContentInfo* video_info =
2843 local_answer->description()->GetContentByName("video");
2844 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002845 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002846 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2847 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002848
2849 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002850 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002851 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002852 video_info = local_offer->description()->GetContentByName("video");
2853 ASSERT_TRUE(video_info != nullptr);
2854 video_info->rejected = true;
2855 cricket::ContentInfo* audio_info =
2856 local_offer->description()->GetContentByName("audio");
2857 ASSERT_TRUE(audio_info != nullptr);
2858 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002859 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002860 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002861 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2862 kTimeout);
2863 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2864 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002865}
2866
2867// This tests that we won't crash if the remote track has been removed outside
2868// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002869// Don't run under Unified Plan since the stream API is not available.
2870TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002871 RTCConfiguration config;
2872 config.enable_dtls_srtp = true;
2873 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002874 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002875 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2876 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2877 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2878
kwibergd1fe2812016-04-27 06:47:29 -07002879 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002880 webrtc::CreateSessionDescription(SdpType::kAnswer,
2881 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002882 cricket::ContentInfo* video_info =
2883 local_answer->description()->GetContentByName("video");
2884 video_info->rejected = true;
2885 cricket::ContentInfo* audio_info =
2886 local_answer->description()->GetContentByName("audio");
2887 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002888 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002889
2890 // No crash is a pass.
2891}
2892
deadbeef5e97fb52015-10-15 12:49:08 -07002893// This tests that if a recvonly remote description is set, no remote streams
2894// will be created, even if the description contains SSRCs/MSIDs.
2895// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002896TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002897 RTCConfiguration config;
2898 config.enable_dtls_srtp = true;
2899 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002900
Steve Anton36da6ff2018-02-16 16:04:20 -08002901 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002902 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 12:49:08 -07002903 CreateAndSetRemoteOffer(recvonly_offer);
2904
2905 EXPECT_EQ(0u, observer_.remote_streams()->count());
2906}
2907
deadbeefab9b2d12015-10-14 11:33:11 -07002908// This tests that a default MediaStream is created if a remote session
2909// description doesn't contain any streams and no MSID support.
2910// It also tests that the default stream is updated if a video m-line is added
2911// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002912// Don't run under Unified Plan since this behavior is Plan B specific.
2913TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002914 RTCConfiguration config;
2915 config.enable_dtls_srtp = true;
2916 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002917 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2918
2919 ASSERT_EQ(1u, observer_.remote_streams()->count());
2920 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2921
2922 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2923 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002924 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002925
2926 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2927 ASSERT_EQ(1u, observer_.remote_streams()->count());
2928 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2929 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002930 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2931 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002932 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2933 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002934 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2935 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002936}
2937
2938// This tests that a default MediaStream is created if a remote session
2939// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002940// Don't run under Unified Plan since this behavior is Plan B specific.
2941TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002942 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002943 RTCConfiguration config;
2944 config.enable_dtls_srtp = true;
2945 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002946 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2947
2948 ASSERT_EQ(1u, observer_.remote_streams()->count());
2949 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2950
2951 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2952 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002953 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002954}
2955
2956// This tests that it won't crash when PeerConnection tries to remove
2957// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002958// Don't run under Unified Plan since this behavior is Plan B specific.
2959TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002960 RTCConfiguration config;
2961 config.enable_dtls_srtp = true;
2962 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002963 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002964 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2965 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2966 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2967
2968 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2969
2970 // No crash is a pass.
2971}
2972
2973// This tests that a default MediaStream is created if the remote session
2974// description doesn't contain any streams and don't contain an indication if
2975// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002976// Don't run under Unified Plan since this behavior is Plan B specific.
2977TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002978 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002979 RTCConfiguration config;
2980 config.enable_dtls_srtp = true;
2981 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002982 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2983
2984 ASSERT_EQ(1u, observer_.remote_streams()->count());
2985 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2986 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2987 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2988}
2989
2990// This tests that a default MediaStream is not created if the remote session
2991// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002992// Don't run under Unified Plan since this behavior is Plan B specific.
2993TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002994 RTCConfiguration config;
2995 config.enable_dtls_srtp = true;
2996 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002997 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2998 EXPECT_EQ(0u, observer_.remote_streams()->count());
2999}
3000
deadbeefbda7e0b2015-12-08 17:13:40 -08003001// This tests that when setting a new description, the old default tracks are
3002// not destroyed and recreated.
3003// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08003004// Don't run under Unified Plan since this behavior is Plan B specific.
3005TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003006 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003007 RTCConfiguration config;
3008 config.enable_dtls_srtp = true;
3009 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08003010 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3011
3012 ASSERT_EQ(1u, observer_.remote_streams()->count());
3013 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3014 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3015
3016 // Set the track to "disabled", then set a new description and ensure the
3017 // track is still disabled, which ensures it hasn't been recreated.
3018 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3019 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3020 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3021 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3022}
3023
deadbeefab9b2d12015-10-14 11:33:11 -07003024// This tests that a default MediaStream is not created if a remote session
3025// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003026// Don't run under Unified Plan since this behavior is Plan B specific.
3027TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003028 RTCConfiguration config;
3029 config.enable_dtls_srtp = true;
3030 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003031 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003032 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003033 EXPECT_TRUE(
3034 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3035
3036 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3037 EXPECT_EQ(0u, observer_.remote_streams()->count());
3038}
3039
Seth Hampson5897a6e2018-04-03 11:16:33 -07003040// This tests that a default MediaStream is created if a remote SDP comes from
3041// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3042TEST_F(PeerConnectionInterfaceTestPlanB,
3043 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003044 RTCConfiguration config;
3045 config.enable_dtls_srtp = true;
3046 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003047 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3048 // Add a=msid lines to simulate a Unified Plan endpoint that only
3049 // signals stream IDs with a=msid lines.
3050 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3051
3052 CreateAndSetRemoteOffer(sdp_string);
3053
3054 ASSERT_EQ(1u, observer_.remote_streams()->count());
3055 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3056 EXPECT_EQ("default", remote_stream->id());
3057 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3058}
3059
Seth Hampson5b4f0752018-04-02 16:31:36 -07003060// This tests that when a Plan B endpoint receives an SDP that signals no media
3061// stream IDs indicated by the special character "-" in the a=msid line, that
3062// a default stream ID will be used for the MediaStream ID. This can occur
3063// when a Unified Plan endpoint signals no media stream IDs, but signals both
3064// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3065TEST_F(PeerConnectionInterfaceTestPlanB,
3066 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003067 RTCConfiguration config;
3068 config.enable_dtls_srtp = true;
3069 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003070 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3071 // the sender's stream ID will be interpreted as no stream IDs.
3072 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3073 sdp_string.append("a=msid:- audiotrack0\n");
3074
3075 CreateAndSetRemoteOffer(sdp_string);
3076
3077 ASSERT_EQ(1u, observer_.remote_streams()->count());
3078 // Because SSRCs are signaled the track ID will be what was signaled in the
3079 // a=msid line.
3080 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3081 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3082 EXPECT_EQ("default", remote_stream->id());
3083 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003084
3085 // Previously a bug ocurred when setting the remote description a second time.
3086 // This is because we checked equality of the remote StreamParams stream ID
3087 // (empty), and the previously set stream ID for the remote sender
3088 // ("default"). This cause a track to be removed, then added, when really
3089 // nothing should occur because it is the same track.
3090 CreateAndSetRemoteOffer(sdp_string);
3091 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3092 EXPECT_EQ(1u, observer_.add_track_events_.size());
3093 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3094 remote_stream = observer_.remote_streams()->at(0);
3095 EXPECT_EQ("default", remote_stream->id());
3096 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003097}
3098
deadbeefab9b2d12015-10-14 11:33:11 -07003099// This tests that an RtpSender is created when the local description is set
3100// after adding a local stream.
3101// TODO(deadbeef): This test and the one below it need to be updated when
3102// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003103// Don't run under Unified Plan since this behavior is Plan B specific.
3104TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003105 RTCConfiguration config;
3106 config.enable_dtls_srtp = true;
3107 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003108
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003109 // Create an offer with 1 stream with 2 tracks of each type.
3110 rtc::scoped_refptr<StreamCollection> stream_collection =
3111 CreateStreamCollection(1, 2);
3112 pc_->AddStream(stream_collection->at(0));
3113 std::unique_ptr<SessionDescriptionInterface> offer;
3114 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003115 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003116
deadbeefab9b2d12015-10-14 11:33:11 -07003117 auto senders = pc_->GetSenders();
3118 EXPECT_EQ(4u, senders.size());
3119 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3120 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3121 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3122 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3123
3124 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003125 pc_->RemoveStream(stream_collection->at(0));
3126 stream_collection = CreateStreamCollection(1, 1);
3127 pc_->AddStream(stream_collection->at(0));
3128 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003129 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003130
deadbeefab9b2d12015-10-14 11:33:11 -07003131 senders = pc_->GetSenders();
3132 EXPECT_EQ(2u, senders.size());
3133 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3134 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3135 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3136 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3137}
3138
3139// This tests that an RtpSender is created when the local description is set
3140// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003141// Don't run under Unified Plan since this behavior is Plan B specific.
3142TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003143 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003144 RTCConfiguration config;
3145 config.enable_dtls_srtp = true;
3146 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003147
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003148 rtc::scoped_refptr<StreamCollection> stream_collection =
3149 CreateStreamCollection(1, 2);
3150 // Add a stream to create the offer, but remove it afterwards.
3151 pc_->AddStream(stream_collection->at(0));
3152 std::unique_ptr<SessionDescriptionInterface> offer;
3153 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3154 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003155
Steve Antondb45ca82017-09-11 18:27:34 -07003156 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003157 auto senders = pc_->GetSenders();
3158 EXPECT_EQ(0u, senders.size());
3159
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003160 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003161 senders = pc_->GetSenders();
3162 EXPECT_EQ(4u, senders.size());
3163 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3164 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3165 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3166 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3167}
3168
3169// This tests that the expected behavior occurs if the SSRC on a local track is
3170// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003171TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003172 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003173 RTCConfiguration config;
3174 config.enable_dtls_srtp = true;
3175 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003176
Steve Anton36da6ff2018-02-16 16:04:20 -08003177 AddAudioTrack(kAudioTracks[0]);
3178 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003179 std::unique_ptr<SessionDescriptionInterface> offer;
3180 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3181 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003182 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3183 webrtc::CreateSessionDescription(
3184 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003185 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-11 18:27:34 -07003186 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003187
deadbeefab9b2d12015-10-14 11:33:11 -07003188 auto senders = pc_->GetSenders();
3189 EXPECT_EQ(2u, senders.size());
3190 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3191 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3192
3193 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003194 cricket::MediaContentDescription* desc =
3195 cricket::GetFirstAudioContentDescription(modified_offer->description());
3196 ASSERT_TRUE(desc != NULL);
3197 for (StreamParams& stream : desc->mutable_streams()) {
3198 for (unsigned int& ssrc : stream.ssrcs) {
3199 ++ssrc;
3200 }
3201 }
deadbeefab9b2d12015-10-14 11:33:11 -07003202
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003203 desc =
3204 cricket::GetFirstVideoContentDescription(modified_offer->description());
3205 ASSERT_TRUE(desc != NULL);
3206 for (StreamParams& stream : desc->mutable_streams()) {
3207 for (unsigned int& ssrc : stream.ssrcs) {
3208 ++ssrc;
3209 }
3210 }
3211
Steve Antondb45ca82017-09-11 18:27:34 -07003212 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003213 senders = pc_->GetSenders();
3214 EXPECT_EQ(2u, senders.size());
3215 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3216 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3217 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3218 // changed.
3219}
3220
3221// This tests that the expected behavior occurs if a new session description is
3222// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003223// Don't run under Unified Plan since the stream API is not available.
3224TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003225 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003226 RTCConfiguration config;
3227 config.enable_dtls_srtp = true;
3228 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003229
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003230 rtc::scoped_refptr<StreamCollection> stream_collection =
3231 CreateStreamCollection(2, 1);
3232 pc_->AddStream(stream_collection->at(0));
3233 std::unique_ptr<SessionDescriptionInterface> offer;
3234 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003235 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003236
deadbeefab9b2d12015-10-14 11:33:11 -07003237 auto senders = pc_->GetSenders();
3238 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003239 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3240 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003241
3242 // Add a new MediaStream but with the same tracks as in the first stream.
3243 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3244 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003245 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3246 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003247 pc_->AddStream(stream_1);
3248
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003249 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003250 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003251
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003252 auto new_senders = pc_->GetSenders();
3253 // Should be the same senders as before, but with updated stream id.
3254 // Note that this behavior is subject to change in the future.
3255 // We may decide the PC should ignore existing tracks in AddStream.
3256 EXPECT_EQ(senders, new_senders);
3257 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3258 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003259}
3260
zhihuang81c3a032016-11-17 12:06:24 -08003261// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003262TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003263 RTCConfiguration config;
3264 config.enable_dtls_srtp = true;
3265 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003266 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3267 EXPECT_EQ(observer_.num_added_tracks_, 1);
3268 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3269
3270 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003271 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003272 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003273 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3274}
3275
deadbeefd1a38b52016-12-10 13:15:33 -08003276// Test that when SetConfiguration is called and the configuration is
3277// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003278TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003279 PeerConnectionInterface::RTCConfiguration config;
3280 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003281 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003282 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003283 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3284 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003285
3286 // Do initial offer/answer so there's something to restart.
3287 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003288 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003289
3290 // Grab the ufrags.
3291 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3292
3293 // Change ICE policy, which should trigger an ICE restart on the next offer.
3294 config.type = PeerConnectionInterface::kAll;
3295 EXPECT_TRUE(pc_->SetConfiguration(config));
3296 CreateOfferAsLocalDescription();
3297
3298 // Grab the new ufrags.
3299 std::vector<std::string> subsequent_ufrags =
3300 GetUfrags(pc_->local_description());
3301
3302 // Sanity check.
3303 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3304 // Check that each ufrag is different.
3305 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3306 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3307 }
3308}
3309
3310// Test that when SetConfiguration is called and the configuration *isn't*
3311// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003312TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003313 PeerConnectionInterface::RTCConfiguration config;
3314 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003315 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003316 config = pc_->GetConfiguration();
3317 AddAudioTrack(kAudioTracks[0]);
3318 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003319
3320 // Do initial offer/answer so there's something to restart.
3321 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003322 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003323
3324 // Grab the ufrags.
3325 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3326
3327 // Call SetConfiguration with a config identical to what the PC was
3328 // constructed with.
3329 EXPECT_TRUE(pc_->SetConfiguration(config));
3330 CreateOfferAsLocalDescription();
3331
3332 // Grab the new ufrags.
3333 std::vector<std::string> subsequent_ufrags =
3334 GetUfrags(pc_->local_description());
3335
3336 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3337}
3338
3339// Test for a weird corner case scenario:
3340// 1. Audio/video session established.
3341// 2. SetConfiguration changes ICE config; ICE restart needed.
3342// 3. ICE restart initiated by remote peer, but only for one m= section.
3343// 4. Next createOffer should initiate an ICE restart, but only for the other
3344// m= section; it would be pointless to do an ICE restart for the m= section
3345// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003346TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003347 PeerConnectionInterface::RTCConfiguration config;
3348 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003349 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003350 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003351 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3352 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003353
3354 // Do initial offer/answer so there's something to restart.
3355 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003356 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003357
3358 // Change ICE policy, which should set the "needs-ice-restart" flag.
3359 config.type = PeerConnectionInterface::kAll;
3360 EXPECT_TRUE(pc_->SetConfiguration(config));
3361
3362 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003363 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003364 webrtc::CreateSessionDescription(SdpType::kOffer,
3365 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003366 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003367 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3368 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003369 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003370 CreateAnswerAsLocalDescription();
3371
3372 // Grab the ufrags.
3373 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003374 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003375
3376 // Create offer and grab the new ufrags.
3377 CreateOfferAsLocalDescription();
3378 std::vector<std::string> subsequent_ufrags =
3379 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003380 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003381
3382 // Ensure that only the ufrag for the second m= section changed.
3383 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3384 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3385}
3386
deadbeeffe4a8a42016-12-20 17:56:17 -08003387// Tests that the methods to return current/pending descriptions work as
3388// expected at different points in the offer/answer exchange. This test does
3389// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003390TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003391 // This disables DTLS so we can apply an answer to ourselves.
3392 CreatePeerConnection();
3393
3394 // Create initial local offer and get SDP (which will also be used as
3395 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003396 std::unique_ptr<SessionDescriptionInterface> local_offer;
3397 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003398 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003399 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003400
3401 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003402 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3403 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3404 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003405 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3406 EXPECT_EQ(nullptr, pc_->current_local_description());
3407 EXPECT_EQ(nullptr, pc_->current_remote_description());
3408
3409 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003410 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003411 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003412 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3413 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3414 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3415 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003416 EXPECT_EQ(nullptr, pc_->current_local_description());
3417 EXPECT_EQ(nullptr, pc_->current_remote_description());
3418
3419 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003420 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003421 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003422 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3423 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003424 EXPECT_EQ(nullptr, pc_->pending_local_description());
3425 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003426 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3427 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003428
3429 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003430 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003431 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003432 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3433 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3434 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003435 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003436 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3437 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003438
3439 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003440 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003441 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003442 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3443 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3444 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3445 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3446 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3447 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003448
3449 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003450 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003451 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003452 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3453 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003454 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3455 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003456 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3457 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003458}
3459
zhihuang77985012017-02-07 15:45:16 -08003460// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3461// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003462// This version tests the StartRtcEventLog version that receives an object
3463// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003464TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003465 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3466 CreatePeerConnection();
3467 // The RtcEventLog will be reset when the PeerConnection is closed.
3468 pc_->Close();
3469
Niels Möllerdec9f742019-06-03 15:25:20 +02003470 EXPECT_FALSE(
3471 pc_->StartRtcEventLog(absl::make_unique<webrtc::RtcEventLogOutputNull>(),
3472 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003473 pc_->StopRtcEventLog();
3474}
3475
deadbeef30952b42017-04-21 02:41:29 -07003476// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003477TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003478 CreatePeerConnection();
3479
3480 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003481 RTCOfferAnswerOptions options;
3482 options.offer_to_receive_audio = 1;
3483 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003484 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003485 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003486 cricket::SessionDescription* desc = offer->description();
3487 ASSERT_EQ(2u, desc->transport_infos().size());
3488 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3489 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3490
3491 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003492 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003493 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003494 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003495 desc = answer->description();
3496 ASSERT_EQ(2u, desc->transport_infos().size());
3497 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3498 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3499}
3500
deadbeef1dcb1642017-03-29 21:08:16 -07003501// Test that ICE renomination isn't offered if it's not enabled in the PC's
3502// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003503TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003504 PeerConnectionInterface::RTCConfiguration config;
3505 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003506 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003507 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003508
3509 std::unique_ptr<SessionDescriptionInterface> offer;
3510 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3511 cricket::SessionDescription* desc = offer->description();
3512 EXPECT_EQ(1u, desc->transport_infos().size());
3513 EXPECT_FALSE(
3514 desc->transport_infos()[0].description.GetIceParameters().renomination);
3515}
3516
3517// Test that the ICE renomination option is present in generated offers/answers
3518// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003519TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003520 PeerConnectionInterface::RTCConfiguration config;
3521 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003522 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003523 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003524
3525 std::unique_ptr<SessionDescriptionInterface> offer;
3526 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3527 cricket::SessionDescription* desc = offer->description();
3528 EXPECT_EQ(1u, desc->transport_infos().size());
3529 EXPECT_TRUE(
3530 desc->transport_infos()[0].description.GetIceParameters().renomination);
3531
3532 // Set the offer as a remote description, then create an answer and ensure it
3533 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003534 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003535 std::unique_ptr<SessionDescriptionInterface> answer;
3536 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3537 desc = answer->description();
3538 EXPECT_EQ(1u, desc->transport_infos().size());
3539 EXPECT_TRUE(
3540 desc->transport_infos()[0].description.GetIceParameters().renomination);
3541}
3542
3543// Test that if CreateOffer is called with the deprecated "offer to receive
3544// audio/video" constraints, they're processed and result in an offer with
3545// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003546TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003547 CreatePeerConnection();
3548
Niels Möllerf06f9232018-08-07 12:32:18 +02003549 RTCOfferAnswerOptions options;
3550 options.offer_to_receive_audio = 1;
3551 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003552 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003553 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003554
3555 cricket::SessionDescription* desc = offer->description();
3556 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3557 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3558 ASSERT_NE(nullptr, audio);
3559 ASSERT_NE(nullptr, video);
3560 EXPECT_FALSE(audio->rejected);
3561 EXPECT_FALSE(video->rejected);
3562}
3563
3564// Test that if CreateAnswer is called with the deprecated "offer to receive
3565// audio/video" constraints, they're processed and can be used to reject an
3566// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003567// Don't run under Unified Plan since this behavior is not supported.
3568TEST_F(PeerConnectionInterfaceTestPlanB,
3569 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003570 CreatePeerConnection();
3571
3572 // First, create an offer with audio/video and apply it as a remote
3573 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003574 RTCOfferAnswerOptions options;
3575 options.offer_to_receive_audio = 1;
3576 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003577 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003578 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003579 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003580
3581 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003582 options.offer_to_receive_audio = 0;
3583 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003584 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003585 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003586
3587 cricket::SessionDescription* desc = answer->description();
3588 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3589 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3590 ASSERT_NE(nullptr, audio);
3591 ASSERT_NE(nullptr, video);
3592 EXPECT_TRUE(audio->rejected);
3593 EXPECT_TRUE(video->rejected);
3594}
3595
deadbeef1dcb1642017-03-29 21:08:16 -07003596// Test that negotiation can succeed with a data channel only, and with the max
3597// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003598#ifdef HAVE_SCTP
3599TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3600#else
3601TEST_P(PeerConnectionInterfaceTest,
3602 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3603#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003604 PeerConnectionInterface::RTCConfiguration config;
3605 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003606 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003607
3608 // First, create an offer with only a data channel and apply it as a remote
3609 // description.
3610 pc_->CreateDataChannel("test", nullptr);
3611 std::unique_ptr<SessionDescriptionInterface> offer;
3612 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003613 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003614
3615 // Create and set answer as well.
3616 std::unique_ptr<SessionDescriptionInterface> answer;
3617 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003618 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003619}
3620
Steve Anton36da6ff2018-02-16 16:04:20 -08003621TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003622 CreatePeerConnection();
3623 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003624 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003625 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3626}
3627
Steve Anton36da6ff2018-02-16 16:04:20 -08003628TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003629 CreatePeerConnection();
3630 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003631 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003632 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3633}
3634
Steve Anton36da6ff2018-02-16 16:04:20 -08003635TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003636 CreatePeerConnection();
3637 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003638 bitrate.min_bitrate_bps = 5;
3639 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003640 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3641}
3642
Steve Anton36da6ff2018-02-16 16:04:20 -08003643TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003644 CreatePeerConnection();
3645 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003646 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003647 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3648}
3649
Steve Anton36da6ff2018-02-16 16:04:20 -08003650TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003651 CreatePeerConnection();
3652 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003653 bitrate.current_bitrate_bps = 10;
3654 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003655 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3656}
3657
Steve Anton36da6ff2018-02-16 16:04:20 -08003658TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003659 CreatePeerConnection();
3660 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003661 bitrate.min_bitrate_bps = 10;
3662 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003663 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3664}
3665
Steve Anton36da6ff2018-02-16 16:04:20 -08003666TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003667 CreatePeerConnection();
3668 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003669 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003670 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3671}
3672
Steve Anton038834f2017-07-14 15:59:59 -07003673// ice_regather_interval_range requires WebRTC to be configured for continual
3674// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003675TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003676 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3677 PeerConnectionInterface::RTCConfiguration config;
3678 config.ice_regather_interval_range.emplace(1000, 2000);
3679 config.continual_gathering_policy =
3680 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3681 CreatePeerConnectionExpectFail(config);
3682}
3683
3684// Ensures that there is no error when ice_regather_interval_range is set with
3685// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003686TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003687 SetIceRegatherIntervalRangeWithContinualGathering) {
3688 PeerConnectionInterface::RTCConfiguration config;
3689 config.ice_regather_interval_range.emplace(1000, 2000);
3690 config.continual_gathering_policy =
3691 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003692 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003693}
3694
Niels Möller0c4f7be2018-05-07 14:01:37 +02003695// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003696// by Call's BitrateConstraints, which comes from the SDP or a default value.
3697// This test checks that a call to SetBitrate with a current bitrate that will
3698// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003699TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003700 CreatePeerConnection();
3701 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003702 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003703 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3704}
3705
zhihuang1c378ed2017-08-17 14:10:50 -07003706// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003707TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003708 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3709 RTCOfferAnswerOptions rtc_options;
3710
3711 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3712 // than kMaxOfferToReceiveMedia should be treated as invalid.
3713 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3714 CreatePeerConnection();
3715 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3716
3717 rtc_options.offer_to_receive_audio =
3718 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3719 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3720}
3721
Steve Anton36da6ff2018-02-16 16:04:20 -08003722TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003723 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3724 RTCOfferAnswerOptions rtc_options;
3725
3726 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3727 // than kMaxOfferToReceiveMedia should be treated as invalid.
3728 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3729 CreatePeerConnection();
3730 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3731
3732 rtc_options.offer_to_receive_video =
3733 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3734 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3735}
3736
3737// Test that the audio and video content will be added to an offer if both
3738// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003739TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003740 RTCOfferAnswerOptions rtc_options;
3741 rtc_options.offer_to_receive_audio = 1;
3742 rtc_options.offer_to_receive_video = 1;
3743
3744 std::unique_ptr<SessionDescriptionInterface> offer;
3745 CreatePeerConnection();
3746 offer = CreateOfferWithOptions(rtc_options);
3747 ASSERT_TRUE(offer);
3748 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3749 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3750}
3751
3752// Test that only audio content will be added to the offer if only
3753// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003754TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003755 RTCOfferAnswerOptions rtc_options;
3756 rtc_options.offer_to_receive_audio = 1;
3757 rtc_options.offer_to_receive_video = 0;
3758
3759 std::unique_ptr<SessionDescriptionInterface> offer;
3760 CreatePeerConnection();
3761 offer = CreateOfferWithOptions(rtc_options);
3762 ASSERT_TRUE(offer);
3763 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3764 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3765}
3766
3767// Test that only video content will be added if only |offer_to_receive_video|
3768// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003769TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003770 RTCOfferAnswerOptions rtc_options;
3771 rtc_options.offer_to_receive_audio = 0;
3772 rtc_options.offer_to_receive_video = 1;
3773
3774 std::unique_ptr<SessionDescriptionInterface> offer;
3775 CreatePeerConnection();
3776 offer = CreateOfferWithOptions(rtc_options);
3777 ASSERT_TRUE(offer);
3778 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3779 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3780}
3781
zhihuang1c378ed2017-08-17 14:10:50 -07003782// Test that no media content will be added to the offer if using default
3783// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003784TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003785 RTCOfferAnswerOptions rtc_options;
3786
3787 std::unique_ptr<SessionDescriptionInterface> offer;
3788 CreatePeerConnection();
3789 offer = CreateOfferWithOptions(rtc_options);
3790 ASSERT_TRUE(offer);
3791 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3792 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3793}
3794
3795// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3796// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003797TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3798 CreatePeerConnection();
3799
zhihuang1c378ed2017-08-17 14:10:50 -07003800 RTCOfferAnswerOptions rtc_options;
3801 rtc_options.ice_restart = false;
3802 rtc_options.offer_to_receive_audio = 1;
3803
3804 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003805 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003806 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3807 auto ufrag1 =
3808 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3809 auto pwd1 =
3810 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003811
3812 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3813 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003814 auto ufrag2 =
3815 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3816 auto pwd2 =
3817 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003818
3819 // |ice_restart| is true, the ufrag/pwd should change.
3820 rtc_options.ice_restart = true;
3821 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003822 auto ufrag3 =
3823 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3824 auto pwd3 =
3825 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003826
3827 EXPECT_EQ(ufrag1, ufrag2);
3828 EXPECT_EQ(pwd1, pwd2);
3829 EXPECT_NE(ufrag2, ufrag3);
3830 EXPECT_NE(pwd2, pwd3);
3831}
3832
3833// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3834// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003835TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003836 RTCOfferAnswerOptions rtc_options;
3837 rtc_options.offer_to_receive_audio = 1;
3838 rtc_options.offer_to_receive_video = 1;
3839
3840 std::unique_ptr<SessionDescriptionInterface> offer;
3841 CreatePeerConnection();
3842
3843 rtc_options.use_rtp_mux = true;
3844 offer = CreateOfferWithOptions(rtc_options);
3845 ASSERT_TRUE(offer);
3846 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3847 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3848 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3849
3850 rtc_options.use_rtp_mux = false;
3851 offer = CreateOfferWithOptions(rtc_options);
3852 ASSERT_TRUE(offer);
3853 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3854 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3855 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3856}
3857
zhihuang141aacb2017-08-29 13:23:53 -07003858// This test ensures OnRenegotiationNeeded is called when we add track with
3859// MediaStream -> AddTrack in the same way it is called when we add track with
3860// PeerConnection -> AddTrack.
3861// The test can be removed once addStream is rewritten in terms of addTrack
3862// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003863// Don't run under Unified Plan since the stream API is not available.
3864TEST_F(PeerConnectionInterfaceTestPlanB,
3865 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003866 CreatePeerConnectionWithoutDtls();
3867 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003868 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003869 pc_->AddStream(stream);
3870 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003871 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003872 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003873 CreateVideoTrack("video_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003874 stream->AddTrack(audio_track);
3875 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3876 observer_.renegotiation_needed_ = false;
3877
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003878 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003879 stream->AddTrack(video_track);
3880 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3881 observer_.renegotiation_needed_ = false;
3882
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003883 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003884 stream->RemoveTrack(audio_track);
3885 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3886 observer_.renegotiation_needed_ = false;
3887
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003888 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003889 stream->RemoveTrack(video_track);
3890 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3891 observer_.renegotiation_needed_ = false;
3892}
3893
Zhi Huangb2d355e2017-10-26 17:26:37 -07003894// Tests that an error is returned if a description is applied that has fewer
3895// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003896TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003897 MediaSectionCountEnforcedForSubsequentOffer) {
3898 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003899 AddAudioTrack("audio_label");
3900 AddVideoTrack("video_label");
3901
Zhi Huangb2d355e2017-10-26 17:26:37 -07003902 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003903 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003904 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3905
3906 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003907 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003908 offer->description()->contents().pop_back();
3909 offer->description()->contents().pop_back();
3910 ASSERT_TRUE(offer->description()->contents().empty());
3911 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3912
3913 std::unique_ptr<SessionDescriptionInterface> answer;
3914 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3915 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3916
3917 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003918 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003919 offer->description()->contents().pop_back();
3920 offer->description()->contents().pop_back();
3921 ASSERT_TRUE(offer->description()->contents().empty());
3922 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3923}
3924
Johannes Kron89f874e2018-11-12 10:25:48 +01003925TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3926 RTCConfiguration config;
3927 // Default behavior is false.
3928 CreatePeerConnection(config);
3929 std::unique_ptr<SessionDescriptionInterface> offer;
3930 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3931 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3932 // Possible to set to true.
3933 config.offer_extmap_allow_mixed = true;
3934 CreatePeerConnection(config);
3935 offer.release();
3936 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3937 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3938}
3939
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003940INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3941 PeerConnectionInterfaceTest,
3942 Values(SdpSemantics::kPlanB,
3943 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003944
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003945class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 02:27:06 -08003946 protected:
3947 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003948 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003949 pcf_->Initialize();
3950 }
nisseeaabdf62017-05-05 02:23:02 -07003951 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003952 const RTCConfiguration& config) {
3953 rtc::scoped_refptr<PeerConnectionInterface> pc(
3954 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003955 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003956 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003957 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003958 }
3959
zhihuang9763d562016-08-05 11:14:50 -07003960 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003961 MockPeerConnectionObserver observer_;
3962};
3963
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003964// This sanity check validates the test infrastructure itself.
3965TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3966 PeerConnectionInterface::RTCConfiguration config;
3967 rtc::scoped_refptr<PeerConnectionInterface> pc(
3968 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3969 EXPECT_TRUE(pc.get());
3970 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3971 pc->Close(); // No abort -> ok.
3972 SUCCEED();
3973}
3974
nisse51542be2016-02-12 02:27:06 -08003975// This test verifies the default behaviour with no constraints and a
3976// default RTCConfiguration.
3977TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3978 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003979
Niels Möllerf06f9232018-08-07 12:32:18 +02003980 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003981
3982 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003983 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3984 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003985 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003986 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003987}
3988
Niels Möller1d7ecd22018-01-18 15:25:12 +01003989// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003990// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003991TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3992 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003993
Niels Möller71bdda02016-03-31 12:59:59 +02003994 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02003995 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003996
Niels Möller1d7ecd22018-01-18 15:25:12 +01003997 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003998}
3999
Niels Möller6539f692018-01-18 08:58:50 +01004000// This test verifies that the experiment_cpu_load_estimator flag is
4001// propagated from RTCConfiguration to the PeerConnection.
4002TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4003 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004004
4005 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004006 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004007
4008 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4009}
4010
deadbeef293e9262017-01-11 12:28:30 -08004011// Tests a few random fields being different.
4012TEST(RTCConfigurationTest, ComparisonOperators) {
4013 PeerConnectionInterface::RTCConfiguration a;
4014 PeerConnectionInterface::RTCConfiguration b;
4015 EXPECT_EQ(a, b);
4016
4017 PeerConnectionInterface::RTCConfiguration c;
4018 c.servers.push_back(PeerConnectionInterface::IceServer());
4019 EXPECT_NE(a, c);
4020
4021 PeerConnectionInterface::RTCConfiguration d;
4022 d.type = PeerConnectionInterface::kRelay;
4023 EXPECT_NE(a, d);
4024
4025 PeerConnectionInterface::RTCConfiguration e;
4026 e.audio_jitter_buffer_max_packets = 5;
4027 EXPECT_NE(a, e);
4028
4029 PeerConnectionInterface::RTCConfiguration f;
4030 f.ice_connection_receiving_timeout = 1337;
4031 EXPECT_NE(a, f);
4032
4033 PeerConnectionInterface::RTCConfiguration g;
4034 g.disable_ipv6 = true;
4035 EXPECT_NE(a, g);
4036
4037 PeerConnectionInterface::RTCConfiguration h(
4038 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4039 EXPECT_NE(a, h);
4040}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01004041
4042} // namespace
4043} // namespace webrtc