blob: 038e42c9b36df66c824d5b74b5dbe801559808fa [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"
52#include "media/base/video_capturer.h"
53#include "media/engine/webrtc_media_engine.h"
54#include "media/sctp/sctp_transport_internal.h"
Yves Gerey3e707812018-11-28 16:47:49 +010055#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020056#include "modules/audio_processing/include/audio_processing.h"
Steve Anton10542f22019-01-11 09:11:00 -080057#include "p2p/base/fake_port_allocator.h"
58#include "p2p/base/p2p_constants.h"
Yves Gerey3e707812018-11-28 16:47:49 +010059#include "p2p/base/port.h"
Steve Anton10542f22019-01-11 09:11:00 -080060#include "p2p/base/port_allocator.h"
61#include "p2p/base/transport_description.h"
62#include "p2p/base/transport_info.h"
63#include "pc/audio_track.h"
64#include "pc/media_session.h"
65#include "pc/media_stream.h"
66#include "pc/peer_connection.h"
67#include "pc/peer_connection_factory.h"
68#include "pc/rtc_stats_collector.h"
69#include "pc/rtp_sender.h"
70#include "pc/session_description.h"
71#include "pc/stream_collection.h"
72#include "pc/test/fake_audio_capture_module.h"
73#include "pc/test/fake_rtc_certificate_generator.h"
74#include "pc/test/fake_video_track_source.h"
75#include "pc/test/mock_peer_connection_observers.h"
76#include "pc/test/test_sdp_strings.h"
77#include "pc/video_track.h"
Yves Gerey3e707812018-11-28 16:47:49 +010078#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080079#include "rtc_base/copy_on_write_buffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020080#include "rtc_base/gunit.h"
Yves Gerey3e707812018-11-28 16:47:49 +010081#include "rtc_base/platform_file.h"
Steve Anton10542f22019-01-11 09:11:00 -080082#include "rtc_base/ref_counted_object.h"
83#include "rtc_base/rtc_certificate_generator.h"
Steve Anton10542f22019-01-11 09:11:00 -080084#include "rtc_base/socket_address.h"
85#include "rtc_base/string_utils.h"
Yves Gerey3e707812018-11-28 16:47:49 +010086#include "rtc_base/thread.h"
Steve Anton10542f22019-01-11 09:11:00 -080087#include "rtc_base/time_utils.h"
88#include "rtc_base/virtual_socket_server.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020089#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010090#include "test/gtest.h"
Steve Anton10542f22019-01-11 09:11:00 -080091#include "test/testsupport/file_utils.h"
kwibergac9f8762016-09-30 22:29:43 -070092
93#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080094#include "pc/test/android_test_initializer.h"
kwibergac9f8762016-09-30 22:29:43 -070095#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +010097namespace webrtc {
98namespace {
99
Seth Hampson845e8782018-03-02 11:34:10 -0800100static const char kStreamId1[] = "local_stream_1";
101static const char kStreamId2[] = "local_stream_2";
102static const char kStreamId3[] = "local_stream_3";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103static const int kDefaultStunPort = 3478;
104static const char kStunAddressOnly[] = "stun:address";
105static const char kStunInvalidPort[] = "stun:address:-1";
106static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
107static const char kStunAddressPortAndMore2[] = "stun:address:port more";
108static const char kTurnIceServerUri[] = "turn:user@turn.example.org";
109static const char kTurnUsername[] = "user";
110static const char kTurnPassword[] = "password";
111static const char kTurnHostname[] = "turn.example.org";
Peter Boström0c4e06b2015-10-07 12:23:21 +0200112static const uint32_t kTimeout = 10000U;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113
deadbeefab9b2d12015-10-14 11:33:11 -0700114static const char kStreams[][8] = {"stream1", "stream2"};
115static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
116static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
117
deadbeef5e97fb52015-10-15 12:49:08 -0700118static const char kRecvonly[] = "recvonly";
119static const char kSendrecv[] = "sendrecv";
120
deadbeefab9b2d12015-10-14 11:33:11 -0700121// Reference SDP with a MediaStream with label "stream1" and audio track with
122// id "audio_1" and a video track with id "video_1;
Steve Anton36da6ff2018-02-16 16:04:20 -0800123static const char kSdpStringWithStream1PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700124 "v=0\r\n"
125 "o=- 0 0 IN IP4 127.0.0.1\r\n"
126 "s=-\r\n"
127 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800128 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700129 "a=ice-ufrag:e5785931\r\n"
130 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
131 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
132 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700133 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700134 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800135 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700136 "a=rtpmap:103 ISAC/16000\r\n"
137 "a=ssrc:1 cname:stream1\r\n"
138 "a=ssrc:1 mslabel:stream1\r\n"
139 "a=ssrc:1 label:audiotrack0\r\n"
140 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800141 "a=ice-ufrag:e5785931\r\n"
142 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
143 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
144 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700145 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700146 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800147 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700148 "a=rtpmap:120 VP8/90000\r\n"
149 "a=ssrc:2 cname:stream1\r\n"
150 "a=ssrc:2 mslabel:stream1\r\n"
151 "a=ssrc:2 label:videotrack0\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800152// Same string as above but with the MID changed to the Unified Plan default.
153// This is needed so that this SDP can be used as an answer for a Unified Plan
154// offer.
155static const char kSdpStringWithStream1UnifiedPlan[] =
156 "v=0\r\n"
157 "o=- 0 0 IN IP4 127.0.0.1\r\n"
158 "s=-\r\n"
159 "t=0 0\r\n"
160 "m=audio 1 RTP/AVPF 103\r\n"
161 "a=ice-ufrag:e5785931\r\n"
162 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
163 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
164 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
165 "a=mid:0\r\n"
166 "a=sendrecv\r\n"
167 "a=rtcp-mux\r\n"
168 "a=rtpmap:103 ISAC/16000\r\n"
169 "a=ssrc:1 cname:stream1\r\n"
170 "a=ssrc:1 mslabel:stream1\r\n"
171 "a=ssrc:1 label:audiotrack0\r\n"
172 "m=video 1 RTP/AVPF 120\r\n"
173 "a=ice-ufrag:e5785931\r\n"
174 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
175 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
176 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
177 "a=mid:1\r\n"
178 "a=sendrecv\r\n"
179 "a=rtcp-mux\r\n"
180 "a=rtpmap:120 VP8/90000\r\n"
181 "a=ssrc:2 cname:stream1\r\n"
182 "a=ssrc:2 mslabel:stream1\r\n"
183 "a=ssrc:2 label:videotrack0\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700184
zhihuang81c3a032016-11-17 12:06:24 -0800185// Reference SDP with a MediaStream with label "stream1" and audio track with
186// id "audio_1";
187static const char kSdpStringWithStream1AudioTrackOnly[] =
188 "v=0\r\n"
189 "o=- 0 0 IN IP4 127.0.0.1\r\n"
190 "s=-\r\n"
191 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800192 "m=audio 1 RTP/AVPF 103\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800193 "a=ice-ufrag:e5785931\r\n"
194 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
195 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
196 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
zhihuang81c3a032016-11-17 12:06:24 -0800197 "a=mid:audio\r\n"
198 "a=sendrecv\r\n"
199 "a=rtpmap:103 ISAC/16000\r\n"
200 "a=ssrc:1 cname:stream1\r\n"
201 "a=ssrc:1 mslabel:stream1\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800202 "a=ssrc:1 label:audiotrack0\r\n"
203 "a=rtcp-mux\r\n";
zhihuang81c3a032016-11-17 12:06:24 -0800204
deadbeefab9b2d12015-10-14 11:33:11 -0700205// Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
206// MediaStreams have one audio track and one video track.
207// This uses MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -0800208static const char kSdpStringWithStream1And2PlanB[] =
deadbeefab9b2d12015-10-14 11:33:11 -0700209 "v=0\r\n"
210 "o=- 0 0 IN IP4 127.0.0.1\r\n"
211 "s=-\r\n"
212 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800213 "a=msid-semantic: WMS stream1 stream2\r\n"
214 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700215 "a=ice-ufrag:e5785931\r\n"
216 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
217 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
218 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700219 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700220 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800221 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700222 "a=rtpmap:103 ISAC/16000\r\n"
223 "a=ssrc:1 cname:stream1\r\n"
224 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
225 "a=ssrc:3 cname:stream2\r\n"
226 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
227 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800228 "a=ice-ufrag:e5785931\r\n"
229 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
230 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
231 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700232 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700233 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800234 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700235 "a=rtpmap:120 VP8/0\r\n"
236 "a=ssrc:2 cname:stream1\r\n"
237 "a=ssrc:2 msid:stream1 videotrack0\r\n"
238 "a=ssrc:4 cname:stream2\r\n"
239 "a=ssrc:4 msid:stream2 videotrack1\r\n";
Steve Anton36da6ff2018-02-16 16:04:20 -0800240static const char kSdpStringWithStream1And2UnifiedPlan[] =
241 "v=0\r\n"
242 "o=- 0 0 IN IP4 127.0.0.1\r\n"
243 "s=-\r\n"
244 "t=0 0\r\n"
245 "a=msid-semantic: WMS stream1 stream2\r\n"
246 "m=audio 1 RTP/AVPF 103\r\n"
247 "a=ice-ufrag:e5785931\r\n"
248 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
249 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
250 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
251 "a=mid:0\r\n"
252 "a=sendrecv\r\n"
253 "a=rtcp-mux\r\n"
254 "a=rtpmap:103 ISAC/16000\r\n"
255 "a=ssrc:1 cname:stream1\r\n"
256 "a=ssrc:1 msid:stream1 audiotrack0\r\n"
257 "m=video 1 RTP/AVPF 120\r\n"
258 "a=ice-ufrag:e5785931\r\n"
259 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
260 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
261 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
262 "a=mid:1\r\n"
263 "a=sendrecv\r\n"
264 "a=rtcp-mux\r\n"
265 "a=rtpmap:120 VP8/0\r\n"
266 "a=ssrc:2 cname:stream1\r\n"
267 "a=ssrc:2 msid:stream1 videotrack0\r\n"
268 "m=audio 1 RTP/AVPF 103\r\n"
269 "a=ice-ufrag:e5785931\r\n"
270 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
271 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
272 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
273 "a=mid:2\r\n"
274 "a=sendrecv\r\n"
275 "a=rtcp-mux\r\n"
276 "a=rtpmap:103 ISAC/16000\r\n"
277 "a=ssrc:3 cname:stream2\r\n"
278 "a=ssrc:3 msid:stream2 audiotrack1\r\n"
279 "m=video 1 RTP/AVPF 120\r\n"
280 "a=ice-ufrag:e5785931\r\n"
281 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
282 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
283 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
284 "a=mid:3\r\n"
285 "a=sendrecv\r\n"
286 "a=rtcp-mux\r\n"
287 "a=rtpmap:120 VP8/0\r\n"
288 "a=ssrc:4 cname:stream2\r\n"
289 "a=ssrc:4 msid:stream2 videotrack1\r\n";
deadbeefab9b2d12015-10-14 11:33:11 -0700290
291// Reference SDP without MediaStreams. Msid is not supported.
292static const char kSdpStringWithoutStreams[] =
293 "v=0\r\n"
294 "o=- 0 0 IN IP4 127.0.0.1\r\n"
295 "s=-\r\n"
296 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800297 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700298 "a=ice-ufrag:e5785931\r\n"
299 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
300 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
301 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700302 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700303 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800304 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700305 "a=rtpmap:103 ISAC/16000\r\n"
306 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800307 "a=ice-ufrag:e5785931\r\n"
308 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
309 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
310 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700311 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700312 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800313 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700314 "a=rtpmap:120 VP8/90000\r\n";
315
316// Reference SDP without MediaStreams. Msid is supported.
317static const char kSdpStringWithMsidWithoutStreams[] =
318 "v=0\r\n"
319 "o=- 0 0 IN IP4 127.0.0.1\r\n"
320 "s=-\r\n"
321 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800322 "a=msid-semantic: WMS\r\n"
323 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700324 "a=ice-ufrag:e5785931\r\n"
325 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
326 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
327 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700328 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700329 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800330 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700331 "a=rtpmap:103 ISAC/16000\r\n"
332 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800333 "a=ice-ufrag:e5785931\r\n"
334 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
335 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
336 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700337 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700338 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800339 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700340 "a=rtpmap:120 VP8/90000\r\n";
341
342// Reference SDP without MediaStreams and audio only.
343static const char kSdpStringWithoutStreamsAudioOnly[] =
344 "v=0\r\n"
345 "o=- 0 0 IN IP4 127.0.0.1\r\n"
346 "s=-\r\n"
347 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800348 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700349 "a=ice-ufrag:e5785931\r\n"
350 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
351 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
352 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700353 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700354 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800355 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700356 "a=rtpmap:103 ISAC/16000\r\n";
357
358// Reference SENDONLY SDP without MediaStreams. Msid is not supported.
359static const char kSdpStringSendOnlyWithoutStreams[] =
360 "v=0\r\n"
361 "o=- 0 0 IN IP4 127.0.0.1\r\n"
362 "s=-\r\n"
363 "t=0 0\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800364 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700365 "a=ice-ufrag:e5785931\r\n"
366 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
367 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
368 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700369 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700370 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700371 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800372 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700373 "a=rtpmap:103 ISAC/16000\r\n"
374 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800375 "a=ice-ufrag:e5785931\r\n"
376 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
377 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
378 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700379 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700380 "a=sendrecv\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700381 "a=sendonly\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800382 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700383 "a=rtpmap:120 VP8/90000\r\n";
384
385static const char kSdpStringInit[] =
386 "v=0\r\n"
387 "o=- 0 0 IN IP4 127.0.0.1\r\n"
388 "s=-\r\n"
389 "t=0 0\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700390 "a=msid-semantic: WMS\r\n";
391
392static const char kSdpStringAudio[] =
393 "m=audio 1 RTP/AVPF 103\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800394 "a=ice-ufrag:e5785931\r\n"
395 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
396 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
397 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700398 "a=mid:audio\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700399 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800400 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700401 "a=rtpmap:103 ISAC/16000\r\n";
402
403static const char kSdpStringVideo[] =
404 "m=video 1 RTP/AVPF 120\r\n"
deadbeefd1a38b52016-12-10 13:15:33 -0800405 "a=ice-ufrag:e5785931\r\n"
406 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
407 "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
408 "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700409 "a=mid:video\r\n"
deadbeef5e97fb52015-10-15 12:49:08 -0700410 "a=sendrecv\r\n"
zhihuang4dfb8ce2016-11-23 10:30:12 -0800411 "a=rtcp-mux\r\n"
deadbeefab9b2d12015-10-14 11:33:11 -0700412 "a=rtpmap:120 VP8/90000\r\n";
413
414static const char kSdpStringMs1Audio0[] =
415 "a=ssrc:1 cname:stream1\r\n"
416 "a=ssrc:1 msid:stream1 audiotrack0\r\n";
417
418static const char kSdpStringMs1Video0[] =
419 "a=ssrc:2 cname:stream1\r\n"
420 "a=ssrc:2 msid:stream1 videotrack0\r\n";
421
422static const char kSdpStringMs1Audio1[] =
423 "a=ssrc:3 cname:stream1\r\n"
424 "a=ssrc:3 msid:stream1 audiotrack1\r\n";
425
426static const char kSdpStringMs1Video1[] =
427 "a=ssrc:4 cname:stream1\r\n"
428 "a=ssrc:4 msid:stream1 videotrack1\r\n";
429
deadbeef8662f942017-01-20 21:20:51 -0800430static const char kDtlsSdesFallbackSdp[] =
431 "v=0\r\n"
432 "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
433 "s=-\r\n"
434 "c=IN IP4 0.0.0.0\r\n"
435 "t=0 0\r\n"
436 "a=group:BUNDLE audio\r\n"
437 "a=msid-semantic: WMS\r\n"
438 "m=audio 1 RTP/SAVPF 0\r\n"
439 "a=sendrecv\r\n"
440 "a=rtcp-mux\r\n"
441 "a=mid:audio\r\n"
442 "a=ssrc:1 cname:stream1\r\n"
443 "a=ssrc:1 mslabel:stream1\r\n"
444 "a=ssrc:1 label:audiotrack0\r\n"
445 "a=ice-ufrag:e5785931\r\n"
446 "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
447 "a=rtpmap:0 pcmu/8000\r\n"
448 "a=fingerprint:sha-1 "
449 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
450 "a=setup:actpass\r\n"
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700451 "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
deadbeef8662f942017-01-20 21:20:51 -0800452 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
453 "dummy_session_params\r\n";
454
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +0100455using ::cricket::StreamParams;
perkjd61bf802016-03-24 03:16:19 -0700456using ::testing::Exactly;
Steve Anton36da6ff2018-02-16 16:04:20 -0800457using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458
Steve Anton36da6ff2018-02-16 16:04:20 -0800459using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
460using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
deadbeefab9b2d12015-10-14 11:33:11 -0700461
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462// Gets the first ssrc of given content type from the ContentInfo.
463bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
464 if (!content_info || !ssrc) {
465 return false;
466 }
467 const cricket::MediaContentDescription* media_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -0800468 content_info->media_description();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 if (!media_desc || media_desc->streams().empty()) {
470 return false;
471 }
472 *ssrc = media_desc->streams().begin()->first_ssrc();
473 return true;
474}
475
deadbeefd1a38b52016-12-10 13:15:33 -0800476// Get the ufrags out of an SDP blob. Useful for testing ICE restart
477// behavior.
478std::vector<std::string> GetUfrags(
479 const webrtc::SessionDescriptionInterface* desc) {
480 std::vector<std::string> ufrags;
481 for (const cricket::TransportInfo& info :
482 desc->description()->transport_infos()) {
483 ufrags.push_back(info.description.ice_ufrag);
484 }
485 return ufrags;
486}
487
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488void SetSsrcToZero(std::string* sdp) {
489 const char kSdpSsrcAtribute[] = "a=ssrc:";
490 const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
491 size_t ssrc_pos = 0;
492 while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
Yves Gerey665174f2018-06-19 15:03:05 +0200493 std::string::npos) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 size_t end_ssrc = sdp->find(" ", ssrc_pos);
495 sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
496 ssrc_pos = end_ssrc;
497 }
498}
499
deadbeefab9b2d12015-10-14 11:33:11 -0700500// Check if |streams| contains the specified track.
501bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
Seth Hampson845e8782018-03-02 11:34:10 -0800502 const std::string& stream_id,
deadbeefab9b2d12015-10-14 11:33:11 -0700503 const std::string& track_id) {
504 for (const cricket::StreamParams& params : streams) {
Seth Hampson845e8782018-03-02 11:34:10 -0800505 if (params.first_stream_id() == stream_id && params.id == track_id) {
deadbeefab9b2d12015-10-14 11:33:11 -0700506 return true;
507 }
508 }
509 return false;
510}
511
512// Check if |senders| contains the specified sender, by id.
513bool ContainsSender(
514 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
515 const std::string& id) {
516 for (const auto& sender : senders) {
517 if (sender->id() == id) {
518 return true;
519 }
520 }
521 return false;
522}
523
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700524// Check if |senders| contains the specified sender, by id and stream id.
525bool ContainsSender(
526 const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
527 const std::string& id,
528 const std::string& stream_id) {
529 for (const auto& sender : senders) {
deadbeefa601f5c2016-06-06 14:27:39 -0700530 if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700531 return true;
532 }
533 }
534 return false;
535}
536
deadbeefab9b2d12015-10-14 11:33:11 -0700537// Create a collection of streams.
538// CreateStreamCollection(1) creates a collection that
539// correspond to kSdpStringWithStream1.
540// CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
541rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700542 int number_of_streams,
543 int tracks_per_stream) {
deadbeefab9b2d12015-10-14 11:33:11 -0700544 rtc::scoped_refptr<StreamCollection> local_collection(
545 StreamCollection::Create());
546
547 for (int i = 0; i < number_of_streams; ++i) {
548 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
549 webrtc::MediaStream::Create(kStreams[i]));
550
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700551 for (int j = 0; j < tracks_per_stream; ++j) {
552 // Add a local audio track.
553 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
554 webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
555 nullptr));
556 stream->AddTrack(audio_track);
deadbeefab9b2d12015-10-14 11:33:11 -0700557
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700558 // Add a local video track.
559 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
560 webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
perkj773be362017-07-31 23:22:01 -0700561 webrtc::FakeVideoTrackSource::Create(),
562 rtc::Thread::Current()));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -0700563 stream->AddTrack(video_track);
564 }
deadbeefab9b2d12015-10-14 11:33:11 -0700565
566 local_collection->AddStream(stream);
567 }
568 return local_collection;
569}
570
571// Check equality of StreamCollections.
572bool CompareStreamCollections(StreamCollectionInterface* s1,
573 StreamCollectionInterface* s2) {
574 if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
575 return false;
576 }
577
578 for (size_t i = 0; i != s1->count(); ++i) {
Seth Hampson13b8bad2018-03-13 16:05:28 -0700579 if (s1->at(i)->id() != s2->at(i)->id()) {
deadbeefab9b2d12015-10-14 11:33:11 -0700580 return false;
581 }
582 webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
583 webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
584 webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
585 webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
586
587 if (audio_tracks1.size() != audio_tracks2.size()) {
588 return false;
589 }
590 for (size_t j = 0; j != audio_tracks1.size(); ++j) {
591 if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
592 return false;
593 }
594 }
595 if (video_tracks1.size() != video_tracks2.size()) {
596 return false;
597 }
598 for (size_t j = 0; j != video_tracks1.size(); ++j) {
599 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
600 return false;
601 }
602 }
603 }
604 return true;
605}
606
perkjd61bf802016-03-24 03:16:19 -0700607// Helper class to test Observer.
608class MockTrackObserver : public ObserverInterface {
609 public:
610 explicit MockTrackObserver(NotifierInterface* notifier)
611 : notifier_(notifier) {
612 notifier_->RegisterObserver(this);
613 }
614
615 ~MockTrackObserver() { Unregister(); }
616
617 void Unregister() {
618 if (notifier_) {
619 notifier_->UnregisterObserver(this);
620 notifier_ = nullptr;
621 }
622 }
623
624 MOCK_METHOD0(OnChanged, void());
625
626 private:
627 NotifierInterface* notifier_;
628};
629
nisse528b7932017-05-08 03:21:43 -0700630// The PeerConnectionMediaConfig tests below verify that configuration and
631// constraints are propagated into the PeerConnection's MediaConfig. These
632// settings are intended for MediaChannel constructors, but that is not
633// exercised by these unittest.
zhihuang29ff8442016-07-27 11:07:25 -0700634class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
635 public:
zhihuang38ede132017-06-15 12:52:32 -0700636 static rtc::scoped_refptr<PeerConnectionFactoryForTest>
637 CreatePeerConnectionFactoryForTest() {
638 auto audio_encoder_factory = webrtc::CreateBuiltinAudioEncoderFactory();
639 auto audio_decoder_factory = webrtc::CreateBuiltinAudioDecoderFactory();
Anders Carlssonb3306882018-05-14 10:11:42 +0200640 auto video_encoder_factory = webrtc::CreateBuiltinVideoEncoderFactory();
641 auto video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
zhihuang38ede132017-06-15 12:52:32 -0700642
henrika919dc2e2017-10-12 14:24:55 +0200643 // Use fake audio device module since we're only testing the interface
644 // level, and using a real one could make tests flaky when run in parallel.
zhihuang38ede132017-06-15 12:52:32 -0700645 auto media_engine = std::unique_ptr<cricket::MediaEngineInterface>(
646 cricket::WebRtcMediaEngineFactory::Create(
henrika919dc2e2017-10-12 14:24:55 +0200647 FakeAudioCaptureModule::Create(), audio_encoder_factory,
Anders Carlssonb3306882018-05-14 10:11:42 +0200648 audio_decoder_factory, std::move(video_encoder_factory),
Qingsi Wang59844ce2018-11-01 04:45:53 +0000649 std::move(video_decoder_factory), nullptr,
Ivo Creusen62337e52018-01-09 14:17:33 +0100650 webrtc::AudioProcessingBuilder().Create()));
zhihuang38ede132017-06-15 12:52:32 -0700651
652 std::unique_ptr<webrtc::CallFactoryInterface> call_factory =
653 webrtc::CreateCallFactory();
654
655 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory =
656 webrtc::CreateRtcEventLogFactory();
657
658 return new rtc::RefCountedObject<PeerConnectionFactoryForTest>(
659 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200660 std::move(media_engine), std::move(call_factory),
zhihuang38ede132017-06-15 12:52:32 -0700661 std::move(event_log_factory));
662 }
663
664 PeerConnectionFactoryForTest(
665 rtc::Thread* network_thread,
666 rtc::Thread* worker_thread,
667 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700668 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
669 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
670 std::unique_ptr<webrtc::RtcEventLogFactoryInterface> event_log_factory)
671 : webrtc::PeerConnectionFactory(network_thread,
672 worker_thread,
673 signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700674 std::move(media_engine),
675 std::move(call_factory),
676 std::move(event_log_factory)) {}
kwiberg1e4e8cb2017-01-31 01:48:08 -0800677
deadbeefd7850b22017-08-23 10:59:19 -0700678 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
zhihuang29ff8442016-07-27 11:07:25 -0700679};
680
Steve Anton36da6ff2018-02-16 16:04:20 -0800681// TODO(steveanton): Convert to use the new PeerConnectionWrapper.
682class PeerConnectionInterfaceBaseTest : public testing::Test {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 protected:
Steve Anton36da6ff2018-02-16 16:04:20 -0800684 explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
685 : vss_(new rtc::VirtualSocketServer()),
686 main_(vss_.get()),
687 sdp_semantics_(sdp_semantics) {
phoglund37ebcf02016-01-08 05:04:57 -0800688#ifdef WEBRTC_ANDROID
689 webrtc::InitializeAndroidObjects();
690#endif
691 }
692
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 virtual void SetUp() {
deadbeefd7850b22017-08-23 10:59:19 -0700694 // Use fake audio capture module since we're only testing the interface
695 // level, and using a real one could make tests flaky when run in parallel.
696 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 pc_factory_ = webrtc::CreatePeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700698 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
Anders Carlsson67537952018-05-03 11:28:29 +0200699 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
700 fake_audio_capture_module_),
701 webrtc::CreateBuiltinAudioEncoderFactory(),
702 webrtc::CreateBuiltinAudioDecoderFactory(),
703 webrtc::CreateBuiltinVideoEncoderFactory(),
704 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
705 nullptr /* audio_processing */);
danilchape9021a32016-05-17 01:52:02 -0700706 ASSERT_TRUE(pc_factory_);
zhihuang29ff8442016-07-27 11:07:25 -0700707 pc_factory_for_test_ =
zhihuang38ede132017-06-15 12:52:32 -0700708 PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
zhihuang29ff8442016-07-27 11:07:25 -0700709 pc_factory_for_test_->Initialize();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 }
711
712 void CreatePeerConnection() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200713 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 }
715
deadbeef293e9262017-01-11 12:28:30 -0800716 // DTLS does not work in a loopback call, so is disabled for most of the
717 // tests in this file.
718 void CreatePeerConnectionWithoutDtls() {
Niels Möllerf06f9232018-08-07 12:32:18 +0200719 RTCConfiguration config;
720 config.enable_dtls_srtp = false;
deadbeef293e9262017-01-11 12:28:30 -0800721
Niels Möllerf06f9232018-08-07 12:32:18 +0200722 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 }
724
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700725 void CreatePeerConnectionWithIceTransportsType(
726 PeerConnectionInterface::IceTransportsType type) {
727 PeerConnectionInterface::RTCConfiguration config;
728 config.type = type;
Niels Möllerf06f9232018-08-07 12:32:18 +0200729 return CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700730 }
731
732 void CreatePeerConnectionWithIceServer(const std::string& uri,
733 const std::string& password) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800734 PeerConnectionInterface::RTCConfiguration config;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 PeerConnectionInterface::IceServer server;
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700736 server.uri = uri;
737 server.password = password;
738 config.servers.push_back(server);
Niels Möllerf06f9232018-08-07 12:32:18 +0200739 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700740 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741
Niels Möllerf06f9232018-08-07 12:32:18 +0200742 void CreatePeerConnection(const RTCConfiguration& config) {
kwibergd1fe2812016-04-27 06:47:29 -0700743 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800744 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
745 port_allocator_ = port_allocator.get();
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000746
deadbeef1dcb1642017-03-29 21:08:16 -0700747 // Create certificate generator unless DTLS constraint is explicitly set to
748 // false.
Henrik Boströmd79599d2016-06-01 13:58:50 +0200749 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
Niels Möllerf06f9232018-08-07 12:32:18 +0200750
751 if (config.enable_dtls_srtp.value_or(true)) {
deadbeef8662f942017-01-20 21:20:51 -0800752 fake_certificate_generator_ = new FakeRTCCertificateGenerator();
753 cert_generator.reset(fake_certificate_generator_);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000754 }
Steve Anton36da6ff2018-02-16 16:04:20 -0800755 RTCConfiguration modified_config = config;
756 modified_config.sdp_semantics = sdp_semantics_;
Henrik Boströmd79599d2016-06-01 13:58:50 +0200757 pc_ = pc_factory_->CreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +0200758 modified_config, std::move(port_allocator), std::move(cert_generator),
759 &observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 ASSERT_TRUE(pc_.get() != NULL);
761 observer_.SetPeerConnectionInterface(pc_.get());
762 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
763 }
764
deadbeef0a6c4ca2015-10-06 11:38:28 -0700765 void CreatePeerConnectionExpectFail(const std::string& uri) {
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800766 PeerConnectionInterface::RTCConfiguration config;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700767 PeerConnectionInterface::IceServer server;
deadbeef0a6c4ca2015-10-06 11:38:28 -0700768 server.uri = uri;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800769 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800770 config.sdp_semantics = sdp_semantics_;
771 rtc::scoped_refptr<PeerConnectionInterface> pc =
Niels Möllerf06f9232018-08-07 12:32:18 +0200772 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800773 EXPECT_EQ(nullptr, pc);
deadbeef0a6c4ca2015-10-06 11:38:28 -0700774 }
775
Steve Anton038834f2017-07-14 15:59:59 -0700776 void CreatePeerConnectionExpectFail(
777 PeerConnectionInterface::RTCConfiguration config) {
778 PeerConnectionInterface::IceServer server;
779 server.uri = kTurnIceServerUri;
780 server.password = kTurnPassword;
781 config.servers.push_back(server);
Steve Anton36da6ff2018-02-16 16:04:20 -0800782 config.sdp_semantics = sdp_semantics_;
Steve Anton038834f2017-07-14 15:59:59 -0700783 rtc::scoped_refptr<PeerConnectionInterface> pc =
784 pc_factory_->CreatePeerConnection(config, nullptr, nullptr, &observer_);
785 EXPECT_EQ(nullptr, pc);
786 }
787
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 void CreatePeerConnectionWithDifferentConfigurations() {
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700789 CreatePeerConnectionWithIceServer(kStunAddressOnly, "");
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800790 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
791 EXPECT_EQ(0u, port_allocator_->turn_servers().size());
792 EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 EXPECT_EQ(kDefaultStunPort,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800794 port_allocator_->stun_servers().begin()->port());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795
deadbeef0a6c4ca2015-10-06 11:38:28 -0700796 CreatePeerConnectionExpectFail(kStunInvalidPort);
797 CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
798 CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799
Taylor Brandstettera1c30352016-05-13 08:15:11 -0700800 CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnPassword);
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800801 EXPECT_EQ(0u, port_allocator_->stun_servers().size());
802 EXPECT_EQ(1u, port_allocator_->turn_servers().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_EQ(kTurnUsername,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800804 port_allocator_->turn_servers()[0].credentials.username);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 EXPECT_EQ(kTurnPassword,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800806 port_allocator_->turn_servers()[0].credentials.password);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 EXPECT_EQ(kTurnHostname,
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -0800808 port_allocator_->turn_servers()[0].ports[0].address.hostname());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 }
810
811 void ReleasePeerConnection() {
812 pc_ = NULL;
813 observer_.SetPeerConnectionInterface(NULL);
814 }
815
Steve Anton36da6ff2018-02-16 16:04:20 -0800816 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
817 const std::string& label) {
Niels Möller215ba602019-01-18 13:59:45 +0100818 return pc_factory_->CreateVideoTrack(label, FakeVideoTrackSource::Create());
Steve Anton36da6ff2018-02-16 16:04:20 -0800819 }
820
821 void AddVideoTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800822 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800823 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800824 pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800825 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
827 observer_.renegotiation_needed_ = false;
828 }
829
Steve Anton36da6ff2018-02-16 16:04:20 -0800830 void AddVideoStream(const std::string& label) {
zhihuang9763d562016-08-05 11:14:50 -0700831 rtc::scoped_refptr<MediaStreamInterface> stream(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 pc_factory_->CreateLocalMediaStream(label));
Steve Anton36da6ff2018-02-16 16:04:20 -0800833 stream->AddTrack(CreateVideoTrack(label + "v0"));
834 ASSERT_TRUE(pc_->AddStream(stream));
835 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
836 observer_.renegotiation_needed_ = false;
837 }
838
839 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
840 const std::string& label) {
841 return pc_factory_->CreateAudioTrack(label, nullptr);
842 }
843
844 void AddAudioTrack(const std::string& track_label,
Seth Hampson845e8782018-03-02 11:34:10 -0800845 const std::vector<std::string>& stream_ids = {}) {
Steve Anton36da6ff2018-02-16 16:04:20 -0800846 auto sender_or_error =
Seth Hampson845e8782018-03-02 11:34:10 -0800847 pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
Steve Anton36da6ff2018-02-16 16:04:20 -0800848 ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
849 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
850 observer_.renegotiation_needed_ = false;
851 }
852
853 void AddAudioStream(const std::string& label) {
854 rtc::scoped_refptr<MediaStreamInterface> stream(
855 pc_factory_->CreateLocalMediaStream(label));
856 stream->AddTrack(CreateAudioTrack(label + "a0"));
857 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
859 observer_.renegotiation_needed_ = false;
860 }
861
Seth Hampson845e8782018-03-02 11:34:10 -0800862 void AddAudioVideoStream(const std::string& stream_id,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 const std::string& audio_track_label,
864 const std::string& video_track_label) {
865 // Create a local stream.
zhihuang9763d562016-08-05 11:14:50 -0700866 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -0800867 pc_factory_->CreateLocalMediaStream(stream_id));
Steve Anton36da6ff2018-02-16 16:04:20 -0800868 stream->AddTrack(CreateAudioTrack(audio_track_label));
869 stream->AddTrack(CreateVideoTrack(video_track_label));
870 ASSERT_TRUE(pc_->AddStream(stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
872 observer_.renegotiation_needed_ = false;
873 }
874
Steve Anton36da6ff2018-02-16 16:04:20 -0800875 rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
876 cricket::MediaType media_type) {
877 for (auto receiver : pc_->GetReceivers()) {
878 if (receiver->media_type() == media_type) {
879 return receiver;
880 }
881 }
882 return nullptr;
883 }
884
kwibergd1fe2812016-04-27 06:47:29 -0700885 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200886 const RTCOfferAnswerOptions* options,
887 bool offer) {
Yves Gerey665174f2018-06-19 15:03:05 +0200888 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
889 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 if (offer) {
Niels Möllerf06f9232018-08-07 12:32:18 +0200891 pc_->CreateOffer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 } else {
Niels Möllerf06f9232018-08-07 12:32:18 +0200893 pc_->CreateAnswer(observer, options ? *options : RTCOfferAnswerOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 }
895 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -0700896 *desc = observer->MoveDescription();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 return observer->result();
898 }
899
kwibergd1fe2812016-04-27 06:47:29 -0700900 bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200901 const RTCOfferAnswerOptions* options) {
902 return DoCreateOfferAnswer(desc, options, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 }
904
kwibergd1fe2812016-04-27 06:47:29 -0700905 bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
Niels Möllerf06f9232018-08-07 12:32:18 +0200906 const RTCOfferAnswerOptions* options) {
907 return DoCreateOfferAnswer(desc, options, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 }
909
Steve Antondb45ca82017-09-11 18:27:34 -0700910 bool DoSetSessionDescription(
911 std::unique_ptr<SessionDescriptionInterface> desc,
912 bool local) {
Yves Gerey665174f2018-06-19 15:03:05 +0200913 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
914 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 if (local) {
Steve Antondb45ca82017-09-11 18:27:34 -0700916 pc_->SetLocalDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 } else {
Steve Antondb45ca82017-09-11 18:27:34 -0700918 pc_->SetRemoteDescription(observer, desc.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 }
zhihuang29ff8442016-07-27 11:07:25 -0700920 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
921 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
922 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 return observer->result();
924 }
925
Steve Antondb45ca82017-09-11 18:27:34 -0700926 bool DoSetLocalDescription(
927 std::unique_ptr<SessionDescriptionInterface> desc) {
928 return DoSetSessionDescription(std::move(desc), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 }
930
Steve Antondb45ca82017-09-11 18:27:34 -0700931 bool DoSetRemoteDescription(
932 std::unique_ptr<SessionDescriptionInterface> desc) {
933 return DoSetSessionDescription(std::move(desc), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 }
935
936 // Calls PeerConnection::GetStats and check the return value.
937 // It does not verify the values in the StatReports since a RTCP packet might
938 // be required.
939 bool DoGetStats(MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 rtc::scoped_refptr<MockStatsObserver> observer(
941 new rtc::RefCountedObject<MockStatsObserver>());
Yves Gerey665174f2018-06-19 15:03:05 +0200942 if (!pc_->GetStats(observer, track,
943 PeerConnectionInterface::kStatsOutputLevelStandard))
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 return false;
945 EXPECT_TRUE_WAIT(observer->called(), kTimeout);
946 return observer->called();
947 }
948
Harald Alvestrand89061872018-01-02 14:08:34 +0100949 // Call the standards-compliant GetStats function.
950 bool DoGetRTCStats() {
951 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
952 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
953 pc_->GetStats(callback);
954 EXPECT_TRUE_WAIT(callback->called(), kTimeout);
955 return callback->called();
956 }
957
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 void InitiateCall() {
deadbeef293e9262017-01-11 12:28:30 -0800959 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 // Create a local stream with audio&video tracks.
Steve Anton36da6ff2018-02-16 16:04:20 -0800961 if (sdp_semantics_ == SdpSemantics::kPlanB) {
Seth Hampson845e8782018-03-02 11:34:10 -0800962 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
Steve Anton36da6ff2018-02-16 16:04:20 -0800963 } else {
964 // Unified Plan does not support AddStream, so just add an audio and video
965 // track.
Seth Hampson845e8782018-03-02 11:34:10 -0800966 AddAudioTrack(kAudioTracks[0], {kStreamId1});
967 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Steve Anton36da6ff2018-02-16 16:04:20 -0800968 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 CreateOfferReceiveAnswer();
970 }
971
972 // Verify that RTP Header extensions has been negotiated for audio and video.
973 void VerifyRemoteRtpHeaderExtensions() {
974 const cricket::MediaContentDescription* desc =
975 cricket::GetFirstAudioContentDescription(
976 pc_->remote_description()->description());
977 ASSERT_TRUE(desc != NULL);
978 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
979
980 desc = cricket::GetFirstVideoContentDescription(
981 pc_->remote_description()->description());
982 ASSERT_TRUE(desc != NULL);
983 EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
984 }
985
986 void CreateOfferAsRemoteDescription() {
kwibergd1fe2812016-04-27 06:47:29 -0700987 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -0700988 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 std::string sdp;
990 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700991 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800992 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -0700993 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
995 }
996
deadbeefab9b2d12015-10-14 11:33:11 -0700997 void CreateAndSetRemoteOffer(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -0700998 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -0800999 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001000 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07001001 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1002 }
1003
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 void CreateAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001005 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001006 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007
1008 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1009 // audio codec change, even if the parameter has nothing to do with
1010 // receiving. Not all parameters are serialized to SDP.
1011 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1012 // the SessionDescription, it is necessary to do that here to in order to
1013 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1014 // https://code.google.com/p/webrtc/issues/detail?id=1356
1015 std::string sdp;
1016 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001017 std::unique_ptr<SessionDescriptionInterface> new_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001018 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001019 EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1021 }
1022
1023 void CreatePrAnswerAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001024 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001025 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026
1027 std::string sdp;
1028 EXPECT_TRUE(answer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001029 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001030 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001031 EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1033 }
1034
1035 void CreateOfferReceiveAnswer() {
1036 CreateOfferAsLocalDescription();
1037 std::string sdp;
1038 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1039 CreateAnswerAsRemoteDescription(sdp);
1040 }
1041
1042 void CreateOfferAsLocalDescription() {
kwibergd1fe2812016-04-27 06:47:29 -07001043 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001044 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1046 // audio codec change, even if the parameter has nothing to do with
1047 // receiving. Not all parameters are serialized to SDP.
1048 // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1049 // the SessionDescription, it is necessary to do that here to in order to
1050 // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1051 // https://code.google.com/p/webrtc/issues/detail?id=1356
1052 std::string sdp;
1053 EXPECT_TRUE(offer->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001054 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001055 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056
Steve Antondb45ca82017-09-11 18:27:34 -07001057 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
mallinath@webrtc.org68cbd012014-01-22 00:16:46 +00001059 // Wait for the ice_complete message, so that SDP will have candidates.
Steve Anton6f25b092017-10-23 09:39:20 -07001060 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 }
1062
deadbeefab9b2d12015-10-14 11:33:11 -07001063 void CreateAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001064 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001065 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001066 ASSERT_TRUE(answer);
1067 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1069 }
1070
deadbeefab9b2d12015-10-14 11:33:11 -07001071 void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
Steve Antondb45ca82017-09-11 18:27:34 -07001072 std::unique_ptr<SessionDescriptionInterface> pr_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001073 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001074 ASSERT_TRUE(pr_answer);
1075 EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
Steve Antondb45ca82017-09-11 18:27:34 -07001077 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08001078 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001079 ASSERT_TRUE(answer);
1080 EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1082 }
1083
Seth Hampson845e8782018-03-02 11:34:10 -08001084 // Waits until a remote stream with the given id is signaled. This helper
Steve Anton36da6ff2018-02-16 16:04:20 -08001085 // function will verify both OnAddTrack and OnAddStream (Plan B only) are
Seth Hampson845e8782018-03-02 11:34:10 -08001086 // called with the given stream id and expected number of tracks.
1087 void WaitAndVerifyOnAddStream(const std::string& stream_id,
Steve Anton36da6ff2018-02-16 16:04:20 -08001088 int expected_num_tracks) {
1089 // Verify that both OnAddStream and OnAddTrack are called.
Seth Hampson845e8782018-03-02 11:34:10 -08001090 EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
Steve Anton36da6ff2018-02-16 16:04:20 -08001091 EXPECT_EQ_WAIT(expected_num_tracks,
Seth Hampson845e8782018-03-02 11:34:10 -08001092 observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 }
1094
1095 // Creates an offer and applies it as a local session description.
1096 // Creates an answer with the same SDP an the offer but removes all lines
1097 // that start with a:ssrc"
1098 void CreateOfferReceiveAnswerWithoutSsrc() {
1099 CreateOfferAsLocalDescription();
1100 std::string sdp;
1101 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1102 SetSsrcToZero(&sdp);
1103 CreateAnswerAsRemoteDescription(sdp);
1104 }
1105
deadbeefab9b2d12015-10-14 11:33:11 -07001106 // This function creates a MediaStream with label kStreams[0] and
1107 // |number_of_audio_tracks| and |number_of_video_tracks| tracks and the
1108 // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
kwiberg2bbff992016-03-16 11:03:04 -07001109 // is returned and the MediaStream is stored in
deadbeefab9b2d12015-10-14 11:33:11 -07001110 // |reference_collection_|
kwibergd1fe2812016-04-27 06:47:29 -07001111 std::unique_ptr<SessionDescriptionInterface>
kwiberg2bbff992016-03-16 11:03:04 -07001112 CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1113 size_t number_of_video_tracks) {
1114 EXPECT_LE(number_of_audio_tracks, 2u);
1115 EXPECT_LE(number_of_video_tracks, 2u);
deadbeefab9b2d12015-10-14 11:33:11 -07001116
1117 reference_collection_ = StreamCollection::Create();
1118 std::string sdp_ms1 = std::string(kSdpStringInit);
1119
Seth Hampson845e8782018-03-02 11:34:10 -08001120 std::string mediastream_id = kStreams[0];
deadbeefab9b2d12015-10-14 11:33:11 -07001121
1122 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001123 webrtc::MediaStream::Create(mediastream_id));
deadbeefab9b2d12015-10-14 11:33:11 -07001124 reference_collection_->AddStream(stream);
1125
1126 if (number_of_audio_tracks > 0) {
1127 sdp_ms1 += std::string(kSdpStringAudio);
1128 sdp_ms1 += std::string(kSdpStringMs1Audio0);
1129 AddAudioTrack(kAudioTracks[0], stream);
1130 }
1131 if (number_of_audio_tracks > 1) {
1132 sdp_ms1 += kSdpStringMs1Audio1;
1133 AddAudioTrack(kAudioTracks[1], stream);
1134 }
1135
1136 if (number_of_video_tracks > 0) {
1137 sdp_ms1 += std::string(kSdpStringVideo);
1138 sdp_ms1 += std::string(kSdpStringMs1Video0);
1139 AddVideoTrack(kVideoTracks[0], stream);
1140 }
1141 if (number_of_video_tracks > 1) {
1142 sdp_ms1 += kSdpStringMs1Video1;
1143 AddVideoTrack(kVideoTracks[1], stream);
1144 }
1145
kwibergd1fe2812016-04-27 06:47:29 -07001146 return std::unique_ptr<SessionDescriptionInterface>(
Steve Antona3a92c22017-12-07 10:27:41 -08001147 webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
deadbeefab9b2d12015-10-14 11:33:11 -07001148 }
1149
1150 void AddAudioTrack(const std::string& track_id,
1151 MediaStreamInterface* stream) {
1152 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1153 webrtc::AudioTrack::Create(track_id, nullptr));
1154 ASSERT_TRUE(stream->AddTrack(audio_track));
1155 }
1156
1157 void AddVideoTrack(const std::string& track_id,
1158 MediaStreamInterface* stream) {
1159 rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
nisseaf510af2016-03-21 08:20:42 -07001160 webrtc::VideoTrack::Create(track_id,
perkj773be362017-07-31 23:22:01 -07001161 webrtc::FakeVideoTrackSource::Create(),
1162 rtc::Thread::Current()));
deadbeefab9b2d12015-10-14 11:33:11 -07001163 ASSERT_TRUE(stream->AddTrack(video_track));
1164 }
1165
Steve Anton36da6ff2018-02-16 16:04:20 -08001166 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
deadbeef293e9262017-01-11 12:28:30 -08001167 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08001168 AddAudioTrack(kAudioTracks[0]);
kwibergfd8be342016-05-14 19:44:11 -07001169 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001170 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1171 return offer;
1172 }
1173
Steve Anton36da6ff2018-02-16 16:04:20 -08001174 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1175 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001176 AddAudioStream(kStreamId1);
Steve Anton36da6ff2018-02-16 16:04:20 -08001177 std::unique_ptr<SessionDescriptionInterface> offer;
1178 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1179 return offer;
1180 }
1181
1182 std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1183 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1184 std::unique_ptr<SessionDescriptionInterface> answer;
1185 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1186 return answer;
1187 }
1188
kwibergfd8be342016-05-14 19:44:11 -07001189 std::unique_ptr<SessionDescriptionInterface>
zhihuang8f65cdf2016-05-06 18:40:30 -07001190 CreateAnswerWithOneAudioStream() {
Steve Antondb45ca82017-09-11 18:27:34 -07001191 EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
kwibergfd8be342016-05-14 19:44:11 -07001192 std::unique_ptr<SessionDescriptionInterface> answer;
zhihuang8f65cdf2016-05-06 18:40:30 -07001193 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1194 return answer;
1195 }
1196
1197 const std::string& GetFirstAudioStreamCname(
1198 const SessionDescriptionInterface* desc) {
zhihuang8f65cdf2016-05-06 18:40:30 -07001199 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001200 cricket::GetFirstAudioContentDescription(desc->description());
zhihuang8f65cdf2016-05-06 18:40:30 -07001201 return audio_desc->streams()[0].cname;
1202 }
1203
zhihuang1c378ed2017-08-17 14:10:50 -07001204 std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1205 const RTCOfferAnswerOptions& offer_answer_options) {
1206 RTC_DCHECK(pc_);
1207 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
1208 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
1209 pc_->CreateOffer(observer, offer_answer_options);
1210 EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1211 return observer->MoveDescription();
1212 }
1213
1214 void CreateOfferWithOptionsAsRemoteDescription(
1215 std::unique_ptr<SessionDescriptionInterface>* desc,
1216 const RTCOfferAnswerOptions& offer_answer_options) {
1217 *desc = CreateOfferWithOptions(offer_answer_options);
1218 ASSERT_TRUE(desc != nullptr);
1219 std::string sdp;
1220 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001221 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001222 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001223 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001224 EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1225 }
1226
1227 void CreateOfferWithOptionsAsLocalDescription(
1228 std::unique_ptr<SessionDescriptionInterface>* desc,
1229 const RTCOfferAnswerOptions& offer_answer_options) {
1230 *desc = CreateOfferWithOptions(offer_answer_options);
1231 ASSERT_TRUE(desc != nullptr);
1232 std::string sdp;
1233 EXPECT_TRUE((*desc)->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07001234 std::unique_ptr<SessionDescriptionInterface> new_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08001235 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
zhihuang1c378ed2017-08-17 14:10:50 -07001236
Steve Antondb45ca82017-09-11 18:27:34 -07001237 EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
zhihuang1c378ed2017-08-17 14:10:50 -07001238 EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1239 }
1240
1241 bool HasCNCodecs(const cricket::ContentInfo* content) {
Steve Antonb1c1de12017-12-21 15:14:30 -08001242 RTC_DCHECK(content);
1243 RTC_DCHECK(content->media_description());
1244 for (const cricket::AudioCodec& codec :
1245 content->media_description()->as_audio()->codecs()) {
1246 if (codec.name == "CN") {
zhihuang1c378ed2017-08-17 14:10:50 -07001247 return true;
Steve Antonb1c1de12017-12-21 15:14:30 -08001248 }
zhihuang1c378ed2017-08-17 14:10:50 -07001249 }
1250 return false;
1251 }
1252
Steve Anton36da6ff2018-02-16 16:04:20 -08001253 const char* GetSdpStringWithStream1() const {
1254 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1255 return kSdpStringWithStream1PlanB;
1256 } else {
1257 return kSdpStringWithStream1UnifiedPlan;
1258 }
1259 }
1260
1261 const char* GetSdpStringWithStream1And2() const {
1262 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1263 return kSdpStringWithStream1And2PlanB;
1264 } else {
1265 return kSdpStringWithStream1And2UnifiedPlan;
1266 }
1267 }
1268
deadbeef9a6f4d42017-05-15 19:43:33 -07001269 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1270 rtc::AutoSocketServerThread main_;
deadbeefd7850b22017-08-23 10:59:19 -07001271 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08001272 cricket::FakePortAllocator* port_allocator_ = nullptr;
deadbeef8662f942017-01-20 21:20:51 -08001273 FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
zhihuang9763d562016-08-05 11:14:50 -07001274 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1275 rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1276 rtc::scoped_refptr<PeerConnectionInterface> pc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 MockPeerConnectionObserver observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001278 rtc::scoped_refptr<StreamCollection> reference_collection_;
Steve Anton36da6ff2018-02-16 16:04:20 -08001279 const SdpSemantics sdp_semantics_;
1280};
1281
1282class PeerConnectionInterfaceTest
1283 : public PeerConnectionInterfaceBaseTest,
1284 public ::testing::WithParamInterface<SdpSemantics> {
1285 protected:
1286 PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1287};
1288
1289class PeerConnectionInterfaceTestPlanB
1290 : public PeerConnectionInterfaceBaseTest {
1291 protected:
1292 PeerConnectionInterfaceTestPlanB()
1293 : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294};
1295
zhihuang8f65cdf2016-05-06 18:40:30 -07001296// Generate different CNAMEs when PeerConnections are created.
1297// The CNAMEs are expected to be generated randomly. It is possible
1298// that the test fails, though the possibility is very low.
Steve Anton36da6ff2018-02-16 16:04:20 -08001299TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
kwibergfd8be342016-05-14 19:44:11 -07001300 std::unique_ptr<SessionDescriptionInterface> offer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001301 CreateOfferWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001302 std::unique_ptr<SessionDescriptionInterface> offer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001303 CreateOfferWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001304 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1305 GetFirstAudioStreamCname(offer2.get()));
1306}
1307
Steve Anton36da6ff2018-02-16 16:04:20 -08001308TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
kwibergfd8be342016-05-14 19:44:11 -07001309 std::unique_ptr<SessionDescriptionInterface> answer1 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001310 CreateAnswerWithOneAudioTrack();
kwibergfd8be342016-05-14 19:44:11 -07001311 std::unique_ptr<SessionDescriptionInterface> answer2 =
Steve Anton36da6ff2018-02-16 16:04:20 -08001312 CreateAnswerWithOneAudioTrack();
zhihuang8f65cdf2016-05-06 18:40:30 -07001313 EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1314 GetFirstAudioStreamCname(answer2.get()));
1315}
1316
Steve Anton36da6ff2018-02-16 16:04:20 -08001317TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318 CreatePeerConnectionWithDifferentConfigurations) {
1319 CreatePeerConnectionWithDifferentConfigurations();
1320}
1321
Steve Anton36da6ff2018-02-16 16:04:20 -08001322TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001323 CreatePeerConnectionWithDifferentIceTransportsTypes) {
1324 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1325 EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1326 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1327 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1328 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1329 EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1330 port_allocator_->candidate_filter());
1331 CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1332 EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1333}
1334
1335// Test that when a PeerConnection is created with a nonzero candidate pool
1336// size, the pooled PortAllocatorSession is created with all the attributes
1337// in the RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001338TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001339 PeerConnectionInterface::RTCConfiguration config;
1340 PeerConnectionInterface::IceServer server;
1341 server.uri = kStunAddressOnly;
1342 config.servers.push_back(server);
1343 config.type = PeerConnectionInterface::kRelay;
1344 config.disable_ipv6 = true;
1345 config.tcp_candidate_policy =
1346 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
honghaiz60347052016-05-31 18:29:12 -07001347 config.candidate_network_policy =
1348 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001349 config.ice_candidate_pool_size = 1;
Niels Möllerf06f9232018-08-07 12:32:18 +02001350 CreatePeerConnection(config);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001351
1352 const cricket::FakePortAllocatorSession* session =
1353 static_cast<const cricket::FakePortAllocatorSession*>(
1354 port_allocator_->GetPooledSession());
1355 ASSERT_NE(nullptr, session);
1356 EXPECT_EQ(1UL, session->stun_servers().size());
1357 EXPECT_EQ(0U, session->flags() & cricket::PORTALLOCATOR_ENABLE_IPV6);
1358 EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
honghaiz60347052016-05-31 18:29:12 -07001359 EXPECT_LT(0U,
1360 session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
Taylor Brandstettera1c30352016-05-13 08:15:11 -07001361}
1362
deadbeefd21eab32017-07-26 16:50:11 -07001363// Test that network-related RTCConfiguration members are applied to the
1364// PortAllocator when CreatePeerConnection is called. Specifically:
1365// - disable_ipv6_on_wifi
1366// - max_ipv6_networks
1367// - tcp_candidate_policy
1368// - candidate_network_policy
1369// - prune_turn_ports
1370//
1371// Note that the candidate filter (RTCConfiguration::type) is already tested
1372// above.
Steve Anton36da6ff2018-02-16 16:04:20 -08001373TEST_P(PeerConnectionInterfaceTest,
deadbeefd21eab32017-07-26 16:50:11 -07001374 CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1375 // Create fake port allocator.
1376 std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1377 new cricket::FakePortAllocator(rtc::Thread::Current(), nullptr));
1378 cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1379
1380 // Create RTCConfiguration with some network-related fields relevant to
1381 // PortAllocator populated.
1382 PeerConnectionInterface::RTCConfiguration config;
1383 config.disable_ipv6_on_wifi = true;
1384 config.max_ipv6_networks = 10;
1385 config.tcp_candidate_policy =
1386 PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1387 config.candidate_network_policy =
1388 PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1389 config.prune_turn_ports = true;
1390
1391 // Create the PC factory and PC with the above config.
1392 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1393 webrtc::CreatePeerConnectionFactory(
1394 rtc::Thread::Current(), rtc::Thread::Current(),
Karl Wiberg1b0eae32017-10-17 14:48:54 +02001395 rtc::Thread::Current(), fake_audio_capture_module_,
1396 webrtc::CreateBuiltinAudioEncoderFactory(),
Anders Carlsson67537952018-05-03 11:28:29 +02001397 webrtc::CreateBuiltinAudioDecoderFactory(),
1398 webrtc::CreateBuiltinVideoEncoderFactory(),
1399 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1400 nullptr /* audio_processing */));
deadbeefd21eab32017-07-26 16:50:11 -07001401 rtc::scoped_refptr<PeerConnectionInterface> pc(
Niels Möllerf06f9232018-08-07 12:32:18 +02001402 pc_factory->CreatePeerConnection(config, std::move(port_allocator),
1403 nullptr, &observer_));
Yves Gerey4e933292018-10-31 15:36:05 +01001404 EXPECT_TRUE(pc.get());
1405 observer_.SetPeerConnectionInterface(pc.get());
deadbeefd21eab32017-07-26 16:50:11 -07001406
1407 // Now validate that the config fields set above were applied to the
1408 // PortAllocator, as flags or otherwise.
1409 EXPECT_FALSE(raw_port_allocator->flags() &
1410 cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1411 EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1412 EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1413 EXPECT_TRUE(raw_port_allocator->flags() &
1414 cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1415 EXPECT_TRUE(raw_port_allocator->prune_turn_ports());
1416}
1417
deadbeef46c73892016-11-16 19:42:04 -08001418// Check that GetConfiguration returns the configuration the PeerConnection was
1419// constructed with, before SetConfiguration is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08001420TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
deadbeef46c73892016-11-16 19:42:04 -08001421 PeerConnectionInterface::RTCConfiguration config;
1422 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02001423 CreatePeerConnection(config);
deadbeef46c73892016-11-16 19:42:04 -08001424
1425 PeerConnectionInterface::RTCConfiguration returned_config =
1426 pc_->GetConfiguration();
1427 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1428}
1429
1430// Check that GetConfiguration returns the last configuration passed into
1431// SetConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08001432TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
Piotr (Peter) Slatala37227be2018-11-21 07:42:22 -08001433 PeerConnectionInterface::RTCConfiguration starting_config;
1434 starting_config.bundle_policy =
1435 webrtc::PeerConnection::kBundlePolicyMaxBundle;
1436 CreatePeerConnection(starting_config);
deadbeef46c73892016-11-16 19:42:04 -08001437
Steve Anton36da6ff2018-02-16 16:04:20 -08001438 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef46c73892016-11-16 19:42:04 -08001439 config.type = PeerConnectionInterface::kRelay;
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001440 config.use_media_transport = true;
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001441 config.use_media_transport_for_data_channels = true;
deadbeef46c73892016-11-16 19:42:04 -08001442 EXPECT_TRUE(pc_->SetConfiguration(config));
1443
1444 PeerConnectionInterface::RTCConfiguration returned_config =
1445 pc_->GetConfiguration();
1446 EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
Piotr (Peter) Slatalaaa1e7c22018-10-16 10:04:45 -07001447 EXPECT_TRUE(returned_config.use_media_transport);
Bjorn Mellema9bbd862018-11-02 09:07:48 -07001448 EXPECT_TRUE(returned_config.use_media_transport_for_data_channels);
deadbeef46c73892016-11-16 19:42:04 -08001449}
1450
Steve Antonc79268f2018-04-24 09:54:10 -07001451TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1452 CreatePeerConnection();
1453
1454 pc_->Close();
1455
1456 EXPECT_FALSE(
1457 pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()));
1458}
1459
Steve Anton36da6ff2018-02-16 16:04:20 -08001460TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
deadbeef293e9262017-01-11 12:28:30 -08001461 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001462 AddVideoStream(kStreamId1);
1463 AddAudioStream(kStreamId2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 ASSERT_EQ(2u, pc_->local_streams()->count());
1465
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001466 // Test we can add multiple local streams to one peerconnection.
zhihuang9763d562016-08-05 11:14:50 -07001467 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08001468 pc_factory_->CreateLocalMediaStream(kStreamId3));
zhihuang9763d562016-08-05 11:14:50 -07001469 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Seth Hampson845e8782018-03-02 11:34:10 -08001470 pc_factory_->CreateAudioTrack(kStreamId3,
zhihuang9763d562016-08-05 11:14:50 -07001471 static_cast<AudioSourceInterface*>(NULL)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 stream->AddTrack(audio_track.get());
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00001473 EXPECT_TRUE(pc_->AddStream(stream));
wu@webrtc.org9dba5252013-08-05 20:36:57 +00001474 EXPECT_EQ(3u, pc_->local_streams()->count());
1475
1476 // Remove the third stream.
1477 pc_->RemoveStream(pc_->local_streams()->at(2));
1478 EXPECT_EQ(2u, pc_->local_streams()->count());
1479
1480 // Remove the second stream.
1481 pc_->RemoveStream(pc_->local_streams()->at(1));
1482 EXPECT_EQ(1u, pc_->local_streams()->count());
1483
1484 // Remove the first stream.
1485 pc_->RemoveStream(pc_->local_streams()->at(0));
1486 EXPECT_EQ(0u, pc_->local_streams()->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487}
1488
deadbeefab9b2d12015-10-14 11:33:11 -07001489// Test that the created offer includes streams we added.
Steve Anton36da6ff2018-02-16 16:04:20 -08001490// Don't run under Unified Plan since the stream API is not available.
1491TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
deadbeef293e9262017-01-11 12:28:30 -08001492 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001493 AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
kwibergd1fe2812016-04-27 06:47:29 -07001494 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001495 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001496
deadbeefab9b2d12015-10-14 11:33:11 -07001497 const cricket::AudioContentDescription* audio_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001498 cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001499 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001500
deadbeefab9b2d12015-10-14 11:33:11 -07001501 const cricket::VideoContentDescription* video_desc =
Steve Antonb1c1de12017-12-21 15:14:30 -08001502 cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001503 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
deadbeefab9b2d12015-10-14 11:33:11 -07001504
1505 // Add another stream and ensure the offer includes both the old and new
1506 // streams.
Seth Hampson845e8782018-03-02 11:34:10 -08001507 AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
kwiberg2bbff992016-03-16 11:03:04 -07001508 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07001509
Steve Antonb1c1de12017-12-21 15:14:30 -08001510 audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001511 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1512 EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001513
Steve Antonb1c1de12017-12-21 15:14:30 -08001514 video_desc = cricket::GetFirstVideoContentDescription(offer->description());
Seth Hampson845e8782018-03-02 11:34:10 -08001515 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1516 EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
deadbeefab9b2d12015-10-14 11:33:11 -07001517}
1518
Steve Anton36da6ff2018-02-16 16:04:20 -08001519// Don't run under Unified Plan since the stream API is not available.
1520TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
deadbeef293e9262017-01-11 12:28:30 -08001521 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001522 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 ASSERT_EQ(1u, pc_->local_streams()->count());
1524 pc_->RemoveStream(pc_->local_streams()->at(0));
1525 EXPECT_EQ(0u, pc_->local_streams()->count());
1526}
1527
deadbeefe1f9d832016-01-14 15:35:42 -08001528// Test for AddTrack and RemoveTrack methods.
1529// Tests that the created offer includes tracks we added,
1530// and that the RtpSenders are created correctly.
1531// Also tests that RemoveTrack removes the tracks from subsequent offers.
Steve Anton36da6ff2018-02-16 16:04:20 -08001532// Only tested with Plan B since Unified Plan is covered in more detail by tests
1533// in peerconnection_jsep_unittests.cc
1534TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
deadbeef293e9262017-01-11 12:28:30 -08001535 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001536 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001537 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001538 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001539 CreateVideoTrack("video_track"));
Seth Hampson845e8782018-03-02 11:34:10 -08001540 auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1541 auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
deadbeefa601f5c2016-06-06 14:27:39 -07001542 EXPECT_EQ(1UL, audio_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001543 EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001544 EXPECT_EQ("audio_track", audio_sender->id());
1545 EXPECT_EQ(audio_track, audio_sender->track());
deadbeefa601f5c2016-06-06 14:27:39 -07001546 EXPECT_EQ(1UL, video_sender->stream_ids().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001547 EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
deadbeefe1f9d832016-01-14 15:35:42 -08001548 EXPECT_EQ("video_track", video_sender->id());
1549 EXPECT_EQ(video_track, video_sender->track());
1550
1551 // Now create an offer and check for the senders.
kwibergd1fe2812016-04-27 06:47:29 -07001552 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001553 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001554
1555 const cricket::ContentInfo* audio_content =
1556 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001557 EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001558 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001559
1560 const cricket::ContentInfo* video_content =
1561 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001562 EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001563 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001564
Steve Antondb45ca82017-09-11 18:27:34 -07001565 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001566
1567 // Now try removing the tracks.
1568 EXPECT_TRUE(pc_->RemoveTrack(audio_sender));
1569 EXPECT_TRUE(pc_->RemoveTrack(video_sender));
1570
1571 // Create a new offer and ensure it doesn't contain the removed senders.
kwiberg2bbff992016-03-16 11:03:04 -07001572 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefe1f9d832016-01-14 15:35:42 -08001573
1574 audio_content = cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001575 EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001576 kStreamId1, "audio_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001577
1578 video_content = cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08001579 EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
Seth Hampson845e8782018-03-02 11:34:10 -08001580 kStreamId1, "video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001581
Steve Antondb45ca82017-09-11 18:27:34 -07001582 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefe1f9d832016-01-14 15:35:42 -08001583
1584 // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1585 // should return false.
1586 EXPECT_FALSE(pc_->RemoveTrack(audio_sender));
1587 EXPECT_FALSE(pc_->RemoveTrack(video_sender));
1588}
1589
1590// Test creating senders without a stream specified,
1591// expecting a random stream ID to be generated.
Steve Anton36da6ff2018-02-16 16:04:20 -08001592TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
deadbeef293e9262017-01-11 12:28:30 -08001593 CreatePeerConnectionWithoutDtls();
zhihuang9763d562016-08-05 11:14:50 -07001594 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001595 CreateAudioTrack("audio_track"));
zhihuang9763d562016-08-05 11:14:50 -07001596 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001597 CreateVideoTrack("video_track"));
deadbeefe1f9d832016-01-14 15:35:42 -08001598 auto audio_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001599 pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001600 auto video_sender =
Steve Anton2d6c76a2018-01-05 17:10:52 -08001601 pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
deadbeefe1f9d832016-01-14 15:35:42 -08001602 EXPECT_EQ("audio_track", audio_sender->id());
1603 EXPECT_EQ(audio_track, audio_sender->track());
1604 EXPECT_EQ("video_track", video_sender->id());
1605 EXPECT_EQ(video_track, video_sender->track());
Seth Hampson5b4f0752018-04-02 16:31:36 -07001606 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1607 // If the ID is truly a random GUID, it should be infinitely unlikely they
1608 // will be the same.
1609 EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1610 } else {
1611 // We allows creating tracks without stream ids under Unified Plan
1612 // semantics.
1613 EXPECT_EQ(0u, video_sender->stream_ids().size());
1614 EXPECT_EQ(0u, audio_sender->stream_ids().size());
1615 }
deadbeefe1f9d832016-01-14 15:35:42 -08001616}
1617
Harald Alvestrand89061872018-01-02 14:08:34 +01001618// Test that we can call GetStats() after AddTrack but before connecting
1619// the PeerConnection to a peer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001620TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001621 CreatePeerConnectionWithoutDtls();
1622 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001623 CreateAudioTrack("audio_track"));
Harald Alvestrand89061872018-01-02 14:08:34 +01001624 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001625 CreateVideoTrack("video_track"));
Steve Anton2d6c76a2018-01-05 17:10:52 -08001626 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1627 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Harald Alvestrand89061872018-01-02 14:08:34 +01001628 EXPECT_TRUE(DoGetStats(nullptr));
1629}
1630
Steve Anton36da6ff2018-02-16 16:04:20 -08001631TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001632 CreatePeerConnectionWithoutDtls();
1633 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01001634 CreateAudioTrack("audio_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001635 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001636 CreateVideoTrack("video_track"));
Harald Alvestrandc72af932018-01-11 17:18:19 +01001637 auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001638 ASSERT_TRUE(audio_sender.ok());
1639 auto* audio_sender_proxy =
1640 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1641 audio_sender.value().get());
1642 EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1643
Harald Alvestrandc72af932018-01-11 17:18:19 +01001644 auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
Steve Anton57858b32018-02-15 15:19:50 -08001645 ASSERT_TRUE(video_sender.ok());
1646 auto* video_sender_proxy =
1647 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1648 video_sender.value().get());
1649 EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001650}
1651
Steve Anton36da6ff2018-02-16 16:04:20 -08001652// Don't run under Unified Plan since the stream API is not available.
1653TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
Harald Alvestrandc72af932018-01-11 17:18:19 +01001654 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001655 AddVideoStream(kStreamId1);
Harald Alvestrandc72af932018-01-11 17:18:19 +01001656 auto senders = pc_->GetSenders();
Steve Anton57858b32018-02-15 15:19:50 -08001657 ASSERT_EQ(1u, senders.size());
1658 auto* sender_proxy =
1659 static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1660 senders[0].get());
1661 EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
Harald Alvestrandc72af932018-01-11 17:18:19 +01001662}
1663
Steve Anton36da6ff2018-02-16 16:04:20 -08001664TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 InitiateCall();
Seth Hampson845e8782018-03-02 11:34:10 -08001666 WaitAndVerifyOnAddStream(kStreamId1, 2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 VerifyRemoteRtpHeaderExtensions();
1668}
1669
Steve Anton36da6ff2018-02-16 16:04:20 -08001670TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001671 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001672 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 CreateOfferAsLocalDescription();
1674 std::string offer;
1675 EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1676 CreatePrAnswerAndAnswerAsRemoteDescription(offer);
Seth Hampson845e8782018-03-02 11:34:10 -08001677 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678}
1679
Steve Anton36da6ff2018-02-16 16:04:20 -08001680TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001681 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001682 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683
1684 CreateOfferAsRemoteDescription();
1685 CreateAnswerAsLocalDescription();
1686
Seth Hampson845e8782018-03-02 11:34:10 -08001687 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688}
1689
Steve Anton36da6ff2018-02-16 16:04:20 -08001690TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001691 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001692 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693
1694 CreateOfferAsRemoteDescription();
1695 CreatePrAnswerAsLocalDescription();
1696 CreateAnswerAsLocalDescription();
1697
Seth Hampson845e8782018-03-02 11:34:10 -08001698 WaitAndVerifyOnAddStream(kStreamId1, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699}
1700
Steve Anton36da6ff2018-02-16 16:04:20 -08001701// Don't run under Unified Plan since the stream API is not available.
1702TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 InitiateCall();
1704 ASSERT_EQ(1u, pc_->remote_streams()->count());
1705 pc_->RemoveStream(pc_->local_streams()->at(0));
1706 CreateOfferReceiveAnswer();
1707 EXPECT_EQ(0u, pc_->remote_streams()->count());
Seth Hampson845e8782018-03-02 11:34:10 -08001708 AddVideoStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709 CreateOfferReceiveAnswer();
1710}
1711
1712// Tests that after negotiating an audio only call, the respondent can perform a
1713// renegotiation that removes the audio stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08001714TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
deadbeef293e9262017-01-11 12:28:30 -08001715 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001716 AddAudioStream(kStreamId1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 CreateOfferAsRemoteDescription();
1718 CreateAnswerAsLocalDescription();
1719
1720 ASSERT_EQ(1u, pc_->remote_streams()->count());
1721 pc_->RemoveStream(pc_->local_streams()->at(0));
1722 CreateOfferReceiveAnswer();
1723 EXPECT_EQ(0u, pc_->remote_streams()->count());
1724}
1725
1726// Test that candidates are generated and that we can parse our own candidates.
Steve Anton36da6ff2018-02-16 16:04:20 -08001727TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
deadbeef293e9262017-01-11 12:28:30 -08001728 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729
Steve Antonf1c6db12017-10-13 11:13:35 -07001730 EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 // SetRemoteDescription takes ownership of offer.
kwibergd1fe2812016-04-27 06:47:29 -07001732 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08001733 AddVideoTrack(kVideoTracks[0]);
deadbeefc80741f2015-10-22 13:14:45 -07001734 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001735 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736
1737 // SetLocalDescription takes ownership of answer.
kwibergd1fe2812016-04-27 06:47:29 -07001738 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001739 EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07001740 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741
Steve Antonf1c6db12017-10-13 11:13:35 -07001742 EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07001743 EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744
Steve Antonf1c6db12017-10-13 11:13:35 -07001745 EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746}
1747
deadbeefab9b2d12015-10-14 11:33:11 -07001748// Test that CreateOffer and CreateAnswer will fail if the track labels are
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749// not unique.
Steve Anton07563732018-06-26 11:13:50 -07001750TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
deadbeef293e9262017-01-11 12:28:30 -08001751 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 // Create a regular offer for the CreateAnswer test later.
kwibergd1fe2812016-04-27 06:47:29 -07001753 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07001754 EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
kwiberg2bbff992016-03-16 11:03:04 -07001755 EXPECT_TRUE(offer);
1756 offer.reset();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757
1758 // Create a local stream with audio&video tracks having same label.
Seth Hampson845e8782018-03-02 11:34:10 -08001759 AddAudioTrack("track_label", {kStreamId1});
1760 AddVideoTrack("track_label", {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761
1762 // Test CreateOffer
deadbeefc80741f2015-10-22 13:14:45 -07001763 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764
1765 // Test CreateAnswer
kwibergd1fe2812016-04-27 06:47:29 -07001766 std::unique_ptr<SessionDescriptionInterface> answer;
deadbeefc80741f2015-10-22 13:14:45 -07001767 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768}
1769
1770// Test that we will get different SSRCs for each tracks in the offer and answer
1771// we created.
Steve Anton36da6ff2018-02-16 16:04:20 -08001772TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
deadbeef293e9262017-01-11 12:28:30 -08001773 CreatePeerConnectionWithoutDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 // Create a local stream with audio&video tracks having different labels.
Seth Hampson845e8782018-03-02 11:34:10 -08001775 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1776 AddVideoTrack(kVideoTracks[0], {kStreamId1});
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777
1778 // Test CreateOffer
kwibergd1fe2812016-04-27 06:47:29 -07001779 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001780 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 int audio_ssrc = 0;
1782 int video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001783 EXPECT_TRUE(
1784 GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1785 EXPECT_TRUE(
1786 GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 EXPECT_NE(audio_ssrc, video_ssrc);
1788
1789 // Test CreateAnswer
Steve Antondb45ca82017-09-11 18:27:34 -07001790 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
kwibergd1fe2812016-04-27 06:47:29 -07001791 std::unique_ptr<SessionDescriptionInterface> answer;
kwiberg2bbff992016-03-16 11:03:04 -07001792 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 audio_ssrc = 0;
1794 video_ssrc = 0;
Yves Gerey665174f2018-06-19 15:03:05 +02001795 EXPECT_TRUE(
1796 GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1797 EXPECT_TRUE(
1798 GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 EXPECT_NE(audio_ssrc, video_ssrc);
1800}
1801
deadbeefeb459812015-12-15 19:24:43 -08001802// Test that it's possible to call AddTrack on a MediaStream after adding
1803// the stream to a PeerConnection.
1804// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001805// Don't run under Unified Plan since the stream API is not available.
1806TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001807 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001808 // Create audio stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001809 AddAudioStream(kStreamId1);
deadbeefeb459812015-12-15 19:24:43 -08001810 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1811
1812 // Add video track to the audio-only stream.
zhihuang9763d562016-08-05 11:14:50 -07001813 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01001814 CreateVideoTrack("video_label"));
deadbeefeb459812015-12-15 19:24:43 -08001815 stream->AddTrack(video_track.get());
1816
kwibergd1fe2812016-04-27 06:47:29 -07001817 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001818 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001819
1820 const cricket::MediaContentDescription* video_desc =
1821 cricket::GetFirstVideoContentDescription(offer->description());
1822 EXPECT_TRUE(video_desc != nullptr);
1823}
1824
1825// Test that it's possible to call RemoveTrack on a MediaStream after adding
1826// the stream to a PeerConnection.
1827// TODO(deadbeef): Remove this test once this behavior is no longer supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08001828// Don't run under Unified Plan since the stream API is not available.
1829TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
deadbeef293e9262017-01-11 12:28:30 -08001830 CreatePeerConnectionWithoutDtls();
deadbeefeb459812015-12-15 19:24:43 -08001831 // Create audio/video stream and add to PeerConnection.
Seth Hampson845e8782018-03-02 11:34:10 -08001832 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
deadbeefeb459812015-12-15 19:24:43 -08001833 MediaStreamInterface* stream = pc_->local_streams()->at(0);
1834
1835 // Remove the video track.
1836 stream->RemoveTrack(stream->GetVideoTracks()[0]);
1837
kwibergd1fe2812016-04-27 06:47:29 -07001838 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001839 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefeb459812015-12-15 19:24:43 -08001840
1841 const cricket::MediaContentDescription* video_desc =
1842 cricket::GetFirstVideoContentDescription(offer->description());
1843 EXPECT_TRUE(video_desc == nullptr);
1844}
1845
deadbeefbd7d8f72015-12-18 16:58:44 -08001846// Test creating a sender with a stream ID, and ensure the ID is populated
1847// in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08001848// Don't run under Unified Plan since the stream API is not available.
1849TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
deadbeef293e9262017-01-11 12:28:30 -08001850 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08001851 pc_->CreateSender("video", kStreamId1);
deadbeefbd7d8f72015-12-18 16:58:44 -08001852
kwibergd1fe2812016-04-27 06:47:29 -07001853 std::unique_ptr<SessionDescriptionInterface> offer;
kwiberg2bbff992016-03-16 11:03:04 -07001854 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
deadbeefbd7d8f72015-12-18 16:58:44 -08001855
1856 const cricket::MediaContentDescription* video_desc =
1857 cricket::GetFirstVideoContentDescription(offer->description());
1858 ASSERT_TRUE(video_desc != nullptr);
1859 ASSERT_EQ(1u, video_desc->streams().size());
Seth Hampson845e8782018-03-02 11:34:10 -08001860 EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
deadbeefbd7d8f72015-12-18 16:58:44 -08001861}
1862
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863// Test that we can specify a certain track that we want statistics about.
Steve Anton36da6ff2018-02-16 16:04:20 -08001864TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001866 ASSERT_LT(0u, pc_->GetSenders().size());
1867 ASSERT_LT(0u, pc_->GetReceivers().size());
zhihuang9763d562016-08-05 11:14:50 -07001868 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
Steve Anton36da6ff2018-02-16 16:04:20 -08001869 pc_->GetReceivers()[0]->track();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870 EXPECT_TRUE(DoGetStats(remote_audio));
1871
1872 // Remove the stream. Since we are sending to our selves the local
1873 // and the remote stream is the same.
Steve Anton36da6ff2018-02-16 16:04:20 -08001874 pc_->RemoveTrack(pc_->GetSenders()[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 // Do a re-negotiation.
1876 CreateOfferReceiveAnswer();
1877
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001878 // Test that we still can get statistics for the old track. Even if it is not
1879 // sent any longer.
1880 EXPECT_TRUE(DoGetStats(remote_audio));
1881}
1882
1883// Test that we can get stats on a video track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001884TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001885 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08001886 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1887 ASSERT_TRUE(video_receiver);
1888 EXPECT_TRUE(DoGetStats(video_receiver->track()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889}
1890
1891// Test that we don't get statistics for an invalid track.
Steve Anton36da6ff2018-02-16 16:04:20 -08001892TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 InitiateCall();
zhihuang9763d562016-08-05 11:14:50 -07001894 rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895 pc_factory_->CreateAudioTrack("unknown track", NULL));
1896 EXPECT_FALSE(DoGetStats(unknown_audio_track));
1897}
1898
Steve Anton36da6ff2018-02-16 16:04:20 -08001899TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
Harald Alvestrand89061872018-01-02 14:08:34 +01001900 CreatePeerConnectionWithoutDtls();
1901 EXPECT_TRUE(DoGetRTCStats());
1902 // Clearing stats cache is needed now, but should be temporary.
1903 // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1904 pc_->ClearStatsCache();
Seth Hampson845e8782018-03-02 11:34:10 -08001905 AddAudioTrack(kAudioTracks[0], {kStreamId1});
1906 AddVideoTrack(kVideoTracks[0], {kStreamId1});
Harald Alvestrand89061872018-01-02 14:08:34 +01001907 EXPECT_TRUE(DoGetRTCStats());
1908 pc_->ClearStatsCache();
1909 CreateOfferReceiveAnswer();
1910 EXPECT_TRUE(DoGetRTCStats());
1911}
1912
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913// This test setup two RTP data channels in loop back.
Steve Anton36da6ff2018-02-16 16:04:20 -08001914TEST_P(PeerConnectionInterfaceTest, TestDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001915 RTCConfiguration config;
1916 config.enable_rtp_data_channel = true;
1917 config.enable_dtls_srtp = false;
1918 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001919 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001921 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 pc_->CreateDataChannel("test2", NULL);
1923 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001924 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001926 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927 new MockDataChannelObserver(data2));
1928
1929 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1930 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1931 std::string data_to_send1 = "testing testing";
1932 std::string data_to_send2 = "testing something else";
1933 EXPECT_FALSE(data1->Send(DataBuffer(data_to_send1)));
1934
1935 CreateOfferReceiveAnswer();
1936 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1937 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1938
1939 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1940 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1941 EXPECT_TRUE(data1->Send(DataBuffer(data_to_send1)));
1942 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1943
1944 EXPECT_EQ_WAIT(data_to_send1, observer1->last_message(), kTimeout);
1945 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1946
1947 data1->Close();
1948 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
1949 CreateOfferReceiveAnswer();
1950 EXPECT_FALSE(observer1->IsOpen());
1951 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
1952 EXPECT_TRUE(observer2->IsOpen());
1953
1954 data_to_send2 = "testing something else again";
1955 EXPECT_TRUE(data2->Send(DataBuffer(data_to_send2)));
1956
1957 EXPECT_EQ_WAIT(data_to_send2, observer2->last_message(), kTimeout);
1958}
1959
1960// This test verifies that sendnig binary data over RTP data channels should
1961// fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08001962TEST_P(PeerConnectionInterfaceTest, TestSendBinaryOnRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001963 RTCConfiguration config;
1964 config.enable_rtp_data_channel = true;
1965 config.enable_dtls_srtp = false;
1966 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001967 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07001969 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 pc_->CreateDataChannel("test2", NULL);
1971 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07001972 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07001974 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 new MockDataChannelObserver(data2));
1976
1977 EXPECT_EQ(DataChannelInterface::kConnecting, data1->state());
1978 EXPECT_EQ(DataChannelInterface::kConnecting, data2->state());
1979
1980 CreateOfferReceiveAnswer();
1981 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
1982 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
1983
1984 EXPECT_EQ(DataChannelInterface::kOpen, data1->state());
1985 EXPECT_EQ(DataChannelInterface::kOpen, data2->state());
1986
jbaucheec21bd2016-03-20 06:15:43 -07001987 rtc::CopyOnWriteBuffer buffer("test", 4);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 EXPECT_FALSE(data1->Send(DataBuffer(buffer, true)));
1989}
1990
1991// This test setup a RTP data channels in loop back and test that a channel is
1992// opened even if the remote end answer with a zero SSRC.
Steve Anton36da6ff2018-02-16 16:04:20 -08001993TEST_P(PeerConnectionInterfaceTest, TestSendOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02001994 RTCConfiguration config;
1995 config.enable_rtp_data_channel = true;
1996 config.enable_dtls_srtp = false;
1997 CreatePeerConnection(config);
zhihuang9763d562016-08-05 11:14:50 -07001998 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 pc_->CreateDataChannel("test1", NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002000 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 new MockDataChannelObserver(data1));
2002
2003 CreateOfferReceiveAnswerWithoutSsrc();
2004
2005 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2006
2007 data1->Close();
2008 EXPECT_EQ(DataChannelInterface::kClosing, data1->state());
2009 CreateOfferReceiveAnswerWithoutSsrc();
2010 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2011 EXPECT_FALSE(observer1->IsOpen());
2012}
2013
2014// This test that if a data channel is added in an answer a receive only channel
2015// channel is created.
Steve Anton36da6ff2018-02-16 16:04:20 -08002016TEST_P(PeerConnectionInterfaceTest, TestReceiveOnlyDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002017 RTCConfiguration config;
2018 config.enable_rtp_data_channel = true;
2019 config.enable_dtls_srtp = false;
2020
2021 CreatePeerConnection(config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022
2023 std::string offer_label = "offer_channel";
zhihuang9763d562016-08-05 11:14:50 -07002024 rtc::scoped_refptr<DataChannelInterface> offer_channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 pc_->CreateDataChannel(offer_label, NULL);
2026
2027 CreateOfferAsLocalDescription();
2028
2029 // Replace the data channel label in the offer and apply it as an answer.
2030 std::string receive_label = "answer_channel";
2031 std::string sdp;
2032 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002033 rtc::replace_substrs(offer_label.c_str(), offer_label.length(),
Yves Gerey665174f2018-06-19 15:03:05 +02002034 receive_label.c_str(), receive_label.length(), &sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 CreateAnswerAsRemoteDescription(sdp);
2036
2037 // Verify that a new incoming data channel has been created and that
2038 // it is open but can't we written to.
2039 ASSERT_TRUE(observer_.last_datachannel_ != NULL);
2040 DataChannelInterface* received_channel = observer_.last_datachannel_;
2041 EXPECT_EQ(DataChannelInterface::kConnecting, received_channel->state());
2042 EXPECT_EQ(receive_label, received_channel->label());
2043 EXPECT_FALSE(received_channel->Send(DataBuffer("something")));
2044
2045 // Verify that the channel we initially offered has been rejected.
2046 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2047
2048 // Do another offer / answer exchange and verify that the data channel is
2049 // opened.
2050 CreateOfferReceiveAnswer();
2051 EXPECT_EQ_WAIT(DataChannelInterface::kOpen, received_channel->state(),
2052 kTimeout);
2053}
2054
2055// This test that no data channel is returned if a reliable channel is
2056// requested.
2057// TODO(perkj): Remove this test once reliable channels are implemented.
Steve Anton36da6ff2018-02-16 16:04:20 -08002058TEST_P(PeerConnectionInterfaceTest, CreateReliableRtpDataChannelShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002059 RTCConfiguration rtc_config;
2060 rtc_config.enable_rtp_data_channel = true;
2061 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062
2063 std::string label = "test";
2064 webrtc::DataChannelInit config;
2065 config.reliable = true;
zhihuang9763d562016-08-05 11:14:50 -07002066 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 pc_->CreateDataChannel(label, &config);
2068 EXPECT_TRUE(channel == NULL);
2069}
2070
deadbeefab9b2d12015-10-14 11:33:11 -07002071// Verifies that duplicated label is not allowed for RTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002072TEST_P(PeerConnectionInterfaceTest, RtpDuplicatedLabelNotAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002073 RTCConfiguration config;
2074 config.enable_rtp_data_channel = true;
2075 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002076
2077 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002078 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002079 pc_->CreateDataChannel(label, nullptr);
2080 EXPECT_NE(channel, nullptr);
2081
zhihuang9763d562016-08-05 11:14:50 -07002082 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002083 pc_->CreateDataChannel(label, nullptr);
2084 EXPECT_EQ(dup_channel, nullptr);
2085}
2086
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087// This tests that a SCTP data channel is returned using different
2088// DataChannelInit configurations.
Steve Anton36da6ff2018-02-16 16:04:20 -08002089TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002090 RTCConfiguration rtc_config;
2091 rtc_config.enable_dtls_srtp = true;
2092 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093
2094 webrtc::DataChannelInit config;
2095
zhihuang9763d562016-08-05 11:14:50 -07002096 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 pc_->CreateDataChannel("1", &config);
2098 EXPECT_TRUE(channel != NULL);
2099 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002100 EXPECT_TRUE(observer_.renegotiation_needed_);
2101 observer_.renegotiation_needed_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102
2103 config.ordered = false;
2104 channel = pc_->CreateDataChannel("2", &config);
2105 EXPECT_TRUE(channel != NULL);
2106 EXPECT_TRUE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002107 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
2109 config.ordered = true;
2110 config.maxRetransmits = 0;
2111 channel = pc_->CreateDataChannel("3", &config);
2112 EXPECT_TRUE(channel != NULL);
2113 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002114 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115
2116 config.maxRetransmits = -1;
2117 config.maxRetransmitTime = 0;
2118 channel = pc_->CreateDataChannel("4", &config);
2119 EXPECT_TRUE(channel != NULL);
2120 EXPECT_FALSE(channel->reliable());
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002121 EXPECT_FALSE(observer_.renegotiation_needed_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122}
2123
2124// This tests that no data channel is returned if both maxRetransmits and
2125// maxRetransmitTime are set for SCTP data channels.
Steve Anton36da6ff2018-02-16 16:04:20 -08002126TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 CreateSctpDataChannelShouldFailForInvalidConfig) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002128 RTCConfiguration rtc_config;
2129 rtc_config.enable_dtls_srtp = true;
2130 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131
2132 std::string label = "test";
2133 webrtc::DataChannelInit config;
2134 config.maxRetransmits = 0;
2135 config.maxRetransmitTime = 0;
2136
zhihuang9763d562016-08-05 11:14:50 -07002137 rtc::scoped_refptr<DataChannelInterface> channel =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 pc_->CreateDataChannel(label, &config);
2139 EXPECT_TRUE(channel == NULL);
2140}
2141
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142// The test verifies that creating a SCTP data channel with an id already in use
2143// or out of range should fail.
Steve Anton36da6ff2018-02-16 16:04:20 -08002144TEST_P(PeerConnectionInterfaceTest,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 CreateSctpDataChannelWithInvalidIdShouldFail) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002146 RTCConfiguration rtc_config;
2147 rtc_config.enable_dtls_srtp = true;
2148 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149
2150 webrtc::DataChannelInit config;
zhihuang9763d562016-08-05 11:14:50 -07002151 rtc::scoped_refptr<DataChannelInterface> channel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152
wu@webrtc.orgcecfd182013-10-30 05:18:12 +00002153 config.id = 1;
2154 channel = pc_->CreateDataChannel("1", &config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 EXPECT_TRUE(channel != NULL);
2156 EXPECT_EQ(1, channel->id());
2157
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 channel = pc_->CreateDataChannel("x", &config);
2159 EXPECT_TRUE(channel == NULL);
2160
2161 config.id = cricket::kMaxSctpSid;
2162 channel = pc_->CreateDataChannel("max", &config);
2163 EXPECT_TRUE(channel != NULL);
2164 EXPECT_EQ(config.id, channel->id());
2165
2166 config.id = cricket::kMaxSctpSid + 1;
2167 channel = pc_->CreateDataChannel("x", &config);
2168 EXPECT_TRUE(channel == NULL);
2169}
2170
deadbeefab9b2d12015-10-14 11:33:11 -07002171// Verifies that duplicated label is allowed for SCTP data channel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002172TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002173 RTCConfiguration rtc_config;
2174 rtc_config.enable_dtls_srtp = true;
2175 CreatePeerConnection(rtc_config);
deadbeefab9b2d12015-10-14 11:33:11 -07002176
2177 std::string label = "test";
zhihuang9763d562016-08-05 11:14:50 -07002178 rtc::scoped_refptr<DataChannelInterface> channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002179 pc_->CreateDataChannel(label, nullptr);
2180 EXPECT_NE(channel, nullptr);
2181
zhihuang9763d562016-08-05 11:14:50 -07002182 rtc::scoped_refptr<DataChannelInterface> dup_channel =
deadbeefab9b2d12015-10-14 11:33:11 -07002183 pc_->CreateDataChannel(label, nullptr);
2184 EXPECT_NE(dup_channel, nullptr);
2185}
2186
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002187// This test verifies that OnRenegotiationNeeded is fired for every new RTP
2188// DataChannel.
Steve Anton36da6ff2018-02-16 16:04:20 -08002189TEST_P(PeerConnectionInterfaceTest, RenegotiationNeededForNewRtpDataChannel) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002190 RTCConfiguration rtc_config;
2191 rtc_config.enable_rtp_data_channel = true;
2192 rtc_config.enable_dtls_srtp = false;
2193 CreatePeerConnection(rtc_config);
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002194
zhihuang9763d562016-08-05 11:14:50 -07002195 rtc::scoped_refptr<DataChannelInterface> dc1 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002196 pc_->CreateDataChannel("test1", NULL);
2197 EXPECT_TRUE(observer_.renegotiation_needed_);
2198 observer_.renegotiation_needed_ = false;
2199
zhihuang9763d562016-08-05 11:14:50 -07002200 rtc::scoped_refptr<DataChannelInterface> dc2 =
jiayl@webrtc.org001fd2d2014-05-29 15:31:11 +00002201 pc_->CreateDataChannel("test2", NULL);
2202 EXPECT_TRUE(observer_.renegotiation_needed_);
2203}
2204
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205// This test that a data channel closes when a PeerConnection is deleted/closed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002206TEST_P(PeerConnectionInterfaceTest, DataChannelCloseWhenPeerConnectionClose) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002207 RTCConfiguration rtc_config;
2208 rtc_config.enable_rtp_data_channel = true;
2209 rtc_config.enable_dtls_srtp = false;
2210 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211
zhihuang9763d562016-08-05 11:14:50 -07002212 rtc::scoped_refptr<DataChannelInterface> data1 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 pc_->CreateDataChannel("test1", NULL);
zhihuang9763d562016-08-05 11:14:50 -07002214 rtc::scoped_refptr<DataChannelInterface> data2 =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 pc_->CreateDataChannel("test2", NULL);
2216 ASSERT_TRUE(data1 != NULL);
kwibergd1fe2812016-04-27 06:47:29 -07002217 std::unique_ptr<MockDataChannelObserver> observer1(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218 new MockDataChannelObserver(data1));
kwibergd1fe2812016-04-27 06:47:29 -07002219 std::unique_ptr<MockDataChannelObserver> observer2(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 new MockDataChannelObserver(data2));
2221
2222 CreateOfferReceiveAnswer();
2223 EXPECT_TRUE_WAIT(observer1->IsOpen(), kTimeout);
2224 EXPECT_TRUE_WAIT(observer2->IsOpen(), kTimeout);
2225
2226 ReleasePeerConnection();
2227 EXPECT_EQ(DataChannelInterface::kClosed, data1->state());
2228 EXPECT_EQ(DataChannelInterface::kClosed, data2->state());
2229}
2230
Zhi Huang644fde42018-04-02 19:16:26 -07002231// This tests that RTP data channels can be rejected in an answer.
2232TEST_P(PeerConnectionInterfaceTest, TestRejectRtpDataChannelInAnswer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002233 RTCConfiguration rtc_config;
2234 rtc_config.enable_rtp_data_channel = true;
2235 rtc_config.enable_dtls_srtp = false;
2236 CreatePeerConnection(rtc_config);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237
zhihuang9763d562016-08-05 11:14:50 -07002238 rtc::scoped_refptr<DataChannelInterface> offer_channel(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 pc_->CreateDataChannel("offer_channel", NULL));
2240
2241 CreateOfferAsLocalDescription();
2242
2243 // Create an answer where the m-line for data channels are rejected.
2244 std::string sdp;
2245 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002246 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Antona3a92c22017-12-07 10:27:41 -08002247 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002248 ASSERT_TRUE(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 cricket::ContentInfo* data_info =
Steve Anton36da6ff2018-02-16 16:04:20 -08002250 cricket::GetFirstDataContent(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 data_info->rejected = true;
2252
Steve Antondb45ca82017-09-11 18:27:34 -07002253 DoSetRemoteDescription(std::move(answer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2255}
2256
Zhi Huang644fde42018-04-02 19:16:26 -07002257#ifdef HAVE_SCTP
2258// This tests that SCTP data channels can be rejected in an answer.
2259TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2260#else
2261TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2262#endif
2263{
Niels Möllerf06f9232018-08-07 12:32:18 +02002264 RTCConfiguration rtc_config;
2265 CreatePeerConnection(rtc_config);
Zhi Huang644fde42018-04-02 19:16:26 -07002266
2267 rtc::scoped_refptr<DataChannelInterface> offer_channel(
2268 pc_->CreateDataChannel("offer_channel", NULL));
2269
2270 CreateOfferAsLocalDescription();
2271
2272 // Create an answer where the m-line for data channels are rejected.
2273 std::string sdp;
2274 EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2275 std::unique_ptr<SessionDescriptionInterface> answer(
2276 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2277 ASSERT_TRUE(answer);
2278 cricket::ContentInfo* data_info =
2279 cricket::GetFirstDataContent(answer->description());
2280 data_info->rejected = true;
2281
2282 DoSetRemoteDescription(std::move(answer));
2283 EXPECT_EQ(DataChannelInterface::kClosed, offer_channel->state());
2284}
2285
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286// Test that we can create a session description from an SDP string from
2287// FireFox, use it as a remote session description, generate an answer and use
2288// the answer as a local description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002289TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002290 RTCConfiguration rtc_config;
2291 rtc_config.enable_dtls_srtp = true;
2292 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002293 AddAudioTrack("audio_label");
2294 AddVideoTrack("video_label");
Steve Antondb45ca82017-09-11 18:27:34 -07002295 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002296 webrtc::CreateSessionDescription(SdpType::kOffer,
Steve Antondb45ca82017-09-11 18:27:34 -07002297 webrtc::kFireFoxSdpOffer, nullptr));
2298 EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299 CreateAnswerAsLocalDescription();
2300 ASSERT_TRUE(pc_->local_description() != NULL);
2301 ASSERT_TRUE(pc_->remote_description() != NULL);
2302
2303 const cricket::ContentInfo* content =
2304 cricket::GetFirstAudioContent(pc_->local_description()->description());
2305 ASSERT_TRUE(content != NULL);
2306 EXPECT_FALSE(content->rejected);
2307
2308 content =
2309 cricket::GetFirstVideoContent(pc_->local_description()->description());
2310 ASSERT_TRUE(content != NULL);
2311 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002312#ifdef HAVE_SCTP
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313 content =
2314 cricket::GetFirstDataContent(pc_->local_description()->description());
2315 ASSERT_TRUE(content != NULL);
Zhi Huange830e682018-03-30 10:48:35 -07002316 EXPECT_FALSE(content->rejected);
sergeyu@chromium.orga23f0ca2013-11-13 22:48:52 +00002317#endif
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318}
2319
zhihuangb19012e2017-09-19 13:47:59 -07002320// Test that fallback from DTLS to SDES is not supported.
2321// The fallback was previously supported but was removed to simplify the code
2322// and because it's non-standard.
Steve Anton36da6ff2018-02-16 16:04:20 -08002323TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002324 RTCConfiguration rtc_config;
2325 rtc_config.enable_dtls_srtp = true;
2326 CreatePeerConnection(rtc_config);
deadbeef8662f942017-01-20 21:20:51 -08002327 // Wait for fake certificate to be generated. Previously, this is what caused
2328 // the "a=crypto" lines to be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08002329 AddAudioTrack("audio_label");
2330 AddVideoTrack("video_label");
deadbeef8662f942017-01-20 21:20:51 -08002331 ASSERT_NE(nullptr, fake_certificate_generator_);
2332 EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2333 kTimeout);
Steve Antondb45ca82017-09-11 18:27:34 -07002334 std::unique_ptr<SessionDescriptionInterface> desc(
Steve Antona3a92c22017-12-07 10:27:41 -08002335 webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2336 nullptr));
Zhi Huange830e682018-03-30 10:48:35 -07002337 EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
deadbeef8662f942017-01-20 21:20:51 -08002338}
2339
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340// Test that we can create an audio only offer and receive an answer with a
2341// limited set of audio codecs and receive an updated offer with more audio
2342// codecs, where the added codecs are not supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002343TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
deadbeef293e9262017-01-11 12:28:30 -08002344 CreatePeerConnectionWithoutDtls();
Steve Anton36da6ff2018-02-16 16:04:20 -08002345 AddAudioTrack("audio_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346 CreateOfferAsLocalDescription();
2347
Steve Anton36da6ff2018-02-16 16:04:20 -08002348 const char* answer_sdp =
2349 (sdp_semantics_ == SdpSemantics::kPlanB ? webrtc::kAudioSdpPlanB
2350 : webrtc::kAudioSdpUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002351 std::unique_ptr<SessionDescriptionInterface> answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002352 webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002353 EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354
Steve Anton36da6ff2018-02-16 16:04:20 -08002355 const char* reoffer_sdp =
2356 (sdp_semantics_ == SdpSemantics::kPlanB
2357 ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2358 : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
Steve Antondb45ca82017-09-11 18:27:34 -07002359 std::unique_ptr<SessionDescriptionInterface> updated_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002360 webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07002361 EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 CreateAnswerAsLocalDescription();
2363}
2364
deadbeefc80741f2015-10-22 13:14:45 -07002365// Test that if we're receiving (but not sending) a track, subsequent offers
2366// will have m-lines with a=recvonly.
Steve Anton36da6ff2018-02-16 16:04:20 -08002367TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002368 RTCConfiguration rtc_config;
2369 rtc_config.enable_dtls_srtp = true;
2370 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002371 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002372 CreateAnswerAsLocalDescription();
2373
2374 // At this point we should be receiving stream 1, but not sending anything.
2375 // A new offer should be recvonly.
kwibergd1fe2812016-04-27 06:47:29 -07002376 std::unique_ptr<SessionDescriptionInterface> offer;
deadbeefc80741f2015-10-22 13:14:45 -07002377 DoCreateOffer(&offer, nullptr);
2378
2379 const cricket::ContentInfo* video_content =
2380 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002381 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2382 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002383
2384 const cricket::ContentInfo* audio_content =
2385 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002386 ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2387 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002388}
2389
2390// Test that if we're receiving (but not sending) a track, and the
2391// offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2392// false, the generated m-lines will be a=inactive.
Steve Anton36da6ff2018-02-16 16:04:20 -08002393TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002394 RTCConfiguration rtc_config;
2395 rtc_config.enable_dtls_srtp = true;
2396 CreatePeerConnection(rtc_config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002397 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefc80741f2015-10-22 13:14:45 -07002398 CreateAnswerAsLocalDescription();
2399
2400 // At this point we should be receiving stream 1, but not sending anything.
2401 // A new offer would be recvonly, but we'll set the "no receive" constraints
2402 // to make it inactive.
kwibergd1fe2812016-04-27 06:47:29 -07002403 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02002404 RTCOfferAnswerOptions options;
2405 options.offer_to_receive_audio = 0;
2406 options.offer_to_receive_video = 0;
2407 DoCreateOffer(&offer, &options);
deadbeefc80741f2015-10-22 13:14:45 -07002408
2409 const cricket::ContentInfo* video_content =
2410 cricket::GetFirstVideoContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002411 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2412 video_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002413
2414 const cricket::ContentInfo* audio_content =
2415 cricket::GetFirstAudioContent(offer->description());
Steve Antonb1c1de12017-12-21 15:14:30 -08002416 ASSERT_EQ(RtpTransceiverDirection::kInactive,
2417 audio_content->media_description()->direction());
deadbeefc80741f2015-10-22 13:14:45 -07002418}
2419
deadbeef653b8e02015-11-11 12:55:10 -08002420// Test that we can use SetConfiguration to change the ICE servers of the
2421// PortAllocator.
Steve Anton36da6ff2018-02-16 16:04:20 -08002422TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
deadbeef653b8e02015-11-11 12:55:10 -08002423 CreatePeerConnection();
2424
Steve Anton36da6ff2018-02-16 16:04:20 -08002425 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef653b8e02015-11-11 12:55:10 -08002426 PeerConnectionInterface::IceServer server;
2427 server.uri = "stun:test_hostname";
2428 config.servers.push_back(server);
2429 EXPECT_TRUE(pc_->SetConfiguration(config));
2430
Taylor Brandstetter0c7e9f52015-12-29 14:14:52 -08002431 EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2432 EXPECT_EQ("test_hostname",
2433 port_allocator_->stun_servers().begin()->hostname());
deadbeef653b8e02015-11-11 12:55:10 -08002434}
2435
Steve Anton36da6ff2018-02-16 16:04:20 -08002436TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002437 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002438 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002439 config.type = PeerConnectionInterface::kRelay;
2440 EXPECT_TRUE(pc_->SetConfiguration(config));
2441 EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2442}
2443
Steve Anton36da6ff2018-02-16 16:04:20 -08002444TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
deadbeef293e9262017-01-11 12:28:30 -08002445 PeerConnectionInterface::RTCConfiguration config;
2446 config.prune_turn_ports = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02002447 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002448 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002449 EXPECT_FALSE(port_allocator_->prune_turn_ports());
2450
2451 config.prune_turn_ports = true;
2452 EXPECT_TRUE(pc_->SetConfiguration(config));
2453 EXPECT_TRUE(port_allocator_->prune_turn_ports());
2454}
2455
skvladd1f5fda2017-02-03 16:54:05 -08002456// Test that the ice check interval can be changed. This does not verify that
2457// the setting makes it all the way to P2PTransportChannel, as that would
2458// require a very complex set of mocks.
Steve Anton36da6ff2018-02-16 16:04:20 -08002459TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
skvladd1f5fda2017-02-03 16:54:05 -08002460 PeerConnectionInterface::RTCConfiguration config;
Danil Chapovalov66cadcc2018-06-19 16:47:43 +02002461 config.ice_check_min_interval = absl::nullopt;
Niels Möllerf06f9232018-08-07 12:32:18 +02002462 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002463 config = pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002464 config.ice_check_min_interval = 100;
skvladd1f5fda2017-02-03 16:54:05 -08002465 EXPECT_TRUE(pc_->SetConfiguration(config));
2466 PeerConnectionInterface::RTCConfiguration new_config =
2467 pc_->GetConfiguration();
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01002468 EXPECT_EQ(new_config.ice_check_min_interval, 100);
skvladd1f5fda2017-02-03 16:54:05 -08002469}
2470
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002471// Test that when SetConfiguration changes both the pool size and other
2472// attributes, the pooled session is created with the updated attributes.
Steve Anton36da6ff2018-02-16 16:04:20 -08002473TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002474 SetConfigurationCreatesPooledSessionCorrectly) {
2475 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08002476 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002477 config.ice_candidate_pool_size = 1;
2478 PeerConnectionInterface::IceServer server;
2479 server.uri = kStunAddressOnly;
2480 config.servers.push_back(server);
2481 config.type = PeerConnectionInterface::kRelay;
Taylor Brandstetter417eebe2016-05-23 16:02:19 -07002482 EXPECT_TRUE(pc_->SetConfiguration(config));
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002483
2484 const cricket::FakePortAllocatorSession* session =
2485 static_cast<const cricket::FakePortAllocatorSession*>(
2486 port_allocator_->GetPooledSession());
2487 ASSERT_NE(nullptr, session);
2488 EXPECT_EQ(1UL, session->stun_servers().size());
Taylor Brandstettera1c30352016-05-13 08:15:11 -07002489}
2490
deadbeef293e9262017-01-11 12:28:30 -08002491// Test that after SetLocalDescription, changing the pool size is not allowed,
2492// and an invalid modification error is returned.
Steve Anton36da6ff2018-02-16 16:04:20 -08002493TEST_P(PeerConnectionInterfaceTest,
deadbeef6de92f92016-12-12 18:49:32 -08002494 CantChangePoolSizeAfterSetLocalDescription) {
2495 CreatePeerConnection();
2496 // Start by setting a size of 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08002497 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef6de92f92016-12-12 18:49:32 -08002498 config.ice_candidate_pool_size = 1;
2499 EXPECT_TRUE(pc_->SetConfiguration(config));
2500
2501 // Set remote offer; can still change pool size at this point.
2502 CreateOfferAsRemoteDescription();
2503 config.ice_candidate_pool_size = 2;
2504 EXPECT_TRUE(pc_->SetConfiguration(config));
2505
2506 // Set local answer; now it's too late.
2507 CreateAnswerAsLocalDescription();
2508 config.ice_candidate_pool_size = 3;
deadbeef293e9262017-01-11 12:28:30 -08002509 RTCError error;
2510 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2511 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2512}
2513
deadbeef42a42632017-03-10 15:18:00 -08002514// Test that after setting an answer, extra pooled sessions are discarded. The
2515// ICE candidate pool is only intended to be used for the first offer/answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002516TEST_P(PeerConnectionInterfaceTest,
deadbeef42a42632017-03-10 15:18:00 -08002517 ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2518 CreatePeerConnection();
2519
2520 // Set a larger-than-necessary size.
Steve Anton36da6ff2018-02-16 16:04:20 -08002521 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002522 config.ice_candidate_pool_size = 4;
2523 EXPECT_TRUE(pc_->SetConfiguration(config));
2524
2525 // Do offer/answer.
2526 CreateOfferAsRemoteDescription();
2527 CreateAnswerAsLocalDescription();
2528
2529 // Expect no pooled sessions to be left.
2530 const cricket::PortAllocatorSession* session =
2531 port_allocator_->GetPooledSession();
2532 EXPECT_EQ(nullptr, session);
2533}
2534
2535// After Close is called, pooled candidates should be discarded so as to not
2536// waste network resources.
Steve Anton36da6ff2018-02-16 16:04:20 -08002537TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
deadbeef42a42632017-03-10 15:18:00 -08002538 CreatePeerConnection();
2539
Steve Anton36da6ff2018-02-16 16:04:20 -08002540 PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
deadbeef42a42632017-03-10 15:18:00 -08002541 config.ice_candidate_pool_size = 3;
2542 EXPECT_TRUE(pc_->SetConfiguration(config));
2543 pc_->Close();
2544
2545 // Expect no pooled sessions to be left.
2546 const cricket::PortAllocatorSession* session =
2547 port_allocator_->GetPooledSession();
2548 EXPECT_EQ(nullptr, session);
2549}
2550
deadbeef293e9262017-01-11 12:28:30 -08002551// Test that SetConfiguration returns an invalid modification error if
2552// modifying a field in the configuration that isn't allowed to be modified.
Steve Anton36da6ff2018-02-16 16:04:20 -08002553TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002554 SetConfigurationReturnsInvalidModificationError) {
2555 PeerConnectionInterface::RTCConfiguration config;
2556 config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2557 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2558 config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
Niels Möllerf06f9232018-08-07 12:32:18 +02002559 CreatePeerConnection(config);
deadbeef293e9262017-01-11 12:28:30 -08002560
Steve Anton36da6ff2018-02-16 16:04:20 -08002561 PeerConnectionInterface::RTCConfiguration modified_config =
2562 pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002563 modified_config.bundle_policy =
2564 PeerConnectionInterface::kBundlePolicyMaxBundle;
2565 RTCError error;
2566 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2567 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2568
Steve Anton36da6ff2018-02-16 16:04:20 -08002569 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002570 modified_config.rtcp_mux_policy =
2571 PeerConnectionInterface::kRtcpMuxPolicyRequire;
2572 error.set_type(RTCErrorType::NONE);
2573 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2574 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2575
Steve Anton36da6ff2018-02-16 16:04:20 -08002576 modified_config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002577 modified_config.continual_gathering_policy =
2578 PeerConnectionInterface::GATHER_CONTINUALLY;
2579 error.set_type(RTCErrorType::NONE);
2580 EXPECT_FALSE(pc_->SetConfiguration(modified_config, &error));
2581 EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2582}
2583
2584// Test that SetConfiguration returns a range error if the candidate pool size
2585// is negative or larger than allowed by the spec.
Steve Anton36da6ff2018-02-16 16:04:20 -08002586TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002587 SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2588 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002589 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002590 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002591
2592 config.ice_candidate_pool_size = -1;
2593 RTCError error;
2594 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2595 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2596
2597 config.ice_candidate_pool_size = INT_MAX;
2598 error.set_type(RTCErrorType::NONE);
2599 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2600 EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2601}
2602
2603// Test that SetConfiguration returns a syntax error if parsing an ICE server
2604// URL failed.
Steve Anton36da6ff2018-02-16 16:04:20 -08002605TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002606 SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2607 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002608 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002609 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002610
2611 PeerConnectionInterface::IceServer bad_server;
2612 bad_server.uri = "stunn:www.example.com";
2613 config.servers.push_back(bad_server);
2614 RTCError error;
2615 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2616 EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2617}
2618
2619// Test that SetConfiguration returns an invalid parameter error if a TURN
2620// IceServer is missing a username or password.
Steve Anton36da6ff2018-02-16 16:04:20 -08002621TEST_P(PeerConnectionInterfaceTest,
deadbeef293e9262017-01-11 12:28:30 -08002622 SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2623 PeerConnectionInterface::RTCConfiguration config;
Niels Möllerf06f9232018-08-07 12:32:18 +02002624 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002625 config = pc_->GetConfiguration();
deadbeef293e9262017-01-11 12:28:30 -08002626
2627 PeerConnectionInterface::IceServer bad_server;
2628 bad_server.uri = "turn:www.example.com";
2629 // Missing password.
2630 bad_server.username = "foo";
2631 config.servers.push_back(bad_server);
2632 RTCError error;
2633 EXPECT_FALSE(pc_->SetConfiguration(config, &error));
2634 EXPECT_EQ(RTCErrorType::INVALID_PARAMETER, error.type());
deadbeef6de92f92016-12-12 18:49:32 -08002635}
2636
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637// Test that PeerConnection::Close changes the states to closed and all remote
2638// tracks change state to ended.
Steve Anton36da6ff2018-02-16 16:04:20 -08002639TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002640 // Initialize a PeerConnection and negotiate local and remote session
2641 // description.
2642 InitiateCall();
Steve Anton36da6ff2018-02-16 16:04:20 -08002643
2644 // With Plan B, verify the stream count. The analog with Unified Plan is the
2645 // RtpTransceiver count.
2646 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2647 ASSERT_EQ(1u, pc_->local_streams()->count());
2648 ASSERT_EQ(1u, pc_->remote_streams()->count());
2649 } else {
2650 ASSERT_EQ(2u, pc_->GetTransceivers().size());
2651 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652
2653 pc_->Close();
2654
2655 EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2656 EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2657 pc_->ice_connection_state());
2658 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2659 pc_->ice_gathering_state());
2660
Steve Anton36da6ff2018-02-16 16:04:20 -08002661 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2662 EXPECT_EQ(1u, pc_->local_streams()->count());
2663 EXPECT_EQ(1u, pc_->remote_streams()->count());
2664 } else {
2665 // Verify that the RtpTransceivers are still present but all stopped.
2666 EXPECT_EQ(2u, pc_->GetTransceivers().size());
Mirko Bonadei739baf02019-01-27 17:29:42 +01002667 for (const auto& transceiver : pc_->GetTransceivers()) {
Steve Anton36da6ff2018-02-16 16:04:20 -08002668 EXPECT_TRUE(transceiver->stopped());
2669 }
2670 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671
Steve Anton36da6ff2018-02-16 16:04:20 -08002672 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2673 ASSERT_TRUE(audio_receiver);
2674 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2675 ASSERT_TRUE(video_receiver);
2676
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002677 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002678 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002679 audio_receiver->track()->state(), kTimeout);
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002680 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
Steve Anton36da6ff2018-02-16 16:04:20 -08002681 video_receiver->track()->state(), kTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682}
2683
2684// Test that PeerConnection methods fails gracefully after
2685// PeerConnection::Close has been called.
Steve Anton36da6ff2018-02-16 16:04:20 -08002686// Don't run under Unified Plan since the stream API is not available.
2687TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
deadbeef293e9262017-01-11 12:28:30 -08002688 CreatePeerConnectionWithoutDtls();
Seth Hampson845e8782018-03-02 11:34:10 -08002689 AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690 CreateOfferAsRemoteDescription();
2691 CreateAnswerAsLocalDescription();
2692
2693 ASSERT_EQ(1u, pc_->local_streams()->count());
zhihuang9763d562016-08-05 11:14:50 -07002694 rtc::scoped_refptr<MediaStreamInterface> local_stream =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002695 pc_->local_streams()->at(0);
2696
2697 pc_->Close();
2698
2699 pc_->RemoveStream(local_stream);
perkj@webrtc.orgc2dd5ee2014-11-04 11:31:29 +00002700 EXPECT_FALSE(pc_->AddStream(local_stream));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002702 EXPECT_TRUE(pc_->CreateDataChannel("test", NULL) == NULL);
2703
2704 EXPECT_TRUE(pc_->local_description() != NULL);
2705 EXPECT_TRUE(pc_->remote_description() != NULL);
2706
kwibergd1fe2812016-04-27 06:47:29 -07002707 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002708 EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
kwibergd1fe2812016-04-27 06:47:29 -07002709 std::unique_ptr<SessionDescriptionInterface> answer;
Steve Anton8d3444d2017-10-20 15:30:51 -07002710 EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711
2712 std::string sdp;
2713 ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002714 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002715 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002716 EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717
2718 ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002719 std::unique_ptr<SessionDescriptionInterface> local_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08002720 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07002721 EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002722}
2723
2724// Test that GetStats can still be called after PeerConnection::Close.
Steve Anton36da6ff2018-02-16 16:04:20 -08002725TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002726 InitiateCall();
2727 pc_->Close();
2728 DoGetStats(NULL);
2729}
deadbeefab9b2d12015-10-14 11:33:11 -07002730
2731// NOTE: The series of tests below come from what used to be
2732// mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2733// setting a remote or local description has the expected effects.
2734
2735// This test verifies that the remote MediaStreams corresponding to a received
2736// SDP string is created. In this test the two separate MediaStreams are
2737// signaled.
Steve Anton36da6ff2018-02-16 16:04:20 -08002738TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002739 RTCConfiguration config;
2740 config.enable_dtls_srtp = true;
2741 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002742 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002743
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002744 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002745 EXPECT_TRUE(
2746 CompareStreamCollections(observer_.remote_streams(), reference.get()));
2747 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2748 EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2749
2750 // Create a session description based on another SDP with another
2751 // MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002752 CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
deadbeefab9b2d12015-10-14 11:33:11 -07002753
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07002754 rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07002755 EXPECT_TRUE(
2756 CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2757}
2758
2759// This test verifies that when remote tracks are added/removed from SDP, the
2760// created remote streams are updated appropriately.
Steve Anton36da6ff2018-02-16 16:04:20 -08002761// Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2762// specific behavior.
2763TEST_F(PeerConnectionInterfaceTestPlanB,
deadbeefab9b2d12015-10-14 11:33:11 -07002764 AddRemoveTrackFromExistingRemoteMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002765 RTCConfiguration config;
2766 config.enable_dtls_srtp = true;
2767 CreatePeerConnection(config);
kwibergd1fe2812016-04-27 06:47:29 -07002768 std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
kwiberg2bbff992016-03-16 11:03:04 -07002769 CreateSessionDescriptionAndReference(1, 1);
Steve Antondb45ca82017-09-11 18:27:34 -07002770 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
deadbeefab9b2d12015-10-14 11:33:11 -07002771 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2772 reference_collection_));
2773
2774 // Add extra audio and video tracks to the same MediaStream.
kwibergd1fe2812016-04-27 06:47:29 -07002775 std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
kwiberg2bbff992016-03-16 11:03:04 -07002776 CreateSessionDescriptionAndReference(2, 2);
Steve Antondb45ca82017-09-11 18:27:34 -07002777 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
deadbeefab9b2d12015-10-14 11:33:11 -07002778 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2779 reference_collection_));
zhihuang9763d562016-08-05 11:14:50 -07002780 rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
perkjd61bf802016-03-24 03:16:19 -07002781 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2782 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
zhihuang9763d562016-08-05 11:14:50 -07002783 rtc::scoped_refptr<VideoTrackInterface> video_track2 =
perkjd61bf802016-03-24 03:16:19 -07002784 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2785 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002786
2787 // Remove the extra audio and video tracks.
kwibergd1fe2812016-04-27 06:47:29 -07002788 std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
kwiberg2bbff992016-03-16 11:03:04 -07002789 CreateSessionDescriptionAndReference(1, 1);
perkjd61bf802016-03-24 03:16:19 -07002790 MockTrackObserver audio_track_observer(audio_track2);
2791 MockTrackObserver video_track_observer(video_track2);
2792
2793 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2794 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
Steve Antondb45ca82017-09-11 18:27:34 -07002795 EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
deadbeefab9b2d12015-10-14 11:33:11 -07002796 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2797 reference_collection_));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002798 // Track state may be updated asynchronously.
perkjd61bf802016-03-24 03:16:19 -07002799 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002800 audio_track2->state(), kTimeout);
2801 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2802 video_track2->state(), kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002803}
2804
2805// This tests that remote tracks are ended if a local session description is set
2806// that rejects the media content type.
Steve Anton36da6ff2018-02-16 16:04:20 -08002807TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002808 RTCConfiguration config;
2809 config.enable_dtls_srtp = true;
2810 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002811 // First create and set a remote offer, then reject its video content in our
2812 // answer.
Steve Anton36da6ff2018-02-16 16:04:20 -08002813 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2814 auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2815 ASSERT_TRUE(audio_receiver);
2816 auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2817 ASSERT_TRUE(video_receiver);
deadbeefab9b2d12015-10-14 11:33:11 -07002818
Steve Anton36da6ff2018-02-16 16:04:20 -08002819 rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2820 audio_receiver->track();
deadbeefab9b2d12015-10-14 11:33:11 -07002821 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
Steve Anton36da6ff2018-02-16 16:04:20 -08002822 rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2823 video_receiver->track();
2824 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002825
kwibergd1fe2812016-04-27 06:47:29 -07002826 std::unique_ptr<SessionDescriptionInterface> local_answer;
kwiberg2bbff992016-03-16 11:03:04 -07002827 EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002828 cricket::ContentInfo* video_info =
2829 local_answer->description()->GetContentByName("video");
2830 video_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002831 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
Steve Anton36da6ff2018-02-16 16:04:20 -08002832 EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2833 EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002834
2835 // Now create an offer where we reject both video and audio.
kwibergd1fe2812016-04-27 06:47:29 -07002836 std::unique_ptr<SessionDescriptionInterface> local_offer;
kwiberg2bbff992016-03-16 11:03:04 -07002837 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002838 video_info = local_offer->description()->GetContentByName("video");
2839 ASSERT_TRUE(video_info != nullptr);
2840 video_info->rejected = true;
2841 cricket::ContentInfo* audio_info =
2842 local_offer->description()->GetContentByName("audio");
2843 ASSERT_TRUE(audio_info != nullptr);
2844 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002845 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
Taylor Brandstetterd45b95c2016-03-29 13:16:52 -07002846 // Track state may be updated asynchronously.
Steve Anton36da6ff2018-02-16 16:04:20 -08002847 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2848 kTimeout);
2849 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2850 kTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002851}
2852
2853// This tests that we won't crash if the remote track has been removed outside
2854// of PeerConnection and then PeerConnection tries to reject the track.
Steve Anton36da6ff2018-02-16 16:04:20 -08002855// Don't run under Unified Plan since the stream API is not available.
2856TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002857 RTCConfiguration config;
2858 config.enable_dtls_srtp = true;
2859 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002860 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002861 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2862 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2863 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2864
kwibergd1fe2812016-04-27 06:47:29 -07002865 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Anton36da6ff2018-02-16 16:04:20 -08002866 webrtc::CreateSessionDescription(SdpType::kAnswer,
2867 GetSdpStringWithStream1(), nullptr));
deadbeefab9b2d12015-10-14 11:33:11 -07002868 cricket::ContentInfo* video_info =
2869 local_answer->description()->GetContentByName("video");
2870 video_info->rejected = true;
2871 cricket::ContentInfo* audio_info =
2872 local_answer->description()->GetContentByName("audio");
2873 audio_info->rejected = true;
Steve Antondb45ca82017-09-11 18:27:34 -07002874 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeefab9b2d12015-10-14 11:33:11 -07002875
2876 // No crash is a pass.
2877}
2878
deadbeef5e97fb52015-10-15 12:49:08 -07002879// This tests that if a recvonly remote description is set, no remote streams
2880// will be created, even if the description contains SSRCs/MSIDs.
2881// See: https://code.google.com/p/webrtc/issues/detail?id=5054
Steve Anton36da6ff2018-02-16 16:04:20 -08002882TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002883 RTCConfiguration config;
2884 config.enable_dtls_srtp = true;
2885 CreatePeerConnection(config);
deadbeef5e97fb52015-10-15 12:49:08 -07002886
Steve Anton36da6ff2018-02-16 16:04:20 -08002887 std::string recvonly_offer = GetSdpStringWithStream1();
deadbeef5e97fb52015-10-15 12:49:08 -07002888 rtc::replace_substrs(kSendrecv, strlen(kSendrecv), kRecvonly,
2889 strlen(kRecvonly), &recvonly_offer);
2890 CreateAndSetRemoteOffer(recvonly_offer);
2891
2892 EXPECT_EQ(0u, observer_.remote_streams()->count());
2893}
2894
deadbeefab9b2d12015-10-14 11:33:11 -07002895// This tests that a default MediaStream is created if a remote session
2896// description doesn't contain any streams and no MSID support.
2897// It also tests that the default stream is updated if a video m-line is added
2898// in a subsequent session description.
Steve Anton36da6ff2018-02-16 16:04:20 -08002899// Don't run under Unified Plan since this behavior is Plan B specific.
2900TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002901 RTCConfiguration config;
2902 config.enable_dtls_srtp = true;
2903 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002904 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2905
2906 ASSERT_EQ(1u, observer_.remote_streams()->count());
2907 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2908
2909 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2910 EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002911 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002912
2913 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2914 ASSERT_EQ(1u, observer_.remote_streams()->count());
2915 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2916 EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002917 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2918 remote_stream->GetAudioTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002919 ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2920 EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
deadbeef884f5852016-01-15 09:20:04 -08002921 EXPECT_EQ(MediaStreamTrackInterface::kLive,
2922 remote_stream->GetVideoTracks()[0]->state());
deadbeefab9b2d12015-10-14 11:33:11 -07002923}
2924
2925// This tests that a default MediaStream is created if a remote session
2926// description doesn't contain any streams and media direction is send only.
Steve Anton36da6ff2018-02-16 16:04:20 -08002927// Don't run under Unified Plan since this behavior is Plan B specific.
2928TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002929 SendOnlySdpWithoutMsidCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002930 RTCConfiguration config;
2931 config.enable_dtls_srtp = true;
2932 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002933 CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2934
2935 ASSERT_EQ(1u, observer_.remote_streams()->count());
2936 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2937
2938 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2939 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
Seth Hampson13b8bad2018-03-13 16:05:28 -07002940 EXPECT_EQ("default", remote_stream->id());
deadbeefab9b2d12015-10-14 11:33:11 -07002941}
2942
2943// This tests that it won't crash when PeerConnection tries to remove
2944// a remote track that as already been removed from the MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08002945// Don't run under Unified Plan since this behavior is Plan B specific.
2946TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002947 RTCConfiguration config;
2948 config.enable_dtls_srtp = true;
2949 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08002950 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
deadbeefab9b2d12015-10-14 11:33:11 -07002951 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2952 remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2953 remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2954
2955 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2956
2957 // No crash is a pass.
2958}
2959
2960// This tests that a default MediaStream is created if the remote session
2961// description doesn't contain any streams and don't contain an indication if
2962// MSID is supported.
Steve Anton36da6ff2018-02-16 16:04:20 -08002963// Don't run under Unified Plan since this behavior is Plan B specific.
2964TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002965 SdpWithoutMsidAndStreamsCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002966 RTCConfiguration config;
2967 config.enable_dtls_srtp = true;
2968 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002969 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2970
2971 ASSERT_EQ(1u, observer_.remote_streams()->count());
2972 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2973 EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2974 EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2975}
2976
2977// This tests that a default MediaStream is not created if the remote session
2978// description doesn't contain any streams but does support MSID.
Steve Anton36da6ff2018-02-16 16:04:20 -08002979// Don't run under Unified Plan since this behavior is Plan B specific.
2980TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002981 RTCConfiguration config;
2982 config.enable_dtls_srtp = true;
2983 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002984 CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2985 EXPECT_EQ(0u, observer_.remote_streams()->count());
2986}
2987
deadbeefbda7e0b2015-12-08 17:13:40 -08002988// This tests that when setting a new description, the old default tracks are
2989// not destroyed and recreated.
2990// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
Steve Anton36da6ff2018-02-16 16:04:20 -08002991// Don't run under Unified Plan since this behavior is Plan B specific.
2992TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07002993 DefaultTracksNotDestroyedAndRecreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02002994 RTCConfiguration config;
2995 config.enable_dtls_srtp = true;
2996 CreatePeerConnection(config);
deadbeefbda7e0b2015-12-08 17:13:40 -08002997 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2998
2999 ASSERT_EQ(1u, observer_.remote_streams()->count());
3000 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3001 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3002
3003 // Set the track to "disabled", then set a new description and ensure the
3004 // track is still disabled, which ensures it hasn't been recreated.
3005 remote_stream->GetAudioTracks()[0]->set_enabled(false);
3006 CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
3007 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3008 EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
3009}
3010
deadbeefab9b2d12015-10-14 11:33:11 -07003011// This tests that a default MediaStream is not created if a remote session
3012// description is updated to not have any MediaStreams.
Steve Anton36da6ff2018-02-16 16:04:20 -08003013// Don't run under Unified Plan since this behavior is Plan B specific.
3014TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003015 RTCConfiguration config;
3016 config.enable_dtls_srtp = true;
3017 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003018 CreateAndSetRemoteOffer(GetSdpStringWithStream1());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003019 rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
deadbeefab9b2d12015-10-14 11:33:11 -07003020 EXPECT_TRUE(
3021 CompareStreamCollections(observer_.remote_streams(), reference.get()));
3022
3023 CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
3024 EXPECT_EQ(0u, observer_.remote_streams()->count());
3025}
3026
Seth Hampson5897a6e2018-04-03 11:16:33 -07003027// This tests that a default MediaStream is created if a remote SDP comes from
3028// an endpoint that doesn't signal SSRCs, but signals media stream IDs.
3029TEST_F(PeerConnectionInterfaceTestPlanB,
3030 SdpWithMsidWithoutSsrcCreatesDefaultStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003031 RTCConfiguration config;
3032 config.enable_dtls_srtp = true;
3033 CreatePeerConnection(config);
Seth Hampson5897a6e2018-04-03 11:16:33 -07003034 std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
3035 // Add a=msid lines to simulate a Unified Plan endpoint that only
3036 // signals stream IDs with a=msid lines.
3037 sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
3038
3039 CreateAndSetRemoteOffer(sdp_string);
3040
3041 ASSERT_EQ(1u, observer_.remote_streams()->count());
3042 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3043 EXPECT_EQ("default", remote_stream->id());
3044 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
3045}
3046
Seth Hampson5b4f0752018-04-02 16:31:36 -07003047// This tests that when a Plan B endpoint receives an SDP that signals no media
3048// stream IDs indicated by the special character "-" in the a=msid line, that
3049// a default stream ID will be used for the MediaStream ID. This can occur
3050// when a Unified Plan endpoint signals no media stream IDs, but signals both
3051// a=ssrc msid and a=msid lines for interop signaling with Plan B.
3052TEST_F(PeerConnectionInterfaceTestPlanB,
3053 SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003054 RTCConfiguration config;
3055 config.enable_dtls_srtp = true;
3056 CreatePeerConnection(config);
Seth Hampson5b4f0752018-04-02 16:31:36 -07003057 // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
3058 // the sender's stream ID will be interpreted as no stream IDs.
3059 std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
3060 sdp_string.append("a=msid:- audiotrack0\n");
3061
3062 CreateAndSetRemoteOffer(sdp_string);
3063
3064 ASSERT_EQ(1u, observer_.remote_streams()->count());
3065 // Because SSRCs are signaled the track ID will be what was signaled in the
3066 // a=msid line.
3067 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3068 MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
3069 EXPECT_EQ("default", remote_stream->id());
3070 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson83d676b2018-04-05 18:12:09 -07003071
3072 // Previously a bug ocurred when setting the remote description a second time.
3073 // This is because we checked equality of the remote StreamParams stream ID
3074 // (empty), and the previously set stream ID for the remote sender
3075 // ("default"). This cause a track to be removed, then added, when really
3076 // nothing should occur because it is the same track.
3077 CreateAndSetRemoteOffer(sdp_string);
3078 EXPECT_EQ(0u, observer_.remove_track_events_.size());
3079 EXPECT_EQ(1u, observer_.add_track_events_.size());
3080 EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
3081 remote_stream = observer_.remote_streams()->at(0);
3082 EXPECT_EQ("default", remote_stream->id());
3083 ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
Seth Hampson5b4f0752018-04-02 16:31:36 -07003084}
3085
deadbeefab9b2d12015-10-14 11:33:11 -07003086// This tests that an RtpSender is created when the local description is set
3087// after adding a local stream.
3088// TODO(deadbeef): This test and the one below it need to be updated when
3089// an RtpSender's lifetime isn't determined by when a local description is set.
Steve Anton36da6ff2018-02-16 16:04:20 -08003090// Don't run under Unified Plan since this behavior is Plan B specific.
3091TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003092 RTCConfiguration config;
3093 config.enable_dtls_srtp = true;
3094 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003095
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003096 // Create an offer with 1 stream with 2 tracks of each type.
3097 rtc::scoped_refptr<StreamCollection> stream_collection =
3098 CreateStreamCollection(1, 2);
3099 pc_->AddStream(stream_collection->at(0));
3100 std::unique_ptr<SessionDescriptionInterface> offer;
3101 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003102 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003103
deadbeefab9b2d12015-10-14 11:33:11 -07003104 auto senders = pc_->GetSenders();
3105 EXPECT_EQ(4u, senders.size());
3106 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3107 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3108 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3109 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3110
3111 // Remove an audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003112 pc_->RemoveStream(stream_collection->at(0));
3113 stream_collection = CreateStreamCollection(1, 1);
3114 pc_->AddStream(stream_collection->at(0));
3115 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003116 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003117
deadbeefab9b2d12015-10-14 11:33:11 -07003118 senders = pc_->GetSenders();
3119 EXPECT_EQ(2u, senders.size());
3120 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3121 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3122 EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
3123 EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
3124}
3125
3126// This tests that an RtpSender is created when the local description is set
3127// before adding a local stream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003128// Don't run under Unified Plan since this behavior is Plan B specific.
3129TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003130 AddLocalStreamAfterLocalDescriptionChanged) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003131 RTCConfiguration config;
3132 config.enable_dtls_srtp = true;
3133 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003134
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003135 rtc::scoped_refptr<StreamCollection> stream_collection =
3136 CreateStreamCollection(1, 2);
3137 // Add a stream to create the offer, but remove it afterwards.
3138 pc_->AddStream(stream_collection->at(0));
3139 std::unique_ptr<SessionDescriptionInterface> offer;
3140 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3141 pc_->RemoveStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003142
Steve Antondb45ca82017-09-11 18:27:34 -07003143 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003144 auto senders = pc_->GetSenders();
3145 EXPECT_EQ(0u, senders.size());
3146
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003147 pc_->AddStream(stream_collection->at(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003148 senders = pc_->GetSenders();
3149 EXPECT_EQ(4u, senders.size());
3150 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3151 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3152 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
3153 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
3154}
3155
3156// This tests that the expected behavior occurs if the SSRC on a local track is
3157// changed when SetLocalDescription is called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003158TEST_P(PeerConnectionInterfaceTest,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003159 ChangeSsrcOnTrackInLocalSessionDescription) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003160 RTCConfiguration config;
3161 config.enable_dtls_srtp = true;
3162 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003163
Steve Anton36da6ff2018-02-16 16:04:20 -08003164 AddAudioTrack(kAudioTracks[0]);
3165 AddVideoTrack(kVideoTracks[0]);
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003166 std::unique_ptr<SessionDescriptionInterface> offer;
3167 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3168 // Grab a copy of the offer before it gets passed into the PC.
Steve Antond9e4a062018-07-24 18:23:33 -07003169 std::unique_ptr<SessionDescriptionInterface> modified_offer =
3170 webrtc::CreateSessionDescription(
3171 webrtc::SdpType::kOffer, offer->session_id(),
3172 offer->session_version(),
3173 absl::WrapUnique(offer->description()->Copy()));
Steve Antondb45ca82017-09-11 18:27:34 -07003174 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003175
deadbeefab9b2d12015-10-14 11:33:11 -07003176 auto senders = pc_->GetSenders();
3177 EXPECT_EQ(2u, senders.size());
3178 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3179 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3180
3181 // Change the ssrc of the audio and video track.
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003182 cricket::MediaContentDescription* desc =
3183 cricket::GetFirstAudioContentDescription(modified_offer->description());
3184 ASSERT_TRUE(desc != NULL);
3185 for (StreamParams& stream : desc->mutable_streams()) {
3186 for (unsigned int& ssrc : stream.ssrcs) {
3187 ++ssrc;
3188 }
3189 }
deadbeefab9b2d12015-10-14 11:33:11 -07003190
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003191 desc =
3192 cricket::GetFirstVideoContentDescription(modified_offer->description());
3193 ASSERT_TRUE(desc != NULL);
3194 for (StreamParams& stream : desc->mutable_streams()) {
3195 for (unsigned int& ssrc : stream.ssrcs) {
3196 ++ssrc;
3197 }
3198 }
3199
Steve Antondb45ca82017-09-11 18:27:34 -07003200 EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003201 senders = pc_->GetSenders();
3202 EXPECT_EQ(2u, senders.size());
3203 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
3204 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
3205 // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
3206 // changed.
3207}
3208
3209// This tests that the expected behavior occurs if a new session description is
3210// set with the same tracks, but on a different MediaStream.
Steve Anton36da6ff2018-02-16 16:04:20 -08003211// Don't run under Unified Plan since the stream API is not available.
3212TEST_F(PeerConnectionInterfaceTestPlanB,
Taylor Brandstetter7ff17372016-04-01 11:50:39 -07003213 SignalSameTracksInSeparateMediaStream) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003214 RTCConfiguration config;
3215 config.enable_dtls_srtp = true;
3216 CreatePeerConnection(config);
deadbeefab9b2d12015-10-14 11:33:11 -07003217
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003218 rtc::scoped_refptr<StreamCollection> stream_collection =
3219 CreateStreamCollection(2, 1);
3220 pc_->AddStream(stream_collection->at(0));
3221 std::unique_ptr<SessionDescriptionInterface> offer;
3222 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003223 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003224
deadbeefab9b2d12015-10-14 11:33:11 -07003225 auto senders = pc_->GetSenders();
3226 EXPECT_EQ(2u, senders.size());
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003227 EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3228 EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
deadbeefab9b2d12015-10-14 11:33:11 -07003229
3230 // Add a new MediaStream but with the same tracks as in the first stream.
3231 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3232 webrtc::MediaStream::Create(kStreams[1]));
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003233 stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3234 stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
deadbeefab9b2d12015-10-14 11:33:11 -07003235 pc_->AddStream(stream_1);
3236
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003237 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003238 EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
deadbeefab9b2d12015-10-14 11:33:11 -07003239
Taylor Brandstetterdc4eb8c2016-05-12 08:14:50 -07003240 auto new_senders = pc_->GetSenders();
3241 // Should be the same senders as before, but with updated stream id.
3242 // Note that this behavior is subject to change in the future.
3243 // We may decide the PC should ignore existing tracks in AddStream.
3244 EXPECT_EQ(senders, new_senders);
3245 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3246 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
deadbeefab9b2d12015-10-14 11:33:11 -07003247}
3248
zhihuang81c3a032016-11-17 12:06:24 -08003249// This tests that PeerConnectionObserver::OnAddTrack is correctly called.
Steve Anton36da6ff2018-02-16 16:04:20 -08003250TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
Niels Möllerf06f9232018-08-07 12:32:18 +02003251 RTCConfiguration config;
3252 config.enable_dtls_srtp = true;
3253 CreatePeerConnection(config);
zhihuang81c3a032016-11-17 12:06:24 -08003254 CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3255 EXPECT_EQ(observer_.num_added_tracks_, 1);
3256 EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3257
3258 // Create and set the updated remote SDP.
Steve Anton36da6ff2018-02-16 16:04:20 -08003259 CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
Steve Anton0f5400a2018-07-17 14:25:36 -07003260 EXPECT_EQ(observer_.num_added_tracks_, 2);
zhihuang81c3a032016-11-17 12:06:24 -08003261 EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3262}
3263
deadbeefd1a38b52016-12-10 13:15:33 -08003264// Test that when SetConfiguration is called and the configuration is
3265// changing, the next offer causes an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003266TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003267 PeerConnectionInterface::RTCConfiguration config;
3268 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003269 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003270 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003271 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3272 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003273
3274 // Do initial offer/answer so there's something to restart.
3275 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003276 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003277
3278 // Grab the ufrags.
3279 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3280
3281 // Change ICE policy, which should trigger an ICE restart on the next offer.
3282 config.type = PeerConnectionInterface::kAll;
3283 EXPECT_TRUE(pc_->SetConfiguration(config));
3284 CreateOfferAsLocalDescription();
3285
3286 // Grab the new ufrags.
3287 std::vector<std::string> subsequent_ufrags =
3288 GetUfrags(pc_->local_description());
3289
3290 // Sanity check.
3291 EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3292 // Check that each ufrag is different.
3293 for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3294 EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3295 }
3296}
3297
3298// Test that when SetConfiguration is called and the configuration *isn't*
3299// changing, the next offer does *not* cause an ICE restart.
Steve Anton36da6ff2018-02-16 16:04:20 -08003300TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003301 PeerConnectionInterface::RTCConfiguration config;
3302 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003303 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003304 config = pc_->GetConfiguration();
3305 AddAudioTrack(kAudioTracks[0]);
3306 AddVideoTrack(kVideoTracks[0]);
deadbeefd1a38b52016-12-10 13:15:33 -08003307
3308 // Do initial offer/answer so there's something to restart.
3309 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003310 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003311
3312 // Grab the ufrags.
3313 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3314
3315 // Call SetConfiguration with a config identical to what the PC was
3316 // constructed with.
3317 EXPECT_TRUE(pc_->SetConfiguration(config));
3318 CreateOfferAsLocalDescription();
3319
3320 // Grab the new ufrags.
3321 std::vector<std::string> subsequent_ufrags =
3322 GetUfrags(pc_->local_description());
3323
3324 EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3325}
3326
3327// Test for a weird corner case scenario:
3328// 1. Audio/video session established.
3329// 2. SetConfiguration changes ICE config; ICE restart needed.
3330// 3. ICE restart initiated by remote peer, but only for one m= section.
3331// 4. Next createOffer should initiate an ICE restart, but only for the other
3332// m= section; it would be pointless to do an ICE restart for the m= section
3333// that was already restarted.
Steve Anton36da6ff2018-02-16 16:04:20 -08003334TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
deadbeefd1a38b52016-12-10 13:15:33 -08003335 PeerConnectionInterface::RTCConfiguration config;
3336 config.type = PeerConnectionInterface::kRelay;
Niels Möllerf06f9232018-08-07 12:32:18 +02003337 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003338 config = pc_->GetConfiguration();
Seth Hampson845e8782018-03-02 11:34:10 -08003339 AddAudioTrack(kAudioTracks[0], {kStreamId1});
3340 AddVideoTrack(kVideoTracks[0], {kStreamId1});
deadbeefd1a38b52016-12-10 13:15:33 -08003341
3342 // Do initial offer/answer so there's something to restart.
3343 CreateOfferAsLocalDescription();
Steve Anton36da6ff2018-02-16 16:04:20 -08003344 CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
deadbeefd1a38b52016-12-10 13:15:33 -08003345
3346 // Change ICE policy, which should set the "needs-ice-restart" flag.
3347 config.type = PeerConnectionInterface::kAll;
3348 EXPECT_TRUE(pc_->SetConfiguration(config));
3349
3350 // Do ICE restart for the first m= section, initiated by remote peer.
Steve Antondb45ca82017-09-11 18:27:34 -07003351 std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
Steve Anton36da6ff2018-02-16 16:04:20 -08003352 webrtc::CreateSessionDescription(SdpType::kOffer,
3353 GetSdpStringWithStream1(), nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003354 ASSERT_TRUE(remote_offer);
deadbeefd1a38b52016-12-10 13:15:33 -08003355 remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3356 "modified";
Steve Antondb45ca82017-09-11 18:27:34 -07003357 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
deadbeefd1a38b52016-12-10 13:15:33 -08003358 CreateAnswerAsLocalDescription();
3359
3360 // Grab the ufrags.
3361 std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003362 ASSERT_EQ(2U, initial_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003363
3364 // Create offer and grab the new ufrags.
3365 CreateOfferAsLocalDescription();
3366 std::vector<std::string> subsequent_ufrags =
3367 GetUfrags(pc_->local_description());
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003368 ASSERT_EQ(2U, subsequent_ufrags.size());
deadbeefd1a38b52016-12-10 13:15:33 -08003369
3370 // Ensure that only the ufrag for the second m= section changed.
3371 EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3372 EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3373}
3374
deadbeeffe4a8a42016-12-20 17:56:17 -08003375// Tests that the methods to return current/pending descriptions work as
3376// expected at different points in the offer/answer exchange. This test does
3377// one offer/answer exchange as the offerer, then another as the answerer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003378TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
deadbeeffe4a8a42016-12-20 17:56:17 -08003379 // This disables DTLS so we can apply an answer to ourselves.
3380 CreatePeerConnection();
3381
3382 // Create initial local offer and get SDP (which will also be used as
3383 // answer/pranswer);
Steve Antondb45ca82017-09-11 18:27:34 -07003384 std::unique_ptr<SessionDescriptionInterface> local_offer;
3385 ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
deadbeeffe4a8a42016-12-20 17:56:17 -08003386 std::string sdp;
Steve Antondb45ca82017-09-11 18:27:34 -07003387 EXPECT_TRUE(local_offer->ToString(&sdp));
deadbeeffe4a8a42016-12-20 17:56:17 -08003388
3389 // Set local offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003390 SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3391 EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3392 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003393 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3394 EXPECT_EQ(nullptr, pc_->current_local_description());
3395 EXPECT_EQ(nullptr, pc_->current_remote_description());
3396
3397 // Set remote pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003398 std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003399 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003400 SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3401 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3402 EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3403 EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003404 EXPECT_EQ(nullptr, pc_->current_local_description());
3405 EXPECT_EQ(nullptr, pc_->current_remote_description());
3406
3407 // Set remote answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003408 std::unique_ptr<SessionDescriptionInterface> remote_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003409 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003410 SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3411 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003412 EXPECT_EQ(nullptr, pc_->pending_local_description());
3413 EXPECT_EQ(nullptr, pc_->pending_remote_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003414 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3415 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003416
3417 // Set remote offer.
Steve Antondb45ca82017-09-11 18:27:34 -07003418 std::unique_ptr<SessionDescriptionInterface> remote_offer(
Steve Antona3a92c22017-12-07 10:27:41 -08003419 webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003420 SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3421 EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3422 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003423 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003424 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3425 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003426
3427 // Set local pranswer.
Steve Antondb45ca82017-09-11 18:27:34 -07003428 std::unique_ptr<SessionDescriptionInterface> local_pranswer(
Steve Antona3a92c22017-12-07 10:27:41 -08003429 webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003430 SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3431 EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3432 EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3433 EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3434 EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3435 EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003436
3437 // Set local answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003438 std::unique_ptr<SessionDescriptionInterface> local_answer(
Steve Antona3a92c22017-12-07 10:27:41 -08003439 webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
Steve Antondb45ca82017-09-11 18:27:34 -07003440 SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3441 EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
deadbeeffe4a8a42016-12-20 17:56:17 -08003442 EXPECT_EQ(nullptr, pc_->pending_remote_description());
3443 EXPECT_EQ(nullptr, pc_->pending_local_description());
Steve Antondb45ca82017-09-11 18:27:34 -07003444 EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3445 EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
deadbeeffe4a8a42016-12-20 17:56:17 -08003446}
3447
zhihuang77985012017-02-07 15:45:16 -08003448// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3449// after the PeerConnection is closed.
Elad Alon99c3fe52017-10-13 16:29:40 +02003450// This version tests the StartRtcEventLog version that receives a file.
Steve Anton36da6ff2018-02-16 16:04:20 -08003451TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003452 StartAndStopLoggingToFileAfterPeerConnectionClosed) {
zhihuang77985012017-02-07 15:45:16 -08003453 CreatePeerConnection();
3454 // The RtcEventLog will be reset when the PeerConnection is closed.
3455 pc_->Close();
3456
Elad Alon9e6565b2017-10-11 16:04:13 +02003457 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
3458 std::string filename = webrtc::test::OutputPath() +
3459 test_info->test_case_name() + test_info->name();
3460 rtc::PlatformFile file = rtc::CreatePlatformFile(filename);
3461
3462 constexpr int64_t max_size_bytes = 1024;
3463
zhihuang77985012017-02-07 15:45:16 -08003464 EXPECT_FALSE(pc_->StartRtcEventLog(file, max_size_bytes));
3465 pc_->StopRtcEventLog();
Elad Alon9e6565b2017-10-11 16:04:13 +02003466
3467 // Cleanup.
3468 rtc::ClosePlatformFile(file);
3469 rtc::RemoveFile(filename);
zhihuang77985012017-02-07 15:45:16 -08003470}
3471
Elad Alon99c3fe52017-10-13 16:29:40 +02003472// Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3473// after the PeerConnection is closed.
3474// This version tests the StartRtcEventLog version that receives an object
3475// of type |RtcEventLogOutput|.
Steve Anton36da6ff2018-02-16 16:04:20 -08003476TEST_P(PeerConnectionInterfaceTest,
Elad Alon99c3fe52017-10-13 16:29:40 +02003477 StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3478 CreatePeerConnection();
3479 // The RtcEventLog will be reset when the PeerConnection is closed.
3480 pc_->Close();
3481
3482 rtc::PlatformFile file = 0;
3483 int64_t max_size_bytes = 1024;
3484 EXPECT_FALSE(pc_->StartRtcEventLog(
Karl Wiberg918f50c2018-07-05 11:40:33 +02003485 absl::make_unique<webrtc::RtcEventLogOutputFile>(file, max_size_bytes),
Bjorn Tereliusde939432017-11-20 17:38:14 +01003486 webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02003487 pc_->StopRtcEventLog();
3488}
3489
deadbeef30952b42017-04-21 02:41:29 -07003490// Test that generated offers/answers include "ice-option:trickle".
Steve Anton36da6ff2018-02-16 16:04:20 -08003491TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
deadbeef30952b42017-04-21 02:41:29 -07003492 CreatePeerConnection();
3493
3494 // First, create an offer with audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003495 RTCOfferAnswerOptions options;
3496 options.offer_to_receive_audio = 1;
3497 options.offer_to_receive_video = 1;
deadbeef30952b42017-04-21 02:41:29 -07003498 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003499 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003500 cricket::SessionDescription* desc = offer->description();
3501 ASSERT_EQ(2u, desc->transport_infos().size());
3502 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3503 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3504
3505 // Apply the offer as a remote description, then create an answer.
Steve Antondb45ca82017-09-11 18:27:34 -07003506 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef30952b42017-04-21 02:41:29 -07003507 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003508 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef30952b42017-04-21 02:41:29 -07003509 desc = answer->description();
3510 ASSERT_EQ(2u, desc->transport_infos().size());
3511 EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3512 EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3513}
3514
deadbeef1dcb1642017-03-29 21:08:16 -07003515// Test that ICE renomination isn't offered if it's not enabled in the PC's
3516// RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003517TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
deadbeef1dcb1642017-03-29 21:08:16 -07003518 PeerConnectionInterface::RTCConfiguration config;
3519 config.enable_ice_renomination = false;
Niels Möllerf06f9232018-08-07 12:32:18 +02003520 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003521 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003522
3523 std::unique_ptr<SessionDescriptionInterface> offer;
3524 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3525 cricket::SessionDescription* desc = offer->description();
3526 EXPECT_EQ(1u, desc->transport_infos().size());
3527 EXPECT_FALSE(
3528 desc->transport_infos()[0].description.GetIceParameters().renomination);
3529}
3530
3531// Test that the ICE renomination option is present in generated offers/answers
3532// if it's enabled in the PC's RTCConfiguration.
Steve Anton36da6ff2018-02-16 16:04:20 -08003533TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003534 PeerConnectionInterface::RTCConfiguration config;
3535 config.enable_ice_renomination = true;
Niels Möllerf06f9232018-08-07 12:32:18 +02003536 CreatePeerConnection(config);
Steve Anton36da6ff2018-02-16 16:04:20 -08003537 AddAudioTrack("foo");
deadbeef1dcb1642017-03-29 21:08:16 -07003538
3539 std::unique_ptr<SessionDescriptionInterface> offer;
3540 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3541 cricket::SessionDescription* desc = offer->description();
3542 EXPECT_EQ(1u, desc->transport_infos().size());
3543 EXPECT_TRUE(
3544 desc->transport_infos()[0].description.GetIceParameters().renomination);
3545
3546 // Set the offer as a remote description, then create an answer and ensure it
3547 // has the renomination flag too.
Steve Antondb45ca82017-09-11 18:27:34 -07003548 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003549 std::unique_ptr<SessionDescriptionInterface> answer;
3550 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3551 desc = answer->description();
3552 EXPECT_EQ(1u, desc->transport_infos().size());
3553 EXPECT_TRUE(
3554 desc->transport_infos()[0].description.GetIceParameters().renomination);
3555}
3556
3557// Test that if CreateOffer is called with the deprecated "offer to receive
3558// audio/video" constraints, they're processed and result in an offer with
3559// audio/video sections just as if RTCOfferAnswerOptions had been used.
Steve Anton36da6ff2018-02-16 16:04:20 -08003560TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003561 CreatePeerConnection();
3562
Niels Möllerf06f9232018-08-07 12:32:18 +02003563 RTCOfferAnswerOptions options;
3564 options.offer_to_receive_audio = 1;
3565 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003566 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003567 ASSERT_TRUE(DoCreateOffer(&offer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003568
3569 cricket::SessionDescription* desc = offer->description();
3570 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3571 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3572 ASSERT_NE(nullptr, audio);
3573 ASSERT_NE(nullptr, video);
3574 EXPECT_FALSE(audio->rejected);
3575 EXPECT_FALSE(video->rejected);
3576}
3577
3578// Test that if CreateAnswer is called with the deprecated "offer to receive
3579// audio/video" constraints, they're processed and can be used to reject an
3580// offered m= section just as can be done with RTCOfferAnswerOptions;
Steve Anton36da6ff2018-02-16 16:04:20 -08003581// Don't run under Unified Plan since this behavior is not supported.
3582TEST_F(PeerConnectionInterfaceTestPlanB,
3583 CreateAnswerWithOfferToReceiveConstraints) {
deadbeef1dcb1642017-03-29 21:08:16 -07003584 CreatePeerConnection();
3585
3586 // First, create an offer with audio/video and apply it as a remote
3587 // description.
Niels Möllerf06f9232018-08-07 12:32:18 +02003588 RTCOfferAnswerOptions options;
3589 options.offer_to_receive_audio = 1;
3590 options.offer_to_receive_video = 1;
deadbeef1dcb1642017-03-29 21:08:16 -07003591 std::unique_ptr<SessionDescriptionInterface> offer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003592 ASSERT_TRUE(DoCreateOffer(&offer, &options));
Steve Antondb45ca82017-09-11 18:27:34 -07003593 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003594
3595 // Now create answer that rejects audio/video.
Niels Möllerf06f9232018-08-07 12:32:18 +02003596 options.offer_to_receive_audio = 0;
3597 options.offer_to_receive_video = 0;
deadbeef1dcb1642017-03-29 21:08:16 -07003598 std::unique_ptr<SessionDescriptionInterface> answer;
Niels Möllerf06f9232018-08-07 12:32:18 +02003599 ASSERT_TRUE(DoCreateAnswer(&answer, &options));
deadbeef1dcb1642017-03-29 21:08:16 -07003600
3601 cricket::SessionDescription* desc = answer->description();
3602 const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3603 const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3604 ASSERT_NE(nullptr, audio);
3605 ASSERT_NE(nullptr, video);
3606 EXPECT_TRUE(audio->rejected);
3607 EXPECT_TRUE(video->rejected);
3608}
3609
deadbeef1dcb1642017-03-29 21:08:16 -07003610// Test that negotiation can succeed with a data channel only, and with the max
3611// bundle policy. Previously there was a bug that prevented this.
Steve Anton36da6ff2018-02-16 16:04:20 -08003612#ifdef HAVE_SCTP
3613TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3614#else
3615TEST_P(PeerConnectionInterfaceTest,
3616 DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3617#endif // HAVE_SCTP
deadbeef1dcb1642017-03-29 21:08:16 -07003618 PeerConnectionInterface::RTCConfiguration config;
3619 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
Niels Möllerf06f9232018-08-07 12:32:18 +02003620 CreatePeerConnection(config);
deadbeef1dcb1642017-03-29 21:08:16 -07003621
3622 // First, create an offer with only a data channel and apply it as a remote
3623 // description.
3624 pc_->CreateDataChannel("test", nullptr);
3625 std::unique_ptr<SessionDescriptionInterface> offer;
3626 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003627 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003628
3629 // Create and set answer as well.
3630 std::unique_ptr<SessionDescriptionInterface> answer;
3631 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
Steve Antondb45ca82017-09-11 18:27:34 -07003632 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
deadbeef1dcb1642017-03-29 21:08:16 -07003633}
3634
Steve Anton36da6ff2018-02-16 16:04:20 -08003635TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
zstein4b979802017-06-02 14:37:37 -07003636 CreatePeerConnection();
3637 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003638 bitrate.current_bitrate_bps = 100000;
zstein4b979802017-06-02 14:37:37 -07003639 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3640}
3641
Steve Anton36da6ff2018-02-16 16:04:20 -08003642TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
zstein4b979802017-06-02 14:37:37 -07003643 CreatePeerConnection();
3644 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003645 bitrate.min_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003646 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3647}
3648
Steve Anton36da6ff2018-02-16 16:04:20 -08003649TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003650 CreatePeerConnection();
3651 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003652 bitrate.min_bitrate_bps = 5;
3653 bitrate.current_bitrate_bps = 3;
zstein4b979802017-06-02 14:37:37 -07003654 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3655}
3656
Steve Anton36da6ff2018-02-16 16:04:20 -08003657TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003658 CreatePeerConnection();
3659 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003660 bitrate.current_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003661 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3662}
3663
Steve Anton36da6ff2018-02-16 16:04:20 -08003664TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
zstein4b979802017-06-02 14:37:37 -07003665 CreatePeerConnection();
3666 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003667 bitrate.current_bitrate_bps = 10;
3668 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003669 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3670}
3671
Steve Anton36da6ff2018-02-16 16:04:20 -08003672TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
zstein4b979802017-06-02 14:37:37 -07003673 CreatePeerConnection();
3674 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003675 bitrate.min_bitrate_bps = 10;
3676 bitrate.max_bitrate_bps = 8;
zstein4b979802017-06-02 14:37:37 -07003677 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3678}
3679
Steve Anton36da6ff2018-02-16 16:04:20 -08003680TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
zstein4b979802017-06-02 14:37:37 -07003681 CreatePeerConnection();
3682 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003683 bitrate.max_bitrate_bps = -1;
zstein4b979802017-06-02 14:37:37 -07003684 EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3685}
3686
Steve Anton038834f2017-07-14 15:59:59 -07003687// ice_regather_interval_range requires WebRTC to be configured for continual
3688// gathering already.
Steve Anton36da6ff2018-02-16 16:04:20 -08003689TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003690 SetIceRegatherIntervalRangeWithoutContinualGatheringFails) {
3691 PeerConnectionInterface::RTCConfiguration config;
3692 config.ice_regather_interval_range.emplace(1000, 2000);
3693 config.continual_gathering_policy =
3694 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_ONCE;
3695 CreatePeerConnectionExpectFail(config);
3696}
3697
3698// Ensures that there is no error when ice_regather_interval_range is set with
3699// continual gathering enabled.
Steve Anton36da6ff2018-02-16 16:04:20 -08003700TEST_P(PeerConnectionInterfaceTest,
Steve Anton038834f2017-07-14 15:59:59 -07003701 SetIceRegatherIntervalRangeWithContinualGathering) {
3702 PeerConnectionInterface::RTCConfiguration config;
3703 config.ice_regather_interval_range.emplace(1000, 2000);
3704 config.continual_gathering_policy =
3705 PeerConnectionInterface::ContinualGatheringPolicy::GATHER_CONTINUALLY;
Niels Möllerf06f9232018-08-07 12:32:18 +02003706 CreatePeerConnection(config);
Steve Anton038834f2017-07-14 15:59:59 -07003707}
3708
Niels Möller0c4f7be2018-05-07 14:01:37 +02003709// The current bitrate from BitrateSettings is currently clamped
Sebastian Janssonfc8d26b2018-02-21 09:52:06 +01003710// by Call's BitrateConstraints, which comes from the SDP or a default value.
3711// This test checks that a call to SetBitrate with a current bitrate that will
3712// be clamped succeeds.
Steve Anton36da6ff2018-02-16 16:04:20 -08003713TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
zstein4b979802017-06-02 14:37:37 -07003714 CreatePeerConnection();
3715 PeerConnectionInterface::BitrateParameters bitrate;
Oskar Sundbomb95fd2c2017-11-16 10:54:38 +01003716 bitrate.current_bitrate_bps = 1;
zstein4b979802017-06-02 14:37:37 -07003717 EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3718}
3719
zhihuang1c378ed2017-08-17 14:10:50 -07003720// The following tests verify that the offer can be created correctly.
Steve Anton36da6ff2018-02-16 16:04:20 -08003721TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003722 CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3723 RTCOfferAnswerOptions rtc_options;
3724
3725 // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3726 // than kMaxOfferToReceiveMedia should be treated as invalid.
3727 rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3728 CreatePeerConnection();
3729 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3730
3731 rtc_options.offer_to_receive_audio =
3732 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3733 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3734}
3735
Steve Anton36da6ff2018-02-16 16:04:20 -08003736TEST_P(PeerConnectionInterfaceTest,
zhihuang1c378ed2017-08-17 14:10:50 -07003737 CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3738 RTCOfferAnswerOptions rtc_options;
3739
3740 // Setting offer_to_receive_video to a value lower than kUndefined or greater
3741 // than kMaxOfferToReceiveMedia should be treated as invalid.
3742 rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3743 CreatePeerConnection();
3744 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3745
3746 rtc_options.offer_to_receive_video =
3747 RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3748 EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3749}
3750
3751// Test that the audio and video content will be added to an offer if both
3752// |offer_to_receive_audio| and |offer_to_receive_video| options are 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003753TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003754 RTCOfferAnswerOptions rtc_options;
3755 rtc_options.offer_to_receive_audio = 1;
3756 rtc_options.offer_to_receive_video = 1;
3757
3758 std::unique_ptr<SessionDescriptionInterface> offer;
3759 CreatePeerConnection();
3760 offer = CreateOfferWithOptions(rtc_options);
3761 ASSERT_TRUE(offer);
3762 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3763 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3764}
3765
3766// Test that only audio content will be added to the offer if only
3767// |offer_to_receive_audio| options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003768TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003769 RTCOfferAnswerOptions rtc_options;
3770 rtc_options.offer_to_receive_audio = 1;
3771 rtc_options.offer_to_receive_video = 0;
3772
3773 std::unique_ptr<SessionDescriptionInterface> offer;
3774 CreatePeerConnection();
3775 offer = CreateOfferWithOptions(rtc_options);
3776 ASSERT_TRUE(offer);
3777 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3778 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3779}
3780
3781// Test that only video content will be added if only |offer_to_receive_video|
3782// options is 1.
Steve Anton36da6ff2018-02-16 16:04:20 -08003783TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003784 RTCOfferAnswerOptions rtc_options;
3785 rtc_options.offer_to_receive_audio = 0;
3786 rtc_options.offer_to_receive_video = 1;
3787
3788 std::unique_ptr<SessionDescriptionInterface> offer;
3789 CreatePeerConnection();
3790 offer = CreateOfferWithOptions(rtc_options);
3791 ASSERT_TRUE(offer);
3792 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3793 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3794}
3795
zhihuang1c378ed2017-08-17 14:10:50 -07003796// Test that no media content will be added to the offer if using default
3797// RTCOfferAnswerOptions.
Steve Anton36da6ff2018-02-16 16:04:20 -08003798TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
zhihuang1c378ed2017-08-17 14:10:50 -07003799 RTCOfferAnswerOptions rtc_options;
3800
3801 std::unique_ptr<SessionDescriptionInterface> offer;
3802 CreatePeerConnection();
3803 offer = CreateOfferWithOptions(rtc_options);
3804 ASSERT_TRUE(offer);
3805 EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3806 EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3807}
3808
3809// Test that if |ice_restart| is true, the ufrag/pwd will change, otherwise
3810// ufrag/pwd will be the same in the new offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003811TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3812 CreatePeerConnection();
3813
zhihuang1c378ed2017-08-17 14:10:50 -07003814 RTCOfferAnswerOptions rtc_options;
3815 rtc_options.ice_restart = false;
3816 rtc_options.offer_to_receive_audio = 1;
3817
3818 std::unique_ptr<SessionDescriptionInterface> offer;
zhihuang1c378ed2017-08-17 14:10:50 -07003819 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003820 std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3821 auto ufrag1 =
3822 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3823 auto pwd1 =
3824 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003825
3826 // |ice_restart| is false, the ufrag/pwd shouldn't change.
3827 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003828 auto ufrag2 =
3829 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3830 auto pwd2 =
3831 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003832
3833 // |ice_restart| is true, the ufrag/pwd should change.
3834 rtc_options.ice_restart = true;
3835 CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
Steve Anton36da6ff2018-02-16 16:04:20 -08003836 auto ufrag3 =
3837 offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3838 auto pwd3 =
3839 offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
zhihuang1c378ed2017-08-17 14:10:50 -07003840
3841 EXPECT_EQ(ufrag1, ufrag2);
3842 EXPECT_EQ(pwd1, pwd2);
3843 EXPECT_NE(ufrag2, ufrag3);
3844 EXPECT_NE(pwd2, pwd3);
3845}
3846
3847// Test that if |use_rtp_mux| is true, the bundling will be enabled in the
3848// offer; if it is false, there won't be any bundle group in the offer.
Steve Anton36da6ff2018-02-16 16:04:20 -08003849TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
zhihuang1c378ed2017-08-17 14:10:50 -07003850 RTCOfferAnswerOptions rtc_options;
3851 rtc_options.offer_to_receive_audio = 1;
3852 rtc_options.offer_to_receive_video = 1;
3853
3854 std::unique_ptr<SessionDescriptionInterface> offer;
3855 CreatePeerConnection();
3856
3857 rtc_options.use_rtp_mux = true;
3858 offer = CreateOfferWithOptions(rtc_options);
3859 ASSERT_TRUE(offer);
3860 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3861 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3862 EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3863
3864 rtc_options.use_rtp_mux = false;
3865 offer = CreateOfferWithOptions(rtc_options);
3866 ASSERT_TRUE(offer);
3867 EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3868 EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3869 EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3870}
3871
zhihuang141aacb2017-08-29 13:23:53 -07003872// This test ensures OnRenegotiationNeeded is called when we add track with
3873// MediaStream -> AddTrack in the same way it is called when we add track with
3874// PeerConnection -> AddTrack.
3875// The test can be removed once addStream is rewritten in terms of addTrack
3876// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
Steve Anton36da6ff2018-02-16 16:04:20 -08003877// Don't run under Unified Plan since the stream API is not available.
3878TEST_F(PeerConnectionInterfaceTestPlanB,
3879 MediaStreamAddTrackRemoveTrackRenegotiate) {
zhihuang141aacb2017-08-29 13:23:53 -07003880 CreatePeerConnectionWithoutDtls();
3881 rtc::scoped_refptr<MediaStreamInterface> stream(
Seth Hampson845e8782018-03-02 11:34:10 -08003882 pc_factory_->CreateLocalMediaStream(kStreamId1));
zhihuang141aacb2017-08-29 13:23:53 -07003883 pc_->AddStream(stream);
3884 rtc::scoped_refptr<AudioTrackInterface> audio_track(
Niels Möller215ba602019-01-18 13:59:45 +01003885 CreateAudioTrack("audio_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003886 rtc::scoped_refptr<VideoTrackInterface> video_track(
Niels Möller215ba602019-01-18 13:59:45 +01003887 CreateVideoTrack("video_track"));
zhihuang141aacb2017-08-29 13:23:53 -07003888 stream->AddTrack(audio_track);
3889 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3890 observer_.renegotiation_needed_ = false;
3891
3892 stream->AddTrack(video_track);
3893 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3894 observer_.renegotiation_needed_ = false;
3895
3896 stream->RemoveTrack(audio_track);
3897 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3898 observer_.renegotiation_needed_ = false;
3899
3900 stream->RemoveTrack(video_track);
3901 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3902 observer_.renegotiation_needed_ = false;
3903}
3904
Zhi Huangb2d355e2017-10-26 17:26:37 -07003905// Tests that an error is returned if a description is applied that has fewer
3906// media sections than the existing description.
Steve Anton36da6ff2018-02-16 16:04:20 -08003907TEST_P(PeerConnectionInterfaceTest,
Zhi Huangb2d355e2017-10-26 17:26:37 -07003908 MediaSectionCountEnforcedForSubsequentOffer) {
3909 CreatePeerConnection();
Steve Anton36da6ff2018-02-16 16:04:20 -08003910 AddAudioTrack("audio_label");
3911 AddVideoTrack("video_label");
3912
Zhi Huangb2d355e2017-10-26 17:26:37 -07003913 std::unique_ptr<SessionDescriptionInterface> offer;
Steve Anton36da6ff2018-02-16 16:04:20 -08003914 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003915 EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3916
3917 // A remote offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003918 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003919 offer->description()->contents().pop_back();
3920 offer->description()->contents().pop_back();
3921 ASSERT_TRUE(offer->description()->contents().empty());
3922 EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3923
3924 std::unique_ptr<SessionDescriptionInterface> answer;
3925 ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3926 EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3927
3928 // A subsequent local offer with fewer media sections should be rejected.
Steve Anton36da6ff2018-02-16 16:04:20 -08003929 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
Zhi Huangb2d355e2017-10-26 17:26:37 -07003930 offer->description()->contents().pop_back();
3931 offer->description()->contents().pop_back();
3932 ASSERT_TRUE(offer->description()->contents().empty());
3933 EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3934}
3935
Johannes Kron89f874e2018-11-12 10:25:48 +01003936TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3937 RTCConfiguration config;
3938 // Default behavior is false.
3939 CreatePeerConnection(config);
3940 std::unique_ptr<SessionDescriptionInterface> offer;
3941 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3942 EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3943 // Possible to set to true.
3944 config.offer_extmap_allow_mixed = true;
3945 CreatePeerConnection(config);
3946 offer.release();
3947 ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3948 EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3949}
3950
Steve Anton36da6ff2018-02-16 16:04:20 -08003951INSTANTIATE_TEST_CASE_P(PeerConnectionInterfaceTest,
3952 PeerConnectionInterfaceTest,
3953 Values(SdpSemantics::kPlanB,
3954 SdpSemantics::kUnifiedPlan));
3955
nisse51542be2016-02-12 02:27:06 -08003956class PeerConnectionMediaConfigTest : public testing::Test {
3957 protected:
3958 void SetUp() override {
zhihuang38ede132017-06-15 12:52:32 -07003959 pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
nisse51542be2016-02-12 02:27:06 -08003960 pcf_->Initialize();
3961 }
nisseeaabdf62017-05-05 02:23:02 -07003962 const cricket::MediaConfig TestCreatePeerConnection(
Niels Möllerf06f9232018-08-07 12:32:18 +02003963 const RTCConfiguration& config) {
3964 rtc::scoped_refptr<PeerConnectionInterface> pc(
3965 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
nisse51542be2016-02-12 02:27:06 -08003966 EXPECT_TRUE(pc.get());
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003967 observer_.SetPeerConnectionInterface(pc.get());
nisseeaabdf62017-05-05 02:23:02 -07003968 return pc->GetConfiguration().media_config;
nisse51542be2016-02-12 02:27:06 -08003969 }
3970
zhihuang9763d562016-08-05 11:14:50 -07003971 rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
nisse51542be2016-02-12 02:27:06 -08003972 MockPeerConnectionObserver observer_;
3973};
3974
Yves Gereyf3ff14c2018-10-25 10:28:12 +02003975// This sanity check validates the test infrastructure itself.
3976TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3977 PeerConnectionInterface::RTCConfiguration config;
3978 rtc::scoped_refptr<PeerConnectionInterface> pc(
3979 pcf_->CreatePeerConnection(config, nullptr, nullptr, &observer_));
3980 EXPECT_TRUE(pc.get());
3981 observer_.SetPeerConnectionInterface(pc.get()); // Required.
3982 pc->Close(); // No abort -> ok.
3983 SUCCEED();
3984}
3985
nisse51542be2016-02-12 02:27:06 -08003986// This test verifies the default behaviour with no constraints and a
3987// default RTCConfiguration.
3988TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3989 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08003990
Niels Möllerf06f9232018-08-07 12:32:18 +02003991 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08003992
3993 EXPECT_FALSE(media_config.enable_dscp);
Niels Möller1d7ecd22018-01-18 15:25:12 +01003994 EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3995 EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08003996 EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
Niels Möller6539f692018-01-18 08:58:50 +01003997 EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
nisse51542be2016-02-12 02:27:06 -08003998}
3999
Niels Möller1d7ecd22018-01-18 15:25:12 +01004000// This test verifies that the enable_prerenderer_smoothing flag is
nisse528b7932017-05-08 03:21:43 -07004001// propagated from RTCConfiguration to the PeerConnection.
nisse51542be2016-02-12 02:27:06 -08004002TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
4003 PeerConnectionInterface::RTCConfiguration config;
nisse51542be2016-02-12 02:27:06 -08004004
Niels Möller71bdda02016-03-31 12:59:59 +02004005 config.set_prerenderer_smoothing(false);
Niels Möllerf06f9232018-08-07 12:32:18 +02004006 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
nisse51542be2016-02-12 02:27:06 -08004007
Niels Möller1d7ecd22018-01-18 15:25:12 +01004008 EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
nisse0db023a2016-03-01 04:29:59 -08004009}
4010
Niels Möller6539f692018-01-18 08:58:50 +01004011// This test verifies that the experiment_cpu_load_estimator flag is
4012// propagated from RTCConfiguration to the PeerConnection.
4013TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
4014 PeerConnectionInterface::RTCConfiguration config;
Niels Möller6539f692018-01-18 08:58:50 +01004015
4016 config.set_experiment_cpu_load_estimator(true);
Niels Möllerf06f9232018-08-07 12:32:18 +02004017 const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
Niels Möller6539f692018-01-18 08:58:50 +01004018
4019 EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
4020}
4021
deadbeef293e9262017-01-11 12:28:30 -08004022// Tests a few random fields being different.
4023TEST(RTCConfigurationTest, ComparisonOperators) {
4024 PeerConnectionInterface::RTCConfiguration a;
4025 PeerConnectionInterface::RTCConfiguration b;
4026 EXPECT_EQ(a, b);
4027
4028 PeerConnectionInterface::RTCConfiguration c;
4029 c.servers.push_back(PeerConnectionInterface::IceServer());
4030 EXPECT_NE(a, c);
4031
4032 PeerConnectionInterface::RTCConfiguration d;
4033 d.type = PeerConnectionInterface::kRelay;
4034 EXPECT_NE(a, d);
4035
4036 PeerConnectionInterface::RTCConfiguration e;
4037 e.audio_jitter_buffer_max_packets = 5;
4038 EXPECT_NE(a, e);
4039
4040 PeerConnectionInterface::RTCConfiguration f;
4041 f.ice_connection_receiving_timeout = 1337;
4042 EXPECT_NE(a, f);
4043
4044 PeerConnectionInterface::RTCConfiguration g;
4045 g.disable_ipv6 = true;
4046 EXPECT_NE(a, g);
4047
4048 PeerConnectionInterface::RTCConfiguration h(
4049 PeerConnectionInterface::RTCConfigurationType::kAggressive);
4050 EXPECT_NE(a, h);
4051}
Mirko Bonadeiab64e8a2018-12-12 12:10:18 +01004052
4053} // namespace
4054} // namespace webrtc