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