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