blob: 1ea4b7fd59d308b4f2fa7c85cf117eca0c81d958 [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"
Yves Gerey3e707812018-11-28 16:47:49 +010082#include "rtc_base/platform_file.h"
Steve Anton10542f22019-01-11 09:11:00 -080083#include "rtc_base/ref_counted_object.h"
84#include "rtc_base/rtc_certificate_generator.h"
Steve Anton10542f22019-01-11 09:11:00 -080085#include "rtc_base/socket_address.h"
Yves Gerey3e707812018-11-28 16:47:49 +010086#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080087#include "rtc_base/time_utils.h"
88#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020089#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010090#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080091#include "test/testsupport/file_utils.h"
kwibergac9f8762016-09-30 22:29:43 -070092
93#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080094#include "pc/test/android_test_initializer.h"
kwibergac9f8762016-09-30 22:29:43 -070095#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010097namespace webrtc {
98namespace {
99
Seth Hampson845e8782018-03-02 11:34:10 -0800100static const char kStreamId1[] = "local_stream_1";
101static const char kStreamId2[] = "local_stream_2";
102static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103static const int kDefaultStunPort = 3478;
104static const char kStunAddressOnly[] = "stun:address";
105static const char kStunInvalidPort[] = "stun:address:-1";
106static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
107static const char kStunAddressPortAndMore2[] = "stun:address:port more";
Niels Möllerdb4def92019-03-18 16:53:59 +0100108static const char kTurnIceServerUri[] = "turn:turn.example.org";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109static const char kTurnUsername[] = "user";
110static const char kTurnPassword[] = "password";
111static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200112static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113
deadbeefab9b2d12015-10-14 11:33:11 -0700114static const char kStreams[][8] = {"stream1", "stream2"};
115static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
116static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
117
deadbeef5e97fb52015-10-15 12:49:08 -0700118static const char kRecvonly[] = "recvonly";
119static const char kSendrecv[] = "sendrecv";
120
deadbeefab9b2d12015-10-14 11:33:11 -0700121// Reference SDP with a MediaStream with label "stream1" and audio track with
122// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800123static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700124 "v=0\r\n"
125 "o=- 0 0 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800128 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700129 "a=ice-ufrag:e5785931\r\n"
130 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
131 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
132 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700133 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700134 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800135 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700136 "a=rtpmap:103 ISAC/16000\r\n"
137 "a=ssrc:1 cname:stream1\r\n"
138 "a=ssrc:1 mslabel:stream1\r\n"
139 "a=ssrc:1 label:audiotrack0\r\n"
140 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800141 "a=ice-ufrag:e5785931\r\n"
142 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
143 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
144 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700145 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700146 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800147 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700148 "a=rtpmap:120 VP8/90000\r\n"
149 "a=ssrc:2 cname:stream1\r\n"
150 "a=ssrc:2 mslabel:stream1\r\n"
151 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800152// Same string as above but with the MID changed to the Unified Plan default.
153// This is needed so that this SDP can be used as an answer for a Unified Plan
154// offer.
155static const char kSdpStringWithStream1UnifiedPlan[] =
156 "v=0\r\n"
157 "o=- 0 0 IN IP4 127.0.0.1\r\n"
158 "s=-\r\n"
159 "t=0 0\r\n"
160 "m=audio 1 RTP/AVPF 103\r\n"
161 "a=ice-ufrag:e5785931\r\n"
162 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
163 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
164 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
165 "a=mid:0\r\n"
166 "a=sendrecv\r\n"
167 "a=rtcp-mux\r\n"
168 "a=rtpmap:103 ISAC/16000\r\n"
169 "a=ssrc:1 cname:stream1\r\n"
170 "a=ssrc:1 mslabel:stream1\r\n"
171 "a=ssrc:1 label:audiotrack0\r\n"
172 "m=video 1 RTP/AVPF 120\r\n"
173 "a=ice-ufrag:e5785931\r\n"
174 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
175 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
176 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
177 "a=mid:1\r\n"
178 "a=sendrecv\r\n"
179 "a=rtcp-mux\r\n"
180 "a=rtpmap:120 VP8/90000\r\n"
181 "a=ssrc:2 cname:stream1\r\n"
182 "a=ssrc:2 mslabel:stream1\r\n"
183 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700184
zhihuang81c3a032016-11-17 12:06:24 -0800185// Reference SDP with a MediaStream with label "stream1" and audio track with
186// id "audio_1";
187static const char kSdpStringWithStream1AudioTrackOnly[] =
188 "v=0\r\n"
189 "o=- 0 0 IN IP4 127.0.0.1\r\n"
190 "s=-\r\n"
191 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800192 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800193 "a=ice-ufrag:e5785931\r\n"
194 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
195 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
196 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800197 "a=mid:audio\r\n"
198 "a=sendrecv\r\n"
199 "a=rtpmap:103 ISAC/16000\r\n"
200 "a=ssrc:1 cname:stream1\r\n"
201 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800202 "a=ssrc:1 label:audiotrack0\r\n"
203 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800204
deadbeefab9b2d12015-10-14 11:33:11 -0700205// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
206// MediaStreams have one audio track and one video track.
207// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800208static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700209 "v=0\r\n"
210 "o=- 0 0 IN IP4 127.0.0.1\r\n"
211 "s=-\r\n"
212 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800213 "a=msid-semantic: WMS stream1 stream2\r\n"
214 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700215 "a=ice-ufrag:e5785931\r\n"
216 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
217 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
218 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700219 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700220 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800221 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700222 "a=rtpmap:103 ISAC/16000\r\n"
223 "a=ssrc:1 cname:stream1\r\n"
224 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
225 "a=ssrc:3 cname:stream2\r\n"
226 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
227 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800228 "a=ice-ufrag:e5785931\r\n"
229 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
230 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
231 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700232 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700233 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800234 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700235 "a=rtpmap:120 VP8/0\r\n"
236 "a=ssrc:2 cname:stream1\r\n"
237 "a=ssrc:2 msid:stream1 videotrack0\r\n"
238 "a=ssrc:4 cname:stream2\r\n"
239 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800240static const char kSdpStringWithStream1And2UnifiedPlan[] =
241 "v=0\r\n"
242 "o=- 0 0 IN IP4 127.0.0.1\r\n"
243 "s=-\r\n"
244 "t=0 0\r\n"
245 "a=msid-semantic: WMS stream1 stream2\r\n"
246 "m=audio 1 RTP/AVPF 103\r\n"
247 "a=ice-ufrag:e5785931\r\n"
248 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
249 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
250 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
251 "a=mid:0\r\n"
252 "a=sendrecv\r\n"
253 "a=rtcp-mux\r\n"
254 "a=rtpmap:103 ISAC/16000\r\n"
255 "a=ssrc:1 cname:stream1\r\n"
256 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
257 "m=video 1 RTP/AVPF 120\r\n"
258 "a=ice-ufrag:e5785931\r\n"
259 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
260 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
261 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
262 "a=mid:1\r\n"
263 "a=sendrecv\r\n"
264 "a=rtcp-mux\r\n"
265 "a=rtpmap:120 VP8/0\r\n"
266 "a=ssrc:2 cname:stream1\r\n"
267 "a=ssrc:2 msid:stream1 videotrack0\r\n"
268 "m=audio 1 RTP/AVPF 103\r\n"
269 "a=ice-ufrag:e5785931\r\n"
270 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
271 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
272 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
273 "a=mid:2\r\n"
274 "a=sendrecv\r\n"
275 "a=rtcp-mux\r\n"
276 "a=rtpmap:103 ISAC/16000\r\n"
277 "a=ssrc:3 cname:stream2\r\n"
278 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
279 "m=video 1 RTP/AVPF 120\r\n"
280 "a=ice-ufrag:e5785931\r\n"
281 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
282 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
283 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
284 "a=mid:3\r\n"
285 "a=sendrecv\r\n"
286 "a=rtcp-mux\r\n"
287 "a=rtpmap:120 VP8/0\r\n"
288 "a=ssrc:4 cname:stream2\r\n"
289 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700290
291// Reference SDP without MediaStreams. Msid is not supported.
292static const char kSdpStringWithoutStreams[] =
293 "v=0\r\n"
294 "o=- 0 0 IN IP4 127.0.0.1\r\n"
295 "s=-\r\n"
296 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800297 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700298 "a=ice-ufrag:e5785931\r\n"
299 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
300 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
301 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700302 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700303 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800304 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700305 "a=rtpmap:103 ISAC/16000\r\n"
306 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800307 "a=ice-ufrag:e5785931\r\n"
308 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
309 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
310 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700311 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700312 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800313 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700314 "a=rtpmap:120 VP8/90000\r\n";
315
316// Reference SDP without MediaStreams. Msid is supported.
317static const char kSdpStringWithMsidWithoutStreams[] =
318 "v=0\r\n"
319 "o=- 0 0 IN IP4 127.0.0.1\r\n"
320 "s=-\r\n"
321 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800322 "a=msid-semantic: WMS\r\n"
323 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700324 "a=ice-ufrag:e5785931\r\n"
325 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
326 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
327 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700328 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700329 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800330 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700331 "a=rtpmap:103 ISAC/16000\r\n"
332 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800333 "a=ice-ufrag:e5785931\r\n"
334 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
335 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
336 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700337 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700338 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800339 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700340 "a=rtpmap:120 VP8/90000\r\n";
341
342// Reference SDP without MediaStreams and audio only.
343static const char kSdpStringWithoutStreamsAudioOnly[] =
344 "v=0\r\n"
345 "o=- 0 0 IN IP4 127.0.0.1\r\n"
346 "s=-\r\n"
347 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800348 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700349 "a=ice-ufrag:e5785931\r\n"
350 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
351 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
352 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700353 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700354 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800355 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700356 "a=rtpmap:103 ISAC/16000\r\n";
357
358// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
359static const char kSdpStringSendOnlyWithoutStreams[] =
360 "v=0\r\n"
361 "o=- 0 0 IN IP4 127.0.0.1\r\n"
362 "s=-\r\n"
363 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800364 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700365 "a=ice-ufrag:e5785931\r\n"
366 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
367 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
368 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700369 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700370 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700371 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800372 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700373 "a=rtpmap:103 ISAC/16000\r\n"
374 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800375 "a=ice-ufrag:e5785931\r\n"
376 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
377 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
378 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700379 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700380 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700381 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800382 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700383 "a=rtpmap:120 VP8/90000\r\n";
384
385static const char kSdpStringInit[] =
386 "v=0\r\n"
387 "o=- 0 0 IN IP4 127.0.0.1\r\n"
388 "s=-\r\n"
389 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700390 "a=msid-semantic: WMS\r\n";
391
392static const char kSdpStringAudio[] =
393 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800394 "a=ice-ufrag:e5785931\r\n"
395 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
396 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
397 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700398 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700399 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800400 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700401 "a=rtpmap:103 ISAC/16000\r\n";
402
403static const char kSdpStringVideo[] =
404 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800405 "a=ice-ufrag:e5785931\r\n"
406 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
407 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
408 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700409 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700410 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800411 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700412 "a=rtpmap:120 VP8/90000\r\n";
413
414static const char kSdpStringMs1Audio0[] =
415 "a=ssrc:1 cname:stream1\r\n"
416 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
417
418static const char kSdpStringMs1Video0[] =
419 "a=ssrc:2 cname:stream1\r\n"
420 "a=ssrc:2 msid:stream1 videotrack0\r\n";
421
422static const char kSdpStringMs1Audio1[] =
423 "a=ssrc:3 cname:stream1\r\n"
424 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
425
426static const char kSdpStringMs1Video1[] =
427 "a=ssrc:4 cname:stream1\r\n"
428 "a=ssrc:4 msid:stream1 videotrack1\r\n";
429
deadbeef8662f942017-01-20 21:20:51 -0800430static const char kDtlsSdesFallbackSdp[] =
431 "v=0\r\n"
432 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
433 "s=-\r\n"
434 "c=IN IP4 0.0.0.0\r\n"
435 "t=0 0\r\n"
436 "a=group:BUNDLE audio\r\n"
437 "a=msid-semantic: WMS\r\n"
438 "m=audio 1 RTP/SAVPF 0\r\n"
439 "a=sendrecv\r\n"
440 "a=rtcp-mux\r\n"
441 "a=mid:audio\r\n"
442 "a=ssrc:1 cname:stream1\r\n"
443 "a=ssrc:1 mslabel:stream1\r\n"
444 "a=ssrc:1 label:audiotrack0\r\n"
445 "a=ice-ufrag:e5785931\r\n"
446 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
447 "a=rtpmap:0 pcmu/8000\r\n"
448 "a=fingerprint:sha-1 "
449 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
450 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700451 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800452 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
453 "dummy_session_params\r\n";
454
Niels Möllerdec9f742019-06-03 15:25:20 +0200455class RtcEventLogOutputNull final : public RtcEventLogOutput {
456 public:
457 bool IsActive() const override { return true; }
458 bool Write(const std::string& output) override { return true; }
459};
460
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100461using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700462using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800463using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464
Steve Anton36da6ff2018-02-16 16:04:20 -0800465using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
466using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700467
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468// Gets the first ssrc of given content type from the ContentInfo.
469bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
470 if (!content_info || !ssrc) {
471 return false;
472 }
473 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800474 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 if (!media_desc || media_desc->streams().empty()) {
476 return false;
477 }
478 *ssrc = media_desc->streams().begin()->first_ssrc();
479 return true;
480}
481
deadbeefd1a38b52016-12-10 13:15:33 -0800482// Get the ufrags out of an SDP blob. Useful for testing ICE restart
483// behavior.
484std::vector<std::string> GetUfrags(
485 const webrtc::SessionDescriptionInterface* desc) {
486 std::vector<std::string> ufrags;
487 for (const cricket::TransportInfo& info :
488 desc->description()->transport_infos()) {
489 ufrags.push_back(info.description.ice_ufrag);
490 }
491 return ufrags;
492}
493
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494void SetSsrcToZero(std::string* sdp) {
495 const char kSdpSsrcAtribute[] = "a=ssrc:";
496 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
497 size_t ssrc_pos = 0;
498 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200499 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500 size_t end_ssrc = sdp->find(" ", ssrc_pos);
501 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
502 ssrc_pos = end_ssrc;
503 }
504}
505
deadbeefab9b2d12015-10-14 11:33:11 -0700506// Check if |streams| contains the specified track.
507bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800508 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700509 const std::string& track_id) {
510 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800511 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700512 return true;
513 }
514 }
515 return false;
516}
517
518// Check if |senders| contains the specified sender, by id.
519bool ContainsSender(
520 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
521 const std::string& id) {
522 for (const auto& sender : senders) {
523 if (sender->id() == id) {
524 return true;
525 }
526 }
527 return false;
528}
529
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700530// Check if |senders| contains the specified sender, by id and stream id.
531bool ContainsSender(
532 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
533 const std::string& id,
534 const std::string& stream_id) {
535 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700536 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700537 return true;
538 }
539 }
540 return false;
541}
542
deadbeefab9b2d12015-10-14 11:33:11 -0700543// Create a collection of streams.
544// CreateStreamCollection(1) creates a collection that
545// correspond to kSdpStringWithStream1.
546// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
547rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700548 int number_of_streams,
549 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700550 rtc::scoped_refptr<StreamCollection> local_collection(
551 StreamCollection::Create());
552
553 for (int i = 0; i < number_of_streams; ++i) {
554 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
555 webrtc::MediaStream::Create(kStreams[i]));
556
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700557 for (int j = 0; j < tracks_per_stream; ++j) {
558 // Add a local audio track.
559 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
560 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
561 nullptr));
562 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700563
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700564 // Add a local video track.
565 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
566 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700567 webrtc::FakeVideoTrackSource::Create(),
568 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700569 stream->AddTrack(video_track);
570 }
deadbeefab9b2d12015-10-14 11:33:11 -0700571
572 local_collection->AddStream(stream);
573 }
574 return local_collection;
575}
576
577// Check equality of StreamCollections.
578bool CompareStreamCollections(StreamCollectionInterface* s1,
579 StreamCollectionInterface* s2) {
580 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
581 return false;
582 }
583
584 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700585 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700586 return false;
587 }
588 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
589 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
590 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
591 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
592
593 if (audio_tracks1.size() != audio_tracks2.size()) {
594 return false;
595 }
596 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
597 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
598 return false;
599 }
600 }
601 if (video_tracks1.size() != video_tracks2.size()) {
602 return false;
603 }
604 for (size_t j = 0; j != video_tracks1.size(); ++j) {
605 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
606 return false;
607 }
608 }
609 }
610 return true;
611}
612
perkjd61bf802016-03-24 03:16:19 -0700613// Helper class to test Observer.
614class MockTrackObserver : public ObserverInterface {
615 public:
616 explicit MockTrackObserver(NotifierInterface* notifier)
617 : notifier_(notifier) {
618 notifier_->RegisterObserver(this);
619 }
620
621 ~MockTrackObserver() { Unregister(); }
622
623 void Unregister() {
624 if (notifier_) {
625 notifier_->UnregisterObserver(this);
626 notifier_ = nullptr;
627 }
628 }
629
630 MOCK_METHOD0(OnChanged, void());
631
632 private:
633 NotifierInterface* notifier_;
634};
635
nisse528b7932017-05-08 03:21:43 -0700636// The PeerConnectionMediaConfig tests below verify that configuration and
637// constraints are propagated into the PeerConnection's MediaConfig. These
638// settings are intended for MediaChannel constructors, but that is not
639// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700640class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
641 public:
zhihuang38ede132017-06-15 12:52:32 -0700642 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
643 CreatePeerConnectionFactoryForTest() {
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100644 PeerConnectionFactoryDependencies dependencies;
645 dependencies.worker_thread = rtc::Thread::Current();
646 dependencies.network_thread = rtc::Thread::Current();
647 dependencies.signaling_thread = rtc::Thread::Current();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200648 dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
649 cricket::MediaEngineDependencies media_deps;
650 media_deps.task_queue_factory = dependencies.task_queue_factory.get();
henrika919dc2e2017-10-12 14:24:55 +0200651 // Use fake audio device module since we're only testing the interface
652 // level, and using a real one could make tests flaky when run in parallel.
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200653 media_deps.adm = FakeAudioCaptureModule::Create();
654 SetMediaEngineDefaults(&media_deps);
655 dependencies.media_engine =
656 cricket::CreateMediaEngine(std::move(media_deps));
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100657 dependencies.call_factory = webrtc::CreateCallFactory();
Danil Chapovalov9da25bd2019-06-20 10:19:42 +0200658 dependencies.event_log_factory = absl::make_unique<RtcEventLogFactory>(
659 dependencies.task_queue_factory.get());
zhihuang38ede132017-06-15 12:52:32 -0700660
661 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100662 std::move(dependencies));
zhihuang38ede132017-06-15 12:52:32 -0700663 }
664
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100665 using PeerConnectionFactory::PeerConnectionFactory;
kwiberg1e4e8cb2017-01-31 01:48:08 -0800666
Danil Chapovalovf5258be2019-03-19 17:45:24 +0100667 private:
deadbeefd7850b22017-08-23 10:59:19 -0700668 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700669};
670
Steve Anton36da6ff2018-02-16 16:04:20 -0800671// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
Mirko Bonadei6a489f22019-04-09 15:11:12 +0200672class PeerConnectionInterfaceBaseTest : public ::testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800674 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
675 : vss_(new rtc::VirtualSocketServer()),
676 main_(vss_.get()),
677 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800678#ifdef WEBRTC_ANDROID
679 webrtc::InitializeAndroidObjects();
680#endif
681 }
682
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700684 // Use fake audio capture module since we're only testing the interface
685 // level, and using a real one could make tests flaky when run in parallel.
686 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700688 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200689 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
690 fake_audio_capture_module_),
691 webrtc::CreateBuiltinAudioEncoderFactory(),
692 webrtc::CreateBuiltinAudioDecoderFactory(),
693 webrtc::CreateBuiltinVideoEncoderFactory(),
694 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
695 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700696 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700697 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700698 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700699 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 }
701
702 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200703 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 }
705
deadbeef293e9262017-01-11 12:28:30 -0800706 // DTLS does not work in a loopback call, so is disabled for most of the
707 // tests in this file.
708 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200709 RTCConfiguration config;
710 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800711
Niels Möllerf06f9232018-08-07 12:32:18 +0200712 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 }
714
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700715 void CreatePeerConnectionWithIceTransportsType(
716 PeerConnectionInterface::IceTransportsType type) {
717 PeerConnectionInterface::RTCConfiguration config;
718 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200719 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700720 }
721
722 void CreatePeerConnectionWithIceServer(const std::string& uri,
Niels Möllerdb4def92019-03-18 16:53:59 +0100723 const std::string& username,
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700724 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800725 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700727 server.uri = uri;
Niels Möllerdb4def92019-03-18 16:53:59 +0100728 server.username = username;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700729 server.password = password;
730 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200731 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700732 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733
Niels Möllerf06f9232018-08-07 12:32:18 +0200734 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700735 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800736 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
737 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000738
deadbeef1dcb1642017-03-29 21:08:16 -0700739 // Create certificate generator unless DTLS constraint is explicitly set to
740 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200741 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200742
743 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800744 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
745 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000746 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800747 RTCConfiguration modified_config = config;
748 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200749 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200750 modified_config, std::move(port_allocator), std::move(cert_generator),
751 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 ASSERT_TRUE(pc_.get() != NULL);
753 observer_.SetPeerConnectionInterface(pc_.get());
754 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
755 }
756
deadbeef0a6c4ca2015-10-06 11:38:28 -0700757 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800758 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700759 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700760 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800761 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800762 config.sdp_semantics = sdp_semantics_;
763 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200764 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800765 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700766 }
767
Steve Anton038834f2017-07-14 15:59:59 -0700768 void CreatePeerConnectionExpectFail(
769 PeerConnectionInterface::RTCConfiguration config) {
770 PeerConnectionInterface::IceServer server;
771 server.uri = kTurnIceServerUri;
772 server.password = kTurnPassword;
773 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800774 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700775 rtc::scoped_refptr<PeerConnectionInterface> pc =
776 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
777 EXPECT_EQ(nullptr, pc);
778 }
779
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 void CreatePeerConnectionWithDifferentConfigurations() {
Niels Möllerdb4def92019-03-18 16:53:59 +0100781 CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800782 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
783 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
784 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800786 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787
deadbeef0a6c4ca2015-10-06 11:38:28 -0700788 CreatePeerConnectionExpectFail(kStunInvalidPort);
789 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
790 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791
Niels Möllerdb4def92019-03-18 16:53:59 +0100792 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
793 kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800794 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
795 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800797 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800799 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 }
803
804 void ReleasePeerConnection() {
805 pc_ = NULL;
806 observer_.SetPeerConnectionInterface(NULL);
807 }
808
Steve Anton36da6ff2018-02-16 16:04:20 -0800809 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
810 const std::string& label) {
Niels Möller215ba602019-01-18 13:59:45 +0100811 return pc_factory_->CreateVideoTrack(label, FakeVideoTrackSource::Create());
Steve Anton36da6ff2018-02-16 16:04:20 -0800812 }
813
814 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800815 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800816 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800817 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800818 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 }
820
Steve Anton36da6ff2018-02-16 16:04:20 -0800821 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700822 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800824 stream->AddTrack(CreateVideoTrack(label + "v0"));
825 ASSERT_TRUE(pc_->AddStream(stream));
Steve Anton36da6ff2018-02-16 16:04:20 -0800826 }
827
828 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
829 const std::string& label) {
830 return pc_factory_->CreateAudioTrack(label, nullptr);
831 }
832
833 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800834 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800835 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800836 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800837 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
Steve Anton36da6ff2018-02-16 16:04:20 -0800838 }
839
840 void AddAudioStream(const std::string& label) {
841 rtc::scoped_refptr<MediaStreamInterface> stream(
842 pc_factory_->CreateLocalMediaStream(label));
843 stream->AddTrack(CreateAudioTrack(label + "a0"));
844 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 }
846
Seth Hampson845e8782018-03-02 11:34:10 -0800847 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 const std::string& audio_track_label,
849 const std::string& video_track_label) {
850 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700851 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800852 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800853 stream->AddTrack(CreateAudioTrack(audio_track_label));
854 stream->AddTrack(CreateVideoTrack(video_track_label));
855 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 }
857
Steve Anton36da6ff2018-02-16 16:04:20 -0800858 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
859 cricket::MediaType media_type) {
860 for (auto receiver : pc_->GetReceivers()) {
861 if (receiver->media_type() == media_type) {
862 return receiver;
863 }
864 }
865 return nullptr;
866 }
867
kwibergd1fe2812016-04-27 06:47:29 -0700868 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200869 const RTCOfferAnswerOptions* options,
870 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200871 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
872 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200874 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200876 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 }
878 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700879 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 return observer->result();
881 }
882
kwibergd1fe2812016-04-27 06:47:29 -0700883 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200884 const RTCOfferAnswerOptions* options) {
885 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 }
887
kwibergd1fe2812016-04-27 06:47:29 -0700888 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200889 const RTCOfferAnswerOptions* options) {
890 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 }
892
Steve Antondb45ca82017-09-11 18:27:34 -0700893 bool DoSetSessionDescription(
894 std::unique_ptr<SessionDescriptionInterface> desc,
895 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200896 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
897 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700899 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700901 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 }
zhihuang29ff8442016-07-27 11:07:25 -0700903 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
904 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
905 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 return observer->result();
907 }
908
Steve Antondb45ca82017-09-11 18:27:34 -0700909 bool DoSetLocalDescription(
910 std::unique_ptr<SessionDescriptionInterface> desc) {
911 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 }
913
Steve Antondb45ca82017-09-11 18:27:34 -0700914 bool DoSetRemoteDescription(
915 std::unique_ptr<SessionDescriptionInterface> desc) {
916 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 }
918
919 // Calls PeerConnection::GetStats and check the return value.
920 // It does not verify the values in the StatReports since a RTCP packet might
921 // be required.
922 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000923 rtc::scoped_refptr<MockStatsObserver> observer(
924 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200925 if (!pc_->GetStats(observer, track,
926 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 return false;
928 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
929 return observer->called();
930 }
931
Harald Alvestrand89061872018-01-02 14:08:34 +0100932 // Call the standards-compliant GetStats function.
933 bool DoGetRTCStats() {
934 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
935 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
936 pc_->GetStats(callback);
937 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
938 return callback->called();
939 }
940
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800942 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800944 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800945 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800946 } else {
947 // Unified Plan does not support AddStream, so just add an audio and video
948 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800949 AddAudioTrack(kAudioTracks[0], {kStreamId1});
950 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800951 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 CreateOfferReceiveAnswer();
953 }
954
955 // Verify that RTP Header extensions has been negotiated for audio and video.
956 void VerifyRemoteRtpHeaderExtensions() {
957 const cricket::MediaContentDescription* desc =
958 cricket::GetFirstAudioContentDescription(
959 pc_->remote_description()->description());
960 ASSERT_TRUE(desc != NULL);
961 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
962
963 desc = cricket::GetFirstVideoContentDescription(
964 pc_->remote_description()->description());
965 ASSERT_TRUE(desc != NULL);
966 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
967 }
968
969 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700970 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700971 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 std::string sdp;
973 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700974 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800975 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700976 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
978 }
979
deadbeefab9b2d12015-10-14 11:33:11 -0700980 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700981 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800982 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700983 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -0700984 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
985 }
986
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700988 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -0700989 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990
991 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
992 // audio codec change, even if the parameter has nothing to do with
993 // receiving. Not all parameters are serialized to SDP.
994 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
995 // the SessionDescription, it is necessary to do that here to in order to
996 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
997 // https://code.google.com/p/webrtc/issues/detail?id=1356
998 std::string sdp;
999 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001000 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001001 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001002 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1004 }
1005
1006 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001007 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001008 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009
1010 std::string sdp;
1011 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001012 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001013 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001014 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1016 }
1017
1018 void CreateOfferReceiveAnswer() {
1019 CreateOfferAsLocalDescription();
1020 std::string sdp;
1021 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1022 CreateAnswerAsRemoteDescription(sdp);
1023 }
1024
1025 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001026 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001027 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1029 // audio codec change, even if the parameter has nothing to do with
1030 // receiving. Not all parameters are serialized to SDP.
1031 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1032 // the SessionDescription, it is necessary to do that here to in order to
1033 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1034 // https://code.google.com/p/webrtc/issues/detail?id=1356
1035 std::string sdp;
1036 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001037 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001038 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039
Steve Antondb45ca82017-09-11 18:27:34 -07001040 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001042 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001043 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 }
1045
deadbeefab9b2d12015-10-14 11:33:11 -07001046 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001047 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001048 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001049 ASSERT_TRUE(answer);
1050 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1052 }
1053
deadbeefab9b2d12015-10-14 11:33:11 -07001054 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001055 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001056 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001057 ASSERT_TRUE(pr_answer);
1058 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001060 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001061 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001062 ASSERT_TRUE(answer);
1063 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1065 }
1066
Seth Hampson845e8782018-03-02 11:34:10 -08001067 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001068 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001069 // called with the given stream id and expected number of tracks.
1070 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001071 int expected_num_tracks) {
1072 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001073 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001074 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001075 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 }
1077
1078 // Creates an offer and applies it as a local session description.
1079 // Creates an answer with the same SDP an the offer but removes all lines
1080 // that start with a:ssrc"
1081 void CreateOfferReceiveAnswerWithoutSsrc() {
1082 CreateOfferAsLocalDescription();
1083 std::string sdp;
1084 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1085 SetSsrcToZero(&sdp);
1086 CreateAnswerAsRemoteDescription(sdp);
1087 }
1088
deadbeefab9b2d12015-10-14 11:33:11 -07001089 // This function creates a MediaStream with label kStreams[0] and
1090 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1091 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001092 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001093 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001094 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001095 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1096 size_t number_of_video_tracks) {
1097 EXPECT_LE(number_of_audio_tracks, 2u);
1098 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001099
1100 reference_collection_ = StreamCollection::Create();
1101 std::string sdp_ms1 = std::string(kSdpStringInit);
1102
Seth Hampson845e8782018-03-02 11:34:10 -08001103 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001104
1105 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001106 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001107 reference_collection_->AddStream(stream);
1108
1109 if (number_of_audio_tracks > 0) {
1110 sdp_ms1 += std::string(kSdpStringAudio);
1111 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1112 AddAudioTrack(kAudioTracks[0], stream);
1113 }
1114 if (number_of_audio_tracks > 1) {
1115 sdp_ms1 += kSdpStringMs1Audio1;
1116 AddAudioTrack(kAudioTracks[1], stream);
1117 }
1118
1119 if (number_of_video_tracks > 0) {
1120 sdp_ms1 += std::string(kSdpStringVideo);
1121 sdp_ms1 += std::string(kSdpStringMs1Video0);
1122 AddVideoTrack(kVideoTracks[0], stream);
1123 }
1124 if (number_of_video_tracks > 1) {
1125 sdp_ms1 += kSdpStringMs1Video1;
1126 AddVideoTrack(kVideoTracks[1], stream);
1127 }
1128
kwibergd1fe2812016-04-27 06:47:29 -07001129 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001130 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001131 }
1132
1133 void AddAudioTrack(const std::string& track_id,
1134 MediaStreamInterface* stream) {
1135 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1136 webrtc::AudioTrack::Create(track_id, nullptr));
1137 ASSERT_TRUE(stream->AddTrack(audio_track));
1138 }
1139
1140 void AddVideoTrack(const std::string& track_id,
1141 MediaStreamInterface* stream) {
1142 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001143 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001144 webrtc::FakeVideoTrackSource::Create(),
1145 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001146 ASSERT_TRUE(stream->AddTrack(video_track));
1147 }
1148
Steve Anton36da6ff2018-02-16 16:04:20 -08001149 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001150 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001151 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001152 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001153 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1154 return offer;
1155 }
1156
Steve Anton36da6ff2018-02-16 16:04:20 -08001157 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1158 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001159 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001160 std::unique_ptr<SessionDescriptionInterface> offer;
1161 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1162 return offer;
1163 }
1164
1165 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1166 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1167 std::unique_ptr<SessionDescriptionInterface> answer;
1168 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1169 return answer;
1170 }
1171
kwibergfd8be342016-05-14 19:44:11 -07001172 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001173 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001174 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001175 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001176 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1177 return answer;
1178 }
1179
1180 const std::string& GetFirstAudioStreamCname(
1181 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001182 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001183 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001184 return audio_desc->streams()[0].cname;
1185 }
1186
zhihuang1c378ed2017-08-17 14:10:50 -07001187 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1188 const RTCOfferAnswerOptions& offer_answer_options) {
1189 RTC_DCHECK(pc_);
1190 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1191 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1192 pc_->CreateOffer(observer, offer_answer_options);
1193 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1194 return observer->MoveDescription();
1195 }
1196
1197 void CreateOfferWithOptionsAsRemoteDescription(
1198 std::unique_ptr<SessionDescriptionInterface>* desc,
1199 const RTCOfferAnswerOptions& offer_answer_options) {
1200 *desc = CreateOfferWithOptions(offer_answer_options);
1201 ASSERT_TRUE(desc != nullptr);
1202 std::string sdp;
1203 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001204 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001205 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001206 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001207 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1208 }
1209
1210 void CreateOfferWithOptionsAsLocalDescription(
1211 std::unique_ptr<SessionDescriptionInterface>* desc,
1212 const RTCOfferAnswerOptions& offer_answer_options) {
1213 *desc = CreateOfferWithOptions(offer_answer_options);
1214 ASSERT_TRUE(desc != nullptr);
1215 std::string sdp;
1216 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001217 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001218 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001219
Steve Antondb45ca82017-09-11 18:27:34 -07001220 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001221 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1222 }
1223
1224 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001225 RTC_DCHECK(content);
1226 RTC_DCHECK(content->media_description());
1227 for (const cricket::AudioCodec& codec :
1228 content->media_description()->as_audio()->codecs()) {
1229 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001230 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001231 }
zhihuang1c378ed2017-08-17 14:10:50 -07001232 }
1233 return false;
1234 }
1235
Steve Anton36da6ff2018-02-16 16:04:20 -08001236 const char* GetSdpStringWithStream1() const {
1237 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1238 return kSdpStringWithStream1PlanB;
1239 } else {
1240 return kSdpStringWithStream1UnifiedPlan;
1241 }
1242 }
1243
1244 const char* GetSdpStringWithStream1And2() const {
1245 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1246 return kSdpStringWithStream1And2PlanB;
1247 } else {
1248 return kSdpStringWithStream1And2UnifiedPlan;
1249 }
1250 }
1251
deadbeef9a6f4d42017-05-15 19:43:33 -07001252 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1253 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001254 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001255 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001256 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001257 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1258 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1259 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001261 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001262 const SdpSemantics sdp_semantics_;
1263};
1264
1265class PeerConnectionInterfaceTest
1266 : public PeerConnectionInterfaceBaseTest,
1267 public ::testing::WithParamInterface<SdpSemantics> {
1268 protected:
1269 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1270};
1271
1272class PeerConnectionInterfaceTestPlanB
1273 : public PeerConnectionInterfaceBaseTest {
1274 protected:
1275 PeerConnectionInterfaceTestPlanB()
1276 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277};
1278
zhihuang8f65cdf2016-05-06 18:40:30 -07001279// Generate different CNAMEs when PeerConnections are created.
1280// The CNAMEs are expected to be generated randomly. It is possible
1281// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001282TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001283 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001284 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001285 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001286 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001287 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1288 GetFirstAudioStreamCname(offer2.get()));
1289}
1290
Steve Anton36da6ff2018-02-16 16:04:20 -08001291TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001292 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001293 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001294 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001295 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001296 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1297 GetFirstAudioStreamCname(answer2.get()));
1298}
1299
Steve Anton36da6ff2018-02-16 16:04:20 -08001300TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 CreatePeerConnectionWithDifferentConfigurations) {
1302 CreatePeerConnectionWithDifferentConfigurations();
1303}
1304
Steve Anton36da6ff2018-02-16 16:04:20 -08001305TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001306 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1307 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1308 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1309 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1310 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1311 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1312 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1313 port_allocator_->candidate_filter());
1314 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1315 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1316}
1317
1318// Test that when a PeerConnection is created with a nonzero candidate pool
1319// size, the pooled PortAllocatorSession is created with all the attributes
1320// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001321TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001322 PeerConnectionInterface::RTCConfiguration config;
1323 PeerConnectionInterface::IceServer server;
1324 server.uri = kStunAddressOnly;
1325 config.servers.push_back(server);
1326 config.type = PeerConnectionInterface::kRelay;
1327 config.disable_ipv6 = true;
1328 config.tcp_candidate_policy =
1329 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001330 config.candidate_network_policy =
1331 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001332 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001333 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001334
1335 const cricket::FakePortAllocatorSession* session =
1336 static_cast<const cricket::FakePortAllocatorSession*>(
1337 port_allocator_->GetPooledSession());
1338 ASSERT_NE(nullptr, session);
1339 EXPECT_EQ(1UL, session->stun_servers().size());
1340 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1341 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001342 EXPECT_LT(0U,
1343 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001344}
1345
deadbeefd21eab32017-07-26 16:50:11 -07001346// Test that network-related RTCConfiguration members are applied to the
1347// PortAllocator when CreatePeerConnection is called. Specifically:
1348// - disable_ipv6_on_wifi
1349// - max_ipv6_networks
1350// - tcp_candidate_policy
1351// - candidate_network_policy
1352// - prune_turn_ports
1353//
1354// Note that the candidate filter (RTCConfiguration::type) is already tested
1355// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001356TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001357 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1358 // Create fake port allocator.
1359 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1360 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1361 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1362
1363 // Create RTCConfiguration with some network-related fields relevant to
1364 // PortAllocator populated.
1365 PeerConnectionInterface::RTCConfiguration config;
1366 config.disable_ipv6_on_wifi = true;
1367 config.max_ipv6_networks = 10;
1368 config.tcp_candidate_policy =
1369 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1370 config.candidate_network_policy =
1371 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1372 config.prune_turn_ports = true;
1373
1374 // Create the PC factory and PC with the above config.
1375 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1376 webrtc::CreatePeerConnectionFactory(
1377 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001378 rtc::Thread::Current(), fake_audio_capture_module_,
1379 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001380 webrtc::CreateBuiltinAudioDecoderFactory(),
1381 webrtc::CreateBuiltinVideoEncoderFactory(),
1382 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1383 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001384 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001385 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1386 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001387 EXPECT_TRUE(pc.get());
1388 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001389
1390 // Now validate that the config fields set above were applied to the
1391 // PortAllocator, as flags or otherwise.
1392 EXPECT_FALSE(raw_port_allocator->flags() &
1393 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1394 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1395 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1396 EXPECT_TRUE(raw_port_allocator->flags() &
1397 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1398 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1399}
1400
deadbeef46c73892016-11-16 19:42:04 -08001401// Check that GetConfiguration returns the configuration the PeerConnection was
1402// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001403TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001404 PeerConnectionInterface::RTCConfiguration config;
1405 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001406 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001407
1408 PeerConnectionInterface::RTCConfiguration returned_config =
1409 pc_->GetConfiguration();
1410 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1411}
1412
1413// Check that GetConfiguration returns the last configuration passed into
1414// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001415TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001416 PeerConnectionInterface::RTCConfiguration starting_config;
1417 starting_config.bundle_policy =
1418 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1419 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001420
Steve Anton36da6ff2018-02-16 16:04:20 -08001421 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001422 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001423 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001424 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001425 EXPECT_TRUE(pc_->SetConfiguration(config));
1426
1427 PeerConnectionInterface::RTCConfiguration returned_config =
1428 pc_->GetConfiguration();
1429 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001430 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001431 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001432}
1433
Steve Antonc79268f2018-04-24 09:54:10 -07001434TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1435 CreatePeerConnection();
1436
1437 pc_->Close();
1438
1439 EXPECT_FALSE(
1440 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1441}
1442
Steve Anton36da6ff2018-02-16 16:04:20 -08001443TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001444 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001445 AddVideoStream(kStreamId1);
1446 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 ASSERT_EQ(2u, pc_->local_streams()->count());
1448
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001449 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001450 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001451 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001452 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001453 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001454 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001456 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001457 EXPECT_EQ(3u, pc_->local_streams()->count());
1458
1459 // Remove the third stream.
1460 pc_->RemoveStream(pc_->local_streams()->at(2));
1461 EXPECT_EQ(2u, pc_->local_streams()->count());
1462
1463 // Remove the second stream.
1464 pc_->RemoveStream(pc_->local_streams()->at(1));
1465 EXPECT_EQ(1u, pc_->local_streams()->count());
1466
1467 // Remove the first stream.
1468 pc_->RemoveStream(pc_->local_streams()->at(0));
1469 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470}
1471
deadbeefab9b2d12015-10-14 11:33:11 -07001472// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001473// Don't run under Unified Plan since the stream API is not available.
1474TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001475 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001476 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001477 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001478 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001479
deadbeefab9b2d12015-10-14 11:33:11 -07001480 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001481 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001482 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001483
deadbeefab9b2d12015-10-14 11:33:11 -07001484 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001485 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001486 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001487
1488 // Add another stream and ensure the offer includes both the old and new
1489 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001490 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001491 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001492
Steve Antonb1c1de12017-12-21 15:14:30 -08001493 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001494 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1495 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001496
Steve Antonb1c1de12017-12-21 15:14:30 -08001497 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001498 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1499 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001500}
1501
Steve Anton36da6ff2018-02-16 16:04:20 -08001502// Don't run under Unified Plan since the stream API is not available.
1503TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001504 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001505 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 ASSERT_EQ(1u, pc_->local_streams()->count());
1507 pc_->RemoveStream(pc_->local_streams()->at(0));
1508 EXPECT_EQ(0u, pc_->local_streams()->count());
1509}
1510
deadbeefe1f9d832016-01-14 15:35:42 -08001511// Test for AddTrack and RemoveTrack methods.
1512// Tests that the created offer includes tracks we added,
1513// and that the RtpSenders are created correctly.
1514// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001515// Only tested with Plan B since Unified Plan is covered in more detail by tests
1516// in peerconnection_jsep_unittests.cc
1517TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001518 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001519 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001520 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001521 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001522 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001523 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1524 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001525 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001526 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001527 EXPECT_EQ("audio_track", audio_sender->id());
1528 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001529 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001530 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001531 EXPECT_EQ("video_track", video_sender->id());
1532 EXPECT_EQ(video_track, video_sender->track());
1533
1534 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001535 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001536 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001537
1538 const cricket::ContentInfo* audio_content =
1539 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001540 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001541 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001542
1543 const cricket::ContentInfo* video_content =
1544 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001545 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001546 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001547
Steve Antondb45ca82017-09-11 18:27:34 -07001548 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001549
1550 // Now try removing the tracks.
1551 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1552 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1553
1554 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001555 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001556
1557 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001558 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001559 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001560
1561 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001562 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001563 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001564
Steve Antondb45ca82017-09-11 18:27:34 -07001565 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001566
1567 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1568 // should return false.
1569 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1570 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1571}
1572
1573// Test creating senders without a stream specified,
1574// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001575TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001576 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001577 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001578 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001579 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001580 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001581 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001582 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001583 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001584 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001585 EXPECT_EQ("audio_track", audio_sender->id());
1586 EXPECT_EQ(audio_track, audio_sender->track());
1587 EXPECT_EQ("video_track", video_sender->id());
1588 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001589 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1590 // If the ID is truly a random GUID, it should be infinitely unlikely they
1591 // will be the same.
1592 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1593 } else {
1594 // We allows creating tracks without stream ids under Unified Plan
1595 // semantics.
1596 EXPECT_EQ(0u, video_sender->stream_ids().size());
1597 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1598 }
deadbeefe1f9d832016-01-14 15:35:42 -08001599}
1600
Harald Alvestrand89061872018-01-02 14:08:34 +01001601// Test that we can call GetStats() after AddTrack but before connecting
1602// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001603TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001604 CreatePeerConnectionWithoutDtls();
1605 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001606 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001607 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001608 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001609 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1610 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001611 EXPECT_TRUE(DoGetStats(nullptr));
1612}
1613
Steve Anton36da6ff2018-02-16 16:04:20 -08001614TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001615 CreatePeerConnectionWithoutDtls();
1616 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001617 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001618 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001619 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001620 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001621 ASSERT_TRUE(audio_sender.ok());
1622 auto* audio_sender_proxy =
1623 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1624 audio_sender.value().get());
1625 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1626
Harald Alvestrandc72af932018-01-11 17:18:19 +01001627 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001628 ASSERT_TRUE(video_sender.ok());
1629 auto* video_sender_proxy =
1630 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1631 video_sender.value().get());
1632 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001633}
1634
Steve Anton36da6ff2018-02-16 16:04:20 -08001635// Don't run under Unified Plan since the stream API is not available.
1636TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001637 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001638 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001639 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001640 ASSERT_EQ(1u, senders.size());
1641 auto* sender_proxy =
1642 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1643 senders[0].get());
1644 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001645}
1646
Steve Anton36da6ff2018-02-16 16:04:20 -08001647TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001649 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 VerifyRemoteRtpHeaderExtensions();
1651}
1652
Steve Anton36da6ff2018-02-16 16:04:20 -08001653TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001654 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001655 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656 CreateOfferAsLocalDescription();
1657 std::string offer;
1658 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1659 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001660 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661}
1662
Steve Anton36da6ff2018-02-16 16:04:20 -08001663TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001664 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001665 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666
1667 CreateOfferAsRemoteDescription();
1668 CreateAnswerAsLocalDescription();
1669
Seth Hampson845e8782018-03-02 11:34:10 -08001670 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671}
1672
Steve Anton36da6ff2018-02-16 16:04:20 -08001673TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001674 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001675 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676
1677 CreateOfferAsRemoteDescription();
1678 CreatePrAnswerAsLocalDescription();
1679 CreateAnswerAsLocalDescription();
1680
Seth Hampson845e8782018-03-02 11:34:10 -08001681 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682}
1683
Steve Anton36da6ff2018-02-16 16:04:20 -08001684// Don't run under Unified Plan since the stream API is not available.
1685TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 InitiateCall();
1687 ASSERT_EQ(1u, pc_->remote_streams()->count());
1688 pc_->RemoveStream(pc_->local_streams()->at(0));
1689 CreateOfferReceiveAnswer();
1690 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001691 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 CreateOfferReceiveAnswer();
1693}
1694
1695// Tests that after negotiating an audio only call, the respondent can perform a
1696// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001697TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001698 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001699 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 CreateOfferAsRemoteDescription();
1701 CreateAnswerAsLocalDescription();
1702
1703 ASSERT_EQ(1u, pc_->remote_streams()->count());
1704 pc_->RemoveStream(pc_->local_streams()->at(0));
1705 CreateOfferReceiveAnswer();
1706 EXPECT_EQ(0u, pc_->remote_streams()->count());
1707}
1708
1709// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001710TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001711 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712
Steve Antonf1c6db12017-10-13 11:13:35 -07001713 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001715 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001716 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001717 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001718 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719
1720 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001721 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001722 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001723 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724
Steve Antonf1c6db12017-10-13 11:13:35 -07001725 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001726 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727
Steve Antonf1c6db12017-10-13 11:13:35 -07001728 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729}
1730
deadbeefab9b2d12015-10-14 11:33:11 -07001731// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001733TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001734 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001736 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001737 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001738 EXPECT_TRUE(offer);
1739 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740
1741 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001742 AddAudioTrack("track_label", {kStreamId1});
1743 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744
1745 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001746 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747
1748 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001749 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001750 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751}
1752
1753// Test that we will get different SSRCs for each tracks in the offer and answer
1754// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001755TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001756 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001758 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1759 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760
1761 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001762 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001763 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 int audio_ssrc = 0;
1765 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001766 EXPECT_TRUE(
1767 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1768 EXPECT_TRUE(
1769 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 EXPECT_NE(audio_ssrc, video_ssrc);
1771
1772 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001773 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001774 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001775 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 audio_ssrc = 0;
1777 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001778 EXPECT_TRUE(
1779 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1780 EXPECT_TRUE(
1781 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 EXPECT_NE(audio_ssrc, video_ssrc);
1783}
1784
deadbeefeb459812015-12-15 19:24:43 -08001785// Test that it's possible to call AddTrack on a MediaStream after adding
1786// the stream to a PeerConnection.
1787// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001788// Don't run under Unified Plan since the stream API is not available.
1789TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001790 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001791 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001792 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001793 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1794
1795 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001796 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001797 CreateVideoTrack("video_label"));
deadbeefeb459812015-12-15 19:24:43 -08001798 stream->AddTrack(video_track.get());
1799
kwibergd1fe2812016-04-27 06:47:29 -07001800 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001801 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001802
1803 const cricket::MediaContentDescription* video_desc =
1804 cricket::GetFirstVideoContentDescription(offer->description());
1805 EXPECT_TRUE(video_desc != nullptr);
1806}
1807
1808// Test that it's possible to call RemoveTrack on a MediaStream after adding
1809// the stream to a PeerConnection.
1810// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001811// Don't run under Unified Plan since the stream API is not available.
1812TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001813 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001814 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001815 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001816 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1817
1818 // Remove the video track.
1819 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1820
kwibergd1fe2812016-04-27 06:47:29 -07001821 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001822 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001823
1824 const cricket::MediaContentDescription* video_desc =
1825 cricket::GetFirstVideoContentDescription(offer->description());
1826 EXPECT_TRUE(video_desc == nullptr);
1827}
1828
deadbeefbd7d8f72015-12-18 16:58:44 -08001829// Test creating a sender with a stream ID, and ensure the ID is populated
1830// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001831// Don't run under Unified Plan since the stream API is not available.
1832TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001833 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001834 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001835
kwibergd1fe2812016-04-27 06:47:29 -07001836 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001837 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001838
1839 const cricket::MediaContentDescription* video_desc =
1840 cricket::GetFirstVideoContentDescription(offer->description());
1841 ASSERT_TRUE(video_desc != nullptr);
1842 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001843 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001844}
1845
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001847TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001849 ASSERT_LT(0u, pc_->GetSenders().size());
1850 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001851 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001852 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 EXPECT_TRUE(DoGetStats(remote_audio));
1854
1855 // Remove the stream. Since we are sending to our selves the local
1856 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001857 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 // Do a re-negotiation.
1859 CreateOfferReceiveAnswer();
1860
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 // Test that we still can get statistics for the old track. Even if it is not
1862 // sent any longer.
1863 EXPECT_TRUE(DoGetStats(remote_audio));
1864}
1865
1866// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001867TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001869 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1870 ASSERT_TRUE(video_receiver);
1871 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872}
1873
1874// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001875TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001877 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 pc_factory_->CreateAudioTrack("unknown track", NULL));
1879 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1880}
1881
Steve Anton36da6ff2018-02-16 16:04:20 -08001882TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001883 CreatePeerConnectionWithoutDtls();
1884 EXPECT_TRUE(DoGetRTCStats());
1885 // Clearing stats cache is needed now, but should be temporary.
1886 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1887 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001888 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1889 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001890 EXPECT_TRUE(DoGetRTCStats());
1891 pc_->ClearStatsCache();
1892 CreateOfferReceiveAnswer();
1893 EXPECT_TRUE(DoGetRTCStats());
1894}
1895
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001897TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001898 RTCConfiguration config;
1899 config.enable_rtp_data_channel = true;
1900 config.enable_dtls_srtp = false;
1901 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001902 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001904 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 pc_->CreateDataChannel("test2", NULL);
1906 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001907 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001909 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 new MockDataChannelObserver(data2));
1911
1912 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1913 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1914 std::string data_to_send1 = "testing testing";
1915 std::string data_to_send2 = "testing something else";
1916 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1917
1918 CreateOfferReceiveAnswer();
1919 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1920 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1921
1922 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1923 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1924 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1925 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1926
1927 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1928 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1929
1930 data1->Close();
1931 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1932 CreateOfferReceiveAnswer();
1933 EXPECT_FALSE(observer1->IsOpen());
1934 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1935 EXPECT_TRUE(observer2->IsOpen());
1936
1937 data_to_send2 = "testing something else again";
1938 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1939
1940 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1941}
1942
1943// This test verifies that sendnig binary data over RTP data channels should
1944// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001945TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001946 RTCConfiguration config;
1947 config.enable_rtp_data_channel = true;
1948 config.enable_dtls_srtp = false;
1949 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001950 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001952 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953 pc_->CreateDataChannel("test2", NULL);
1954 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001955 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001957 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 new MockDataChannelObserver(data2));
1959
1960 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1961 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1962
1963 CreateOfferReceiveAnswer();
1964 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1965 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1966
1967 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1968 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1969
jbaucheec21bd2016-03-20 06:15:43 -07001970 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001971 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1972}
1973
1974// This test setup a RTP data channels in loop back and test that a channel is
1975// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08001976TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001977 RTCConfiguration config;
1978 config.enable_rtp_data_channel = true;
1979 config.enable_dtls_srtp = false;
1980 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001981 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001983 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 new MockDataChannelObserver(data1));
1985
1986 CreateOfferReceiveAnswerWithoutSsrc();
1987
1988 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1989
1990 data1->Close();
1991 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1992 CreateOfferReceiveAnswerWithoutSsrc();
1993 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1994 EXPECT_FALSE(observer1->IsOpen());
1995}
1996
1997// This test that if a data channel is added in an answer a receive only channel
1998// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001999TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002000 RTCConfiguration config;
2001 config.enable_rtp_data_channel = true;
2002 config.enable_dtls_srtp = false;
2003
2004 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005
2006 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002007 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 pc_->CreateDataChannel(offer_label, NULL);
2009
2010 CreateOfferAsLocalDescription();
2011
2012 // Replace the data channel label in the offer and apply it as an answer.
2013 std::string receive_label = "answer_channel";
2014 std::string sdp;
2015 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002016 absl::StrReplaceAll({{offer_label, receive_label}}, &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 CreateAnswerAsRemoteDescription(sdp);
2018
2019 // Verify that a new incoming data channel has been created and that
2020 // it is open but can't we written to.
2021 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2022 DataChannelInterface* received_channel = observer_.last_datachannel_;
2023 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2024 EXPECT_EQ(receive_label, received_channel->label());
2025 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2026
2027 // Verify that the channel we initially offered has been rejected.
2028 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2029
2030 // Do another offer / answer exchange and verify that the data channel is
2031 // opened.
2032 CreateOfferReceiveAnswer();
2033 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2034 kTimeout);
2035}
2036
2037// This test that no data channel is returned if a reliable channel is
2038// requested.
2039// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002040TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002041 RTCConfiguration rtc_config;
2042 rtc_config.enable_rtp_data_channel = true;
2043 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044
2045 std::string label = "test";
2046 webrtc::DataChannelInit config;
2047 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002048 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 pc_->CreateDataChannel(label, &config);
2050 EXPECT_TRUE(channel == NULL);
2051}
2052
deadbeefab9b2d12015-10-14 11:33:11 -07002053// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002054TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002055 RTCConfiguration config;
2056 config.enable_rtp_data_channel = true;
2057 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002058
2059 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002060 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002061 pc_->CreateDataChannel(label, nullptr);
2062 EXPECT_NE(channel, nullptr);
2063
zhihuang9763d562016-08-05 11:14:50 -07002064 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002065 pc_->CreateDataChannel(label, nullptr);
2066 EXPECT_EQ(dup_channel, nullptr);
2067}
2068
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069// This tests that a SCTP data channel is returned using different
2070// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002071TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002072 RTCConfiguration rtc_config;
2073 rtc_config.enable_dtls_srtp = true;
2074 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075
2076 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002077 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 pc_->CreateDataChannel("1", &config);
2079 EXPECT_TRUE(channel != NULL);
2080 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002081 EXPECT_TRUE(observer_.renegotiation_needed_);
2082 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083
2084 config.ordered = false;
2085 channel = pc_->CreateDataChannel("2", &config);
2086 EXPECT_TRUE(channel != NULL);
2087 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002088 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089
2090 config.ordered = true;
2091 config.maxRetransmits = 0;
2092 channel = pc_->CreateDataChannel("3", &config);
2093 EXPECT_TRUE(channel != NULL);
2094 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002095 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02002097 config.maxRetransmits = absl::nullopt;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 config.maxRetransmitTime = 0;
2099 channel = pc_->CreateDataChannel("4", &config);
2100 EXPECT_TRUE(channel != NULL);
2101 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002102 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103}
2104
Harald Alvestrandf3736ed2019-04-08 13:09:30 +02002105// For backwards compatibility, we want people who "unset" maxRetransmits
2106// and maxRetransmitTime by setting them to -1 to get what they want.
2107TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
2108 RTCConfiguration rtc_config;
2109 rtc_config.enable_dtls_srtp = true;
2110 CreatePeerConnection(rtc_config);
2111
2112 webrtc::DataChannelInit config;
2113 config.maxRetransmitTime = -1;
2114 config.maxRetransmits = -1;
2115 rtc::scoped_refptr<DataChannelInterface> channel =
2116 pc_->CreateDataChannel("1", &config);
2117 EXPECT_TRUE(channel != NULL);
2118}
2119
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120// This tests that no data channel is returned if both maxRetransmits and
2121// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002122TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002124 RTCConfiguration rtc_config;
2125 rtc_config.enable_dtls_srtp = true;
2126 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127
2128 std::string label = "test";
2129 webrtc::DataChannelInit config;
2130 config.maxRetransmits = 0;
2131 config.maxRetransmitTime = 0;
2132
zhihuang9763d562016-08-05 11:14:50 -07002133 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 pc_->CreateDataChannel(label, &config);
2135 EXPECT_TRUE(channel == NULL);
2136}
2137
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138// The test verifies that creating a SCTP data channel with an id already in use
2139// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002140TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002142 RTCConfiguration rtc_config;
2143 rtc_config.enable_dtls_srtp = true;
2144 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145
2146 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002147 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002149 config.id = 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002150 config.negotiated = true;
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002151 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 EXPECT_TRUE(channel != NULL);
2153 EXPECT_EQ(1, channel->id());
2154
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 channel = pc_->CreateDataChannel("x", &config);
2156 EXPECT_TRUE(channel == NULL);
2157
2158 config.id = cricket::kMaxSctpSid;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002159 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 channel = pc_->CreateDataChannel("max", &config);
2161 EXPECT_TRUE(channel != NULL);
2162 EXPECT_EQ(config.id, channel->id());
2163
2164 config.id = cricket::kMaxSctpSid + 1;
Harald Alvestrand5c4d2ee2019-04-01 12:58:15 +02002165 config.negotiated = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 channel = pc_->CreateDataChannel("x", &config);
2167 EXPECT_TRUE(channel == NULL);
2168}
2169
deadbeefab9b2d12015-10-14 11:33:11 -07002170// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002171TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002172 RTCConfiguration rtc_config;
2173 rtc_config.enable_dtls_srtp = true;
2174 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002175
2176 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002177 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002178 pc_->CreateDataChannel(label, nullptr);
2179 EXPECT_NE(channel, nullptr);
2180
zhihuang9763d562016-08-05 11:14:50 -07002181 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002182 pc_->CreateDataChannel(label, nullptr);
2183 EXPECT_NE(dup_channel, nullptr);
2184}
2185
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002186// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2187// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002188TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002189 RTCConfiguration rtc_config;
2190 rtc_config.enable_rtp_data_channel = true;
2191 rtc_config.enable_dtls_srtp = false;
2192 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002193
zhihuang9763d562016-08-05 11:14:50 -07002194 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002195 pc_->CreateDataChannel("test1", NULL);
2196 EXPECT_TRUE(observer_.renegotiation_needed_);
2197 observer_.renegotiation_needed_ = false;
2198
Guido Urdaneta70c2db12019-04-16 12:24:14 +02002199 CreateOfferReceiveAnswer();
2200
zhihuang9763d562016-08-05 11:14:50 -07002201 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002202 pc_->CreateDataChannel("test2", NULL);
Guido Urdaneta70c2db12019-04-16 12:24:14 +02002203 EXPECT_EQ(observer_.renegotiation_needed_,
2204 GetParam() == SdpSemantics::kPlanB);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002205}
2206
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002208TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002209 RTCConfiguration rtc_config;
2210 rtc_config.enable_rtp_data_channel = true;
2211 rtc_config.enable_dtls_srtp = false;
2212 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213
zhihuang9763d562016-08-05 11:14:50 -07002214 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002216 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 pc_->CreateDataChannel("test2", NULL);
2218 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002219 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002221 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222 new MockDataChannelObserver(data2));
2223
2224 CreateOfferReceiveAnswer();
2225 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2226 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2227
2228 ReleasePeerConnection();
2229 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2230 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2231}
2232
Zhi Huang644fde42018-04-02 19:16:26 -07002233// This tests that RTP data channels can be rejected in an answer.
2234TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002235 RTCConfiguration rtc_config;
2236 rtc_config.enable_rtp_data_channel = true;
2237 rtc_config.enable_dtls_srtp = false;
2238 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239
zhihuang9763d562016-08-05 11:14:50 -07002240 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 pc_->CreateDataChannel("offer_channel", NULL));
2242
2243 CreateOfferAsLocalDescription();
2244
2245 // Create an answer where the m-line for data channels are rejected.
2246 std::string sdp;
2247 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002248 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002249 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002250 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002252 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253 data_info->rejected = true;
2254
Steve Antondb45ca82017-09-11 18:27:34 -07002255 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2257}
2258
Zhi Huang644fde42018-04-02 19:16:26 -07002259#ifdef HAVE_SCTP
2260// This tests that SCTP data channels can be rejected in an answer.
2261TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2262#else
2263TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2264#endif
2265{
Niels Möllerf06f9232018-08-07 12:32:18 +02002266 RTCConfiguration rtc_config;
2267 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002268
2269 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2270 pc_->CreateDataChannel("offer_channel", NULL));
2271
2272 CreateOfferAsLocalDescription();
2273
2274 // Create an answer where the m-line for data channels are rejected.
2275 std::string sdp;
2276 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2277 std::unique_ptr<SessionDescriptionInterface> answer(
2278 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2279 ASSERT_TRUE(answer);
2280 cricket::ContentInfo* data_info =
2281 cricket::GetFirstDataContent(answer->description());
2282 data_info->rejected = true;
2283
2284 DoSetRemoteDescription(std::move(answer));
2285 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2286}
2287
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288// Test that we can create a session description from an SDP string from
2289// FireFox, use it as a remote session description, generate an answer and use
2290// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002291TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002292 RTCConfiguration rtc_config;
2293 rtc_config.enable_dtls_srtp = true;
2294 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002295 AddAudioTrack("audio_label");
2296 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002297 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002298 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002299 webrtc::kFireFoxSdpOffer, nullptr));
2300 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 CreateAnswerAsLocalDescription();
2302 ASSERT_TRUE(pc_->local_description() != NULL);
2303 ASSERT_TRUE(pc_->remote_description() != NULL);
2304
2305 const cricket::ContentInfo* content =
2306 cricket::GetFirstAudioContent(pc_->local_description()->description());
2307 ASSERT_TRUE(content != NULL);
2308 EXPECT_FALSE(content->rejected);
2309
2310 content =
2311 cricket::GetFirstVideoContent(pc_->local_description()->description());
2312 ASSERT_TRUE(content != NULL);
2313 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002314#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315 content =
2316 cricket::GetFirstDataContent(pc_->local_description()->description());
2317 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002318 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002319#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320}
2321
zhihuangb19012e2017-09-19 13:47:59 -07002322// Test that fallback from DTLS to SDES is not supported.
2323// The fallback was previously supported but was removed to simplify the code
2324// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002325TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002326 RTCConfiguration rtc_config;
2327 rtc_config.enable_dtls_srtp = true;
2328 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002329 // Wait for fake certificate to be generated. Previously, this is what caused
2330 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002331 AddAudioTrack("audio_label");
2332 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002333 ASSERT_NE(nullptr, fake_certificate_generator_);
2334 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2335 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002336 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002337 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2338 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002339 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002340}
2341
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342// Test that we can create an audio only offer and receive an answer with a
2343// limited set of audio codecs and receive an updated offer with more audio
2344// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002345TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002346 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002347 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 CreateOfferAsLocalDescription();
2349
Steve Anton36da6ff2018-02-16 16:04:20 -08002350 const char* answer_sdp =
2351 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2352 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002353 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002354 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002355 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356
Steve Anton36da6ff2018-02-16 16:04:20 -08002357 const char* reoffer_sdp =
2358 (sdp_semantics_ == SdpSemantics::kPlanB
2359 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2360 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002361 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002362 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002363 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 CreateAnswerAsLocalDescription();
2365}
2366
deadbeefc80741f2015-10-22 13:14:45 -07002367// Test that if we're receiving (but not sending) a track, subsequent offers
2368// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002369TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002370 RTCConfiguration rtc_config;
2371 rtc_config.enable_dtls_srtp = true;
2372 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002373 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002374 CreateAnswerAsLocalDescription();
2375
2376 // At this point we should be receiving stream 1, but not sending anything.
2377 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002378 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002379 DoCreateOffer(&offer, nullptr);
2380
2381 const cricket::ContentInfo* video_content =
2382 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002383 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2384 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002385
2386 const cricket::ContentInfo* audio_content =
2387 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002388 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2389 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002390}
2391
2392// Test that if we're receiving (but not sending) a track, and the
2393// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2394// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002395TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002396 RTCConfiguration rtc_config;
2397 rtc_config.enable_dtls_srtp = true;
2398 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002399 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002400 CreateAnswerAsLocalDescription();
2401
2402 // At this point we should be receiving stream 1, but not sending anything.
2403 // A new offer would be recvonly, but we'll set the "no receive" constraints
2404 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002405 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002406 RTCOfferAnswerOptions options;
2407 options.offer_to_receive_audio = 0;
2408 options.offer_to_receive_video = 0;
2409 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002410
2411 const cricket::ContentInfo* video_content =
2412 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002413 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2414 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002415
2416 const cricket::ContentInfo* audio_content =
2417 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002418 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2419 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002420}
2421
deadbeef653b8e02015-11-11 12:55:10 -08002422// Test that we can use SetConfiguration to change the ICE servers of the
2423// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002424TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002425 CreatePeerConnection();
2426
Steve Anton36da6ff2018-02-16 16:04:20 -08002427 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002428 PeerConnectionInterface::IceServer server;
2429 server.uri = "stun:test_hostname";
2430 config.servers.push_back(server);
2431 EXPECT_TRUE(pc_->SetConfiguration(config));
2432
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002433 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2434 EXPECT_EQ("test_hostname",
2435 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002436}
2437
Steve Anton36da6ff2018-02-16 16:04:20 -08002438TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002439 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002440 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002441 config.type = PeerConnectionInterface::kRelay;
2442 EXPECT_TRUE(pc_->SetConfiguration(config));
2443 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2444}
2445
Steve Anton36da6ff2018-02-16 16:04:20 -08002446TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002447 PeerConnectionInterface::RTCConfiguration config;
2448 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002449 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002450 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002451 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2452
2453 config.prune_turn_ports = true;
2454 EXPECT_TRUE(pc_->SetConfiguration(config));
2455 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2456}
2457
skvladd1f5fda2017-02-03 16:54:05 -08002458// Test that the ice check interval can be changed. This does not verify that
2459// the setting makes it all the way to P2PTransportChannel, as that would
2460// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002461TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002462 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002463 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002464 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002465 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002466 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002467 EXPECT_TRUE(pc_->SetConfiguration(config));
2468 PeerConnectionInterface::RTCConfiguration new_config =
2469 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002470 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002471}
2472
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002473// Test that when SetConfiguration changes both the pool size and other
2474// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002475TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002476 SetConfigurationCreatesPooledSessionCorrectly) {
2477 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002478 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002479 config.ice_candidate_pool_size = 1;
2480 PeerConnectionInterface::IceServer server;
2481 server.uri = kStunAddressOnly;
2482 config.servers.push_back(server);
2483 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002484 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002485
2486 const cricket::FakePortAllocatorSession* session =
2487 static_cast<const cricket::FakePortAllocatorSession*>(
2488 port_allocator_->GetPooledSession());
2489 ASSERT_NE(nullptr, session);
2490 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002491}
2492
deadbeef293e9262017-01-11 12:28:30 -08002493// Test that after SetLocalDescription, changing the pool size is not allowed,
2494// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002495TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002496 CantChangePoolSizeAfterSetLocalDescription) {
2497 CreatePeerConnection();
2498 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002499 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002500 config.ice_candidate_pool_size = 1;
2501 EXPECT_TRUE(pc_->SetConfiguration(config));
2502
2503 // Set remote offer; can still change pool size at this point.
2504 CreateOfferAsRemoteDescription();
2505 config.ice_candidate_pool_size = 2;
2506 EXPECT_TRUE(pc_->SetConfiguration(config));
2507
2508 // Set local answer; now it's too late.
2509 CreateAnswerAsLocalDescription();
2510 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002511 RTCError error;
2512 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2513 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2514}
2515
deadbeef42a42632017-03-10 15:18:00 -08002516// Test that after setting an answer, extra pooled sessions are discarded. The
2517// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002518TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002519 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2520 CreatePeerConnection();
2521
2522 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002523 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002524 config.ice_candidate_pool_size = 4;
2525 EXPECT_TRUE(pc_->SetConfiguration(config));
2526
2527 // Do offer/answer.
2528 CreateOfferAsRemoteDescription();
2529 CreateAnswerAsLocalDescription();
2530
2531 // Expect no pooled sessions to be left.
2532 const cricket::PortAllocatorSession* session =
2533 port_allocator_->GetPooledSession();
2534 EXPECT_EQ(nullptr, session);
2535}
2536
2537// After Close is called, pooled candidates should be discarded so as to not
2538// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002539TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002540 CreatePeerConnection();
2541
Steve Anton36da6ff2018-02-16 16:04:20 -08002542 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002543 config.ice_candidate_pool_size = 3;
2544 EXPECT_TRUE(pc_->SetConfiguration(config));
2545 pc_->Close();
2546
2547 // Expect no pooled sessions to be left.
2548 const cricket::PortAllocatorSession* session =
2549 port_allocator_->GetPooledSession();
2550 EXPECT_EQ(nullptr, session);
2551}
2552
deadbeef293e9262017-01-11 12:28:30 -08002553// Test that SetConfiguration returns an invalid modification error if
2554// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002555TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002556 SetConfigurationReturnsInvalidModificationError) {
2557 PeerConnectionInterface::RTCConfiguration config;
2558 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2559 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2560 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002561 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002562
Steve Anton36da6ff2018-02-16 16:04:20 -08002563 PeerConnectionInterface::RTCConfiguration modified_config =
2564 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002565 modified_config.bundle_policy =
2566 PeerConnectionInterface::kBundlePolicyMaxBundle;
2567 RTCError error;
2568 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2569 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2570
Steve Anton36da6ff2018-02-16 16:04:20 -08002571 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002572 modified_config.rtcp_mux_policy =
2573 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2574 error.set_type(RTCErrorType::NONE);
2575 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2576 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2577
Steve Anton36da6ff2018-02-16 16:04:20 -08002578 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002579 modified_config.continual_gathering_policy =
2580 PeerConnectionInterface::GATHER_CONTINUALLY;
2581 error.set_type(RTCErrorType::NONE);
2582 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2583 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2584}
2585
2586// Test that SetConfiguration returns a range error if the candidate pool size
2587// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002588TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002589 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2590 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002591 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002592 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002593
2594 config.ice_candidate_pool_size = -1;
2595 RTCError error;
2596 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2597 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2598
2599 config.ice_candidate_pool_size = INT_MAX;
2600 error.set_type(RTCErrorType::NONE);
2601 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2602 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2603}
2604
2605// Test that SetConfiguration returns a syntax error if parsing an ICE server
2606// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002607TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002608 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2609 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002610 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002611 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002612
2613 PeerConnectionInterface::IceServer bad_server;
2614 bad_server.uri = "stunn:www.example.com";
2615 config.servers.push_back(bad_server);
2616 RTCError error;
2617 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2618 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2619}
2620
2621// Test that SetConfiguration returns an invalid parameter error if a TURN
2622// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002623TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002624 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2625 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002626 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002627 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002628
2629 PeerConnectionInterface::IceServer bad_server;
2630 bad_server.uri = "turn:www.example.com";
2631 // Missing password.
2632 bad_server.username = "foo";
2633 config.servers.push_back(bad_server);
2634 RTCError error;
2635 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2636 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002637}
2638
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002639// Test that PeerConnection::Close changes the states to closed and all remote
2640// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002641TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642 // Initialize a PeerConnection and negotiate local and remote session
2643 // description.
2644 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002645
2646 // With Plan B, verify the stream count. The analog with Unified Plan is the
2647 // RtpTransceiver count.
2648 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2649 ASSERT_EQ(1u, pc_->local_streams()->count());
2650 ASSERT_EQ(1u, pc_->remote_streams()->count());
2651 } else {
2652 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2653 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654
2655 pc_->Close();
2656
2657 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2658 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2659 pc_->ice_connection_state());
2660 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2661 pc_->ice_gathering_state());
2662
Steve Anton36da6ff2018-02-16 16:04:20 -08002663 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2664 EXPECT_EQ(1u, pc_->local_streams()->count());
2665 EXPECT_EQ(1u, pc_->remote_streams()->count());
2666 } else {
2667 // Verify that the RtpTransceivers are still present but all stopped.
2668 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Mirko Bonadei739baf02019-01-27 17:29:42 +01002669 for (const auto& transceiver : pc_->GetTransceivers()) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002670 EXPECT_TRUE(transceiver->stopped());
2671 }
2672 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673
Steve Anton36da6ff2018-02-16 16:04:20 -08002674 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2675 ASSERT_TRUE(audio_receiver);
2676 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2677 ASSERT_TRUE(video_receiver);
2678
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002679 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002680 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002681 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002682 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002683 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684}
2685
2686// Test that PeerConnection methods fails gracefully after
2687// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002688// Don't run under Unified Plan since the stream API is not available.
2689TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002690 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002691 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692 CreateOfferAsRemoteDescription();
2693 CreateAnswerAsLocalDescription();
2694
2695 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002696 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002697 pc_->local_streams()->at(0);
2698
2699 pc_->Close();
2700
2701 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002702 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002703
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2705
2706 EXPECT_TRUE(pc_->local_description() != NULL);
2707 EXPECT_TRUE(pc_->remote_description() != NULL);
2708
kwibergd1fe2812016-04-27 06:47:29 -07002709 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002710 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002711 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002712 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713
2714 std::string sdp;
2715 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002716 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002717 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002718 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002719
2720 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002721 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002722 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002723 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002724}
2725
2726// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002727TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728 InitiateCall();
2729 pc_->Close();
2730 DoGetStats(NULL);
2731}
deadbeefab9b2d12015-10-14 11:33:11 -07002732
2733// NOTE: The series of tests below come from what used to be
2734// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2735// setting a remote or local description has the expected effects.
2736
2737// This test verifies that the remote MediaStreams corresponding to a received
2738// SDP string is created. In this test the two separate MediaStreams are
2739// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002740TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002741 RTCConfiguration config;
2742 config.enable_dtls_srtp = true;
2743 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002744 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002745
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002746 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002747 EXPECT_TRUE(
2748 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2749 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2750 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2751
2752 // Create a session description based on another SDP with another
2753 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002754 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002755
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002756 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002757 EXPECT_TRUE(
2758 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2759}
2760
2761// This test verifies that when remote tracks are added/removed from SDP, the
2762// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002763// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2764// specific behavior.
2765TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002766 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002767 RTCConfiguration config;
2768 config.enable_dtls_srtp = true;
2769 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002770 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002771 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002772 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002773 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2774 reference_collection_));
2775
2776 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002777 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002778 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002779 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002780 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2781 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002782 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002783 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2784 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002785 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002786 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2787 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002788
2789 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002790 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002791 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002792 MockTrackObserver audio_track_observer(audio_track2);
2793 MockTrackObserver video_track_observer(video_track2);
2794
2795 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2796 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002797 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002798 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2799 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002800 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002801 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002802 audio_track2->state(), kTimeout);
2803 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2804 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002805}
2806
2807// This tests that remote tracks are ended if a local session description is set
2808// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002809TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002810 RTCConfiguration config;
2811 config.enable_dtls_srtp = true;
2812 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002813 // First create and set a remote offer, then reject its video content in our
2814 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002815 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2816 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2817 ASSERT_TRUE(audio_receiver);
2818 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2819 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002820
Steve Anton36da6ff2018-02-16 16:04:20 -08002821 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2822 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002823 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002824 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2825 video_receiver->track();
2826 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002827
kwibergd1fe2812016-04-27 06:47:29 -07002828 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002829 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002830 cricket::ContentInfo* video_info =
2831 local_answer->description()->GetContentByName("video");
2832 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002833 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002834 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2835 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002836
2837 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002838 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002839 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002840 video_info = local_offer->description()->GetContentByName("video");
2841 ASSERT_TRUE(video_info != nullptr);
2842 video_info->rejected = true;
2843 cricket::ContentInfo* audio_info =
2844 local_offer->description()->GetContentByName("audio");
2845 ASSERT_TRUE(audio_info != nullptr);
2846 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002847 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002848 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002849 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2850 kTimeout);
2851 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2852 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002853}
2854
2855// This tests that we won't crash if the remote track has been removed outside
2856// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002857// Don't run under Unified Plan since the stream API is not available.
2858TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002859 RTCConfiguration config;
2860 config.enable_dtls_srtp = true;
2861 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002862 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002863 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2864 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2865 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2866
kwibergd1fe2812016-04-27 06:47:29 -07002867 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002868 webrtc::CreateSessionDescription(SdpType::kAnswer,
2869 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002870 cricket::ContentInfo* video_info =
2871 local_answer->description()->GetContentByName("video");
2872 video_info->rejected = true;
2873 cricket::ContentInfo* audio_info =
2874 local_answer->description()->GetContentByName("audio");
2875 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002876 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002877
2878 // No crash is a pass.
2879}
2880
deadbeef5e97fb52015-10-15 12:49:08 -07002881// This tests that if a recvonly remote description is set, no remote streams
2882// will be created, even if the description contains SSRCs/MSIDs.
2883// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002884TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002885 RTCConfiguration config;
2886 config.enable_dtls_srtp = true;
2887 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002888
Steve Anton36da6ff2018-02-16 16:04:20 -08002889 std::string recvonly_offer = GetSdpStringWithStream1();
Steve Anton1c9c9fc2019-02-14 15:13:09 -08002890 absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
deadbeef5e97fb52015-10-15 12:49:08 -07002891 CreateAndSetRemoteOffer(recvonly_offer);
2892
2893 EXPECT_EQ(0u, observer_.remote_streams()->count());
2894}
2895
deadbeefab9b2d12015-10-14 11:33:11 -07002896// This tests that a default MediaStream is created if a remote session
2897// description doesn't contain any streams and no MSID support.
2898// It also tests that the default stream is updated if a video m-line is added
2899// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002900// Don't run under Unified Plan since this behavior is Plan B specific.
2901TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002902 RTCConfiguration config;
2903 config.enable_dtls_srtp = true;
2904 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002905 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2906
2907 ASSERT_EQ(1u, observer_.remote_streams()->count());
2908 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2909
2910 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2911 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002912 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002913
2914 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2915 ASSERT_EQ(1u, observer_.remote_streams()->count());
2916 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2917 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002918 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2919 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002920 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2921 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002922 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2923 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002924}
2925
2926// This tests that a default MediaStream is created if a remote session
2927// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002928// Don't run under Unified Plan since this behavior is Plan B specific.
2929TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002930 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002931 RTCConfiguration config;
2932 config.enable_dtls_srtp = true;
2933 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002934 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2935
2936 ASSERT_EQ(1u, observer_.remote_streams()->count());
2937 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2938
2939 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2940 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002941 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002942}
2943
2944// This tests that it won't crash when PeerConnection tries to remove
2945// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002946// Don't run under Unified Plan since this behavior is Plan B specific.
2947TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002948 RTCConfiguration config;
2949 config.enable_dtls_srtp = true;
2950 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002951 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002952 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2953 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2954 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2955
2956 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2957
2958 // No crash is a pass.
2959}
2960
2961// This tests that a default MediaStream is created if the remote session
2962// description doesn't contain any streams and don't contain an indication if
2963// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002964// Don't run under Unified Plan since this behavior is Plan B specific.
2965TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002966 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002967 RTCConfiguration config;
2968 config.enable_dtls_srtp = true;
2969 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002970 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2971
2972 ASSERT_EQ(1u, observer_.remote_streams()->count());
2973 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2974 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2975 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2976}
2977
2978// This tests that a default MediaStream is not created if the remote session
2979// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002980// Don't run under Unified Plan since this behavior is Plan B specific.
2981TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002982 RTCConfiguration config;
2983 config.enable_dtls_srtp = true;
2984 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002985 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2986 EXPECT_EQ(0u, observer_.remote_streams()->count());
2987}
2988
deadbeefbda7e0b2015-12-08 17:13:40 -08002989// This tests that when setting a new description, the old default tracks are
2990// not destroyed and recreated.
2991// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002992// Don't run under Unified Plan since this behavior is Plan B specific.
2993TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002994 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002995 RTCConfiguration config;
2996 config.enable_dtls_srtp = true;
2997 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08002998 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2999
3000 ASSERT_EQ(1u, observer_.remote_streams()->count());
3001 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3002 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3003
3004 // Set the track to "disabled", then set a new description and ensure the
3005 // track is still disabled, which ensures it hasn't been recreated.
3006 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3007 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3008 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3009 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3010}
3011
deadbeefab9b2d12015-10-14 11:33:11 -07003012// This tests that a default MediaStream is not created if a remote session
3013// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003014// Don't run under Unified Plan since this behavior is Plan B specific.
3015TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003016 RTCConfiguration config;
3017 config.enable_dtls_srtp = true;
3018 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003019 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003020 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003021 EXPECT_TRUE(
3022 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3023
3024 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3025 EXPECT_EQ(0u, observer_.remote_streams()->count());
3026}
3027
Seth Hampson5897a6e2018-04-03 11:16:33 -07003028// This tests that a default MediaStream is created if a remote SDP comes from
3029// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3030TEST_F(PeerConnectionInterfaceTestPlanB,
3031 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003032 RTCConfiguration config;
3033 config.enable_dtls_srtp = true;
3034 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003035 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3036 // Add a=msid lines to simulate a Unified Plan endpoint that only
3037 // signals stream IDs with a=msid lines.
3038 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3039
3040 CreateAndSetRemoteOffer(sdp_string);
3041
3042 ASSERT_EQ(1u, observer_.remote_streams()->count());
3043 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3044 EXPECT_EQ("default", remote_stream->id());
3045 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3046}
3047
Seth Hampson5b4f0752018-04-02 16:31:36 -07003048// This tests that when a Plan B endpoint receives an SDP that signals no media
3049// stream IDs indicated by the special character "-" in the a=msid line, that
3050// a default stream ID will be used for the MediaStream ID. This can occur
3051// when a Unified Plan endpoint signals no media stream IDs, but signals both
3052// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3053TEST_F(PeerConnectionInterfaceTestPlanB,
3054 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003055 RTCConfiguration config;
3056 config.enable_dtls_srtp = true;
3057 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003058 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3059 // the sender's stream ID will be interpreted as no stream IDs.
3060 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3061 sdp_string.append("a=msid:- audiotrack0\n");
3062
3063 CreateAndSetRemoteOffer(sdp_string);
3064
3065 ASSERT_EQ(1u, observer_.remote_streams()->count());
3066 // Because SSRCs are signaled the track ID will be what was signaled in the
3067 // a=msid line.
3068 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3069 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3070 EXPECT_EQ("default", remote_stream->id());
3071 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003072
3073 // Previously a bug ocurred when setting the remote description a second time.
3074 // This is because we checked equality of the remote StreamParams stream ID
3075 // (empty), and the previously set stream ID for the remote sender
3076 // ("default"). This cause a track to be removed, then added, when really
3077 // nothing should occur because it is the same track.
3078 CreateAndSetRemoteOffer(sdp_string);
3079 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3080 EXPECT_EQ(1u, observer_.add_track_events_.size());
3081 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3082 remote_stream = observer_.remote_streams()->at(0);
3083 EXPECT_EQ("default", remote_stream->id());
3084 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003085}
3086
deadbeefab9b2d12015-10-14 11:33:11 -07003087// This tests that an RtpSender is created when the local description is set
3088// after adding a local stream.
3089// TODO(deadbeef): This test and the one below it need to be updated when
3090// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003091// Don't run under Unified Plan since this behavior is Plan B specific.
3092TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003093 RTCConfiguration config;
3094 config.enable_dtls_srtp = true;
3095 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003096
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003097 // Create an offer with 1 stream with 2 tracks of each type.
3098 rtc::scoped_refptr<StreamCollection> stream_collection =
3099 CreateStreamCollection(1, 2);
3100 pc_->AddStream(stream_collection->at(0));
3101 std::unique_ptr<SessionDescriptionInterface> offer;
3102 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003103 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003104
deadbeefab9b2d12015-10-14 11:33:11 -07003105 auto senders = pc_->GetSenders();
3106 EXPECT_EQ(4u, senders.size());
3107 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3108 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3109 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3110 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3111
3112 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003113 pc_->RemoveStream(stream_collection->at(0));
3114 stream_collection = CreateStreamCollection(1, 1);
3115 pc_->AddStream(stream_collection->at(0));
3116 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003117 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003118
deadbeefab9b2d12015-10-14 11:33:11 -07003119 senders = pc_->GetSenders();
3120 EXPECT_EQ(2u, senders.size());
3121 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3122 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3123 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3124 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3125}
3126
3127// This tests that an RtpSender is created when the local description is set
3128// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003129// Don't run under Unified Plan since this behavior is Plan B specific.
3130TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003131 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003132 RTCConfiguration config;
3133 config.enable_dtls_srtp = true;
3134 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003135
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003136 rtc::scoped_refptr<StreamCollection> stream_collection =
3137 CreateStreamCollection(1, 2);
3138 // Add a stream to create the offer, but remove it afterwards.
3139 pc_->AddStream(stream_collection->at(0));
3140 std::unique_ptr<SessionDescriptionInterface> offer;
3141 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3142 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003143
Steve Antondb45ca82017-09-11 18:27:34 -07003144 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003145 auto senders = pc_->GetSenders();
3146 EXPECT_EQ(0u, senders.size());
3147
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003148 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003149 senders = pc_->GetSenders();
3150 EXPECT_EQ(4u, senders.size());
3151 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3152 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3153 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3154 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3155}
3156
3157// This tests that the expected behavior occurs if the SSRC on a local track is
3158// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003159TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003160 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003161 RTCConfiguration config;
3162 config.enable_dtls_srtp = true;
3163 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003164
Steve Anton36da6ff2018-02-16 16:04:20 -08003165 AddAudioTrack(kAudioTracks[0]);
3166 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003167 std::unique_ptr<SessionDescriptionInterface> offer;
3168 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3169 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003170 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3171 webrtc::CreateSessionDescription(
3172 webrtc::SdpType::kOffer, offer->session_id(),
Harald Alvestrand4d7160e2019-04-12 07:01:29 +02003173 offer->session_version(), offer->description()->Clone());
Steve Antondb45ca82017-09-11 18:27:34 -07003174 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003175
deadbeefab9b2d12015-10-14 11:33:11 -07003176 auto senders = pc_->GetSenders();
3177 EXPECT_EQ(2u, senders.size());
3178 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3179 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3180
3181 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003182 cricket::MediaContentDescription* desc =
3183 cricket::GetFirstAudioContentDescription(modified_offer->description());
3184 ASSERT_TRUE(desc != NULL);
3185 for (StreamParams& stream : desc->mutable_streams()) {
3186 for (unsigned int& ssrc : stream.ssrcs) {
3187 ++ssrc;
3188 }
3189 }
deadbeefab9b2d12015-10-14 11:33:11 -07003190
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003191 desc =
3192 cricket::GetFirstVideoContentDescription(modified_offer->description());
3193 ASSERT_TRUE(desc != NULL);
3194 for (StreamParams& stream : desc->mutable_streams()) {
3195 for (unsigned int& ssrc : stream.ssrcs) {
3196 ++ssrc;
3197 }
3198 }
3199
Steve Antondb45ca82017-09-11 18:27:34 -07003200 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003201 senders = pc_->GetSenders();
3202 EXPECT_EQ(2u, senders.size());
3203 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3204 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3205 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3206 // changed.
3207}
3208
3209// This tests that the expected behavior occurs if a new session description is
3210// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003211// Don't run under Unified Plan since the stream API is not available.
3212TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003213 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003214 RTCConfiguration config;
3215 config.enable_dtls_srtp = true;
3216 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003217
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003218 rtc::scoped_refptr<StreamCollection> stream_collection =
3219 CreateStreamCollection(2, 1);
3220 pc_->AddStream(stream_collection->at(0));
3221 std::unique_ptr<SessionDescriptionInterface> offer;
3222 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003223 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003224
deadbeefab9b2d12015-10-14 11:33:11 -07003225 auto senders = pc_->GetSenders();
3226 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003227 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3228 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003229
3230 // Add a new MediaStream but with the same tracks as in the first stream.
3231 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3232 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003233 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3234 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003235 pc_->AddStream(stream_1);
3236
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003237 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003238 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003239
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003240 auto new_senders = pc_->GetSenders();
3241 // Should be the same senders as before, but with updated stream id.
3242 // Note that this behavior is subject to change in the future.
3243 // We may decide the PC should ignore existing tracks in AddStream.
3244 EXPECT_EQ(senders, new_senders);
3245 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3246 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003247}
3248
zhihuang81c3a032016-11-17 12:06:24 -08003249// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003250TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003251 RTCConfiguration config;
3252 config.enable_dtls_srtp = true;
3253 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003254 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3255 EXPECT_EQ(observer_.num_added_tracks_, 1);
3256 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3257
3258 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003259 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003260 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003261 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3262}
3263
deadbeefd1a38b52016-12-10 13:15:33 -08003264// Test that when SetConfiguration is called and the configuration is
3265// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003266TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003267 PeerConnectionInterface::RTCConfiguration config;
3268 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003269 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003270 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003271 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3272 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003273
3274 // Do initial offer/answer so there's something to restart.
3275 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003276 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003277
3278 // Grab the ufrags.
3279 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3280
3281 // Change ICE policy, which should trigger an ICE restart on the next offer.
3282 config.type = PeerConnectionInterface::kAll;
3283 EXPECT_TRUE(pc_->SetConfiguration(config));
3284 CreateOfferAsLocalDescription();
3285
3286 // Grab the new ufrags.
3287 std::vector<std::string> subsequent_ufrags =
3288 GetUfrags(pc_->local_description());
3289
3290 // Sanity check.
3291 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3292 // Check that each ufrag is different.
3293 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3294 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3295 }
3296}
3297
3298// Test that when SetConfiguration is called and the configuration *isn't*
3299// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003300TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003301 PeerConnectionInterface::RTCConfiguration config;
3302 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003303 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003304 config = pc_->GetConfiguration();
3305 AddAudioTrack(kAudioTracks[0]);
3306 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003307
3308 // Do initial offer/answer so there's something to restart.
3309 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003310 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003311
3312 // Grab the ufrags.
3313 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3314
3315 // Call SetConfiguration with a config identical to what the PC was
3316 // constructed with.
3317 EXPECT_TRUE(pc_->SetConfiguration(config));
3318 CreateOfferAsLocalDescription();
3319
3320 // Grab the new ufrags.
3321 std::vector<std::string> subsequent_ufrags =
3322 GetUfrags(pc_->local_description());
3323
3324 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3325}
3326
3327// Test for a weird corner case scenario:
3328// 1. Audio/video session established.
3329// 2. SetConfiguration changes ICE config; ICE restart needed.
3330// 3. ICE restart initiated by remote peer, but only for one m= section.
3331// 4. Next createOffer should initiate an ICE restart, but only for the other
3332// m= section; it would be pointless to do an ICE restart for the m= section
3333// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003334TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003335 PeerConnectionInterface::RTCConfiguration config;
3336 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003337 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003338 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003339 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3340 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003341
3342 // Do initial offer/answer so there's something to restart.
3343 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003344 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003345
3346 // Change ICE policy, which should set the "needs-ice-restart" flag.
3347 config.type = PeerConnectionInterface::kAll;
3348 EXPECT_TRUE(pc_->SetConfiguration(config));
3349
3350 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003351 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003352 webrtc::CreateSessionDescription(SdpType::kOffer,
3353 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003354 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003355 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3356 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003357 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003358 CreateAnswerAsLocalDescription();
3359
3360 // Grab the ufrags.
3361 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003362 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003363
3364 // Create offer and grab the new ufrags.
3365 CreateOfferAsLocalDescription();
3366 std::vector<std::string> subsequent_ufrags =
3367 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003368 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003369
3370 // Ensure that only the ufrag for the second m= section changed.
3371 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3372 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3373}
3374
deadbeeffe4a8a42016-12-20 17:56:17 -08003375// Tests that the methods to return current/pending descriptions work as
3376// expected at different points in the offer/answer exchange. This test does
3377// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003378TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003379 // This disables DTLS so we can apply an answer to ourselves.
3380 CreatePeerConnection();
3381
3382 // Create initial local offer and get SDP (which will also be used as
3383 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003384 std::unique_ptr<SessionDescriptionInterface> local_offer;
3385 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003386 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003387 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003388
3389 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003390 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3391 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3392 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003393 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3394 EXPECT_EQ(nullptr, pc_->current_local_description());
3395 EXPECT_EQ(nullptr, pc_->current_remote_description());
3396
3397 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003398 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003399 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003400 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3401 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3402 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3403 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003404 EXPECT_EQ(nullptr, pc_->current_local_description());
3405 EXPECT_EQ(nullptr, pc_->current_remote_description());
3406
3407 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003408 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003409 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003410 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3411 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003412 EXPECT_EQ(nullptr, pc_->pending_local_description());
3413 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003414 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3415 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003416
3417 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003418 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003419 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003420 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3421 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3422 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003423 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003424 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3425 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003426
3427 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003428 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003429 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003430 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3431 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3432 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3433 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3434 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3435 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003436
3437 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003438 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003439 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003440 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3441 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003442 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3443 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003444 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3445 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003446}
3447
zhihuang77985012017-02-07 15:45:16 -08003448// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3449// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003450// This version tests the StartRtcEventLog version that receives an object
3451// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003452TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003453 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3454 CreatePeerConnection();
3455 // The RtcEventLog will be reset when the PeerConnection is closed.
3456 pc_->Close();
3457
Niels Möllerdec9f742019-06-03 15:25:20 +02003458 EXPECT_FALSE(
3459 pc_->StartRtcEventLog(absl::make_unique<webrtc::RtcEventLogOutputNull>(),
3460 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003461 pc_->StopRtcEventLog();
3462}
3463
deadbeef30952b42017-04-21 02:41:29 -07003464// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003465TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003466 CreatePeerConnection();
3467
3468 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003469 RTCOfferAnswerOptions options;
3470 options.offer_to_receive_audio = 1;
3471 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003472 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003473 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003474 cricket::SessionDescription* desc = offer->description();
3475 ASSERT_EQ(2u, desc->transport_infos().size());
3476 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3477 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3478
3479 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003480 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003481 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003482 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003483 desc = answer->description();
3484 ASSERT_EQ(2u, desc->transport_infos().size());
3485 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3486 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3487}
3488
deadbeef1dcb1642017-03-29 21:08:16 -07003489// Test that ICE renomination isn't offered if it's not enabled in the PC's
3490// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003491TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003492 PeerConnectionInterface::RTCConfiguration config;
3493 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003494 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003495 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003496
3497 std::unique_ptr<SessionDescriptionInterface> offer;
3498 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3499 cricket::SessionDescription* desc = offer->description();
3500 EXPECT_EQ(1u, desc->transport_infos().size());
3501 EXPECT_FALSE(
3502 desc->transport_infos()[0].description.GetIceParameters().renomination);
3503}
3504
3505// Test that the ICE renomination option is present in generated offers/answers
3506// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003507TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003508 PeerConnectionInterface::RTCConfiguration config;
3509 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003510 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003511 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003512
3513 std::unique_ptr<SessionDescriptionInterface> offer;
3514 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3515 cricket::SessionDescription* desc = offer->description();
3516 EXPECT_EQ(1u, desc->transport_infos().size());
3517 EXPECT_TRUE(
3518 desc->transport_infos()[0].description.GetIceParameters().renomination);
3519
3520 // Set the offer as a remote description, then create an answer and ensure it
3521 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003522 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003523 std::unique_ptr<SessionDescriptionInterface> answer;
3524 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3525 desc = answer->description();
3526 EXPECT_EQ(1u, desc->transport_infos().size());
3527 EXPECT_TRUE(
3528 desc->transport_infos()[0].description.GetIceParameters().renomination);
3529}
3530
3531// Test that if CreateOffer is called with the deprecated "offer to receive
3532// audio/video" constraints, they're processed and result in an offer with
3533// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003534TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003535 CreatePeerConnection();
3536
Niels Möllerf06f9232018-08-07 12:32:18 +02003537 RTCOfferAnswerOptions options;
3538 options.offer_to_receive_audio = 1;
3539 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003540 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003541 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003542
3543 cricket::SessionDescription* desc = offer->description();
3544 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3545 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3546 ASSERT_NE(nullptr, audio);
3547 ASSERT_NE(nullptr, video);
3548 EXPECT_FALSE(audio->rejected);
3549 EXPECT_FALSE(video->rejected);
3550}
3551
3552// Test that if CreateAnswer is called with the deprecated "offer to receive
3553// audio/video" constraints, they're processed and can be used to reject an
3554// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003555// Don't run under Unified Plan since this behavior is not supported.
3556TEST_F(PeerConnectionInterfaceTestPlanB,
3557 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003558 CreatePeerConnection();
3559
3560 // First, create an offer with audio/video and apply it as a remote
3561 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003562 RTCOfferAnswerOptions options;
3563 options.offer_to_receive_audio = 1;
3564 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003565 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003566 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003567 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003568
3569 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003570 options.offer_to_receive_audio = 0;
3571 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003572 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003573 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003574
3575 cricket::SessionDescription* desc = answer->description();
3576 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3577 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3578 ASSERT_NE(nullptr, audio);
3579 ASSERT_NE(nullptr, video);
3580 EXPECT_TRUE(audio->rejected);
3581 EXPECT_TRUE(video->rejected);
3582}
3583
deadbeef1dcb1642017-03-29 21:08:16 -07003584// Test that negotiation can succeed with a data channel only, and with the max
3585// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003586#ifdef HAVE_SCTP
3587TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3588#else
3589TEST_P(PeerConnectionInterfaceTest,
3590 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3591#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003592 PeerConnectionInterface::RTCConfiguration config;
3593 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003594 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003595
3596 // First, create an offer with only a data channel and apply it as a remote
3597 // description.
3598 pc_->CreateDataChannel("test", nullptr);
3599 std::unique_ptr<SessionDescriptionInterface> offer;
3600 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003601 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003602
3603 // Create and set answer as well.
3604 std::unique_ptr<SessionDescriptionInterface> answer;
3605 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003606 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003607}
3608
Steve Anton36da6ff2018-02-16 16:04:20 -08003609TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003610 CreatePeerConnection();
3611 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003612 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003613 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3614}
3615
Steve Anton36da6ff2018-02-16 16:04:20 -08003616TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003617 CreatePeerConnection();
3618 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003619 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003620 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3621}
3622
Steve Anton36da6ff2018-02-16 16:04:20 -08003623TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003624 CreatePeerConnection();
3625 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003626 bitrate.min_bitrate_bps = 5;
3627 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003628 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3629}
3630
Steve Anton36da6ff2018-02-16 16:04:20 -08003631TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003632 CreatePeerConnection();
3633 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003634 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003635 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3636}
3637
Steve Anton36da6ff2018-02-16 16:04:20 -08003638TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003639 CreatePeerConnection();
3640 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003641 bitrate.current_bitrate_bps = 10;
3642 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003643 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3644}
3645
Steve Anton36da6ff2018-02-16 16:04:20 -08003646TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003647 CreatePeerConnection();
3648 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003649 bitrate.min_bitrate_bps = 10;
3650 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003651 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3652}
3653
Steve Anton36da6ff2018-02-16 16:04:20 -08003654TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003655 CreatePeerConnection();
3656 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003657 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003658 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3659}
3660
Steve Anton038834f2017-07-14 15:59:59 -07003661// ice_regather_interval_range requires WebRTC to be configured for continual
3662// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003663TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003664 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3665 PeerConnectionInterface::RTCConfiguration config;
3666 config.ice_regather_interval_range.emplace(1000, 2000);
3667 config.continual_gathering_policy =
3668 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3669 CreatePeerConnectionExpectFail(config);
3670}
3671
3672// Ensures that there is no error when ice_regather_interval_range is set with
3673// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003674TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003675 SetIceRegatherIntervalRangeWithContinualGathering) {
3676 PeerConnectionInterface::RTCConfiguration config;
3677 config.ice_regather_interval_range.emplace(1000, 2000);
3678 config.continual_gathering_policy =
3679 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003680 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003681}
3682
Niels Möller0c4f7be2018-05-07 14:01:37 +02003683// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003684// by Call's BitrateConstraints, which comes from the SDP or a default value.
3685// This test checks that a call to SetBitrate with a current bitrate that will
3686// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003687TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003688 CreatePeerConnection();
3689 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003690 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003691 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3692}
3693
zhihuang1c378ed2017-08-17 14:10:50 -07003694// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003695TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003696 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3697 RTCOfferAnswerOptions rtc_options;
3698
3699 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3700 // than kMaxOfferToReceiveMedia should be treated as invalid.
3701 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3702 CreatePeerConnection();
3703 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3704
3705 rtc_options.offer_to_receive_audio =
3706 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3707 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3708}
3709
Steve Anton36da6ff2018-02-16 16:04:20 -08003710TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003711 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3712 RTCOfferAnswerOptions rtc_options;
3713
3714 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3715 // than kMaxOfferToReceiveMedia should be treated as invalid.
3716 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3717 CreatePeerConnection();
3718 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3719
3720 rtc_options.offer_to_receive_video =
3721 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3722 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3723}
3724
3725// Test that the audio and video content will be added to an offer if both
3726// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003727TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003728 RTCOfferAnswerOptions rtc_options;
3729 rtc_options.offer_to_receive_audio = 1;
3730 rtc_options.offer_to_receive_video = 1;
3731
3732 std::unique_ptr<SessionDescriptionInterface> offer;
3733 CreatePeerConnection();
3734 offer = CreateOfferWithOptions(rtc_options);
3735 ASSERT_TRUE(offer);
3736 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3737 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3738}
3739
3740// Test that only audio content will be added to the offer if only
3741// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003742TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003743 RTCOfferAnswerOptions rtc_options;
3744 rtc_options.offer_to_receive_audio = 1;
3745 rtc_options.offer_to_receive_video = 0;
3746
3747 std::unique_ptr<SessionDescriptionInterface> offer;
3748 CreatePeerConnection();
3749 offer = CreateOfferWithOptions(rtc_options);
3750 ASSERT_TRUE(offer);
3751 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3752 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3753}
3754
3755// Test that only video content will be added if only |offer_to_receive_video|
3756// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003757TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003758 RTCOfferAnswerOptions rtc_options;
3759 rtc_options.offer_to_receive_audio = 0;
3760 rtc_options.offer_to_receive_video = 1;
3761
3762 std::unique_ptr<SessionDescriptionInterface> offer;
3763 CreatePeerConnection();
3764 offer = CreateOfferWithOptions(rtc_options);
3765 ASSERT_TRUE(offer);
3766 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3767 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3768}
3769
zhihuang1c378ed2017-08-17 14:10:50 -07003770// Test that no media content will be added to the offer if using default
3771// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003772TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003773 RTCOfferAnswerOptions rtc_options;
3774
3775 std::unique_ptr<SessionDescriptionInterface> offer;
3776 CreatePeerConnection();
3777 offer = CreateOfferWithOptions(rtc_options);
3778 ASSERT_TRUE(offer);
3779 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3780 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3781}
3782
3783// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3784// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003785TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3786 CreatePeerConnection();
3787
zhihuang1c378ed2017-08-17 14:10:50 -07003788 RTCOfferAnswerOptions rtc_options;
3789 rtc_options.ice_restart = false;
3790 rtc_options.offer_to_receive_audio = 1;
3791
3792 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003793 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003794 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3795 auto ufrag1 =
3796 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3797 auto pwd1 =
3798 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003799
3800 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3801 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003802 auto ufrag2 =
3803 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3804 auto pwd2 =
3805 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003806
3807 // |ice_restart| is true, the ufrag/pwd should change.
3808 rtc_options.ice_restart = true;
3809 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003810 auto ufrag3 =
3811 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3812 auto pwd3 =
3813 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003814
3815 EXPECT_EQ(ufrag1, ufrag2);
3816 EXPECT_EQ(pwd1, pwd2);
3817 EXPECT_NE(ufrag2, ufrag3);
3818 EXPECT_NE(pwd2, pwd3);
3819}
3820
3821// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3822// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003823TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003824 RTCOfferAnswerOptions rtc_options;
3825 rtc_options.offer_to_receive_audio = 1;
3826 rtc_options.offer_to_receive_video = 1;
3827
3828 std::unique_ptr<SessionDescriptionInterface> offer;
3829 CreatePeerConnection();
3830
3831 rtc_options.use_rtp_mux = true;
3832 offer = CreateOfferWithOptions(rtc_options);
3833 ASSERT_TRUE(offer);
3834 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3835 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3836 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3837
3838 rtc_options.use_rtp_mux = false;
3839 offer = CreateOfferWithOptions(rtc_options);
3840 ASSERT_TRUE(offer);
3841 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3842 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3843 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3844}
3845
zhihuang141aacb2017-08-29 13:23:53 -07003846// This test ensures OnRenegotiationNeeded is called when we add track with
3847// MediaStream -> AddTrack in the same way it is called when we add track with
3848// PeerConnection -> AddTrack.
3849// The test can be removed once addStream is rewritten in terms of addTrack
3850// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003851// Don't run under Unified Plan since the stream API is not available.
3852TEST_F(PeerConnectionInterfaceTestPlanB,
3853 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003854 CreatePeerConnectionWithoutDtls();
3855 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003856 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003857 pc_->AddStream(stream);
3858 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003859 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003860 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003861 CreateVideoTrack("video_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003862 stream->AddTrack(audio_track);
3863 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3864 observer_.renegotiation_needed_ = false;
3865
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003866 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003867 stream->AddTrack(video_track);
3868 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3869 observer_.renegotiation_needed_ = false;
3870
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003871 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003872 stream->RemoveTrack(audio_track);
3873 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3874 observer_.renegotiation_needed_ = false;
3875
Guido Urdaneta70c2db12019-04-16 12:24:14 +02003876 CreateOfferReceiveAnswer();
zhihuang141aacb2017-08-29 13:23:53 -07003877 stream->RemoveTrack(video_track);
3878 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3879 observer_.renegotiation_needed_ = false;
3880}
3881
Zhi Huangb2d355e2017-10-26 17:26:37 -07003882// Tests that an error is returned if a description is applied that has fewer
3883// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003884TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003885 MediaSectionCountEnforcedForSubsequentOffer) {
3886 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003887 AddAudioTrack("audio_label");
3888 AddVideoTrack("video_label");
3889
Zhi Huangb2d355e2017-10-26 17:26:37 -07003890 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003891 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003892 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3893
3894 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003895 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003896 offer->description()->contents().pop_back();
3897 offer->description()->contents().pop_back();
3898 ASSERT_TRUE(offer->description()->contents().empty());
3899 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3900
3901 std::unique_ptr<SessionDescriptionInterface> answer;
3902 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3903 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3904
3905 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003906 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003907 offer->description()->contents().pop_back();
3908 offer->description()->contents().pop_back();
3909 ASSERT_TRUE(offer->description()->contents().empty());
3910 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3911}
3912
Johannes Kron89f874e2018-11-12 10:25:48 +01003913TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3914 RTCConfiguration config;
3915 // Default behavior is false.
3916 CreatePeerConnection(config);
3917 std::unique_ptr<SessionDescriptionInterface> offer;
3918 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3919 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3920 // Possible to set to true.
3921 config.offer_extmap_allow_mixed = true;
3922 CreatePeerConnection(config);
3923 offer.release();
3924 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3925 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3926}
3927
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003928INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3929 PeerConnectionInterfaceTest,
3930 Values(SdpSemantics::kPlanB,
3931 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003932
Mirko Bonadei6a489f22019-04-09 15:11:12 +02003933class PeerConnectionMediaConfigTest : public ::testing::Test {
nisse51542be2016-02-12 02:27:06 -08003934 protected:
3935 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003936 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003937 pcf_->Initialize();
3938 }
nisseeaabdf62017-05-05 02:23:02 -07003939 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003940 const RTCConfiguration& config) {
3941 rtc::scoped_refptr<PeerConnectionInterface> pc(
3942 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003943 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003944 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003945 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003946 }
3947
zhihuang9763d562016-08-05 11:14:50 -07003948 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003949 MockPeerConnectionObserver observer_;
3950};
3951
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003952// This sanity check validates the test infrastructure itself.
3953TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3954 PeerConnectionInterface::RTCConfiguration config;
3955 rtc::scoped_refptr<PeerConnectionInterface> pc(
3956 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3957 EXPECT_TRUE(pc.get());
3958 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3959 pc->Close(); // No abort -> ok.
3960 SUCCEED();
3961}
3962
nisse51542be2016-02-12 02:27:06 -08003963// This test verifies the default behaviour with no constraints and a
3964// default RTCConfiguration.
3965TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3966 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003967
Niels Möllerf06f9232018-08-07 12:32:18 +02003968 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003969
3970 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003971 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3972 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003973 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003974 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003975}
3976
Niels Möller1d7ecd22018-01-18 15:25:12 +01003977// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07003978// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08003979TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3980 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003981
Niels Möller71bdda02016-03-31 12:59:59 +02003982 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02003983 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003984
Niels Möller1d7ecd22018-01-18 15:25:12 +01003985 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003986}
3987
Niels Möller6539f692018-01-18 08:58:50 +01003988// This test verifies that the experiment_cpu_load_estimator flag is
3989// propagated from RTCConfiguration to the PeerConnection.
3990TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
3991 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01003992
3993 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02003994 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01003995
3996 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
3997}
3998
deadbeef293e9262017-01-11 12:28:30 -08003999// Tests a few random fields being different.
4000TEST(RTCConfigurationTest, ComparisonOperators) {
4001 PeerConnectionInterface::RTCConfiguration a;
4002 PeerConnectionInterface::RTCConfiguration b;
4003 EXPECT_EQ(a, b);
4004
4005 PeerConnectionInterface::RTCConfiguration c;
4006 c.servers.push_back(PeerConnectionInterface::IceServer());
4007 EXPECT_NE(a, c);
4008
4009 PeerConnectionInterface::RTCConfiguration d;
4010 d.type = PeerConnectionInterface::kRelay;
4011 EXPECT_NE(a, d);
4012
4013 PeerConnectionInterface::RTCConfiguration e;
4014 e.audio_jitter_buffer_max_packets = 5;
4015 EXPECT_NE(a, e);
4016
4017 PeerConnectionInterface::RTCConfiguration f;
4018 f.ice_connection_receiving_timeout = 1337;
4019 EXPECT_NE(a, f);
4020
4021 PeerConnectionInterface::RTCConfiguration g;
4022 g.disable_ipv6 = true;
4023 EXPECT_NE(a, g);
4024
4025 PeerConnectionInterface::RTCConfiguration h(
4026 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4027 EXPECT_NE(a, h);
4028}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01004029
4030} // namespace
4031} // namespace webrtc