1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker *
4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker */
10*d9f75844SAndroid Build Coastguard Worker
11*d9f75844SAndroid Build Coastguard Worker #include "api/peer_connection_interface.h"
12*d9f75844SAndroid Build Coastguard Worker
13*d9f75844SAndroid Build Coastguard Worker #include <limits.h>
14*d9f75844SAndroid Build Coastguard Worker #include <stdint.h>
15*d9f75844SAndroid Build Coastguard Worker
16*d9f75844SAndroid Build Coastguard Worker #include <string>
17*d9f75844SAndroid Build Coastguard Worker #include <utility>
18*d9f75844SAndroid Build Coastguard Worker #include <vector>
19*d9f75844SAndroid Build Coastguard Worker
20*d9f75844SAndroid Build Coastguard Worker #include "absl/strings/str_replace.h"
21*d9f75844SAndroid Build Coastguard Worker #include "absl/types/optional.h"
22*d9f75844SAndroid Build Coastguard Worker #include "api/audio/audio_mixer.h"
23*d9f75844SAndroid Build Coastguard Worker #include "api/audio_codecs/builtin_audio_decoder_factory.h"
24*d9f75844SAndroid Build Coastguard Worker #include "api/audio_codecs/builtin_audio_encoder_factory.h"
25*d9f75844SAndroid Build Coastguard Worker #include "api/call/call_factory_interface.h"
26*d9f75844SAndroid Build Coastguard Worker #include "api/create_peerconnection_factory.h"
27*d9f75844SAndroid Build Coastguard Worker #include "api/data_channel_interface.h"
28*d9f75844SAndroid Build Coastguard Worker #include "api/jsep.h"
29*d9f75844SAndroid Build Coastguard Worker #include "api/media_stream_interface.h"
30*d9f75844SAndroid Build Coastguard Worker #include "api/media_types.h"
31*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_error.h"
32*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_event_log/rtc_event_log.h"
33*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_event_log/rtc_event_log_factory.h"
34*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_event_log_output.h"
35*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_receiver_interface.h"
36*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_sender_interface.h"
37*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_transceiver_direction.h"
38*d9f75844SAndroid Build Coastguard Worker #include "api/scoped_refptr.h"
39*d9f75844SAndroid Build Coastguard Worker #include "api/task_queue/default_task_queue_factory.h"
40*d9f75844SAndroid Build Coastguard Worker #include "api/transport/field_trial_based_config.h"
41*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/builtin_video_decoder_factory.h"
42*d9f75844SAndroid Build Coastguard Worker #include "api/video_codecs/builtin_video_encoder_factory.h"
43*d9f75844SAndroid Build Coastguard Worker #include "media/base/codec.h"
44*d9f75844SAndroid Build Coastguard Worker #include "media/base/media_config.h"
45*d9f75844SAndroid Build Coastguard Worker #include "media/base/media_engine.h"
46*d9f75844SAndroid Build Coastguard Worker #include "media/base/stream_params.h"
47*d9f75844SAndroid Build Coastguard Worker #include "media/engine/webrtc_media_engine.h"
48*d9f75844SAndroid Build Coastguard Worker #include "media/engine/webrtc_media_engine_defaults.h"
49*d9f75844SAndroid Build Coastguard Worker #include "media/sctp/sctp_transport_internal.h"
50*d9f75844SAndroid Build Coastguard Worker #include "modules/audio_device/include/audio_device.h"
51*d9f75844SAndroid Build Coastguard Worker #include "modules/audio_processing/include/audio_processing.h"
52*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/fake_port_allocator.h"
53*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/p2p_constants.h"
54*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/port.h"
55*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/port_allocator.h"
56*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/transport_description.h"
57*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/transport_info.h"
58*d9f75844SAndroid Build Coastguard Worker #include "pc/audio_track.h"
59*d9f75844SAndroid Build Coastguard Worker #include "pc/media_session.h"
60*d9f75844SAndroid Build Coastguard Worker #include "pc/media_stream.h"
61*d9f75844SAndroid Build Coastguard Worker #include "pc/peer_connection.h"
62*d9f75844SAndroid Build Coastguard Worker #include "pc/peer_connection_factory.h"
63*d9f75844SAndroid Build Coastguard Worker #include "pc/rtp_sender.h"
64*d9f75844SAndroid Build Coastguard Worker #include "pc/rtp_sender_proxy.h"
65*d9f75844SAndroid Build Coastguard Worker #include "pc/session_description.h"
66*d9f75844SAndroid Build Coastguard Worker #include "pc/stream_collection.h"
67*d9f75844SAndroid Build Coastguard Worker #include "pc/test/fake_audio_capture_module.h"
68*d9f75844SAndroid Build Coastguard Worker #include "pc/test/fake_rtc_certificate_generator.h"
69*d9f75844SAndroid Build Coastguard Worker #include "pc/test/fake_video_track_source.h"
70*d9f75844SAndroid Build Coastguard Worker #include "pc/test/mock_peer_connection_observers.h"
71*d9f75844SAndroid Build Coastguard Worker #include "pc/test/test_sdp_strings.h"
72*d9f75844SAndroid Build Coastguard Worker #include "pc/video_track.h"
73*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/checks.h"
74*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/gunit.h"
75*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/rtc_certificate_generator.h"
76*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/socket_address.h"
77*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread.h"
78*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/virtual_socket_server.h"
79*d9f75844SAndroid Build Coastguard Worker #include "test/gmock.h"
80*d9f75844SAndroid Build Coastguard Worker #include "test/gtest.h"
81*d9f75844SAndroid Build Coastguard Worker
82*d9f75844SAndroid Build Coastguard Worker #ifdef WEBRTC_ANDROID
83*d9f75844SAndroid Build Coastguard Worker #include "pc/test/android_test_initializer.h"
84*d9f75844SAndroid Build Coastguard Worker #endif
85*d9f75844SAndroid Build Coastguard Worker
86*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
87*d9f75844SAndroid Build Coastguard Worker namespace {
88*d9f75844SAndroid Build Coastguard Worker
89*d9f75844SAndroid Build Coastguard Worker static const char kStreamId1[] = "local_stream_1";
90*d9f75844SAndroid Build Coastguard Worker static const char kStreamId2[] = "local_stream_2";
91*d9f75844SAndroid Build Coastguard Worker static const char kStreamId3[] = "local_stream_3";
92*d9f75844SAndroid Build Coastguard Worker static const int kDefaultStunPort = 3478;
93*d9f75844SAndroid Build Coastguard Worker static const char kStunAddressOnly[] = "stun:address";
94*d9f75844SAndroid Build Coastguard Worker static const char kStunInvalidPort[] = "stun:address:-1";
95*d9f75844SAndroid Build Coastguard Worker static const char kStunAddressPortAndMore1[] = "stun:address:port:more";
96*d9f75844SAndroid Build Coastguard Worker static const char kStunAddressPortAndMore2[] = "stun:address:port more";
97*d9f75844SAndroid Build Coastguard Worker static const char kTurnIceServerUri[] = "turn:turn.example.org";
98*d9f75844SAndroid Build Coastguard Worker static const char kTurnUsername[] = "user";
99*d9f75844SAndroid Build Coastguard Worker static const char kTurnPassword[] = "password";
100*d9f75844SAndroid Build Coastguard Worker static const char kTurnHostname[] = "turn.example.org";
101*d9f75844SAndroid Build Coastguard Worker static const uint32_t kTimeout = 10000U;
102*d9f75844SAndroid Build Coastguard Worker
103*d9f75844SAndroid Build Coastguard Worker static const char kStreams[][8] = {"stream1", "stream2"};
104*d9f75844SAndroid Build Coastguard Worker static const char kAudioTracks[][32] = {"audiotrack0", "audiotrack1"};
105*d9f75844SAndroid Build Coastguard Worker static const char kVideoTracks[][32] = {"videotrack0", "videotrack1"};
106*d9f75844SAndroid Build Coastguard Worker
107*d9f75844SAndroid Build Coastguard Worker static const char kRecvonly[] = "recvonly";
108*d9f75844SAndroid Build Coastguard Worker static const char kSendrecv[] = "sendrecv";
109*d9f75844SAndroid Build Coastguard Worker constexpr uint64_t kTiebreakerDefault = 44444;
110*d9f75844SAndroid Build Coastguard Worker
111*d9f75844SAndroid Build Coastguard Worker // Reference SDP with a MediaStream with label "stream1" and audio track with
112*d9f75844SAndroid Build Coastguard Worker // id "audio_1" and a video track with id "video_1;
113*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringWithStream1PlanB[] =
114*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
115*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
116*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
117*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
118*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
119*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
120*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
121*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
122*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
123*d9f75844SAndroid Build Coastguard Worker "a=mid:audio\r\n"
124*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
125*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
126*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n"
127*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 cname:stream1\r\n"
128*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 msid:stream1 audiotrack0\r\n"
129*d9f75844SAndroid Build Coastguard Worker "m=video 1 RTP/AVPF 120\r\n"
130*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
131*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
132*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
133*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
134*d9f75844SAndroid Build Coastguard Worker "a=mid:video\r\n"
135*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
136*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
137*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:120 VP8/90000\r\n"
138*d9f75844SAndroid Build Coastguard Worker "a=ssrc:2 cname:stream1\r\n"
139*d9f75844SAndroid Build Coastguard Worker "a=ssrc:2 msid:stream1 videotrack0\r\n";
140*d9f75844SAndroid Build Coastguard Worker // Same string as above but with the MID changed to the Unified Plan default and
141*d9f75844SAndroid Build Coastguard Worker // a=msid added. This is needed so that this SDP can be used as an answer for a
142*d9f75844SAndroid Build Coastguard Worker // Unified Plan offer.
143*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringWithStream1UnifiedPlan[] =
144*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
145*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
146*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
147*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
148*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
149*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
150*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
151*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
152*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
153*d9f75844SAndroid Build Coastguard Worker "a=mid:0\r\n"
154*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
155*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
156*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n"
157*d9f75844SAndroid Build Coastguard Worker "a=msid:stream1 audiotrack0\r\n"
158*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 cname:stream1\r\n"
159*d9f75844SAndroid Build Coastguard Worker "m=video 1 RTP/AVPF 120\r\n"
160*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
161*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
162*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
163*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
164*d9f75844SAndroid Build Coastguard Worker "a=mid:1\r\n"
165*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
166*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
167*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:120 VP8/90000\r\n"
168*d9f75844SAndroid Build Coastguard Worker "a=msid:stream1 videotrack0\r\n"
169*d9f75844SAndroid Build Coastguard Worker "a=ssrc:2 cname:stream1\r\n";
170*d9f75844SAndroid Build Coastguard Worker
171*d9f75844SAndroid Build Coastguard Worker // Reference SDP with a MediaStream with label "stream1" and audio track with
172*d9f75844SAndroid Build Coastguard Worker // id "audio_1";
173*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringWithStream1AudioTrackOnly[] =
174*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
175*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
176*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
177*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
178*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
179*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
180*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
181*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
182*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
183*d9f75844SAndroid Build Coastguard Worker "a=mid:audio\r\n"
184*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
185*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n"
186*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 cname:stream1\r\n"
187*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 msid:stream1 audiotrack0\r\n"
188*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n";
189*d9f75844SAndroid Build Coastguard Worker
190*d9f75844SAndroid Build Coastguard Worker // Reference SDP with two MediaStreams with label "stream1" and "stream2. Each
191*d9f75844SAndroid Build Coastguard Worker // MediaStreams have one audio track and one video track.
192*d9f75844SAndroid Build Coastguard Worker // This uses MSID.
193*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringWithStream1And2PlanB[] =
194*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
195*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
196*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
197*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
198*d9f75844SAndroid Build Coastguard Worker "a=msid-semantic: WMS stream1 stream2\r\n"
199*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
200*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
201*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
202*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
203*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
204*d9f75844SAndroid Build Coastguard Worker "a=mid:audio\r\n"
205*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
206*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
207*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n"
208*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 cname:stream1\r\n"
209*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 msid:stream1 audiotrack0\r\n"
210*d9f75844SAndroid Build Coastguard Worker "a=ssrc:3 cname:stream2\r\n"
211*d9f75844SAndroid Build Coastguard Worker "a=ssrc:3 msid:stream2 audiotrack1\r\n"
212*d9f75844SAndroid Build Coastguard Worker "m=video 1 RTP/AVPF 120\r\n"
213*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
214*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
215*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
216*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
217*d9f75844SAndroid Build Coastguard Worker "a=mid:video\r\n"
218*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
219*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
220*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:120 VP8/0\r\n"
221*d9f75844SAndroid Build Coastguard Worker "a=ssrc:2 cname:stream1\r\n"
222*d9f75844SAndroid Build Coastguard Worker "a=ssrc:2 msid:stream1 videotrack0\r\n"
223*d9f75844SAndroid Build Coastguard Worker "a=ssrc:4 cname:stream2\r\n"
224*d9f75844SAndroid Build Coastguard Worker "a=ssrc:4 msid:stream2 videotrack1\r\n";
225*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringWithStream1And2UnifiedPlan[] =
226*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
227*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
228*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
229*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
230*d9f75844SAndroid Build Coastguard Worker "a=msid-semantic: WMS stream1 stream2\r\n"
231*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
232*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
233*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
234*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
235*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
236*d9f75844SAndroid Build Coastguard Worker "a=mid:0\r\n"
237*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
238*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
239*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n"
240*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 cname:stream1\r\n"
241*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 msid:stream1 audiotrack0\r\n"
242*d9f75844SAndroid Build Coastguard Worker "m=video 1 RTP/AVPF 120\r\n"
243*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
244*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
245*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
246*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
247*d9f75844SAndroid Build Coastguard Worker "a=mid:1\r\n"
248*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
249*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
250*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:120 VP8/0\r\n"
251*d9f75844SAndroid Build Coastguard Worker "a=ssrc:2 cname:stream1\r\n"
252*d9f75844SAndroid Build Coastguard Worker "a=ssrc:2 msid:stream1 videotrack0\r\n"
253*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
254*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
255*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
256*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
257*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
258*d9f75844SAndroid Build Coastguard Worker "a=mid:2\r\n"
259*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
260*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
261*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n"
262*d9f75844SAndroid Build Coastguard Worker "a=ssrc:3 cname:stream2\r\n"
263*d9f75844SAndroid Build Coastguard Worker "a=ssrc:3 msid:stream2 audiotrack1\r\n"
264*d9f75844SAndroid Build Coastguard Worker "m=video 1 RTP/AVPF 120\r\n"
265*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
266*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
267*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
268*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
269*d9f75844SAndroid Build Coastguard Worker "a=mid:3\r\n"
270*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
271*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
272*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:120 VP8/0\r\n"
273*d9f75844SAndroid Build Coastguard Worker "a=ssrc:4 cname:stream2\r\n"
274*d9f75844SAndroid Build Coastguard Worker "a=ssrc:4 msid:stream2 videotrack1\r\n";
275*d9f75844SAndroid Build Coastguard Worker
276*d9f75844SAndroid Build Coastguard Worker // Reference SDP without MediaStreams. Msid is not supported.
277*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringWithoutStreams[] =
278*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
279*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
280*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
281*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
282*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
283*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
284*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
285*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
286*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
287*d9f75844SAndroid Build Coastguard Worker "a=mid:audio\r\n"
288*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
289*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
290*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n"
291*d9f75844SAndroid Build Coastguard Worker "m=video 1 RTP/AVPF 120\r\n"
292*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
293*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
294*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
295*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
296*d9f75844SAndroid Build Coastguard Worker "a=mid:video\r\n"
297*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
298*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
299*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:120 VP8/90000\r\n";
300*d9f75844SAndroid Build Coastguard Worker
301*d9f75844SAndroid Build Coastguard Worker // Reference SDP without MediaStreams. Msid is supported.
302*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringWithMsidWithoutStreams[] =
303*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
304*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
305*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
306*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
307*d9f75844SAndroid Build Coastguard Worker "a=msid-semantic: WMS\r\n"
308*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
309*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
310*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
311*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
312*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
313*d9f75844SAndroid Build Coastguard Worker "a=mid:audio\r\n"
314*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
315*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
316*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n"
317*d9f75844SAndroid Build Coastguard Worker "m=video 1 RTP/AVPF 120\r\n"
318*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
319*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
320*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
321*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
322*d9f75844SAndroid Build Coastguard Worker "a=mid:video\r\n"
323*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
324*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
325*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:120 VP8/90000\r\n";
326*d9f75844SAndroid Build Coastguard Worker
327*d9f75844SAndroid Build Coastguard Worker // Reference SDP without MediaStreams and audio only.
328*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringWithoutStreamsAudioOnly[] =
329*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
330*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
331*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
332*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
333*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
334*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
335*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
336*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
337*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
338*d9f75844SAndroid Build Coastguard Worker "a=mid:audio\r\n"
339*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
340*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
341*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n";
342*d9f75844SAndroid Build Coastguard Worker
343*d9f75844SAndroid Build Coastguard Worker // Reference SENDONLY SDP without MediaStreams. Msid is not supported.
344*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringSendOnlyWithoutStreams[] =
345*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
346*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
347*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
348*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
349*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
350*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
351*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
352*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
353*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
354*d9f75844SAndroid Build Coastguard Worker "a=mid:audio\r\n"
355*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
356*d9f75844SAndroid Build Coastguard Worker "a=sendonly\r\n"
357*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
358*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n"
359*d9f75844SAndroid Build Coastguard Worker "m=video 1 RTP/AVPF 120\r\n"
360*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
361*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
362*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
363*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
364*d9f75844SAndroid Build Coastguard Worker "a=mid:video\r\n"
365*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
366*d9f75844SAndroid Build Coastguard Worker "a=sendonly\r\n"
367*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
368*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:120 VP8/90000\r\n";
369*d9f75844SAndroid Build Coastguard Worker
370*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringInit[] =
371*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
372*d9f75844SAndroid Build Coastguard Worker "o=- 0 0 IN IP4 127.0.0.1\r\n"
373*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
374*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
375*d9f75844SAndroid Build Coastguard Worker "a=msid-semantic: WMS\r\n";
376*d9f75844SAndroid Build Coastguard Worker
377*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringAudio[] =
378*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/AVPF 111\r\n"
379*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
380*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
381*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
382*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
383*d9f75844SAndroid Build Coastguard Worker "a=mid:audio\r\n"
384*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
385*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
386*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:111 OPUS/48000/2\r\n";
387*d9f75844SAndroid Build Coastguard Worker
388*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringVideo[] =
389*d9f75844SAndroid Build Coastguard Worker "m=video 1 RTP/AVPF 120\r\n"
390*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
391*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
392*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-256 58:AB:6E:F5:F1:E4:57:B7:E9:46:F4:86:04:28:F9:A7:ED:"
393*d9f75844SAndroid Build Coastguard Worker "BD:AB:AE:40:EF:CE:9A:51:2C:2A:B1:9B:8B:78:84\r\n"
394*d9f75844SAndroid Build Coastguard Worker "a=mid:video\r\n"
395*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
396*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
397*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:120 VP8/90000\r\n";
398*d9f75844SAndroid Build Coastguard Worker
399*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringMs1Audio0[] =
400*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 cname:stream1\r\n"
401*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 msid:stream1 audiotrack0\r\n";
402*d9f75844SAndroid Build Coastguard Worker
403*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringMs1Video0[] =
404*d9f75844SAndroid Build Coastguard Worker "a=ssrc:2 cname:stream1\r\n"
405*d9f75844SAndroid Build Coastguard Worker "a=ssrc:2 msid:stream1 videotrack0\r\n";
406*d9f75844SAndroid Build Coastguard Worker
407*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringMs1Audio1[] =
408*d9f75844SAndroid Build Coastguard Worker "a=ssrc:3 cname:stream1\r\n"
409*d9f75844SAndroid Build Coastguard Worker "a=ssrc:3 msid:stream1 audiotrack1\r\n";
410*d9f75844SAndroid Build Coastguard Worker
411*d9f75844SAndroid Build Coastguard Worker static const char kSdpStringMs1Video1[] =
412*d9f75844SAndroid Build Coastguard Worker "a=ssrc:4 cname:stream1\r\n"
413*d9f75844SAndroid Build Coastguard Worker "a=ssrc:4 msid:stream1 videotrack1\r\n";
414*d9f75844SAndroid Build Coastguard Worker
415*d9f75844SAndroid Build Coastguard Worker static const char kDtlsSdesFallbackSdp[] =
416*d9f75844SAndroid Build Coastguard Worker "v=0\r\n"
417*d9f75844SAndroid Build Coastguard Worker "o=xxxxxx 7 2 IN IP4 0.0.0.0\r\n"
418*d9f75844SAndroid Build Coastguard Worker "s=-\r\n"
419*d9f75844SAndroid Build Coastguard Worker "c=IN IP4 0.0.0.0\r\n"
420*d9f75844SAndroid Build Coastguard Worker "t=0 0\r\n"
421*d9f75844SAndroid Build Coastguard Worker "a=group:BUNDLE audio\r\n"
422*d9f75844SAndroid Build Coastguard Worker "a=msid-semantic: WMS\r\n"
423*d9f75844SAndroid Build Coastguard Worker "m=audio 1 RTP/SAVPF 0\r\n"
424*d9f75844SAndroid Build Coastguard Worker "a=sendrecv\r\n"
425*d9f75844SAndroid Build Coastguard Worker "a=rtcp-mux\r\n"
426*d9f75844SAndroid Build Coastguard Worker "a=mid:audio\r\n"
427*d9f75844SAndroid Build Coastguard Worker "a=ssrc:1 cname:stream1\r\n"
428*d9f75844SAndroid Build Coastguard Worker "a=ice-ufrag:e5785931\r\n"
429*d9f75844SAndroid Build Coastguard Worker "a=ice-pwd:36fb7878390db89481c1d46daa4278d8\r\n"
430*d9f75844SAndroid Build Coastguard Worker "a=rtpmap:0 pcmu/8000\r\n"
431*d9f75844SAndroid Build Coastguard Worker "a=fingerprint:sha-1 "
432*d9f75844SAndroid Build Coastguard Worker "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"
433*d9f75844SAndroid Build Coastguard Worker "a=setup:actpass\r\n"
434*d9f75844SAndroid Build Coastguard Worker "a=crypto:0 AES_CM_128_HMAC_SHA1_80 "
435*d9f75844SAndroid Build Coastguard Worker "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 "
436*d9f75844SAndroid Build Coastguard Worker "dummy_session_params\r\n";
437*d9f75844SAndroid Build Coastguard Worker
438*d9f75844SAndroid Build Coastguard Worker class RtcEventLogOutputNull final : public RtcEventLogOutput {
439*d9f75844SAndroid Build Coastguard Worker public:
IsActive() const440*d9f75844SAndroid Build Coastguard Worker bool IsActive() const override { return true; }
Write(const absl::string_view)441*d9f75844SAndroid Build Coastguard Worker bool Write(const absl::string_view /*output*/) override { return true; }
442*d9f75844SAndroid Build Coastguard Worker };
443*d9f75844SAndroid Build Coastguard Worker
444*d9f75844SAndroid Build Coastguard Worker using ::cricket::StreamParams;
445*d9f75844SAndroid Build Coastguard Worker using ::testing::Eq;
446*d9f75844SAndroid Build Coastguard Worker using ::testing::Exactly;
447*d9f75844SAndroid Build Coastguard Worker using ::testing::SizeIs;
448*d9f75844SAndroid Build Coastguard Worker using ::testing::Values;
449*d9f75844SAndroid Build Coastguard Worker
450*d9f75844SAndroid Build Coastguard Worker using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
451*d9f75844SAndroid Build Coastguard Worker using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
452*d9f75844SAndroid Build Coastguard Worker
453*d9f75844SAndroid Build Coastguard Worker // Gets the first ssrc of given content type from the ContentInfo.
GetFirstSsrc(const cricket::ContentInfo * content_info,int * ssrc)454*d9f75844SAndroid Build Coastguard Worker bool GetFirstSsrc(const cricket::ContentInfo* content_info, int* ssrc) {
455*d9f75844SAndroid Build Coastguard Worker if (!content_info || !ssrc) {
456*d9f75844SAndroid Build Coastguard Worker return false;
457*d9f75844SAndroid Build Coastguard Worker }
458*d9f75844SAndroid Build Coastguard Worker const cricket::MediaContentDescription* media_desc =
459*d9f75844SAndroid Build Coastguard Worker content_info->media_description();
460*d9f75844SAndroid Build Coastguard Worker if (!media_desc || media_desc->streams().empty()) {
461*d9f75844SAndroid Build Coastguard Worker return false;
462*d9f75844SAndroid Build Coastguard Worker }
463*d9f75844SAndroid Build Coastguard Worker *ssrc = media_desc->streams().begin()->first_ssrc();
464*d9f75844SAndroid Build Coastguard Worker return true;
465*d9f75844SAndroid Build Coastguard Worker }
466*d9f75844SAndroid Build Coastguard Worker
467*d9f75844SAndroid Build Coastguard Worker // Get the ufrags out of an SDP blob. Useful for testing ICE restart
468*d9f75844SAndroid Build Coastguard Worker // behavior.
GetUfrags(const webrtc::SessionDescriptionInterface * desc)469*d9f75844SAndroid Build Coastguard Worker std::vector<std::string> GetUfrags(
470*d9f75844SAndroid Build Coastguard Worker const webrtc::SessionDescriptionInterface* desc) {
471*d9f75844SAndroid Build Coastguard Worker std::vector<std::string> ufrags;
472*d9f75844SAndroid Build Coastguard Worker for (const cricket::TransportInfo& info :
473*d9f75844SAndroid Build Coastguard Worker desc->description()->transport_infos()) {
474*d9f75844SAndroid Build Coastguard Worker ufrags.push_back(info.description.ice_ufrag);
475*d9f75844SAndroid Build Coastguard Worker }
476*d9f75844SAndroid Build Coastguard Worker return ufrags;
477*d9f75844SAndroid Build Coastguard Worker }
478*d9f75844SAndroid Build Coastguard Worker
SetSsrcToZero(std::string * sdp)479*d9f75844SAndroid Build Coastguard Worker void SetSsrcToZero(std::string* sdp) {
480*d9f75844SAndroid Build Coastguard Worker const char kSdpSsrcAtribute[] = "a=ssrc:";
481*d9f75844SAndroid Build Coastguard Worker const char kSdpSsrcAtributeZero[] = "a=ssrc:0";
482*d9f75844SAndroid Build Coastguard Worker size_t ssrc_pos = 0;
483*d9f75844SAndroid Build Coastguard Worker while ((ssrc_pos = sdp->find(kSdpSsrcAtribute, ssrc_pos)) !=
484*d9f75844SAndroid Build Coastguard Worker std::string::npos) {
485*d9f75844SAndroid Build Coastguard Worker size_t end_ssrc = sdp->find(" ", ssrc_pos);
486*d9f75844SAndroid Build Coastguard Worker sdp->replace(ssrc_pos, end_ssrc - ssrc_pos, kSdpSsrcAtributeZero);
487*d9f75844SAndroid Build Coastguard Worker ssrc_pos = end_ssrc;
488*d9f75844SAndroid Build Coastguard Worker }
489*d9f75844SAndroid Build Coastguard Worker }
490*d9f75844SAndroid Build Coastguard Worker
491*d9f75844SAndroid Build Coastguard Worker // Check if `streams` contains the specified track.
ContainsTrack(const std::vector<cricket::StreamParams> & streams,const std::string & stream_id,const std::string & track_id)492*d9f75844SAndroid Build Coastguard Worker bool ContainsTrack(const std::vector<cricket::StreamParams>& streams,
493*d9f75844SAndroid Build Coastguard Worker const std::string& stream_id,
494*d9f75844SAndroid Build Coastguard Worker const std::string& track_id) {
495*d9f75844SAndroid Build Coastguard Worker for (const cricket::StreamParams& params : streams) {
496*d9f75844SAndroid Build Coastguard Worker if (params.first_stream_id() == stream_id && params.id == track_id) {
497*d9f75844SAndroid Build Coastguard Worker return true;
498*d9f75844SAndroid Build Coastguard Worker }
499*d9f75844SAndroid Build Coastguard Worker }
500*d9f75844SAndroid Build Coastguard Worker return false;
501*d9f75844SAndroid Build Coastguard Worker }
502*d9f75844SAndroid Build Coastguard Worker
503*d9f75844SAndroid Build Coastguard Worker // Check if `senders` contains the specified sender, by id.
ContainsSender(const std::vector<rtc::scoped_refptr<RtpSenderInterface>> & senders,const std::string & id)504*d9f75844SAndroid Build Coastguard Worker bool ContainsSender(
505*d9f75844SAndroid Build Coastguard Worker const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
506*d9f75844SAndroid Build Coastguard Worker const std::string& id) {
507*d9f75844SAndroid Build Coastguard Worker for (const auto& sender : senders) {
508*d9f75844SAndroid Build Coastguard Worker if (sender->id() == id) {
509*d9f75844SAndroid Build Coastguard Worker return true;
510*d9f75844SAndroid Build Coastguard Worker }
511*d9f75844SAndroid Build Coastguard Worker }
512*d9f75844SAndroid Build Coastguard Worker return false;
513*d9f75844SAndroid Build Coastguard Worker }
514*d9f75844SAndroid Build Coastguard Worker
515*d9f75844SAndroid Build Coastguard Worker // Check if `senders` contains the specified sender, by id and stream id.
ContainsSender(const std::vector<rtc::scoped_refptr<RtpSenderInterface>> & senders,const std::string & id,const std::string & stream_id)516*d9f75844SAndroid Build Coastguard Worker bool ContainsSender(
517*d9f75844SAndroid Build Coastguard Worker const std::vector<rtc::scoped_refptr<RtpSenderInterface>>& senders,
518*d9f75844SAndroid Build Coastguard Worker const std::string& id,
519*d9f75844SAndroid Build Coastguard Worker const std::string& stream_id) {
520*d9f75844SAndroid Build Coastguard Worker for (const auto& sender : senders) {
521*d9f75844SAndroid Build Coastguard Worker if (sender->id() == id && sender->stream_ids()[0] == stream_id) {
522*d9f75844SAndroid Build Coastguard Worker return true;
523*d9f75844SAndroid Build Coastguard Worker }
524*d9f75844SAndroid Build Coastguard Worker }
525*d9f75844SAndroid Build Coastguard Worker return false;
526*d9f75844SAndroid Build Coastguard Worker }
527*d9f75844SAndroid Build Coastguard Worker
528*d9f75844SAndroid Build Coastguard Worker // Create a collection of streams.
529*d9f75844SAndroid Build Coastguard Worker // CreateStreamCollection(1) creates a collection that
530*d9f75844SAndroid Build Coastguard Worker // correspond to kSdpStringWithStream1.
531*d9f75844SAndroid Build Coastguard Worker // CreateStreamCollection(2) correspond to kSdpStringWithStream1And2.
CreateStreamCollection(int number_of_streams,int tracks_per_stream)532*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<StreamCollection> CreateStreamCollection(
533*d9f75844SAndroid Build Coastguard Worker int number_of_streams,
534*d9f75844SAndroid Build Coastguard Worker int tracks_per_stream) {
535*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<StreamCollection> local_collection(
536*d9f75844SAndroid Build Coastguard Worker StreamCollection::Create());
537*d9f75844SAndroid Build Coastguard Worker
538*d9f75844SAndroid Build Coastguard Worker for (int i = 0; i < number_of_streams; ++i) {
539*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
540*d9f75844SAndroid Build Coastguard Worker webrtc::MediaStream::Create(kStreams[i]));
541*d9f75844SAndroid Build Coastguard Worker
542*d9f75844SAndroid Build Coastguard Worker for (int j = 0; j < tracks_per_stream; ++j) {
543*d9f75844SAndroid Build Coastguard Worker // Add a local audio track.
544*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
545*d9f75844SAndroid Build Coastguard Worker webrtc::AudioTrack::Create(kAudioTracks[i * tracks_per_stream + j],
546*d9f75844SAndroid Build Coastguard Worker nullptr));
547*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(audio_track);
548*d9f75844SAndroid Build Coastguard Worker
549*d9f75844SAndroid Build Coastguard Worker // Add a local video track.
550*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
551*d9f75844SAndroid Build Coastguard Worker webrtc::VideoTrack::Create(kVideoTracks[i * tracks_per_stream + j],
552*d9f75844SAndroid Build Coastguard Worker webrtc::FakeVideoTrackSource::Create(),
553*d9f75844SAndroid Build Coastguard Worker rtc::Thread::Current()));
554*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(video_track);
555*d9f75844SAndroid Build Coastguard Worker }
556*d9f75844SAndroid Build Coastguard Worker
557*d9f75844SAndroid Build Coastguard Worker local_collection->AddStream(stream);
558*d9f75844SAndroid Build Coastguard Worker }
559*d9f75844SAndroid Build Coastguard Worker return local_collection;
560*d9f75844SAndroid Build Coastguard Worker }
561*d9f75844SAndroid Build Coastguard Worker
562*d9f75844SAndroid Build Coastguard Worker // Check equality of StreamCollections.
CompareStreamCollections(StreamCollectionInterface * s1,StreamCollectionInterface * s2)563*d9f75844SAndroid Build Coastguard Worker bool CompareStreamCollections(StreamCollectionInterface* s1,
564*d9f75844SAndroid Build Coastguard Worker StreamCollectionInterface* s2) {
565*d9f75844SAndroid Build Coastguard Worker if (s1 == nullptr || s2 == nullptr || s1->count() != s2->count()) {
566*d9f75844SAndroid Build Coastguard Worker return false;
567*d9f75844SAndroid Build Coastguard Worker }
568*d9f75844SAndroid Build Coastguard Worker
569*d9f75844SAndroid Build Coastguard Worker for (size_t i = 0; i != s1->count(); ++i) {
570*d9f75844SAndroid Build Coastguard Worker if (s1->at(i)->id() != s2->at(i)->id()) {
571*d9f75844SAndroid Build Coastguard Worker return false;
572*d9f75844SAndroid Build Coastguard Worker }
573*d9f75844SAndroid Build Coastguard Worker webrtc::AudioTrackVector audio_tracks1 = s1->at(i)->GetAudioTracks();
574*d9f75844SAndroid Build Coastguard Worker webrtc::AudioTrackVector audio_tracks2 = s2->at(i)->GetAudioTracks();
575*d9f75844SAndroid Build Coastguard Worker webrtc::VideoTrackVector video_tracks1 = s1->at(i)->GetVideoTracks();
576*d9f75844SAndroid Build Coastguard Worker webrtc::VideoTrackVector video_tracks2 = s2->at(i)->GetVideoTracks();
577*d9f75844SAndroid Build Coastguard Worker
578*d9f75844SAndroid Build Coastguard Worker if (audio_tracks1.size() != audio_tracks2.size()) {
579*d9f75844SAndroid Build Coastguard Worker return false;
580*d9f75844SAndroid Build Coastguard Worker }
581*d9f75844SAndroid Build Coastguard Worker for (size_t j = 0; j != audio_tracks1.size(); ++j) {
582*d9f75844SAndroid Build Coastguard Worker if (audio_tracks1[j]->id() != audio_tracks2[j]->id()) {
583*d9f75844SAndroid Build Coastguard Worker return false;
584*d9f75844SAndroid Build Coastguard Worker }
585*d9f75844SAndroid Build Coastguard Worker }
586*d9f75844SAndroid Build Coastguard Worker if (video_tracks1.size() != video_tracks2.size()) {
587*d9f75844SAndroid Build Coastguard Worker return false;
588*d9f75844SAndroid Build Coastguard Worker }
589*d9f75844SAndroid Build Coastguard Worker for (size_t j = 0; j != video_tracks1.size(); ++j) {
590*d9f75844SAndroid Build Coastguard Worker if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
591*d9f75844SAndroid Build Coastguard Worker return false;
592*d9f75844SAndroid Build Coastguard Worker }
593*d9f75844SAndroid Build Coastguard Worker }
594*d9f75844SAndroid Build Coastguard Worker }
595*d9f75844SAndroid Build Coastguard Worker return true;
596*d9f75844SAndroid Build Coastguard Worker }
597*d9f75844SAndroid Build Coastguard Worker
598*d9f75844SAndroid Build Coastguard Worker // Helper class to test Observer.
599*d9f75844SAndroid Build Coastguard Worker class MockTrackObserver : public ObserverInterface {
600*d9f75844SAndroid Build Coastguard Worker public:
MockTrackObserver(NotifierInterface * notifier)601*d9f75844SAndroid Build Coastguard Worker explicit MockTrackObserver(NotifierInterface* notifier)
602*d9f75844SAndroid Build Coastguard Worker : notifier_(notifier) {
603*d9f75844SAndroid Build Coastguard Worker notifier_->RegisterObserver(this);
604*d9f75844SAndroid Build Coastguard Worker }
605*d9f75844SAndroid Build Coastguard Worker
~MockTrackObserver()606*d9f75844SAndroid Build Coastguard Worker ~MockTrackObserver() { Unregister(); }
607*d9f75844SAndroid Build Coastguard Worker
Unregister()608*d9f75844SAndroid Build Coastguard Worker void Unregister() {
609*d9f75844SAndroid Build Coastguard Worker if (notifier_) {
610*d9f75844SAndroid Build Coastguard Worker notifier_->UnregisterObserver(this);
611*d9f75844SAndroid Build Coastguard Worker notifier_ = nullptr;
612*d9f75844SAndroid Build Coastguard Worker }
613*d9f75844SAndroid Build Coastguard Worker }
614*d9f75844SAndroid Build Coastguard Worker
615*d9f75844SAndroid Build Coastguard Worker MOCK_METHOD(void, OnChanged, (), (override));
616*d9f75844SAndroid Build Coastguard Worker
617*d9f75844SAndroid Build Coastguard Worker private:
618*d9f75844SAndroid Build Coastguard Worker NotifierInterface* notifier_;
619*d9f75844SAndroid Build Coastguard Worker };
620*d9f75844SAndroid Build Coastguard Worker
621*d9f75844SAndroid Build Coastguard Worker // The PeerConnectionMediaConfig tests below verify that configuration and
622*d9f75844SAndroid Build Coastguard Worker // constraints are propagated into the PeerConnection's MediaConfig. These
623*d9f75844SAndroid Build Coastguard Worker // settings are intended for MediaChannel constructors, but that is not
624*d9f75844SAndroid Build Coastguard Worker // exercised by these unittest.
625*d9f75844SAndroid Build Coastguard Worker class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory {
626*d9f75844SAndroid Build Coastguard Worker public:
627*d9f75844SAndroid Build Coastguard Worker static rtc::scoped_refptr<PeerConnectionFactoryForTest>
CreatePeerConnectionFactoryForTest()628*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionFactoryForTest() {
629*d9f75844SAndroid Build Coastguard Worker PeerConnectionFactoryDependencies dependencies;
630*d9f75844SAndroid Build Coastguard Worker dependencies.worker_thread = rtc::Thread::Current();
631*d9f75844SAndroid Build Coastguard Worker dependencies.network_thread = rtc::Thread::Current();
632*d9f75844SAndroid Build Coastguard Worker dependencies.signaling_thread = rtc::Thread::Current();
633*d9f75844SAndroid Build Coastguard Worker dependencies.task_queue_factory = CreateDefaultTaskQueueFactory();
634*d9f75844SAndroid Build Coastguard Worker dependencies.trials = std::make_unique<FieldTrialBasedConfig>();
635*d9f75844SAndroid Build Coastguard Worker cricket::MediaEngineDependencies media_deps;
636*d9f75844SAndroid Build Coastguard Worker media_deps.task_queue_factory = dependencies.task_queue_factory.get();
637*d9f75844SAndroid Build Coastguard Worker // Use fake audio device module since we're only testing the interface
638*d9f75844SAndroid Build Coastguard Worker // level, and using a real one could make tests flaky when run in parallel.
639*d9f75844SAndroid Build Coastguard Worker media_deps.adm = FakeAudioCaptureModule::Create();
640*d9f75844SAndroid Build Coastguard Worker SetMediaEngineDefaults(&media_deps);
641*d9f75844SAndroid Build Coastguard Worker media_deps.trials = dependencies.trials.get();
642*d9f75844SAndroid Build Coastguard Worker dependencies.media_engine =
643*d9f75844SAndroid Build Coastguard Worker cricket::CreateMediaEngine(std::move(media_deps));
644*d9f75844SAndroid Build Coastguard Worker dependencies.call_factory = webrtc::CreateCallFactory();
645*d9f75844SAndroid Build Coastguard Worker dependencies.event_log_factory = std::make_unique<RtcEventLogFactory>(
646*d9f75844SAndroid Build Coastguard Worker dependencies.task_queue_factory.get());
647*d9f75844SAndroid Build Coastguard Worker
648*d9f75844SAndroid Build Coastguard Worker return rtc::make_ref_counted<PeerConnectionFactoryForTest>(
649*d9f75844SAndroid Build Coastguard Worker std::move(dependencies));
650*d9f75844SAndroid Build Coastguard Worker }
651*d9f75844SAndroid Build Coastguard Worker
652*d9f75844SAndroid Build Coastguard Worker using PeerConnectionFactory::PeerConnectionFactory;
653*d9f75844SAndroid Build Coastguard Worker
654*d9f75844SAndroid Build Coastguard Worker private:
655*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
656*d9f75844SAndroid Build Coastguard Worker };
657*d9f75844SAndroid Build Coastguard Worker
658*d9f75844SAndroid Build Coastguard Worker // TODO(steveanton): Convert to use the new PeerConnectionWrapper.
659*d9f75844SAndroid Build Coastguard Worker class PeerConnectionInterfaceBaseTest : public ::testing::Test {
660*d9f75844SAndroid Build Coastguard Worker protected:
PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)661*d9f75844SAndroid Build Coastguard Worker explicit PeerConnectionInterfaceBaseTest(SdpSemantics sdp_semantics)
662*d9f75844SAndroid Build Coastguard Worker : vss_(new rtc::VirtualSocketServer()),
663*d9f75844SAndroid Build Coastguard Worker main_(vss_.get()),
664*d9f75844SAndroid Build Coastguard Worker sdp_semantics_(sdp_semantics) {
665*d9f75844SAndroid Build Coastguard Worker #ifdef WEBRTC_ANDROID
666*d9f75844SAndroid Build Coastguard Worker webrtc::InitializeAndroidObjects();
667*d9f75844SAndroid Build Coastguard Worker #endif
668*d9f75844SAndroid Build Coastguard Worker }
669*d9f75844SAndroid Build Coastguard Worker
SetUp()670*d9f75844SAndroid Build Coastguard Worker void SetUp() override {
671*d9f75844SAndroid Build Coastguard Worker // Use fake audio capture module since we're only testing the interface
672*d9f75844SAndroid Build Coastguard Worker // level, and using a real one could make tests flaky when run in parallel.
673*d9f75844SAndroid Build Coastguard Worker fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
674*d9f75844SAndroid Build Coastguard Worker pc_factory_ = webrtc::CreatePeerConnectionFactory(
675*d9f75844SAndroid Build Coastguard Worker rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
676*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::AudioDeviceModule>(
677*d9f75844SAndroid Build Coastguard Worker fake_audio_capture_module_),
678*d9f75844SAndroid Build Coastguard Worker webrtc::CreateBuiltinAudioEncoderFactory(),
679*d9f75844SAndroid Build Coastguard Worker webrtc::CreateBuiltinAudioDecoderFactory(),
680*d9f75844SAndroid Build Coastguard Worker webrtc::CreateBuiltinVideoEncoderFactory(),
681*d9f75844SAndroid Build Coastguard Worker webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
682*d9f75844SAndroid Build Coastguard Worker nullptr /* audio_processing */);
683*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pc_factory_);
684*d9f75844SAndroid Build Coastguard Worker pc_factory_for_test_ =
685*d9f75844SAndroid Build Coastguard Worker PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
686*d9f75844SAndroid Build Coastguard Worker }
687*d9f75844SAndroid Build Coastguard Worker
TearDown()688*d9f75844SAndroid Build Coastguard Worker void TearDown() override {
689*d9f75844SAndroid Build Coastguard Worker if (pc_)
690*d9f75844SAndroid Build Coastguard Worker pc_->Close();
691*d9f75844SAndroid Build Coastguard Worker }
692*d9f75844SAndroid Build Coastguard Worker
CreatePeerConnection()693*d9f75844SAndroid Build Coastguard Worker void CreatePeerConnection() {
694*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(PeerConnectionInterface::RTCConfiguration());
695*d9f75844SAndroid Build Coastguard Worker }
696*d9f75844SAndroid Build Coastguard Worker
697*d9f75844SAndroid Build Coastguard Worker // DTLS does not work in a loopback call, so is disabled for many
698*d9f75844SAndroid Build Coastguard Worker // tests in this file.
CreatePeerConnectionWithoutDtls()699*d9f75844SAndroid Build Coastguard Worker void CreatePeerConnectionWithoutDtls() {
700*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
701*d9f75844SAndroid Build Coastguard Worker PeerConnectionFactoryInterface::Options options;
702*d9f75844SAndroid Build Coastguard Worker options.disable_encryption = true;
703*d9f75844SAndroid Build Coastguard Worker pc_factory_->SetOptions(options);
704*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
705*d9f75844SAndroid Build Coastguard Worker options.disable_encryption = false;
706*d9f75844SAndroid Build Coastguard Worker pc_factory_->SetOptions(options);
707*d9f75844SAndroid Build Coastguard Worker }
708*d9f75844SAndroid Build Coastguard Worker
CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::IceTransportsType type)709*d9f75844SAndroid Build Coastguard Worker void CreatePeerConnectionWithIceTransportsType(
710*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::IceTransportsType type) {
711*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
712*d9f75844SAndroid Build Coastguard Worker config.type = type;
713*d9f75844SAndroid Build Coastguard Worker return CreatePeerConnection(config);
714*d9f75844SAndroid Build Coastguard Worker }
715*d9f75844SAndroid Build Coastguard Worker
CreatePeerConnectionWithIceServer(const std::string & uri,const std::string & username,const std::string & password)716*d9f75844SAndroid Build Coastguard Worker void CreatePeerConnectionWithIceServer(const std::string& uri,
717*d9f75844SAndroid Build Coastguard Worker const std::string& username,
718*d9f75844SAndroid Build Coastguard Worker const std::string& password) {
719*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
720*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::IceServer server;
721*d9f75844SAndroid Build Coastguard Worker server.uri = uri;
722*d9f75844SAndroid Build Coastguard Worker server.username = username;
723*d9f75844SAndroid Build Coastguard Worker server.password = password;
724*d9f75844SAndroid Build Coastguard Worker config.servers.push_back(server);
725*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
726*d9f75844SAndroid Build Coastguard Worker }
727*d9f75844SAndroid Build Coastguard Worker
CreatePeerConnection(const RTCConfiguration & config)728*d9f75844SAndroid Build Coastguard Worker void CreatePeerConnection(const RTCConfiguration& config) {
729*d9f75844SAndroid Build Coastguard Worker if (pc_) {
730*d9f75844SAndroid Build Coastguard Worker pc_->Close();
731*d9f75844SAndroid Build Coastguard Worker pc_ = nullptr;
732*d9f75844SAndroid Build Coastguard Worker }
733*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<cricket::FakePortAllocator> port_allocator(
734*d9f75844SAndroid Build Coastguard Worker new cricket::FakePortAllocator(
735*d9f75844SAndroid Build Coastguard Worker rtc::Thread::Current(),
736*d9f75844SAndroid Build Coastguard Worker std::make_unique<rtc::BasicPacketSocketFactory>(vss_.get())));
737*d9f75844SAndroid Build Coastguard Worker port_allocator_ = port_allocator.get();
738*d9f75844SAndroid Build Coastguard Worker port_allocator_->SetIceTiebreaker(kTiebreakerDefault);
739*d9f75844SAndroid Build Coastguard Worker
740*d9f75844SAndroid Build Coastguard Worker // Create certificate generator unless DTLS constraint is explicitly set to
741*d9f75844SAndroid Build Coastguard Worker // false.
742*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
743*d9f75844SAndroid Build Coastguard Worker
744*d9f75844SAndroid Build Coastguard Worker // These won't be used if encryption is turned off, but that's harmless.
745*d9f75844SAndroid Build Coastguard Worker fake_certificate_generator_ = new FakeRTCCertificateGenerator();
746*d9f75844SAndroid Build Coastguard Worker cert_generator.reset(fake_certificate_generator_);
747*d9f75844SAndroid Build Coastguard Worker
748*d9f75844SAndroid Build Coastguard Worker RTCConfiguration modified_config = config;
749*d9f75844SAndroid Build Coastguard Worker modified_config.sdp_semantics = sdp_semantics_;
750*d9f75844SAndroid Build Coastguard Worker PeerConnectionDependencies pc_dependencies(&observer_);
751*d9f75844SAndroid Build Coastguard Worker pc_dependencies.cert_generator = std::move(cert_generator);
752*d9f75844SAndroid Build Coastguard Worker pc_dependencies.allocator = std::move(port_allocator);
753*d9f75844SAndroid Build Coastguard Worker auto result = pc_factory_->CreatePeerConnectionOrError(
754*d9f75844SAndroid Build Coastguard Worker modified_config, std::move(pc_dependencies));
755*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(result.ok());
756*d9f75844SAndroid Build Coastguard Worker pc_ = result.MoveValue();
757*d9f75844SAndroid Build Coastguard Worker observer_.SetPeerConnectionInterface(pc_.get());
758*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
759*d9f75844SAndroid Build Coastguard Worker }
760*d9f75844SAndroid Build Coastguard Worker
CreatePeerConnectionExpectFail(const std::string & uri)761*d9f75844SAndroid Build Coastguard Worker void CreatePeerConnectionExpectFail(const std::string& uri) {
762*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
763*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::IceServer server;
764*d9f75844SAndroid Build Coastguard Worker server.uri = uri;
765*d9f75844SAndroid Build Coastguard Worker config.servers.push_back(server);
766*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
767*d9f75844SAndroid Build Coastguard Worker PeerConnectionDependencies pc_dependencies(&observer_);
768*d9f75844SAndroid Build Coastguard Worker auto result = pc_factory_->CreatePeerConnectionOrError(
769*d9f75844SAndroid Build Coastguard Worker config, std::move(pc_dependencies));
770*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(result.ok());
771*d9f75844SAndroid Build Coastguard Worker }
772*d9f75844SAndroid Build Coastguard Worker
CreatePeerConnectionExpectFail(PeerConnectionInterface::RTCConfiguration config)773*d9f75844SAndroid Build Coastguard Worker void CreatePeerConnectionExpectFail(
774*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config) {
775*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::IceServer server;
776*d9f75844SAndroid Build Coastguard Worker server.uri = kTurnIceServerUri;
777*d9f75844SAndroid Build Coastguard Worker server.password = kTurnPassword;
778*d9f75844SAndroid Build Coastguard Worker config.servers.push_back(server);
779*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
780*d9f75844SAndroid Build Coastguard Worker PeerConnectionDependencies pc_dependencies(&observer_);
781*d9f75844SAndroid Build Coastguard Worker auto result = pc_factory_->CreatePeerConnectionOrError(
782*d9f75844SAndroid Build Coastguard Worker config, std::move(pc_dependencies));
783*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(result.ok());
784*d9f75844SAndroid Build Coastguard Worker }
785*d9f75844SAndroid Build Coastguard Worker
CreatePeerConnectionWithDifferentConfigurations()786*d9f75844SAndroid Build Coastguard Worker void CreatePeerConnectionWithDifferentConfigurations() {
787*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithIceServer(kStunAddressOnly, "", "");
788*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, port_allocator_->stun_servers().size());
789*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, port_allocator_->turn_servers().size());
790*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("address", port_allocator_->stun_servers().begin()->hostname());
791*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(kDefaultStunPort,
792*d9f75844SAndroid Build Coastguard Worker port_allocator_->stun_servers().begin()->port());
793*d9f75844SAndroid Build Coastguard Worker
794*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionExpectFail(kStunInvalidPort);
795*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionExpectFail(kStunAddressPortAndMore1);
796*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionExpectFail(kStunAddressPortAndMore2);
797*d9f75844SAndroid Build Coastguard Worker
798*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithIceServer(kTurnIceServerUri, kTurnUsername,
799*d9f75844SAndroid Build Coastguard Worker kTurnPassword);
800*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, port_allocator_->stun_servers().size());
801*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, port_allocator_->turn_servers().size());
802*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(kTurnUsername,
803*d9f75844SAndroid Build Coastguard Worker port_allocator_->turn_servers()[0].credentials.username);
804*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(kTurnPassword,
805*d9f75844SAndroid Build Coastguard Worker port_allocator_->turn_servers()[0].credentials.password);
806*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(kTurnHostname,
807*d9f75844SAndroid Build Coastguard Worker port_allocator_->turn_servers()[0].ports[0].address.hostname());
808*d9f75844SAndroid Build Coastguard Worker }
809*d9f75844SAndroid Build Coastguard Worker
ReleasePeerConnection()810*d9f75844SAndroid Build Coastguard Worker void ReleasePeerConnection() {
811*d9f75844SAndroid Build Coastguard Worker pc_ = nullptr;
812*d9f75844SAndroid Build Coastguard Worker observer_.SetPeerConnectionInterface(nullptr);
813*d9f75844SAndroid Build Coastguard Worker }
814*d9f75844SAndroid Build Coastguard Worker
CreateVideoTrack(const std::string & label)815*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
816*d9f75844SAndroid Build Coastguard Worker const std::string& label) {
817*d9f75844SAndroid Build Coastguard Worker return pc_factory_->CreateVideoTrack(label,
818*d9f75844SAndroid Build Coastguard Worker FakeVideoTrackSource::Create().get());
819*d9f75844SAndroid Build Coastguard Worker }
820*d9f75844SAndroid Build Coastguard Worker
AddVideoTrack(const std::string & track_label,const std::vector<std::string> & stream_ids={})821*d9f75844SAndroid Build Coastguard Worker void AddVideoTrack(const std::string& track_label,
822*d9f75844SAndroid Build Coastguard Worker const std::vector<std::string>& stream_ids = {}) {
823*d9f75844SAndroid Build Coastguard Worker auto sender_or_error =
824*d9f75844SAndroid Build Coastguard Worker pc_->AddTrack(CreateVideoTrack(track_label), stream_ids);
825*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
826*d9f75844SAndroid Build Coastguard Worker }
827*d9f75844SAndroid Build Coastguard Worker
AddVideoStream(const std::string & label)828*d9f75844SAndroid Build Coastguard Worker void AddVideoStream(const std::string& label) {
829*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamInterface> stream(
830*d9f75844SAndroid Build Coastguard Worker pc_factory_->CreateLocalMediaStream(label));
831*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(CreateVideoTrack(label + "v0"));
832*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pc_->AddStream(stream.get()));
833*d9f75844SAndroid Build Coastguard Worker }
834*d9f75844SAndroid Build Coastguard Worker
CreateAudioTrack(const std::string & label)835*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
836*d9f75844SAndroid Build Coastguard Worker const std::string& label) {
837*d9f75844SAndroid Build Coastguard Worker return pc_factory_->CreateAudioTrack(label, nullptr);
838*d9f75844SAndroid Build Coastguard Worker }
839*d9f75844SAndroid Build Coastguard Worker
AddAudioTrack(const std::string & track_label,const std::vector<std::string> & stream_ids={})840*d9f75844SAndroid Build Coastguard Worker void AddAudioTrack(const std::string& track_label,
841*d9f75844SAndroid Build Coastguard Worker const std::vector<std::string>& stream_ids = {}) {
842*d9f75844SAndroid Build Coastguard Worker auto sender_or_error =
843*d9f75844SAndroid Build Coastguard Worker pc_->AddTrack(CreateAudioTrack(track_label), stream_ids);
844*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(RTCErrorType::NONE, sender_or_error.error().type());
845*d9f75844SAndroid Build Coastguard Worker }
846*d9f75844SAndroid Build Coastguard Worker
AddAudioStream(const std::string & label)847*d9f75844SAndroid Build Coastguard Worker void AddAudioStream(const std::string& label) {
848*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamInterface> stream(
849*d9f75844SAndroid Build Coastguard Worker pc_factory_->CreateLocalMediaStream(label));
850*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(CreateAudioTrack(label + "a0"));
851*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pc_->AddStream(stream.get()));
852*d9f75844SAndroid Build Coastguard Worker }
853*d9f75844SAndroid Build Coastguard Worker
AddAudioVideoStream(const std::string & stream_id,const std::string & audio_track_label,const std::string & video_track_label)854*d9f75844SAndroid Build Coastguard Worker void AddAudioVideoStream(const std::string& stream_id,
855*d9f75844SAndroid Build Coastguard Worker const std::string& audio_track_label,
856*d9f75844SAndroid Build Coastguard Worker const std::string& video_track_label) {
857*d9f75844SAndroid Build Coastguard Worker // Create a local stream.
858*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamInterface> stream(
859*d9f75844SAndroid Build Coastguard Worker pc_factory_->CreateLocalMediaStream(stream_id));
860*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(CreateAudioTrack(audio_track_label));
861*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(CreateVideoTrack(video_track_label));
862*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pc_->AddStream(stream.get()));
863*d9f75844SAndroid Build Coastguard Worker }
864*d9f75844SAndroid Build Coastguard Worker
GetFirstReceiverOfType(cricket::MediaType media_type)865*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<RtpReceiverInterface> GetFirstReceiverOfType(
866*d9f75844SAndroid Build Coastguard Worker cricket::MediaType media_type) {
867*d9f75844SAndroid Build Coastguard Worker for (auto receiver : pc_->GetReceivers()) {
868*d9f75844SAndroid Build Coastguard Worker if (receiver->media_type() == media_type) {
869*d9f75844SAndroid Build Coastguard Worker return receiver;
870*d9f75844SAndroid Build Coastguard Worker }
871*d9f75844SAndroid Build Coastguard Worker }
872*d9f75844SAndroid Build Coastguard Worker return nullptr;
873*d9f75844SAndroid Build Coastguard Worker }
874*d9f75844SAndroid Build Coastguard Worker
DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface> * desc,const RTCOfferAnswerOptions * options,bool offer)875*d9f75844SAndroid Build Coastguard Worker bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
876*d9f75844SAndroid Build Coastguard Worker const RTCOfferAnswerOptions* options,
877*d9f75844SAndroid Build Coastguard Worker bool offer) {
878*d9f75844SAndroid Build Coastguard Worker auto observer =
879*d9f75844SAndroid Build Coastguard Worker rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
880*d9f75844SAndroid Build Coastguard Worker if (offer) {
881*d9f75844SAndroid Build Coastguard Worker pc_->CreateOffer(observer.get(),
882*d9f75844SAndroid Build Coastguard Worker options ? *options : RTCOfferAnswerOptions());
883*d9f75844SAndroid Build Coastguard Worker } else {
884*d9f75844SAndroid Build Coastguard Worker pc_->CreateAnswer(observer.get(),
885*d9f75844SAndroid Build Coastguard Worker options ? *options : RTCOfferAnswerOptions());
886*d9f75844SAndroid Build Coastguard Worker }
887*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
888*d9f75844SAndroid Build Coastguard Worker *desc = observer->MoveDescription();
889*d9f75844SAndroid Build Coastguard Worker return observer->result();
890*d9f75844SAndroid Build Coastguard Worker }
891*d9f75844SAndroid Build Coastguard Worker
DoCreateOffer(std::unique_ptr<SessionDescriptionInterface> * desc,const RTCOfferAnswerOptions * options)892*d9f75844SAndroid Build Coastguard Worker bool DoCreateOffer(std::unique_ptr<SessionDescriptionInterface>* desc,
893*d9f75844SAndroid Build Coastguard Worker const RTCOfferAnswerOptions* options) {
894*d9f75844SAndroid Build Coastguard Worker return DoCreateOfferAnswer(desc, options, true);
895*d9f75844SAndroid Build Coastguard Worker }
896*d9f75844SAndroid Build Coastguard Worker
DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface> * desc,const RTCOfferAnswerOptions * options)897*d9f75844SAndroid Build Coastguard Worker bool DoCreateAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
898*d9f75844SAndroid Build Coastguard Worker const RTCOfferAnswerOptions* options) {
899*d9f75844SAndroid Build Coastguard Worker return DoCreateOfferAnswer(desc, options, false);
900*d9f75844SAndroid Build Coastguard Worker }
901*d9f75844SAndroid Build Coastguard Worker
DoSetSessionDescription(std::unique_ptr<SessionDescriptionInterface> desc,bool local)902*d9f75844SAndroid Build Coastguard Worker bool DoSetSessionDescription(
903*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> desc,
904*d9f75844SAndroid Build Coastguard Worker bool local) {
905*d9f75844SAndroid Build Coastguard Worker auto observer = rtc::make_ref_counted<MockSetSessionDescriptionObserver>();
906*d9f75844SAndroid Build Coastguard Worker if (local) {
907*d9f75844SAndroid Build Coastguard Worker pc_->SetLocalDescription(observer.get(), desc.release());
908*d9f75844SAndroid Build Coastguard Worker } else {
909*d9f75844SAndroid Build Coastguard Worker pc_->SetRemoteDescription(observer.get(), desc.release());
910*d9f75844SAndroid Build Coastguard Worker }
911*d9f75844SAndroid Build Coastguard Worker if (pc_->signaling_state() != PeerConnectionInterface::kClosed) {
912*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
913*d9f75844SAndroid Build Coastguard Worker }
914*d9f75844SAndroid Build Coastguard Worker return observer->result();
915*d9f75844SAndroid Build Coastguard Worker }
916*d9f75844SAndroid Build Coastguard Worker
DoSetLocalDescription(std::unique_ptr<SessionDescriptionInterface> desc)917*d9f75844SAndroid Build Coastguard Worker bool DoSetLocalDescription(
918*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> desc) {
919*d9f75844SAndroid Build Coastguard Worker return DoSetSessionDescription(std::move(desc), true);
920*d9f75844SAndroid Build Coastguard Worker }
921*d9f75844SAndroid Build Coastguard Worker
DoSetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc)922*d9f75844SAndroid Build Coastguard Worker bool DoSetRemoteDescription(
923*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> desc) {
924*d9f75844SAndroid Build Coastguard Worker return DoSetSessionDescription(std::move(desc), false);
925*d9f75844SAndroid Build Coastguard Worker }
926*d9f75844SAndroid Build Coastguard Worker
927*d9f75844SAndroid Build Coastguard Worker // Calls PeerConnection::GetStats and check the return value.
928*d9f75844SAndroid Build Coastguard Worker // It does not verify the values in the StatReports since a RTCP packet might
929*d9f75844SAndroid Build Coastguard Worker // be required.
DoGetStats(MediaStreamTrackInterface * track)930*d9f75844SAndroid Build Coastguard Worker bool DoGetStats(MediaStreamTrackInterface* track) {
931*d9f75844SAndroid Build Coastguard Worker auto observer = rtc::make_ref_counted<MockStatsObserver>();
932*d9f75844SAndroid Build Coastguard Worker if (!pc_->GetStats(observer.get(), track,
933*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::kStatsOutputLevelStandard))
934*d9f75844SAndroid Build Coastguard Worker return false;
935*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE_WAIT(observer->called(), kTimeout);
936*d9f75844SAndroid Build Coastguard Worker return observer->called();
937*d9f75844SAndroid Build Coastguard Worker }
938*d9f75844SAndroid Build Coastguard Worker
939*d9f75844SAndroid Build Coastguard Worker // Call the standards-compliant GetStats function.
DoGetRTCStats()940*d9f75844SAndroid Build Coastguard Worker bool DoGetRTCStats() {
941*d9f75844SAndroid Build Coastguard Worker auto callback =
942*d9f75844SAndroid Build Coastguard Worker rtc::make_ref_counted<webrtc::MockRTCStatsCollectorCallback>();
943*d9f75844SAndroid Build Coastguard Worker pc_->GetStats(callback.get());
944*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE_WAIT(callback->called(), kTimeout);
945*d9f75844SAndroid Build Coastguard Worker return callback->called();
946*d9f75844SAndroid Build Coastguard Worker }
947*d9f75844SAndroid Build Coastguard Worker
InitiateCall()948*d9f75844SAndroid Build Coastguard Worker void InitiateCall() {
949*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
950*d9f75844SAndroid Build Coastguard Worker // Create a local stream with audio&video tracks.
951*d9f75844SAndroid Build Coastguard Worker if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
952*d9f75844SAndroid Build Coastguard Worker AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
953*d9f75844SAndroid Build Coastguard Worker } else {
954*d9f75844SAndroid Build Coastguard Worker // Unified Plan does not support AddStream, so just add an audio and video
955*d9f75844SAndroid Build Coastguard Worker // track.
956*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[0], {kStreamId1});
957*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0], {kStreamId1});
958*d9f75844SAndroid Build Coastguard Worker }
959*d9f75844SAndroid Build Coastguard Worker CreateOfferReceiveAnswer();
960*d9f75844SAndroid Build Coastguard Worker }
961*d9f75844SAndroid Build Coastguard Worker
962*d9f75844SAndroid Build Coastguard Worker // Verify that RTP Header extensions has been negotiated for audio and video.
VerifyRemoteRtpHeaderExtensions()963*d9f75844SAndroid Build Coastguard Worker void VerifyRemoteRtpHeaderExtensions() {
964*d9f75844SAndroid Build Coastguard Worker const cricket::MediaContentDescription* desc =
965*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstAudioContentDescription(
966*d9f75844SAndroid Build Coastguard Worker pc_->remote_description()->description());
967*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(desc != nullptr);
968*d9f75844SAndroid Build Coastguard Worker EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
969*d9f75844SAndroid Build Coastguard Worker
970*d9f75844SAndroid Build Coastguard Worker desc = cricket::GetFirstVideoContentDescription(
971*d9f75844SAndroid Build Coastguard Worker pc_->remote_description()->description());
972*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(desc != nullptr);
973*d9f75844SAndroid Build Coastguard Worker EXPECT_GT(desc->rtp_header_extensions().size(), 0u);
974*d9f75844SAndroid Build Coastguard Worker }
975*d9f75844SAndroid Build Coastguard Worker
CreateOfferAsRemoteDescription()976*d9f75844SAndroid Build Coastguard Worker void CreateOfferAsRemoteDescription() {
977*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
978*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
979*d9f75844SAndroid Build Coastguard Worker std::string sdp;
980*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(offer->ToString(&sdp));
981*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> remote_offer(
982*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
983*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
984*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
985*d9f75844SAndroid Build Coastguard Worker }
986*d9f75844SAndroid Build Coastguard Worker
CreateAndSetRemoteOffer(const std::string & sdp)987*d9f75844SAndroid Build Coastguard Worker void CreateAndSetRemoteOffer(const std::string& sdp) {
988*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> remote_offer(
989*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
990*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
991*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
992*d9f75844SAndroid Build Coastguard Worker }
993*d9f75844SAndroid Build Coastguard Worker
CreateAnswerAsLocalDescription()994*d9f75844SAndroid Build Coastguard Worker void CreateAnswerAsLocalDescription() {
995*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
996*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
997*d9f75844SAndroid Build Coastguard Worker
998*d9f75844SAndroid Build Coastguard Worker // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
999*d9f75844SAndroid Build Coastguard Worker // audio codec change, even if the parameter has nothing to do with
1000*d9f75844SAndroid Build Coastguard Worker // receiving. Not all parameters are serialized to SDP.
1001*d9f75844SAndroid Build Coastguard Worker // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1002*d9f75844SAndroid Build Coastguard Worker // the SessionDescription, it is necessary to do that here to in order to
1003*d9f75844SAndroid Build Coastguard Worker // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1004*d9f75844SAndroid Build Coastguard Worker // https://code.google.com/p/webrtc/issues/detail?id=1356
1005*d9f75844SAndroid Build Coastguard Worker std::string sdp;
1006*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(answer->ToString(&sdp));
1007*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> new_answer(
1008*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
1009*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(new_answer)));
1010*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1011*d9f75844SAndroid Build Coastguard Worker }
1012*d9f75844SAndroid Build Coastguard Worker
CreatePrAnswerAsLocalDescription()1013*d9f75844SAndroid Build Coastguard Worker void CreatePrAnswerAsLocalDescription() {
1014*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
1015*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
1016*d9f75844SAndroid Build Coastguard Worker
1017*d9f75844SAndroid Build Coastguard Worker std::string sdp;
1018*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(answer->ToString(&sdp));
1019*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> pr_answer(
1020*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
1021*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(pr_answer)));
1022*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kHaveLocalPrAnswer, observer_.state_);
1023*d9f75844SAndroid Build Coastguard Worker }
1024*d9f75844SAndroid Build Coastguard Worker
CreateOfferReceiveAnswer()1025*d9f75844SAndroid Build Coastguard Worker void CreateOfferReceiveAnswer() {
1026*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
1027*d9f75844SAndroid Build Coastguard Worker std::string sdp;
1028*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1029*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsRemoteDescription(sdp);
1030*d9f75844SAndroid Build Coastguard Worker }
1031*d9f75844SAndroid Build Coastguard Worker
CreateOfferAsLocalDescription()1032*d9f75844SAndroid Build Coastguard Worker void CreateOfferAsLocalDescription() {
1033*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1034*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1035*d9f75844SAndroid Build Coastguard Worker // TODO(perkj): Currently SetLocalDescription fails if any parameters in an
1036*d9f75844SAndroid Build Coastguard Worker // audio codec change, even if the parameter has nothing to do with
1037*d9f75844SAndroid Build Coastguard Worker // receiving. Not all parameters are serialized to SDP.
1038*d9f75844SAndroid Build Coastguard Worker // Since CreatePrAnswerAsLocalDescription serialize/deserialize
1039*d9f75844SAndroid Build Coastguard Worker // the SessionDescription, it is necessary to do that here to in order to
1040*d9f75844SAndroid Build Coastguard Worker // get ReceiveOfferCreatePrAnswerAndAnswer and RenegotiateAudioOnly to pass.
1041*d9f75844SAndroid Build Coastguard Worker // https://code.google.com/p/webrtc/issues/detail?id=1356
1042*d9f75844SAndroid Build Coastguard Worker std::string sdp;
1043*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(offer->ToString(&sdp));
1044*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> new_offer(
1045*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
1046*d9f75844SAndroid Build Coastguard Worker
1047*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
1048*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1049*d9f75844SAndroid Build Coastguard Worker // Wait for the ice_complete message, so that SDP will have candidates.
1050*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
1051*d9f75844SAndroid Build Coastguard Worker }
1052*d9f75844SAndroid Build Coastguard Worker
CreateAnswerAsRemoteDescription(const std::string & sdp)1053*d9f75844SAndroid Build Coastguard Worker void CreateAnswerAsRemoteDescription(const std::string& sdp) {
1054*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer(
1055*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
1056*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(answer);
1057*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
1058*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1059*d9f75844SAndroid Build Coastguard Worker }
1060*d9f75844SAndroid Build Coastguard Worker
CreatePrAnswerAndAnswerAsRemoteDescription(const std::string & sdp)1061*d9f75844SAndroid Build Coastguard Worker void CreatePrAnswerAndAnswerAsRemoteDescription(const std::string& sdp) {
1062*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> pr_answer(
1063*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
1064*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pr_answer);
1065*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(pr_answer)));
1066*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kHaveRemotePrAnswer, observer_.state_);
1067*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer(
1068*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
1069*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(answer);
1070*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(answer)));
1071*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kStable, observer_.state_);
1072*d9f75844SAndroid Build Coastguard Worker }
1073*d9f75844SAndroid Build Coastguard Worker
1074*d9f75844SAndroid Build Coastguard Worker // Waits until a remote stream with the given id is signaled. This helper
1075*d9f75844SAndroid Build Coastguard Worker // function will verify both OnAddTrack and OnAddStream (Plan B only) are
1076*d9f75844SAndroid Build Coastguard Worker // called with the given stream id and expected number of tracks.
WaitAndVerifyOnAddStream(const std::string & stream_id,int expected_num_tracks)1077*d9f75844SAndroid Build Coastguard Worker void WaitAndVerifyOnAddStream(const std::string& stream_id,
1078*d9f75844SAndroid Build Coastguard Worker int expected_num_tracks) {
1079*d9f75844SAndroid Build Coastguard Worker // Verify that both OnAddStream and OnAddTrack are called.
1080*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(stream_id, observer_.GetLastAddedStreamId(), kTimeout);
1081*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(expected_num_tracks,
1082*d9f75844SAndroid Build Coastguard Worker observer_.CountAddTrackEventsForStream(stream_id), kTimeout);
1083*d9f75844SAndroid Build Coastguard Worker }
1084*d9f75844SAndroid Build Coastguard Worker
1085*d9f75844SAndroid Build Coastguard Worker // Creates an offer and applies it as a local session description.
1086*d9f75844SAndroid Build Coastguard Worker // Creates an answer with the same SDP an the offer but removes all lines
1087*d9f75844SAndroid Build Coastguard Worker // that start with a:ssrc"
CreateOfferReceiveAnswerWithoutSsrc()1088*d9f75844SAndroid Build Coastguard Worker void CreateOfferReceiveAnswerWithoutSsrc() {
1089*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
1090*d9f75844SAndroid Build Coastguard Worker std::string sdp;
1091*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
1092*d9f75844SAndroid Build Coastguard Worker SetSsrcToZero(&sdp);
1093*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsRemoteDescription(sdp);
1094*d9f75844SAndroid Build Coastguard Worker }
1095*d9f75844SAndroid Build Coastguard Worker
1096*d9f75844SAndroid Build Coastguard Worker // This function creates a MediaStream with label kStreams[0] and
1097*d9f75844SAndroid Build Coastguard Worker // `number_of_audio_tracks` and `number_of_video_tracks` tracks and the
1098*d9f75844SAndroid Build Coastguard Worker // corresponding SessionDescriptionInterface. The SessionDescriptionInterface
1099*d9f75844SAndroid Build Coastguard Worker // is returned and the MediaStream is stored in
1100*d9f75844SAndroid Build Coastguard Worker // `reference_collection_`
1101*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface>
CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,size_t number_of_video_tracks)1102*d9f75844SAndroid Build Coastguard Worker CreateSessionDescriptionAndReference(size_t number_of_audio_tracks,
1103*d9f75844SAndroid Build Coastguard Worker size_t number_of_video_tracks) {
1104*d9f75844SAndroid Build Coastguard Worker EXPECT_LE(number_of_audio_tracks, 2u);
1105*d9f75844SAndroid Build Coastguard Worker EXPECT_LE(number_of_video_tracks, 2u);
1106*d9f75844SAndroid Build Coastguard Worker
1107*d9f75844SAndroid Build Coastguard Worker reference_collection_ = StreamCollection::Create();
1108*d9f75844SAndroid Build Coastguard Worker std::string sdp_ms1 = std::string(kSdpStringInit);
1109*d9f75844SAndroid Build Coastguard Worker
1110*d9f75844SAndroid Build Coastguard Worker std::string mediastream_id = kStreams[0];
1111*d9f75844SAndroid Build Coastguard Worker
1112*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::MediaStreamInterface> stream(
1113*d9f75844SAndroid Build Coastguard Worker webrtc::MediaStream::Create(mediastream_id));
1114*d9f75844SAndroid Build Coastguard Worker reference_collection_->AddStream(stream);
1115*d9f75844SAndroid Build Coastguard Worker
1116*d9f75844SAndroid Build Coastguard Worker if (number_of_audio_tracks > 0) {
1117*d9f75844SAndroid Build Coastguard Worker sdp_ms1 += std::string(kSdpStringAudio);
1118*d9f75844SAndroid Build Coastguard Worker sdp_ms1 += std::string(kSdpStringMs1Audio0);
1119*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[0], stream.get());
1120*d9f75844SAndroid Build Coastguard Worker }
1121*d9f75844SAndroid Build Coastguard Worker if (number_of_audio_tracks > 1) {
1122*d9f75844SAndroid Build Coastguard Worker sdp_ms1 += kSdpStringMs1Audio1;
1123*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[1], stream.get());
1124*d9f75844SAndroid Build Coastguard Worker }
1125*d9f75844SAndroid Build Coastguard Worker
1126*d9f75844SAndroid Build Coastguard Worker if (number_of_video_tracks > 0) {
1127*d9f75844SAndroid Build Coastguard Worker sdp_ms1 += std::string(kSdpStringVideo);
1128*d9f75844SAndroid Build Coastguard Worker sdp_ms1 += std::string(kSdpStringMs1Video0);
1129*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0], stream.get());
1130*d9f75844SAndroid Build Coastguard Worker }
1131*d9f75844SAndroid Build Coastguard Worker if (number_of_video_tracks > 1) {
1132*d9f75844SAndroid Build Coastguard Worker sdp_ms1 += kSdpStringMs1Video1;
1133*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[1], stream.get());
1134*d9f75844SAndroid Build Coastguard Worker }
1135*d9f75844SAndroid Build Coastguard Worker
1136*d9f75844SAndroid Build Coastguard Worker return std::unique_ptr<SessionDescriptionInterface>(
1137*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, sdp_ms1));
1138*d9f75844SAndroid Build Coastguard Worker }
1139*d9f75844SAndroid Build Coastguard Worker
AddAudioTrack(const std::string & track_id,MediaStreamInterface * stream)1140*d9f75844SAndroid Build Coastguard Worker void AddAudioTrack(const std::string& track_id,
1141*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* stream) {
1142*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
1143*d9f75844SAndroid Build Coastguard Worker webrtc::AudioTrack::Create(track_id, nullptr));
1144*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(stream->AddTrack(audio_track));
1145*d9f75844SAndroid Build Coastguard Worker }
1146*d9f75844SAndroid Build Coastguard Worker
AddVideoTrack(const std::string & track_id,MediaStreamInterface * stream)1147*d9f75844SAndroid Build Coastguard Worker void AddVideoTrack(const std::string& track_id,
1148*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* stream) {
1149*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track(
1150*d9f75844SAndroid Build Coastguard Worker webrtc::VideoTrack::Create(track_id,
1151*d9f75844SAndroid Build Coastguard Worker webrtc::FakeVideoTrackSource::Create(),
1152*d9f75844SAndroid Build Coastguard Worker rtc::Thread::Current()));
1153*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(stream->AddTrack(video_track));
1154*d9f75844SAndroid Build Coastguard Worker }
1155*d9f75844SAndroid Build Coastguard Worker
CreateOfferWithOneAudioTrack()1156*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioTrack() {
1157*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1158*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[0]);
1159*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1160*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1161*d9f75844SAndroid Build Coastguard Worker return offer;
1162*d9f75844SAndroid Build Coastguard Worker }
1163*d9f75844SAndroid Build Coastguard Worker
CreateOfferWithOneAudioStream()1164*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOneAudioStream() {
1165*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1166*d9f75844SAndroid Build Coastguard Worker AddAudioStream(kStreamId1);
1167*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1168*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1169*d9f75844SAndroid Build Coastguard Worker return offer;
1170*d9f75844SAndroid Build Coastguard Worker }
1171*d9f75844SAndroid Build Coastguard Worker
CreateAnswerWithOneAudioTrack()1172*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> CreateAnswerWithOneAudioTrack() {
1173*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioTrack()));
1174*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
1175*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1176*d9f75844SAndroid Build Coastguard Worker return answer;
1177*d9f75844SAndroid Build Coastguard Worker }
1178*d9f75844SAndroid Build Coastguard Worker
1179*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface>
CreateAnswerWithOneAudioStream()1180*d9f75844SAndroid Build Coastguard Worker CreateAnswerWithOneAudioStream() {
1181*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(CreateOfferWithOneAudioStream()));
1182*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
1183*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1184*d9f75844SAndroid Build Coastguard Worker return answer;
1185*d9f75844SAndroid Build Coastguard Worker }
1186*d9f75844SAndroid Build Coastguard Worker
GetFirstAudioStreamCname(const SessionDescriptionInterface * desc)1187*d9f75844SAndroid Build Coastguard Worker const std::string& GetFirstAudioStreamCname(
1188*d9f75844SAndroid Build Coastguard Worker const SessionDescriptionInterface* desc) {
1189*d9f75844SAndroid Build Coastguard Worker const cricket::AudioContentDescription* audio_desc =
1190*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstAudioContentDescription(desc->description());
1191*d9f75844SAndroid Build Coastguard Worker return audio_desc->streams()[0].cname;
1192*d9f75844SAndroid Build Coastguard Worker }
1193*d9f75844SAndroid Build Coastguard Worker
CreateOfferWithOptions(const RTCOfferAnswerOptions & offer_answer_options)1194*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> CreateOfferWithOptions(
1195*d9f75844SAndroid Build Coastguard Worker const RTCOfferAnswerOptions& offer_answer_options) {
1196*d9f75844SAndroid Build Coastguard Worker RTC_DCHECK(pc_);
1197*d9f75844SAndroid Build Coastguard Worker auto observer =
1198*d9f75844SAndroid Build Coastguard Worker rtc::make_ref_counted<MockCreateSessionDescriptionObserver>();
1199*d9f75844SAndroid Build Coastguard Worker pc_->CreateOffer(observer.get(), offer_answer_options);
1200*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(true, observer->called(), kTimeout);
1201*d9f75844SAndroid Build Coastguard Worker return observer->MoveDescription();
1202*d9f75844SAndroid Build Coastguard Worker }
1203*d9f75844SAndroid Build Coastguard Worker
CreateOfferWithOptionsAsRemoteDescription(std::unique_ptr<SessionDescriptionInterface> * desc,const RTCOfferAnswerOptions & offer_answer_options)1204*d9f75844SAndroid Build Coastguard Worker void CreateOfferWithOptionsAsRemoteDescription(
1205*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface>* desc,
1206*d9f75844SAndroid Build Coastguard Worker const RTCOfferAnswerOptions& offer_answer_options) {
1207*d9f75844SAndroid Build Coastguard Worker *desc = CreateOfferWithOptions(offer_answer_options);
1208*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(desc != nullptr);
1209*d9f75844SAndroid Build Coastguard Worker std::string sdp;
1210*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE((*desc)->ToString(&sdp));
1211*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> remote_offer(
1212*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
1213*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
1214*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kHaveRemoteOffer, observer_.state_);
1215*d9f75844SAndroid Build Coastguard Worker }
1216*d9f75844SAndroid Build Coastguard Worker
CreateOfferWithOptionsAsLocalDescription(std::unique_ptr<SessionDescriptionInterface> * desc,const RTCOfferAnswerOptions & offer_answer_options)1217*d9f75844SAndroid Build Coastguard Worker void CreateOfferWithOptionsAsLocalDescription(
1218*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface>* desc,
1219*d9f75844SAndroid Build Coastguard Worker const RTCOfferAnswerOptions& offer_answer_options) {
1220*d9f75844SAndroid Build Coastguard Worker *desc = CreateOfferWithOptions(offer_answer_options);
1221*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(desc != nullptr);
1222*d9f75844SAndroid Build Coastguard Worker std::string sdp;
1223*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE((*desc)->ToString(&sdp));
1224*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> new_offer(
1225*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
1226*d9f75844SAndroid Build Coastguard Worker
1227*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(new_offer)));
1228*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kHaveLocalOffer, observer_.state_);
1229*d9f75844SAndroid Build Coastguard Worker }
1230*d9f75844SAndroid Build Coastguard Worker
HasCNCodecs(const cricket::ContentInfo * content)1231*d9f75844SAndroid Build Coastguard Worker bool HasCNCodecs(const cricket::ContentInfo* content) {
1232*d9f75844SAndroid Build Coastguard Worker RTC_DCHECK(content);
1233*d9f75844SAndroid Build Coastguard Worker RTC_DCHECK(content->media_description());
1234*d9f75844SAndroid Build Coastguard Worker for (const cricket::AudioCodec& codec :
1235*d9f75844SAndroid Build Coastguard Worker content->media_description()->as_audio()->codecs()) {
1236*d9f75844SAndroid Build Coastguard Worker if (codec.name == "CN") {
1237*d9f75844SAndroid Build Coastguard Worker return true;
1238*d9f75844SAndroid Build Coastguard Worker }
1239*d9f75844SAndroid Build Coastguard Worker }
1240*d9f75844SAndroid Build Coastguard Worker return false;
1241*d9f75844SAndroid Build Coastguard Worker }
1242*d9f75844SAndroid Build Coastguard Worker
GetSdpStringWithStream1() const1243*d9f75844SAndroid Build Coastguard Worker const char* GetSdpStringWithStream1() const {
1244*d9f75844SAndroid Build Coastguard Worker if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
1245*d9f75844SAndroid Build Coastguard Worker return kSdpStringWithStream1PlanB;
1246*d9f75844SAndroid Build Coastguard Worker } else {
1247*d9f75844SAndroid Build Coastguard Worker return kSdpStringWithStream1UnifiedPlan;
1248*d9f75844SAndroid Build Coastguard Worker }
1249*d9f75844SAndroid Build Coastguard Worker }
1250*d9f75844SAndroid Build Coastguard Worker
GetSdpStringWithStream1And2() const1251*d9f75844SAndroid Build Coastguard Worker const char* GetSdpStringWithStream1And2() const {
1252*d9f75844SAndroid Build Coastguard Worker if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
1253*d9f75844SAndroid Build Coastguard Worker return kSdpStringWithStream1And2PlanB;
1254*d9f75844SAndroid Build Coastguard Worker } else {
1255*d9f75844SAndroid Build Coastguard Worker return kSdpStringWithStream1And2UnifiedPlan;
1256*d9f75844SAndroid Build Coastguard Worker }
1257*d9f75844SAndroid Build Coastguard Worker }
1258*d9f75844SAndroid Build Coastguard Worker
socket_server() const1259*d9f75844SAndroid Build Coastguard Worker rtc::SocketServer* socket_server() const { return vss_.get(); }
1260*d9f75844SAndroid Build Coastguard Worker
1261*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<rtc::VirtualSocketServer> vss_;
1262*d9f75844SAndroid Build Coastguard Worker rtc::AutoSocketServerThread main_;
1263*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
1264*d9f75844SAndroid Build Coastguard Worker cricket::FakePortAllocator* port_allocator_ = nullptr;
1265*d9f75844SAndroid Build Coastguard Worker FakeRTCCertificateGenerator* fake_certificate_generator_ = nullptr;
1266*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
1267*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_;
1268*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<PeerConnectionInterface> pc_;
1269*d9f75844SAndroid Build Coastguard Worker MockPeerConnectionObserver observer_;
1270*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<StreamCollection> reference_collection_;
1271*d9f75844SAndroid Build Coastguard Worker const SdpSemantics sdp_semantics_;
1272*d9f75844SAndroid Build Coastguard Worker };
1273*d9f75844SAndroid Build Coastguard Worker
1274*d9f75844SAndroid Build Coastguard Worker class PeerConnectionInterfaceTest
1275*d9f75844SAndroid Build Coastguard Worker : public PeerConnectionInterfaceBaseTest,
1276*d9f75844SAndroid Build Coastguard Worker public ::testing::WithParamInterface<SdpSemantics> {
1277*d9f75844SAndroid Build Coastguard Worker protected:
PeerConnectionInterfaceTest()1278*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterfaceTest() : PeerConnectionInterfaceBaseTest(GetParam()) {}
1279*d9f75844SAndroid Build Coastguard Worker };
1280*d9f75844SAndroid Build Coastguard Worker
1281*d9f75844SAndroid Build Coastguard Worker class PeerConnectionInterfaceTestPlanB
1282*d9f75844SAndroid Build Coastguard Worker : public PeerConnectionInterfaceBaseTest {
1283*d9f75844SAndroid Build Coastguard Worker protected:
PeerConnectionInterfaceTestPlanB()1284*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterfaceTestPlanB()
1285*d9f75844SAndroid Build Coastguard Worker : PeerConnectionInterfaceBaseTest(SdpSemantics::kPlanB_DEPRECATED) {}
1286*d9f75844SAndroid Build Coastguard Worker };
1287*d9f75844SAndroid Build Coastguard Worker
1288*d9f75844SAndroid Build Coastguard Worker // Generate different CNAMEs when PeerConnections are created.
1289*d9f75844SAndroid Build Coastguard Worker // The CNAMEs are expected to be generated randomly. It is possible
1290*d9f75844SAndroid Build Coastguard Worker // that the test fails, though the possibility is very low.
TEST_P(PeerConnectionInterfaceTest,CnameGenerationInOffer)1291*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CnameGenerationInOffer) {
1292*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer1 =
1293*d9f75844SAndroid Build Coastguard Worker CreateOfferWithOneAudioTrack();
1294*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer2 =
1295*d9f75844SAndroid Build Coastguard Worker CreateOfferWithOneAudioTrack();
1296*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(GetFirstAudioStreamCname(offer1.get()),
1297*d9f75844SAndroid Build Coastguard Worker GetFirstAudioStreamCname(offer2.get()));
1298*d9f75844SAndroid Build Coastguard Worker }
1299*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,CnameGenerationInAnswer)1300*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CnameGenerationInAnswer) {
1301*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer1 =
1302*d9f75844SAndroid Build Coastguard Worker CreateAnswerWithOneAudioTrack();
1303*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer2 =
1304*d9f75844SAndroid Build Coastguard Worker CreateAnswerWithOneAudioTrack();
1305*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(GetFirstAudioStreamCname(answer1.get()),
1306*d9f75844SAndroid Build Coastguard Worker GetFirstAudioStreamCname(answer2.get()));
1307*d9f75844SAndroid Build Coastguard Worker }
1308*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,CreatePeerConnectionWithDifferentConfigurations)1309*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
1310*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithDifferentConfigurations) {
1311*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithDifferentConfigurations();
1312*d9f75844SAndroid Build Coastguard Worker }
1313*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,CreatePeerConnectionWithDifferentIceTransportsTypes)1314*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
1315*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithDifferentIceTransportsTypes) {
1316*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNone);
1317*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(cricket::CF_NONE, port_allocator_->candidate_filter());
1318*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kRelay);
1319*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
1320*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kNoHost);
1321*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(cricket::CF_ALL & ~cricket::CF_HOST,
1322*d9f75844SAndroid Build Coastguard Worker port_allocator_->candidate_filter());
1323*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithIceTransportsType(PeerConnectionInterface::kAll);
1324*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(cricket::CF_ALL, port_allocator_->candidate_filter());
1325*d9f75844SAndroid Build Coastguard Worker }
1326*d9f75844SAndroid Build Coastguard Worker
1327*d9f75844SAndroid Build Coastguard Worker // Test that when a PeerConnection is created with a nonzero candidate pool
1328*d9f75844SAndroid Build Coastguard Worker // size, the pooled PortAllocatorSession is created with all the attributes
1329*d9f75844SAndroid Build Coastguard Worker // in the RTCConfiguration.
TEST_P(PeerConnectionInterfaceTest,CreatePeerConnectionWithPooledCandidates)1330*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
1331*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
1332*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
1333*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::IceServer server;
1334*d9f75844SAndroid Build Coastguard Worker server.uri = kStunAddressOnly;
1335*d9f75844SAndroid Build Coastguard Worker config.servers.push_back(server);
1336*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kRelay;
1337*d9f75844SAndroid Build Coastguard Worker config.tcp_candidate_policy =
1338*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1339*d9f75844SAndroid Build Coastguard Worker config.candidate_network_policy =
1340*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1341*d9f75844SAndroid Build Coastguard Worker config.ice_candidate_pool_size = 1;
1342*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
1343*d9f75844SAndroid Build Coastguard Worker
1344*d9f75844SAndroid Build Coastguard Worker const cricket::FakePortAllocatorSession* session =
1345*d9f75844SAndroid Build Coastguard Worker static_cast<const cricket::FakePortAllocatorSession*>(
1346*d9f75844SAndroid Build Coastguard Worker port_allocator_->GetPooledSession());
1347*d9f75844SAndroid Build Coastguard Worker ASSERT_NE(nullptr, session);
1348*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1UL, session->stun_servers().size());
1349*d9f75844SAndroid Build Coastguard Worker EXPECT_LT(0U, session->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1350*d9f75844SAndroid Build Coastguard Worker EXPECT_LT(0U,
1351*d9f75844SAndroid Build Coastguard Worker session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1352*d9f75844SAndroid Build Coastguard Worker }
1353*d9f75844SAndroid Build Coastguard Worker
1354*d9f75844SAndroid Build Coastguard Worker // Test that network-related RTCConfiguration members are applied to the
1355*d9f75844SAndroid Build Coastguard Worker // PortAllocator when CreatePeerConnection is called. Specifically:
1356*d9f75844SAndroid Build Coastguard Worker // - disable_ipv6_on_wifi
1357*d9f75844SAndroid Build Coastguard Worker // - max_ipv6_networks
1358*d9f75844SAndroid Build Coastguard Worker // - tcp_candidate_policy
1359*d9f75844SAndroid Build Coastguard Worker // - candidate_network_policy
1360*d9f75844SAndroid Build Coastguard Worker // - prune_turn_ports
1361*d9f75844SAndroid Build Coastguard Worker //
1362*d9f75844SAndroid Build Coastguard Worker // Note that the candidate filter (RTCConfiguration::type) is already tested
1363*d9f75844SAndroid Build Coastguard Worker // above.
TEST_P(PeerConnectionInterfaceTest,CreatePeerConnectionAppliesNetworkConfigToPortAllocator)1364*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
1365*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionAppliesNetworkConfigToPortAllocator) {
1366*d9f75844SAndroid Build Coastguard Worker // Create fake port allocator.
1367*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory(
1368*d9f75844SAndroid Build Coastguard Worker new rtc::BasicPacketSocketFactory(socket_server()));
1369*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<cricket::FakePortAllocator> port_allocator(
1370*d9f75844SAndroid Build Coastguard Worker new cricket::FakePortAllocator(rtc::Thread::Current(),
1371*d9f75844SAndroid Build Coastguard Worker packet_socket_factory.get()));
1372*d9f75844SAndroid Build Coastguard Worker cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
1373*d9f75844SAndroid Build Coastguard Worker
1374*d9f75844SAndroid Build Coastguard Worker // Create RTCConfiguration with some network-related fields relevant to
1375*d9f75844SAndroid Build Coastguard Worker // PortAllocator populated.
1376*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
1377*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
1378*d9f75844SAndroid Build Coastguard Worker config.disable_ipv6_on_wifi = true;
1379*d9f75844SAndroid Build Coastguard Worker config.max_ipv6_networks = 10;
1380*d9f75844SAndroid Build Coastguard Worker config.tcp_candidate_policy =
1381*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::kTcpCandidatePolicyDisabled;
1382*d9f75844SAndroid Build Coastguard Worker config.candidate_network_policy =
1383*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::kCandidateNetworkPolicyLowCost;
1384*d9f75844SAndroid Build Coastguard Worker config.prune_turn_ports = true;
1385*d9f75844SAndroid Build Coastguard Worker
1386*d9f75844SAndroid Build Coastguard Worker // Create the PC factory and PC with the above config.
1387*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
1388*d9f75844SAndroid Build Coastguard Worker webrtc::CreatePeerConnectionFactory(
1389*d9f75844SAndroid Build Coastguard Worker rtc::Thread::Current(), rtc::Thread::Current(),
1390*d9f75844SAndroid Build Coastguard Worker rtc::Thread::Current(), fake_audio_capture_module_,
1391*d9f75844SAndroid Build Coastguard Worker webrtc::CreateBuiltinAudioEncoderFactory(),
1392*d9f75844SAndroid Build Coastguard Worker webrtc::CreateBuiltinAudioDecoderFactory(),
1393*d9f75844SAndroid Build Coastguard Worker webrtc::CreateBuiltinVideoEncoderFactory(),
1394*d9f75844SAndroid Build Coastguard Worker webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */,
1395*d9f75844SAndroid Build Coastguard Worker nullptr /* audio_processing */));
1396*d9f75844SAndroid Build Coastguard Worker PeerConnectionDependencies pc_dependencies(&observer_);
1397*d9f75844SAndroid Build Coastguard Worker pc_dependencies.allocator = std::move(port_allocator);
1398*d9f75844SAndroid Build Coastguard Worker auto result = pc_factory_->CreatePeerConnectionOrError(
1399*d9f75844SAndroid Build Coastguard Worker config, std::move(pc_dependencies));
1400*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(result.ok());
1401*d9f75844SAndroid Build Coastguard Worker observer_.SetPeerConnectionInterface(result.value().get());
1402*d9f75844SAndroid Build Coastguard Worker
1403*d9f75844SAndroid Build Coastguard Worker // Now validate that the config fields set above were applied to the
1404*d9f75844SAndroid Build Coastguard Worker // PortAllocator, as flags or otherwise.
1405*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(raw_port_allocator->flags() &
1406*d9f75844SAndroid Build Coastguard Worker cricket::PORTALLOCATOR_ENABLE_IPV6_ON_WIFI);
1407*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(10, raw_port_allocator->max_ipv6_networks());
1408*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(raw_port_allocator->flags() & cricket::PORTALLOCATOR_DISABLE_TCP);
1409*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(raw_port_allocator->flags() &
1410*d9f75844SAndroid Build Coastguard Worker cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
1411*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
1412*d9f75844SAndroid Build Coastguard Worker raw_port_allocator->turn_port_prune_policy());
1413*d9f75844SAndroid Build Coastguard Worker }
1414*d9f75844SAndroid Build Coastguard Worker
1415*d9f75844SAndroid Build Coastguard Worker // Check that GetConfiguration returns the configuration the PeerConnection was
1416*d9f75844SAndroid Build Coastguard Worker // constructed with, before SetConfiguration is called.
TEST_P(PeerConnectionInterfaceTest,GetConfigurationAfterCreatePeerConnection)1417*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterCreatePeerConnection) {
1418*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
1419*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
1420*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kRelay;
1421*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
1422*d9f75844SAndroid Build Coastguard Worker
1423*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration returned_config =
1424*d9f75844SAndroid Build Coastguard Worker pc_->GetConfiguration();
1425*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1426*d9f75844SAndroid Build Coastguard Worker }
1427*d9f75844SAndroid Build Coastguard Worker
1428*d9f75844SAndroid Build Coastguard Worker // Check that GetConfiguration returns the last configuration passed into
1429*d9f75844SAndroid Build Coastguard Worker // SetConfiguration.
TEST_P(PeerConnectionInterfaceTest,GetConfigurationAfterSetConfiguration)1430*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, GetConfigurationAfterSetConfiguration) {
1431*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration starting_config;
1432*d9f75844SAndroid Build Coastguard Worker starting_config.sdp_semantics = sdp_semantics_;
1433*d9f75844SAndroid Build Coastguard Worker starting_config.bundle_policy =
1434*d9f75844SAndroid Build Coastguard Worker webrtc::PeerConnection::kBundlePolicyMaxBundle;
1435*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(starting_config);
1436*d9f75844SAndroid Build Coastguard Worker
1437*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
1438*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kRelay;
1439*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
1440*d9f75844SAndroid Build Coastguard Worker
1441*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration returned_config =
1442*d9f75844SAndroid Build Coastguard Worker pc_->GetConfiguration();
1443*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kRelay, returned_config.type);
1444*d9f75844SAndroid Build Coastguard Worker }
1445*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,SetConfigurationFailsAfterClose)1446*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetConfigurationFailsAfterClose) {
1447*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
1448*d9f75844SAndroid Build Coastguard Worker
1449*d9f75844SAndroid Build Coastguard Worker pc_->Close();
1450*d9f75844SAndroid Build Coastguard Worker
1451*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(
1452*d9f75844SAndroid Build Coastguard Worker pc_->SetConfiguration(PeerConnectionInterface::RTCConfiguration()).ok());
1453*d9f75844SAndroid Build Coastguard Worker }
1454*d9f75844SAndroid Build Coastguard Worker
TEST_F(PeerConnectionInterfaceTestPlanB,AddStreams)1455*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, AddStreams) {
1456*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1457*d9f75844SAndroid Build Coastguard Worker AddVideoStream(kStreamId1);
1458*d9f75844SAndroid Build Coastguard Worker AddAudioStream(kStreamId2);
1459*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(2u, pc_->local_streams()->count());
1460*d9f75844SAndroid Build Coastguard Worker
1461*d9f75844SAndroid Build Coastguard Worker // Test we can add multiple local streams to one peerconnection.
1462*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamInterface> stream(
1463*d9f75844SAndroid Build Coastguard Worker pc_factory_->CreateLocalMediaStream(kStreamId3));
1464*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> audio_track(
1465*d9f75844SAndroid Build Coastguard Worker pc_factory_->CreateAudioTrack(
1466*d9f75844SAndroid Build Coastguard Worker kStreamId3, static_cast<AudioSourceInterface*>(nullptr)));
1467*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(audio_track);
1468*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->AddStream(stream.get()));
1469*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(3u, pc_->local_streams()->count());
1470*d9f75844SAndroid Build Coastguard Worker
1471*d9f75844SAndroid Build Coastguard Worker // Remove the third stream.
1472*d9f75844SAndroid Build Coastguard Worker pc_->RemoveStream(pc_->local_streams()->at(2));
1473*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(2u, pc_->local_streams()->count());
1474*d9f75844SAndroid Build Coastguard Worker
1475*d9f75844SAndroid Build Coastguard Worker // Remove the second stream.
1476*d9f75844SAndroid Build Coastguard Worker pc_->RemoveStream(pc_->local_streams()->at(1));
1477*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, pc_->local_streams()->count());
1478*d9f75844SAndroid Build Coastguard Worker
1479*d9f75844SAndroid Build Coastguard Worker // Remove the first stream.
1480*d9f75844SAndroid Build Coastguard Worker pc_->RemoveStream(pc_->local_streams()->at(0));
1481*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, pc_->local_streams()->count());
1482*d9f75844SAndroid Build Coastguard Worker }
1483*d9f75844SAndroid Build Coastguard Worker
1484*d9f75844SAndroid Build Coastguard Worker // Test that the created offer includes streams we added.
1485*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,AddedStreamsPresentInOffer)1486*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, AddedStreamsPresentInOffer) {
1487*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1488*d9f75844SAndroid Build Coastguard Worker AddAudioVideoStream(kStreamId1, "audio_track", "video_track");
1489*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1490*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1491*d9f75844SAndroid Build Coastguard Worker
1492*d9f75844SAndroid Build Coastguard Worker const cricket::AudioContentDescription* audio_desc =
1493*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstAudioContentDescription(offer->description());
1494*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1495*d9f75844SAndroid Build Coastguard Worker
1496*d9f75844SAndroid Build Coastguard Worker const cricket::VideoContentDescription* video_desc =
1497*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContentDescription(offer->description());
1498*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1499*d9f75844SAndroid Build Coastguard Worker
1500*d9f75844SAndroid Build Coastguard Worker // Add another stream and ensure the offer includes both the old and new
1501*d9f75844SAndroid Build Coastguard Worker // streams.
1502*d9f75844SAndroid Build Coastguard Worker AddAudioVideoStream(kStreamId2, "audio_track2", "video_track2");
1503*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1504*d9f75844SAndroid Build Coastguard Worker
1505*d9f75844SAndroid Build Coastguard Worker audio_desc = cricket::GetFirstAudioContentDescription(offer->description());
1506*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId1, "audio_track"));
1507*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(audio_desc->streams(), kStreamId2, "audio_track2"));
1508*d9f75844SAndroid Build Coastguard Worker
1509*d9f75844SAndroid Build Coastguard Worker video_desc = cricket::GetFirstVideoContentDescription(offer->description());
1510*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId1, "video_track"));
1511*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(video_desc->streams(), kStreamId2, "video_track2"));
1512*d9f75844SAndroid Build Coastguard Worker }
1513*d9f75844SAndroid Build Coastguard Worker
1514*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,RemoveStream)1515*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, RemoveStream) {
1516*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1517*d9f75844SAndroid Build Coastguard Worker AddVideoStream(kStreamId1);
1518*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, pc_->local_streams()->count());
1519*d9f75844SAndroid Build Coastguard Worker pc_->RemoveStream(pc_->local_streams()->at(0));
1520*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, pc_->local_streams()->count());
1521*d9f75844SAndroid Build Coastguard Worker }
1522*d9f75844SAndroid Build Coastguard Worker
1523*d9f75844SAndroid Build Coastguard Worker // Test for AddTrack and RemoveTrack methods.
1524*d9f75844SAndroid Build Coastguard Worker // Tests that the created offer includes tracks we added,
1525*d9f75844SAndroid Build Coastguard Worker // and that the RtpSenders are created correctly.
1526*d9f75844SAndroid Build Coastguard Worker // Also tests that RemoveTrack removes the tracks from subsequent offers.
1527*d9f75844SAndroid Build Coastguard Worker // Only tested with Plan B since Unified Plan is covered in more detail by tests
1528*d9f75844SAndroid Build Coastguard Worker // in peerconnection_jsep_unittests.cc
TEST_F(PeerConnectionInterfaceTestPlanB,AddTrackRemoveTrack)1529*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackRemoveTrack) {
1530*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1531*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> audio_track(
1532*d9f75844SAndroid Build Coastguard Worker CreateAudioTrack("audio_track"));
1533*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> video_track(
1534*d9f75844SAndroid Build Coastguard Worker CreateVideoTrack("video_track"));
1535*d9f75844SAndroid Build Coastguard Worker auto audio_sender = pc_->AddTrack(audio_track, {kStreamId1}).MoveValue();
1536*d9f75844SAndroid Build Coastguard Worker auto video_sender = pc_->AddTrack(video_track, {kStreamId1}).MoveValue();
1537*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1UL, audio_sender->stream_ids().size());
1538*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
1539*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("audio_track", audio_sender->id());
1540*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(audio_track, audio_sender->track());
1541*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1UL, video_sender->stream_ids().size());
1542*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
1543*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("video_track", video_sender->id());
1544*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(video_track, video_sender->track());
1545*d9f75844SAndroid Build Coastguard Worker
1546*d9f75844SAndroid Build Coastguard Worker // Now create an offer and check for the senders.
1547*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1548*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1549*d9f75844SAndroid Build Coastguard Worker
1550*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* audio_content =
1551*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstAudioContent(offer->description());
1552*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
1553*d9f75844SAndroid Build Coastguard Worker kStreamId1, "audio_track"));
1554*d9f75844SAndroid Build Coastguard Worker
1555*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* video_content =
1556*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContent(offer->description());
1557*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
1558*d9f75844SAndroid Build Coastguard Worker kStreamId1, "video_track"));
1559*d9f75844SAndroid Build Coastguard Worker
1560*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
1561*d9f75844SAndroid Build Coastguard Worker
1562*d9f75844SAndroid Build Coastguard Worker // Now try removing the tracks.
1563*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->RemoveTrackOrError(audio_sender).ok());
1564*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->RemoveTrackOrError(video_sender).ok());
1565*d9f75844SAndroid Build Coastguard Worker
1566*d9f75844SAndroid Build Coastguard Worker // Create a new offer and ensure it doesn't contain the removed senders.
1567*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1568*d9f75844SAndroid Build Coastguard Worker
1569*d9f75844SAndroid Build Coastguard Worker audio_content = cricket::GetFirstAudioContent(offer->description());
1570*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(ContainsTrack(audio_content->media_description()->streams(),
1571*d9f75844SAndroid Build Coastguard Worker kStreamId1, "audio_track"));
1572*d9f75844SAndroid Build Coastguard Worker
1573*d9f75844SAndroid Build Coastguard Worker video_content = cricket::GetFirstVideoContent(offer->description());
1574*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(ContainsTrack(video_content->media_description()->streams(),
1575*d9f75844SAndroid Build Coastguard Worker kStreamId1, "video_track"));
1576*d9f75844SAndroid Build Coastguard Worker
1577*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
1578*d9f75844SAndroid Build Coastguard Worker
1579*d9f75844SAndroid Build Coastguard Worker // Calling RemoveTrack on a sender no longer attached to a PeerConnection
1580*d9f75844SAndroid Build Coastguard Worker // should return false.
1581*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->RemoveTrackOrError(audio_sender).ok());
1582*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->RemoveTrackOrError(video_sender).ok());
1583*d9f75844SAndroid Build Coastguard Worker }
1584*d9f75844SAndroid Build Coastguard Worker
1585*d9f75844SAndroid Build Coastguard Worker // Test for AddTrack with init_send_encoding.
TEST_F(PeerConnectionInterfaceTestPlanB,AddTrackWithSendEncodings)1586*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackWithSendEncodings) {
1587*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1588*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> audio_track(
1589*d9f75844SAndroid Build Coastguard Worker CreateAudioTrack("audio_track"));
1590*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> video_track(
1591*d9f75844SAndroid Build Coastguard Worker CreateVideoTrack("video_track"));
1592*d9f75844SAndroid Build Coastguard Worker RtpEncodingParameters audio_encodings;
1593*d9f75844SAndroid Build Coastguard Worker audio_encodings.active = false;
1594*d9f75844SAndroid Build Coastguard Worker auto audio_sender =
1595*d9f75844SAndroid Build Coastguard Worker pc_->AddTrack(audio_track, {kStreamId1}, {audio_encodings}).MoveValue();
1596*d9f75844SAndroid Build Coastguard Worker RtpEncodingParameters video_encodings;
1597*d9f75844SAndroid Build Coastguard Worker video_encodings.active = true;
1598*d9f75844SAndroid Build Coastguard Worker auto video_sender =
1599*d9f75844SAndroid Build Coastguard Worker pc_->AddTrack(video_track, {kStreamId1}, {video_encodings}).MoveValue();
1600*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1UL, audio_sender->stream_ids().size());
1601*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(kStreamId1, audio_sender->stream_ids()[0]);
1602*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("audio_track", audio_sender->id());
1603*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(audio_track, audio_sender->track());
1604*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1UL, video_sender->stream_ids().size());
1605*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(kStreamId1, video_sender->stream_ids()[0]);
1606*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("video_track", video_sender->id());
1607*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(video_track, video_sender->track());
1608*d9f75844SAndroid Build Coastguard Worker
1609*d9f75844SAndroid Build Coastguard Worker // Now create an offer and check for the senders.
1610*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1611*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1612*d9f75844SAndroid Build Coastguard Worker
1613*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* audio_content =
1614*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstAudioContent(offer->description());
1615*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(audio_content->media_description()->streams(),
1616*d9f75844SAndroid Build Coastguard Worker kStreamId1, "audio_track"));
1617*d9f75844SAndroid Build Coastguard Worker
1618*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* video_content =
1619*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContent(offer->description());
1620*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsTrack(video_content->media_description()->streams(),
1621*d9f75844SAndroid Build Coastguard Worker kStreamId1, "video_track"));
1622*d9f75844SAndroid Build Coastguard Worker
1623*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
1624*d9f75844SAndroid Build Coastguard Worker
1625*d9f75844SAndroid Build Coastguard Worker // Check the encodings.
1626*d9f75844SAndroid Build Coastguard Worker ASSERT_THAT(audio_sender->GetParameters().encodings, SizeIs(1));
1627*d9f75844SAndroid Build Coastguard Worker EXPECT_THAT(audio_sender->GetParameters().encodings[0].active, Eq(false));
1628*d9f75844SAndroid Build Coastguard Worker ASSERT_THAT(video_sender->GetParameters().encodings, SizeIs(1));
1629*d9f75844SAndroid Build Coastguard Worker EXPECT_THAT(video_sender->GetParameters().encodings[0].active, Eq(true));
1630*d9f75844SAndroid Build Coastguard Worker
1631*d9f75844SAndroid Build Coastguard Worker // Now try removing the tracks.
1632*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->RemoveTrackOrError(audio_sender).ok());
1633*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->RemoveTrackOrError(video_sender).ok());
1634*d9f75844SAndroid Build Coastguard Worker }
1635*d9f75844SAndroid Build Coastguard Worker
1636*d9f75844SAndroid Build Coastguard Worker // Test creating senders without a stream specified,
1637*d9f75844SAndroid Build Coastguard Worker // expecting a random stream ID to be generated.
TEST_P(PeerConnectionInterfaceTest,AddTrackWithoutStream)1638*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, AddTrackWithoutStream) {
1639*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1640*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> audio_track(
1641*d9f75844SAndroid Build Coastguard Worker CreateAudioTrack("audio_track"));
1642*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> video_track(
1643*d9f75844SAndroid Build Coastguard Worker CreateVideoTrack("video_track"));
1644*d9f75844SAndroid Build Coastguard Worker auto audio_sender =
1645*d9f75844SAndroid Build Coastguard Worker pc_->AddTrack(audio_track, std::vector<std::string>()).MoveValue();
1646*d9f75844SAndroid Build Coastguard Worker auto video_sender =
1647*d9f75844SAndroid Build Coastguard Worker pc_->AddTrack(video_track, std::vector<std::string>()).MoveValue();
1648*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("audio_track", audio_sender->id());
1649*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(audio_track, audio_sender->track());
1650*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("video_track", video_sender->id());
1651*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(video_track, video_sender->track());
1652*d9f75844SAndroid Build Coastguard Worker if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
1653*d9f75844SAndroid Build Coastguard Worker // If the ID is truly a random GUID, it should be infinitely unlikely they
1654*d9f75844SAndroid Build Coastguard Worker // will be the same.
1655*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(video_sender->stream_ids(), audio_sender->stream_ids());
1656*d9f75844SAndroid Build Coastguard Worker } else {
1657*d9f75844SAndroid Build Coastguard Worker // We allows creating tracks without stream ids under Unified Plan
1658*d9f75844SAndroid Build Coastguard Worker // semantics.
1659*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, video_sender->stream_ids().size());
1660*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, audio_sender->stream_ids().size());
1661*d9f75844SAndroid Build Coastguard Worker }
1662*d9f75844SAndroid Build Coastguard Worker }
1663*d9f75844SAndroid Build Coastguard Worker
1664*d9f75844SAndroid Build Coastguard Worker // Test that we can call GetStats() after AddTrack but before connecting
1665*d9f75844SAndroid Build Coastguard Worker // the PeerConnection to a peer.
TEST_P(PeerConnectionInterfaceTest,AddTrackBeforeConnecting)1666*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, AddTrackBeforeConnecting) {
1667*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1668*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> audio_track(
1669*d9f75844SAndroid Build Coastguard Worker CreateAudioTrack("audio_track"));
1670*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> video_track(
1671*d9f75844SAndroid Build Coastguard Worker CreateVideoTrack("video_track"));
1672*d9f75844SAndroid Build Coastguard Worker auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1673*d9f75844SAndroid Build Coastguard Worker auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
1674*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoGetStats(nullptr));
1675*d9f75844SAndroid Build Coastguard Worker }
1676*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,AttachmentIdIsSetOnAddTrack)1677*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, AttachmentIdIsSetOnAddTrack) {
1678*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1679*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> audio_track(
1680*d9f75844SAndroid Build Coastguard Worker CreateAudioTrack("audio_track"));
1681*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> video_track(
1682*d9f75844SAndroid Build Coastguard Worker CreateVideoTrack("video_track"));
1683*d9f75844SAndroid Build Coastguard Worker auto audio_sender = pc_->AddTrack(audio_track, std::vector<std::string>());
1684*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(audio_sender.ok());
1685*d9f75844SAndroid Build Coastguard Worker auto* audio_sender_proxy =
1686*d9f75844SAndroid Build Coastguard Worker static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1687*d9f75844SAndroid Build Coastguard Worker audio_sender.value().get());
1688*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(0, audio_sender_proxy->internal()->AttachmentId());
1689*d9f75844SAndroid Build Coastguard Worker
1690*d9f75844SAndroid Build Coastguard Worker auto video_sender = pc_->AddTrack(video_track, std::vector<std::string>());
1691*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(video_sender.ok());
1692*d9f75844SAndroid Build Coastguard Worker auto* video_sender_proxy =
1693*d9f75844SAndroid Build Coastguard Worker static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1694*d9f75844SAndroid Build Coastguard Worker video_sender.value().get());
1695*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(0, video_sender_proxy->internal()->AttachmentId());
1696*d9f75844SAndroid Build Coastguard Worker }
1697*d9f75844SAndroid Build Coastguard Worker
1698*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,AttachmentIdIsSetOnAddStream)1699*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, AttachmentIdIsSetOnAddStream) {
1700*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1701*d9f75844SAndroid Build Coastguard Worker AddVideoStream(kStreamId1);
1702*d9f75844SAndroid Build Coastguard Worker auto senders = pc_->GetSenders();
1703*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, senders.size());
1704*d9f75844SAndroid Build Coastguard Worker auto* sender_proxy =
1705*d9f75844SAndroid Build Coastguard Worker static_cast<RtpSenderProxyWithInternal<RtpSenderInternal>*>(
1706*d9f75844SAndroid Build Coastguard Worker senders[0].get());
1707*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(0, sender_proxy->internal()->AttachmentId());
1708*d9f75844SAndroid Build Coastguard Worker }
1709*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,CreateOfferReceiveAnswer)1710*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateOfferReceiveAnswer) {
1711*d9f75844SAndroid Build Coastguard Worker InitiateCall();
1712*d9f75844SAndroid Build Coastguard Worker WaitAndVerifyOnAddStream(kStreamId1, 2);
1713*d9f75844SAndroid Build Coastguard Worker VerifyRemoteRtpHeaderExtensions();
1714*d9f75844SAndroid Build Coastguard Worker }
1715*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,CreateOfferReceivePrAnswerAndAnswer)1716*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateOfferReceivePrAnswerAndAnswer) {
1717*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1718*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0], {kStreamId1});
1719*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
1720*d9f75844SAndroid Build Coastguard Worker std::string offer;
1721*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->local_description()->ToString(&offer));
1722*d9f75844SAndroid Build Coastguard Worker CreatePrAnswerAndAnswerAsRemoteDescription(offer);
1723*d9f75844SAndroid Build Coastguard Worker WaitAndVerifyOnAddStream(kStreamId1, 1);
1724*d9f75844SAndroid Build Coastguard Worker }
1725*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,ReceiveOfferCreateAnswer)1726*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreateAnswer) {
1727*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1728*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0], {kStreamId1});
1729*d9f75844SAndroid Build Coastguard Worker
1730*d9f75844SAndroid Build Coastguard Worker CreateOfferAsRemoteDescription();
1731*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
1732*d9f75844SAndroid Build Coastguard Worker
1733*d9f75844SAndroid Build Coastguard Worker WaitAndVerifyOnAddStream(kStreamId1, 1);
1734*d9f75844SAndroid Build Coastguard Worker }
1735*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,ReceiveOfferCreatePrAnswerAndAnswer)1736*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, ReceiveOfferCreatePrAnswerAndAnswer) {
1737*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1738*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0], {kStreamId1});
1739*d9f75844SAndroid Build Coastguard Worker
1740*d9f75844SAndroid Build Coastguard Worker CreateOfferAsRemoteDescription();
1741*d9f75844SAndroid Build Coastguard Worker CreatePrAnswerAsLocalDescription();
1742*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
1743*d9f75844SAndroid Build Coastguard Worker
1744*d9f75844SAndroid Build Coastguard Worker WaitAndVerifyOnAddStream(kStreamId1, 1);
1745*d9f75844SAndroid Build Coastguard Worker }
1746*d9f75844SAndroid Build Coastguard Worker
1747*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,Renegotiate)1748*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, Renegotiate) {
1749*d9f75844SAndroid Build Coastguard Worker InitiateCall();
1750*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, pc_->remote_streams()->count());
1751*d9f75844SAndroid Build Coastguard Worker pc_->RemoveStream(pc_->local_streams()->at(0));
1752*d9f75844SAndroid Build Coastguard Worker CreateOfferReceiveAnswer();
1753*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, pc_->remote_streams()->count());
1754*d9f75844SAndroid Build Coastguard Worker AddVideoStream(kStreamId1);
1755*d9f75844SAndroid Build Coastguard Worker CreateOfferReceiveAnswer();
1756*d9f75844SAndroid Build Coastguard Worker }
1757*d9f75844SAndroid Build Coastguard Worker
1758*d9f75844SAndroid Build Coastguard Worker // Tests that after negotiating an audio only call, the respondent can perform a
1759*d9f75844SAndroid Build Coastguard Worker // renegotiation that removes the audio stream.
TEST_F(PeerConnectionInterfaceTestPlanB,RenegotiateAudioOnly)1760*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, RenegotiateAudioOnly) {
1761*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1762*d9f75844SAndroid Build Coastguard Worker AddAudioStream(kStreamId1);
1763*d9f75844SAndroid Build Coastguard Worker CreateOfferAsRemoteDescription();
1764*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
1765*d9f75844SAndroid Build Coastguard Worker
1766*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, pc_->remote_streams()->count());
1767*d9f75844SAndroid Build Coastguard Worker pc_->RemoveStream(pc_->local_streams()->at(0));
1768*d9f75844SAndroid Build Coastguard Worker CreateOfferReceiveAnswer();
1769*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, pc_->remote_streams()->count());
1770*d9f75844SAndroid Build Coastguard Worker }
1771*d9f75844SAndroid Build Coastguard Worker
1772*d9f75844SAndroid Build Coastguard Worker // Test that candidates are generated and that we can parse our own candidates.
TEST_P(PeerConnectionInterfaceTest,IceCandidates)1773*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, IceCandidates) {
1774*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1775*d9f75844SAndroid Build Coastguard Worker
1776*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->AddIceCandidate(observer_.last_candidate()));
1777*d9f75844SAndroid Build Coastguard Worker // SetRemoteDescription takes ownership of offer.
1778*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1779*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0]);
1780*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1781*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
1782*d9f75844SAndroid Build Coastguard Worker
1783*d9f75844SAndroid Build Coastguard Worker // SetLocalDescription takes ownership of answer.
1784*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
1785*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoCreateAnswer(&answer, nullptr));
1786*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
1787*d9f75844SAndroid Build Coastguard Worker
1788*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE_WAIT(observer_.last_candidate() != nullptr, kTimeout);
1789*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE_WAIT(observer_.ice_gathering_complete_, kTimeout);
1790*d9f75844SAndroid Build Coastguard Worker
1791*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->AddIceCandidate(observer_.last_candidate()));
1792*d9f75844SAndroid Build Coastguard Worker }
1793*d9f75844SAndroid Build Coastguard Worker
1794*d9f75844SAndroid Build Coastguard Worker // Test that CreateOffer and CreateAnswer will fail if the track labels are
1795*d9f75844SAndroid Build Coastguard Worker // not unique.
TEST_F(PeerConnectionInterfaceTestPlanB,CreateOfferAnswerWithInvalidStream)1796*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, CreateOfferAnswerWithInvalidStream) {
1797*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1798*d9f75844SAndroid Build Coastguard Worker // Create a regular offer for the CreateAnswer test later.
1799*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1800*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoCreateOffer(&offer, nullptr));
1801*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(offer);
1802*d9f75844SAndroid Build Coastguard Worker offer.reset();
1803*d9f75844SAndroid Build Coastguard Worker
1804*d9f75844SAndroid Build Coastguard Worker // Create a local stream with audio&video tracks having same label.
1805*d9f75844SAndroid Build Coastguard Worker AddAudioTrack("track_label", {kStreamId1});
1806*d9f75844SAndroid Build Coastguard Worker AddVideoTrack("track_label", {kStreamId1});
1807*d9f75844SAndroid Build Coastguard Worker
1808*d9f75844SAndroid Build Coastguard Worker // Test CreateOffer
1809*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
1810*d9f75844SAndroid Build Coastguard Worker
1811*d9f75844SAndroid Build Coastguard Worker // Test CreateAnswer
1812*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
1813*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
1814*d9f75844SAndroid Build Coastguard Worker }
1815*d9f75844SAndroid Build Coastguard Worker
1816*d9f75844SAndroid Build Coastguard Worker // Test that we will get different SSRCs for each tracks in the offer and answer
1817*d9f75844SAndroid Build Coastguard Worker // we created.
TEST_P(PeerConnectionInterfaceTest,SsrcInOfferAnswer)1818*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SsrcInOfferAnswer) {
1819*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1820*d9f75844SAndroid Build Coastguard Worker // Create a local stream with audio&video tracks having different labels.
1821*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[0], {kStreamId1});
1822*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0], {kStreamId1});
1823*d9f75844SAndroid Build Coastguard Worker
1824*d9f75844SAndroid Build Coastguard Worker // Test CreateOffer
1825*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1826*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1827*d9f75844SAndroid Build Coastguard Worker int audio_ssrc = 0;
1828*d9f75844SAndroid Build Coastguard Worker int video_ssrc = 0;
1829*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(
1830*d9f75844SAndroid Build Coastguard Worker GetFirstSsrc(GetFirstAudioContent(offer->description()), &audio_ssrc));
1831*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(
1832*d9f75844SAndroid Build Coastguard Worker GetFirstSsrc(GetFirstVideoContent(offer->description()), &video_ssrc));
1833*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(audio_ssrc, video_ssrc);
1834*d9f75844SAndroid Build Coastguard Worker
1835*d9f75844SAndroid Build Coastguard Worker // Test CreateAnswer
1836*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
1837*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
1838*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
1839*d9f75844SAndroid Build Coastguard Worker audio_ssrc = 0;
1840*d9f75844SAndroid Build Coastguard Worker video_ssrc = 0;
1841*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(
1842*d9f75844SAndroid Build Coastguard Worker GetFirstSsrc(GetFirstAudioContent(answer->description()), &audio_ssrc));
1843*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(
1844*d9f75844SAndroid Build Coastguard Worker GetFirstSsrc(GetFirstVideoContent(answer->description()), &video_ssrc));
1845*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(audio_ssrc, video_ssrc);
1846*d9f75844SAndroid Build Coastguard Worker }
1847*d9f75844SAndroid Build Coastguard Worker
1848*d9f75844SAndroid Build Coastguard Worker // Test that it's possible to call AddTrack on a MediaStream after adding
1849*d9f75844SAndroid Build Coastguard Worker // the stream to a PeerConnection.
1850*d9f75844SAndroid Build Coastguard Worker // TODO(deadbeef): Remove this test once this behavior is no longer supported.
1851*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,AddTrackAfterAddStream)1852*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, AddTrackAfterAddStream) {
1853*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1854*d9f75844SAndroid Build Coastguard Worker // Create audio stream and add to PeerConnection.
1855*d9f75844SAndroid Build Coastguard Worker AddAudioStream(kStreamId1);
1856*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* stream = pc_->local_streams()->at(0);
1857*d9f75844SAndroid Build Coastguard Worker
1858*d9f75844SAndroid Build Coastguard Worker // Add video track to the audio-only stream.
1859*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> video_track(
1860*d9f75844SAndroid Build Coastguard Worker CreateVideoTrack("video_label"));
1861*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(video_track);
1862*d9f75844SAndroid Build Coastguard Worker
1863*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1864*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1865*d9f75844SAndroid Build Coastguard Worker
1866*d9f75844SAndroid Build Coastguard Worker const cricket::MediaContentDescription* video_desc =
1867*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContentDescription(offer->description());
1868*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(video_desc != nullptr);
1869*d9f75844SAndroid Build Coastguard Worker }
1870*d9f75844SAndroid Build Coastguard Worker
1871*d9f75844SAndroid Build Coastguard Worker // Test that it's possible to call RemoveTrack on a MediaStream after adding
1872*d9f75844SAndroid Build Coastguard Worker // the stream to a PeerConnection.
1873*d9f75844SAndroid Build Coastguard Worker // TODO(deadbeef): Remove this test once this behavior is no longer supported.
1874*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,RemoveTrackAfterAddStream)1875*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackAfterAddStream) {
1876*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1877*d9f75844SAndroid Build Coastguard Worker // Create audio/video stream and add to PeerConnection.
1878*d9f75844SAndroid Build Coastguard Worker AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
1879*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* stream = pc_->local_streams()->at(0);
1880*d9f75844SAndroid Build Coastguard Worker
1881*d9f75844SAndroid Build Coastguard Worker // Remove the video track.
1882*d9f75844SAndroid Build Coastguard Worker stream->RemoveTrack(stream->GetVideoTracks()[0]);
1883*d9f75844SAndroid Build Coastguard Worker
1884*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1885*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1886*d9f75844SAndroid Build Coastguard Worker
1887*d9f75844SAndroid Build Coastguard Worker const cricket::MediaContentDescription* video_desc =
1888*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContentDescription(offer->description());
1889*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(video_desc == nullptr);
1890*d9f75844SAndroid Build Coastguard Worker }
1891*d9f75844SAndroid Build Coastguard Worker
1892*d9f75844SAndroid Build Coastguard Worker // Test creating a sender with a stream ID, and ensure the ID is populated
1893*d9f75844SAndroid Build Coastguard Worker // in the offer.
1894*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,CreateSenderWithStream)1895*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, CreateSenderWithStream) {
1896*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1897*d9f75844SAndroid Build Coastguard Worker pc_->CreateSender("video", kStreamId1);
1898*d9f75844SAndroid Build Coastguard Worker
1899*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
1900*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
1901*d9f75844SAndroid Build Coastguard Worker
1902*d9f75844SAndroid Build Coastguard Worker const cricket::MediaContentDescription* video_desc =
1903*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContentDescription(offer->description());
1904*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(video_desc != nullptr);
1905*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, video_desc->streams().size());
1906*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(kStreamId1, video_desc->streams()[0].first_stream_id());
1907*d9f75844SAndroid Build Coastguard Worker }
1908*d9f75844SAndroid Build Coastguard Worker
1909*d9f75844SAndroid Build Coastguard Worker // Test that we can specify a certain track that we want statistics about.
TEST_P(PeerConnectionInterfaceTest,GetStatsForSpecificTrack)1910*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, GetStatsForSpecificTrack) {
1911*d9f75844SAndroid Build Coastguard Worker InitiateCall();
1912*d9f75844SAndroid Build Coastguard Worker ASSERT_LT(0u, pc_->GetSenders().size());
1913*d9f75844SAndroid Build Coastguard Worker ASSERT_LT(0u, pc_->GetReceivers().size());
1914*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
1915*d9f75844SAndroid Build Coastguard Worker pc_->GetReceivers()[0]->track();
1916*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoGetStats(remote_audio.get()));
1917*d9f75844SAndroid Build Coastguard Worker
1918*d9f75844SAndroid Build Coastguard Worker // Remove the stream. Since we are sending to our selves the local
1919*d9f75844SAndroid Build Coastguard Worker // and the remote stream is the same.
1920*d9f75844SAndroid Build Coastguard Worker pc_->RemoveTrackOrError(pc_->GetSenders()[0]);
1921*d9f75844SAndroid Build Coastguard Worker // Do a re-negotiation.
1922*d9f75844SAndroid Build Coastguard Worker CreateOfferReceiveAnswer();
1923*d9f75844SAndroid Build Coastguard Worker
1924*d9f75844SAndroid Build Coastguard Worker // Test that we still can get statistics for the old track. Even if it is not
1925*d9f75844SAndroid Build Coastguard Worker // sent any longer.
1926*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoGetStats(remote_audio.get()));
1927*d9f75844SAndroid Build Coastguard Worker }
1928*d9f75844SAndroid Build Coastguard Worker
1929*d9f75844SAndroid Build Coastguard Worker // Test that we can get stats on a video track.
TEST_P(PeerConnectionInterfaceTest,GetStatsForVideoTrack)1930*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
1931*d9f75844SAndroid Build Coastguard Worker InitiateCall();
1932*d9f75844SAndroid Build Coastguard Worker auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
1933*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(video_receiver);
1934*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoGetStats(video_receiver->track().get()));
1935*d9f75844SAndroid Build Coastguard Worker }
1936*d9f75844SAndroid Build Coastguard Worker
1937*d9f75844SAndroid Build Coastguard Worker // Test that we don't get statistics for an invalid track.
TEST_P(PeerConnectionInterfaceTest,GetStatsForInvalidTrack)1938*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
1939*d9f75844SAndroid Build Coastguard Worker InitiateCall();
1940*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
1941*d9f75844SAndroid Build Coastguard Worker pc_factory_->CreateAudioTrack("unknown track", nullptr));
1942*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoGetStats(unknown_audio_track.get()));
1943*d9f75844SAndroid Build Coastguard Worker }
1944*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,GetRTCStatsBeforeAndAfterCalling)1945*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, GetRTCStatsBeforeAndAfterCalling) {
1946*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
1947*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoGetRTCStats());
1948*d9f75844SAndroid Build Coastguard Worker // Clearing stats cache is needed now, but should be temporary.
1949*d9f75844SAndroid Build Coastguard Worker // https://bugs.chromium.org/p/webrtc/issues/detail?id=8693
1950*d9f75844SAndroid Build Coastguard Worker pc_->ClearStatsCache();
1951*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[0], {kStreamId1});
1952*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0], {kStreamId1});
1953*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoGetRTCStats());
1954*d9f75844SAndroid Build Coastguard Worker pc_->ClearStatsCache();
1955*d9f75844SAndroid Build Coastguard Worker CreateOfferReceiveAnswer();
1956*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoGetRTCStats());
1957*d9f75844SAndroid Build Coastguard Worker }
1958*d9f75844SAndroid Build Coastguard Worker
1959*d9f75844SAndroid Build Coastguard Worker // This tests that a SCTP data channel is returned using different
1960*d9f75844SAndroid Build Coastguard Worker // DataChannelInit configurations.
TEST_P(PeerConnectionInterfaceTest,CreateSctpDataChannel)1961*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannel) {
1962*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
1963*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
1964*d9f75844SAndroid Build Coastguard Worker
1965*d9f75844SAndroid Build Coastguard Worker webrtc::DataChannelInit config;
1966*d9f75844SAndroid Build Coastguard Worker auto channel = pc_->CreateDataChannelOrError("1", &config);
1967*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.ok());
1968*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.value()->reliable());
1969*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(observer_.renegotiation_needed_);
1970*d9f75844SAndroid Build Coastguard Worker observer_.renegotiation_needed_ = false;
1971*d9f75844SAndroid Build Coastguard Worker
1972*d9f75844SAndroid Build Coastguard Worker config.ordered = false;
1973*d9f75844SAndroid Build Coastguard Worker channel = pc_->CreateDataChannelOrError("2", &config);
1974*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.ok());
1975*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.value()->reliable());
1976*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(observer_.renegotiation_needed_);
1977*d9f75844SAndroid Build Coastguard Worker
1978*d9f75844SAndroid Build Coastguard Worker config.ordered = true;
1979*d9f75844SAndroid Build Coastguard Worker config.maxRetransmits = 0;
1980*d9f75844SAndroid Build Coastguard Worker channel = pc_->CreateDataChannelOrError("3", &config);
1981*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.ok());
1982*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(channel.value()->reliable());
1983*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(observer_.renegotiation_needed_);
1984*d9f75844SAndroid Build Coastguard Worker
1985*d9f75844SAndroid Build Coastguard Worker config.maxRetransmits = absl::nullopt;
1986*d9f75844SAndroid Build Coastguard Worker config.maxRetransmitTime = 0;
1987*d9f75844SAndroid Build Coastguard Worker channel = pc_->CreateDataChannelOrError("4", &config);
1988*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.ok());
1989*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(channel.value()->reliable());
1990*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(observer_.renegotiation_needed_);
1991*d9f75844SAndroid Build Coastguard Worker }
1992*d9f75844SAndroid Build Coastguard Worker
1993*d9f75844SAndroid Build Coastguard Worker // For backwards compatibility, we want people who "unset" maxRetransmits
1994*d9f75844SAndroid Build Coastguard Worker // and maxRetransmitTime by setting them to -1 to get what they want.
TEST_P(PeerConnectionInterfaceTest,CreateSctpDataChannelWithMinusOne)1995*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateSctpDataChannelWithMinusOne) {
1996*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
1997*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
1998*d9f75844SAndroid Build Coastguard Worker
1999*d9f75844SAndroid Build Coastguard Worker webrtc::DataChannelInit config;
2000*d9f75844SAndroid Build Coastguard Worker config.maxRetransmitTime = -1;
2001*d9f75844SAndroid Build Coastguard Worker config.maxRetransmits = -1;
2002*d9f75844SAndroid Build Coastguard Worker auto channel = pc_->CreateDataChannelOrError("1", &config);
2003*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.ok());
2004*d9f75844SAndroid Build Coastguard Worker }
2005*d9f75844SAndroid Build Coastguard Worker
2006*d9f75844SAndroid Build Coastguard Worker // This tests that no data channel is returned if both maxRetransmits and
2007*d9f75844SAndroid Build Coastguard Worker // maxRetransmitTime are set for SCTP data channels.
TEST_P(PeerConnectionInterfaceTest,CreateSctpDataChannelShouldFailForInvalidConfig)2008*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2009*d9f75844SAndroid Build Coastguard Worker CreateSctpDataChannelShouldFailForInvalidConfig) {
2010*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
2011*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
2012*d9f75844SAndroid Build Coastguard Worker
2013*d9f75844SAndroid Build Coastguard Worker std::string label = "test";
2014*d9f75844SAndroid Build Coastguard Worker webrtc::DataChannelInit config;
2015*d9f75844SAndroid Build Coastguard Worker config.maxRetransmits = 0;
2016*d9f75844SAndroid Build Coastguard Worker config.maxRetransmitTime = 0;
2017*d9f75844SAndroid Build Coastguard Worker
2018*d9f75844SAndroid Build Coastguard Worker auto channel = pc_->CreateDataChannelOrError(label, &config);
2019*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(channel.ok());
2020*d9f75844SAndroid Build Coastguard Worker }
2021*d9f75844SAndroid Build Coastguard Worker
2022*d9f75844SAndroid Build Coastguard Worker // The test verifies that creating a SCTP data channel with an id already in use
2023*d9f75844SAndroid Build Coastguard Worker // or out of range should fail.
TEST_P(PeerConnectionInterfaceTest,CreateSctpDataChannelWithInvalidIdShouldFail)2024*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2025*d9f75844SAndroid Build Coastguard Worker CreateSctpDataChannelWithInvalidIdShouldFail) {
2026*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
2027*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
2028*d9f75844SAndroid Build Coastguard Worker
2029*d9f75844SAndroid Build Coastguard Worker webrtc::DataChannelInit config;
2030*d9f75844SAndroid Build Coastguard Worker
2031*d9f75844SAndroid Build Coastguard Worker config.id = 1;
2032*d9f75844SAndroid Build Coastguard Worker config.negotiated = true;
2033*d9f75844SAndroid Build Coastguard Worker auto channel = pc_->CreateDataChannelOrError("1", &config);
2034*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.ok());
2035*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1, channel.value()->id());
2036*d9f75844SAndroid Build Coastguard Worker
2037*d9f75844SAndroid Build Coastguard Worker channel = pc_->CreateDataChannelOrError("x", &config);
2038*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(channel.ok());
2039*d9f75844SAndroid Build Coastguard Worker
2040*d9f75844SAndroid Build Coastguard Worker config.id = cricket::kMaxSctpSid;
2041*d9f75844SAndroid Build Coastguard Worker config.negotiated = true;
2042*d9f75844SAndroid Build Coastguard Worker channel = pc_->CreateDataChannelOrError("max", &config);
2043*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.ok());
2044*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(config.id, channel.value()->id());
2045*d9f75844SAndroid Build Coastguard Worker
2046*d9f75844SAndroid Build Coastguard Worker config.id = cricket::kMaxSctpSid + 1;
2047*d9f75844SAndroid Build Coastguard Worker config.negotiated = true;
2048*d9f75844SAndroid Build Coastguard Worker channel = pc_->CreateDataChannelOrError("x", &config);
2049*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(channel.ok());
2050*d9f75844SAndroid Build Coastguard Worker }
2051*d9f75844SAndroid Build Coastguard Worker
2052*d9f75844SAndroid Build Coastguard Worker // Verifies that duplicated label is allowed for SCTP data channel.
TEST_P(PeerConnectionInterfaceTest,SctpDuplicatedLabelAllowed)2053*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SctpDuplicatedLabelAllowed) {
2054*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
2055*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
2056*d9f75844SAndroid Build Coastguard Worker
2057*d9f75844SAndroid Build Coastguard Worker std::string label = "test";
2058*d9f75844SAndroid Build Coastguard Worker auto channel = pc_->CreateDataChannelOrError(label, nullptr);
2059*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(channel.ok());
2060*d9f75844SAndroid Build Coastguard Worker
2061*d9f75844SAndroid Build Coastguard Worker auto dup_channel = pc_->CreateDataChannelOrError(label, nullptr);
2062*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(dup_channel.ok());
2063*d9f75844SAndroid Build Coastguard Worker }
2064*d9f75844SAndroid Build Coastguard Worker
2065*d9f75844SAndroid Build Coastguard Worker #ifdef WEBRTC_HAVE_SCTP
2066*d9f75844SAndroid Build Coastguard Worker // This tests that SCTP data channels can be rejected in an answer.
TEST_P(PeerConnectionInterfaceTest,TestRejectSctpDataChannelInAnswer)2067*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, TestRejectSctpDataChannelInAnswer)
2068*d9f75844SAndroid Build Coastguard Worker #else
2069*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, DISABLED_TestRejectSctpDataChannelInAnswer)
2070*d9f75844SAndroid Build Coastguard Worker #endif
2071*d9f75844SAndroid Build Coastguard Worker {
2072*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
2073*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
2074*d9f75844SAndroid Build Coastguard Worker
2075*d9f75844SAndroid Build Coastguard Worker auto offer_channel = pc_->CreateDataChannelOrError("offer_channel", NULL);
2076*d9f75844SAndroid Build Coastguard Worker
2077*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
2078*d9f75844SAndroid Build Coastguard Worker
2079*d9f75844SAndroid Build Coastguard Worker // Create an answer where the m-line for data channels are rejected.
2080*d9f75844SAndroid Build Coastguard Worker std::string sdp;
2081*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->local_description()->ToString(&sdp));
2082*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer(
2083*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
2084*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(answer);
2085*d9f75844SAndroid Build Coastguard Worker cricket::ContentInfo* data_info =
2086*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstDataContent(answer->description());
2087*d9f75844SAndroid Build Coastguard Worker data_info->rejected = true;
2088*d9f75844SAndroid Build Coastguard Worker
2089*d9f75844SAndroid Build Coastguard Worker DoSetRemoteDescription(std::move(answer));
2090*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(DataChannelInterface::kClosed, offer_channel.value()->state());
2091*d9f75844SAndroid Build Coastguard Worker }
2092*d9f75844SAndroid Build Coastguard Worker
2093*d9f75844SAndroid Build Coastguard Worker // Test that we can create a session description from an SDP string from
2094*d9f75844SAndroid Build Coastguard Worker // FireFox, use it as a remote session description, generate an answer and use
2095*d9f75844SAndroid Build Coastguard Worker // the answer as a local description.
TEST_P(PeerConnectionInterfaceTest,ReceiveFireFoxOffer)2096*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, ReceiveFireFoxOffer) {
2097*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
2098*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
2099*d9f75844SAndroid Build Coastguard Worker AddAudioTrack("audio_label");
2100*d9f75844SAndroid Build Coastguard Worker AddVideoTrack("video_label");
2101*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> desc(
2102*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer,
2103*d9f75844SAndroid Build Coastguard Worker webrtc::kFireFoxSdpOffer, nullptr));
2104*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetSessionDescription(std::move(desc), false));
2105*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
2106*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pc_->local_description() != nullptr);
2107*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pc_->remote_description() != nullptr);
2108*d9f75844SAndroid Build Coastguard Worker
2109*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* content =
2110*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstAudioContent(pc_->local_description()->description());
2111*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(content != nullptr);
2112*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(content->rejected);
2113*d9f75844SAndroid Build Coastguard Worker
2114*d9f75844SAndroid Build Coastguard Worker content =
2115*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContent(pc_->local_description()->description());
2116*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(content != nullptr);
2117*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(content->rejected);
2118*d9f75844SAndroid Build Coastguard Worker #ifdef WEBRTC_HAVE_SCTP
2119*d9f75844SAndroid Build Coastguard Worker content =
2120*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstDataContent(pc_->local_description()->description());
2121*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(content != nullptr);
2122*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(content->rejected);
2123*d9f75844SAndroid Build Coastguard Worker #endif
2124*d9f75844SAndroid Build Coastguard Worker }
2125*d9f75844SAndroid Build Coastguard Worker
2126*d9f75844SAndroid Build Coastguard Worker // Test that fallback from DTLS to SDES is not supported.
2127*d9f75844SAndroid Build Coastguard Worker // The fallback was previously supported but was removed to simplify the code
2128*d9f75844SAndroid Build Coastguard Worker // and because it's non-standard.
TEST_P(PeerConnectionInterfaceTest,DtlsSdesFallbackNotSupported)2129*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, DtlsSdesFallbackNotSupported) {
2130*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
2131*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
2132*d9f75844SAndroid Build Coastguard Worker // Wait for fake certificate to be generated. Previously, this is what caused
2133*d9f75844SAndroid Build Coastguard Worker // the "a=crypto" lines to be rejected.
2134*d9f75844SAndroid Build Coastguard Worker AddAudioTrack("audio_label");
2135*d9f75844SAndroid Build Coastguard Worker AddVideoTrack("video_label");
2136*d9f75844SAndroid Build Coastguard Worker ASSERT_NE(nullptr, fake_certificate_generator_);
2137*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(1, fake_certificate_generator_->generated_certificates(),
2138*d9f75844SAndroid Build Coastguard Worker kTimeout);
2139*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> desc(
2140*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, kDtlsSdesFallbackSdp,
2141*d9f75844SAndroid Build Coastguard Worker nullptr));
2142*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoSetSessionDescription(std::move(desc), /*local=*/false));
2143*d9f75844SAndroid Build Coastguard Worker }
2144*d9f75844SAndroid Build Coastguard Worker
2145*d9f75844SAndroid Build Coastguard Worker // Test that we can create an audio only offer and receive an answer with a
2146*d9f75844SAndroid Build Coastguard Worker // limited set of audio codecs and receive an updated offer with more audio
2147*d9f75844SAndroid Build Coastguard Worker // codecs, where the added codecs are not supported.
TEST_P(PeerConnectionInterfaceTest,ReceiveUpdatedAudioOfferWithBadCodecs)2148*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, ReceiveUpdatedAudioOfferWithBadCodecs) {
2149*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
2150*d9f75844SAndroid Build Coastguard Worker AddAudioTrack("audio_label");
2151*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
2152*d9f75844SAndroid Build Coastguard Worker
2153*d9f75844SAndroid Build Coastguard Worker const char* answer_sdp = (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
2154*d9f75844SAndroid Build Coastguard Worker ? webrtc::kAudioSdpPlanB
2155*d9f75844SAndroid Build Coastguard Worker : webrtc::kAudioSdpUnifiedPlan);
2156*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer(
2157*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kAnswer, answer_sdp, nullptr));
2158*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetSessionDescription(std::move(answer), false));
2159*d9f75844SAndroid Build Coastguard Worker
2160*d9f75844SAndroid Build Coastguard Worker const char* reoffer_sdp =
2161*d9f75844SAndroid Build Coastguard Worker (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED
2162*d9f75844SAndroid Build Coastguard Worker ? webrtc::kAudioSdpWithUnsupportedCodecsPlanB
2163*d9f75844SAndroid Build Coastguard Worker : webrtc::kAudioSdpWithUnsupportedCodecsUnifiedPlan);
2164*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> updated_offer(
2165*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, reoffer_sdp, nullptr));
2166*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetSessionDescription(std::move(updated_offer), false));
2167*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
2168*d9f75844SAndroid Build Coastguard Worker }
2169*d9f75844SAndroid Build Coastguard Worker
2170*d9f75844SAndroid Build Coastguard Worker // Test that if we're receiving (but not sending) a track, subsequent offers
2171*d9f75844SAndroid Build Coastguard Worker // will have m-lines with a=recvonly.
TEST_P(PeerConnectionInterfaceTest,CreateSubsequentRecvOnlyOffer)2172*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateSubsequentRecvOnlyOffer) {
2173*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
2174*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
2175*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(GetSdpStringWithStream1());
2176*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
2177*d9f75844SAndroid Build Coastguard Worker
2178*d9f75844SAndroid Build Coastguard Worker // At this point we should be receiving stream 1, but not sending anything.
2179*d9f75844SAndroid Build Coastguard Worker // A new offer should be recvonly.
2180*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
2181*d9f75844SAndroid Build Coastguard Worker DoCreateOffer(&offer, nullptr);
2182*d9f75844SAndroid Build Coastguard Worker
2183*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* video_content =
2184*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContent(offer->description());
2185*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2186*d9f75844SAndroid Build Coastguard Worker video_content->media_description()->direction());
2187*d9f75844SAndroid Build Coastguard Worker
2188*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* audio_content =
2189*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstAudioContent(offer->description());
2190*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(RtpTransceiverDirection::kRecvOnly,
2191*d9f75844SAndroid Build Coastguard Worker audio_content->media_description()->direction());
2192*d9f75844SAndroid Build Coastguard Worker }
2193*d9f75844SAndroid Build Coastguard Worker
2194*d9f75844SAndroid Build Coastguard Worker // Test that if we're receiving (but not sending) a track, and the
2195*d9f75844SAndroid Build Coastguard Worker // offerToReceiveVideo/offerToReceiveAudio constraints are explicitly set to
2196*d9f75844SAndroid Build Coastguard Worker // false, the generated m-lines will be a=inactive.
TEST_P(PeerConnectionInterfaceTest,CreateSubsequentInactiveOffer)2197*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateSubsequentInactiveOffer) {
2198*d9f75844SAndroid Build Coastguard Worker RTCConfiguration rtc_config;
2199*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(rtc_config);
2200*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(GetSdpStringWithStream1());
2201*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
2202*d9f75844SAndroid Build Coastguard Worker
2203*d9f75844SAndroid Build Coastguard Worker // At this point we should be receiving stream 1, but not sending anything.
2204*d9f75844SAndroid Build Coastguard Worker // A new offer would be recvonly, but we'll set the "no receive" constraints
2205*d9f75844SAndroid Build Coastguard Worker // to make it inactive.
2206*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
2207*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions options;
2208*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_audio = 0;
2209*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_video = 0;
2210*d9f75844SAndroid Build Coastguard Worker DoCreateOffer(&offer, &options);
2211*d9f75844SAndroid Build Coastguard Worker
2212*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* video_content =
2213*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContent(offer->description());
2214*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(RtpTransceiverDirection::kInactive,
2215*d9f75844SAndroid Build Coastguard Worker video_content->media_description()->direction());
2216*d9f75844SAndroid Build Coastguard Worker
2217*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* audio_content =
2218*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstAudioContent(offer->description());
2219*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(RtpTransceiverDirection::kInactive,
2220*d9f75844SAndroid Build Coastguard Worker audio_content->media_description()->direction());
2221*d9f75844SAndroid Build Coastguard Worker }
2222*d9f75844SAndroid Build Coastguard Worker
2223*d9f75844SAndroid Build Coastguard Worker // Test that we can use SetConfiguration to change the ICE servers of the
2224*d9f75844SAndroid Build Coastguard Worker // PortAllocator.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationChangesIceServers)2225*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceServers) {
2226*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
2227*d9f75844SAndroid Build Coastguard Worker
2228*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
2229*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::IceServer server;
2230*d9f75844SAndroid Build Coastguard Worker server.uri = "stun:test_hostname";
2231*d9f75844SAndroid Build Coastguard Worker config.servers.push_back(server);
2232*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2233*d9f75844SAndroid Build Coastguard Worker
2234*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, port_allocator_->stun_servers().size());
2235*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("test_hostname",
2236*d9f75844SAndroid Build Coastguard Worker port_allocator_->stun_servers().begin()->hostname());
2237*d9f75844SAndroid Build Coastguard Worker }
2238*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,SetConfigurationChangesCandidateFilter)2239*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesCandidateFilter) {
2240*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
2241*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
2242*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kRelay;
2243*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2244*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(cricket::CF_RELAY, port_allocator_->candidate_filter());
2245*d9f75844SAndroid Build Coastguard Worker }
2246*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,SetConfigurationChangesPruneTurnPortsFlag)2247*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesPruneTurnPortsFlag) {
2248*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
2249*d9f75844SAndroid Build Coastguard Worker config.prune_turn_ports = false;
2250*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2251*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
2252*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(webrtc::NO_PRUNE, port_allocator_->turn_port_prune_policy());
2253*d9f75844SAndroid Build Coastguard Worker
2254*d9f75844SAndroid Build Coastguard Worker config.prune_turn_ports = true;
2255*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2256*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(webrtc::PRUNE_BASED_ON_PRIORITY,
2257*d9f75844SAndroid Build Coastguard Worker port_allocator_->turn_port_prune_policy());
2258*d9f75844SAndroid Build Coastguard Worker }
2259*d9f75844SAndroid Build Coastguard Worker
2260*d9f75844SAndroid Build Coastguard Worker // Test that the ice check interval can be changed. This does not verify that
2261*d9f75844SAndroid Build Coastguard Worker // the setting makes it all the way to P2PTransportChannel, as that would
2262*d9f75844SAndroid Build Coastguard Worker // require a very complex set of mocks.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationChangesIceCheckInterval)2263*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetConfigurationChangesIceCheckInterval) {
2264*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
2265*d9f75844SAndroid Build Coastguard Worker config.ice_check_min_interval = absl::nullopt;
2266*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2267*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
2268*d9f75844SAndroid Build Coastguard Worker config.ice_check_min_interval = 100;
2269*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2270*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
2271*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(config.ice_check_min_interval, 100);
2272*d9f75844SAndroid Build Coastguard Worker }
2273*d9f75844SAndroid Build Coastguard Worker
TEST_P(PeerConnectionInterfaceTest,SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged)2274*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2275*d9f75844SAndroid Build Coastguard Worker SetConfigurationChangesSurfaceIceCandidatesOnIceTransportTypeChanged) {
2276*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
2277*d9f75844SAndroid Build Coastguard Worker config.surface_ice_candidates_on_ice_transport_type_changed = false;
2278*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2279*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
2280*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(config.surface_ice_candidates_on_ice_transport_type_changed);
2281*d9f75844SAndroid Build Coastguard Worker
2282*d9f75844SAndroid Build Coastguard Worker config.surface_ice_candidates_on_ice_transport_type_changed = true;
2283*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2284*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
2285*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(config.surface_ice_candidates_on_ice_transport_type_changed);
2286*d9f75844SAndroid Build Coastguard Worker }
2287*d9f75844SAndroid Build Coastguard Worker
2288*d9f75844SAndroid Build Coastguard Worker // Test that when SetConfiguration changes both the pool size and other
2289*d9f75844SAndroid Build Coastguard Worker // attributes, the pooled session is created with the updated attributes.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationCreatesPooledSessionCorrectly)2290*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2291*d9f75844SAndroid Build Coastguard Worker SetConfigurationCreatesPooledSessionCorrectly) {
2292*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
2293*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
2294*d9f75844SAndroid Build Coastguard Worker config.ice_candidate_pool_size = 1;
2295*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::IceServer server;
2296*d9f75844SAndroid Build Coastguard Worker server.uri = kStunAddressOnly;
2297*d9f75844SAndroid Build Coastguard Worker config.servers.push_back(server);
2298*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kRelay;
2299*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2300*d9f75844SAndroid Build Coastguard Worker
2301*d9f75844SAndroid Build Coastguard Worker const cricket::FakePortAllocatorSession* session =
2302*d9f75844SAndroid Build Coastguard Worker static_cast<const cricket::FakePortAllocatorSession*>(
2303*d9f75844SAndroid Build Coastguard Worker port_allocator_->GetPooledSession());
2304*d9f75844SAndroid Build Coastguard Worker ASSERT_NE(nullptr, session);
2305*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1UL, session->stun_servers().size());
2306*d9f75844SAndroid Build Coastguard Worker }
2307*d9f75844SAndroid Build Coastguard Worker
2308*d9f75844SAndroid Build Coastguard Worker // Test that after SetLocalDescription, changing the pool size is not allowed,
2309*d9f75844SAndroid Build Coastguard Worker // and an invalid modification error is returned.
TEST_P(PeerConnectionInterfaceTest,CantChangePoolSizeAfterSetLocalDescription)2310*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2311*d9f75844SAndroid Build Coastguard Worker CantChangePoolSizeAfterSetLocalDescription) {
2312*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
2313*d9f75844SAndroid Build Coastguard Worker // Start by setting a size of 1.
2314*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
2315*d9f75844SAndroid Build Coastguard Worker config.ice_candidate_pool_size = 1;
2316*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2317*d9f75844SAndroid Build Coastguard Worker
2318*d9f75844SAndroid Build Coastguard Worker // Set remote offer; can still change pool size at this point.
2319*d9f75844SAndroid Build Coastguard Worker CreateOfferAsRemoteDescription();
2320*d9f75844SAndroid Build Coastguard Worker config.ice_candidate_pool_size = 2;
2321*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2322*d9f75844SAndroid Build Coastguard Worker
2323*d9f75844SAndroid Build Coastguard Worker // Set local answer; now it's too late.
2324*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
2325*d9f75844SAndroid Build Coastguard Worker config.ice_candidate_pool_size = 3;
2326*d9f75844SAndroid Build Coastguard Worker RTCError error = pc_->SetConfiguration(config);
2327*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2328*d9f75844SAndroid Build Coastguard Worker }
2329*d9f75844SAndroid Build Coastguard Worker
2330*d9f75844SAndroid Build Coastguard Worker // Test that after setting an answer, extra pooled sessions are discarded. The
2331*d9f75844SAndroid Build Coastguard Worker // ICE candidate pool is only intended to be used for the first offer/answer.
TEST_P(PeerConnectionInterfaceTest,ExtraPooledSessionsDiscardedAfterApplyingAnswer)2332*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2333*d9f75844SAndroid Build Coastguard Worker ExtraPooledSessionsDiscardedAfterApplyingAnswer) {
2334*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
2335*d9f75844SAndroid Build Coastguard Worker
2336*d9f75844SAndroid Build Coastguard Worker // Set a larger-than-necessary size.
2337*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
2338*d9f75844SAndroid Build Coastguard Worker config.ice_candidate_pool_size = 4;
2339*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2340*d9f75844SAndroid Build Coastguard Worker
2341*d9f75844SAndroid Build Coastguard Worker // Do offer/answer.
2342*d9f75844SAndroid Build Coastguard Worker CreateOfferAsRemoteDescription();
2343*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
2344*d9f75844SAndroid Build Coastguard Worker
2345*d9f75844SAndroid Build Coastguard Worker // Expect no pooled sessions to be left.
2346*d9f75844SAndroid Build Coastguard Worker const cricket::PortAllocatorSession* session =
2347*d9f75844SAndroid Build Coastguard Worker port_allocator_->GetPooledSession();
2348*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, session);
2349*d9f75844SAndroid Build Coastguard Worker }
2350*d9f75844SAndroid Build Coastguard Worker
2351*d9f75844SAndroid Build Coastguard Worker // After Close is called, pooled candidates should be discarded so as to not
2352*d9f75844SAndroid Build Coastguard Worker // waste network resources.
TEST_P(PeerConnectionInterfaceTest,PooledSessionsDiscardedAfterClose)2353*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, PooledSessionsDiscardedAfterClose) {
2354*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
2355*d9f75844SAndroid Build Coastguard Worker
2356*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config = pc_->GetConfiguration();
2357*d9f75844SAndroid Build Coastguard Worker config.ice_candidate_pool_size = 3;
2358*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
2359*d9f75844SAndroid Build Coastguard Worker pc_->Close();
2360*d9f75844SAndroid Build Coastguard Worker
2361*d9f75844SAndroid Build Coastguard Worker // Expect no pooled sessions to be left.
2362*d9f75844SAndroid Build Coastguard Worker const cricket::PortAllocatorSession* session =
2363*d9f75844SAndroid Build Coastguard Worker port_allocator_->GetPooledSession();
2364*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, session);
2365*d9f75844SAndroid Build Coastguard Worker }
2366*d9f75844SAndroid Build Coastguard Worker
2367*d9f75844SAndroid Build Coastguard Worker // Test that SetConfiguration returns an invalid modification error if
2368*d9f75844SAndroid Build Coastguard Worker // modifying a field in the configuration that isn't allowed to be modified.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationReturnsInvalidModificationError)2369*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2370*d9f75844SAndroid Build Coastguard Worker SetConfigurationReturnsInvalidModificationError) {
2371*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
2372*d9f75844SAndroid Build Coastguard Worker config.bundle_policy = PeerConnectionInterface::kBundlePolicyBalanced;
2373*d9f75844SAndroid Build Coastguard Worker config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyNegotiate;
2374*d9f75844SAndroid Build Coastguard Worker config.continual_gathering_policy = PeerConnectionInterface::GATHER_ONCE;
2375*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2376*d9f75844SAndroid Build Coastguard Worker
2377*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration modified_config =
2378*d9f75844SAndroid Build Coastguard Worker pc_->GetConfiguration();
2379*d9f75844SAndroid Build Coastguard Worker modified_config.bundle_policy =
2380*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::kBundlePolicyMaxBundle;
2381*d9f75844SAndroid Build Coastguard Worker RTCError error = pc_->SetConfiguration(modified_config);
2382*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2383*d9f75844SAndroid Build Coastguard Worker
2384*d9f75844SAndroid Build Coastguard Worker modified_config = pc_->GetConfiguration();
2385*d9f75844SAndroid Build Coastguard Worker modified_config.rtcp_mux_policy =
2386*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::kRtcpMuxPolicyRequire;
2387*d9f75844SAndroid Build Coastguard Worker error = pc_->SetConfiguration(modified_config);
2388*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2389*d9f75844SAndroid Build Coastguard Worker
2390*d9f75844SAndroid Build Coastguard Worker modified_config = pc_->GetConfiguration();
2391*d9f75844SAndroid Build Coastguard Worker modified_config.continual_gathering_policy =
2392*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::GATHER_CONTINUALLY;
2393*d9f75844SAndroid Build Coastguard Worker error = pc_->SetConfiguration(modified_config);
2394*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, error.type());
2395*d9f75844SAndroid Build Coastguard Worker }
2396*d9f75844SAndroid Build Coastguard Worker
2397*d9f75844SAndroid Build Coastguard Worker // Test that SetConfiguration returns a range error if the candidate pool size
2398*d9f75844SAndroid Build Coastguard Worker // is negative or larger than allowed by the spec.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationReturnsRangeErrorForBadCandidatePoolSize)2399*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2400*d9f75844SAndroid Build Coastguard Worker SetConfigurationReturnsRangeErrorForBadCandidatePoolSize) {
2401*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
2402*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2403*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
2404*d9f75844SAndroid Build Coastguard Worker
2405*d9f75844SAndroid Build Coastguard Worker config.ice_candidate_pool_size = -1;
2406*d9f75844SAndroid Build Coastguard Worker RTCError error = pc_->SetConfiguration(config);
2407*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2408*d9f75844SAndroid Build Coastguard Worker
2409*d9f75844SAndroid Build Coastguard Worker config.ice_candidate_pool_size = INT_MAX;
2410*d9f75844SAndroid Build Coastguard Worker error = pc_->SetConfiguration(config);
2411*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(RTCErrorType::INVALID_RANGE, error.type());
2412*d9f75844SAndroid Build Coastguard Worker }
2413*d9f75844SAndroid Build Coastguard Worker
2414*d9f75844SAndroid Build Coastguard Worker // Test that SetConfiguration returns a syntax error if parsing an ICE server
2415*d9f75844SAndroid Build Coastguard Worker // URL failed.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationReturnsSyntaxErrorFromBadIceUrls)2416*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2417*d9f75844SAndroid Build Coastguard Worker SetConfigurationReturnsSyntaxErrorFromBadIceUrls) {
2418*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
2419*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2420*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
2421*d9f75844SAndroid Build Coastguard Worker
2422*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::IceServer bad_server;
2423*d9f75844SAndroid Build Coastguard Worker bad_server.uri = "stunn:www.example.com";
2424*d9f75844SAndroid Build Coastguard Worker config.servers.push_back(bad_server);
2425*d9f75844SAndroid Build Coastguard Worker RTCError error = pc_->SetConfiguration(config);
2426*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(RTCErrorType::SYNTAX_ERROR, error.type());
2427*d9f75844SAndroid Build Coastguard Worker }
2428*d9f75844SAndroid Build Coastguard Worker
2429*d9f75844SAndroid Build Coastguard Worker // Test that SetConfiguration returns an invalid parameter error if a TURN
2430*d9f75844SAndroid Build Coastguard Worker // IceServer is missing a username or password.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationReturnsInvalidParameterIfCredentialsMissing)2431*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2432*d9f75844SAndroid Build Coastguard Worker SetConfigurationReturnsInvalidParameterIfCredentialsMissing) {
2433*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
2434*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2435*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
2436*d9f75844SAndroid Build Coastguard Worker
2437*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::IceServer bad_server;
2438*d9f75844SAndroid Build Coastguard Worker bad_server.uri = "turn:www.example.com";
2439*d9f75844SAndroid Build Coastguard Worker // Missing password.
2440*d9f75844SAndroid Build Coastguard Worker bad_server.username = "foo";
2441*d9f75844SAndroid Build Coastguard Worker config.servers.push_back(bad_server);
2442*d9f75844SAndroid Build Coastguard Worker RTCError error;
2443*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(pc_->SetConfiguration(config).type(),
2444*d9f75844SAndroid Build Coastguard Worker RTCErrorType::INVALID_PARAMETER);
2445*d9f75844SAndroid Build Coastguard Worker }
2446*d9f75844SAndroid Build Coastguard Worker
2447*d9f75844SAndroid Build Coastguard Worker // Test that PeerConnection::Close changes the states to closed and all remote
2448*d9f75844SAndroid Build Coastguard Worker // tracks change state to ended.
TEST_P(PeerConnectionInterfaceTest,CloseAndTestStreamsAndStates)2449*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CloseAndTestStreamsAndStates) {
2450*d9f75844SAndroid Build Coastguard Worker // Initialize a PeerConnection and negotiate local and remote session
2451*d9f75844SAndroid Build Coastguard Worker // description.
2452*d9f75844SAndroid Build Coastguard Worker InitiateCall();
2453*d9f75844SAndroid Build Coastguard Worker
2454*d9f75844SAndroid Build Coastguard Worker // With Plan B, verify the stream count. The analog with Unified Plan is the
2455*d9f75844SAndroid Build Coastguard Worker // RtpTransceiver count.
2456*d9f75844SAndroid Build Coastguard Worker if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
2457*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, pc_->local_streams()->count());
2458*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, pc_->remote_streams()->count());
2459*d9f75844SAndroid Build Coastguard Worker } else {
2460*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(2u, pc_->GetTransceivers().size());
2461*d9f75844SAndroid Build Coastguard Worker }
2462*d9f75844SAndroid Build Coastguard Worker
2463*d9f75844SAndroid Build Coastguard Worker pc_->Close();
2464*d9f75844SAndroid Build Coastguard Worker
2465*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kClosed, pc_->signaling_state());
2466*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kIceConnectionClosed,
2467*d9f75844SAndroid Build Coastguard Worker pc_->ice_connection_state());
2468*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
2469*d9f75844SAndroid Build Coastguard Worker pc_->ice_gathering_state());
2470*d9f75844SAndroid Build Coastguard Worker
2471*d9f75844SAndroid Build Coastguard Worker if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
2472*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, pc_->local_streams()->count());
2473*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, pc_->remote_streams()->count());
2474*d9f75844SAndroid Build Coastguard Worker } else {
2475*d9f75844SAndroid Build Coastguard Worker // Verify that the RtpTransceivers are still returned.
2476*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(2u, pc_->GetTransceivers().size());
2477*d9f75844SAndroid Build Coastguard Worker }
2478*d9f75844SAndroid Build Coastguard Worker
2479*d9f75844SAndroid Build Coastguard Worker auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2480*d9f75844SAndroid Build Coastguard Worker auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2481*d9f75844SAndroid Build Coastguard Worker if (sdp_semantics_ == SdpSemantics::kPlanB_DEPRECATED) {
2482*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(audio_receiver);
2483*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(video_receiver);
2484*d9f75844SAndroid Build Coastguard Worker // Track state may be updated asynchronously.
2485*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2486*d9f75844SAndroid Build Coastguard Worker audio_receiver->track()->state(), kTimeout);
2487*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
2488*d9f75844SAndroid Build Coastguard Worker video_receiver->track()->state(), kTimeout);
2489*d9f75844SAndroid Build Coastguard Worker } else {
2490*d9f75844SAndroid Build Coastguard Worker ASSERT_FALSE(audio_receiver);
2491*d9f75844SAndroid Build Coastguard Worker ASSERT_FALSE(video_receiver);
2492*d9f75844SAndroid Build Coastguard Worker }
2493*d9f75844SAndroid Build Coastguard Worker }
2494*d9f75844SAndroid Build Coastguard Worker
2495*d9f75844SAndroid Build Coastguard Worker // Test that PeerConnection methods fails gracefully after
2496*d9f75844SAndroid Build Coastguard Worker // PeerConnection::Close has been called.
2497*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,CloseAndTestMethods)2498*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, CloseAndTestMethods) {
2499*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
2500*d9f75844SAndroid Build Coastguard Worker AddAudioVideoStream(kStreamId1, "audio_label", "video_label");
2501*d9f75844SAndroid Build Coastguard Worker CreateOfferAsRemoteDescription();
2502*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
2503*d9f75844SAndroid Build Coastguard Worker
2504*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, pc_->local_streams()->count());
2505*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamInterface> local_stream(
2506*d9f75844SAndroid Build Coastguard Worker pc_->local_streams()->at(0));
2507*d9f75844SAndroid Build Coastguard Worker
2508*d9f75844SAndroid Build Coastguard Worker pc_->Close();
2509*d9f75844SAndroid Build Coastguard Worker
2510*d9f75844SAndroid Build Coastguard Worker pc_->RemoveStream(local_stream.get());
2511*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->AddStream(local_stream.get()));
2512*d9f75844SAndroid Build Coastguard Worker
2513*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->CreateDataChannelOrError("test", NULL).ok());
2514*d9f75844SAndroid Build Coastguard Worker
2515*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->local_description() != nullptr);
2516*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->remote_description() != nullptr);
2517*d9f75844SAndroid Build Coastguard Worker
2518*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
2519*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoCreateOffer(&offer, nullptr));
2520*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
2521*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoCreateAnswer(&answer, nullptr));
2522*d9f75844SAndroid Build Coastguard Worker
2523*d9f75844SAndroid Build Coastguard Worker std::string sdp;
2524*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pc_->remote_description()->ToString(&sdp));
2525*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> remote_offer(
2526*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
2527*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoSetRemoteDescription(std::move(remote_offer)));
2528*d9f75844SAndroid Build Coastguard Worker
2529*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pc_->local_description()->ToString(&sdp));
2530*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> local_offer(
2531*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
2532*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoSetLocalDescription(std::move(local_offer)));
2533*d9f75844SAndroid Build Coastguard Worker }
2534*d9f75844SAndroid Build Coastguard Worker
2535*d9f75844SAndroid Build Coastguard Worker // Test that GetStats can still be called after PeerConnection::Close.
TEST_P(PeerConnectionInterfaceTest,CloseAndGetStats)2536*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CloseAndGetStats) {
2537*d9f75844SAndroid Build Coastguard Worker InitiateCall();
2538*d9f75844SAndroid Build Coastguard Worker pc_->Close();
2539*d9f75844SAndroid Build Coastguard Worker DoGetStats(nullptr);
2540*d9f75844SAndroid Build Coastguard Worker }
2541*d9f75844SAndroid Build Coastguard Worker
2542*d9f75844SAndroid Build Coastguard Worker // NOTE: The series of tests below come from what used to be
2543*d9f75844SAndroid Build Coastguard Worker // mediastreamsignaling_unittest.cc, and are mostly aimed at testing that
2544*d9f75844SAndroid Build Coastguard Worker // setting a remote or local description has the expected effects.
2545*d9f75844SAndroid Build Coastguard Worker
2546*d9f75844SAndroid Build Coastguard Worker // This test verifies that the remote MediaStreams corresponding to a received
2547*d9f75844SAndroid Build Coastguard Worker // SDP string is created. In this test the two separate MediaStreams are
2548*d9f75844SAndroid Build Coastguard Worker // signaled.
TEST_P(PeerConnectionInterfaceTest,UpdateRemoteStreams)2549*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, UpdateRemoteStreams) {
2550*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2551*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2552*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(GetSdpStringWithStream1());
2553*d9f75844SAndroid Build Coastguard Worker
2554*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
2555*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(
2556*d9f75844SAndroid Build Coastguard Worker CompareStreamCollections(observer_.remote_streams(), reference.get()));
2557*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2558*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(remote_stream->GetVideoTracks()[0]->GetSource() != nullptr);
2559*d9f75844SAndroid Build Coastguard Worker
2560*d9f75844SAndroid Build Coastguard Worker // Create a session description based on another SDP with another
2561*d9f75844SAndroid Build Coastguard Worker // MediaStream.
2562*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(GetSdpStringWithStream1And2());
2563*d9f75844SAndroid Build Coastguard Worker
2564*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<StreamCollection> reference2(CreateStreamCollection(2, 1));
2565*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(
2566*d9f75844SAndroid Build Coastguard Worker CompareStreamCollections(observer_.remote_streams(), reference2.get()));
2567*d9f75844SAndroid Build Coastguard Worker }
2568*d9f75844SAndroid Build Coastguard Worker
2569*d9f75844SAndroid Build Coastguard Worker // This test verifies that when remote tracks are added/removed from SDP, the
2570*d9f75844SAndroid Build Coastguard Worker // created remote streams are updated appropriately.
2571*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this test uses Plan B SDP to test Plan B
2572*d9f75844SAndroid Build Coastguard Worker // specific behavior.
TEST_F(PeerConnectionInterfaceTestPlanB,AddRemoveTrackFromExistingRemoteMediaStream)2573*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
2574*d9f75844SAndroid Build Coastguard Worker AddRemoveTrackFromExistingRemoteMediaStream) {
2575*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2576*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2577*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> desc_ms1 =
2578*d9f75844SAndroid Build Coastguard Worker CreateSessionDescriptionAndReference(1, 1);
2579*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1)));
2580*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2581*d9f75844SAndroid Build Coastguard Worker reference_collection_.get()));
2582*d9f75844SAndroid Build Coastguard Worker
2583*d9f75844SAndroid Build Coastguard Worker // Add extra audio and video tracks to the same MediaStream.
2584*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
2585*d9f75844SAndroid Build Coastguard Worker CreateSessionDescriptionAndReference(2, 2);
2586*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms1_two_tracks)));
2587*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2588*d9f75844SAndroid Build Coastguard Worker reference_collection_.get()));
2589*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> audio_track2 =
2590*d9f75844SAndroid Build Coastguard Worker observer_.remote_streams()->at(0)->GetAudioTracks()[1];
2591*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
2592*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> video_track2 =
2593*d9f75844SAndroid Build Coastguard Worker observer_.remote_streams()->at(0)->GetVideoTracks()[1];
2594*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
2595*d9f75844SAndroid Build Coastguard Worker
2596*d9f75844SAndroid Build Coastguard Worker // Remove the extra audio and video tracks.
2597*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> desc_ms2 =
2598*d9f75844SAndroid Build Coastguard Worker CreateSessionDescriptionAndReference(1, 1);
2599*d9f75844SAndroid Build Coastguard Worker MockTrackObserver audio_track_observer(audio_track2.get());
2600*d9f75844SAndroid Build Coastguard Worker MockTrackObserver video_track_observer(video_track2.get());
2601*d9f75844SAndroid Build Coastguard Worker
2602*d9f75844SAndroid Build Coastguard Worker EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
2603*d9f75844SAndroid Build Coastguard Worker EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
2604*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(desc_ms2)));
2605*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
2606*d9f75844SAndroid Build Coastguard Worker reference_collection_.get()));
2607*d9f75844SAndroid Build Coastguard Worker // Track state may be updated asynchronously.
2608*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2609*d9f75844SAndroid Build Coastguard Worker audio_track2->state(), kTimeout);
2610*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2611*d9f75844SAndroid Build Coastguard Worker video_track2->state(), kTimeout);
2612*d9f75844SAndroid Build Coastguard Worker }
2613*d9f75844SAndroid Build Coastguard Worker
2614*d9f75844SAndroid Build Coastguard Worker // This tests that remote tracks are ended if a local session description is set
2615*d9f75844SAndroid Build Coastguard Worker // that rejects the media content type.
TEST_P(PeerConnectionInterfaceTest,RejectMediaContent)2616*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, RejectMediaContent) {
2617*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2618*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2619*d9f75844SAndroid Build Coastguard Worker // First create and set a remote offer, then reject its video content in our
2620*d9f75844SAndroid Build Coastguard Worker // answer.
2621*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
2622*d9f75844SAndroid Build Coastguard Worker auto audio_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_AUDIO);
2623*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(audio_receiver);
2624*d9f75844SAndroid Build Coastguard Worker auto video_receiver = GetFirstReceiverOfType(cricket::MEDIA_TYPE_VIDEO);
2625*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(video_receiver);
2626*d9f75844SAndroid Build Coastguard Worker
2627*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamTrackInterface> remote_audio =
2628*d9f75844SAndroid Build Coastguard Worker audio_receiver->track();
2629*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, remote_audio->state());
2630*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamTrackInterface> remote_video =
2631*d9f75844SAndroid Build Coastguard Worker video_receiver->track();
2632*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_video->state());
2633*d9f75844SAndroid Build Coastguard Worker
2634*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> local_answer;
2635*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoCreateAnswer(&local_answer, nullptr));
2636*d9f75844SAndroid Build Coastguard Worker cricket::ContentInfo* video_info =
2637*d9f75844SAndroid Build Coastguard Worker local_answer->description()->GetContentByName("video");
2638*d9f75844SAndroid Build Coastguard Worker video_info->rejected = true;
2639*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
2640*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(MediaStreamTrackInterface::kEnded, remote_video->state());
2641*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(MediaStreamTrackInterface::kLive, remote_audio->state());
2642*d9f75844SAndroid Build Coastguard Worker
2643*d9f75844SAndroid Build Coastguard Worker // Now create an offer where we reject both video and audio.
2644*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> local_offer;
2645*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
2646*d9f75844SAndroid Build Coastguard Worker video_info = local_offer->description()->GetContentByName("video");
2647*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(video_info != nullptr);
2648*d9f75844SAndroid Build Coastguard Worker video_info->rejected = true;
2649*d9f75844SAndroid Build Coastguard Worker cricket::ContentInfo* audio_info =
2650*d9f75844SAndroid Build Coastguard Worker local_offer->description()->GetContentByName("audio");
2651*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(audio_info != nullptr);
2652*d9f75844SAndroid Build Coastguard Worker audio_info->rejected = true;
2653*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
2654*d9f75844SAndroid Build Coastguard Worker // Track state may be updated asynchronously.
2655*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_audio->state(),
2656*d9f75844SAndroid Build Coastguard Worker kTimeout);
2657*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded, remote_video->state(),
2658*d9f75844SAndroid Build Coastguard Worker kTimeout);
2659*d9f75844SAndroid Build Coastguard Worker }
2660*d9f75844SAndroid Build Coastguard Worker
2661*d9f75844SAndroid Build Coastguard Worker // This tests that we won't crash if the remote track has been removed outside
2662*d9f75844SAndroid Build Coastguard Worker // of PeerConnection and then PeerConnection tries to reject the track.
2663*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,RemoveTrackThenRejectMediaContent)2664*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, RemoveTrackThenRejectMediaContent) {
2665*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2666*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2667*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(GetSdpStringWithStream1());
2668*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2669*d9f75844SAndroid Build Coastguard Worker remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2670*d9f75844SAndroid Build Coastguard Worker remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2671*d9f75844SAndroid Build Coastguard Worker
2672*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> local_answer(
2673*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kAnswer,
2674*d9f75844SAndroid Build Coastguard Worker GetSdpStringWithStream1(), nullptr));
2675*d9f75844SAndroid Build Coastguard Worker cricket::ContentInfo* video_info =
2676*d9f75844SAndroid Build Coastguard Worker local_answer->description()->GetContentByName("video");
2677*d9f75844SAndroid Build Coastguard Worker video_info->rejected = true;
2678*d9f75844SAndroid Build Coastguard Worker cricket::ContentInfo* audio_info =
2679*d9f75844SAndroid Build Coastguard Worker local_answer->description()->GetContentByName("audio");
2680*d9f75844SAndroid Build Coastguard Worker audio_info->rejected = true;
2681*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
2682*d9f75844SAndroid Build Coastguard Worker
2683*d9f75844SAndroid Build Coastguard Worker // No crash is a pass.
2684*d9f75844SAndroid Build Coastguard Worker }
2685*d9f75844SAndroid Build Coastguard Worker
2686*d9f75844SAndroid Build Coastguard Worker // This tests that if a recvonly remote description is set, no remote streams
2687*d9f75844SAndroid Build Coastguard Worker // will be created, even if the description contains SSRCs/MSIDs.
2688*d9f75844SAndroid Build Coastguard Worker // See: https://code.google.com/p/webrtc/issues/detail?id=5054
TEST_P(PeerConnectionInterfaceTest,RecvonlyDescriptionDoesntCreateStream)2689*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, RecvonlyDescriptionDoesntCreateStream) {
2690*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2691*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2692*d9f75844SAndroid Build Coastguard Worker
2693*d9f75844SAndroid Build Coastguard Worker std::string recvonly_offer = GetSdpStringWithStream1();
2694*d9f75844SAndroid Build Coastguard Worker absl::StrReplaceAll({{kSendrecv, kRecvonly}}, &recvonly_offer);
2695*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(recvonly_offer);
2696*d9f75844SAndroid Build Coastguard Worker
2697*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, observer_.remote_streams()->count());
2698*d9f75844SAndroid Build Coastguard Worker }
2699*d9f75844SAndroid Build Coastguard Worker
2700*d9f75844SAndroid Build Coastguard Worker // This tests that a default MediaStream is created if a remote session
2701*d9f75844SAndroid Build Coastguard Worker // description doesn't contain any streams and no MSID support.
2702*d9f75844SAndroid Build Coastguard Worker // It also tests that the default stream is updated if a video m-line is added
2703*d9f75844SAndroid Build Coastguard Worker // in a subsequent session description.
2704*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is Plan B specific.
TEST_F(PeerConnectionInterfaceTestPlanB,SdpWithoutMsidCreatesDefaultStream)2705*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithoutMsidCreatesDefaultStream) {
2706*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2707*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2708*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2709*d9f75844SAndroid Build Coastguard Worker
2710*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, observer_.remote_streams()->count());
2711*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2712*d9f75844SAndroid Build Coastguard Worker
2713*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2714*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, remote_stream->GetVideoTracks().size());
2715*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("default", remote_stream->id());
2716*d9f75844SAndroid Build Coastguard Worker
2717*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2718*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, observer_.remote_streams()->count());
2719*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2720*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("defaulta0", remote_stream->GetAudioTracks()[0]->id());
2721*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(MediaStreamTrackInterface::kLive,
2722*d9f75844SAndroid Build Coastguard Worker remote_stream->GetAudioTracks()[0]->state());
2723*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, remote_stream->GetVideoTracks().size());
2724*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("defaultv0", remote_stream->GetVideoTracks()[0]->id());
2725*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(MediaStreamTrackInterface::kLive,
2726*d9f75844SAndroid Build Coastguard Worker remote_stream->GetVideoTracks()[0]->state());
2727*d9f75844SAndroid Build Coastguard Worker }
2728*d9f75844SAndroid Build Coastguard Worker
2729*d9f75844SAndroid Build Coastguard Worker // This tests that a default MediaStream is created if a remote session
2730*d9f75844SAndroid Build Coastguard Worker // description doesn't contain any streams and media direction is send only.
2731*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is Plan B specific.
TEST_F(PeerConnectionInterfaceTestPlanB,SendOnlySdpWithoutMsidCreatesDefaultStream)2732*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
2733*d9f75844SAndroid Build Coastguard Worker SendOnlySdpWithoutMsidCreatesDefaultStream) {
2734*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2735*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2736*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringSendOnlyWithoutStreams);
2737*d9f75844SAndroid Build Coastguard Worker
2738*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, observer_.remote_streams()->count());
2739*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2740*d9f75844SAndroid Build Coastguard Worker
2741*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2742*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2743*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("default", remote_stream->id());
2744*d9f75844SAndroid Build Coastguard Worker }
2745*d9f75844SAndroid Build Coastguard Worker
2746*d9f75844SAndroid Build Coastguard Worker // This tests that it won't crash when PeerConnection tries to remove
2747*d9f75844SAndroid Build Coastguard Worker // a remote track that as already been removed from the MediaStream.
2748*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is Plan B specific.
TEST_F(PeerConnectionInterfaceTestPlanB,RemoveAlreadyGoneRemoteStream)2749*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, RemoveAlreadyGoneRemoteStream) {
2750*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2751*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2752*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(GetSdpStringWithStream1());
2753*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2754*d9f75844SAndroid Build Coastguard Worker remote_stream->RemoveTrack(remote_stream->GetAudioTracks()[0]);
2755*d9f75844SAndroid Build Coastguard Worker remote_stream->RemoveTrack(remote_stream->GetVideoTracks()[0]);
2756*d9f75844SAndroid Build Coastguard Worker
2757*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2758*d9f75844SAndroid Build Coastguard Worker
2759*d9f75844SAndroid Build Coastguard Worker // No crash is a pass.
2760*d9f75844SAndroid Build Coastguard Worker }
2761*d9f75844SAndroid Build Coastguard Worker
2762*d9f75844SAndroid Build Coastguard Worker // This tests that a default MediaStream is created if the remote session
2763*d9f75844SAndroid Build Coastguard Worker // description doesn't contain any streams and don't contain an indication if
2764*d9f75844SAndroid Build Coastguard Worker // MSID is supported.
2765*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is Plan B specific.
TEST_F(PeerConnectionInterfaceTestPlanB,SdpWithoutMsidAndStreamsCreatesDefaultStream)2766*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
2767*d9f75844SAndroid Build Coastguard Worker SdpWithoutMsidAndStreamsCreatesDefaultStream) {
2768*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2769*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2770*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2771*d9f75844SAndroid Build Coastguard Worker
2772*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, observer_.remote_streams()->count());
2773*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2774*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, remote_stream->GetAudioTracks().size());
2775*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, remote_stream->GetVideoTracks().size());
2776*d9f75844SAndroid Build Coastguard Worker }
2777*d9f75844SAndroid Build Coastguard Worker
2778*d9f75844SAndroid Build Coastguard Worker // This tests that a default MediaStream is not created if the remote session
2779*d9f75844SAndroid Build Coastguard Worker // description doesn't contain any streams but does support MSID.
2780*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is Plan B specific.
TEST_F(PeerConnectionInterfaceTestPlanB,SdpWithMsidDontCreatesDefaultStream)2781*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, SdpWithMsidDontCreatesDefaultStream) {
2782*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2783*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2784*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithMsidWithoutStreams);
2785*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, observer_.remote_streams()->count());
2786*d9f75844SAndroid Build Coastguard Worker }
2787*d9f75844SAndroid Build Coastguard Worker
2788*d9f75844SAndroid Build Coastguard Worker // This tests that when setting a new description, the old default tracks are
2789*d9f75844SAndroid Build Coastguard Worker // not destroyed and recreated.
2790*d9f75844SAndroid Build Coastguard Worker // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=5250
2791*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is Plan B specific.
TEST_F(PeerConnectionInterfaceTestPlanB,DefaultTracksNotDestroyedAndRecreated)2792*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
2793*d9f75844SAndroid Build Coastguard Worker DefaultTracksNotDestroyedAndRecreated) {
2794*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2795*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2796*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2797*d9f75844SAndroid Build Coastguard Worker
2798*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, observer_.remote_streams()->count());
2799*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2800*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2801*d9f75844SAndroid Build Coastguard Worker
2802*d9f75844SAndroid Build Coastguard Worker // Set the track to "disabled", then set a new description and ensure the
2803*d9f75844SAndroid Build Coastguard Worker // track is still disabled, which ensures it hasn't been recreated.
2804*d9f75844SAndroid Build Coastguard Worker remote_stream->GetAudioTracks()[0]->set_enabled(false);
2805*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithoutStreamsAudioOnly);
2806*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2807*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(remote_stream->GetAudioTracks()[0]->enabled());
2808*d9f75844SAndroid Build Coastguard Worker }
2809*d9f75844SAndroid Build Coastguard Worker
2810*d9f75844SAndroid Build Coastguard Worker // This tests that a default MediaStream is not created if a remote session
2811*d9f75844SAndroid Build Coastguard Worker // description is updated to not have any MediaStreams.
2812*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is Plan B specific.
TEST_F(PeerConnectionInterfaceTestPlanB,VerifyDefaultStreamIsNotCreated)2813*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, VerifyDefaultStreamIsNotCreated) {
2814*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2815*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2816*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(GetSdpStringWithStream1());
2817*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<StreamCollection> reference(CreateStreamCollection(1, 1));
2818*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(
2819*d9f75844SAndroid Build Coastguard Worker CompareStreamCollections(observer_.remote_streams(), reference.get()));
2820*d9f75844SAndroid Build Coastguard Worker
2821*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithoutStreams);
2822*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, observer_.remote_streams()->count());
2823*d9f75844SAndroid Build Coastguard Worker }
2824*d9f75844SAndroid Build Coastguard Worker
2825*d9f75844SAndroid Build Coastguard Worker // This tests that a default MediaStream is created if a remote SDP comes from
2826*d9f75844SAndroid Build Coastguard Worker // an endpoint that doesn't signal SSRCs, but signals media stream IDs.
TEST_F(PeerConnectionInterfaceTestPlanB,SdpWithMsidWithoutSsrcCreatesDefaultStream)2827*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
2828*d9f75844SAndroid Build Coastguard Worker SdpWithMsidWithoutSsrcCreatesDefaultStream) {
2829*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2830*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2831*d9f75844SAndroid Build Coastguard Worker std::string sdp_string = kSdpStringWithoutStreamsAudioOnly;
2832*d9f75844SAndroid Build Coastguard Worker // Add a=msid lines to simulate a Unified Plan endpoint that only
2833*d9f75844SAndroid Build Coastguard Worker // signals stream IDs with a=msid lines.
2834*d9f75844SAndroid Build Coastguard Worker sdp_string.append("a=msid:audio_stream_id audio_track_id\n");
2835*d9f75844SAndroid Build Coastguard Worker
2836*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(sdp_string);
2837*d9f75844SAndroid Build Coastguard Worker
2838*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, observer_.remote_streams()->count());
2839*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2840*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("default", remote_stream->id());
2841*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2842*d9f75844SAndroid Build Coastguard Worker }
2843*d9f75844SAndroid Build Coastguard Worker
2844*d9f75844SAndroid Build Coastguard Worker // This tests that when a Plan B endpoint receives an SDP that signals no media
2845*d9f75844SAndroid Build Coastguard Worker // stream IDs indicated by the special character "-" in the a=msid line, that
2846*d9f75844SAndroid Build Coastguard Worker // a default stream ID will be used for the MediaStream ID. This can occur
2847*d9f75844SAndroid Build Coastguard Worker // when a Unified Plan endpoint signals no media stream IDs, but signals both
2848*d9f75844SAndroid Build Coastguard Worker // a=ssrc msid and a=msid lines for interop signaling with Plan B.
TEST_F(PeerConnectionInterfaceTestPlanB,SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId)2849*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
2850*d9f75844SAndroid Build Coastguard Worker SdpWithEmptyMsidAndSsrcCreatesDefaultStreamId) {
2851*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2852*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2853*d9f75844SAndroid Build Coastguard Worker // Add a a=msid line to the SDP. This is prioritized when parsing the SDP, so
2854*d9f75844SAndroid Build Coastguard Worker // the sender's stream ID will be interpreted as no stream IDs.
2855*d9f75844SAndroid Build Coastguard Worker std::string sdp_string = kSdpStringWithStream1AudioTrackOnly;
2856*d9f75844SAndroid Build Coastguard Worker sdp_string.append("a=msid:- audiotrack0\n");
2857*d9f75844SAndroid Build Coastguard Worker
2858*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(sdp_string);
2859*d9f75844SAndroid Build Coastguard Worker
2860*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, observer_.remote_streams()->count());
2861*d9f75844SAndroid Build Coastguard Worker // Because SSRCs are signaled the track ID will be what was signaled in the
2862*d9f75844SAndroid Build Coastguard Worker // a=msid line.
2863*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2864*d9f75844SAndroid Build Coastguard Worker MediaStreamInterface* remote_stream = observer_.remote_streams()->at(0);
2865*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("default", remote_stream->id());
2866*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2867*d9f75844SAndroid Build Coastguard Worker
2868*d9f75844SAndroid Build Coastguard Worker // Previously a bug ocurred when setting the remote description a second time.
2869*d9f75844SAndroid Build Coastguard Worker // This is because we checked equality of the remote StreamParams stream ID
2870*d9f75844SAndroid Build Coastguard Worker // (empty), and the previously set stream ID for the remote sender
2871*d9f75844SAndroid Build Coastguard Worker // ("default"). This cause a track to be removed, then added, when really
2872*d9f75844SAndroid Build Coastguard Worker // nothing should occur because it is the same track.
2873*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(sdp_string);
2874*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, observer_.remove_track_events_.size());
2875*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, observer_.add_track_events_.size());
2876*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("audiotrack0", observer_.last_added_track_label_);
2877*d9f75844SAndroid Build Coastguard Worker remote_stream = observer_.remote_streams()->at(0);
2878*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ("default", remote_stream->id());
2879*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(1u, remote_stream->GetAudioTracks().size());
2880*d9f75844SAndroid Build Coastguard Worker }
2881*d9f75844SAndroid Build Coastguard Worker
2882*d9f75844SAndroid Build Coastguard Worker // This tests that an RtpSender is created when the local description is set
2883*d9f75844SAndroid Build Coastguard Worker // after adding a local stream.
2884*d9f75844SAndroid Build Coastguard Worker // TODO(deadbeef): This test and the one below it need to be updated when
2885*d9f75844SAndroid Build Coastguard Worker // an RtpSender's lifetime isn't determined by when a local description is set.
2886*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is Plan B specific.
TEST_F(PeerConnectionInterfaceTestPlanB,LocalDescriptionChanged)2887*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB, LocalDescriptionChanged) {
2888*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2889*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2890*d9f75844SAndroid Build Coastguard Worker
2891*d9f75844SAndroid Build Coastguard Worker // Create an offer with 1 stream with 2 tracks of each type.
2892*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<StreamCollection> stream_collection =
2893*d9f75844SAndroid Build Coastguard Worker CreateStreamCollection(1, 2);
2894*d9f75844SAndroid Build Coastguard Worker pc_->AddStream(stream_collection->at(0));
2895*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
2896*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2897*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
2898*d9f75844SAndroid Build Coastguard Worker
2899*d9f75844SAndroid Build Coastguard Worker auto senders = pc_->GetSenders();
2900*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(4u, senders.size());
2901*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2902*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2903*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2904*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2905*d9f75844SAndroid Build Coastguard Worker
2906*d9f75844SAndroid Build Coastguard Worker // Remove an audio and video track.
2907*d9f75844SAndroid Build Coastguard Worker pc_->RemoveStream(stream_collection->at(0));
2908*d9f75844SAndroid Build Coastguard Worker stream_collection = CreateStreamCollection(1, 1);
2909*d9f75844SAndroid Build Coastguard Worker pc_->AddStream(stream_collection->at(0));
2910*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2911*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
2912*d9f75844SAndroid Build Coastguard Worker
2913*d9f75844SAndroid Build Coastguard Worker senders = pc_->GetSenders();
2914*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(2u, senders.size());
2915*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2916*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2917*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(ContainsSender(senders, kAudioTracks[1]));
2918*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(ContainsSender(senders, kVideoTracks[1]));
2919*d9f75844SAndroid Build Coastguard Worker }
2920*d9f75844SAndroid Build Coastguard Worker
2921*d9f75844SAndroid Build Coastguard Worker // This tests that an RtpSender is created when the local description is set
2922*d9f75844SAndroid Build Coastguard Worker // before adding a local stream.
2923*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is Plan B specific.
TEST_F(PeerConnectionInterfaceTestPlanB,AddLocalStreamAfterLocalDescriptionChanged)2924*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
2925*d9f75844SAndroid Build Coastguard Worker AddLocalStreamAfterLocalDescriptionChanged) {
2926*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2927*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2928*d9f75844SAndroid Build Coastguard Worker
2929*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<StreamCollection> stream_collection =
2930*d9f75844SAndroid Build Coastguard Worker CreateStreamCollection(1, 2);
2931*d9f75844SAndroid Build Coastguard Worker // Add a stream to create the offer, but remove it afterwards.
2932*d9f75844SAndroid Build Coastguard Worker pc_->AddStream(stream_collection->at(0));
2933*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
2934*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2935*d9f75844SAndroid Build Coastguard Worker pc_->RemoveStream(stream_collection->at(0));
2936*d9f75844SAndroid Build Coastguard Worker
2937*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
2938*d9f75844SAndroid Build Coastguard Worker auto senders = pc_->GetSenders();
2939*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(0u, senders.size());
2940*d9f75844SAndroid Build Coastguard Worker
2941*d9f75844SAndroid Build Coastguard Worker pc_->AddStream(stream_collection->at(0));
2942*d9f75844SAndroid Build Coastguard Worker senders = pc_->GetSenders();
2943*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(4u, senders.size());
2944*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2945*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2946*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kAudioTracks[1]));
2947*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kVideoTracks[1]));
2948*d9f75844SAndroid Build Coastguard Worker }
2949*d9f75844SAndroid Build Coastguard Worker
2950*d9f75844SAndroid Build Coastguard Worker // This tests that the expected behavior occurs if the SSRC on a local track is
2951*d9f75844SAndroid Build Coastguard Worker // changed when SetLocalDescription is called.
TEST_P(PeerConnectionInterfaceTest,ChangeSsrcOnTrackInLocalSessionDescription)2952*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
2953*d9f75844SAndroid Build Coastguard Worker ChangeSsrcOnTrackInLocalSessionDescription) {
2954*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
2955*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
2956*d9f75844SAndroid Build Coastguard Worker
2957*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[0]);
2958*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0]);
2959*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
2960*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
2961*d9f75844SAndroid Build Coastguard Worker // Grab a copy of the offer before it gets passed into the PC.
2962*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> modified_offer =
2963*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(
2964*d9f75844SAndroid Build Coastguard Worker webrtc::SdpType::kOffer, offer->session_id(),
2965*d9f75844SAndroid Build Coastguard Worker offer->session_version(), offer->description()->Clone());
2966*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
2967*d9f75844SAndroid Build Coastguard Worker
2968*d9f75844SAndroid Build Coastguard Worker auto senders = pc_->GetSenders();
2969*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(2u, senders.size());
2970*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2971*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2972*d9f75844SAndroid Build Coastguard Worker
2973*d9f75844SAndroid Build Coastguard Worker // Change the ssrc of the audio and video track.
2974*d9f75844SAndroid Build Coastguard Worker cricket::MediaContentDescription* desc =
2975*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstAudioContentDescription(modified_offer->description());
2976*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(desc != nullptr);
2977*d9f75844SAndroid Build Coastguard Worker for (StreamParams& stream : desc->mutable_streams()) {
2978*d9f75844SAndroid Build Coastguard Worker for (unsigned int& ssrc : stream.ssrcs) {
2979*d9f75844SAndroid Build Coastguard Worker ++ssrc;
2980*d9f75844SAndroid Build Coastguard Worker }
2981*d9f75844SAndroid Build Coastguard Worker }
2982*d9f75844SAndroid Build Coastguard Worker
2983*d9f75844SAndroid Build Coastguard Worker desc =
2984*d9f75844SAndroid Build Coastguard Worker cricket::GetFirstVideoContentDescription(modified_offer->description());
2985*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(desc != nullptr);
2986*d9f75844SAndroid Build Coastguard Worker for (StreamParams& stream : desc->mutable_streams()) {
2987*d9f75844SAndroid Build Coastguard Worker for (unsigned int& ssrc : stream.ssrcs) {
2988*d9f75844SAndroid Build Coastguard Worker ++ssrc;
2989*d9f75844SAndroid Build Coastguard Worker }
2990*d9f75844SAndroid Build Coastguard Worker }
2991*d9f75844SAndroid Build Coastguard Worker
2992*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(modified_offer)));
2993*d9f75844SAndroid Build Coastguard Worker senders = pc_->GetSenders();
2994*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(2u, senders.size());
2995*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0]));
2996*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0]));
2997*d9f75844SAndroid Build Coastguard Worker // TODO(deadbeef): Once RtpSenders expose parameters, check that the SSRC
2998*d9f75844SAndroid Build Coastguard Worker // changed.
2999*d9f75844SAndroid Build Coastguard Worker }
3000*d9f75844SAndroid Build Coastguard Worker
3001*d9f75844SAndroid Build Coastguard Worker // This tests that the expected behavior occurs if a new session description is
3002*d9f75844SAndroid Build Coastguard Worker // set with the same tracks, but on a different MediaStream.
3003*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
TEST_F(PeerConnectionInterfaceTestPlanB,SignalSameTracksInSeparateMediaStream)3004*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
3005*d9f75844SAndroid Build Coastguard Worker SignalSameTracksInSeparateMediaStream) {
3006*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
3007*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3008*d9f75844SAndroid Build Coastguard Worker
3009*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<StreamCollection> stream_collection =
3010*d9f75844SAndroid Build Coastguard Worker CreateStreamCollection(2, 1);
3011*d9f75844SAndroid Build Coastguard Worker pc_->AddStream(stream_collection->at(0));
3012*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3013*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3014*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
3015*d9f75844SAndroid Build Coastguard Worker
3016*d9f75844SAndroid Build Coastguard Worker auto senders = pc_->GetSenders();
3017*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(2u, senders.size());
3018*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kAudioTracks[0], kStreams[0]));
3019*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(senders, kVideoTracks[0], kStreams[0]));
3020*d9f75844SAndroid Build Coastguard Worker
3021*d9f75844SAndroid Build Coastguard Worker // Add a new MediaStream but with the same tracks as in the first stream.
3022*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<webrtc::MediaStreamInterface> stream_1(
3023*d9f75844SAndroid Build Coastguard Worker webrtc::MediaStream::Create(kStreams[1]));
3024*d9f75844SAndroid Build Coastguard Worker stream_1->AddTrack(stream_collection->at(0)->GetVideoTracks()[0]);
3025*d9f75844SAndroid Build Coastguard Worker stream_1->AddTrack(stream_collection->at(0)->GetAudioTracks()[0]);
3026*d9f75844SAndroid Build Coastguard Worker pc_->AddStream(stream_1.get());
3027*d9f75844SAndroid Build Coastguard Worker
3028*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3029*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(offer)));
3030*d9f75844SAndroid Build Coastguard Worker
3031*d9f75844SAndroid Build Coastguard Worker auto new_senders = pc_->GetSenders();
3032*d9f75844SAndroid Build Coastguard Worker // Should be the same senders as before, but with updated stream id.
3033*d9f75844SAndroid Build Coastguard Worker // Note that this behavior is subject to change in the future.
3034*d9f75844SAndroid Build Coastguard Worker // We may decide the PC should ignore existing tracks in AddStream.
3035*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(senders, new_senders);
3036*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1]));
3037*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1]));
3038*d9f75844SAndroid Build Coastguard Worker }
3039*d9f75844SAndroid Build Coastguard Worker
3040*d9f75844SAndroid Build Coastguard Worker // This tests that PeerConnectionObserver::OnAddTrack is correctly called.
TEST_P(PeerConnectionInterfaceTest,OnAddTrackCallback)3041*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, OnAddTrackCallback) {
3042*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
3043*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3044*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithStream1AudioTrackOnly);
3045*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(observer_.num_added_tracks_, 1);
3046*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(observer_.last_added_track_label_, kAudioTracks[0]);
3047*d9f75844SAndroid Build Coastguard Worker
3048*d9f75844SAndroid Build Coastguard Worker // Create and set the updated remote SDP.
3049*d9f75844SAndroid Build Coastguard Worker CreateAndSetRemoteOffer(kSdpStringWithStream1PlanB);
3050*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(observer_.num_added_tracks_, 2);
3051*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(observer_.last_added_track_label_, kVideoTracks[0]);
3052*d9f75844SAndroid Build Coastguard Worker }
3053*d9f75844SAndroid Build Coastguard Worker
3054*d9f75844SAndroid Build Coastguard Worker // Test that when SetConfiguration is called and the configuration is
3055*d9f75844SAndroid Build Coastguard Worker // changing, the next offer causes an ICE restart.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationCausingIceRestart)3056*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingIceRestart) {
3057*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3058*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
3059*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kRelay;
3060*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3061*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
3062*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[0], {kStreamId1});
3063*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0], {kStreamId1});
3064*d9f75844SAndroid Build Coastguard Worker
3065*d9f75844SAndroid Build Coastguard Worker // Do initial offer/answer so there's something to restart.
3066*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
3067*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
3068*d9f75844SAndroid Build Coastguard Worker
3069*d9f75844SAndroid Build Coastguard Worker // Grab the ufrags.
3070*d9f75844SAndroid Build Coastguard Worker std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3071*d9f75844SAndroid Build Coastguard Worker
3072*d9f75844SAndroid Build Coastguard Worker // Change ICE policy, which should trigger an ICE restart on the next offer.
3073*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kAll;
3074*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
3075*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
3076*d9f75844SAndroid Build Coastguard Worker
3077*d9f75844SAndroid Build Coastguard Worker // Grab the new ufrags.
3078*d9f75844SAndroid Build Coastguard Worker std::vector<std::string> subsequent_ufrags =
3079*d9f75844SAndroid Build Coastguard Worker GetUfrags(pc_->local_description());
3080*d9f75844SAndroid Build Coastguard Worker
3081*d9f75844SAndroid Build Coastguard Worker // Sanity check.
3082*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(initial_ufrags.size(), subsequent_ufrags.size());
3083*d9f75844SAndroid Build Coastguard Worker // Check that each ufrag is different.
3084*d9f75844SAndroid Build Coastguard Worker for (int i = 0; i < static_cast<int>(initial_ufrags.size()); ++i) {
3085*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(initial_ufrags[i], subsequent_ufrags[i]);
3086*d9f75844SAndroid Build Coastguard Worker }
3087*d9f75844SAndroid Build Coastguard Worker }
3088*d9f75844SAndroid Build Coastguard Worker
3089*d9f75844SAndroid Build Coastguard Worker // Test that when SetConfiguration is called and the configuration *isn't*
3090*d9f75844SAndroid Build Coastguard Worker // changing, the next offer does *not* cause an ICE restart.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationNotCausingIceRestart)3091*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetConfigurationNotCausingIceRestart) {
3092*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3093*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
3094*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kRelay;
3095*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3096*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
3097*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[0]);
3098*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0]);
3099*d9f75844SAndroid Build Coastguard Worker
3100*d9f75844SAndroid Build Coastguard Worker // Do initial offer/answer so there's something to restart.
3101*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
3102*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
3103*d9f75844SAndroid Build Coastguard Worker
3104*d9f75844SAndroid Build Coastguard Worker // Grab the ufrags.
3105*d9f75844SAndroid Build Coastguard Worker std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3106*d9f75844SAndroid Build Coastguard Worker
3107*d9f75844SAndroid Build Coastguard Worker // Call SetConfiguration with a config identical to what the PC was
3108*d9f75844SAndroid Build Coastguard Worker // constructed with.
3109*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
3110*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
3111*d9f75844SAndroid Build Coastguard Worker
3112*d9f75844SAndroid Build Coastguard Worker // Grab the new ufrags.
3113*d9f75844SAndroid Build Coastguard Worker std::vector<std::string> subsequent_ufrags =
3114*d9f75844SAndroid Build Coastguard Worker GetUfrags(pc_->local_description());
3115*d9f75844SAndroid Build Coastguard Worker
3116*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(initial_ufrags, subsequent_ufrags);
3117*d9f75844SAndroid Build Coastguard Worker }
3118*d9f75844SAndroid Build Coastguard Worker
3119*d9f75844SAndroid Build Coastguard Worker // Test for a weird corner case scenario:
3120*d9f75844SAndroid Build Coastguard Worker // 1. Audio/video session established.
3121*d9f75844SAndroid Build Coastguard Worker // 2. SetConfiguration changes ICE config; ICE restart needed.
3122*d9f75844SAndroid Build Coastguard Worker // 3. ICE restart initiated by remote peer, but only for one m= section.
3123*d9f75844SAndroid Build Coastguard Worker // 4. Next createOffer should initiate an ICE restart, but only for the other
3124*d9f75844SAndroid Build Coastguard Worker // m= section; it would be pointless to do an ICE restart for the m= section
3125*d9f75844SAndroid Build Coastguard Worker // that was already restarted.
TEST_P(PeerConnectionInterfaceTest,SetConfigurationCausingPartialIceRestart)3126*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetConfigurationCausingPartialIceRestart) {
3127*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3128*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
3129*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kRelay;
3130*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3131*d9f75844SAndroid Build Coastguard Worker config = pc_->GetConfiguration();
3132*d9f75844SAndroid Build Coastguard Worker AddAudioTrack(kAudioTracks[0], {kStreamId1});
3133*d9f75844SAndroid Build Coastguard Worker AddVideoTrack(kVideoTracks[0], {kStreamId1});
3134*d9f75844SAndroid Build Coastguard Worker
3135*d9f75844SAndroid Build Coastguard Worker // Do initial offer/answer so there's something to restart.
3136*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
3137*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsRemoteDescription(GetSdpStringWithStream1());
3138*d9f75844SAndroid Build Coastguard Worker
3139*d9f75844SAndroid Build Coastguard Worker // Change ICE policy, which should set the "needs-ice-restart" flag.
3140*d9f75844SAndroid Build Coastguard Worker config.type = PeerConnectionInterface::kAll;
3141*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetConfiguration(config).ok());
3142*d9f75844SAndroid Build Coastguard Worker
3143*d9f75844SAndroid Build Coastguard Worker // Do ICE restart for the first m= section, initiated by remote peer.
3144*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<webrtc::SessionDescriptionInterface> remote_offer(
3145*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer,
3146*d9f75844SAndroid Build Coastguard Worker GetSdpStringWithStream1(), nullptr));
3147*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(remote_offer);
3148*d9f75844SAndroid Build Coastguard Worker remote_offer->description()->transport_infos()[0].description.ice_ufrag =
3149*d9f75844SAndroid Build Coastguard Worker "modified";
3150*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3151*d9f75844SAndroid Build Coastguard Worker CreateAnswerAsLocalDescription();
3152*d9f75844SAndroid Build Coastguard Worker
3153*d9f75844SAndroid Build Coastguard Worker // Grab the ufrags.
3154*d9f75844SAndroid Build Coastguard Worker std::vector<std::string> initial_ufrags = GetUfrags(pc_->local_description());
3155*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(2U, initial_ufrags.size());
3156*d9f75844SAndroid Build Coastguard Worker
3157*d9f75844SAndroid Build Coastguard Worker // Create offer and grab the new ufrags.
3158*d9f75844SAndroid Build Coastguard Worker CreateOfferAsLocalDescription();
3159*d9f75844SAndroid Build Coastguard Worker std::vector<std::string> subsequent_ufrags =
3160*d9f75844SAndroid Build Coastguard Worker GetUfrags(pc_->local_description());
3161*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(2U, subsequent_ufrags.size());
3162*d9f75844SAndroid Build Coastguard Worker
3163*d9f75844SAndroid Build Coastguard Worker // Ensure that only the ufrag for the second m= section changed.
3164*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(initial_ufrags[0], subsequent_ufrags[0]);
3165*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(initial_ufrags[1], subsequent_ufrags[1]);
3166*d9f75844SAndroid Build Coastguard Worker }
3167*d9f75844SAndroid Build Coastguard Worker
3168*d9f75844SAndroid Build Coastguard Worker // Tests that the methods to return current/pending descriptions work as
3169*d9f75844SAndroid Build Coastguard Worker // expected at different points in the offer/answer exchange. This test does
3170*d9f75844SAndroid Build Coastguard Worker // one offer/answer exchange as the offerer, then another as the answerer.
TEST_P(PeerConnectionInterfaceTest,CurrentAndPendingDescriptions)3171*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CurrentAndPendingDescriptions) {
3172*d9f75844SAndroid Build Coastguard Worker // This disables DTLS so we can apply an answer to ourselves.
3173*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3174*d9f75844SAndroid Build Coastguard Worker
3175*d9f75844SAndroid Build Coastguard Worker // Create initial local offer and get SDP (which will also be used as
3176*d9f75844SAndroid Build Coastguard Worker // answer/pranswer);
3177*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> local_offer;
3178*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
3179*d9f75844SAndroid Build Coastguard Worker std::string sdp;
3180*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(local_offer->ToString(&sdp));
3181*d9f75844SAndroid Build Coastguard Worker
3182*d9f75844SAndroid Build Coastguard Worker // Set local offer.
3183*d9f75844SAndroid Build Coastguard Worker SessionDescriptionInterface* local_offer_ptr = local_offer.get();
3184*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3185*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3186*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->pending_remote_description());
3187*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->current_local_description());
3188*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->current_remote_description());
3189*d9f75844SAndroid Build Coastguard Worker
3190*d9f75844SAndroid Build Coastguard Worker // Set remote pranswer.
3191*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> remote_pranswer(
3192*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
3193*d9f75844SAndroid Build Coastguard Worker SessionDescriptionInterface* remote_pranswer_ptr = remote_pranswer.get();
3194*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_pranswer)));
3195*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(local_offer_ptr, pc_->pending_local_description());
3196*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(remote_pranswer_ptr, pc_->pending_remote_description());
3197*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->current_local_description());
3198*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->current_remote_description());
3199*d9f75844SAndroid Build Coastguard Worker
3200*d9f75844SAndroid Build Coastguard Worker // Set remote answer.
3201*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> remote_answer(
3202*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
3203*d9f75844SAndroid Build Coastguard Worker SessionDescriptionInterface* remote_answer_ptr = remote_answer.get();
3204*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_answer)));
3205*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->pending_local_description());
3206*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->pending_remote_description());
3207*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3208*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
3209*d9f75844SAndroid Build Coastguard Worker
3210*d9f75844SAndroid Build Coastguard Worker // Set remote offer.
3211*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> remote_offer(
3212*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kOffer, sdp));
3213*d9f75844SAndroid Build Coastguard Worker SessionDescriptionInterface* remote_offer_ptr = remote_offer.get();
3214*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(remote_offer)));
3215*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3216*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->pending_local_description());
3217*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3218*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
3219*d9f75844SAndroid Build Coastguard Worker
3220*d9f75844SAndroid Build Coastguard Worker // Set local pranswer.
3221*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> local_pranswer(
3222*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kPrAnswer, sdp));
3223*d9f75844SAndroid Build Coastguard Worker SessionDescriptionInterface* local_pranswer_ptr = local_pranswer.get();
3224*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(local_pranswer)));
3225*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(remote_offer_ptr, pc_->pending_remote_description());
3226*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(local_pranswer_ptr, pc_->pending_local_description());
3227*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(local_offer_ptr, pc_->current_local_description());
3228*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(remote_answer_ptr, pc_->current_remote_description());
3229*d9f75844SAndroid Build Coastguard Worker
3230*d9f75844SAndroid Build Coastguard Worker // Set local answer.
3231*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> local_answer(
3232*d9f75844SAndroid Build Coastguard Worker webrtc::CreateSessionDescription(SdpType::kAnswer, sdp));
3233*d9f75844SAndroid Build Coastguard Worker SessionDescriptionInterface* local_answer_ptr = local_answer.get();
3234*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(local_answer)));
3235*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->pending_remote_description());
3236*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, pc_->pending_local_description());
3237*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(remote_offer_ptr, pc_->current_remote_description());
3238*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(local_answer_ptr, pc_->current_local_description());
3239*d9f75844SAndroid Build Coastguard Worker }
3240*d9f75844SAndroid Build Coastguard Worker
3241*d9f75844SAndroid Build Coastguard Worker // Tests that it won't crash when calling StartRtcEventLog or StopRtcEventLog
3242*d9f75844SAndroid Build Coastguard Worker // after the PeerConnection is closed.
3243*d9f75844SAndroid Build Coastguard Worker // This version tests the StartRtcEventLog version that receives an object
3244*d9f75844SAndroid Build Coastguard Worker // of type `RtcEventLogOutput`.
TEST_P(PeerConnectionInterfaceTest,StartAndStopLoggingToOutputAfterPeerConnectionClosed)3245*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
3246*d9f75844SAndroid Build Coastguard Worker StartAndStopLoggingToOutputAfterPeerConnectionClosed) {
3247*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3248*d9f75844SAndroid Build Coastguard Worker // The RtcEventLog will be reset when the PeerConnection is closed.
3249*d9f75844SAndroid Build Coastguard Worker pc_->Close();
3250*d9f75844SAndroid Build Coastguard Worker
3251*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(
3252*d9f75844SAndroid Build Coastguard Worker pc_->StartRtcEventLog(std::make_unique<webrtc::RtcEventLogOutputNull>(),
3253*d9f75844SAndroid Build Coastguard Worker webrtc::RtcEventLog::kImmediateOutput));
3254*d9f75844SAndroid Build Coastguard Worker pc_->StopRtcEventLog();
3255*d9f75844SAndroid Build Coastguard Worker }
3256*d9f75844SAndroid Build Coastguard Worker
3257*d9f75844SAndroid Build Coastguard Worker // Test that generated offers/answers include "ice-option:trickle".
TEST_P(PeerConnectionInterfaceTest,OffersAndAnswersHaveTrickleIceOption)3258*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, OffersAndAnswersHaveTrickleIceOption) {
3259*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3260*d9f75844SAndroid Build Coastguard Worker
3261*d9f75844SAndroid Build Coastguard Worker // First, create an offer with audio/video.
3262*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions options;
3263*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_audio = 1;
3264*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_video = 1;
3265*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3266*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, &options));
3267*d9f75844SAndroid Build Coastguard Worker cricket::SessionDescription* desc = offer->description();
3268*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(2u, desc->transport_infos().size());
3269*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3270*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3271*d9f75844SAndroid Build Coastguard Worker
3272*d9f75844SAndroid Build Coastguard Worker // Apply the offer as a remote description, then create an answer.
3273*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->can_trickle_ice_candidates());
3274*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3275*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(pc_->can_trickle_ice_candidates());
3276*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(*(pc_->can_trickle_ice_candidates()));
3277*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
3278*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateAnswer(&answer, &options));
3279*d9f75844SAndroid Build Coastguard Worker desc = answer->description();
3280*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(2u, desc->transport_infos().size());
3281*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(desc->transport_infos()[0].description.HasOption("trickle"));
3282*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(desc->transport_infos()[1].description.HasOption("trickle"));
3283*d9f75844SAndroid Build Coastguard Worker }
3284*d9f75844SAndroid Build Coastguard Worker
3285*d9f75844SAndroid Build Coastguard Worker // Test that ICE renomination isn't offered if it's not enabled in the PC's
3286*d9f75844SAndroid Build Coastguard Worker // RTCConfiguration.
TEST_P(PeerConnectionInterfaceTest,IceRenominationNotOffered)3287*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, IceRenominationNotOffered) {
3288*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3289*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
3290*d9f75844SAndroid Build Coastguard Worker config.enable_ice_renomination = false;
3291*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3292*d9f75844SAndroid Build Coastguard Worker AddAudioTrack("foo");
3293*d9f75844SAndroid Build Coastguard Worker
3294*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3295*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3296*d9f75844SAndroid Build Coastguard Worker cricket::SessionDescription* desc = offer->description();
3297*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, desc->transport_infos().size());
3298*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(
3299*d9f75844SAndroid Build Coastguard Worker desc->transport_infos()[0].description.GetIceParameters().renomination);
3300*d9f75844SAndroid Build Coastguard Worker }
3301*d9f75844SAndroid Build Coastguard Worker
3302*d9f75844SAndroid Build Coastguard Worker // Test that the ICE renomination option is present in generated offers/answers
3303*d9f75844SAndroid Build Coastguard Worker // if it's enabled in the PC's RTCConfiguration.
TEST_P(PeerConnectionInterfaceTest,IceRenominationOptionInOfferAndAnswer)3304*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, IceRenominationOptionInOfferAndAnswer) {
3305*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3306*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
3307*d9f75844SAndroid Build Coastguard Worker config.enable_ice_renomination = true;
3308*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3309*d9f75844SAndroid Build Coastguard Worker AddAudioTrack("foo");
3310*d9f75844SAndroid Build Coastguard Worker
3311*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3312*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3313*d9f75844SAndroid Build Coastguard Worker cricket::SessionDescription* desc = offer->description();
3314*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, desc->transport_infos().size());
3315*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(
3316*d9f75844SAndroid Build Coastguard Worker desc->transport_infos()[0].description.GetIceParameters().renomination);
3317*d9f75844SAndroid Build Coastguard Worker
3318*d9f75844SAndroid Build Coastguard Worker // Set the offer as a remote description, then create an answer and ensure it
3319*d9f75844SAndroid Build Coastguard Worker // has the renomination flag too.
3320*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3321*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
3322*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3323*d9f75844SAndroid Build Coastguard Worker desc = answer->description();
3324*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(1u, desc->transport_infos().size());
3325*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(
3326*d9f75844SAndroid Build Coastguard Worker desc->transport_infos()[0].description.GetIceParameters().renomination);
3327*d9f75844SAndroid Build Coastguard Worker }
3328*d9f75844SAndroid Build Coastguard Worker
3329*d9f75844SAndroid Build Coastguard Worker // Test that if CreateOffer is called with the deprecated "offer to receive
3330*d9f75844SAndroid Build Coastguard Worker // audio/video" constraints, they're processed and result in an offer with
3331*d9f75844SAndroid Build Coastguard Worker // audio/video sections just as if RTCOfferAnswerOptions had been used.
TEST_P(PeerConnectionInterfaceTest,CreateOfferWithOfferToReceiveConstraints)3332*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateOfferWithOfferToReceiveConstraints) {
3333*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3334*d9f75844SAndroid Build Coastguard Worker
3335*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions options;
3336*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_audio = 1;
3337*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_video = 1;
3338*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3339*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, &options));
3340*d9f75844SAndroid Build Coastguard Worker
3341*d9f75844SAndroid Build Coastguard Worker cricket::SessionDescription* desc = offer->description();
3342*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3343*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3344*d9f75844SAndroid Build Coastguard Worker ASSERT_NE(nullptr, audio);
3345*d9f75844SAndroid Build Coastguard Worker ASSERT_NE(nullptr, video);
3346*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(audio->rejected);
3347*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(video->rejected);
3348*d9f75844SAndroid Build Coastguard Worker }
3349*d9f75844SAndroid Build Coastguard Worker
3350*d9f75844SAndroid Build Coastguard Worker // Test that if CreateAnswer is called with the deprecated "offer to receive
3351*d9f75844SAndroid Build Coastguard Worker // audio/video" constraints, they're processed and can be used to reject an
3352*d9f75844SAndroid Build Coastguard Worker // offered m= section just as can be done with RTCOfferAnswerOptions;
3353*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since this behavior is not supported.
TEST_F(PeerConnectionInterfaceTestPlanB,CreateAnswerWithOfferToReceiveConstraints)3354*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
3355*d9f75844SAndroid Build Coastguard Worker CreateAnswerWithOfferToReceiveConstraints) {
3356*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3357*d9f75844SAndroid Build Coastguard Worker
3358*d9f75844SAndroid Build Coastguard Worker // First, create an offer with audio/video and apply it as a remote
3359*d9f75844SAndroid Build Coastguard Worker // description.
3360*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions options;
3361*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_audio = 1;
3362*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_video = 1;
3363*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3364*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, &options));
3365*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3366*d9f75844SAndroid Build Coastguard Worker
3367*d9f75844SAndroid Build Coastguard Worker // Now create answer that rejects audio/video.
3368*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_audio = 0;
3369*d9f75844SAndroid Build Coastguard Worker options.offer_to_receive_video = 0;
3370*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
3371*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateAnswer(&answer, &options));
3372*d9f75844SAndroid Build Coastguard Worker
3373*d9f75844SAndroid Build Coastguard Worker cricket::SessionDescription* desc = answer->description();
3374*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* audio = cricket::GetFirstAudioContent(desc);
3375*d9f75844SAndroid Build Coastguard Worker const cricket::ContentInfo* video = cricket::GetFirstVideoContent(desc);
3376*d9f75844SAndroid Build Coastguard Worker ASSERT_NE(nullptr, audio);
3377*d9f75844SAndroid Build Coastguard Worker ASSERT_NE(nullptr, video);
3378*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(audio->rejected);
3379*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(video->rejected);
3380*d9f75844SAndroid Build Coastguard Worker }
3381*d9f75844SAndroid Build Coastguard Worker
3382*d9f75844SAndroid Build Coastguard Worker // Test that negotiation can succeed with a data channel only, and with the max
3383*d9f75844SAndroid Build Coastguard Worker // bundle policy. Previously there was a bug that prevented this.
3384*d9f75844SAndroid Build Coastguard Worker #ifdef WEBRTC_HAVE_SCTP
TEST_P(PeerConnectionInterfaceTest,DataChannelOnlyOfferWithMaxBundlePolicy)3385*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, DataChannelOnlyOfferWithMaxBundlePolicy) {
3386*d9f75844SAndroid Build Coastguard Worker #else
3387*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
3388*d9f75844SAndroid Build Coastguard Worker DISABLED_DataChannelOnlyOfferWithMaxBundlePolicy) {
3389*d9f75844SAndroid Build Coastguard Worker #endif // WEBRTC_HAVE_SCTP
3390*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3391*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = sdp_semantics_;
3392*d9f75844SAndroid Build Coastguard Worker config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3393*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3394*d9f75844SAndroid Build Coastguard Worker
3395*d9f75844SAndroid Build Coastguard Worker // First, create an offer with only a data channel and apply it as a remote
3396*d9f75844SAndroid Build Coastguard Worker // description.
3397*d9f75844SAndroid Build Coastguard Worker pc_->CreateDataChannelOrError("test", nullptr);
3398*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3399*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3400*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3401*d9f75844SAndroid Build Coastguard Worker
3402*d9f75844SAndroid Build Coastguard Worker // Create and set answer as well.
3403*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
3404*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3405*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3406*d9f75844SAndroid Build Coastguard Worker }
3407*d9f75844SAndroid Build Coastguard Worker
3408*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetBitrateWithoutMinSucceeds) {
3409*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3410*d9f75844SAndroid Build Coastguard Worker BitrateSettings bitrate;
3411*d9f75844SAndroid Build Coastguard Worker bitrate.start_bitrate_bps = 100000;
3412*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3413*d9f75844SAndroid Build Coastguard Worker }
3414*d9f75844SAndroid Build Coastguard Worker
3415*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetBitrateNegativeMinFails) {
3416*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3417*d9f75844SAndroid Build Coastguard Worker BitrateSettings bitrate;
3418*d9f75844SAndroid Build Coastguard Worker bitrate.min_bitrate_bps = -1;
3419*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3420*d9f75844SAndroid Build Coastguard Worker }
3421*d9f75844SAndroid Build Coastguard Worker
3422*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanMinFails) {
3423*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3424*d9f75844SAndroid Build Coastguard Worker BitrateSettings bitrate;
3425*d9f75844SAndroid Build Coastguard Worker bitrate.min_bitrate_bps = 5;
3426*d9f75844SAndroid Build Coastguard Worker bitrate.start_bitrate_bps = 3;
3427*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3428*d9f75844SAndroid Build Coastguard Worker }
3429*d9f75844SAndroid Build Coastguard Worker
3430*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentNegativeFails) {
3431*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3432*d9f75844SAndroid Build Coastguard Worker BitrateSettings bitrate;
3433*d9f75844SAndroid Build Coastguard Worker bitrate.start_bitrate_bps = -1;
3434*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3435*d9f75844SAndroid Build Coastguard Worker }
3436*d9f75844SAndroid Build Coastguard Worker
3437*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanCurrentFails) {
3438*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3439*d9f75844SAndroid Build Coastguard Worker BitrateSettings bitrate;
3440*d9f75844SAndroid Build Coastguard Worker bitrate.start_bitrate_bps = 10;
3441*d9f75844SAndroid Build Coastguard Worker bitrate.max_bitrate_bps = 8;
3442*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3443*d9f75844SAndroid Build Coastguard Worker }
3444*d9f75844SAndroid Build Coastguard Worker
3445*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxLessThanMinFails) {
3446*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3447*d9f75844SAndroid Build Coastguard Worker BitrateSettings bitrate;
3448*d9f75844SAndroid Build Coastguard Worker bitrate.min_bitrate_bps = 10;
3449*d9f75844SAndroid Build Coastguard Worker bitrate.max_bitrate_bps = 8;
3450*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3451*d9f75844SAndroid Build Coastguard Worker }
3452*d9f75844SAndroid Build Coastguard Worker
3453*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetBitrateMaxNegativeFails) {
3454*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3455*d9f75844SAndroid Build Coastguard Worker BitrateSettings bitrate;
3456*d9f75844SAndroid Build Coastguard Worker bitrate.max_bitrate_bps = -1;
3457*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(pc_->SetBitrate(bitrate).ok());
3458*d9f75844SAndroid Build Coastguard Worker }
3459*d9f75844SAndroid Build Coastguard Worker
3460*d9f75844SAndroid Build Coastguard Worker // The current bitrate from BitrateSettings is currently clamped
3461*d9f75844SAndroid Build Coastguard Worker // by Call's BitrateConstraints, which comes from the SDP or a default value.
3462*d9f75844SAndroid Build Coastguard Worker // This test checks that a call to SetBitrate with a current bitrate that will
3463*d9f75844SAndroid Build Coastguard Worker // be clamped succeeds.
3464*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, SetBitrateCurrentLessThanImplicitMin) {
3465*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3466*d9f75844SAndroid Build Coastguard Worker BitrateSettings bitrate;
3467*d9f75844SAndroid Build Coastguard Worker bitrate.start_bitrate_bps = 1;
3468*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(pc_->SetBitrate(bitrate).ok());
3469*d9f75844SAndroid Build Coastguard Worker }
3470*d9f75844SAndroid Build Coastguard Worker
3471*d9f75844SAndroid Build Coastguard Worker // The following tests verify that the offer can be created correctly.
3472*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
3473*d9f75844SAndroid Build Coastguard Worker CreateOfferFailsWithInvalidOfferToReceiveAudio) {
3474*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions rtc_options;
3475*d9f75844SAndroid Build Coastguard Worker
3476*d9f75844SAndroid Build Coastguard Worker // Setting offer_to_receive_audio to a value lower than kUndefined or greater
3477*d9f75844SAndroid Build Coastguard Worker // than kMaxOfferToReceiveMedia should be treated as invalid.
3478*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_audio = RTCOfferAnswerOptions::kUndefined - 1;
3479*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3480*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3481*d9f75844SAndroid Build Coastguard Worker
3482*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_audio =
3483*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3484*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3485*d9f75844SAndroid Build Coastguard Worker }
3486*d9f75844SAndroid Build Coastguard Worker
3487*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
3488*d9f75844SAndroid Build Coastguard Worker CreateOfferFailsWithInvalidOfferToReceiveVideo) {
3489*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions rtc_options;
3490*d9f75844SAndroid Build Coastguard Worker
3491*d9f75844SAndroid Build Coastguard Worker // Setting offer_to_receive_video to a value lower than kUndefined or greater
3492*d9f75844SAndroid Build Coastguard Worker // than kMaxOfferToReceiveMedia should be treated as invalid.
3493*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_video = RTCOfferAnswerOptions::kUndefined - 1;
3494*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3495*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3496*d9f75844SAndroid Build Coastguard Worker
3497*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_video =
3498*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions::kMaxOfferToReceiveMedia + 1;
3499*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(CreateOfferWithOptions(rtc_options));
3500*d9f75844SAndroid Build Coastguard Worker }
3501*d9f75844SAndroid Build Coastguard Worker
3502*d9f75844SAndroid Build Coastguard Worker // Test that the audio and video content will be added to an offer if both
3503*d9f75844SAndroid Build Coastguard Worker // `offer_to_receive_audio` and `offer_to_receive_video` options are 1.
3504*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioVideoOptions) {
3505*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions rtc_options;
3506*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_audio = 1;
3507*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_video = 1;
3508*d9f75844SAndroid Build Coastguard Worker
3509*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3510*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3511*d9f75844SAndroid Build Coastguard Worker offer = CreateOfferWithOptions(rtc_options);
3512*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(offer);
3513*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3514*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3515*d9f75844SAndroid Build Coastguard Worker }
3516*d9f75844SAndroid Build Coastguard Worker
3517*d9f75844SAndroid Build Coastguard Worker // Test that only audio content will be added to the offer if only
3518*d9f75844SAndroid Build Coastguard Worker // `offer_to_receive_audio` options is 1.
3519*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateOfferWithAudioOnlyOptions) {
3520*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions rtc_options;
3521*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_audio = 1;
3522*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_video = 0;
3523*d9f75844SAndroid Build Coastguard Worker
3524*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3525*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3526*d9f75844SAndroid Build Coastguard Worker offer = CreateOfferWithOptions(rtc_options);
3527*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(offer);
3528*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3529*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3530*d9f75844SAndroid Build Coastguard Worker }
3531*d9f75844SAndroid Build Coastguard Worker
3532*d9f75844SAndroid Build Coastguard Worker // Test that only video content will be added if only `offer_to_receive_video`
3533*d9f75844SAndroid Build Coastguard Worker // options is 1.
3534*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateOfferWithVideoOnlyOptions) {
3535*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions rtc_options;
3536*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_audio = 0;
3537*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_video = 1;
3538*d9f75844SAndroid Build Coastguard Worker
3539*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3540*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3541*d9f75844SAndroid Build Coastguard Worker offer = CreateOfferWithOptions(rtc_options);
3542*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(offer);
3543*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3544*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3545*d9f75844SAndroid Build Coastguard Worker }
3546*d9f75844SAndroid Build Coastguard Worker
3547*d9f75844SAndroid Build Coastguard Worker // Test that no media content will be added to the offer if using default
3548*d9f75844SAndroid Build Coastguard Worker // RTCOfferAnswerOptions.
3549*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateOfferWithDefaultOfferAnswerOptions) {
3550*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions rtc_options;
3551*d9f75844SAndroid Build Coastguard Worker
3552*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3553*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3554*d9f75844SAndroid Build Coastguard Worker offer = CreateOfferWithOptions(rtc_options);
3555*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(offer);
3556*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, GetFirstAudioContent(offer->description()));
3557*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(nullptr, GetFirstVideoContent(offer->description()));
3558*d9f75844SAndroid Build Coastguard Worker }
3559*d9f75844SAndroid Build Coastguard Worker
3560*d9f75844SAndroid Build Coastguard Worker // Test that if `ice_restart` is true, the ufrag/pwd will change, otherwise
3561*d9f75844SAndroid Build Coastguard Worker // ufrag/pwd will be the same in the new offer.
3562*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateOfferWithIceRestart) {
3563*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3564*d9f75844SAndroid Build Coastguard Worker
3565*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions rtc_options;
3566*d9f75844SAndroid Build Coastguard Worker rtc_options.ice_restart = false;
3567*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_audio = 1;
3568*d9f75844SAndroid Build Coastguard Worker
3569*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3570*d9f75844SAndroid Build Coastguard Worker CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
3571*d9f75844SAndroid Build Coastguard Worker std::string mid = cricket::GetFirstAudioContent(offer->description())->name;
3572*d9f75844SAndroid Build Coastguard Worker auto ufrag1 =
3573*d9f75844SAndroid Build Coastguard Worker offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3574*d9f75844SAndroid Build Coastguard Worker auto pwd1 =
3575*d9f75844SAndroid Build Coastguard Worker offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
3576*d9f75844SAndroid Build Coastguard Worker
3577*d9f75844SAndroid Build Coastguard Worker // `ice_restart` is false, the ufrag/pwd shouldn't change.
3578*d9f75844SAndroid Build Coastguard Worker CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
3579*d9f75844SAndroid Build Coastguard Worker auto ufrag2 =
3580*d9f75844SAndroid Build Coastguard Worker offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3581*d9f75844SAndroid Build Coastguard Worker auto pwd2 =
3582*d9f75844SAndroid Build Coastguard Worker offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
3583*d9f75844SAndroid Build Coastguard Worker
3584*d9f75844SAndroid Build Coastguard Worker // `ice_restart` is true, the ufrag/pwd should change.
3585*d9f75844SAndroid Build Coastguard Worker rtc_options.ice_restart = true;
3586*d9f75844SAndroid Build Coastguard Worker CreateOfferWithOptionsAsLocalDescription(&offer, rtc_options);
3587*d9f75844SAndroid Build Coastguard Worker auto ufrag3 =
3588*d9f75844SAndroid Build Coastguard Worker offer->description()->GetTransportInfoByName(mid)->description.ice_ufrag;
3589*d9f75844SAndroid Build Coastguard Worker auto pwd3 =
3590*d9f75844SAndroid Build Coastguard Worker offer->description()->GetTransportInfoByName(mid)->description.ice_pwd;
3591*d9f75844SAndroid Build Coastguard Worker
3592*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(ufrag1, ufrag2);
3593*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(pwd1, pwd2);
3594*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(ufrag2, ufrag3);
3595*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(pwd2, pwd3);
3596*d9f75844SAndroid Build Coastguard Worker }
3597*d9f75844SAndroid Build Coastguard Worker
3598*d9f75844SAndroid Build Coastguard Worker // Test that if `use_rtp_mux` is true, the bundling will be enabled in the
3599*d9f75844SAndroid Build Coastguard Worker // offer; if it is false, there won't be any bundle group in the offer.
3600*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, CreateOfferWithRtpMux) {
3601*d9f75844SAndroid Build Coastguard Worker RTCOfferAnswerOptions rtc_options;
3602*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_audio = 1;
3603*d9f75844SAndroid Build Coastguard Worker rtc_options.offer_to_receive_video = 1;
3604*d9f75844SAndroid Build Coastguard Worker
3605*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3606*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3607*d9f75844SAndroid Build Coastguard Worker
3608*d9f75844SAndroid Build Coastguard Worker rtc_options.use_rtp_mux = true;
3609*d9f75844SAndroid Build Coastguard Worker offer = CreateOfferWithOptions(rtc_options);
3610*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(offer);
3611*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3612*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3613*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3614*d9f75844SAndroid Build Coastguard Worker
3615*d9f75844SAndroid Build Coastguard Worker rtc_options.use_rtp_mux = false;
3616*d9f75844SAndroid Build Coastguard Worker offer = CreateOfferWithOptions(rtc_options);
3617*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(offer);
3618*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(nullptr, GetFirstAudioContent(offer->description()));
3619*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(nullptr, GetFirstVideoContent(offer->description()));
3620*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(offer->description()->HasGroup(cricket::GROUP_TYPE_BUNDLE));
3621*d9f75844SAndroid Build Coastguard Worker }
3622*d9f75844SAndroid Build Coastguard Worker
3623*d9f75844SAndroid Build Coastguard Worker // This test ensures OnRenegotiationNeeded is called when we add track with
3624*d9f75844SAndroid Build Coastguard Worker // MediaStream -> AddTrack in the same way it is called when we add track with
3625*d9f75844SAndroid Build Coastguard Worker // PeerConnection -> AddTrack.
3626*d9f75844SAndroid Build Coastguard Worker // The test can be removed once addStream is rewritten in terms of addTrack
3627*d9f75844SAndroid Build Coastguard Worker // https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
3628*d9f75844SAndroid Build Coastguard Worker // Don't run under Unified Plan since the stream API is not available.
3629*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionInterfaceTestPlanB,
3630*d9f75844SAndroid Build Coastguard Worker MediaStreamAddTrackRemoveTrackRenegotiate) {
3631*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionWithoutDtls();
3632*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamInterface> stream(
3633*d9f75844SAndroid Build Coastguard Worker pc_factory_->CreateLocalMediaStream(kStreamId1));
3634*d9f75844SAndroid Build Coastguard Worker pc_->AddStream(stream.get());
3635*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> audio_track(
3636*d9f75844SAndroid Build Coastguard Worker CreateAudioTrack("audio_track"));
3637*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> video_track(
3638*d9f75844SAndroid Build Coastguard Worker CreateVideoTrack("video_track"));
3639*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(audio_track);
3640*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3641*d9f75844SAndroid Build Coastguard Worker observer_.renegotiation_needed_ = false;
3642*d9f75844SAndroid Build Coastguard Worker
3643*d9f75844SAndroid Build Coastguard Worker CreateOfferReceiveAnswer();
3644*d9f75844SAndroid Build Coastguard Worker stream->AddTrack(video_track);
3645*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3646*d9f75844SAndroid Build Coastguard Worker observer_.renegotiation_needed_ = false;
3647*d9f75844SAndroid Build Coastguard Worker
3648*d9f75844SAndroid Build Coastguard Worker CreateOfferReceiveAnswer();
3649*d9f75844SAndroid Build Coastguard Worker stream->RemoveTrack(audio_track);
3650*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3651*d9f75844SAndroid Build Coastguard Worker observer_.renegotiation_needed_ = false;
3652*d9f75844SAndroid Build Coastguard Worker
3653*d9f75844SAndroid Build Coastguard Worker CreateOfferReceiveAnswer();
3654*d9f75844SAndroid Build Coastguard Worker stream->RemoveTrack(video_track);
3655*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3656*d9f75844SAndroid Build Coastguard Worker observer_.renegotiation_needed_ = false;
3657*d9f75844SAndroid Build Coastguard Worker }
3658*d9f75844SAndroid Build Coastguard Worker
3659*d9f75844SAndroid Build Coastguard Worker // Tests that an error is returned if a description is applied that has fewer
3660*d9f75844SAndroid Build Coastguard Worker // media sections than the existing description.
3661*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
3662*d9f75844SAndroid Build Coastguard Worker MediaSectionCountEnforcedForSubsequentOffer) {
3663*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3664*d9f75844SAndroid Build Coastguard Worker AddAudioTrack("audio_label");
3665*d9f75844SAndroid Build Coastguard Worker AddVideoTrack("video_label");
3666*d9f75844SAndroid Build Coastguard Worker
3667*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3668*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3669*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetRemoteDescription(std::move(offer)));
3670*d9f75844SAndroid Build Coastguard Worker
3671*d9f75844SAndroid Build Coastguard Worker // A remote offer with fewer media sections should be rejected.
3672*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3673*d9f75844SAndroid Build Coastguard Worker offer->description()->contents().pop_back();
3674*d9f75844SAndroid Build Coastguard Worker offer->description()->contents().pop_back();
3675*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(offer->description()->contents().empty());
3676*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoSetRemoteDescription(std::move(offer)));
3677*d9f75844SAndroid Build Coastguard Worker
3678*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> answer;
3679*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateAnswer(&answer, nullptr));
3680*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(DoSetLocalDescription(std::move(answer)));
3681*d9f75844SAndroid Build Coastguard Worker
3682*d9f75844SAndroid Build Coastguard Worker // A subsequent local offer with fewer media sections should be rejected.
3683*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3684*d9f75844SAndroid Build Coastguard Worker offer->description()->contents().pop_back();
3685*d9f75844SAndroid Build Coastguard Worker offer->description()->contents().pop_back();
3686*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(offer->description()->contents().empty());
3687*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(DoSetLocalDescription(std::move(offer)));
3688*d9f75844SAndroid Build Coastguard Worker }
3689*d9f75844SAndroid Build Coastguard Worker
3690*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest, ExtmapAllowMixedIsConfigurable) {
3691*d9f75844SAndroid Build Coastguard Worker RTCConfiguration config;
3692*d9f75844SAndroid Build Coastguard Worker // Default behavior is true.
3693*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3694*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> offer;
3695*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3696*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(offer->description()->extmap_allow_mixed());
3697*d9f75844SAndroid Build Coastguard Worker // Possible to set to false.
3698*d9f75844SAndroid Build Coastguard Worker config.offer_extmap_allow_mixed = false;
3699*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection(config);
3700*d9f75844SAndroid Build Coastguard Worker offer = nullptr;
3701*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&offer, nullptr));
3702*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(offer->description()->extmap_allow_mixed());
3703*d9f75844SAndroid Build Coastguard Worker }
3704*d9f75844SAndroid Build Coastguard Worker
3705*d9f75844SAndroid Build Coastguard Worker TEST_P(PeerConnectionInterfaceTest,
3706*d9f75844SAndroid Build Coastguard Worker RtpSenderSetDegradationPreferenceWithoutEncodings) {
3707*d9f75844SAndroid Build Coastguard Worker CreatePeerConnection();
3708*d9f75844SAndroid Build Coastguard Worker AddVideoTrack("video_label");
3709*d9f75844SAndroid Build Coastguard Worker
3710*d9f75844SAndroid Build Coastguard Worker std::vector<rtc::scoped_refptr<RtpSenderInterface>> rtp_senders =
3711*d9f75844SAndroid Build Coastguard Worker pc_->GetSenders();
3712*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(rtp_senders.size(), 1u);
3713*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(rtp_senders[0]->media_type(), cricket::MEDIA_TYPE_VIDEO);
3714*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<RtpSenderInterface> video_rtp_sender = rtp_senders[0];
3715*d9f75844SAndroid Build Coastguard Worker RtpParameters parameters = video_rtp_sender->GetParameters();
3716*d9f75844SAndroid Build Coastguard Worker ASSERT_NE(parameters.degradation_preference,
3717*d9f75844SAndroid Build Coastguard Worker DegradationPreference::MAINTAIN_RESOLUTION);
3718*d9f75844SAndroid Build Coastguard Worker parameters.degradation_preference =
3719*d9f75844SAndroid Build Coastguard Worker DegradationPreference::MAINTAIN_RESOLUTION;
3720*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(video_rtp_sender->SetParameters(parameters).ok());
3721*d9f75844SAndroid Build Coastguard Worker
3722*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<SessionDescriptionInterface> local_offer;
3723*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoCreateOffer(&local_offer, nullptr));
3724*d9f75844SAndroid Build Coastguard Worker ASSERT_TRUE(DoSetLocalDescription(std::move(local_offer)));
3725*d9f75844SAndroid Build Coastguard Worker
3726*d9f75844SAndroid Build Coastguard Worker RtpParameters parameters_new = video_rtp_sender->GetParameters();
3727*d9f75844SAndroid Build Coastguard Worker ASSERT_EQ(parameters_new.degradation_preference,
3728*d9f75844SAndroid Build Coastguard Worker DegradationPreference::MAINTAIN_RESOLUTION);
3729*d9f75844SAndroid Build Coastguard Worker }
3730*d9f75844SAndroid Build Coastguard Worker
3731*d9f75844SAndroid Build Coastguard Worker INSTANTIATE_TEST_SUITE_P(PeerConnectionInterfaceTest,
3732*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterfaceTest,
3733*d9f75844SAndroid Build Coastguard Worker Values(SdpSemantics::kPlanB_DEPRECATED,
3734*d9f75844SAndroid Build Coastguard Worker SdpSemantics::kUnifiedPlan));
3735*d9f75844SAndroid Build Coastguard Worker
3736*d9f75844SAndroid Build Coastguard Worker class PeerConnectionMediaConfigTest : public ::testing::Test {
3737*d9f75844SAndroid Build Coastguard Worker protected:
3738*d9f75844SAndroid Build Coastguard Worker void SetUp() override {
3739*d9f75844SAndroid Build Coastguard Worker pcf_ = PeerConnectionFactoryForTest::CreatePeerConnectionFactoryForTest();
3740*d9f75844SAndroid Build Coastguard Worker }
3741*d9f75844SAndroid Build Coastguard Worker const cricket::MediaConfig TestCreatePeerConnection(
3742*d9f75844SAndroid Build Coastguard Worker const RTCConfiguration& config) {
3743*d9f75844SAndroid Build Coastguard Worker PeerConnectionDependencies pc_dependencies(&observer_);
3744*d9f75844SAndroid Build Coastguard Worker auto result =
3745*d9f75844SAndroid Build Coastguard Worker pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3746*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(result.ok());
3747*d9f75844SAndroid Build Coastguard Worker observer_.SetPeerConnectionInterface(result.value().get());
3748*d9f75844SAndroid Build Coastguard Worker return result.value()->GetConfiguration().media_config;
3749*d9f75844SAndroid Build Coastguard Worker }
3750*d9f75844SAndroid Build Coastguard Worker
3751*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<PeerConnectionFactoryForTest> pcf_;
3752*d9f75844SAndroid Build Coastguard Worker MockPeerConnectionObserver observer_;
3753*d9f75844SAndroid Build Coastguard Worker };
3754*d9f75844SAndroid Build Coastguard Worker
3755*d9f75844SAndroid Build Coastguard Worker // This sanity check validates the test infrastructure itself.
3756*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionMediaConfigTest, TestCreateAndClose) {
3757*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3758*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = SdpSemantics::kUnifiedPlan;
3759*d9f75844SAndroid Build Coastguard Worker PeerConnectionDependencies pc_dependencies(&observer_);
3760*d9f75844SAndroid Build Coastguard Worker auto result =
3761*d9f75844SAndroid Build Coastguard Worker pcf_->CreatePeerConnectionOrError(config, std::move(pc_dependencies));
3762*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(result.ok());
3763*d9f75844SAndroid Build Coastguard Worker observer_.SetPeerConnectionInterface(result.value().get());
3764*d9f75844SAndroid Build Coastguard Worker result.value()->Close(); // No abort -> ok.
3765*d9f75844SAndroid Build Coastguard Worker SUCCEED();
3766*d9f75844SAndroid Build Coastguard Worker }
3767*d9f75844SAndroid Build Coastguard Worker
3768*d9f75844SAndroid Build Coastguard Worker // This test verifies the default behaviour with no constraints and a
3769*d9f75844SAndroid Build Coastguard Worker // default RTCConfiguration.
3770*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionMediaConfigTest, TestDefaults) {
3771*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3772*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = SdpSemantics::kUnifiedPlan;
3773*d9f75844SAndroid Build Coastguard Worker
3774*d9f75844SAndroid Build Coastguard Worker const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
3775*d9f75844SAndroid Build Coastguard Worker
3776*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(media_config.enable_dscp);
3777*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(media_config.video.enable_cpu_adaptation);
3778*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(media_config.video.enable_prerenderer_smoothing);
3779*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(media_config.video.suspend_below_min_bitrate);
3780*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(media_config.video.experiment_cpu_load_estimator);
3781*d9f75844SAndroid Build Coastguard Worker }
3782*d9f75844SAndroid Build Coastguard Worker
3783*d9f75844SAndroid Build Coastguard Worker // This test verifies that the enable_prerenderer_smoothing flag is
3784*d9f75844SAndroid Build Coastguard Worker // propagated from RTCConfiguration to the PeerConnection.
3785*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionMediaConfigTest, TestDisablePrerendererSmoothingTrue) {
3786*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3787*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = SdpSemantics::kUnifiedPlan;
3788*d9f75844SAndroid Build Coastguard Worker
3789*d9f75844SAndroid Build Coastguard Worker config.set_prerenderer_smoothing(false);
3790*d9f75844SAndroid Build Coastguard Worker const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
3791*d9f75844SAndroid Build Coastguard Worker
3792*d9f75844SAndroid Build Coastguard Worker EXPECT_FALSE(media_config.video.enable_prerenderer_smoothing);
3793*d9f75844SAndroid Build Coastguard Worker }
3794*d9f75844SAndroid Build Coastguard Worker
3795*d9f75844SAndroid Build Coastguard Worker // This test verifies that the experiment_cpu_load_estimator flag is
3796*d9f75844SAndroid Build Coastguard Worker // propagated from RTCConfiguration to the PeerConnection.
3797*d9f75844SAndroid Build Coastguard Worker TEST_F(PeerConnectionMediaConfigTest, TestEnableExperimentCpuLoadEstimator) {
3798*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration config;
3799*d9f75844SAndroid Build Coastguard Worker config.sdp_semantics = SdpSemantics::kUnifiedPlan;
3800*d9f75844SAndroid Build Coastguard Worker
3801*d9f75844SAndroid Build Coastguard Worker config.set_experiment_cpu_load_estimator(true);
3802*d9f75844SAndroid Build Coastguard Worker const cricket::MediaConfig& media_config = TestCreatePeerConnection(config);
3803*d9f75844SAndroid Build Coastguard Worker
3804*d9f75844SAndroid Build Coastguard Worker EXPECT_TRUE(media_config.video.experiment_cpu_load_estimator);
3805*d9f75844SAndroid Build Coastguard Worker }
3806*d9f75844SAndroid Build Coastguard Worker
3807*d9f75844SAndroid Build Coastguard Worker // Tests a few random fields being different.
3808*d9f75844SAndroid Build Coastguard Worker TEST(RTCConfigurationTest, ComparisonOperators) {
3809*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration a;
3810*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration b;
3811*d9f75844SAndroid Build Coastguard Worker EXPECT_EQ(a, b);
3812*d9f75844SAndroid Build Coastguard Worker
3813*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration c;
3814*d9f75844SAndroid Build Coastguard Worker c.servers.push_back(PeerConnectionInterface::IceServer());
3815*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(a, c);
3816*d9f75844SAndroid Build Coastguard Worker
3817*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration d;
3818*d9f75844SAndroid Build Coastguard Worker d.type = PeerConnectionInterface::kRelay;
3819*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(a, d);
3820*d9f75844SAndroid Build Coastguard Worker
3821*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration e;
3822*d9f75844SAndroid Build Coastguard Worker e.audio_jitter_buffer_max_packets = 5;
3823*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(a, e);
3824*d9f75844SAndroid Build Coastguard Worker
3825*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration f;
3826*d9f75844SAndroid Build Coastguard Worker f.ice_connection_receiving_timeout = 1337;
3827*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(a, f);
3828*d9f75844SAndroid Build Coastguard Worker
3829*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfiguration h(
3830*d9f75844SAndroid Build Coastguard Worker PeerConnectionInterface::RTCConfigurationType::kAggressive);
3831*d9f75844SAndroid Build Coastguard Worker EXPECT_NE(a, h);
3832*d9f75844SAndroid Build Coastguard Worker }
3833*d9f75844SAndroid Build Coastguard Worker
3834*d9f75844SAndroid Build Coastguard Worker } // namespace
3835*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc
3836