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