blob: 3803b7fa23f34cd066bc01efcfafd816a2b6f876 [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"
Yves Gerey3e707812018-11-28 16:47:49 +010020#include "absl/types/optional.h"
21#include "api/audio/audio_mixer.h"
22#include "api/audio_codecs/audio_decoder_factory.h"
23#include "api/audio_codecs/audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "api/audio_codecs/builtin_audio_decoder_factory.h"
25#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080026#include "api/call/call_factory_interface.h"
Mirko Bonadei2ff3f492018-11-22 09:00:13 +010027#include "api/create_peerconnection_factory.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "api/data_channel_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010029#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080030#include "api/jsep_session_description.h"
31#include "api/media_stream_interface.h"
32#include "api/media_types.h"
33#include "api/peer_connection_interface.h"
34#include "api/rtc_error.h"
35#include "api/rtc_event_log_output.h"
36#include "api/rtp_receiver_interface.h"
37#include "api/rtp_sender_interface.h"
38#include "api/rtp_transceiver_interface.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010039#include "api/scoped_refptr.h"
Anders Carlsson67537952018-05-03 11:28:29 +020040#include "api/video_codecs/builtin_video_decoder_factory.h"
41#include "api/video_codecs/builtin_video_encoder_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010042#include "api/video_codecs/video_decoder_factory.h"
43#include "api/video_codecs/video_encoder_factory.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020044#include "logging/rtc_event_log/output/rtc_event_log_output_file.h"
Yves Gerey3e707812018-11-28 16:47:49 +010045#include "logging/rtc_event_log/rtc_event_log.h"
Bjorn Tereliusb8b3c992019-01-09 11:15:34 +010046#include "logging/rtc_event_log/rtc_event_log_factory.h"
Yves Gerey3e707812018-11-28 16:47:49 +010047#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
48#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080049#include "media/base/media_config.h"
50#include "media/base/media_engine.h"
51#include "media/base/stream_params.h"
Steve Anton10542f22019-01-11 09:11:00 -080052#include "media/engine/webrtc_media_engine.h"
53#include "media/sctp/sctp_transport_internal.h"
Yves Gerey3e707812018-11-28 16:47:49 +010054#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020055#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080056#include "p2p/base/fake_port_allocator.h"
57#include "p2p/base/p2p_constants.h"
Yves Gerey3e707812018-11-28 16:47:49 +010058#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080059#include "p2p/base/port_allocator.h"
60#include "p2p/base/transport_description.h"
61#include "p2p/base/transport_info.h"
62#include "pc/audio_track.h"
63#include "pc/media_session.h"
64#include "pc/media_stream.h"
65#include "pc/peer_connection.h"
66#include "pc/peer_connection_factory.h"
67#include "pc/rtc_stats_collector.h"
68#include "pc/rtp_sender.h"
69#include "pc/session_description.h"
70#include "pc/stream_collection.h"
71#include "pc/test/fake_audio_capture_module.h"
72#include "pc/test/fake_rtc_certificate_generator.h"
73#include "pc/test/fake_video_track_source.h"
74#include "pc/test/mock_peer_connection_observers.h"
75#include "pc/test/test_sdp_strings.h"
76#include "pc/video_track.h"
Yves Gerey3e707812018-11-28 16:47:49 +010077#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080078#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020079#include "rtc_base/gunit.h"
Yves Gerey3e707812018-11-28 16:47:49 +010080#include "rtc_base/platform_file.h"
Steve Anton10542f22019-01-11 09:11:00 -080081#include "rtc_base/ref_counted_object.h"
82#include "rtc_base/rtc_certificate_generator.h"
Steve Anton10542f22019-01-11 09:11:00 -080083#include "rtc_base/socket_address.h"
84#include "rtc_base/string_utils.h"
Yves Gerey3e707812018-11-28 16:47:49 +010085#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080086#include "rtc_base/time_utils.h"
87#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020088#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010089#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080090#include "test/testsupport/file_utils.h"
kwibergac9f8762016-09-30 22:29:43 -070091
92#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080093#include "pc/test/android_test_initializer.h"
kwibergac9f8762016-09-30 22:29:43 -070094#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010096namespace webrtc {
97namespace {
98
Seth Hampson845e8782018-03-02 11:34:10 -080099static const char kStreamId1[] = "local_stream_1";
100static const char kStreamId2[] = "local_stream_2";
101static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102static const int kDefaultStunPort = 3478;
103static const char kStunAddressOnly[] = "stun:address";
104static const char kStunInvalidPort[] = "stun:address:-1";
105static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
106static const char kStunAddressPortAndMore2[] = "stun:address:port more";
107static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
108static const char kTurnUsername[] = "user";
109static const char kTurnPassword[] = "password";
110static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200111static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112
deadbeefab9b2d12015-10-14 11:33:11 -0700113static const char kStreams[][8] = {"stream1", "stream2"};
114static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
115static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
116
deadbeef5e97fb52015-10-15 12:49:08 -0700117static const char kRecvonly[] = "recvonly";
118static const char kSendrecv[] = "sendrecv";
119
deadbeefab9b2d12015-10-14 11:33:11 -0700120// Reference SDP with a MediaStream with label "stream1" and audio track with
121// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800122static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700123 "v=0\r\n"
124 "o=- 0 0 IN IP4 127.0.0.1\r\n"
125 "s=-\r\n"
126 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800127 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700128 "a=ice-ufrag:e5785931\r\n"
129 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
130 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
131 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700132 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700133 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800134 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700135 "a=rtpmap:103 ISAC/16000\r\n"
136 "a=ssrc:1 cname:stream1\r\n"
137 "a=ssrc:1 mslabel:stream1\r\n"
138 "a=ssrc:1 label:audiotrack0\r\n"
139 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800140 "a=ice-ufrag:e5785931\r\n"
141 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
142 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
143 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700144 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700145 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800146 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700147 "a=rtpmap:120 VP8/90000\r\n"
148 "a=ssrc:2 cname:stream1\r\n"
149 "a=ssrc:2 mslabel:stream1\r\n"
150 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800151// Same string as above but with the MID changed to the Unified Plan default.
152// This is needed so that this SDP can be used as an answer for a Unified Plan
153// offer.
154static const char kSdpStringWithStream1UnifiedPlan[] =
155 "v=0\r\n"
156 "o=- 0 0 IN IP4 127.0.0.1\r\n"
157 "s=-\r\n"
158 "t=0 0\r\n"
159 "m=audio 1 RTP/AVPF 103\r\n"
160 "a=ice-ufrag:e5785931\r\n"
161 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
162 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
163 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
164 "a=mid:0\r\n"
165 "a=sendrecv\r\n"
166 "a=rtcp-mux\r\n"
167 "a=rtpmap:103 ISAC/16000\r\n"
168 "a=ssrc:1 cname:stream1\r\n"
169 "a=ssrc:1 mslabel:stream1\r\n"
170 "a=ssrc:1 label:audiotrack0\r\n"
171 "m=video 1 RTP/AVPF 120\r\n"
172 "a=ice-ufrag:e5785931\r\n"
173 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
174 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
175 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
176 "a=mid:1\r\n"
177 "a=sendrecv\r\n"
178 "a=rtcp-mux\r\n"
179 "a=rtpmap:120 VP8/90000\r\n"
180 "a=ssrc:2 cname:stream1\r\n"
181 "a=ssrc:2 mslabel:stream1\r\n"
182 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700183
zhihuang81c3a032016-11-17 12:06:24 -0800184// Reference SDP with a MediaStream with label "stream1" and audio track with
185// id "audio_1";
186static const char kSdpStringWithStream1AudioTrackOnly[] =
187 "v=0\r\n"
188 "o=- 0 0 IN IP4 127.0.0.1\r\n"
189 "s=-\r\n"
190 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800191 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800192 "a=ice-ufrag:e5785931\r\n"
193 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
194 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
195 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800196 "a=mid:audio\r\n"
197 "a=sendrecv\r\n"
198 "a=rtpmap:103 ISAC/16000\r\n"
199 "a=ssrc:1 cname:stream1\r\n"
200 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800201 "a=ssrc:1 label:audiotrack0\r\n"
202 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800203
deadbeefab9b2d12015-10-14 11:33:11 -0700204// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
205// MediaStreams have one audio track and one video track.
206// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800207static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700208 "v=0\r\n"
209 "o=- 0 0 IN IP4 127.0.0.1\r\n"
210 "s=-\r\n"
211 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800212 "a=msid-semantic: WMS stream1 stream2\r\n"
213 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700214 "a=ice-ufrag:e5785931\r\n"
215 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
216 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
217 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700218 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700219 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800220 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700221 "a=rtpmap:103 ISAC/16000\r\n"
222 "a=ssrc:1 cname:stream1\r\n"
223 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
224 "a=ssrc:3 cname:stream2\r\n"
225 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
226 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800227 "a=ice-ufrag:e5785931\r\n"
228 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
229 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
230 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700231 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700232 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800233 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700234 "a=rtpmap:120 VP8/0\r\n"
235 "a=ssrc:2 cname:stream1\r\n"
236 "a=ssrc:2 msid:stream1 videotrack0\r\n"
237 "a=ssrc:4 cname:stream2\r\n"
238 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800239static const char kSdpStringWithStream1And2UnifiedPlan[] =
240 "v=0\r\n"
241 "o=- 0 0 IN IP4 127.0.0.1\r\n"
242 "s=-\r\n"
243 "t=0 0\r\n"
244 "a=msid-semantic: WMS stream1 stream2\r\n"
245 "m=audio 1 RTP/AVPF 103\r\n"
246 "a=ice-ufrag:e5785931\r\n"
247 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
248 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
249 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
250 "a=mid:0\r\n"
251 "a=sendrecv\r\n"
252 "a=rtcp-mux\r\n"
253 "a=rtpmap:103 ISAC/16000\r\n"
254 "a=ssrc:1 cname:stream1\r\n"
255 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
256 "m=video 1 RTP/AVPF 120\r\n"
257 "a=ice-ufrag:e5785931\r\n"
258 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
259 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
260 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
261 "a=mid:1\r\n"
262 "a=sendrecv\r\n"
263 "a=rtcp-mux\r\n"
264 "a=rtpmap:120 VP8/0\r\n"
265 "a=ssrc:2 cname:stream1\r\n"
266 "a=ssrc:2 msid:stream1 videotrack0\r\n"
267 "m=audio 1 RTP/AVPF 103\r\n"
268 "a=ice-ufrag:e5785931\r\n"
269 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
270 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
271 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
272 "a=mid:2\r\n"
273 "a=sendrecv\r\n"
274 "a=rtcp-mux\r\n"
275 "a=rtpmap:103 ISAC/16000\r\n"
276 "a=ssrc:3 cname:stream2\r\n"
277 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
278 "m=video 1 RTP/AVPF 120\r\n"
279 "a=ice-ufrag:e5785931\r\n"
280 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
281 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
282 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
283 "a=mid:3\r\n"
284 "a=sendrecv\r\n"
285 "a=rtcp-mux\r\n"
286 "a=rtpmap:120 VP8/0\r\n"
287 "a=ssrc:4 cname:stream2\r\n"
288 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700289
290// Reference SDP without MediaStreams. Msid is not supported.
291static const char kSdpStringWithoutStreams[] =
292 "v=0\r\n"
293 "o=- 0 0 IN IP4 127.0.0.1\r\n"
294 "s=-\r\n"
295 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800296 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700297 "a=ice-ufrag:e5785931\r\n"
298 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
299 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
300 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700301 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700302 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800303 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700304 "a=rtpmap:103 ISAC/16000\r\n"
305 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800306 "a=ice-ufrag:e5785931\r\n"
307 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
308 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
309 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700310 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700311 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800312 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700313 "a=rtpmap:120 VP8/90000\r\n";
314
315// Reference SDP without MediaStreams. Msid is supported.
316static const char kSdpStringWithMsidWithoutStreams[] =
317 "v=0\r\n"
318 "o=- 0 0 IN IP4 127.0.0.1\r\n"
319 "s=-\r\n"
320 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800321 "a=msid-semantic: WMS\r\n"
322 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700323 "a=ice-ufrag:e5785931\r\n"
324 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
325 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
326 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700327 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700328 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800329 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700330 "a=rtpmap:103 ISAC/16000\r\n"
331 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800332 "a=ice-ufrag:e5785931\r\n"
333 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
334 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
335 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700336 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700337 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800338 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700339 "a=rtpmap:120 VP8/90000\r\n";
340
341// Reference SDP without MediaStreams and audio only.
342static const char kSdpStringWithoutStreamsAudioOnly[] =
343 "v=0\r\n"
344 "o=- 0 0 IN IP4 127.0.0.1\r\n"
345 "s=-\r\n"
346 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800347 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700348 "a=ice-ufrag:e5785931\r\n"
349 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
350 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
351 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700352 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700353 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800354 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700355 "a=rtpmap:103 ISAC/16000\r\n";
356
357// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
358static const char kSdpStringSendOnlyWithoutStreams[] =
359 "v=0\r\n"
360 "o=- 0 0 IN IP4 127.0.0.1\r\n"
361 "s=-\r\n"
362 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800363 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700364 "a=ice-ufrag:e5785931\r\n"
365 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
366 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
367 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700368 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700369 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700370 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800371 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700372 "a=rtpmap:103 ISAC/16000\r\n"
373 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800374 "a=ice-ufrag:e5785931\r\n"
375 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
376 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
377 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700378 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700379 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700380 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800381 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700382 "a=rtpmap:120 VP8/90000\r\n";
383
384static const char kSdpStringInit[] =
385 "v=0\r\n"
386 "o=- 0 0 IN IP4 127.0.0.1\r\n"
387 "s=-\r\n"
388 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700389 "a=msid-semantic: WMS\r\n";
390
391static const char kSdpStringAudio[] =
392 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800393 "a=ice-ufrag:e5785931\r\n"
394 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
395 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
396 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700397 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700398 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800399 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700400 "a=rtpmap:103 ISAC/16000\r\n";
401
402static const char kSdpStringVideo[] =
403 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800404 "a=ice-ufrag:e5785931\r\n"
405 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
406 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
407 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700408 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700409 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800410 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700411 "a=rtpmap:120 VP8/90000\r\n";
412
413static const char kSdpStringMs1Audio0[] =
414 "a=ssrc:1 cname:stream1\r\n"
415 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
416
417static const char kSdpStringMs1Video0[] =
418 "a=ssrc:2 cname:stream1\r\n"
419 "a=ssrc:2 msid:stream1 videotrack0\r\n";
420
421static const char kSdpStringMs1Audio1[] =
422 "a=ssrc:3 cname:stream1\r\n"
423 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
424
425static const char kSdpStringMs1Video1[] =
426 "a=ssrc:4 cname:stream1\r\n"
427 "a=ssrc:4 msid:stream1 videotrack1\r\n";
428
deadbeef8662f942017-01-20 21:20:51 -0800429static const char kDtlsSdesFallbackSdp[] =
430 "v=0\r\n"
431 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
432 "s=-\r\n"
433 "c=IN IP4 0.0.0.0\r\n"
434 "t=0 0\r\n"
435 "a=group:BUNDLE audio\r\n"
436 "a=msid-semantic: WMS\r\n"
437 "m=audio 1 RTP/SAVPF 0\r\n"
438 "a=sendrecv\r\n"
439 "a=rtcp-mux\r\n"
440 "a=mid:audio\r\n"
441 "a=ssrc:1 cname:stream1\r\n"
442 "a=ssrc:1 mslabel:stream1\r\n"
443 "a=ssrc:1 label:audiotrack0\r\n"
444 "a=ice-ufrag:e5785931\r\n"
445 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
446 "a=rtpmap:0 pcmu/8000\r\n"
447 "a=fingerprint:sha-1 "
448 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
449 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700450 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800451 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
452 "dummy_session_params\r\n";
453
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100454using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700455using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800456using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457
Steve Anton36da6ff2018-02-16 16:04:20 -0800458using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
459using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700460
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461// Gets the first ssrc of given content type from the ContentInfo.
462bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
463 if (!content_info || !ssrc) {
464 return false;
465 }
466 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800467 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 if (!media_desc || media_desc->streams().empty()) {
469 return false;
470 }
471 *ssrc = media_desc->streams().begin()->first_ssrc();
472 return true;
473}
474
deadbeefd1a38b52016-12-10 13:15:33 -0800475// Get the ufrags out of an SDP blob. Useful for testing ICE restart
476// behavior.
477std::vector<std::string> GetUfrags(
478 const webrtc::SessionDescriptionInterface* desc) {
479 std::vector<std::string> ufrags;
480 for (const cricket::TransportInfo& info :
481 desc->description()->transport_infos()) {
482 ufrags.push_back(info.description.ice_ufrag);
483 }
484 return ufrags;
485}
486
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487void SetSsrcToZero(std::string* sdp) {
488 const char kSdpSsrcAtribute[] = "a=ssrc:";
489 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
490 size_t ssrc_pos = 0;
491 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200492 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493 size_t end_ssrc = sdp->find(" ", ssrc_pos);
494 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
495 ssrc_pos = end_ssrc;
496 }
497}
498
deadbeefab9b2d12015-10-14 11:33:11 -0700499// Check if |streams| contains the specified track.
500bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800501 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700502 const std::string& track_id) {
503 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800504 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700505 return true;
506 }
507 }
508 return false;
509}
510
511// Check if |senders| contains the specified sender, by id.
512bool ContainsSender(
513 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
514 const std::string& id) {
515 for (const auto& sender : senders) {
516 if (sender->id() == id) {
517 return true;
518 }
519 }
520 return false;
521}
522
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700523// Check if |senders| contains the specified sender, by id and stream id.
524bool ContainsSender(
525 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
526 const std::string& id,
527 const std::string& stream_id) {
528 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700529 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700530 return true;
531 }
532 }
533 return false;
534}
535
deadbeefab9b2d12015-10-14 11:33:11 -0700536// Create a collection of streams.
537// CreateStreamCollection(1) creates a collection that
538// correspond to kSdpStringWithStream1.
539// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
540rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700541 int number_of_streams,
542 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700543 rtc::scoped_refptr<StreamCollection> local_collection(
544 StreamCollection::Create());
545
546 for (int i = 0; i < number_of_streams; ++i) {
547 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
548 webrtc::MediaStream::Create(kStreams[i]));
549
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700550 for (int j = 0; j < tracks_per_stream; ++j) {
551 // Add a local audio track.
552 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
553 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
554 nullptr));
555 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700556
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700557 // Add a local video track.
558 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
559 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700560 webrtc::FakeVideoTrackSource::Create(),
561 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700562 stream->AddTrack(video_track);
563 }
deadbeefab9b2d12015-10-14 11:33:11 -0700564
565 local_collection->AddStream(stream);
566 }
567 return local_collection;
568}
569
570// Check equality of StreamCollections.
571bool CompareStreamCollections(StreamCollectionInterface* s1,
572 StreamCollectionInterface* s2) {
573 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
574 return false;
575 }
576
577 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700578 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700579 return false;
580 }
581 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
582 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
583 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
584 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
585
586 if (audio_tracks1.size() != audio_tracks2.size()) {
587 return false;
588 }
589 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
590 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
591 return false;
592 }
593 }
594 if (video_tracks1.size() != video_tracks2.size()) {
595 return false;
596 }
597 for (size_t j = 0; j != video_tracks1.size(); ++j) {
598 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
599 return false;
600 }
601 }
602 }
603 return true;
604}
605
perkjd61bf802016-03-24 03:16:19 -0700606// Helper class to test Observer.
607class MockTrackObserver : public ObserverInterface {
608 public:
609 explicit MockTrackObserver(NotifierInterface* notifier)
610 : notifier_(notifier) {
611 notifier_->RegisterObserver(this);
612 }
613
614 ~MockTrackObserver() { Unregister(); }
615
616 void Unregister() {
617 if (notifier_) {
618 notifier_->UnregisterObserver(this);
619 notifier_ = nullptr;
620 }
621 }
622
623 MOCK_METHOD0(OnChanged, void());
624
625 private:
626 NotifierInterface* notifier_;
627};
628
nisse528b7932017-05-08 03:21:43 -0700629// The PeerConnectionMediaConfig tests below verify that configuration and
630// constraints are propagated into the PeerConnection's MediaConfig. These
631// settings are intended for MediaChannel constructors, but that is not
632// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700633class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
634 public:
zhihuang38ede132017-06-15 12:52:32 -0700635 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
636 CreatePeerConnectionFactoryForTest() {
637 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
638 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200639 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
640 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 12:52:32 -0700641
henrika919dc2e2017-10-12 14:24:55 +0200642 // Use fake audio device module since we're only testing the interface
643 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700644 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
645 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200646 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200647 audio_decoder_factory, std::move(video_encoder_factory),
Qingsi Wang59844ce2018-11-01 04:45:53 +0000648 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100649 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700650
651 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
652 webrtc::CreateCallFactory();
653
654 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
655 webrtc::CreateRtcEventLogFactory();
656
657 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
658 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200659 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700660 std::move(event_log_factory));
661 }
662
663 PeerConnectionFactoryForTest(
664 rtc::Thread* network_thread,
665 rtc::Thread* worker_thread,
666 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700667 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
668 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
669 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
670 : webrtc::PeerConnectionFactory(network_thread,
671 worker_thread,
672 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700673 std::move(media_engine),
674 std::move(call_factory),
675 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800676
deadbeefd7850b22017-08-23 10:59:19 -0700677 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700678};
679
Steve Anton36da6ff2018-02-16 16:04:20 -0800680// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
681class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800683 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
684 : vss_(new rtc::VirtualSocketServer()),
685 main_(vss_.get()),
686 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800687#ifdef WEBRTC_ANDROID
688 webrtc::InitializeAndroidObjects();
689#endif
690 }
691
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700693 // Use fake audio capture module since we're only testing the interface
694 // level, and using a real one could make tests flaky when run in parallel.
695 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700697 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200698 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
699 fake_audio_capture_module_),
700 webrtc::CreateBuiltinAudioEncoderFactory(),
701 webrtc::CreateBuiltinAudioDecoderFactory(),
702 webrtc::CreateBuiltinVideoEncoderFactory(),
703 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
704 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700705 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700706 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700707 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700708 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 }
710
711 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200712 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 }
714
deadbeef293e9262017-01-11 12:28:30 -0800715 // DTLS does not work in a loopback call, so is disabled for most of the
716 // tests in this file.
717 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200718 RTCConfiguration config;
719 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800720
Niels Möllerf06f9232018-08-07 12:32:18 +0200721 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 }
723
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700724 void CreatePeerConnectionWithIceTransportsType(
725 PeerConnectionInterface::IceTransportsType type) {
726 PeerConnectionInterface::RTCConfiguration config;
727 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200728 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700729 }
730
731 void CreatePeerConnectionWithIceServer(const std::string& uri,
732 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800733 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700735 server.uri = uri;
736 server.password = password;
737 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200738 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700739 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740
Niels Möllerf06f9232018-08-07 12:32:18 +0200741 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700742 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800743 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
744 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000745
deadbeef1dcb1642017-03-29 21:08:16 -0700746 // Create certificate generator unless DTLS constraint is explicitly set to
747 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200748 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200749
750 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800751 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
752 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000753 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800754 RTCConfiguration modified_config = config;
755 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200756 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200757 modified_config, std::move(port_allocator), std::move(cert_generator),
758 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 ASSERT_TRUE(pc_.get() != NULL);
760 observer_.SetPeerConnectionInterface(pc_.get());
761 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
762 }
763
deadbeef0a6c4ca2015-10-06 11:38:28 -0700764 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800765 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700766 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700767 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800768 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800769 config.sdp_semantics = sdp_semantics_;
770 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200771 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800772 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700773 }
774
Steve Anton038834f2017-07-14 15:59:59 -0700775 void CreatePeerConnectionExpectFail(
776 PeerConnectionInterface::RTCConfiguration config) {
777 PeerConnectionInterface::IceServer server;
778 server.uri = kTurnIceServerUri;
779 server.password = kTurnPassword;
780 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800781 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700782 rtc::scoped_refptr<PeerConnectionInterface> pc =
783 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
784 EXPECT_EQ(nullptr, pc);
785 }
786
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700788 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800789 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
790 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
791 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800793 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794
deadbeef0a6c4ca2015-10-06 11:38:28 -0700795 CreatePeerConnectionExpectFail(kStunInvalidPort);
796 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
797 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700799 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800800 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
801 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800803 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800805 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800807 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 }
809
810 void ReleasePeerConnection() {
811 pc_ = NULL;
812 observer_.SetPeerConnectionInterface(NULL);
813 }
814
Steve Anton36da6ff2018-02-16 16:04:20 -0800815 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
816 const std::string& label) {
Niels Möller215ba602019-01-18 13:59:45 +0100817 return pc_factory_->CreateVideoTrack(label, FakeVideoTrackSource::Create());
Steve Anton36da6ff2018-02-16 16:04:20 -0800818 }
819
820 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800821 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800822 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800823 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800824 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
826 observer_.renegotiation_needed_ = false;
827 }
828
Steve Anton36da6ff2018-02-16 16:04:20 -0800829 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700830 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800832 stream->AddTrack(CreateVideoTrack(label + "v0"));
833 ASSERT_TRUE(pc_->AddStream(stream));
834 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
835 observer_.renegotiation_needed_ = false;
836 }
837
838 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
839 const std::string& label) {
840 return pc_factory_->CreateAudioTrack(label, nullptr);
841 }
842
843 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800844 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800845 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800846 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800847 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
848 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
849 observer_.renegotiation_needed_ = false;
850 }
851
852 void AddAudioStream(const std::string& label) {
853 rtc::scoped_refptr<MediaStreamInterface> stream(
854 pc_factory_->CreateLocalMediaStream(label));
855 stream->AddTrack(CreateAudioTrack(label + "a0"));
856 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
858 observer_.renegotiation_needed_ = false;
859 }
860
Seth Hampson845e8782018-03-02 11:34:10 -0800861 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 const std::string& audio_track_label,
863 const std::string& video_track_label) {
864 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700865 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800866 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800867 stream->AddTrack(CreateAudioTrack(audio_track_label));
868 stream->AddTrack(CreateVideoTrack(video_track_label));
869 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
871 observer_.renegotiation_needed_ = false;
872 }
873
Steve Anton36da6ff2018-02-16 16:04:20 -0800874 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
875 cricket::MediaType media_type) {
876 for (auto receiver : pc_->GetReceivers()) {
877 if (receiver->media_type() == media_type) {
878 return receiver;
879 }
880 }
881 return nullptr;
882 }
883
kwibergd1fe2812016-04-27 06:47:29 -0700884 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200885 const RTCOfferAnswerOptions* options,
886 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200887 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
888 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200890 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200892 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 }
894 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700895 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 return observer->result();
897 }
898
kwibergd1fe2812016-04-27 06:47:29 -0700899 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200900 const RTCOfferAnswerOptions* options) {
901 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 }
903
kwibergd1fe2812016-04-27 06:47:29 -0700904 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200905 const RTCOfferAnswerOptions* options) {
906 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 }
908
Steve Antondb45ca82017-09-11 18:27:34 -0700909 bool DoSetSessionDescription(
910 std::unique_ptr<SessionDescriptionInterface> desc,
911 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200912 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
913 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700915 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700917 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 }
zhihuang29ff8442016-07-27 11:07:25 -0700919 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
920 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
921 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 return observer->result();
923 }
924
Steve Antondb45ca82017-09-11 18:27:34 -0700925 bool DoSetLocalDescription(
926 std::unique_ptr<SessionDescriptionInterface> desc) {
927 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 }
929
Steve Antondb45ca82017-09-11 18:27:34 -0700930 bool DoSetRemoteDescription(
931 std::unique_ptr<SessionDescriptionInterface> desc) {
932 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 }
934
935 // Calls PeerConnection::GetStats and check the return value.
936 // It does not verify the values in the StatReports since a RTCP packet might
937 // be required.
938 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000939 rtc::scoped_refptr<MockStatsObserver> observer(
940 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200941 if (!pc_->GetStats(observer, track,
942 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 return false;
944 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
945 return observer->called();
946 }
947
Harald Alvestrand89061872018-01-02 14:08:34 +0100948 // Call the standards-compliant GetStats function.
949 bool DoGetRTCStats() {
950 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
951 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
952 pc_->GetStats(callback);
953 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
954 return callback->called();
955 }
956
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800958 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800960 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800961 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800962 } else {
963 // Unified Plan does not support AddStream, so just add an audio and video
964 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800965 AddAudioTrack(kAudioTracks[0], {kStreamId1});
966 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800967 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 CreateOfferReceiveAnswer();
969 }
970
971 // Verify that RTP Header extensions has been negotiated for audio and video.
972 void VerifyRemoteRtpHeaderExtensions() {
973 const cricket::MediaContentDescription* desc =
974 cricket::GetFirstAudioContentDescription(
975 pc_->remote_description()->description());
976 ASSERT_TRUE(desc != NULL);
977 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
978
979 desc = cricket::GetFirstVideoContentDescription(
980 pc_->remote_description()->description());
981 ASSERT_TRUE(desc != NULL);
982 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
983 }
984
985 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700986 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700987 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 std::string sdp;
989 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700990 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800991 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700992 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
994 }
995
deadbeefab9b2d12015-10-14 11:33:11 -0700996 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700997 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800998 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700999 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001000 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1001 }
1002
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001004 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001005 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006
1007 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1008 // audio codec change, even if the parameter has nothing to do with
1009 // receiving. Not all parameters are serialized to SDP.
1010 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1011 // the SessionDescription, it is necessary to do that here to in order to
1012 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1013 // https://code.google.com/p/webrtc/issues/detail?id=1356
1014 std::string sdp;
1015 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001016 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001017 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001018 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1020 }
1021
1022 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001023 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001024 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025
1026 std::string sdp;
1027 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001028 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001029 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001030 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1032 }
1033
1034 void CreateOfferReceiveAnswer() {
1035 CreateOfferAsLocalDescription();
1036 std::string sdp;
1037 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1038 CreateAnswerAsRemoteDescription(sdp);
1039 }
1040
1041 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001042 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001043 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1045 // audio codec change, even if the parameter has nothing to do with
1046 // receiving. Not all parameters are serialized to SDP.
1047 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1048 // the SessionDescription, it is necessary to do that here to in order to
1049 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1050 // https://code.google.com/p/webrtc/issues/detail?id=1356
1051 std::string sdp;
1052 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001053 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001054 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055
Steve Antondb45ca82017-09-11 18:27:34 -07001056 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001058 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001059 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 }
1061
deadbeefab9b2d12015-10-14 11:33:11 -07001062 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001063 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001064 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001065 ASSERT_TRUE(answer);
1066 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1068 }
1069
deadbeefab9b2d12015-10-14 11:33:11 -07001070 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001071 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001072 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001073 ASSERT_TRUE(pr_answer);
1074 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001076 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001077 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001078 ASSERT_TRUE(answer);
1079 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1081 }
1082
Seth Hampson845e8782018-03-02 11:34:10 -08001083 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001084 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001085 // called with the given stream id and expected number of tracks.
1086 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001087 int expected_num_tracks) {
1088 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001089 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001090 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001091 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 }
1093
1094 // Creates an offer and applies it as a local session description.
1095 // Creates an answer with the same SDP an the offer but removes all lines
1096 // that start with a:ssrc"
1097 void CreateOfferReceiveAnswerWithoutSsrc() {
1098 CreateOfferAsLocalDescription();
1099 std::string sdp;
1100 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1101 SetSsrcToZero(&sdp);
1102 CreateAnswerAsRemoteDescription(sdp);
1103 }
1104
deadbeefab9b2d12015-10-14 11:33:11 -07001105 // This function creates a MediaStream with label kStreams[0] and
1106 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1107 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001108 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001109 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001110 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001111 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1112 size_t number_of_video_tracks) {
1113 EXPECT_LE(number_of_audio_tracks, 2u);
1114 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001115
1116 reference_collection_ = StreamCollection::Create();
1117 std::string sdp_ms1 = std::string(kSdpStringInit);
1118
Seth Hampson845e8782018-03-02 11:34:10 -08001119 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001120
1121 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001122 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001123 reference_collection_->AddStream(stream);
1124
1125 if (number_of_audio_tracks > 0) {
1126 sdp_ms1 += std::string(kSdpStringAudio);
1127 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1128 AddAudioTrack(kAudioTracks[0], stream);
1129 }
1130 if (number_of_audio_tracks > 1) {
1131 sdp_ms1 += kSdpStringMs1Audio1;
1132 AddAudioTrack(kAudioTracks[1], stream);
1133 }
1134
1135 if (number_of_video_tracks > 0) {
1136 sdp_ms1 += std::string(kSdpStringVideo);
1137 sdp_ms1 += std::string(kSdpStringMs1Video0);
1138 AddVideoTrack(kVideoTracks[0], stream);
1139 }
1140 if (number_of_video_tracks > 1) {
1141 sdp_ms1 += kSdpStringMs1Video1;
1142 AddVideoTrack(kVideoTracks[1], stream);
1143 }
1144
kwibergd1fe2812016-04-27 06:47:29 -07001145 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001146 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001147 }
1148
1149 void AddAudioTrack(const std::string& track_id,
1150 MediaStreamInterface* stream) {
1151 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1152 webrtc::AudioTrack::Create(track_id, nullptr));
1153 ASSERT_TRUE(stream->AddTrack(audio_track));
1154 }
1155
1156 void AddVideoTrack(const std::string& track_id,
1157 MediaStreamInterface* stream) {
1158 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001159 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001160 webrtc::FakeVideoTrackSource::Create(),
1161 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001162 ASSERT_TRUE(stream->AddTrack(video_track));
1163 }
1164
Steve Anton36da6ff2018-02-16 16:04:20 -08001165 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001166 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001167 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001168 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001169 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1170 return offer;
1171 }
1172
Steve Anton36da6ff2018-02-16 16:04:20 -08001173 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1174 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001175 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001176 std::unique_ptr<SessionDescriptionInterface> offer;
1177 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1178 return offer;
1179 }
1180
1181 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1182 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1183 std::unique_ptr<SessionDescriptionInterface> answer;
1184 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1185 return answer;
1186 }
1187
kwibergfd8be342016-05-14 19:44:11 -07001188 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001189 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001190 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001191 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001192 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1193 return answer;
1194 }
1195
1196 const std::string& GetFirstAudioStreamCname(
1197 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001198 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001199 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001200 return audio_desc->streams()[0].cname;
1201 }
1202
zhihuang1c378ed2017-08-17 14:10:50 -07001203 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1204 const RTCOfferAnswerOptions& offer_answer_options) {
1205 RTC_DCHECK(pc_);
1206 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1207 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1208 pc_->CreateOffer(observer, offer_answer_options);
1209 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1210 return observer->MoveDescription();
1211 }
1212
1213 void CreateOfferWithOptionsAsRemoteDescription(
1214 std::unique_ptr<SessionDescriptionInterface>* desc,
1215 const RTCOfferAnswerOptions& offer_answer_options) {
1216 *desc = CreateOfferWithOptions(offer_answer_options);
1217 ASSERT_TRUE(desc != nullptr);
1218 std::string sdp;
1219 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001220 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001221 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001222 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001223 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1224 }
1225
1226 void CreateOfferWithOptionsAsLocalDescription(
1227 std::unique_ptr<SessionDescriptionInterface>* desc,
1228 const RTCOfferAnswerOptions& offer_answer_options) {
1229 *desc = CreateOfferWithOptions(offer_answer_options);
1230 ASSERT_TRUE(desc != nullptr);
1231 std::string sdp;
1232 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001233 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001234 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001235
Steve Antondb45ca82017-09-11 18:27:34 -07001236 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001237 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1238 }
1239
1240 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001241 RTC_DCHECK(content);
1242 RTC_DCHECK(content->media_description());
1243 for (const cricket::AudioCodec& codec :
1244 content->media_description()->as_audio()->codecs()) {
1245 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001246 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001247 }
zhihuang1c378ed2017-08-17 14:10:50 -07001248 }
1249 return false;
1250 }
1251
Steve Anton36da6ff2018-02-16 16:04:20 -08001252 const char* GetSdpStringWithStream1() const {
1253 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1254 return kSdpStringWithStream1PlanB;
1255 } else {
1256 return kSdpStringWithStream1UnifiedPlan;
1257 }
1258 }
1259
1260 const char* GetSdpStringWithStream1And2() const {
1261 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1262 return kSdpStringWithStream1And2PlanB;
1263 } else {
1264 return kSdpStringWithStream1And2UnifiedPlan;
1265 }
1266 }
1267
deadbeef9a6f4d42017-05-15 19:43:33 -07001268 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1269 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001270 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001271 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001272 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001273 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1274 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1275 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001277 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001278 const SdpSemantics sdp_semantics_;
1279};
1280
1281class PeerConnectionInterfaceTest
1282 : public PeerConnectionInterfaceBaseTest,
1283 public ::testing::WithParamInterface<SdpSemantics> {
1284 protected:
1285 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1286};
1287
1288class PeerConnectionInterfaceTestPlanB
1289 : public PeerConnectionInterfaceBaseTest {
1290 protected:
1291 PeerConnectionInterfaceTestPlanB()
1292 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293};
1294
zhihuang8f65cdf2016-05-06 18:40:30 -07001295// Generate different CNAMEs when PeerConnections are created.
1296// The CNAMEs are expected to be generated randomly. It is possible
1297// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001298TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001299 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001300 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001301 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001302 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001303 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1304 GetFirstAudioStreamCname(offer2.get()));
1305}
1306
Steve Anton36da6ff2018-02-16 16:04:20 -08001307TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001308 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001309 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001310 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001311 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001312 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1313 GetFirstAudioStreamCname(answer2.get()));
1314}
1315
Steve Anton36da6ff2018-02-16 16:04:20 -08001316TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 CreatePeerConnectionWithDifferentConfigurations) {
1318 CreatePeerConnectionWithDifferentConfigurations();
1319}
1320
Steve Anton36da6ff2018-02-16 16:04:20 -08001321TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001322 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1323 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1324 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1325 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1326 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1327 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1328 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1329 port_allocator_->candidate_filter());
1330 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1331 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1332}
1333
1334// Test that when a PeerConnection is created with a nonzero candidate pool
1335// size, the pooled PortAllocatorSession is created with all the attributes
1336// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001337TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001338 PeerConnectionInterface::RTCConfiguration config;
1339 PeerConnectionInterface::IceServer server;
1340 server.uri = kStunAddressOnly;
1341 config.servers.push_back(server);
1342 config.type = PeerConnectionInterface::kRelay;
1343 config.disable_ipv6 = true;
1344 config.tcp_candidate_policy =
1345 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001346 config.candidate_network_policy =
1347 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001348 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001349 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001350
1351 const cricket::FakePortAllocatorSession* session =
1352 static_cast<const cricket::FakePortAllocatorSession*>(
1353 port_allocator_->GetPooledSession());
1354 ASSERT_NE(nullptr, session);
1355 EXPECT_EQ(1UL, session->stun_servers().size());
1356 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1357 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001358 EXPECT_LT(0U,
1359 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001360}
1361
deadbeefd21eab32017-07-26 16:50:11 -07001362// Test that network-related RTCConfiguration members are applied to the
1363// PortAllocator when CreatePeerConnection is called. Specifically:
1364// - disable_ipv6_on_wifi
1365// - max_ipv6_networks
1366// - tcp_candidate_policy
1367// - candidate_network_policy
1368// - prune_turn_ports
1369//
1370// Note that the candidate filter (RTCConfiguration::type) is already tested
1371// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001372TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001373 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1374 // Create fake port allocator.
1375 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1376 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1377 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1378
1379 // Create RTCConfiguration with some network-related fields relevant to
1380 // PortAllocator populated.
1381 PeerConnectionInterface::RTCConfiguration config;
1382 config.disable_ipv6_on_wifi = true;
1383 config.max_ipv6_networks = 10;
1384 config.tcp_candidate_policy =
1385 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1386 config.candidate_network_policy =
1387 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1388 config.prune_turn_ports = true;
1389
1390 // Create the PC factory and PC with the above config.
1391 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1392 webrtc::CreatePeerConnectionFactory(
1393 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001394 rtc::Thread::Current(), fake_audio_capture_module_,
1395 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001396 webrtc::CreateBuiltinAudioDecoderFactory(),
1397 webrtc::CreateBuiltinVideoEncoderFactory(),
1398 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1399 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001400 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001401 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1402 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001403 EXPECT_TRUE(pc.get());
1404 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001405
1406 // Now validate that the config fields set above were applied to the
1407 // PortAllocator, as flags or otherwise.
1408 EXPECT_FALSE(raw_port_allocator->flags() &
1409 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1410 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1411 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1412 EXPECT_TRUE(raw_port_allocator->flags() &
1413 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1414 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1415}
1416
deadbeef46c73892016-11-16 19:42:04 -08001417// Check that GetConfiguration returns the configuration the PeerConnection was
1418// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001419TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001420 PeerConnectionInterface::RTCConfiguration config;
1421 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001422 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001423
1424 PeerConnectionInterface::RTCConfiguration returned_config =
1425 pc_->GetConfiguration();
1426 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1427}
1428
1429// Check that GetConfiguration returns the last configuration passed into
1430// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001431TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001432 PeerConnectionInterface::RTCConfiguration starting_config;
1433 starting_config.bundle_policy =
1434 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1435 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001436
Steve Anton36da6ff2018-02-16 16:04:20 -08001437 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001438 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001439 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001440 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001441 EXPECT_TRUE(pc_->SetConfiguration(config));
1442
1443 PeerConnectionInterface::RTCConfiguration returned_config =
1444 pc_->GetConfiguration();
1445 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001446 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001447 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001448}
1449
Steve Antonc79268f2018-04-24 09:54:10 -07001450TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1451 CreatePeerConnection();
1452
1453 pc_->Close();
1454
1455 EXPECT_FALSE(
1456 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1457}
1458
Steve Anton36da6ff2018-02-16 16:04:20 -08001459TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001460 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001461 AddVideoStream(kStreamId1);
1462 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 ASSERT_EQ(2u, pc_->local_streams()->count());
1464
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001465 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001466 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001467 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001468 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001469 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001470 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001472 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001473 EXPECT_EQ(3u, pc_->local_streams()->count());
1474
1475 // Remove the third stream.
1476 pc_->RemoveStream(pc_->local_streams()->at(2));
1477 EXPECT_EQ(2u, pc_->local_streams()->count());
1478
1479 // Remove the second stream.
1480 pc_->RemoveStream(pc_->local_streams()->at(1));
1481 EXPECT_EQ(1u, pc_->local_streams()->count());
1482
1483 // Remove the first stream.
1484 pc_->RemoveStream(pc_->local_streams()->at(0));
1485 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486}
1487
deadbeefab9b2d12015-10-14 11:33:11 -07001488// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001489// Don't run under Unified Plan since the stream API is not available.
1490TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001491 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001492 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001493 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001494 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001495
deadbeefab9b2d12015-10-14 11:33:11 -07001496 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001497 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001498 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001499
deadbeefab9b2d12015-10-14 11:33:11 -07001500 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001501 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001502 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001503
1504 // Add another stream and ensure the offer includes both the old and new
1505 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001506 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001507 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001508
Steve Antonb1c1de12017-12-21 15:14:30 -08001509 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001510 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1511 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001512
Steve Antonb1c1de12017-12-21 15:14:30 -08001513 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001514 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1515 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001516}
1517
Steve Anton36da6ff2018-02-16 16:04:20 -08001518// Don't run under Unified Plan since the stream API is not available.
1519TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001520 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001521 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 ASSERT_EQ(1u, pc_->local_streams()->count());
1523 pc_->RemoveStream(pc_->local_streams()->at(0));
1524 EXPECT_EQ(0u, pc_->local_streams()->count());
1525}
1526
deadbeefe1f9d832016-01-14 15:35:42 -08001527// Test for AddTrack and RemoveTrack methods.
1528// Tests that the created offer includes tracks we added,
1529// and that the RtpSenders are created correctly.
1530// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001531// Only tested with Plan B since Unified Plan is covered in more detail by tests
1532// in peerconnection_jsep_unittests.cc
1533TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001534 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001535 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001536 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001537 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001538 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001539 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1540 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001541 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001542 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001543 EXPECT_EQ("audio_track", audio_sender->id());
1544 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001545 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001546 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001547 EXPECT_EQ("video_track", video_sender->id());
1548 EXPECT_EQ(video_track, video_sender->track());
1549
1550 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001551 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001552 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001553
1554 const cricket::ContentInfo* audio_content =
1555 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001556 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001557 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001558
1559 const cricket::ContentInfo* video_content =
1560 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001561 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001562 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001563
Steve Antondb45ca82017-09-11 18:27:34 -07001564 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001565
1566 // Now try removing the tracks.
1567 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1568 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1569
1570 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001571 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001572
1573 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001574 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001575 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001576
1577 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001578 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001579 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001580
Steve Antondb45ca82017-09-11 18:27:34 -07001581 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001582
1583 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1584 // should return false.
1585 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1586 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1587}
1588
1589// Test creating senders without a stream specified,
1590// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001591TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001592 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001593 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001594 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001595 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001596 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001597 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001598 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001599 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001600 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001601 EXPECT_EQ("audio_track", audio_sender->id());
1602 EXPECT_EQ(audio_track, audio_sender->track());
1603 EXPECT_EQ("video_track", video_sender->id());
1604 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001605 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1606 // If the ID is truly a random GUID, it should be infinitely unlikely they
1607 // will be the same.
1608 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1609 } else {
1610 // We allows creating tracks without stream ids under Unified Plan
1611 // semantics.
1612 EXPECT_EQ(0u, video_sender->stream_ids().size());
1613 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1614 }
deadbeefe1f9d832016-01-14 15:35:42 -08001615}
1616
Harald Alvestrand89061872018-01-02 14:08:34 +01001617// Test that we can call GetStats() after AddTrack but before connecting
1618// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001619TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001620 CreatePeerConnectionWithoutDtls();
1621 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001622 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001623 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001624 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001625 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1626 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001627 EXPECT_TRUE(DoGetStats(nullptr));
1628}
1629
Steve Anton36da6ff2018-02-16 16:04:20 -08001630TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001631 CreatePeerConnectionWithoutDtls();
1632 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001633 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001634 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001635 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001636 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001637 ASSERT_TRUE(audio_sender.ok());
1638 auto* audio_sender_proxy =
1639 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1640 audio_sender.value().get());
1641 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1642
Harald Alvestrandc72af932018-01-11 17:18:19 +01001643 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001644 ASSERT_TRUE(video_sender.ok());
1645 auto* video_sender_proxy =
1646 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1647 video_sender.value().get());
1648 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001649}
1650
Steve Anton36da6ff2018-02-16 16:04:20 -08001651// Don't run under Unified Plan since the stream API is not available.
1652TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001653 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001654 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001655 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001656 ASSERT_EQ(1u, senders.size());
1657 auto* sender_proxy =
1658 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1659 senders[0].get());
1660 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001661}
1662
Steve Anton36da6ff2018-02-16 16:04:20 -08001663TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001665 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 VerifyRemoteRtpHeaderExtensions();
1667}
1668
Steve Anton36da6ff2018-02-16 16:04:20 -08001669TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001670 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001671 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 CreateOfferAsLocalDescription();
1673 std::string offer;
1674 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1675 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001676 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677}
1678
Steve Anton36da6ff2018-02-16 16:04:20 -08001679TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001680 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001681 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682
1683 CreateOfferAsRemoteDescription();
1684 CreateAnswerAsLocalDescription();
1685
Seth Hampson845e8782018-03-02 11:34:10 -08001686 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687}
1688
Steve Anton36da6ff2018-02-16 16:04:20 -08001689TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001690 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001691 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692
1693 CreateOfferAsRemoteDescription();
1694 CreatePrAnswerAsLocalDescription();
1695 CreateAnswerAsLocalDescription();
1696
Seth Hampson845e8782018-03-02 11:34:10 -08001697 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698}
1699
Steve Anton36da6ff2018-02-16 16:04:20 -08001700// Don't run under Unified Plan since the stream API is not available.
1701TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 InitiateCall();
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());
Seth Hampson845e8782018-03-02 11:34:10 -08001707 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 CreateOfferReceiveAnswer();
1709}
1710
1711// Tests that after negotiating an audio only call, the respondent can perform a
1712// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001713TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001714 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001715 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 CreateOfferAsRemoteDescription();
1717 CreateAnswerAsLocalDescription();
1718
1719 ASSERT_EQ(1u, pc_->remote_streams()->count());
1720 pc_->RemoveStream(pc_->local_streams()->at(0));
1721 CreateOfferReceiveAnswer();
1722 EXPECT_EQ(0u, pc_->remote_streams()->count());
1723}
1724
1725// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001726TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001727 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728
Steve Antonf1c6db12017-10-13 11:13:35 -07001729 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001731 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001732 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001733 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001734 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735
1736 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001737 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001738 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001739 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740
Steve Antonf1c6db12017-10-13 11:13:35 -07001741 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001742 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743
Steve Antonf1c6db12017-10-13 11:13:35 -07001744 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745}
1746
deadbeefab9b2d12015-10-14 11:33:11 -07001747// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001749TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001750 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001752 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001753 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001754 EXPECT_TRUE(offer);
1755 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756
1757 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001758 AddAudioTrack("track_label", {kStreamId1});
1759 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760
1761 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001762 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763
1764 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001765 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001766 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767}
1768
1769// Test that we will get different SSRCs for each tracks in the offer and answer
1770// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001771TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001772 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001774 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1775 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776
1777 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001778 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001779 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 int audio_ssrc = 0;
1781 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001782 EXPECT_TRUE(
1783 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1784 EXPECT_TRUE(
1785 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 EXPECT_NE(audio_ssrc, video_ssrc);
1787
1788 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001789 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001790 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001791 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 audio_ssrc = 0;
1793 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001794 EXPECT_TRUE(
1795 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1796 EXPECT_TRUE(
1797 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 EXPECT_NE(audio_ssrc, video_ssrc);
1799}
1800
deadbeefeb459812015-12-15 19:24:43 -08001801// Test that it's possible to call AddTrack on a MediaStream after adding
1802// the stream to a PeerConnection.
1803// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001804// Don't run under Unified Plan since the stream API is not available.
1805TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001806 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001807 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001808 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001809 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1810
1811 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001812 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001813 CreateVideoTrack("video_label"));
deadbeefeb459812015-12-15 19:24:43 -08001814 stream->AddTrack(video_track.get());
1815
kwibergd1fe2812016-04-27 06:47:29 -07001816 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001817 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001818
1819 const cricket::MediaContentDescription* video_desc =
1820 cricket::GetFirstVideoContentDescription(offer->description());
1821 EXPECT_TRUE(video_desc != nullptr);
1822}
1823
1824// Test that it's possible to call RemoveTrack on a MediaStream after adding
1825// the stream to a PeerConnection.
1826// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001827// Don't run under Unified Plan since the stream API is not available.
1828TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001829 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001830 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001831 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001832 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1833
1834 // Remove the video track.
1835 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1836
kwibergd1fe2812016-04-27 06:47:29 -07001837 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001838 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001839
1840 const cricket::MediaContentDescription* video_desc =
1841 cricket::GetFirstVideoContentDescription(offer->description());
1842 EXPECT_TRUE(video_desc == nullptr);
1843}
1844
deadbeefbd7d8f72015-12-18 16:58:44 -08001845// Test creating a sender with a stream ID, and ensure the ID is populated
1846// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001847// Don't run under Unified Plan since the stream API is not available.
1848TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001849 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001850 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001851
kwibergd1fe2812016-04-27 06:47:29 -07001852 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001853 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001854
1855 const cricket::MediaContentDescription* video_desc =
1856 cricket::GetFirstVideoContentDescription(offer->description());
1857 ASSERT_TRUE(video_desc != nullptr);
1858 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001859 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001860}
1861
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001863TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001865 ASSERT_LT(0u, pc_->GetSenders().size());
1866 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001867 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001868 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 EXPECT_TRUE(DoGetStats(remote_audio));
1870
1871 // Remove the stream. Since we are sending to our selves the local
1872 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001873 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874 // Do a re-negotiation.
1875 CreateOfferReceiveAnswer();
1876
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 // Test that we still can get statistics for the old track. Even if it is not
1878 // sent any longer.
1879 EXPECT_TRUE(DoGetStats(remote_audio));
1880}
1881
1882// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001883TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001885 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1886 ASSERT_TRUE(video_receiver);
1887 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888}
1889
1890// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001891TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001893 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 pc_factory_->CreateAudioTrack("unknown track", NULL));
1895 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1896}
1897
Steve Anton36da6ff2018-02-16 16:04:20 -08001898TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001899 CreatePeerConnectionWithoutDtls();
1900 EXPECT_TRUE(DoGetRTCStats());
1901 // Clearing stats cache is needed now, but should be temporary.
1902 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1903 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001904 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1905 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001906 EXPECT_TRUE(DoGetRTCStats());
1907 pc_->ClearStatsCache();
1908 CreateOfferReceiveAnswer();
1909 EXPECT_TRUE(DoGetRTCStats());
1910}
1911
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001913TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001914 RTCConfiguration config;
1915 config.enable_rtp_data_channel = true;
1916 config.enable_dtls_srtp = false;
1917 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001918 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001920 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001921 pc_->CreateDataChannel("test2", NULL);
1922 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001923 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001925 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926 new MockDataChannelObserver(data2));
1927
1928 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1929 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1930 std::string data_to_send1 = "testing testing";
1931 std::string data_to_send2 = "testing something else";
1932 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1933
1934 CreateOfferReceiveAnswer();
1935 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1936 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1937
1938 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1939 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1940 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1941 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1942
1943 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1944 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1945
1946 data1->Close();
1947 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1948 CreateOfferReceiveAnswer();
1949 EXPECT_FALSE(observer1->IsOpen());
1950 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1951 EXPECT_TRUE(observer2->IsOpen());
1952
1953 data_to_send2 = "testing something else again";
1954 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1955
1956 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1957}
1958
1959// This test verifies that sendnig binary data over RTP data channels should
1960// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001961TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001962 RTCConfiguration config;
1963 config.enable_rtp_data_channel = true;
1964 config.enable_dtls_srtp = false;
1965 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001966 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001968 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001969 pc_->CreateDataChannel("test2", NULL);
1970 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001971 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001973 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 new MockDataChannelObserver(data2));
1975
1976 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1977 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1978
1979 CreateOfferReceiveAnswer();
1980 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1981 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1982
1983 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1984 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1985
jbaucheec21bd2016-03-20 06:15:43 -07001986 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1988}
1989
1990// This test setup a RTP data channels in loop back and test that a channel is
1991// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08001992TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001993 RTCConfiguration config;
1994 config.enable_rtp_data_channel = true;
1995 config.enable_dtls_srtp = false;
1996 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001997 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001999 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 new MockDataChannelObserver(data1));
2001
2002 CreateOfferReceiveAnswerWithoutSsrc();
2003
2004 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2005
2006 data1->Close();
2007 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2008 CreateOfferReceiveAnswerWithoutSsrc();
2009 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2010 EXPECT_FALSE(observer1->IsOpen());
2011}
2012
2013// This test that if a data channel is added in an answer a receive only channel
2014// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002015TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002016 RTCConfiguration config;
2017 config.enable_rtp_data_channel = true;
2018 config.enable_dtls_srtp = false;
2019
2020 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021
2022 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002023 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 pc_->CreateDataChannel(offer_label, NULL);
2025
2026 CreateOfferAsLocalDescription();
2027
2028 // Replace the data channel label in the offer and apply it as an answer.
2029 std::string receive_label = "answer_channel";
2030 std::string sdp;
2031 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002032 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
Yves Gerey665174f2018-06-19 15:03:05 +02002033 receive_label.c_str(), receive_label.length(), &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 CreateAnswerAsRemoteDescription(sdp);
2035
2036 // Verify that a new incoming data channel has been created and that
2037 // it is open but can't we written to.
2038 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2039 DataChannelInterface* received_channel = observer_.last_datachannel_;
2040 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2041 EXPECT_EQ(receive_label, received_channel->label());
2042 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2043
2044 // Verify that the channel we initially offered has been rejected.
2045 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2046
2047 // Do another offer / answer exchange and verify that the data channel is
2048 // opened.
2049 CreateOfferReceiveAnswer();
2050 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2051 kTimeout);
2052}
2053
2054// This test that no data channel is returned if a reliable channel is
2055// requested.
2056// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002057TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002058 RTCConfiguration rtc_config;
2059 rtc_config.enable_rtp_data_channel = true;
2060 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061
2062 std::string label = "test";
2063 webrtc::DataChannelInit config;
2064 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002065 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 pc_->CreateDataChannel(label, &config);
2067 EXPECT_TRUE(channel == NULL);
2068}
2069
deadbeefab9b2d12015-10-14 11:33:11 -07002070// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002071TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002072 RTCConfiguration config;
2073 config.enable_rtp_data_channel = true;
2074 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002075
2076 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002077 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002078 pc_->CreateDataChannel(label, nullptr);
2079 EXPECT_NE(channel, nullptr);
2080
zhihuang9763d562016-08-05 11:14:50 -07002081 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002082 pc_->CreateDataChannel(label, nullptr);
2083 EXPECT_EQ(dup_channel, nullptr);
2084}
2085
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086// This tests that a SCTP data channel is returned using different
2087// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002088TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002089 RTCConfiguration rtc_config;
2090 rtc_config.enable_dtls_srtp = true;
2091 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092
2093 webrtc::DataChannelInit config;
2094
zhihuang9763d562016-08-05 11:14:50 -07002095 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096 pc_->CreateDataChannel("1", &config);
2097 EXPECT_TRUE(channel != NULL);
2098 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002099 EXPECT_TRUE(observer_.renegotiation_needed_);
2100 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101
2102 config.ordered = false;
2103 channel = pc_->CreateDataChannel("2", &config);
2104 EXPECT_TRUE(channel != NULL);
2105 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002106 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107
2108 config.ordered = true;
2109 config.maxRetransmits = 0;
2110 channel = pc_->CreateDataChannel("3", &config);
2111 EXPECT_TRUE(channel != NULL);
2112 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002113 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
2115 config.maxRetransmits = -1;
2116 config.maxRetransmitTime = 0;
2117 channel = pc_->CreateDataChannel("4", &config);
2118 EXPECT_TRUE(channel != NULL);
2119 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002120 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121}
2122
2123// This tests that no data channel is returned if both maxRetransmits and
2124// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002125TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002127 RTCConfiguration rtc_config;
2128 rtc_config.enable_dtls_srtp = true;
2129 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130
2131 std::string label = "test";
2132 webrtc::DataChannelInit config;
2133 config.maxRetransmits = 0;
2134 config.maxRetransmitTime = 0;
2135
zhihuang9763d562016-08-05 11:14:50 -07002136 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 pc_->CreateDataChannel(label, &config);
2138 EXPECT_TRUE(channel == NULL);
2139}
2140
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141// The test verifies that creating a SCTP data channel with an id already in use
2142// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002143TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002145 RTCConfiguration rtc_config;
2146 rtc_config.enable_dtls_srtp = true;
2147 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148
2149 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002150 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002152 config.id = 1;
2153 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 EXPECT_TRUE(channel != NULL);
2155 EXPECT_EQ(1, channel->id());
2156
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157 channel = pc_->CreateDataChannel("x", &config);
2158 EXPECT_TRUE(channel == NULL);
2159
2160 config.id = cricket::kMaxSctpSid;
2161 channel = pc_->CreateDataChannel("max", &config);
2162 EXPECT_TRUE(channel != NULL);
2163 EXPECT_EQ(config.id, channel->id());
2164
2165 config.id = cricket::kMaxSctpSid + 1;
2166 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
zhihuang9763d562016-08-05 11:14:50 -07002199 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002200 pc_->CreateDataChannel("test2", NULL);
2201 EXPECT_TRUE(observer_.renegotiation_needed_);
2202}
2203
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002205TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002206 RTCConfiguration rtc_config;
2207 rtc_config.enable_rtp_data_channel = true;
2208 rtc_config.enable_dtls_srtp = false;
2209 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210
zhihuang9763d562016-08-05 11:14:50 -07002211 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002213 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 pc_->CreateDataChannel("test2", NULL);
2215 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002216 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002218 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 new MockDataChannelObserver(data2));
2220
2221 CreateOfferReceiveAnswer();
2222 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2223 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2224
2225 ReleasePeerConnection();
2226 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2227 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2228}
2229
Zhi Huang644fde42018-04-02 19:16:26 -07002230// This tests that RTP data channels can be rejected in an answer.
2231TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002232 RTCConfiguration rtc_config;
2233 rtc_config.enable_rtp_data_channel = true;
2234 rtc_config.enable_dtls_srtp = false;
2235 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236
zhihuang9763d562016-08-05 11:14:50 -07002237 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 pc_->CreateDataChannel("offer_channel", NULL));
2239
2240 CreateOfferAsLocalDescription();
2241
2242 // Create an answer where the m-line for data channels are rejected.
2243 std::string sdp;
2244 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002245 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002246 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002247 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002249 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 data_info->rejected = true;
2251
Steve Antondb45ca82017-09-11 18:27:34 -07002252 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2254}
2255
Zhi Huang644fde42018-04-02 19:16:26 -07002256#ifdef HAVE_SCTP
2257// This tests that SCTP data channels can be rejected in an answer.
2258TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2259#else
2260TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2261#endif
2262{
Niels Möllerf06f9232018-08-07 12:32:18 +02002263 RTCConfiguration rtc_config;
2264 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002265
2266 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2267 pc_->CreateDataChannel("offer_channel", NULL));
2268
2269 CreateOfferAsLocalDescription();
2270
2271 // Create an answer where the m-line for data channels are rejected.
2272 std::string sdp;
2273 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2274 std::unique_ptr<SessionDescriptionInterface> answer(
2275 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2276 ASSERT_TRUE(answer);
2277 cricket::ContentInfo* data_info =
2278 cricket::GetFirstDataContent(answer->description());
2279 data_info->rejected = true;
2280
2281 DoSetRemoteDescription(std::move(answer));
2282 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2283}
2284
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285// Test that we can create a session description from an SDP string from
2286// FireFox, use it as a remote session description, generate an answer and use
2287// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002288TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002289 RTCConfiguration rtc_config;
2290 rtc_config.enable_dtls_srtp = true;
2291 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002292 AddAudioTrack("audio_label");
2293 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002294 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002295 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002296 webrtc::kFireFoxSdpOffer, nullptr));
2297 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 CreateAnswerAsLocalDescription();
2299 ASSERT_TRUE(pc_->local_description() != NULL);
2300 ASSERT_TRUE(pc_->remote_description() != NULL);
2301
2302 const cricket::ContentInfo* content =
2303 cricket::GetFirstAudioContent(pc_->local_description()->description());
2304 ASSERT_TRUE(content != NULL);
2305 EXPECT_FALSE(content->rejected);
2306
2307 content =
2308 cricket::GetFirstVideoContent(pc_->local_description()->description());
2309 ASSERT_TRUE(content != NULL);
2310 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002311#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 content =
2313 cricket::GetFirstDataContent(pc_->local_description()->description());
2314 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002315 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002316#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317}
2318
zhihuangb19012e2017-09-19 13:47:59 -07002319// Test that fallback from DTLS to SDES is not supported.
2320// The fallback was previously supported but was removed to simplify the code
2321// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002322TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002323 RTCConfiguration rtc_config;
2324 rtc_config.enable_dtls_srtp = true;
2325 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002326 // Wait for fake certificate to be generated. Previously, this is what caused
2327 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002328 AddAudioTrack("audio_label");
2329 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002330 ASSERT_NE(nullptr, fake_certificate_generator_);
2331 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2332 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002333 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002334 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2335 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002336 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002337}
2338
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339// Test that we can create an audio only offer and receive an answer with a
2340// limited set of audio codecs and receive an updated offer with more audio
2341// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002342TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002343 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002344 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 CreateOfferAsLocalDescription();
2346
Steve Anton36da6ff2018-02-16 16:04:20 -08002347 const char* answer_sdp =
2348 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2349 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002350 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002351 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002352 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353
Steve Anton36da6ff2018-02-16 16:04:20 -08002354 const char* reoffer_sdp =
2355 (sdp_semantics_ == SdpSemantics::kPlanB
2356 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2357 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002358 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002359 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002360 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 CreateAnswerAsLocalDescription();
2362}
2363
deadbeefc80741f2015-10-22 13:14:45 -07002364// Test that if we're receiving (but not sending) a track, subsequent offers
2365// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002366TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002367 RTCConfiguration rtc_config;
2368 rtc_config.enable_dtls_srtp = true;
2369 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002370 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002371 CreateAnswerAsLocalDescription();
2372
2373 // At this point we should be receiving stream 1, but not sending anything.
2374 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002375 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002376 DoCreateOffer(&offer, nullptr);
2377
2378 const cricket::ContentInfo* video_content =
2379 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002380 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2381 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002382
2383 const cricket::ContentInfo* audio_content =
2384 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002385 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2386 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002387}
2388
2389// Test that if we're receiving (but not sending) a track, and the
2390// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2391// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002392TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002393 RTCConfiguration rtc_config;
2394 rtc_config.enable_dtls_srtp = true;
2395 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002396 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002397 CreateAnswerAsLocalDescription();
2398
2399 // At this point we should be receiving stream 1, but not sending anything.
2400 // A new offer would be recvonly, but we'll set the "no receive" constraints
2401 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002402 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002403 RTCOfferAnswerOptions options;
2404 options.offer_to_receive_audio = 0;
2405 options.offer_to_receive_video = 0;
2406 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002407
2408 const cricket::ContentInfo* video_content =
2409 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002410 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2411 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002412
2413 const cricket::ContentInfo* audio_content =
2414 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002415 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2416 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002417}
2418
deadbeef653b8e02015-11-11 12:55:10 -08002419// Test that we can use SetConfiguration to change the ICE servers of the
2420// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002421TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002422 CreatePeerConnection();
2423
Steve Anton36da6ff2018-02-16 16:04:20 -08002424 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002425 PeerConnectionInterface::IceServer server;
2426 server.uri = "stun:test_hostname";
2427 config.servers.push_back(server);
2428 EXPECT_TRUE(pc_->SetConfiguration(config));
2429
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002430 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2431 EXPECT_EQ("test_hostname",
2432 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002433}
2434
Steve Anton36da6ff2018-02-16 16:04:20 -08002435TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002436 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002437 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002438 config.type = PeerConnectionInterface::kRelay;
2439 EXPECT_TRUE(pc_->SetConfiguration(config));
2440 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2441}
2442
Steve Anton36da6ff2018-02-16 16:04:20 -08002443TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002444 PeerConnectionInterface::RTCConfiguration config;
2445 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002446 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002447 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002448 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2449
2450 config.prune_turn_ports = true;
2451 EXPECT_TRUE(pc_->SetConfiguration(config));
2452 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2453}
2454
skvladd1f5fda2017-02-03 16:54:05 -08002455// Test that the ice check interval can be changed. This does not verify that
2456// the setting makes it all the way to P2PTransportChannel, as that would
2457// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002458TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002459 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002460 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002461 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002462 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002463 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002464 EXPECT_TRUE(pc_->SetConfiguration(config));
2465 PeerConnectionInterface::RTCConfiguration new_config =
2466 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002467 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002468}
2469
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002470// Test that when SetConfiguration changes both the pool size and other
2471// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002472TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002473 SetConfigurationCreatesPooledSessionCorrectly) {
2474 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002475 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002476 config.ice_candidate_pool_size = 1;
2477 PeerConnectionInterface::IceServer server;
2478 server.uri = kStunAddressOnly;
2479 config.servers.push_back(server);
2480 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002481 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002482
2483 const cricket::FakePortAllocatorSession* session =
2484 static_cast<const cricket::FakePortAllocatorSession*>(
2485 port_allocator_->GetPooledSession());
2486 ASSERT_NE(nullptr, session);
2487 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002488}
2489
deadbeef293e9262017-01-11 12:28:30 -08002490// Test that after SetLocalDescription, changing the pool size is not allowed,
2491// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002492TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002493 CantChangePoolSizeAfterSetLocalDescription) {
2494 CreatePeerConnection();
2495 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002496 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002497 config.ice_candidate_pool_size = 1;
2498 EXPECT_TRUE(pc_->SetConfiguration(config));
2499
2500 // Set remote offer; can still change pool size at this point.
2501 CreateOfferAsRemoteDescription();
2502 config.ice_candidate_pool_size = 2;
2503 EXPECT_TRUE(pc_->SetConfiguration(config));
2504
2505 // Set local answer; now it's too late.
2506 CreateAnswerAsLocalDescription();
2507 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002508 RTCError error;
2509 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2510 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2511}
2512
deadbeef42a42632017-03-10 15:18:00 -08002513// Test that after setting an answer, extra pooled sessions are discarded. The
2514// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002515TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002516 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2517 CreatePeerConnection();
2518
2519 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002520 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002521 config.ice_candidate_pool_size = 4;
2522 EXPECT_TRUE(pc_->SetConfiguration(config));
2523
2524 // Do offer/answer.
2525 CreateOfferAsRemoteDescription();
2526 CreateAnswerAsLocalDescription();
2527
2528 // Expect no pooled sessions to be left.
2529 const cricket::PortAllocatorSession* session =
2530 port_allocator_->GetPooledSession();
2531 EXPECT_EQ(nullptr, session);
2532}
2533
2534// After Close is called, pooled candidates should be discarded so as to not
2535// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002536TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002537 CreatePeerConnection();
2538
Steve Anton36da6ff2018-02-16 16:04:20 -08002539 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002540 config.ice_candidate_pool_size = 3;
2541 EXPECT_TRUE(pc_->SetConfiguration(config));
2542 pc_->Close();
2543
2544 // Expect no pooled sessions to be left.
2545 const cricket::PortAllocatorSession* session =
2546 port_allocator_->GetPooledSession();
2547 EXPECT_EQ(nullptr, session);
2548}
2549
deadbeef293e9262017-01-11 12:28:30 -08002550// Test that SetConfiguration returns an invalid modification error if
2551// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002552TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002553 SetConfigurationReturnsInvalidModificationError) {
2554 PeerConnectionInterface::RTCConfiguration config;
2555 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2556 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2557 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002558 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002559
Steve Anton36da6ff2018-02-16 16:04:20 -08002560 PeerConnectionInterface::RTCConfiguration modified_config =
2561 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002562 modified_config.bundle_policy =
2563 PeerConnectionInterface::kBundlePolicyMaxBundle;
2564 RTCError error;
2565 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2566 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2567
Steve Anton36da6ff2018-02-16 16:04:20 -08002568 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002569 modified_config.rtcp_mux_policy =
2570 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2571 error.set_type(RTCErrorType::NONE);
2572 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2573 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2574
Steve Anton36da6ff2018-02-16 16:04:20 -08002575 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002576 modified_config.continual_gathering_policy =
2577 PeerConnectionInterface::GATHER_CONTINUALLY;
2578 error.set_type(RTCErrorType::NONE);
2579 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2580 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2581}
2582
2583// Test that SetConfiguration returns a range error if the candidate pool size
2584// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002585TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002586 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2587 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002588 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002589 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002590
2591 config.ice_candidate_pool_size = -1;
2592 RTCError error;
2593 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2594 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2595
2596 config.ice_candidate_pool_size = INT_MAX;
2597 error.set_type(RTCErrorType::NONE);
2598 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2599 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2600}
2601
2602// Test that SetConfiguration returns a syntax error if parsing an ICE server
2603// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002604TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002605 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2606 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002607 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002608 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002609
2610 PeerConnectionInterface::IceServer bad_server;
2611 bad_server.uri = "stunn:www.example.com";
2612 config.servers.push_back(bad_server);
2613 RTCError error;
2614 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2615 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2616}
2617
2618// Test that SetConfiguration returns an invalid parameter error if a TURN
2619// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002620TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002621 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2622 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002623 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002624 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002625
2626 PeerConnectionInterface::IceServer bad_server;
2627 bad_server.uri = "turn:www.example.com";
2628 // Missing password.
2629 bad_server.username = "foo";
2630 config.servers.push_back(bad_server);
2631 RTCError error;
2632 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2633 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002634}
2635
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636// Test that PeerConnection::Close changes the states to closed and all remote
2637// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002638TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002639 // Initialize a PeerConnection and negotiate local and remote session
2640 // description.
2641 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002642
2643 // With Plan B, verify the stream count. The analog with Unified Plan is the
2644 // RtpTransceiver count.
2645 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2646 ASSERT_EQ(1u, pc_->local_streams()->count());
2647 ASSERT_EQ(1u, pc_->remote_streams()->count());
2648 } else {
2649 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2650 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651
2652 pc_->Close();
2653
2654 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2655 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2656 pc_->ice_connection_state());
2657 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2658 pc_->ice_gathering_state());
2659
Steve Anton36da6ff2018-02-16 16:04:20 -08002660 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2661 EXPECT_EQ(1u, pc_->local_streams()->count());
2662 EXPECT_EQ(1u, pc_->remote_streams()->count());
2663 } else {
2664 // Verify that the RtpTransceivers are still present but all stopped.
2665 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Mirko Bonadei739baf02019-01-27 17:29:42 +01002666 for (const auto& transceiver : pc_->GetTransceivers()) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002667 EXPECT_TRUE(transceiver->stopped());
2668 }
2669 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670
Steve Anton36da6ff2018-02-16 16:04:20 -08002671 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2672 ASSERT_TRUE(audio_receiver);
2673 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2674 ASSERT_TRUE(video_receiver);
2675
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002676 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002677 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002678 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002679 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002680 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681}
2682
2683// Test that PeerConnection methods fails gracefully after
2684// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002685// Don't run under Unified Plan since the stream API is not available.
2686TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002687 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002688 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689 CreateOfferAsRemoteDescription();
2690 CreateAnswerAsLocalDescription();
2691
2692 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002693 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694 pc_->local_streams()->at(0);
2695
2696 pc_->Close();
2697
2698 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002699 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2702
2703 EXPECT_TRUE(pc_->local_description() != NULL);
2704 EXPECT_TRUE(pc_->remote_description() != NULL);
2705
kwibergd1fe2812016-04-27 06:47:29 -07002706 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002707 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002708 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002709 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710
2711 std::string sdp;
2712 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002713 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002714 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002715 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716
2717 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002718 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002719 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002720 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002721}
2722
2723// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002724TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 InitiateCall();
2726 pc_->Close();
2727 DoGetStats(NULL);
2728}
deadbeefab9b2d12015-10-14 11:33:11 -07002729
2730// NOTE: The series of tests below come from what used to be
2731// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2732// setting a remote or local description has the expected effects.
2733
2734// This test verifies that the remote MediaStreams corresponding to a received
2735// SDP string is created. In this test the two separate MediaStreams are
2736// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002737TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002738 RTCConfiguration config;
2739 config.enable_dtls_srtp = true;
2740 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002741 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002742
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002743 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002744 EXPECT_TRUE(
2745 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2746 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2747 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2748
2749 // Create a session description based on another SDP with another
2750 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002751 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002752
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002753 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002754 EXPECT_TRUE(
2755 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2756}
2757
2758// This test verifies that when remote tracks are added/removed from SDP, the
2759// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002760// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2761// specific behavior.
2762TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002763 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002764 RTCConfiguration config;
2765 config.enable_dtls_srtp = true;
2766 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002767 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002768 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002769 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002770 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2771 reference_collection_));
2772
2773 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002774 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002775 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002776 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002777 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2778 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002779 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002780 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2781 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002782 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002783 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2784 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002785
2786 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002787 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002788 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002789 MockTrackObserver audio_track_observer(audio_track2);
2790 MockTrackObserver video_track_observer(video_track2);
2791
2792 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2793 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002794 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002795 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2796 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002797 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002798 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002799 audio_track2->state(), kTimeout);
2800 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2801 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002802}
2803
2804// This tests that remote tracks are ended if a local session description is set
2805// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002806TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002807 RTCConfiguration config;
2808 config.enable_dtls_srtp = true;
2809 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002810 // First create and set a remote offer, then reject its video content in our
2811 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002812 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2813 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2814 ASSERT_TRUE(audio_receiver);
2815 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2816 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002817
Steve Anton36da6ff2018-02-16 16:04:20 -08002818 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2819 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002820 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002821 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2822 video_receiver->track();
2823 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002824
kwibergd1fe2812016-04-27 06:47:29 -07002825 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002826 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002827 cricket::ContentInfo* video_info =
2828 local_answer->description()->GetContentByName("video");
2829 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002830 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002831 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2832 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002833
2834 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002835 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002836 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002837 video_info = local_offer->description()->GetContentByName("video");
2838 ASSERT_TRUE(video_info != nullptr);
2839 video_info->rejected = true;
2840 cricket::ContentInfo* audio_info =
2841 local_offer->description()->GetContentByName("audio");
2842 ASSERT_TRUE(audio_info != nullptr);
2843 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002844 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002845 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002846 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2847 kTimeout);
2848 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2849 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002850}
2851
2852// This tests that we won't crash if the remote track has been removed outside
2853// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002854// Don't run under Unified Plan since the stream API is not available.
2855TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002856 RTCConfiguration config;
2857 config.enable_dtls_srtp = true;
2858 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002859 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002860 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2861 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2862 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2863
kwibergd1fe2812016-04-27 06:47:29 -07002864 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002865 webrtc::CreateSessionDescription(SdpType::kAnswer,
2866 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002867 cricket::ContentInfo* video_info =
2868 local_answer->description()->GetContentByName("video");
2869 video_info->rejected = true;
2870 cricket::ContentInfo* audio_info =
2871 local_answer->description()->GetContentByName("audio");
2872 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002873 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002874
2875 // No crash is a pass.
2876}
2877
deadbeef5e97fb52015-10-15 12:49:08 -07002878// This tests that if a recvonly remote description is set, no remote streams
2879// will be created, even if the description contains SSRCs/MSIDs.
2880// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002881TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002882 RTCConfiguration config;
2883 config.enable_dtls_srtp = true;
2884 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002885
Steve Anton36da6ff2018-02-16 16:04:20 -08002886 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002887 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2888 strlen(kRecvonly), &recvonly_offer);
2889 CreateAndSetRemoteOffer(recvonly_offer);
2890
2891 EXPECT_EQ(0u, observer_.remote_streams()->count());
2892}
2893
deadbeefab9b2d12015-10-14 11:33:11 -07002894// This tests that a default MediaStream is created if a remote session
2895// description doesn't contain any streams and no MSID support.
2896// It also tests that the default stream is updated if a video m-line is added
2897// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002898// Don't run under Unified Plan since this behavior is Plan B specific.
2899TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002900 RTCConfiguration config;
2901 config.enable_dtls_srtp = true;
2902 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002903 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2904
2905 ASSERT_EQ(1u, observer_.remote_streams()->count());
2906 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2907
2908 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2909 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002910 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002911
2912 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2913 ASSERT_EQ(1u, observer_.remote_streams()->count());
2914 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2915 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002916 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2917 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002918 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2919 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002920 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2921 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002922}
2923
2924// This tests that a default MediaStream is created if a remote session
2925// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002926// Don't run under Unified Plan since this behavior is Plan B specific.
2927TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002928 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002929 RTCConfiguration config;
2930 config.enable_dtls_srtp = true;
2931 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002932 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2933
2934 ASSERT_EQ(1u, observer_.remote_streams()->count());
2935 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2936
2937 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2938 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002939 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002940}
2941
2942// This tests that it won't crash when PeerConnection tries to remove
2943// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002944// Don't run under Unified Plan since this behavior is Plan B specific.
2945TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002946 RTCConfiguration config;
2947 config.enable_dtls_srtp = true;
2948 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002949 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002950 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2951 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2952 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2953
2954 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2955
2956 // No crash is a pass.
2957}
2958
2959// This tests that a default MediaStream is created if the remote session
2960// description doesn't contain any streams and don't contain an indication if
2961// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002962// Don't run under Unified Plan since this behavior is Plan B specific.
2963TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002964 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002965 RTCConfiguration config;
2966 config.enable_dtls_srtp = true;
2967 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002968 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2969
2970 ASSERT_EQ(1u, observer_.remote_streams()->count());
2971 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2972 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2973 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2974}
2975
2976// This tests that a default MediaStream is not created if the remote session
2977// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002978// Don't run under Unified Plan since this behavior is Plan B specific.
2979TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002980 RTCConfiguration config;
2981 config.enable_dtls_srtp = true;
2982 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002983 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2984 EXPECT_EQ(0u, observer_.remote_streams()->count());
2985}
2986
deadbeefbda7e0b2015-12-08 17:13:40 -08002987// This tests that when setting a new description, the old default tracks are
2988// not destroyed and recreated.
2989// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002990// Don't run under Unified Plan since this behavior is Plan B specific.
2991TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002992 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002993 RTCConfiguration config;
2994 config.enable_dtls_srtp = true;
2995 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08002996 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2997
2998 ASSERT_EQ(1u, observer_.remote_streams()->count());
2999 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3000 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3001
3002 // Set the track to "disabled", then set a new description and ensure the
3003 // track is still disabled, which ensures it hasn't been recreated.
3004 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3005 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3006 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3007 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3008}
3009
deadbeefab9b2d12015-10-14 11:33:11 -07003010// This tests that a default MediaStream is not created if a remote session
3011// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003012// Don't run under Unified Plan since this behavior is Plan B specific.
3013TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003014 RTCConfiguration config;
3015 config.enable_dtls_srtp = true;
3016 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003017 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003018 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003019 EXPECT_TRUE(
3020 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3021
3022 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3023 EXPECT_EQ(0u, observer_.remote_streams()->count());
3024}
3025
Seth Hampson5897a6e2018-04-03 11:16:33 -07003026// This tests that a default MediaStream is created if a remote SDP comes from
3027// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3028TEST_F(PeerConnectionInterfaceTestPlanB,
3029 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003030 RTCConfiguration config;
3031 config.enable_dtls_srtp = true;
3032 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003033 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3034 // Add a=msid lines to simulate a Unified Plan endpoint that only
3035 // signals stream IDs with a=msid lines.
3036 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3037
3038 CreateAndSetRemoteOffer(sdp_string);
3039
3040 ASSERT_EQ(1u, observer_.remote_streams()->count());
3041 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3042 EXPECT_EQ("default", remote_stream->id());
3043 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3044}
3045
Seth Hampson5b4f0752018-04-02 16:31:36 -07003046// This tests that when a Plan B endpoint receives an SDP that signals no media
3047// stream IDs indicated by the special character "-" in the a=msid line, that
3048// a default stream ID will be used for the MediaStream ID. This can occur
3049// when a Unified Plan endpoint signals no media stream IDs, but signals both
3050// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3051TEST_F(PeerConnectionInterfaceTestPlanB,
3052 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003053 RTCConfiguration config;
3054 config.enable_dtls_srtp = true;
3055 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003056 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3057 // the sender's stream ID will be interpreted as no stream IDs.
3058 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3059 sdp_string.append("a=msid:- audiotrack0\n");
3060
3061 CreateAndSetRemoteOffer(sdp_string);
3062
3063 ASSERT_EQ(1u, observer_.remote_streams()->count());
3064 // Because SSRCs are signaled the track ID will be what was signaled in the
3065 // a=msid line.
3066 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3067 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3068 EXPECT_EQ("default", remote_stream->id());
3069 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003070
3071 // Previously a bug ocurred when setting the remote description a second time.
3072 // This is because we checked equality of the remote StreamParams stream ID
3073 // (empty), and the previously set stream ID for the remote sender
3074 // ("default"). This cause a track to be removed, then added, when really
3075 // nothing should occur because it is the same track.
3076 CreateAndSetRemoteOffer(sdp_string);
3077 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3078 EXPECT_EQ(1u, observer_.add_track_events_.size());
3079 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3080 remote_stream = observer_.remote_streams()->at(0);
3081 EXPECT_EQ("default", remote_stream->id());
3082 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003083}
3084
deadbeefab9b2d12015-10-14 11:33:11 -07003085// This tests that an RtpSender is created when the local description is set
3086// after adding a local stream.
3087// TODO(deadbeef): This test and the one below it need to be updated when
3088// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003089// Don't run under Unified Plan since this behavior is Plan B specific.
3090TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003091 RTCConfiguration config;
3092 config.enable_dtls_srtp = true;
3093 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003094
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003095 // Create an offer with 1 stream with 2 tracks of each type.
3096 rtc::scoped_refptr<StreamCollection> stream_collection =
3097 CreateStreamCollection(1, 2);
3098 pc_->AddStream(stream_collection->at(0));
3099 std::unique_ptr<SessionDescriptionInterface> offer;
3100 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003101 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003102
deadbeefab9b2d12015-10-14 11:33:11 -07003103 auto senders = pc_->GetSenders();
3104 EXPECT_EQ(4u, senders.size());
3105 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3106 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3107 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3108 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3109
3110 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003111 pc_->RemoveStream(stream_collection->at(0));
3112 stream_collection = CreateStreamCollection(1, 1);
3113 pc_->AddStream(stream_collection->at(0));
3114 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003115 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003116
deadbeefab9b2d12015-10-14 11:33:11 -07003117 senders = pc_->GetSenders();
3118 EXPECT_EQ(2u, senders.size());
3119 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3120 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3121 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3122 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3123}
3124
3125// This tests that an RtpSender is created when the local description is set
3126// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003127// Don't run under Unified Plan since this behavior is Plan B specific.
3128TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003129 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003130 RTCConfiguration config;
3131 config.enable_dtls_srtp = true;
3132 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003133
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003134 rtc::scoped_refptr<StreamCollection> stream_collection =
3135 CreateStreamCollection(1, 2);
3136 // Add a stream to create the offer, but remove it afterwards.
3137 pc_->AddStream(stream_collection->at(0));
3138 std::unique_ptr<SessionDescriptionInterface> offer;
3139 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3140 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003141
Steve Antondb45ca82017-09-11 18:27:34 -07003142 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003143 auto senders = pc_->GetSenders();
3144 EXPECT_EQ(0u, senders.size());
3145
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003146 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003147 senders = pc_->GetSenders();
3148 EXPECT_EQ(4u, senders.size());
3149 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3150 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3151 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3152 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3153}
3154
3155// This tests that the expected behavior occurs if the SSRC on a local track is
3156// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003157TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003158 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003159 RTCConfiguration config;
3160 config.enable_dtls_srtp = true;
3161 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003162
Steve Anton36da6ff2018-02-16 16:04:20 -08003163 AddAudioTrack(kAudioTracks[0]);
3164 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003165 std::unique_ptr<SessionDescriptionInterface> offer;
3166 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3167 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003168 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3169 webrtc::CreateSessionDescription(
3170 webrtc::SdpType::kOffer, offer->session_id(),
3171 offer->session_version(),
3172 absl::WrapUnique(offer->description()->Copy()));
Steve Antondb45ca82017-09-11 18:27:34 -07003173 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003174
deadbeefab9b2d12015-10-14 11:33:11 -07003175 auto senders = pc_->GetSenders();
3176 EXPECT_EQ(2u, senders.size());
3177 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3178 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3179
3180 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003181 cricket::MediaContentDescription* desc =
3182 cricket::GetFirstAudioContentDescription(modified_offer->description());
3183 ASSERT_TRUE(desc != NULL);
3184 for (StreamParams& stream : desc->mutable_streams()) {
3185 for (unsigned int& ssrc : stream.ssrcs) {
3186 ++ssrc;
3187 }
3188 }
deadbeefab9b2d12015-10-14 11:33:11 -07003189
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003190 desc =
3191 cricket::GetFirstVideoContentDescription(modified_offer->description());
3192 ASSERT_TRUE(desc != NULL);
3193 for (StreamParams& stream : desc->mutable_streams()) {
3194 for (unsigned int& ssrc : stream.ssrcs) {
3195 ++ssrc;
3196 }
3197 }
3198
Steve Antondb45ca82017-09-11 18:27:34 -07003199 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003200 senders = pc_->GetSenders();
3201 EXPECT_EQ(2u, senders.size());
3202 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3203 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3204 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3205 // changed.
3206}
3207
3208// This tests that the expected behavior occurs if a new session description is
3209// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003210// Don't run under Unified Plan since the stream API is not available.
3211TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003212 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003213 RTCConfiguration config;
3214 config.enable_dtls_srtp = true;
3215 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003216
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003217 rtc::scoped_refptr<StreamCollection> stream_collection =
3218 CreateStreamCollection(2, 1);
3219 pc_->AddStream(stream_collection->at(0));
3220 std::unique_ptr<SessionDescriptionInterface> offer;
3221 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003222 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003223
deadbeefab9b2d12015-10-14 11:33:11 -07003224 auto senders = pc_->GetSenders();
3225 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003226 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3227 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003228
3229 // Add a new MediaStream but with the same tracks as in the first stream.
3230 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3231 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003232 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3233 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003234 pc_->AddStream(stream_1);
3235
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003236 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003237 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003238
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003239 auto new_senders = pc_->GetSenders();
3240 // Should be the same senders as before, but with updated stream id.
3241 // Note that this behavior is subject to change in the future.
3242 // We may decide the PC should ignore existing tracks in AddStream.
3243 EXPECT_EQ(senders, new_senders);
3244 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3245 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003246}
3247
zhihuang81c3a032016-11-17 12:06:24 -08003248// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003249TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003250 RTCConfiguration config;
3251 config.enable_dtls_srtp = true;
3252 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003253 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3254 EXPECT_EQ(observer_.num_added_tracks_, 1);
3255 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3256
3257 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003258 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003259 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003260 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3261}
3262
deadbeefd1a38b52016-12-10 13:15:33 -08003263// Test that when SetConfiguration is called and the configuration is
3264// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003265TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003266 PeerConnectionInterface::RTCConfiguration config;
3267 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003268 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003269 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003270 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3271 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003272
3273 // Do initial offer/answer so there's something to restart.
3274 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003275 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003276
3277 // Grab the ufrags.
3278 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3279
3280 // Change ICE policy, which should trigger an ICE restart on the next offer.
3281 config.type = PeerConnectionInterface::kAll;
3282 EXPECT_TRUE(pc_->SetConfiguration(config));
3283 CreateOfferAsLocalDescription();
3284
3285 // Grab the new ufrags.
3286 std::vector<std::string> subsequent_ufrags =
3287 GetUfrags(pc_->local_description());
3288
3289 // Sanity check.
3290 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3291 // Check that each ufrag is different.
3292 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3293 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3294 }
3295}
3296
3297// Test that when SetConfiguration is called and the configuration *isn't*
3298// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003299TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003300 PeerConnectionInterface::RTCConfiguration config;
3301 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003302 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003303 config = pc_->GetConfiguration();
3304 AddAudioTrack(kAudioTracks[0]);
3305 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003306
3307 // Do initial offer/answer so there's something to restart.
3308 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003309 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003310
3311 // Grab the ufrags.
3312 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3313
3314 // Call SetConfiguration with a config identical to what the PC was
3315 // constructed with.
3316 EXPECT_TRUE(pc_->SetConfiguration(config));
3317 CreateOfferAsLocalDescription();
3318
3319 // Grab the new ufrags.
3320 std::vector<std::string> subsequent_ufrags =
3321 GetUfrags(pc_->local_description());
3322
3323 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3324}
3325
3326// Test for a weird corner case scenario:
3327// 1. Audio/video session established.
3328// 2. SetConfiguration changes ICE config; ICE restart needed.
3329// 3. ICE restart initiated by remote peer, but only for one m= section.
3330// 4. Next createOffer should initiate an ICE restart, but only for the other
3331// m= section; it would be pointless to do an ICE restart for the m= section
3332// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003333TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003334 PeerConnectionInterface::RTCConfiguration config;
3335 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003336 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003337 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003338 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3339 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003340
3341 // Do initial offer/answer so there's something to restart.
3342 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003343 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003344
3345 // Change ICE policy, which should set the "needs-ice-restart" flag.
3346 config.type = PeerConnectionInterface::kAll;
3347 EXPECT_TRUE(pc_->SetConfiguration(config));
3348
3349 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003350 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003351 webrtc::CreateSessionDescription(SdpType::kOffer,
3352 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003353 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003354 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3355 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003356 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003357 CreateAnswerAsLocalDescription();
3358
3359 // Grab the ufrags.
3360 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003361 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003362
3363 // Create offer and grab the new ufrags.
3364 CreateOfferAsLocalDescription();
3365 std::vector<std::string> subsequent_ufrags =
3366 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003367 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003368
3369 // Ensure that only the ufrag for the second m= section changed.
3370 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3371 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3372}
3373
deadbeeffe4a8a42016-12-20 17:56:17 -08003374// Tests that the methods to return current/pending descriptions work as
3375// expected at different points in the offer/answer exchange. This test does
3376// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003377TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003378 // This disables DTLS so we can apply an answer to ourselves.
3379 CreatePeerConnection();
3380
3381 // Create initial local offer and get SDP (which will also be used as
3382 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003383 std::unique_ptr<SessionDescriptionInterface> local_offer;
3384 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003385 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003386 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003387
3388 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003389 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3390 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3391 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003392 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3393 EXPECT_EQ(nullptr, pc_->current_local_description());
3394 EXPECT_EQ(nullptr, pc_->current_remote_description());
3395
3396 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003397 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003398 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003399 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3400 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3401 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3402 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003403 EXPECT_EQ(nullptr, pc_->current_local_description());
3404 EXPECT_EQ(nullptr, pc_->current_remote_description());
3405
3406 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003407 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003408 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003409 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3410 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003411 EXPECT_EQ(nullptr, pc_->pending_local_description());
3412 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003413 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3414 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003415
3416 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003417 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003418 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003419 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3420 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3421 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003422 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003423 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3424 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003425
3426 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003427 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003428 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003429 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3430 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3431 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3432 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3433 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3434 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003435
3436 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003437 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003438 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003439 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3440 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003441 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3442 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003443 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3444 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003445}
3446
zhihuang77985012017-02-07 15:45:16 -08003447// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3448// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003449// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003450TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003451 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003452 CreatePeerConnection();
3453 // The RtcEventLog will be reset when the PeerConnection is closed.
3454 pc_->Close();
3455
Elad Alon9e6565b2017-10-11 16:04:13 +02003456 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3457 std::string filename = webrtc::test::OutputPath() +
3458 test_info->test_case_name() + test_info->name();
3459 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3460
3461 constexpr int64_t max_size_bytes = 1024;
3462
zhihuang77985012017-02-07 15:45:16 -08003463 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3464 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003465
3466 // Cleanup.
3467 rtc::ClosePlatformFile(file);
3468 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003469}
3470
Elad Alon99c3fe52017-10-13 16:29:40 +02003471// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3472// after the PeerConnection is closed.
3473// This version tests the StartRtcEventLog version that receives an object
3474// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003475TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003476 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3477 CreatePeerConnection();
3478 // The RtcEventLog will be reset when the PeerConnection is closed.
3479 pc_->Close();
3480
3481 rtc::PlatformFile file = 0;
3482 int64_t max_size_bytes = 1024;
3483 EXPECT_FALSE(pc_->StartRtcEventLog(
Karl Wiberg918f50c2018-07-05 11:40:33 +02003484 absl::make_unique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
Bjorn Tereliusde939432017-11-20 17:38:14 +01003485 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003486 pc_->StopRtcEventLog();
3487}
3488
deadbeef30952b42017-04-21 02:41:29 -07003489// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003490TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003491 CreatePeerConnection();
3492
3493 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003494 RTCOfferAnswerOptions options;
3495 options.offer_to_receive_audio = 1;
3496 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003497 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003498 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003499 cricket::SessionDescription* desc = offer->description();
3500 ASSERT_EQ(2u, desc->transport_infos().size());
3501 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3502 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3503
3504 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003505 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003506 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003507 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003508 desc = answer->description();
3509 ASSERT_EQ(2u, desc->transport_infos().size());
3510 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3511 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3512}
3513
deadbeef1dcb1642017-03-29 21:08:16 -07003514// Test that ICE renomination isn't offered if it's not enabled in the PC's
3515// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003516TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003517 PeerConnectionInterface::RTCConfiguration config;
3518 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003519 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003520 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003521
3522 std::unique_ptr<SessionDescriptionInterface> offer;
3523 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3524 cricket::SessionDescription* desc = offer->description();
3525 EXPECT_EQ(1u, desc->transport_infos().size());
3526 EXPECT_FALSE(
3527 desc->transport_infos()[0].description.GetIceParameters().renomination);
3528}
3529
3530// Test that the ICE renomination option is present in generated offers/answers
3531// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003532TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003533 PeerConnectionInterface::RTCConfiguration config;
3534 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003535 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003536 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003537
3538 std::unique_ptr<SessionDescriptionInterface> offer;
3539 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3540 cricket::SessionDescription* desc = offer->description();
3541 EXPECT_EQ(1u, desc->transport_infos().size());
3542 EXPECT_TRUE(
3543 desc->transport_infos()[0].description.GetIceParameters().renomination);
3544
3545 // Set the offer as a remote description, then create an answer and ensure it
3546 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003547 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003548 std::unique_ptr<SessionDescriptionInterface> answer;
3549 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3550 desc = answer->description();
3551 EXPECT_EQ(1u, desc->transport_infos().size());
3552 EXPECT_TRUE(
3553 desc->transport_infos()[0].description.GetIceParameters().renomination);
3554}
3555
3556// Test that if CreateOffer is called with the deprecated "offer to receive
3557// audio/video" constraints, they're processed and result in an offer with
3558// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003559TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003560 CreatePeerConnection();
3561
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));
deadbeef1dcb1642017-03-29 21:08:16 -07003567
3568 cricket::SessionDescription* desc = offer->description();
3569 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3570 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3571 ASSERT_NE(nullptr, audio);
3572 ASSERT_NE(nullptr, video);
3573 EXPECT_FALSE(audio->rejected);
3574 EXPECT_FALSE(video->rejected);
3575}
3576
3577// Test that if CreateAnswer is called with the deprecated "offer to receive
3578// audio/video" constraints, they're processed and can be used to reject an
3579// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003580// Don't run under Unified Plan since this behavior is not supported.
3581TEST_F(PeerConnectionInterfaceTestPlanB,
3582 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003583 CreatePeerConnection();
3584
3585 // First, create an offer with audio/video and apply it as a remote
3586 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003587 RTCOfferAnswerOptions options;
3588 options.offer_to_receive_audio = 1;
3589 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003590 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003591 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003592 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003593
3594 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003595 options.offer_to_receive_audio = 0;
3596 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003597 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003598 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003599
3600 cricket::SessionDescription* desc = answer->description();
3601 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3602 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3603 ASSERT_NE(nullptr, audio);
3604 ASSERT_NE(nullptr, video);
3605 EXPECT_TRUE(audio->rejected);
3606 EXPECT_TRUE(video->rejected);
3607}
3608
deadbeef1dcb1642017-03-29 21:08:16 -07003609// Test that negotiation can succeed with a data channel only, and with the max
3610// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003611#ifdef HAVE_SCTP
3612TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3613#else
3614TEST_P(PeerConnectionInterfaceTest,
3615 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3616#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003617 PeerConnectionInterface::RTCConfiguration config;
3618 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003619 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003620
3621 // First, create an offer with only a data channel and apply it as a remote
3622 // description.
3623 pc_->CreateDataChannel("test", nullptr);
3624 std::unique_ptr<SessionDescriptionInterface> offer;
3625 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003626 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003627
3628 // Create and set answer as well.
3629 std::unique_ptr<SessionDescriptionInterface> answer;
3630 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003631 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003632}
3633
Steve Anton36da6ff2018-02-16 16:04:20 -08003634TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003635 CreatePeerConnection();
3636 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003637 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003638 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3639}
3640
Steve Anton36da6ff2018-02-16 16:04:20 -08003641TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003642 CreatePeerConnection();
3643 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003644 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003645 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3646}
3647
Steve Anton36da6ff2018-02-16 16:04:20 -08003648TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003649 CreatePeerConnection();
3650 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003651 bitrate.min_bitrate_bps = 5;
3652 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003653 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3654}
3655
Steve Anton36da6ff2018-02-16 16:04:20 -08003656TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003657 CreatePeerConnection();
3658 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003659 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003660 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3661}
3662
Steve Anton36da6ff2018-02-16 16:04:20 -08003663TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003664 CreatePeerConnection();
3665 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003666 bitrate.current_bitrate_bps = 10;
3667 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003668 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3669}
3670
Steve Anton36da6ff2018-02-16 16:04:20 -08003671TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003672 CreatePeerConnection();
3673 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003674 bitrate.min_bitrate_bps = 10;
3675 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003676 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3677}
3678
Steve Anton36da6ff2018-02-16 16:04:20 -08003679TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003680 CreatePeerConnection();
3681 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003682 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003683 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3684}
3685
Steve Anton038834f2017-07-14 15:59:59 -07003686// ice_regather_interval_range requires WebRTC to be configured for continual
3687// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003688TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003689 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3690 PeerConnectionInterface::RTCConfiguration config;
3691 config.ice_regather_interval_range.emplace(1000, 2000);
3692 config.continual_gathering_policy =
3693 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3694 CreatePeerConnectionExpectFail(config);
3695}
3696
3697// Ensures that there is no error when ice_regather_interval_range is set with
3698// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003699TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003700 SetIceRegatherIntervalRangeWithContinualGathering) {
3701 PeerConnectionInterface::RTCConfiguration config;
3702 config.ice_regather_interval_range.emplace(1000, 2000);
3703 config.continual_gathering_policy =
3704 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003705 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003706}
3707
Niels Möller0c4f7be2018-05-07 14:01:37 +02003708// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003709// by Call's BitrateConstraints, which comes from the SDP or a default value.
3710// This test checks that a call to SetBitrate with a current bitrate that will
3711// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003712TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003713 CreatePeerConnection();
3714 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003715 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003716 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3717}
3718
zhihuang1c378ed2017-08-17 14:10:50 -07003719// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003720TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003721 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3722 RTCOfferAnswerOptions rtc_options;
3723
3724 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3725 // than kMaxOfferToReceiveMedia should be treated as invalid.
3726 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3727 CreatePeerConnection();
3728 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3729
3730 rtc_options.offer_to_receive_audio =
3731 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3732 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3733}
3734
Steve Anton36da6ff2018-02-16 16:04:20 -08003735TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003736 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3737 RTCOfferAnswerOptions rtc_options;
3738
3739 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3740 // than kMaxOfferToReceiveMedia should be treated as invalid.
3741 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3742 CreatePeerConnection();
3743 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3744
3745 rtc_options.offer_to_receive_video =
3746 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3747 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3748}
3749
3750// Test that the audio and video content will be added to an offer if both
3751// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003752TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003753 RTCOfferAnswerOptions rtc_options;
3754 rtc_options.offer_to_receive_audio = 1;
3755 rtc_options.offer_to_receive_video = 1;
3756
3757 std::unique_ptr<SessionDescriptionInterface> offer;
3758 CreatePeerConnection();
3759 offer = CreateOfferWithOptions(rtc_options);
3760 ASSERT_TRUE(offer);
3761 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3762 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3763}
3764
3765// Test that only audio content will be added to the offer if only
3766// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003767TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003768 RTCOfferAnswerOptions rtc_options;
3769 rtc_options.offer_to_receive_audio = 1;
3770 rtc_options.offer_to_receive_video = 0;
3771
3772 std::unique_ptr<SessionDescriptionInterface> offer;
3773 CreatePeerConnection();
3774 offer = CreateOfferWithOptions(rtc_options);
3775 ASSERT_TRUE(offer);
3776 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3777 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3778}
3779
3780// Test that only video content will be added if only |offer_to_receive_video|
3781// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003782TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003783 RTCOfferAnswerOptions rtc_options;
3784 rtc_options.offer_to_receive_audio = 0;
3785 rtc_options.offer_to_receive_video = 1;
3786
3787 std::unique_ptr<SessionDescriptionInterface> offer;
3788 CreatePeerConnection();
3789 offer = CreateOfferWithOptions(rtc_options);
3790 ASSERT_TRUE(offer);
3791 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3792 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3793}
3794
zhihuang1c378ed2017-08-17 14:10:50 -07003795// Test that no media content will be added to the offer if using default
3796// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003797TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003798 RTCOfferAnswerOptions rtc_options;
3799
3800 std::unique_ptr<SessionDescriptionInterface> offer;
3801 CreatePeerConnection();
3802 offer = CreateOfferWithOptions(rtc_options);
3803 ASSERT_TRUE(offer);
3804 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3805 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3806}
3807
3808// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3809// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003810TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3811 CreatePeerConnection();
3812
zhihuang1c378ed2017-08-17 14:10:50 -07003813 RTCOfferAnswerOptions rtc_options;
3814 rtc_options.ice_restart = false;
3815 rtc_options.offer_to_receive_audio = 1;
3816
3817 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003818 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003819 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3820 auto ufrag1 =
3821 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3822 auto pwd1 =
3823 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003824
3825 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3826 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003827 auto ufrag2 =
3828 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3829 auto pwd2 =
3830 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003831
3832 // |ice_restart| is true, the ufrag/pwd should change.
3833 rtc_options.ice_restart = true;
3834 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003835 auto ufrag3 =
3836 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3837 auto pwd3 =
3838 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003839
3840 EXPECT_EQ(ufrag1, ufrag2);
3841 EXPECT_EQ(pwd1, pwd2);
3842 EXPECT_NE(ufrag2, ufrag3);
3843 EXPECT_NE(pwd2, pwd3);
3844}
3845
3846// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3847// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003848TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003849 RTCOfferAnswerOptions rtc_options;
3850 rtc_options.offer_to_receive_audio = 1;
3851 rtc_options.offer_to_receive_video = 1;
3852
3853 std::unique_ptr<SessionDescriptionInterface> offer;
3854 CreatePeerConnection();
3855
3856 rtc_options.use_rtp_mux = true;
3857 offer = CreateOfferWithOptions(rtc_options);
3858 ASSERT_TRUE(offer);
3859 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3860 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3861 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3862
3863 rtc_options.use_rtp_mux = false;
3864 offer = CreateOfferWithOptions(rtc_options);
3865 ASSERT_TRUE(offer);
3866 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3867 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3868 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3869}
3870
zhihuang141aacb2017-08-29 13:23:53 -07003871// This test ensures OnRenegotiationNeeded is called when we add track with
3872// MediaStream -> AddTrack in the same way it is called when we add track with
3873// PeerConnection -> AddTrack.
3874// The test can be removed once addStream is rewritten in terms of addTrack
3875// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003876// Don't run under Unified Plan since the stream API is not available.
3877TEST_F(PeerConnectionInterfaceTestPlanB,
3878 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003879 CreatePeerConnectionWithoutDtls();
3880 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003881 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003882 pc_->AddStream(stream);
3883 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003884 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003885 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003886 CreateVideoTrack("video_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003887 stream->AddTrack(audio_track);
3888 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3889 observer_.renegotiation_needed_ = false;
3890
3891 stream->AddTrack(video_track);
3892 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3893 observer_.renegotiation_needed_ = false;
3894
3895 stream->RemoveTrack(audio_track);
3896 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3897 observer_.renegotiation_needed_ = false;
3898
3899 stream->RemoveTrack(video_track);
3900 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3901 observer_.renegotiation_needed_ = false;
3902}
3903
Zhi Huangb2d355e2017-10-26 17:26:37 -07003904// Tests that an error is returned if a description is applied that has fewer
3905// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003906TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003907 MediaSectionCountEnforcedForSubsequentOffer) {
3908 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003909 AddAudioTrack("audio_label");
3910 AddVideoTrack("video_label");
3911
Zhi Huangb2d355e2017-10-26 17:26:37 -07003912 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003913 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003914 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3915
3916 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003917 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003918 offer->description()->contents().pop_back();
3919 offer->description()->contents().pop_back();
3920 ASSERT_TRUE(offer->description()->contents().empty());
3921 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3922
3923 std::unique_ptr<SessionDescriptionInterface> answer;
3924 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3925 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3926
3927 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003928 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003929 offer->description()->contents().pop_back();
3930 offer->description()->contents().pop_back();
3931 ASSERT_TRUE(offer->description()->contents().empty());
3932 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3933}
3934
Johannes Kron89f874e2018-11-12 10:25:48 +01003935TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3936 RTCConfiguration config;
3937 // Default behavior is false.
3938 CreatePeerConnection(config);
3939 std::unique_ptr<SessionDescriptionInterface> offer;
3940 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3941 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3942 // Possible to set to true.
3943 config.offer_extmap_allow_mixed = true;
3944 CreatePeerConnection(config);
3945 offer.release();
3946 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3947 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3948}
3949
Mirko Bonadeic84f6612019-01-31 12:20:57 +01003950INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3951 PeerConnectionInterfaceTest,
3952 Values(SdpSemantics::kPlanB,
3953 SdpSemantics::kUnifiedPlan));
Steve Anton36da6ff2018-02-16 16:04:20 -08003954
nisse51542be2016-02-12 02:27:06 -08003955class PeerConnectionMediaConfigTest : public testing::Test {
3956 protected:
3957 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003958 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003959 pcf_->Initialize();
3960 }
nisseeaabdf62017-05-05 02:23:02 -07003961 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003962 const RTCConfiguration& config) {
3963 rtc::scoped_refptr<PeerConnectionInterface> pc(
3964 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003965 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003966 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003967 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003968 }
3969
zhihuang9763d562016-08-05 11:14:50 -07003970 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003971 MockPeerConnectionObserver observer_;
3972};
3973
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003974// This sanity check validates the test infrastructure itself.
3975TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3976 PeerConnectionInterface::RTCConfiguration config;
3977 rtc::scoped_refptr<PeerConnectionInterface> pc(
3978 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3979 EXPECT_TRUE(pc.get());
3980 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3981 pc->Close(); // No abort -> ok.
3982 SUCCEED();
3983}
3984
nisse51542be2016-02-12 02:27:06 -08003985// This test verifies the default behaviour with no constraints and a
3986// default RTCConfiguration.
3987TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3988 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003989
Niels Möllerf06f9232018-08-07 12:32:18 +02003990 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003991
3992 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003993 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3994 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003995 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003996 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003997}
3998
Niels Möller1d7ecd22018-01-18 15:25:12 +01003999// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004000// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004001TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4002 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004003
Niels Möller71bdda02016-03-31 12:59:59 +02004004 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02004005 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004006
Niels Möller1d7ecd22018-01-18 15:25:12 +01004007 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004008}
4009
Niels Möller6539f692018-01-18 08:58:50 +01004010// This test verifies that the experiment_cpu_load_estimator flag is
4011// propagated from RTCConfiguration to the PeerConnection.
4012TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4013 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004014
4015 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004016 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004017
4018 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4019}
4020
deadbeef293e9262017-01-11 12:28:30 -08004021// Tests a few random fields being different.
4022TEST(RTCConfigurationTest, ComparisonOperators) {
4023 PeerConnectionInterface::RTCConfiguration a;
4024 PeerConnectionInterface::RTCConfiguration b;
4025 EXPECT_EQ(a, b);
4026
4027 PeerConnectionInterface::RTCConfiguration c;
4028 c.servers.push_back(PeerConnectionInterface::IceServer());
4029 EXPECT_NE(a, c);
4030
4031 PeerConnectionInterface::RTCConfiguration d;
4032 d.type = PeerConnectionInterface::kRelay;
4033 EXPECT_NE(a, d);
4034
4035 PeerConnectionInterface::RTCConfiguration e;
4036 e.audio_jitter_buffer_max_packets = 5;
4037 EXPECT_NE(a, e);
4038
4039 PeerConnectionInterface::RTCConfiguration f;
4040 f.ice_connection_receiving_timeout = 1337;
4041 EXPECT_NE(a, f);
4042
4043 PeerConnectionInterface::RTCConfiguration g;
4044 g.disable_ipv6 = true;
4045 EXPECT_NE(a, g);
4046
4047 PeerConnectionInterface::RTCConfiguration h(
4048 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4049 EXPECT_NE(a, h);
4050}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01004051
4052} // namespace
4053} // namespace webrtc