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 | |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 11 | #include <memory> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 12 | #include <utility> |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 15 | #include "webrtc/api/fakemetricsobserver.h" |
| 16 | #include "webrtc/api/jsepicecandidate.h" |
| 17 | #include "webrtc/api/jsepsessiondescription.h" |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 18 | #include "webrtc/base/checks.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 19 | #include "webrtc/base/fakenetwork.h" |
| 20 | #include "webrtc/base/firewallsocketserver.h" |
| 21 | #include "webrtc/base/gunit.h" |
| 22 | #include "webrtc/base/logging.h" |
| 23 | #include "webrtc/base/network.h" |
| 24 | #include "webrtc/base/physicalsocketserver.h" |
| 25 | #include "webrtc/base/ssladapter.h" |
Henrik Boström | 5e56c59 | 2015-08-11 10:33:13 +0200 | [diff] [blame] | 26 | #include "webrtc/base/sslidentity.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 27 | #include "webrtc/base/sslstreamadapter.h" |
| 28 | #include "webrtc/base/stringutils.h" |
| 29 | #include "webrtc/base/thread.h" |
| 30 | #include "webrtc/base/virtualsocketserver.h" |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 31 | #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 32 | #include "webrtc/media/base/fakemediaengine.h" |
| 33 | #include "webrtc/media/base/fakevideorenderer.h" |
| 34 | #include "webrtc/media/base/mediachannel.h" |
kjellander@webrtc.org | 5ad1297 | 2016-02-12 06:39:40 +0100 | [diff] [blame] | 35 | #include "webrtc/media/engine/fakewebrtccall.h" |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 36 | #include "webrtc/media/sctp/sctptransportinternal.h" |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 37 | #include "webrtc/p2p/base/packettransportinterface.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 38 | #include "webrtc/p2p/base/stunserver.h" |
| 39 | #include "webrtc/p2p/base/teststunserver.h" |
| 40 | #include "webrtc/p2p/base/testturnserver.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 41 | #include "webrtc/p2p/client/basicportallocator.h" |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 42 | #include "webrtc/pc/audiotrack.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 43 | #include "webrtc/pc/channelmanager.h" |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 44 | #include "webrtc/pc/fakemediacontroller.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 45 | #include "webrtc/pc/mediasession.h" |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 46 | #include "webrtc/pc/peerconnection.h" |
| 47 | #include "webrtc/pc/sctputils.h" |
| 48 | #include "webrtc/pc/test/fakertccertificategenerator.h" |
| 49 | #include "webrtc/pc/videotrack.h" |
| 50 | #include "webrtc/pc/webrtcsession.h" |
| 51 | #include "webrtc/pc/webrtcsessiondescriptionfactory.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 52 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 53 | using cricket::FakeVoiceMediaChannel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | using cricket::TransportInfo; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 55 | using rtc::SocketAddress; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 56 | using rtc::Thread; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | using webrtc::CreateSessionDescription; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 58 | using webrtc::CreateSessionDescriptionObserver; |
| 59 | using webrtc::CreateSessionDescriptionRequest; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 60 | using webrtc::DataChannel; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 61 | using webrtc::FakeMetricsObserver; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | using webrtc::IceCandidateCollection; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 63 | using webrtc::InternalDataChannelInit; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 64 | using webrtc::JsepIceCandidate; |
| 65 | using webrtc::JsepSessionDescription; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 66 | using webrtc::PeerConnectionFactoryInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 67 | using webrtc::PeerConnectionInterface; |
| 68 | using webrtc::SessionDescriptionInterface; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 69 | using webrtc::SessionStats; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | using webrtc::StreamCollection; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 71 | using webrtc::WebRtcSession; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 72 | using webrtc::kBundleWithoutRtcpMux; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 73 | using webrtc::kCreateChannelFailed; |
| 74 | using webrtc::kInvalidSdp; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | using webrtc::kMlineMismatch; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 76 | using webrtc::kPushDownTDFailed; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 77 | using webrtc::kSdpWithoutIceUfragPwd; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 78 | using webrtc::kSdpWithoutDtlsFingerprint; |
| 79 | using webrtc::kSdpWithoutSdesCrypto; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | using webrtc::kSessionError; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 81 | using webrtc::kSessionErrorDesc; |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 82 | using webrtc::kMaxUnsignalledRecvStreams; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 84 | typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 85 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 86 | static const int kClientAddrPort = 0; |
| 87 | static const char kClientAddrHost1[] = "11.11.11.11"; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 88 | static const char kClientIPv6AddrHost1[] = |
| 89 | "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff"; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 90 | static const char kClientAddrHost2[] = "22.22.22.22"; |
| 91 | static const char kStunAddrHost[] = "99.99.99.1"; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 92 | static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478); |
| 93 | static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 94 | static const char kTurnUsername[] = "test"; |
| 95 | static const char kTurnPassword[] = "test"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | |
| 97 | static const char kSessionVersion[] = "1"; |
| 98 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | // Media index of candidates belonging to the first media content. |
| 100 | static const int kMediaContentIndex0 = 0; |
| 101 | static const char kMediaContentName0[] = "audio"; |
| 102 | |
| 103 | // Media index of candidates belonging to the second media content. |
| 104 | static const int kMediaContentIndex1 = 1; |
| 105 | static const char kMediaContentName1[] = "video"; |
| 106 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 107 | static const int kDefaultTimeout = 10000; // 10 seconds. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 108 | static const int kIceCandidatesTimeout = 10000; |
deadbeef | f5f03e8 | 2016-06-06 11:16:06 -0700 | [diff] [blame] | 109 | // STUN timeout with all retransmissions is a total of 9500ms. |
| 110 | static const int kStunTimeout = 9500; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 112 | static const char kFakeDtlsFingerprint[] = |
| 113 | "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:" |
| 114 | "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24"; |
| 115 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 116 | static const char kTooLongIceUfragPwd[] = |
| 117 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag" |
| 118 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag" |
| 119 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag" |
| 120 | "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"; |
| 121 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 122 | static const char kSdpWithRtx[] = |
| 123 | "v=0\r\n" |
| 124 | "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n" |
| 125 | "s=-\r\n" |
| 126 | "t=0 0\r\n" |
| 127 | "a=msid-semantic: WMS stream1\r\n" |
| 128 | "m=video 9 RTP/SAVPF 0 96\r\n" |
| 129 | "c=IN IP4 0.0.0.0\r\n" |
| 130 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 131 | "a=ice-ufrag:CerjGp19G7wpXwl7\r\n" |
| 132 | "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n" |
| 133 | "a=mid:video\r\n" |
| 134 | "a=sendrecv\r\n" |
| 135 | "a=rtcp-mux\r\n" |
| 136 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 137 | "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n" |
| 138 | "a=rtpmap:0 fake_video_codec/90000\r\n" |
| 139 | "a=rtpmap:96 rtx/90000\r\n" |
| 140 | "a=fmtp:96 apt=0\r\n"; |
| 141 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 142 | static const char kStream1[] = "stream1"; |
| 143 | static const char kVideoTrack1[] = "video1"; |
| 144 | static const char kAudioTrack1[] = "audio1"; |
| 145 | |
| 146 | static const char kStream2[] = "stream2"; |
| 147 | static const char kVideoTrack2[] = "video2"; |
| 148 | static const char kAudioTrack2[] = "audio2"; |
| 149 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 150 | enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE }; |
| 151 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 152 | class MockIceObserver : public webrtc::IceObserver { |
| 153 | public: |
| 154 | MockIceObserver() |
| 155 | : oncandidatesready_(false), |
| 156 | ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
| 157 | ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { |
| 158 | } |
| 159 | |
Henrik Kjellander | 3fe372d | 2016-05-12 08:10:52 +0200 | [diff] [blame] | 160 | virtual ~MockIceObserver() = default; |
| 161 | |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 162 | void OnIceConnectionChange( |
| 163 | PeerConnectionInterface::IceConnectionState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | ice_connection_state_ = new_state; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 165 | ice_connection_state_history_.push_back(new_state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 166 | } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 167 | void OnIceGatheringChange( |
| 168 | PeerConnectionInterface::IceGatheringState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 169 | // We can never transition back to "new". |
| 170 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state); |
| 171 | ice_gathering_state_ = new_state; |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 172 | oncandidatesready_ = |
| 173 | new_state == PeerConnectionInterface::kIceGatheringComplete; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | // Found a new candidate. |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 177 | void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 178 | switch (candidate->sdp_mline_index()) { |
| 179 | case kMediaContentIndex0: |
| 180 | mline_0_candidates_.push_back(candidate->candidate()); |
| 181 | break; |
| 182 | case kMediaContentIndex1: |
| 183 | mline_1_candidates_.push_back(candidate->candidate()); |
| 184 | break; |
| 185 | default: |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 186 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 187 | } |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 188 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 189 | // The ICE gathering state should always be Gathering when a candidate is |
| 190 | // received (or possibly Completed in the case of the final candidate). |
| 191 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_); |
| 192 | } |
| 193 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 194 | // Some local candidates are removed. |
| 195 | void OnIceCandidatesRemoved( |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 196 | const std::vector<cricket::Candidate>& candidates) override { |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 197 | num_candidates_removed_ += candidates.size(); |
| 198 | } |
| 199 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 200 | bool oncandidatesready_; |
| 201 | std::vector<cricket::Candidate> mline_0_candidates_; |
| 202 | std::vector<cricket::Candidate> mline_1_candidates_; |
| 203 | PeerConnectionInterface::IceConnectionState ice_connection_state_; |
| 204 | PeerConnectionInterface::IceGatheringState ice_gathering_state_; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 205 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 206 | ice_connection_state_history_; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 207 | size_t num_candidates_removed_ = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | }; |
| 209 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 210 | // Used for tests in this file to verify that WebRtcSession responds to signals |
| 211 | // from the SctpTransport correctly, and calls Start with the correct |
| 212 | // local/remote ports. |
| 213 | class FakeSctpTransport : public cricket::SctpTransportInternal { |
| 214 | public: |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 215 | void SetTransportChannel(rtc::PacketTransportInterface* channel) override {} |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 216 | bool Start(int local_port, int remote_port) override { |
| 217 | local_port_ = local_port; |
| 218 | remote_port_ = remote_port; |
| 219 | return true; |
| 220 | } |
| 221 | bool OpenStream(int sid) override { return true; } |
| 222 | bool ResetStream(int sid) override { return true; } |
| 223 | bool SendData(const cricket::SendDataParams& params, |
| 224 | const rtc::CopyOnWriteBuffer& payload, |
| 225 | cricket::SendDataResult* result = nullptr) override { |
| 226 | return true; |
| 227 | } |
| 228 | bool ReadyToSendData() override { return true; } |
| 229 | void set_debug_name_for_testing(const char* debug_name) override {} |
| 230 | |
| 231 | int local_port() const { return local_port_; } |
| 232 | int remote_port() const { return remote_port_; } |
| 233 | |
| 234 | private: |
| 235 | int local_port_ = -1; |
| 236 | int remote_port_ = -1; |
| 237 | }; |
| 238 | |
| 239 | class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory { |
| 240 | public: |
| 241 | std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport( |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 242 | rtc::PacketTransportInterface*) override { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 243 | last_fake_sctp_transport_ = new FakeSctpTransport(); |
| 244 | return std::unique_ptr<cricket::SctpTransportInternal>( |
| 245 | last_fake_sctp_transport_); |
| 246 | } |
| 247 | |
| 248 | FakeSctpTransport* last_fake_sctp_transport() { |
| 249 | return last_fake_sctp_transport_; |
| 250 | } |
| 251 | |
| 252 | private: |
| 253 | FakeSctpTransport* last_fake_sctp_transport_ = nullptr; |
| 254 | }; |
| 255 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 256 | class WebRtcSessionForTest : public webrtc::WebRtcSession { |
| 257 | public: |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 258 | WebRtcSessionForTest( |
| 259 | webrtc::MediaControllerInterface* media_controller, |
| 260 | rtc::Thread* network_thread, |
| 261 | rtc::Thread* worker_thread, |
| 262 | rtc::Thread* signaling_thread, |
| 263 | cricket::PortAllocator* port_allocator, |
| 264 | webrtc::IceObserver* ice_observer, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 265 | std::unique_ptr<cricket::TransportController> transport_controller, |
| 266 | std::unique_ptr<FakeSctpTransportFactory> sctp_factory) |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 267 | : WebRtcSession(media_controller, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 268 | network_thread, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 269 | worker_thread, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 270 | signaling_thread, |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 271 | port_allocator, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 272 | std::move(transport_controller), |
| 273 | std::move(sctp_factory)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | RegisterIceObserver(ice_observer); |
| 275 | } |
| 276 | virtual ~WebRtcSessionForTest() {} |
| 277 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 278 | // Note that these methods are only safe to use if the signaling thread |
| 279 | // is the same as the worker thread |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 280 | rtc::PacketTransportInterface* voice_rtp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 281 | return rtp_transport_channel(voice_channel()); |
| 282 | } |
| 283 | |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 284 | rtc::PacketTransportInterface* voice_rtcp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 285 | return rtcp_transport_channel(voice_channel()); |
| 286 | } |
| 287 | |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 288 | rtc::PacketTransportInterface* video_rtp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 289 | return rtp_transport_channel(video_channel()); |
| 290 | } |
| 291 | |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 292 | rtc::PacketTransportInterface* video_rtcp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 293 | return rtcp_transport_channel(video_channel()); |
| 294 | } |
| 295 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 296 | private: |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 297 | rtc::PacketTransportInterface* rtp_transport_channel( |
| 298 | cricket::BaseChannel* ch) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 299 | if (!ch) { |
| 300 | return nullptr; |
| 301 | } |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 302 | return ch->rtp_dtls_transport(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 303 | } |
| 304 | |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 305 | rtc::PacketTransportInterface* rtcp_transport_channel( |
| 306 | cricket::BaseChannel* ch) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 307 | if (!ch) { |
| 308 | return nullptr; |
| 309 | } |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 310 | return ch->rtcp_dtls_transport(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 311 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 312 | }; |
| 313 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 314 | class WebRtcSessionCreateSDPObserverForTest |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 315 | : public rtc::RefCountedObject<CreateSessionDescriptionObserver> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 316 | public: |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 317 | enum State { |
| 318 | kInit, |
| 319 | kFailed, |
| 320 | kSucceeded, |
| 321 | }; |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 322 | WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {} |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 323 | |
| 324 | // CreateSessionDescriptionObserver implementation. |
| 325 | virtual void OnSuccess(SessionDescriptionInterface* desc) { |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 326 | description_.reset(desc); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 327 | state_ = kSucceeded; |
| 328 | } |
| 329 | virtual void OnFailure(const std::string& error) { |
| 330 | state_ = kFailed; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 331 | } |
| 332 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 333 | SessionDescriptionInterface* description() { return description_.get(); } |
| 334 | |
| 335 | SessionDescriptionInterface* ReleaseDescription() { |
| 336 | return description_.release(); |
| 337 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 338 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 339 | State state() const { return state_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 340 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 341 | protected: |
| 342 | ~WebRtcSessionCreateSDPObserverForTest() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 343 | |
| 344 | private: |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 345 | std::unique_ptr<SessionDescriptionInterface> description_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 346 | State state_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 347 | }; |
| 348 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 349 | class FakeAudioSource : public cricket::AudioSource { |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 350 | public: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 351 | FakeAudioSource() : sink_(NULL) {} |
| 352 | virtual ~FakeAudioSource() { |
henrike@webrtc.org | a7b9818 | 2014-02-21 15:51:43 +0000 | [diff] [blame] | 353 | if (sink_) |
| 354 | sink_->OnClose(); |
| 355 | } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 356 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 357 | void SetSink(Sink* sink) override { sink_ = sink; } |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 358 | |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 359 | const cricket::AudioSource::Sink* sink() const { return sink_; } |
| 360 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 361 | private: |
Taylor Brandstetter | 1a018dc | 2016-03-08 12:37:39 -0800 | [diff] [blame] | 362 | cricket::AudioSource::Sink* sink_; |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 363 | }; |
| 364 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 365 | class WebRtcSessionTest |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 366 | : public testing::TestWithParam<RTCCertificateGenerationMethod>, |
| 367 | public sigslot::has_slots<> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 368 | protected: |
| 369 | // TODO Investigate why ChannelManager crashes, if it's created |
| 370 | // after stun_server. |
| 371 | WebRtcSessionTest() |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 372 | : media_engine_(new cricket::FakeMediaEngine()), |
| 373 | data_engine_(new cricket::FakeDataEngine()), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 374 | channel_manager_(new cricket::ChannelManager(media_engine_, |
| 375 | data_engine_, |
| 376 | rtc::Thread::Current())), |
| 377 | fake_call_(webrtc::Call::Config(&event_log_)), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 378 | media_controller_( |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 379 | webrtc::MediaControllerInterface::Create(cricket::MediaConfig(), |
| 380 | rtc::Thread::Current(), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 381 | channel_manager_.get(), |
| 382 | &event_log_)), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 383 | tdesc_factory_(new cricket::TransportDescriptionFactory()), |
| 384 | desc_factory_( |
| 385 | new cricket::MediaSessionDescriptionFactory(channel_manager_.get(), |
| 386 | tdesc_factory_.get())), |
| 387 | pss_(new rtc::PhysicalSocketServer), |
| 388 | vss_(new rtc::VirtualSocketServer(pss_.get())), |
| 389 | fss_(new rtc::FirewallSocketServer(vss_.get())), |
| 390 | ss_scope_(fss_.get()), |
| 391 | stun_socket_addr_( |
| 392 | rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)), |
| 393 | stun_server_(cricket::TestStunServer::Create(Thread::Current(), |
| 394 | stun_socket_addr_)), |
| 395 | turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr), |
| 396 | metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) { |
buildbot@webrtc.org | 51c5508 | 2014-07-28 22:26:15 +0000 | [diff] [blame] | 397 | cricket::ServerAddresses stun_servers; |
| 398 | stun_servers.insert(stun_socket_addr_); |
| 399 | allocator_.reset(new cricket::BasicPortAllocator( |
| 400 | &network_manager_, |
| 401 | stun_servers, |
| 402 | SocketAddress(), SocketAddress(), SocketAddress())); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 403 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 404 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 405 | EXPECT_TRUE(channel_manager_->Init()); |
| 406 | desc_factory_->set_add_legacy_streams(false); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 407 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | void AddInterface(const SocketAddress& addr) { |
| 411 | network_manager_.AddInterface(addr); |
| 412 | } |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 413 | void RemoveInterface(const SocketAddress& addr) { |
| 414 | network_manager_.RemoveInterface(addr); |
| 415 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 416 | |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 417 | // If |cert_generator| != null or |rtc_configuration| contains |certificates| |
| 418 | // then DTLS will be enabled unless explicitly disabled by |rtc_configuration| |
| 419 | // options. When DTLS is enabled a certificate will be used if provided, |
| 420 | // otherwise one will be generated using the |cert_generator|. |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 421 | void Init( |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 422 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
| 423 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 424 | ASSERT_TRUE(session_.get() == NULL); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 425 | fake_sctp_transport_factory_ = new FakeSctpTransportFactory(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 426 | session_.reset(new WebRtcSessionForTest( |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 427 | media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(), |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 428 | rtc::Thread::Current(), allocator_.get(), &observer_, |
| 429 | std::unique_ptr<cricket::TransportController>( |
| 430 | new cricket::TransportController(rtc::Thread::Current(), |
| 431 | rtc::Thread::Current(), |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 432 | allocator_.get())), |
| 433 | std::unique_ptr<FakeSctpTransportFactory>( |
| 434 | fake_sctp_transport_factory_))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 435 | session_->SignalDataChannelOpenMessage.connect( |
| 436 | this, &WebRtcSessionTest::OnDataChannelOpenMessage); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 437 | |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 438 | configuration_.rtcp_mux_policy = rtcp_mux_policy; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 439 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 440 | observer_.ice_connection_state_); |
| 441 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 442 | observer_.ice_gathering_state_); |
| 443 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 444 | EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator), |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 445 | configuration_)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 446 | session_->set_metrics_observer(metrics_observer_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 447 | } |
| 448 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 449 | void OnDataChannelOpenMessage(const std::string& label, |
| 450 | const InternalDataChannelInit& config) { |
| 451 | last_data_channel_label_ = label; |
| 452 | last_data_channel_config_ = config; |
| 453 | } |
| 454 | |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 455 | void Init() { |
| 456 | Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
| 457 | } |
| 458 | |
| 459 | void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
| 460 | Init(nullptr, rtcp_mux_policy); |
| 461 | } |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 462 | |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 463 | void InitWithBundlePolicy( |
| 464 | PeerConnectionInterface::BundlePolicy bundle_policy) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 465 | configuration_.bundle_policy = bundle_policy; |
| 466 | Init(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | void InitWithRtcpMuxPolicy( |
| 470 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
| 471 | PeerConnectionInterface::RTCConfiguration configuration; |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 472 | Init(rtcp_mux_policy); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 473 | } |
| 474 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 475 | // Successfully init with DTLS; with a certificate generated and supplied or |
| 476 | // with a store that generates it for us. |
| 477 | void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 478 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 479 | if (cert_gen_method == ALREADY_GENERATED) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 480 | configuration_.certificates.push_back( |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 481 | FakeRTCCertificateGenerator::GenerateCertificate()); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 482 | } else if (cert_gen_method == DTLS_IDENTITY_STORE) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 483 | cert_generator.reset(new FakeRTCCertificateGenerator()); |
| 484 | cert_generator->set_should_fail(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 485 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 486 | RTC_CHECK(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 487 | } |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 488 | Init(std::move(cert_generator), |
| 489 | PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | // Init with DTLS with a store that will fail to generate a certificate. |
| 493 | void InitWithDtlsIdentityGenFail() { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 494 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 495 | new FakeRTCCertificateGenerator()); |
| 496 | cert_generator->set_should_fail(true); |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 497 | Init(std::move(cert_generator), |
| 498 | PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 499 | } |
| 500 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 501 | void InitWithGcm() { |
| 502 | rtc::CryptoOptions crypto_options; |
| 503 | crypto_options.enable_gcm_crypto_suites = true; |
| 504 | channel_manager_->SetCryptoOptions(crypto_options); |
| 505 | with_gcm_ = true; |
| 506 | Init(); |
| 507 | } |
| 508 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 509 | void SendAudioVideoStream1() { |
| 510 | send_stream_1_ = true; |
| 511 | send_stream_2_ = false; |
| 512 | send_audio_ = true; |
| 513 | send_video_ = true; |
| 514 | } |
| 515 | |
| 516 | void SendAudioVideoStream2() { |
| 517 | send_stream_1_ = false; |
| 518 | send_stream_2_ = true; |
| 519 | send_audio_ = true; |
| 520 | send_video_ = true; |
| 521 | } |
| 522 | |
| 523 | void SendAudioVideoStream1And2() { |
| 524 | send_stream_1_ = true; |
| 525 | send_stream_2_ = true; |
| 526 | send_audio_ = true; |
| 527 | send_video_ = true; |
| 528 | } |
| 529 | |
| 530 | void SendNothing() { |
| 531 | send_stream_1_ = false; |
| 532 | send_stream_2_ = false; |
| 533 | send_audio_ = false; |
| 534 | send_video_ = false; |
| 535 | } |
| 536 | |
| 537 | void SendAudioOnlyStream2() { |
| 538 | send_stream_1_ = false; |
| 539 | send_stream_2_ = true; |
| 540 | send_audio_ = true; |
| 541 | send_video_ = false; |
| 542 | } |
| 543 | |
| 544 | void SendVideoOnlyStream2() { |
| 545 | send_stream_1_ = false; |
| 546 | send_stream_2_ = true; |
| 547 | send_audio_ = false; |
| 548 | send_video_ = true; |
| 549 | } |
| 550 | |
| 551 | void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) { |
| 552 | if (send_stream_1_ && send_audio_) { |
| 553 | session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 554 | kStream1); |
| 555 | } |
| 556 | if (send_stream_1_ && send_video_) { |
| 557 | session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 558 | kStream1); |
| 559 | } |
| 560 | if (send_stream_2_ && send_audio_) { |
| 561 | session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 562 | kStream2); |
| 563 | } |
| 564 | if (send_stream_2_ && send_video_) { |
| 565 | session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 566 | kStream2); |
| 567 | } |
| 568 | if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) { |
| 569 | session_options->AddSendStream(cricket::MEDIA_TYPE_DATA, |
| 570 | data_channel_->label(), |
| 571 | data_channel_->label()); |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | void GetOptionsForOffer( |
| 576 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 577 | cricket::MediaSessionOptions* session_options) { |
hta | aac2dea | 2016-03-10 13:35:55 -0800 | [diff] [blame] | 578 | ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 579 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 580 | AddStreamsToOptions(session_options); |
| 581 | if (rtc_options.offer_to_receive_audio == |
| 582 | RTCOfferAnswerOptions::kUndefined) { |
| 583 | session_options->recv_audio = |
| 584 | session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO); |
| 585 | } |
| 586 | if (rtc_options.offer_to_receive_video == |
| 587 | RTCOfferAnswerOptions::kUndefined) { |
| 588 | session_options->recv_video = |
| 589 | session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO); |
| 590 | } |
| 591 | session_options->bundle_enabled = |
| 592 | session_options->bundle_enabled && |
| 593 | (session_options->has_audio() || session_options->has_video() || |
| 594 | session_options->has_data()); |
| 595 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 596 | if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) { |
| 597 | session_options->data_channel_type = cricket::DCT_SCTP; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 598 | } else if (session_->data_channel_type() == cricket::DCT_QUIC) { |
| 599 | session_options->data_channel_type = cricket::DCT_QUIC; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 600 | } |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 601 | |
| 602 | if (with_gcm_) { |
| 603 | session_options->crypto_options.enable_gcm_crypto_suites = true; |
| 604 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 605 | } |
| 606 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 607 | void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { |
| 608 | // ParseConstraintsForAnswer is used to set some defaults. |
| 609 | ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 610 | |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 611 | AddStreamsToOptions(session_options); |
| 612 | session_options->bundle_enabled = |
| 613 | session_options->bundle_enabled && |
| 614 | (session_options->has_audio() || session_options->has_video() || |
| 615 | session_options->has_data()); |
| 616 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 617 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 618 | session_options->data_channel_type = session_->data_channel_type(); |
deadbeef | 907abe4 | 2016-08-04 12:22:18 -0700 | [diff] [blame] | 619 | } |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 620 | |
| 621 | if (with_gcm_) { |
| 622 | session_options->crypto_options.enable_gcm_crypto_suites = true; |
| 623 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | // Creates a local offer and applies it. Starts ICE. |
| 627 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 628 | // to decide which streams to create. |
| 629 | void InitiateCall() { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 630 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 631 | SetLocalDescriptionWithoutError(offer); |
| 632 | EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 633 | observer_.ice_gathering_state_, |
| 634 | kIceCandidatesTimeout); |
| 635 | } |
| 636 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 637 | SessionDescriptionInterface* CreateOffer() { |
| 638 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 639 | options.offer_to_receive_audio = |
| 640 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 641 | |
| 642 | return CreateOffer(options); |
| 643 | } |
| 644 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 645 | SessionDescriptionInterface* CreateOffer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 646 | const PeerConnectionInterface::RTCOfferAnswerOptions options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 647 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 648 | observer = new WebRtcSessionCreateSDPObserverForTest(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 649 | cricket::MediaSessionOptions session_options; |
| 650 | GetOptionsForOffer(options, &session_options); |
| 651 | session_->CreateOffer(observer, options, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 652 | EXPECT_TRUE_WAIT( |
| 653 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 654 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 655 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | SessionDescriptionInterface* CreateAnswer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 659 | const cricket::MediaSessionOptions& options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 660 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 661 | = new WebRtcSessionCreateSDPObserverForTest(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 662 | cricket::MediaSessionOptions session_options = options; |
| 663 | GetOptionsForAnswer(&session_options); |
| 664 | // Overwrite recv_audio and recv_video with passed-in values. |
| 665 | session_options.recv_video = options.recv_video; |
| 666 | session_options.recv_audio = options.recv_audio; |
| 667 | session_->CreateAnswer(observer, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 668 | EXPECT_TRUE_WAIT( |
| 669 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 670 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 671 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 672 | } |
| 673 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 674 | SessionDescriptionInterface* CreateAnswer() { |
| 675 | cricket::MediaSessionOptions options; |
| 676 | options.recv_video = true; |
| 677 | options.recv_audio = true; |
| 678 | return CreateAnswer(options); |
| 679 | } |
| 680 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 681 | bool ChannelsExist() const { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 682 | return (session_->voice_channel() != NULL && |
| 683 | session_->video_channel() != NULL); |
| 684 | } |
| 685 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 686 | void VerifyCryptoParams(const cricket::SessionDescription* sdp, |
| 687 | bool gcm_enabled = false) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 688 | ASSERT_TRUE(session_.get() != NULL); |
| 689 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 690 | ASSERT_TRUE(content != NULL); |
| 691 | const cricket::AudioContentDescription* audio_content = |
| 692 | static_cast<const cricket::AudioContentDescription*>( |
| 693 | content->description); |
| 694 | ASSERT_TRUE(audio_content != NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 695 | if (!gcm_enabled) { |
| 696 | ASSERT_EQ(1U, audio_content->cryptos().size()); |
| 697 | ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size()); |
| 698 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 699 | audio_content->cryptos()[0].cipher_suite); |
| 700 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 701 | audio_content->protocol()); |
| 702 | } else { |
| 703 | // The offer contains 3 possible crypto suites, the answer 1. |
| 704 | EXPECT_LE(1U, audio_content->cryptos().size()); |
| 705 | EXPECT_NE(2U, audio_content->cryptos().size()); |
| 706 | EXPECT_GE(3U, audio_content->cryptos().size()); |
| 707 | ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size()); |
| 708 | ASSERT_EQ("AEAD_AES_256_GCM", |
| 709 | audio_content->cryptos()[0].cipher_suite); |
| 710 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 711 | audio_content->protocol()); |
| 712 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 713 | |
| 714 | content = cricket::GetFirstVideoContent(sdp); |
| 715 | ASSERT_TRUE(content != NULL); |
| 716 | const cricket::VideoContentDescription* video_content = |
| 717 | static_cast<const cricket::VideoContentDescription*>( |
| 718 | content->description); |
| 719 | ASSERT_TRUE(video_content != NULL); |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 720 | if (!gcm_enabled) { |
| 721 | ASSERT_EQ(1U, video_content->cryptos().size()); |
| 722 | ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 723 | video_content->cryptos()[0].cipher_suite); |
| 724 | ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size()); |
| 725 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 726 | video_content->protocol()); |
| 727 | } else { |
| 728 | // The offer contains 3 possible crypto suites, the answer 1. |
| 729 | EXPECT_LE(1U, video_content->cryptos().size()); |
| 730 | EXPECT_NE(2U, video_content->cryptos().size()); |
| 731 | EXPECT_GE(3U, video_content->cryptos().size()); |
| 732 | ASSERT_EQ("AEAD_AES_256_GCM", |
| 733 | video_content->cryptos()[0].cipher_suite); |
| 734 | ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size()); |
| 735 | EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 736 | video_content->protocol()); |
| 737 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) { |
| 741 | const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 742 | ASSERT_TRUE(content != NULL); |
| 743 | const cricket::AudioContentDescription* audio_content = |
| 744 | static_cast<const cricket::AudioContentDescription*>( |
| 745 | content->description); |
| 746 | ASSERT_TRUE(audio_content != NULL); |
| 747 | ASSERT_EQ(0U, audio_content->cryptos().size()); |
| 748 | |
| 749 | content = cricket::GetFirstVideoContent(sdp); |
| 750 | ASSERT_TRUE(content != NULL); |
| 751 | const cricket::VideoContentDescription* video_content = |
| 752 | static_cast<const cricket::VideoContentDescription*>( |
| 753 | content->description); |
| 754 | ASSERT_TRUE(video_content != NULL); |
| 755 | ASSERT_EQ(0U, video_content->cryptos().size()); |
| 756 | |
| 757 | if (dtls) { |
deadbeef | f393829 | 2015-07-15 12:20:53 -0700 | [diff] [blame] | 758 | EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 759 | audio_content->protocol()); |
deadbeef | f393829 | 2015-07-15 12:20:53 -0700 | [diff] [blame] | 760 | EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 761 | video_content->protocol()); |
| 762 | } else { |
| 763 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 764 | audio_content->protocol()); |
| 765 | EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), |
| 766 | video_content->protocol()); |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | // Set the internal fake description factories to do DTLS-SRTP. |
| 771 | void SetFactoryDtlsSrtp() { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 772 | desc_factory_->set_secure(cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 773 | std::string identity_name = "WebRTC" + |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 774 | rtc::ToString(rtc::CreateRandomId()); |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 775 | // Confirmed to work with KT_RSA and KT_ECDSA. |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 776 | tdesc_factory_->set_certificate( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 777 | rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 778 | rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 779 | tdesc_factory_->set_secure(cricket::SEC_REQUIRED); |
| 780 | } |
| 781 | |
| 782 | void VerifyFingerprintStatus(const cricket::SessionDescription* sdp, |
| 783 | bool expected) { |
| 784 | const TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 785 | ASSERT_TRUE(audio != NULL); |
| 786 | ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 787 | const TransportInfo* video = sdp->GetTransportInfoByName("video"); |
| 788 | ASSERT_TRUE(video != NULL); |
| 789 | ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | void VerifyAnswerFromNonCryptoOffer() { |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 793 | // Create an SDP without Crypto. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 794 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 795 | options.recv_video = true; |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 796 | JsepSessionDescription* offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 797 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 798 | ASSERT_TRUE(offer != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 799 | VerifyNoCryptoParams(offer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 800 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, |
| 801 | offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 802 | const webrtc::SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 803 | // Answer should be NULL as no crypto params in offer. |
| 804 | ASSERT_TRUE(answer == NULL); |
| 805 | } |
| 806 | |
| 807 | void VerifyAnswerFromCryptoOffer() { |
| 808 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 809 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 810 | options.bundle_enabled = true; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 811 | std::unique_ptr<JsepSessionDescription> offer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 812 | CreateRemoteOffer(options, cricket::SEC_REQUIRED)); |
| 813 | ASSERT_TRUE(offer.get() != NULL); |
| 814 | VerifyCryptoParams(offer->description()); |
| 815 | SetRemoteDescriptionWithoutError(offer.release()); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 816 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 817 | ASSERT_TRUE(answer.get() != NULL); |
| 818 | VerifyCryptoParams(answer->description()); |
| 819 | } |
| 820 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 821 | bool IceUfragPwdEqual(const cricket::SessionDescription* desc1, |
| 822 | const cricket::SessionDescription* desc2) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 823 | if (desc1->contents().size() != desc2->contents().size()) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 824 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 825 | } |
| 826 | |
| 827 | const cricket::ContentInfos& contents = desc1->contents(); |
| 828 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 829 | |
| 830 | for (; it != contents.end(); ++it) { |
| 831 | const cricket::TransportDescription* transport_desc1 = |
| 832 | desc1->GetTransportDescriptionByName(it->name); |
| 833 | const cricket::TransportDescription* transport_desc2 = |
| 834 | desc2->GetTransportDescriptionByName(it->name); |
| 835 | if (!transport_desc1 || !transport_desc2) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 836 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 837 | } |
| 838 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 839 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 840 | return false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 841 | } |
| 842 | } |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 843 | return true; |
| 844 | } |
| 845 | |
| 846 | // Compares ufrag/password only for the specified |media_type|. |
| 847 | bool IceUfragPwdEqual(const cricket::SessionDescription* desc1, |
| 848 | const cricket::SessionDescription* desc2, |
| 849 | cricket::MediaType media_type) { |
| 850 | if (desc1->contents().size() != desc2->contents().size()) { |
| 851 | return false; |
| 852 | } |
| 853 | |
| 854 | const cricket::ContentInfo* cinfo = |
| 855 | cricket::GetFirstMediaContent(desc1->contents(), media_type); |
| 856 | const cricket::TransportDescription* transport_desc1 = |
| 857 | desc1->GetTransportDescriptionByName(cinfo->name); |
| 858 | const cricket::TransportDescription* transport_desc2 = |
| 859 | desc2->GetTransportDescriptionByName(cinfo->name); |
| 860 | if (!transport_desc1 || !transport_desc2) { |
| 861 | return false; |
| 862 | } |
| 863 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 864 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
| 865 | return false; |
| 866 | } |
| 867 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 868 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 869 | |
| 870 | void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc, |
| 871 | std::string *sdp) { |
| 872 | const cricket::SessionDescription* desc = current_desc->description(); |
| 873 | EXPECT_TRUE(current_desc->ToString(sdp)); |
| 874 | |
| 875 | const cricket::ContentInfos& contents = desc->contents(); |
| 876 | cricket::ContentInfos::const_iterator it = contents.begin(); |
| 877 | // Replace ufrag and pwd lines with empty strings. |
| 878 | for (; it != contents.end(); ++it) { |
| 879 | const cricket::TransportDescription* transport_desc = |
| 880 | desc->GetTransportDescriptionByName(it->name); |
| 881 | std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag |
| 882 | + "\r\n"; |
| 883 | std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd |
| 884 | + "\r\n"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 885 | rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 886 | "", 0, |
| 887 | sdp); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 888 | rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 889 | "", 0, |
| 890 | sdp); |
| 891 | } |
| 892 | } |
| 893 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 894 | void SetIceUfragPwd(SessionDescriptionInterface* current_desc, |
| 895 | const std::string& ufrag, |
| 896 | const std::string& pwd) { |
| 897 | cricket::SessionDescription* desc = current_desc->description(); |
| 898 | for (TransportInfo& transport_info : desc->transport_infos()) { |
| 899 | cricket::TransportDescription& transport_desc = |
| 900 | transport_info.description; |
| 901 | transport_desc.ice_ufrag = ufrag; |
| 902 | transport_desc.ice_pwd = pwd; |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 906 | // Sets ufrag/pwd for specified |media_type|. |
| 907 | void SetIceUfragPwd(SessionDescriptionInterface* current_desc, |
| 908 | cricket::MediaType media_type, |
| 909 | const std::string& ufrag, |
| 910 | const std::string& pwd) { |
| 911 | cricket::SessionDescription* desc = current_desc->description(); |
| 912 | const cricket::ContentInfo* cinfo = |
| 913 | cricket::GetFirstMediaContent(desc->contents(), media_type); |
| 914 | TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name); |
| 915 | cricket::TransportDescription* transport_desc = |
| 916 | &transport_info->description; |
| 917 | transport_desc->ice_ufrag = ufrag; |
| 918 | transport_desc->ice_pwd = pwd; |
| 919 | } |
| 920 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 921 | // Creates a remote offer and and applies it as a remote description, |
| 922 | // creates a local answer and applies is as a local description. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 923 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 924 | // to decide which local and remote streams to create. |
| 925 | void CreateAndSetRemoteOfferAndLocalAnswer() { |
| 926 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 927 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 928 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 929 | SetLocalDescriptionWithoutError(answer); |
| 930 | } |
| 931 | void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 932 | EXPECT_TRUE(session_->SetLocalDescription(desc, NULL)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 933 | session_->MaybeStartGathering(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 934 | } |
| 935 | void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 936 | WebRtcSession::State expected_state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 937 | SetLocalDescriptionWithoutError(desc); |
| 938 | EXPECT_EQ(expected_state, session_->state()); |
| 939 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 940 | void SetLocalDescriptionExpectError(const std::string& action, |
| 941 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 942 | SessionDescriptionInterface* desc) { |
| 943 | std::string error; |
| 944 | EXPECT_FALSE(session_->SetLocalDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 945 | std::string sdp_type = "local "; |
| 946 | sdp_type.append(action); |
| 947 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 948 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 949 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 950 | void SetLocalDescriptionOfferExpectError(const std::string& expected_error, |
| 951 | SessionDescriptionInterface* desc) { |
| 952 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 953 | expected_error, desc); |
| 954 | } |
| 955 | void SetLocalDescriptionAnswerExpectError(const std::string& expected_error, |
| 956 | SessionDescriptionInterface* desc) { |
| 957 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 958 | expected_error, desc); |
| 959 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 960 | void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) { |
| 961 | EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL)); |
| 962 | } |
| 963 | void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 964 | WebRtcSession::State expected_state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 965 | SetRemoteDescriptionWithoutError(desc); |
| 966 | EXPECT_EQ(expected_state, session_->state()); |
| 967 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 968 | void SetRemoteDescriptionExpectError(const std::string& action, |
| 969 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 970 | SessionDescriptionInterface* desc) { |
| 971 | std::string error; |
| 972 | EXPECT_FALSE(session_->SetRemoteDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 973 | std::string sdp_type = "remote "; |
| 974 | sdp_type.append(action); |
| 975 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 976 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 977 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 978 | void SetRemoteDescriptionOfferExpectError( |
| 979 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 980 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 981 | expected_error, desc); |
| 982 | } |
| 983 | void SetRemoteDescriptionPranswerExpectError( |
| 984 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 985 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer, |
| 986 | expected_error, desc); |
| 987 | } |
| 988 | void SetRemoteDescriptionAnswerExpectError( |
| 989 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 990 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 991 | expected_error, desc); |
| 992 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 993 | |
| 994 | void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer, |
| 995 | SessionDescriptionInterface** nocrypto_answer) { |
| 996 | // Create a SDP without Crypto. |
| 997 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 998 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 999 | options.bundle_enabled = true; |
| 1000 | *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 1001 | ASSERT_TRUE(*offer != NULL); |
| 1002 | VerifyCryptoParams((*offer)->description()); |
| 1003 | |
| 1004 | *nocrypto_answer = CreateRemoteAnswer(*offer, options, |
| 1005 | cricket::SEC_DISABLED); |
| 1006 | EXPECT_TRUE(*nocrypto_answer != NULL); |
| 1007 | } |
| 1008 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1009 | void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer, |
| 1010 | SessionDescriptionInterface** nodtls_answer) { |
| 1011 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1012 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1013 | options.bundle_enabled = true; |
| 1014 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1015 | std::unique_ptr<SessionDescriptionInterface> temp_offer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1016 | CreateRemoteOffer(options, cricket::SEC_ENABLED)); |
| 1017 | |
| 1018 | *nodtls_answer = |
| 1019 | CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED); |
| 1020 | EXPECT_TRUE(*nodtls_answer != NULL); |
| 1021 | VerifyFingerprintStatus((*nodtls_answer)->description(), false); |
| 1022 | VerifyCryptoParams((*nodtls_answer)->description()); |
| 1023 | |
| 1024 | SetFactoryDtlsSrtp(); |
| 1025 | *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED); |
| 1026 | ASSERT_TRUE(*offer != NULL); |
| 1027 | VerifyFingerprintStatus((*offer)->description(), true); |
| 1028 | VerifyCryptoParams((*offer)->description()); |
| 1029 | } |
| 1030 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1031 | JsepSessionDescription* CreateRemoteOfferWithVersion( |
| 1032 | cricket::MediaSessionOptions options, |
| 1033 | cricket::SecurePolicy secure_policy, |
| 1034 | const std::string& session_version, |
| 1035 | const SessionDescriptionInterface* current_desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1036 | std::string session_id = rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1037 | const cricket::SessionDescription* cricket_desc = NULL; |
| 1038 | if (current_desc) { |
| 1039 | cricket_desc = current_desc->description(); |
| 1040 | session_id = current_desc->session_id(); |
| 1041 | } |
| 1042 | |
| 1043 | desc_factory_->set_secure(secure_policy); |
| 1044 | JsepSessionDescription* offer( |
| 1045 | new JsepSessionDescription(JsepSessionDescription::kOffer)); |
| 1046 | if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc), |
| 1047 | session_id, session_version)) { |
| 1048 | delete offer; |
| 1049 | offer = NULL; |
| 1050 | } |
| 1051 | return offer; |
| 1052 | } |
| 1053 | JsepSessionDescription* CreateRemoteOffer( |
| 1054 | cricket::MediaSessionOptions options) { |
| 1055 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 1056 | kSessionVersion, NULL); |
| 1057 | } |
| 1058 | JsepSessionDescription* CreateRemoteOffer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1059 | cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) { |
| 1060 | return CreateRemoteOfferWithVersion( |
| 1061 | options, sdes_policy, kSessionVersion, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1062 | } |
| 1063 | JsepSessionDescription* CreateRemoteOffer( |
| 1064 | cricket::MediaSessionOptions options, |
| 1065 | const SessionDescriptionInterface* current_desc) { |
| 1066 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 1067 | kSessionVersion, current_desc); |
| 1068 | } |
| 1069 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1070 | JsepSessionDescription* CreateRemoteOfferWithSctpPort( |
| 1071 | const char* sctp_stream_name, int new_port, |
| 1072 | cricket::MediaSessionOptions options) { |
| 1073 | options.data_channel_type = cricket::DCT_SCTP; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1074 | options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel", |
| 1075 | sctp_stream_name); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1076 | return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options)); |
| 1077 | } |
| 1078 | |
| 1079 | // Takes ownership of offer_basis (and deletes it). |
| 1080 | JsepSessionDescription* ChangeSDPSctpPort( |
| 1081 | int new_port, webrtc::SessionDescriptionInterface *offer_basis) { |
| 1082 | // Stringify the input SDP, swap the 5000 for 'new_port' and create a new |
| 1083 | // SessionDescription from the mutated string. |
| 1084 | const char* default_port_str = "5000"; |
| 1085 | char new_port_str[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1086 | rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1087 | std::string offer_str; |
| 1088 | offer_basis->ToString(&offer_str); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1089 | rtc::replace_substrs(default_port_str, strlen(default_port_str), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1090 | new_port_str, strlen(new_port_str), |
| 1091 | &offer_str); |
| 1092 | JsepSessionDescription* offer = new JsepSessionDescription( |
| 1093 | offer_basis->type()); |
| 1094 | delete offer_basis; |
| 1095 | offer->Initialize(offer_str, NULL); |
| 1096 | return offer; |
| 1097 | } |
| 1098 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1099 | // Create a remote offer. Call SendAudioVideoStreamX() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1100 | // before this function to decide which streams to create. |
| 1101 | JsepSessionDescription* CreateRemoteOffer() { |
| 1102 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1103 | GetOptionsForAnswer(&options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1104 | return CreateRemoteOffer(options, session_->remote_description()); |
| 1105 | } |
| 1106 | |
| 1107 | JsepSessionDescription* CreateRemoteAnswer( |
| 1108 | const SessionDescriptionInterface* offer, |
| 1109 | cricket::MediaSessionOptions options, |
| 1110 | cricket::SecurePolicy policy) { |
| 1111 | desc_factory_->set_secure(policy); |
| 1112 | const std::string session_id = |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1113 | rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1114 | JsepSessionDescription* answer( |
| 1115 | new JsepSessionDescription(JsepSessionDescription::kAnswer)); |
| 1116 | if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(), |
| 1117 | options, NULL), |
| 1118 | session_id, kSessionVersion)) { |
| 1119 | delete answer; |
| 1120 | answer = NULL; |
| 1121 | } |
| 1122 | return answer; |
| 1123 | } |
| 1124 | |
| 1125 | JsepSessionDescription* CreateRemoteAnswer( |
| 1126 | const SessionDescriptionInterface* offer, |
| 1127 | cricket::MediaSessionOptions options) { |
| 1128 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 1129 | } |
| 1130 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1131 | // Creates an answer session description. |
| 1132 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1133 | // to decide which streams to create. |
| 1134 | JsepSessionDescription* CreateRemoteAnswer( |
| 1135 | const SessionDescriptionInterface* offer) { |
| 1136 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1137 | GetOptionsForAnswer(&options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1138 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 1139 | } |
| 1140 | |
| 1141 | void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1142 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1143 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1144 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1145 | |
| 1146 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1147 | options.use_rtp_mux = bundle; |
| 1148 | |
| 1149 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1150 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1151 | // and answer. |
| 1152 | SetLocalDescriptionWithoutError(offer); |
| 1153 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1154 | std::unique_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 1155 | CreateRemoteAnswer(session_->local_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1156 | std::string sdp; |
| 1157 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 1158 | |
| 1159 | size_t expected_candidate_num = 2; |
| 1160 | if (!rtcp_mux) { |
| 1161 | // If rtcp_mux is enabled we should expect 4 candidates - host and srflex |
| 1162 | // for rtp and rtcp. |
| 1163 | expected_candidate_num = 4; |
| 1164 | // Disable rtcp-mux from the answer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1165 | const std::string kRtcpMux = "a=rtcp-mux"; |
| 1166 | const std::string kXRtcpMux = "a=xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1167 | rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1168 | kXRtcpMux.c_str(), kXRtcpMux.length(), |
| 1169 | &sdp); |
| 1170 | } |
| 1171 | |
| 1172 | SessionDescriptionInterface* new_answer = CreateSessionDescription( |
| 1173 | JsepSessionDescription::kAnswer, sdp, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1174 | |
| 1175 | // SetRemoteDescription to enable rtcp mux. |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 1176 | SetRemoteDescriptionWithoutError(new_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1177 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1178 | EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1179 | if (bundle) { |
| 1180 | EXPECT_EQ(0, observer_.mline_1_candidates_.size()); |
| 1181 | } else { |
| 1182 | EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1183 | } |
| 1184 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1185 | |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 1186 | bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc, |
| 1187 | const std::string& codec_name) { |
| 1188 | for (const auto& content : desc->description()->contents()) { |
| 1189 | if (static_cast<cricket::MediaContentDescription*>(content.description) |
| 1190 | ->type() == cricket::MEDIA_TYPE_VIDEO) { |
| 1191 | const auto* mdesc = |
| 1192 | static_cast<cricket::VideoContentDescription*>(content.description); |
| 1193 | for (const auto& codec : mdesc->codecs()) { |
| 1194 | if (codec.name == codec_name) { |
| 1195 | return true; |
| 1196 | } |
| 1197 | } |
| 1198 | } |
| 1199 | } |
| 1200 | return false; |
| 1201 | } |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1202 | // Helper class to configure loopback network and verify Best |
| 1203 | // Connection using right IP protocol for TestLoopbackCall |
| 1204 | // method. LoopbackNetworkManager applies firewall rules to block |
| 1205 | // all ping traffic once ICE completed, and remove them to observe |
| 1206 | // ICE reconnected again. This LoopbackNetworkConfiguration struct |
| 1207 | // verifies the best connection is using the right IP protocol after |
| 1208 | // initial ICE convergences. |
| 1209 | |
| 1210 | class LoopbackNetworkConfiguration { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1211 | public: |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1212 | LoopbackNetworkConfiguration() |
| 1213 | : test_ipv6_network_(false), |
| 1214 | test_extra_ipv4_network_(false), |
| 1215 | best_connection_after_initial_ice_converged_(1, 0) {} |
| 1216 | |
| 1217 | // Used to track the expected best connection count in each IP protocol. |
| 1218 | struct ExpectedBestConnection { |
| 1219 | ExpectedBestConnection(int ipv4_count, int ipv6_count) |
| 1220 | : ipv4_count_(ipv4_count), |
| 1221 | ipv6_count_(ipv6_count) {} |
| 1222 | |
| 1223 | int ipv4_count_; |
| 1224 | int ipv6_count_; |
| 1225 | }; |
| 1226 | |
| 1227 | bool test_ipv6_network_; |
| 1228 | bool test_extra_ipv4_network_; |
| 1229 | ExpectedBestConnection best_connection_after_initial_ice_converged_; |
| 1230 | |
| 1231 | void VerifyBestConnectionAfterIceConverge( |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1232 | const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const { |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1233 | Verify(metrics_observer, best_connection_after_initial_ice_converged_); |
| 1234 | } |
| 1235 | |
| 1236 | private: |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1237 | void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer, |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1238 | const ExpectedBestConnection& expected) const { |
| 1239 | EXPECT_EQ( |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1240 | metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily, |
| 1241 | webrtc::kBestConnections_IPv4), |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1242 | expected.ipv4_count_); |
| 1243 | EXPECT_EQ( |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1244 | metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily, |
| 1245 | webrtc::kBestConnections_IPv6), |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1246 | expected.ipv6_count_); |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1247 | // This is used in the loopback call so there is only single host to host |
| 1248 | // candidate pair. |
| 1249 | EXPECT_EQ(metrics_observer->GetEnumCounter( |
| 1250 | webrtc::kEnumCounterIceCandidatePairTypeUdp, |
| 1251 | webrtc::kIceCandidatePairHostHost), |
Guo-wei Shieh | 3cc834a | 2015-09-04 15:52:14 -0700 | [diff] [blame] | 1252 | 0); |
| 1253 | EXPECT_EQ(metrics_observer->GetEnumCounter( |
| 1254 | webrtc::kEnumCounterIceCandidatePairTypeUdp, |
| 1255 | webrtc::kIceCandidatePairHostPublicHostPublic), |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1256 | 1); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1257 | } |
| 1258 | }; |
| 1259 | |
| 1260 | class LoopbackNetworkManager { |
| 1261 | public: |
| 1262 | LoopbackNetworkManager(WebRtcSessionTest* session, |
| 1263 | const LoopbackNetworkConfiguration& config) |
| 1264 | : config_(config) { |
| 1265 | session->AddInterface( |
| 1266 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1267 | if (config_.test_extra_ipv4_network_) { |
| 1268 | session->AddInterface( |
| 1269 | rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
| 1270 | } |
| 1271 | if (config_.test_ipv6_network_) { |
| 1272 | session->AddInterface( |
| 1273 | rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort)); |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | void ApplyFirewallRules(rtc::FirewallSocketServer* fss) { |
| 1278 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1279 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1280 | if (config_.test_extra_ipv4_network_) { |
| 1281 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1282 | rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
| 1283 | } |
| 1284 | if (config_.test_ipv6_network_) { |
| 1285 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1286 | rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort)); |
| 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); } |
| 1291 | |
| 1292 | private: |
| 1293 | LoopbackNetworkConfiguration config_; |
| 1294 | }; |
| 1295 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1296 | // The method sets up a call from the session to itself, in a loopback |
| 1297 | // arrangement. It also uses a firewall rule to create a temporary |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1298 | // disconnection, and then a permanent disconnection. |
| 1299 | // This code is placed in a method so that it can be invoked |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1300 | // by multiple tests with different allocators (e.g. with and without BUNDLE). |
| 1301 | // While running the call, this method also checks if the session goes through |
| 1302 | // the correct sequence of ICE states when a connection is established, |
| 1303 | // broken, and re-established. |
| 1304 | // The Connection state should go: |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1305 | // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed |
| 1306 | // -> Failed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1307 | // The Gathering state should go: New -> Gathering -> Completed. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1308 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1309 | void SetupLoopbackCall() { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1310 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1311 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1312 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1313 | |
| 1314 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 1315 | observer_.ice_gathering_state_); |
| 1316 | SetLocalDescriptionWithoutError(offer); |
| 1317 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 1318 | observer_.ice_connection_state_); |
| 1319 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1320 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1321 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1322 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1323 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1324 | |
| 1325 | std::string sdp; |
| 1326 | offer->ToString(&sdp); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1327 | SessionDescriptionInterface* desc = webrtc::CreateSessionDescription( |
| 1328 | JsepSessionDescription::kAnswer, sdp, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1329 | ASSERT_TRUE(desc != NULL); |
| 1330 | SetRemoteDescriptionWithoutError(desc); |
| 1331 | |
| 1332 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1333 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 1334 | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1335 | // The ice connection state is "Connected" too briefly to catch in a test. |
| 1336 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1337 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 1338 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1339 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1340 | void TestLoopbackCall(const LoopbackNetworkConfiguration& config) { |
| 1341 | LoopbackNetworkManager loopback_network_manager(this, config); |
| 1342 | SetupLoopbackCall(); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1343 | config.VerifyBestConnectionAfterIceConverge(metrics_observer_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1344 | // Adding firewall rule to block ping requests, which should cause |
| 1345 | // transport channel failure. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1346 | |
| 1347 | loopback_network_manager.ApplyFirewallRules(fss_.get()); |
| 1348 | |
| 1349 | LOG(LS_INFO) << "Firewall Rules applied"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1350 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 1351 | observer_.ice_connection_state_, |
| 1352 | kIceCandidatesTimeout); |
| 1353 | |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1354 | metrics_observer_->Reset(); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1355 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1356 | // Clearing the rules, session should move back to completed state. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1357 | loopback_network_manager.ClearRules(fss_.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1358 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1359 | LOG(LS_INFO) << "Firewall Rules cleared"; |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1360 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1361 | observer_.ice_connection_state_, |
| 1362 | kIceCandidatesTimeout); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1363 | |
| 1364 | // Now we block ping requests and wait until the ICE connection transitions |
| 1365 | // to the Failed state. This will take at least 30 seconds because it must |
| 1366 | // wait for the Port to timeout. |
| 1367 | int port_timeout = 30000; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1368 | |
| 1369 | loopback_network_manager.ApplyFirewallRules(fss_.get()); |
| 1370 | LOG(LS_INFO) << "Firewall Rules applied again"; |
jlmiller@webrtc.org | 804eb46 | 2015-02-20 02:20:03 +0000 | [diff] [blame] | 1371 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1372 | observer_.ice_connection_state_, |
| 1373 | kIceCandidatesTimeout + port_timeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1376 | void TestLoopbackCall() { |
| 1377 | LoopbackNetworkConfiguration config; |
| 1378 | TestLoopbackCall(config); |
| 1379 | } |
| 1380 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1381 | void TestPacketOptions() { |
| 1382 | media_controller_.reset( |
| 1383 | new cricket::FakeMediaController(channel_manager_.get(), &fake_call_)); |
| 1384 | LoopbackNetworkConfiguration config; |
| 1385 | LoopbackNetworkManager loopback_network_manager(this, config); |
| 1386 | |
| 1387 | SetupLoopbackCall(); |
| 1388 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 1389 | // Wait for channel to be ready for sending. |
| 1390 | EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1391 | uint8_t test_packet[15] = {0}; |
| 1392 | rtc::PacketOptions options; |
| 1393 | options.packet_id = 10; |
| 1394 | media_engine_->GetVideoChannel(0) |
| 1395 | ->SendRtp(test_packet, sizeof(test_packet), options); |
| 1396 | |
| 1397 | const int kPacketTimeout = 2000; |
deadbeef | 14461d4 | 2016-06-15 11:06:57 -0700 | [diff] [blame] | 1398 | EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(), |
| 1399 | kPacketTimeout); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1400 | EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1); |
| 1401 | } |
| 1402 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1403 | // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory. |
| 1404 | void AddCNCodecs() { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1405 | const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1); |
| 1406 | const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1407 | |
| 1408 | // Add kCNCodec for dtmf test. |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 1409 | std::vector<cricket::AudioCodec> codecs = |
| 1410 | media_engine_->audio_send_codecs(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1411 | codecs.push_back(kCNCodec1); |
| 1412 | codecs.push_back(kCNCodec2); |
| 1413 | media_engine_->SetAudioCodecs(codecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1414 | desc_factory_->set_audio_codecs(codecs, codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
| 1418 | const cricket::ContentDescription* description = content->description; |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1419 | RTC_CHECK(description != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1420 | const cricket::AudioContentDescription* audio_content_desc = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1421 | static_cast<const cricket::AudioContentDescription*>(description); |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1422 | RTC_CHECK(audio_content_desc != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1423 | for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
| 1424 | if (audio_content_desc->codecs()[i].name == "CN") |
| 1425 | return false; |
| 1426 | } |
| 1427 | return true; |
| 1428 | } |
| 1429 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1430 | void CreateDataChannel() { |
deadbeef | fc648b6 | 2015-10-13 16:42:33 -0700 | [diff] [blame] | 1431 | webrtc::InternalDataChannelInit dci; |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1432 | RTC_CHECK(session_.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1433 | dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP; |
| 1434 | data_channel_ = DataChannel::Create( |
| 1435 | session_.get(), session_->data_channel_type(), "datachannel", dci); |
| 1436 | } |
| 1437 | |
| 1438 | void SetLocalDescriptionWithDataChannel() { |
| 1439 | CreateDataChannel(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1440 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1441 | SetLocalDescriptionWithoutError(offer); |
| 1442 | } |
| 1443 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1444 | void VerifyMultipleAsyncCreateDescription( |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1445 | RTCCertificateGenerationMethod cert_gen_method, |
| 1446 | CreateSessionDescriptionRequest::Type type) { |
| 1447 | InitWithDtls(cert_gen_method); |
| 1448 | VerifyMultipleAsyncCreateDescriptionAfterInit(true, type); |
| 1449 | } |
| 1450 | |
| 1451 | void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure( |
| 1452 | CreateSessionDescriptionRequest::Type type) { |
| 1453 | InitWithDtlsIdentityGenFail(); |
| 1454 | VerifyMultipleAsyncCreateDescriptionAfterInit(false, type); |
| 1455 | } |
| 1456 | |
| 1457 | void VerifyMultipleAsyncCreateDescriptionAfterInit( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1458 | bool success, CreateSessionDescriptionRequest::Type type) { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 1459 | RTC_CHECK(session_); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1460 | SetFactoryDtlsSrtp(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1461 | if (type == CreateSessionDescriptionRequest::kAnswer) { |
| 1462 | cricket::MediaSessionOptions options; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1463 | std::unique_ptr<JsepSessionDescription> offer( |
| 1464 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1465 | ASSERT_TRUE(offer.get() != NULL); |
| 1466 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1467 | } |
| 1468 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1469 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1470 | cricket::MediaSessionOptions session_options; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1471 | const int kNumber = 3; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1472 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1473 | observers[kNumber]; |
| 1474 | for (int i = 0; i < kNumber; ++i) { |
| 1475 | observers[i] = new WebRtcSessionCreateSDPObserverForTest(); |
| 1476 | if (type == CreateSessionDescriptionRequest::kOffer) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1477 | session_->CreateOffer(observers[i], options, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1478 | } else { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1479 | session_->CreateAnswer(observers[i], session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1480 | } |
| 1481 | } |
| 1482 | |
| 1483 | WebRtcSessionCreateSDPObserverForTest::State expected_state = |
| 1484 | success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded : |
| 1485 | WebRtcSessionCreateSDPObserverForTest::kFailed; |
| 1486 | |
| 1487 | for (int i = 0; i < kNumber; ++i) { |
| 1488 | EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000); |
| 1489 | if (success) { |
| 1490 | EXPECT_TRUE(observers[i]->description() != NULL); |
| 1491 | } else { |
| 1492 | EXPECT_TRUE(observers[i]->description() == NULL); |
| 1493 | } |
| 1494 | } |
| 1495 | } |
| 1496 | |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1497 | void ConfigureAllocatorWithTurn() { |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 1498 | cricket::RelayServerConfig turn_server(cricket::RELAY_TURN); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1499 | cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 1500 | turn_server.credentials = credentials; |
| 1501 | turn_server.ports.push_back( |
hnsl | 277b250 | 2016-12-13 05:17:23 -0800 | [diff] [blame] | 1502 | cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP)); |
deadbeef | 653b8e0 | 2015-11-11 12:55:10 -0800 | [diff] [blame] | 1503 | allocator_->AddTurnServer(turn_server); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1504 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 1505 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP); |
mallinath@webrtc.org | 3d81b1b | 2014-09-09 14:38:10 +0000 | [diff] [blame] | 1506 | } |
| 1507 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 1508 | webrtc::RtcEventLogNullImpl event_log_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1509 | cricket::FakeMediaEngine* media_engine_; |
| 1510 | cricket::FakeDataEngine* data_engine_; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1511 | // Actually owned by session_. |
| 1512 | FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1513 | std::unique_ptr<cricket::ChannelManager> channel_manager_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1514 | cricket::FakeCall fake_call_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1515 | std::unique_ptr<webrtc::MediaControllerInterface> media_controller_; |
| 1516 | std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_; |
| 1517 | std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_; |
| 1518 | std::unique_ptr<rtc::PhysicalSocketServer> pss_; |
| 1519 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 1520 | std::unique_ptr<rtc::FirewallSocketServer> fss_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1521 | rtc::SocketServerScope ss_scope_; |
| 1522 | rtc::SocketAddress stun_socket_addr_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1523 | std::unique_ptr<cricket::TestStunServer> stun_server_; |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 1524 | cricket::TestTurnServer turn_server_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1525 | rtc::FakeNetworkManager network_manager_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1526 | std::unique_ptr<cricket::BasicPortAllocator> allocator_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1527 | PeerConnectionFactoryInterface::Options options_; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1528 | PeerConnectionInterface::RTCConfiguration configuration_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1529 | std::unique_ptr<WebRtcSessionForTest> session_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1530 | MockIceObserver observer_; |
| 1531 | cricket::FakeVideoMediaChannel* video_channel_; |
| 1532 | cricket::FakeVoiceMediaChannel* voice_channel_; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1533 | rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1534 | // The following flags affect options created for CreateOffer/CreateAnswer. |
| 1535 | bool send_stream_1_ = false; |
| 1536 | bool send_stream_2_ = false; |
| 1537 | bool send_audio_ = false; |
| 1538 | bool send_video_ = false; |
| 1539 | rtc::scoped_refptr<DataChannel> data_channel_; |
| 1540 | // Last values received from data channel creation signal. |
| 1541 | std::string last_data_channel_label_; |
| 1542 | InternalDataChannelInit last_data_channel_config_; |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 1543 | bool with_gcm_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1544 | }; |
| 1545 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1546 | TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { |
| 1547 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1548 | // SDES is disabled when DTLS is on. |
| 1549 | EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1550 | } |
| 1551 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1552 | TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1553 | Init(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1554 | // SDES is required if DTLS is off. |
| 1555 | EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 1556 | } |
| 1557 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1558 | TEST_F(WebRtcSessionTest, TestSessionCandidates) { |
| 1559 | TestSessionCandidatesWithBundleRtcpMux(false, false); |
| 1560 | } |
| 1561 | |
| 1562 | // Below test cases (TestSessionCandidatesWith*) verify the candidates gathered |
| 1563 | // with rtcp-mux and/or bundle. |
| 1564 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) { |
| 1565 | TestSessionCandidatesWithBundleRtcpMux(false, true); |
| 1566 | } |
| 1567 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1568 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) { |
| 1569 | TestSessionCandidatesWithBundleRtcpMux(true, true); |
| 1570 | } |
| 1571 | |
| 1572 | TEST_F(WebRtcSessionTest, TestMultihomeCandidates) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1573 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1574 | AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1575 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1576 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1577 | InitiateCall(); |
| 1578 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1579 | EXPECT_EQ(8u, observer_.mline_0_candidates_.size()); |
| 1580 | EXPECT_EQ(8u, observer_.mline_1_candidates_.size()); |
| 1581 | } |
| 1582 | |
deadbeef | f5f03e8 | 2016-06-06 11:16:06 -0700 | [diff] [blame] | 1583 | TEST_F(WebRtcSessionTest, TestStunError) { |
| 1584 | rtc::ScopedFakeClock clock; |
| 1585 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1586 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1587 | AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1588 | fss_->AddRule(false, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1589 | rtc::FP_UDP, |
| 1590 | rtc::FD_ANY, |
| 1591 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1592 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1593 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1594 | InitiateCall(); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1595 | // Since kClientAddrHost1 is blocked, not expecting stun candidates for it. |
deadbeef | f5f03e8 | 2016-06-06 11:16:06 -0700 | [diff] [blame] | 1596 | EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1597 | EXPECT_EQ(6u, observer_.mline_0_candidates_.size()); |
| 1598 | EXPECT_EQ(6u, observer_.mline_1_candidates_.size()); |
deadbeef | f5f03e8 | 2016-06-06 11:16:06 -0700 | [diff] [blame] | 1599 | // Destroy session before scoped fake clock goes out of scope to avoid TSan |
| 1600 | // warning. |
| 1601 | session_->Close(); |
| 1602 | session_.reset(nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1605 | TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1606 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1607 | SessionDescriptionInterface* offer = NULL; |
| 1608 | // Since |offer| is NULL, there's no way to tell if it's an offer or answer. |
| 1609 | std::string unknown_action; |
| 1610 | SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1611 | SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1612 | } |
| 1613 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1614 | // Test creating offers and receive answers and make sure the |
| 1615 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1616 | TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1617 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1618 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1619 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1620 | const std::string session_id_orig = offer->session_id(); |
| 1621 | const std::string session_version_orig = offer->session_version(); |
| 1622 | SetLocalDescriptionWithoutError(offer); |
| 1623 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1624 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1625 | SessionDescriptionInterface* answer = |
| 1626 | CreateRemoteAnswer(session_->local_description()); |
| 1627 | SetRemoteDescriptionWithoutError(answer); |
| 1628 | |
| 1629 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1630 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1631 | |
| 1632 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1633 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1634 | |
| 1635 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1636 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1637 | |
| 1638 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1639 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1640 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1641 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1642 | |
| 1643 | // Create new offer without send streams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1644 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1645 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1646 | |
| 1647 | // Verify the session id is the same and the session version is |
| 1648 | // increased. |
| 1649 | EXPECT_EQ(session_id_orig, offer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1650 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1651 | rtc::FromString<uint64_t>(offer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1652 | |
| 1653 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1654 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1655 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1656 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1657 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1658 | answer = CreateRemoteAnswer(session_->local_description()); |
| 1659 | SetRemoteDescriptionWithoutError(answer); |
| 1660 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1661 | // Make sure the receive streams have not changed. |
| 1662 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1663 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1664 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1665 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1666 | } |
| 1667 | |
| 1668 | // Test receiving offers and creating answers and make sure the |
| 1669 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1670 | TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1671 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1672 | SendAudioVideoStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1673 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1674 | VerifyCryptoParams(offer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1675 | SetRemoteDescriptionWithoutError(offer); |
| 1676 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1677 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1678 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1679 | VerifyCryptoParams(answer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1680 | SetLocalDescriptionWithoutError(answer); |
| 1681 | |
| 1682 | const std::string session_id_orig = answer->session_id(); |
| 1683 | const std::string session_version_orig = answer->session_version(); |
| 1684 | |
| 1685 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1686 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1687 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1688 | ASSERT_TRUE(video_channel_); |
| 1689 | ASSERT_TRUE(voice_channel_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1690 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1691 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1692 | |
| 1693 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1694 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1695 | |
| 1696 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1697 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1698 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1699 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1700 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1701 | SendAudioVideoStream1And2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1702 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1703 | SetRemoteDescriptionWithoutError(offer); |
| 1704 | |
| 1705 | // Answer by turning off all send streams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1706 | SendNothing(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1707 | answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1708 | |
| 1709 | // Verify the session id is the same and the session version is |
| 1710 | // increased. |
| 1711 | EXPECT_EQ(session_id_orig, answer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1712 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1713 | rtc::FromString<uint64_t>(answer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1714 | SetLocalDescriptionWithoutError(answer); |
| 1715 | |
| 1716 | ASSERT_EQ(2u, video_channel_->recv_streams().size()); |
| 1717 | EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id); |
| 1718 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id); |
| 1719 | ASSERT_EQ(2u, voice_channel_->recv_streams().size()); |
| 1720 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id); |
| 1721 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id); |
| 1722 | |
| 1723 | // Make sure we have no send streams. |
| 1724 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1725 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
| 1726 | } |
| 1727 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1728 | TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1729 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1730 | media_engine_->set_fail_create_channel(true); |
| 1731 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1732 | SessionDescriptionInterface* offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1733 | ASSERT_TRUE(offer != NULL); |
| 1734 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1735 | // the offer. |
| 1736 | SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1737 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1738 | ASSERT_TRUE(offer != NULL); |
| 1739 | SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer); |
| 1740 | } |
| 1741 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1742 | // |
| 1743 | // Tests for creating/setting SDP under different SDES/DTLS polices: |
| 1744 | // |
| 1745 | // --DTLS off and SDES on |
| 1746 | // TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer: |
| 1747 | // set local/remote offer/answer with crypto --> success |
| 1748 | // TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto ---> |
| 1749 | // failure |
| 1750 | // TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto --> |
| 1751 | // failure |
| 1752 | // TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto --> |
| 1753 | // failure |
| 1754 | // |
| 1755 | // --DTLS on and SDES off |
| 1756 | // TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer: |
| 1757 | // set local/remote offer/answer with DTLS fingerprint --> success |
| 1758 | // TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS |
| 1759 | // fingerprint --> failure |
| 1760 | // TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint |
| 1761 | // --> failure |
| 1762 | // TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint |
| 1763 | // --> failure |
| 1764 | // |
| 1765 | // --Encryption disabled: DTLS off and SDES off |
| 1766 | // TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote |
| 1767 | // answer without SDES or DTLS --> success |
| 1768 | // TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local |
| 1769 | // answer without SDES or DTLS --> success |
| 1770 | // |
| 1771 | |
| 1772 | // Test that we return a failure when applying a remote/local offer that doesn't |
| 1773 | // have cryptos enabled when DTLS is off. |
| 1774 | TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1775 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1776 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1777 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1778 | JsepSessionDescription* offer = CreateRemoteOffer( |
| 1779 | options, cricket::SEC_DISABLED); |
| 1780 | ASSERT_TRUE(offer != NULL); |
| 1781 | VerifyNoCryptoParams(offer->description(), false); |
| 1782 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1783 | // the offer. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1784 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1785 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 1786 | ASSERT_TRUE(offer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1787 | SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1788 | } |
| 1789 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1790 | // Test that we return a failure when applying a local answer that doesn't have |
| 1791 | // cryptos enabled when DTLS is off. |
| 1792 | TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1793 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1794 | SessionDescriptionInterface* offer = NULL; |
| 1795 | SessionDescriptionInterface* answer = NULL; |
| 1796 | CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer); |
| 1797 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1798 | // the offer. |
| 1799 | SetRemoteDescriptionWithoutError(offer); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1800 | SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1803 | // Test we will return fail when apply an remote answer that doesn't have |
| 1804 | // crypto enabled when DTLS is off. |
| 1805 | TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1806 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1807 | SessionDescriptionInterface* offer = NULL; |
| 1808 | SessionDescriptionInterface* answer = NULL; |
| 1809 | CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer); |
| 1810 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1811 | // the offer. |
| 1812 | SetLocalDescriptionWithoutError(offer); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1813 | SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1814 | } |
| 1815 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1816 | // Test that we accept an offer with a DTLS fingerprint when DTLS is on |
| 1817 | // and that we return an answer with a DTLS fingerprint. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1818 | TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1819 | SendAudioVideoStream1(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1820 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1821 | SetFactoryDtlsSrtp(); |
| 1822 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1823 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1824 | JsepSessionDescription* offer = |
| 1825 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1826 | ASSERT_TRUE(offer != NULL); |
| 1827 | VerifyFingerprintStatus(offer->description(), true); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1828 | VerifyNoCryptoParams(offer->description(), true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1829 | |
| 1830 | // SetRemoteDescription will take the ownership of the offer. |
| 1831 | SetRemoteDescriptionWithoutError(offer); |
| 1832 | |
| 1833 | // Verify that we get a crypto fingerprint in the answer. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1834 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1835 | ASSERT_TRUE(answer != NULL); |
| 1836 | VerifyFingerprintStatus(answer->description(), true); |
| 1837 | // Check that we don't have an a=crypto line in the answer. |
| 1838 | VerifyNoCryptoParams(answer->description(), true); |
| 1839 | |
| 1840 | // Now set the local description, which should work, even without a=crypto. |
| 1841 | SetLocalDescriptionWithoutError(answer); |
| 1842 | } |
| 1843 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1844 | // Test that we set a local offer with a DTLS fingerprint when DTLS is on |
| 1845 | // and then we accept a remote answer with a DTLS fingerprint successfully. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1846 | TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1847 | SendAudioVideoStream1(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1848 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1849 | SetFactoryDtlsSrtp(); |
| 1850 | |
| 1851 | // Verify that we get a crypto fingerprint in the answer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1852 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1853 | ASSERT_TRUE(offer != NULL); |
| 1854 | VerifyFingerprintStatus(offer->description(), true); |
| 1855 | // Check that we don't have an a=crypto line in the offer. |
| 1856 | VerifyNoCryptoParams(offer->description(), true); |
| 1857 | |
| 1858 | // Now set the local description, which should work, even without a=crypto. |
| 1859 | SetLocalDescriptionWithoutError(offer); |
| 1860 | |
| 1861 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1862 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1863 | JsepSessionDescription* answer = |
| 1864 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1865 | ASSERT_TRUE(answer != NULL); |
| 1866 | VerifyFingerprintStatus(answer->description(), true); |
| 1867 | VerifyNoCryptoParams(answer->description(), true); |
| 1868 | |
| 1869 | // SetRemoteDescription will take the ownership of the answer. |
| 1870 | SetRemoteDescriptionWithoutError(answer); |
| 1871 | } |
| 1872 | |
| 1873 | // Test that if we support DTLS and the other side didn't offer a fingerprint, |
| 1874 | // we will fail to set the remote description. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1875 | TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1876 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1877 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1878 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1879 | options.bundle_enabled = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1880 | JsepSessionDescription* offer = CreateRemoteOffer( |
| 1881 | options, cricket::SEC_REQUIRED); |
| 1882 | ASSERT_TRUE(offer != NULL); |
| 1883 | VerifyFingerprintStatus(offer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1884 | VerifyCryptoParams(offer->description()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1885 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1886 | // SetRemoteDescription will take the ownership of the offer. |
| 1887 | SetRemoteDescriptionOfferExpectError( |
| 1888 | kSdpWithoutDtlsFingerprint, offer); |
| 1889 | |
| 1890 | offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED); |
| 1891 | // SetLocalDescription will take the ownership of the offer. |
| 1892 | SetLocalDescriptionOfferExpectError( |
| 1893 | kSdpWithoutDtlsFingerprint, offer); |
| 1894 | } |
| 1895 | |
| 1896 | // Test that we return a failure when applying a local answer that doesn't have |
| 1897 | // a DTLS fingerprint when DTLS is required. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1898 | TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1899 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1900 | SessionDescriptionInterface* offer = NULL; |
| 1901 | SessionDescriptionInterface* answer = NULL; |
| 1902 | CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer); |
| 1903 | |
| 1904 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1905 | // the offer and answer. |
| 1906 | SetRemoteDescriptionWithoutError(offer); |
| 1907 | SetLocalDescriptionAnswerExpectError( |
| 1908 | kSdpWithoutDtlsFingerprint, answer); |
| 1909 | } |
| 1910 | |
| 1911 | // Test that we return a failure when applying a remote answer that doesn't have |
| 1912 | // a DTLS fingerprint when DTLS is required. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1913 | TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1914 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1915 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1916 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1917 | options.recv_video = true; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1918 | std::unique_ptr<SessionDescriptionInterface> temp_offer( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1919 | CreateRemoteOffer(options, cricket::SEC_ENABLED)); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1920 | JsepSessionDescription* answer = |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1921 | CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1922 | |
| 1923 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1924 | // the offer and answer. |
| 1925 | SetLocalDescriptionWithoutError(offer); |
| 1926 | SetRemoteDescriptionAnswerExpectError( |
| 1927 | kSdpWithoutDtlsFingerprint, answer); |
| 1928 | } |
| 1929 | |
| 1930 | // Test that we create a local offer without SDES or DTLS and accept a remote |
| 1931 | // answer without SDES or DTLS when encryption is disabled. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1932 | TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1933 | SendAudioVideoStream1(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1934 | options_.disable_encryption = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1935 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1936 | |
| 1937 | // Verify that we get a crypto fingerprint in the answer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1938 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1939 | ASSERT_TRUE(offer != NULL); |
| 1940 | VerifyFingerprintStatus(offer->description(), false); |
| 1941 | // Check that we don't have an a=crypto line in the offer. |
| 1942 | VerifyNoCryptoParams(offer->description(), false); |
| 1943 | |
| 1944 | // Now set the local description, which should work, even without a=crypto. |
| 1945 | SetLocalDescriptionWithoutError(offer); |
| 1946 | |
| 1947 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1948 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1949 | JsepSessionDescription* answer = |
| 1950 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1951 | ASSERT_TRUE(answer != NULL); |
| 1952 | VerifyFingerprintStatus(answer->description(), false); |
| 1953 | VerifyNoCryptoParams(answer->description(), false); |
| 1954 | |
| 1955 | // SetRemoteDescription will take the ownership of the answer. |
| 1956 | SetRemoteDescriptionWithoutError(answer); |
| 1957 | } |
| 1958 | |
| 1959 | // Test that we create a local answer without SDES or DTLS and accept a remote |
| 1960 | // offer without SDES or DTLS when encryption is disabled. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1961 | TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1962 | options_.disable_encryption = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 1963 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1964 | |
| 1965 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 1966 | options.recv_video = true; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1967 | JsepSessionDescription* offer = |
| 1968 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 1969 | ASSERT_TRUE(offer != NULL); |
| 1970 | VerifyFingerprintStatus(offer->description(), false); |
| 1971 | VerifyNoCryptoParams(offer->description(), false); |
| 1972 | |
| 1973 | // SetRemoteDescription will take the ownership of the offer. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1974 | SetRemoteDescriptionWithoutError(offer); |
| 1975 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1976 | // Verify that we get a crypto fingerprint in the answer. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1977 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1978 | ASSERT_TRUE(answer != NULL); |
| 1979 | VerifyFingerprintStatus(answer->description(), false); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1980 | // Check that we don't have an a=crypto line in the answer. |
| 1981 | VerifyNoCryptoParams(answer->description(), false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1982 | |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1983 | // Now set the local description, which should work, even without a=crypto. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1984 | SetLocalDescriptionWithoutError(answer); |
| 1985 | } |
| 1986 | |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1987 | // Test that we can create and set an answer correctly when different |
| 1988 | // SSL roles have been negotiated for different transports. |
| 1989 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525 |
| 1990 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) { |
| 1991 | SendAudioVideoStream1(); |
| 1992 | InitWithDtls(GetParam()); |
| 1993 | SetFactoryDtlsSrtp(); |
| 1994 | |
| 1995 | SessionDescriptionInterface* offer = CreateOffer(); |
| 1996 | SetLocalDescriptionWithoutError(offer); |
| 1997 | |
| 1998 | cricket::MediaSessionOptions options; |
| 1999 | options.recv_video = true; |
| 2000 | |
| 2001 | // First, negotiate different SSL roles. |
| 2002 | SessionDescriptionInterface* answer = |
| 2003 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 2004 | TransportInfo* audio_transport_info = |
| 2005 | answer->description()->GetTransportInfoByName("audio"); |
| 2006 | audio_transport_info->description.connection_role = |
| 2007 | cricket::CONNECTIONROLE_ACTIVE; |
| 2008 | TransportInfo* video_transport_info = |
| 2009 | answer->description()->GetTransportInfoByName("video"); |
| 2010 | video_transport_info->description.connection_role = |
| 2011 | cricket::CONNECTIONROLE_PASSIVE; |
| 2012 | SetRemoteDescriptionWithoutError(answer); |
| 2013 | |
| 2014 | // Now create an offer in the reverse direction, and ensure the initial |
| 2015 | // offerer responds with an answer with correct SSL roles. |
| 2016 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 2017 | kSessionVersion, |
| 2018 | session_->remote_description()); |
| 2019 | SetRemoteDescriptionWithoutError(offer); |
| 2020 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2021 | answer = CreateAnswer(); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 2022 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 2023 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 2024 | audio_transport_info->description.connection_role); |
| 2025 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 2026 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE, |
| 2027 | video_transport_info->description.connection_role); |
| 2028 | SetLocalDescriptionWithoutError(answer); |
| 2029 | |
| 2030 | // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of |
| 2031 | // audio is transferred over to video in the answer that completes the BUNDLE |
| 2032 | // negotiation. |
| 2033 | options.bundle_enabled = true; |
| 2034 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 2035 | kSessionVersion, |
| 2036 | session_->remote_description()); |
| 2037 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2038 | answer = CreateAnswer(); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 2039 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 2040 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 2041 | audio_transport_info->description.connection_role); |
| 2042 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 2043 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 2044 | video_transport_info->description.connection_role); |
| 2045 | SetLocalDescriptionWithoutError(answer); |
| 2046 | } |
| 2047 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2048 | TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2049 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2050 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2051 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2052 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2053 | SetLocalDescriptionWithoutError(offer); |
| 2054 | |
| 2055 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2056 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2057 | SetLocalDescriptionWithoutError(offer2); |
| 2058 | } |
| 2059 | |
| 2060 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2061 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2062 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2063 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2064 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2065 | SetRemoteDescriptionWithoutError(offer); |
| 2066 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2067 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2068 | SetRemoteDescriptionWithoutError(offer2); |
| 2069 | } |
| 2070 | |
| 2071 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2072 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2073 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2074 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2075 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2076 | offer = CreateOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2077 | SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER", |
| 2078 | offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2082 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2083 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2084 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2085 | SetRemoteDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2086 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2087 | SetLocalDescriptionOfferExpectError( |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2088 | "Called in wrong state: STATE_RECEIVEDOFFER", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
| 2091 | TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2092 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2093 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2094 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2095 | SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2096 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2097 | JsepSessionDescription* pranswer = |
| 2098 | static_cast<JsepSessionDescription*>(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2099 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2100 | SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2101 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2102 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2103 | JsepSessionDescription* pranswer2 = |
| 2104 | static_cast<JsepSessionDescription*>(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2105 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 2106 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2107 | SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2108 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2109 | SendAudioVideoStream2(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2110 | SessionDescriptionInterface* answer = CreateAnswer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2111 | SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2115 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2116 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2117 | SessionDescriptionInterface* offer = CreateOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2118 | SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2119 | |
| 2120 | JsepSessionDescription* pranswer = |
| 2121 | CreateRemoteAnswer(session_->local_description()); |
| 2122 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
| 2123 | |
| 2124 | SetRemoteDescriptionExpectState(pranswer, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2125 | WebRtcSession::STATE_RECEIVEDPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2126 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2127 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2128 | JsepSessionDescription* pranswer2 = |
| 2129 | CreateRemoteAnswer(session_->local_description()); |
| 2130 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 2131 | |
| 2132 | SetRemoteDescriptionExpectState(pranswer2, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2133 | WebRtcSession::STATE_RECEIVEDPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2134 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2135 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2136 | SessionDescriptionInterface* answer = |
| 2137 | CreateRemoteAnswer(session_->local_description()); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2138 | SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2142 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2143 | SendNothing(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2144 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2145 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2146 | SessionDescriptionInterface* answer = |
| 2147 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2148 | SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT", |
| 2149 | answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2150 | } |
| 2151 | |
| 2152 | TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2153 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2154 | SendNothing(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2155 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2156 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2157 | SessionDescriptionInterface* answer = |
| 2158 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2159 | SetRemoteDescriptionAnswerExpectError( |
| 2160 | "Called in wrong state: STATE_INIT", answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 2163 | // Tests that the remote candidates are added and removed successfully. |
| 2164 | TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2165 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2166 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2167 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 2168 | cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0, |
| 2169 | "", "", "host", 0, ""); |
| 2170 | candidate.set_transport_name("audio"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2171 | JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate); |
| 2172 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2173 | // Fail since we have not set a remote description. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2174 | EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2175 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2176 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2177 | SetLocalDescriptionWithoutError(offer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2178 | |
| 2179 | // Fail since we have not set a remote description. |
| 2180 | EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2181 | |
| 2182 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 2183 | session_->local_description()); |
| 2184 | SetRemoteDescriptionWithoutError(answer); |
| 2185 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2186 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2187 | candidate.set_component(2); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 2188 | candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000)); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2189 | JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate); |
| 2190 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2191 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2192 | // Verifying the candidates are copied properly from internal vector. |
| 2193 | const SessionDescriptionInterface* remote_desc = |
| 2194 | session_->remote_description(); |
| 2195 | ASSERT_TRUE(remote_desc != NULL); |
| 2196 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2197 | const IceCandidateCollection* candidates = |
| 2198 | remote_desc->candidates(kMediaContentIndex0); |
| 2199 | ASSERT_EQ(2u, candidates->count()); |
| 2200 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2201 | EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid()); |
| 2202 | EXPECT_EQ(1, candidates->at(0)->candidate().component()); |
| 2203 | EXPECT_EQ(2, candidates->at(1)->candidate().component()); |
| 2204 | |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 2205 | // |ice_candidate3| is identical to |ice_candidate2|. It can be added |
| 2206 | // successfully, but the total count of candidates will not increase. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2207 | candidate.set_component(2); |
| 2208 | JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate); |
| 2209 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3)); |
mallinath@webrtc.org | 67ee6b9 | 2014-02-03 16:57:16 +0000 | [diff] [blame] | 2210 | ASSERT_EQ(2u, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2211 | |
| 2212 | JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate); |
| 2213 | EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate)); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 2214 | |
| 2215 | // Remove candidate1 and candidate2 |
| 2216 | std::vector<cricket::Candidate> remote_candidates; |
| 2217 | remote_candidates.push_back(ice_candidate1.candidate()); |
| 2218 | remote_candidates.push_back(ice_candidate2.candidate()); |
| 2219 | EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates)); |
| 2220 | EXPECT_EQ(0u, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 2223 | // Tests that a remote candidate is added to the remote session description and |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2224 | // that it is retained if the remote session description is changed. |
| 2225 | TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2226 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2227 | cricket::Candidate candidate1; |
| 2228 | candidate1.set_component(1); |
| 2229 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 2230 | candidate1); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2231 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2232 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2233 | |
| 2234 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2235 | const SessionDescriptionInterface* remote_desc = |
| 2236 | session_->remote_description(); |
| 2237 | ASSERT_TRUE(remote_desc != NULL); |
| 2238 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2239 | const IceCandidateCollection* candidates = |
| 2240 | remote_desc->candidates(kMediaContentIndex0); |
| 2241 | ASSERT_EQ(1u, candidates->count()); |
| 2242 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2243 | |
| 2244 | // Update the RemoteSessionDescription with a new session description and |
| 2245 | // a candidate and check that the new remote session description contains both |
| 2246 | // candidates. |
| 2247 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2248 | cricket::Candidate candidate2; |
| 2249 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2250 | candidate2); |
| 2251 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate2)); |
| 2252 | SetRemoteDescriptionWithoutError(offer); |
| 2253 | |
| 2254 | remote_desc = session_->remote_description(); |
| 2255 | ASSERT_TRUE(remote_desc != NULL); |
| 2256 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2257 | candidates = remote_desc->candidates(kMediaContentIndex0); |
| 2258 | ASSERT_EQ(2u, candidates->count()); |
| 2259 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2260 | // Username and password have be updated with the TransportInfo of the |
| 2261 | // SessionDescription, won't be equal to the original one. |
| 2262 | candidate2.set_username(candidates->at(0)->candidate().username()); |
| 2263 | candidate2.set_password(candidates->at(0)->candidate().password()); |
| 2264 | EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate())); |
| 2265 | EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index()); |
| 2266 | // No need to verify the username and password. |
| 2267 | candidate1.set_username(candidates->at(1)->candidate().username()); |
| 2268 | candidate1.set_password(candidates->at(1)->candidate().password()); |
| 2269 | EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate())); |
| 2270 | |
| 2271 | // Test that the candidate is ignored if we can add the same candidate again. |
| 2272 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2273 | } |
| 2274 | |
| 2275 | // Test that local candidates are added to the local session description and |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 2276 | // that they are retained if the local session description is changed. And if |
| 2277 | // continual gathering is enabled, they are removed from the local session |
| 2278 | // description when the network is down. |
| 2279 | TEST_F(WebRtcSessionTest, |
| 2280 | TestLocalCandidatesAddedAndRemovedIfGatherContinually) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2281 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2282 | Init(); |
deadbeef | b60a819 | 2016-08-24 15:15:00 -0700 | [diff] [blame] | 2283 | // Enable Continual Gathering. |
| 2284 | cricket::IceConfig config; |
| 2285 | config.continual_gathering_policy = cricket::GATHER_CONTINUALLY; |
| 2286 | session_->SetIceConfig(config); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2287 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2288 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2289 | |
| 2290 | const SessionDescriptionInterface* local_desc = session_->local_description(); |
| 2291 | const IceCandidateCollection* candidates = |
| 2292 | local_desc->candidates(kMediaContentIndex0); |
| 2293 | ASSERT_TRUE(candidates != NULL); |
| 2294 | EXPECT_EQ(0u, candidates->count()); |
| 2295 | |
deadbeef | b60a819 | 2016-08-24 15:15:00 -0700 | [diff] [blame] | 2296 | // Since we're using continual gathering, we won't get "gathering done". |
| 2297 | EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2298 | |
| 2299 | local_desc = session_->local_description(); |
| 2300 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 2301 | ASSERT_TRUE(candidates != NULL); |
| 2302 | EXPECT_LT(0u, candidates->count()); |
| 2303 | candidates = local_desc->candidates(1); |
| 2304 | ASSERT_TRUE(candidates != NULL); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2305 | EXPECT_EQ(0u, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2306 | |
| 2307 | // Update the session descriptions. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2308 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2309 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2310 | |
| 2311 | local_desc = session_->local_description(); |
| 2312 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 2313 | ASSERT_TRUE(candidates != NULL); |
| 2314 | EXPECT_LT(0u, candidates->count()); |
| 2315 | candidates = local_desc->candidates(1); |
| 2316 | ASSERT_TRUE(candidates != NULL); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2317 | EXPECT_EQ(0u, candidates->count()); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 2318 | |
| 2319 | candidates = local_desc->candidates(kMediaContentIndex0); |
| 2320 | size_t num_local_candidates = candidates->count(); |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 2321 | // Bring down the network interface to trigger candidate removals. |
| 2322 | RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 2323 | // Verify that all local candidates are removed. |
| 2324 | EXPECT_EQ(0, observer_.num_candidates_removed_); |
| 2325 | EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_, |
| 2326 | kIceCandidatesTimeout); |
| 2327 | EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout); |
| 2328 | } |
| 2329 | |
| 2330 | // Tests that if continual gathering is disabled, local candidates won't be |
| 2331 | // removed when the interface is turned down. |
| 2332 | TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) { |
| 2333 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 2334 | Init(); |
| 2335 | SendAudioVideoStream1(); |
| 2336 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2337 | |
| 2338 | const SessionDescriptionInterface* local_desc = session_->local_description(); |
| 2339 | const IceCandidateCollection* candidates = |
| 2340 | local_desc->candidates(kMediaContentIndex0); |
| 2341 | ASSERT_TRUE(candidates != NULL); |
| 2342 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 2343 | |
| 2344 | size_t num_local_candidates = candidates->count(); |
| 2345 | EXPECT_LT(0u, num_local_candidates); |
| 2346 | // By default, Continual Gathering is disabled. |
| 2347 | // Bring down the network interface. |
| 2348 | RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 2349 | // Verify that the local candidates are not removed. |
| 2350 | rtc::Thread::Current()->ProcessMessages(1000); |
| 2351 | EXPECT_EQ(0, observer_.num_candidates_removed_); |
| 2352 | EXPECT_EQ(num_local_candidates, candidates->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | // Test that we can set a remote session description with remote candidates. |
| 2356 | TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2357 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2358 | |
| 2359 | cricket::Candidate candidate1; |
| 2360 | candidate1.set_component(1); |
| 2361 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 2362 | candidate1); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2363 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2364 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2365 | |
| 2366 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 2367 | SetRemoteDescriptionWithoutError(offer); |
| 2368 | |
| 2369 | const SessionDescriptionInterface* remote_desc = |
| 2370 | session_->remote_description(); |
| 2371 | ASSERT_TRUE(remote_desc != NULL); |
| 2372 | ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2373 | const IceCandidateCollection* candidates = |
| 2374 | remote_desc->candidates(kMediaContentIndex0); |
| 2375 | ASSERT_EQ(1u, candidates->count()); |
| 2376 | EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2377 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2378 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2379 | SetLocalDescriptionWithoutError(answer); |
| 2380 | } |
| 2381 | |
| 2382 | // Test that offers and answers contains ice candidates when Ice candidates have |
| 2383 | // been gathered. |
| 2384 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2385 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2386 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2387 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2388 | // Ice is started but candidates are not provided until SetLocalDescription |
| 2389 | // is called. |
| 2390 | EXPECT_EQ(0u, observer_.mline_0_candidates_.size()); |
| 2391 | EXPECT_EQ(0u, observer_.mline_1_candidates_.size()); |
| 2392 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2393 | // Wait until at least one local candidate has been collected. |
| 2394 | EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(), |
| 2395 | kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2396 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2397 | std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2398 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2399 | ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL); |
| 2400 | EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2401 | |
| 2402 | SessionDescriptionInterface* remote_offer(CreateRemoteOffer()); |
| 2403 | SetRemoteDescriptionWithoutError(remote_offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2404 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2405 | ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL); |
| 2406 | EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2407 | SetLocalDescriptionWithoutError(answer); |
| 2408 | } |
| 2409 | |
| 2410 | // Verifies TransportProxy and media channels are created with content names |
| 2411 | // present in the SessionDescription. |
| 2412 | TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2413 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2414 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2415 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2416 | |
| 2417 | // CreateOffer creates session description with the content names "audio" and |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2418 | // "video". Goal is to modify these content names and verify transport |
| 2419 | // channels |
| 2420 | // in the WebRtcSession, as channels are created with the content names |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2421 | // present in SDP. |
| 2422 | std::string sdp; |
| 2423 | EXPECT_TRUE(offer->ToString(&sdp)); |
| 2424 | const std::string kAudioMid = "a=mid:audio"; |
| 2425 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
| 2426 | const std::string kVideoMid = "a=mid:video"; |
| 2427 | const std::string kVideoMidReplaceStr = "a=mid:video_content_name"; |
| 2428 | |
| 2429 | // Replacing |audio| with |audio_content_name|. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2430 | rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2431 | kAudioMidReplaceStr.c_str(), |
| 2432 | kAudioMidReplaceStr.length(), |
| 2433 | &sdp); |
| 2434 | // Replacing |video| with |video_content_name|. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2435 | rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2436 | kVideoMidReplaceStr.c_str(), |
| 2437 | kVideoMidReplaceStr.length(), |
| 2438 | &sdp); |
| 2439 | |
| 2440 | SessionDescriptionInterface* modified_offer = |
| 2441 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 2442 | |
| 2443 | SetRemoteDescriptionWithoutError(modified_offer); |
| 2444 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2445 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2446 | SetLocalDescriptionWithoutError(answer); |
| 2447 | |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 2448 | rtc::PacketTransportInterface* voice_transport_channel = |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2449 | session_->voice_rtp_transport_channel(); |
| 2450 | EXPECT_TRUE(voice_transport_channel != NULL); |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 2451 | EXPECT_EQ(voice_transport_channel->debug_name(), |
| 2452 | "audio_content_name " + |
| 2453 | std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
| 2454 | rtc::PacketTransportInterface* video_transport_channel = |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2455 | session_->video_rtp_transport_channel(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2456 | ASSERT_TRUE(video_transport_channel != NULL); |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 2457 | EXPECT_EQ(video_transport_channel->debug_name(), |
| 2458 | "video_content_name " + |
| 2459 | std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2460 | EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL); |
| 2461 | EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL); |
| 2462 | } |
| 2463 | |
| 2464 | // Test that an offer contains the correct media content descriptions based on |
| 2465 | // the send streams when no constraints have been set. |
| 2466 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2467 | Init(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2468 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2469 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2470 | ASSERT_TRUE(offer != NULL); |
| 2471 | const cricket::ContentInfo* content = |
| 2472 | cricket::GetFirstAudioContent(offer->description()); |
| 2473 | EXPECT_TRUE(content != NULL); |
| 2474 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2475 | EXPECT_TRUE(content == NULL); |
| 2476 | } |
| 2477 | |
| 2478 | // Test that an offer contains the correct media content descriptions based on |
| 2479 | // the send streams when no constraints have been set. |
| 2480 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2481 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2482 | // Test Audio only offer. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2483 | SendAudioOnlyStream2(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2484 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2485 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2486 | const cricket::ContentInfo* content = |
| 2487 | cricket::GetFirstAudioContent(offer->description()); |
| 2488 | EXPECT_TRUE(content != NULL); |
| 2489 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2490 | EXPECT_TRUE(content == NULL); |
| 2491 | |
| 2492 | // Test Audio / Video offer. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2493 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2494 | offer.reset(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2495 | content = cricket::GetFirstAudioContent(offer->description()); |
| 2496 | EXPECT_TRUE(content != NULL); |
| 2497 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2498 | EXPECT_TRUE(content != NULL); |
| 2499 | } |
| 2500 | |
| 2501 | // Test that an offer contains no media content descriptions if |
| 2502 | // kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false. |
| 2503 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2504 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2505 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2506 | options.offer_to_receive_audio = 0; |
| 2507 | options.offer_to_receive_video = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2508 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2509 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2510 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2511 | ASSERT_TRUE(offer != NULL); |
| 2512 | const cricket::ContentInfo* content = |
| 2513 | cricket::GetFirstAudioContent(offer->description()); |
| 2514 | EXPECT_TRUE(content == NULL); |
| 2515 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2516 | EXPECT_TRUE(content == NULL); |
| 2517 | } |
| 2518 | |
| 2519 | // Test that an offer contains only audio media content descriptions if |
| 2520 | // kOfferToReceiveAudio constraints are set to true. |
| 2521 | TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2522 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2523 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2524 | options.offer_to_receive_audio = |
| 2525 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2526 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2527 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2528 | |
| 2529 | const cricket::ContentInfo* content = |
| 2530 | cricket::GetFirstAudioContent(offer->description()); |
| 2531 | EXPECT_TRUE(content != NULL); |
| 2532 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2533 | EXPECT_TRUE(content == NULL); |
| 2534 | } |
| 2535 | |
| 2536 | // Test that an offer contains audio and video media content descriptions if |
| 2537 | // kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true. |
| 2538 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2539 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2540 | // Test Audio / Video offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2541 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2542 | options.offer_to_receive_audio = |
| 2543 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2544 | options.offer_to_receive_video = |
| 2545 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2546 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2547 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2548 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2549 | const cricket::ContentInfo* content = |
| 2550 | cricket::GetFirstAudioContent(offer->description()); |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 2551 | EXPECT_TRUE(content != NULL); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 2552 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2553 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2554 | EXPECT_TRUE(content != NULL); |
| 2555 | |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 2556 | // Sets constraints to false and verifies that audio/video contents are |
| 2557 | // removed. |
| 2558 | options.offer_to_receive_audio = 0; |
| 2559 | options.offer_to_receive_video = 0; |
| 2560 | offer.reset(CreateOffer(options)); |
| 2561 | |
| 2562 | content = cricket::GetFirstAudioContent(offer->description()); |
| 2563 | EXPECT_TRUE(content == NULL); |
| 2564 | content = cricket::GetFirstVideoContent(offer->description()); |
| 2565 | EXPECT_TRUE(content == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | // Test that an answer can not be created if the last remote description is not |
| 2569 | // an offer. |
| 2570 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2571 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2572 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2573 | SetLocalDescriptionWithoutError(offer); |
| 2574 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2575 | SetRemoteDescriptionWithoutError(answer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2576 | EXPECT_TRUE(CreateAnswer() == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | // Test that an answer contains the correct media content descriptions when no |
| 2580 | // constraints have been set. |
| 2581 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2582 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2583 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2584 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2585 | SetRemoteDescriptionWithoutError(offer.release()); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2586 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2587 | const cricket::ContentInfo* content = |
| 2588 | cricket::GetFirstAudioContent(answer->description()); |
| 2589 | ASSERT_TRUE(content != NULL); |
| 2590 | EXPECT_FALSE(content->rejected); |
| 2591 | |
| 2592 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2593 | ASSERT_TRUE(content != NULL); |
| 2594 | EXPECT_FALSE(content->rejected); |
| 2595 | } |
| 2596 | |
| 2597 | // Test that an answer contains the correct media content descriptions when no |
| 2598 | // constraints have been set and the offer only contain audio. |
| 2599 | TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2600 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2601 | // Create a remote offer with audio only. |
| 2602 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 2603 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2604 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2605 | ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL); |
| 2606 | ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL); |
| 2607 | |
| 2608 | SetRemoteDescriptionWithoutError(offer.release()); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2609 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2610 | const cricket::ContentInfo* content = |
| 2611 | cricket::GetFirstAudioContent(answer->description()); |
| 2612 | ASSERT_TRUE(content != NULL); |
| 2613 | EXPECT_FALSE(content->rejected); |
| 2614 | |
| 2615 | EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL); |
| 2616 | } |
| 2617 | |
| 2618 | // Test that an answer contains the correct media content descriptions when no |
| 2619 | // constraints have been set. |
| 2620 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2621 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2622 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2623 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2624 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2625 | // Test with a stream with tracks. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2626 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2627 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2628 | const cricket::ContentInfo* content = |
| 2629 | cricket::GetFirstAudioContent(answer->description()); |
| 2630 | ASSERT_TRUE(content != NULL); |
| 2631 | EXPECT_FALSE(content->rejected); |
| 2632 | |
| 2633 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2634 | ASSERT_TRUE(content != NULL); |
| 2635 | EXPECT_FALSE(content->rejected); |
| 2636 | } |
| 2637 | |
| 2638 | // Test that an answer contains the correct media content descriptions when |
| 2639 | // constraints have been set but no stream is sent. |
| 2640 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2641 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2642 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2643 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2644 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2645 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2646 | cricket::MediaSessionOptions session_options; |
| 2647 | session_options.recv_audio = false; |
| 2648 | session_options.recv_video = false; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2649 | std::unique_ptr<SessionDescriptionInterface> answer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2650 | CreateAnswer(session_options)); |
| 2651 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2652 | const cricket::ContentInfo* content = |
| 2653 | cricket::GetFirstAudioContent(answer->description()); |
| 2654 | ASSERT_TRUE(content != NULL); |
| 2655 | EXPECT_TRUE(content->rejected); |
| 2656 | |
| 2657 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2658 | ASSERT_TRUE(content != NULL); |
| 2659 | EXPECT_TRUE(content->rejected); |
| 2660 | } |
| 2661 | |
| 2662 | // Test that an answer contains the correct media content descriptions when |
| 2663 | // constraints have been set and streams are sent. |
| 2664 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2665 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2666 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2667 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2668 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2669 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2670 | cricket::MediaSessionOptions options; |
| 2671 | options.recv_audio = false; |
| 2672 | options.recv_video = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2673 | |
| 2674 | // Test with a stream with tracks. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2675 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2676 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2677 | |
| 2678 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 2679 | const cricket::ContentInfo* content = |
| 2680 | cricket::GetFirstAudioContent(answer->description()); |
| 2681 | ASSERT_TRUE(content != NULL); |
| 2682 | EXPECT_FALSE(content->rejected); |
| 2683 | |
| 2684 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 2685 | content = cricket::GetFirstVideoContent(answer->description()); |
| 2686 | ASSERT_TRUE(content != NULL); |
| 2687 | EXPECT_FALSE(content->rejected); |
| 2688 | } |
| 2689 | |
| 2690 | TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) { |
| 2691 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2692 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2693 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2694 | options.offer_to_receive_audio = |
| 2695 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 2696 | options.voice_activity_detection = false; |
| 2697 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2698 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2699 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2700 | const cricket::ContentInfo* content = |
| 2701 | cricket::GetFirstAudioContent(offer->description()); |
| 2702 | EXPECT_TRUE(content != NULL); |
| 2703 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 2704 | } |
| 2705 | |
| 2706 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) { |
| 2707 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2708 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2709 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2710 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2711 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2712 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2713 | cricket::MediaSessionOptions options; |
| 2714 | options.vad_enabled = false; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2715 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2716 | const cricket::ContentInfo* content = |
| 2717 | cricket::GetFirstAudioContent(answer->description()); |
| 2718 | ASSERT_TRUE(content != NULL); |
| 2719 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 2720 | } |
| 2721 | |
| 2722 | // This test verifies the call setup when remote answer with audio only and |
| 2723 | // later updates with video. |
| 2724 | TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2725 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2726 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2727 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 2728 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2729 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2730 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2731 | |
| 2732 | cricket::MediaSessionOptions options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2733 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options); |
| 2734 | |
| 2735 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2736 | // and answer; |
| 2737 | SetLocalDescriptionWithoutError(offer); |
| 2738 | SetRemoteDescriptionWithoutError(answer); |
| 2739 | |
| 2740 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2741 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2742 | |
| 2743 | ASSERT_TRUE(video_channel_ == NULL); |
| 2744 | |
| 2745 | ASSERT_EQ(0u, voice_channel_->recv_streams().size()); |
| 2746 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2747 | EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id); |
| 2748 | |
| 2749 | // Let the remote end update the session descriptions, with Audio and Video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2750 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2751 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2752 | |
| 2753 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2754 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2755 | |
| 2756 | ASSERT_TRUE(video_channel_ != NULL); |
| 2757 | ASSERT_TRUE(voice_channel_ != NULL); |
| 2758 | |
| 2759 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2760 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2761 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2762 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2763 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2764 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2765 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2766 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2767 | |
| 2768 | // Change session back to audio only. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2769 | SendAudioOnlyStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2770 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2771 | |
| 2772 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 2773 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2774 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2775 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2776 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2777 | } |
| 2778 | |
| 2779 | // This test verifies the call setup when remote answer with video only and |
| 2780 | // later updates with audio. |
| 2781 | TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2782 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2783 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2784 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2785 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2786 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2787 | |
| 2788 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 2789 | options.recv_audio = false; |
| 2790 | options.recv_video = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2791 | SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 2792 | offer, options, cricket::SEC_ENABLED); |
| 2793 | |
| 2794 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2795 | // and answer. |
| 2796 | SetLocalDescriptionWithoutError(offer); |
| 2797 | SetRemoteDescriptionWithoutError(answer); |
| 2798 | |
| 2799 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2800 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2801 | |
| 2802 | ASSERT_TRUE(voice_channel_ == NULL); |
| 2803 | ASSERT_TRUE(video_channel_ != NULL); |
| 2804 | |
| 2805 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 2806 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2807 | EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id); |
| 2808 | |
| 2809 | // Update the session descriptions, with Audio and Video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2810 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2811 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2812 | |
| 2813 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2814 | ASSERT_TRUE(voice_channel_ != NULL); |
| 2815 | |
| 2816 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2817 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2818 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2819 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2820 | |
| 2821 | // Change session back to video only. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2822 | SendVideoOnlyStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2823 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2824 | |
| 2825 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2826 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2827 | |
| 2828 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2829 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2830 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2831 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2832 | } |
| 2833 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2834 | TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2835 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2836 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2837 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2838 | VerifyCryptoParams(offer->description()); |
| 2839 | SetRemoteDescriptionWithoutError(offer.release()); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2840 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2841 | VerifyCryptoParams(answer->description()); |
| 2842 | } |
| 2843 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 2844 | TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) { |
| 2845 | InitWithGcm(); |
| 2846 | SendAudioVideoStream1(); |
| 2847 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2848 | VerifyCryptoParams(offer->description(), true); |
| 2849 | SetRemoteDescriptionWithoutError(offer.release()); |
| 2850 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
| 2851 | VerifyCryptoParams(answer->description(), true); |
| 2852 | } |
| 2853 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2854 | TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2855 | options_.disable_encryption = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2856 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2857 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2858 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2859 | VerifyNoCryptoParams(offer->description(), false); |
| 2860 | } |
| 2861 | |
| 2862 | TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2863 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2864 | VerifyAnswerFromNonCryptoOffer(); |
| 2865 | } |
| 2866 | |
| 2867 | TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2868 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2869 | VerifyAnswerFromCryptoOffer(); |
| 2870 | } |
| 2871 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2872 | // This test verifies that setLocalDescription fails if |
| 2873 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2874 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2875 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2876 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2877 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2878 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2879 | std::string sdp; |
| 2880 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2881 | SessionDescriptionInterface* modified_offer = |
| 2882 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2883 | SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | // This test verifies that setRemoteDescription fails if |
| 2887 | // no a=ice-ufrag and a=ice-pwd lines are present in the SDP. |
| 2888 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2889 | Init(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2890 | std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2891 | std::string sdp; |
| 2892 | RemoveIceUfragPwdLines(offer.get(), &sdp); |
| 2893 | SessionDescriptionInterface* modified_offer = |
| 2894 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2895 | SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2896 | } |
| 2897 | |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2898 | // This test verifies that setLocalDescription fails if local offer has |
| 2899 | // too short ice ufrag and pwd strings. |
| 2900 | TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2901 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2902 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2903 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2904 | // Modifying ice ufrag and pwd in local offer with strings smaller than the |
| 2905 | // recommended values of 4 and 22 bytes respectively. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2906 | SetIceUfragPwd(offer.get(), "ice", "icepwd"); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2907 | std::string error; |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2908 | EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error)); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2909 | |
| 2910 | // Test with string greater than 256. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2911 | offer.reset(CreateOffer()); |
| 2912 | SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd); |
| 2913 | EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error)); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2914 | } |
| 2915 | |
| 2916 | // This test verifies that setRemoteDescription fails if remote offer has |
| 2917 | // too short ice ufrag and pwd strings. |
| 2918 | TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2919 | Init(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2920 | std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2921 | // Modifying ice ufrag and pwd in remote offer with strings smaller than the |
| 2922 | // recommended values of 4 and 22 bytes respectively. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2923 | SetIceUfragPwd(offer.get(), "ice", "icepwd"); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2924 | std::string error; |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2925 | EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error)); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2926 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2927 | offer.reset(CreateRemoteOffer()); |
| 2928 | SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd); |
| 2929 | EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error)); |
buildbot@webrtc.org | 7aa1a47 | 2014-05-23 17:33:05 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2932 | // Test that if the remote offer indicates the peer requested ICE restart (via |
| 2933 | // a new ufrag or pwd), the old ICE candidates are not copied, and vice versa. |
| 2934 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) { |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2935 | Init(); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2936 | |
| 2937 | // Create the first offer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2938 | std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2939 | SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx"); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2940 | cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), |
| 2941 | 0, "", "", "relay", 0, ""); |
| 2942 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 2943 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2944 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate1)); |
| 2945 | SetRemoteDescriptionWithoutError(offer.release()); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2946 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 2947 | |
| 2948 | // The second offer has the same ufrag and pwd but different address. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2949 | offer.reset(CreateRemoteOffer()); |
| 2950 | SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx"); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2951 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 2952 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2953 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2954 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate2)); |
| 2955 | SetRemoteDescriptionWithoutError(offer.release()); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2956 | EXPECT_EQ(2, session_->remote_description()->candidates(0)->count()); |
| 2957 | |
| 2958 | // The third offer has a different ufrag and different address. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2959 | offer.reset(CreateRemoteOffer()); |
| 2960 | SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx"); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2961 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000)); |
| 2962 | JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0, |
| 2963 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2964 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate3)); |
| 2965 | SetRemoteDescriptionWithoutError(offer.release()); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2966 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 2967 | |
| 2968 | // The fourth offer has no candidate but a different ufrag/pwd. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2969 | offer.reset(CreateRemoteOffer()); |
| 2970 | SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz"); |
| 2971 | SetRemoteDescriptionWithoutError(offer.release()); |
honghaiz | 503726c | 2015-07-31 12:37:38 -0700 | [diff] [blame] | 2972 | EXPECT_EQ(0, session_->remote_description()->candidates(0)->count()); |
| 2973 | } |
| 2974 | |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2975 | // Test that if the remote answer indicates the peer requested ICE restart (via |
| 2976 | // a new ufrag or pwd), the old ICE candidates are not copied, and vice versa. |
| 2977 | TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) { |
| 2978 | Init(); |
| 2979 | SessionDescriptionInterface* offer = CreateOffer(); |
| 2980 | SetLocalDescriptionWithoutError(offer); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2981 | |
| 2982 | // Create the first answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2983 | std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer)); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2984 | answer->set_type(JsepSessionDescription::kPrAnswer); |
| 2985 | SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx"); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2986 | cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), |
| 2987 | 0, "", "", "relay", 0, ""); |
| 2988 | JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 2989 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2990 | EXPECT_TRUE(answer->AddCandidate(&ice_candidate1)); |
| 2991 | SetRemoteDescriptionWithoutError(answer.release()); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2992 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 2993 | |
| 2994 | // The second answer has the same ufrag and pwd but different address. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 2995 | answer.reset(CreateRemoteAnswer(offer)); |
| 2996 | answer->set_type(JsepSessionDescription::kPrAnswer); |
| 2997 | SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx"); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 2998 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 2999 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 3000 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3001 | EXPECT_TRUE(answer->AddCandidate(&ice_candidate2)); |
| 3002 | SetRemoteDescriptionWithoutError(answer.release()); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 3003 | EXPECT_EQ(2, session_->remote_description()->candidates(0)->count()); |
| 3004 | |
| 3005 | // The third answer has a different ufrag and different address. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3006 | answer.reset(CreateRemoteAnswer(offer)); |
| 3007 | answer->set_type(JsepSessionDescription::kPrAnswer); |
| 3008 | SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx"); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 3009 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000)); |
| 3010 | JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0, |
| 3011 | candidate1); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3012 | EXPECT_TRUE(answer->AddCandidate(&ice_candidate3)); |
| 3013 | SetRemoteDescriptionWithoutError(answer.release()); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 3014 | EXPECT_EQ(1, session_->remote_description()->candidates(0)->count()); |
| 3015 | |
| 3016 | // The fourth answer has no candidate but a different ufrag/pwd. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3017 | answer.reset(CreateRemoteAnswer(offer)); |
| 3018 | answer->set_type(JsepSessionDescription::kPrAnswer); |
| 3019 | SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz"); |
| 3020 | SetRemoteDescriptionWithoutError(answer.release()); |
Honghai Zhang | 04e9146 | 2015-12-11 14:26:22 -0800 | [diff] [blame] | 3021 | EXPECT_EQ(0, session_->remote_description()->candidates(0)->count()); |
| 3022 | } |
| 3023 | |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3024 | // Test that candidates sent to the "video" transport do not get pushed down to |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3025 | // the "audio" transport channel when bundling. |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3026 | TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) { |
| 3027 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 3028 | |
| 3029 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3030 | SendAudioVideoStream1(); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3031 | |
| 3032 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3033 | options.use_rtp_mux = true; |
| 3034 | |
| 3035 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3036 | SetRemoteDescriptionWithoutError(offer); |
| 3037 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3038 | SessionDescriptionInterface* answer = CreateAnswer(); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3039 | SetLocalDescriptionWithoutError(answer); |
| 3040 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3041 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3042 | session_->video_rtp_transport_channel()); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3043 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3044 | cricket::BaseChannel* voice_channel = session_->voice_channel(); |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 3045 | ASSERT_TRUE(voice_channel != NULL); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3046 | |
| 3047 | // Checks if one of the transport channels contains a connection using a given |
| 3048 | // port. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3049 | auto connection_with_remote_port = [this, voice_channel](int port) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 3050 | std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s(); |
| 3051 | for (auto& kv : stats->transport_stats) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3052 | for (auto& chan_stat : kv.second.channel_stats) { |
| 3053 | for (auto& conn_info : chan_stat.connection_infos) { |
| 3054 | if (conn_info.remote_candidate.address().port() == port) { |
| 3055 | return true; |
| 3056 | } |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 3057 | } |
| 3058 | } |
| 3059 | } |
| 3060 | return false; |
| 3061 | }; |
| 3062 | |
| 3063 | EXPECT_FALSE(connection_with_remote_port(5000)); |
| 3064 | EXPECT_FALSE(connection_with_remote_port(5001)); |
| 3065 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 3066 | |
| 3067 | // The way the *_WAIT checks work is they only wait if the condition fails, |
| 3068 | // which does not help in the case where state is not changing. This is |
| 3069 | // problematic in this test since we want to verify that adding a video |
| 3070 | // candidate does _not_ change state. So we interleave candidates and assume |
| 3071 | // that messages are executed in the order they were posted. |
| 3072 | |
| 3073 | // First audio candidate. |
| 3074 | cricket::Candidate candidate0; |
| 3075 | candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
| 3076 | candidate0.set_component(1); |
| 3077 | candidate0.set_protocol("udp"); |
| 3078 | JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0, |
| 3079 | candidate0); |
| 3080 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0)); |
| 3081 | |
| 3082 | // Video candidate. |
| 3083 | cricket::Candidate candidate1; |
| 3084 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 3085 | candidate1.set_component(1); |
| 3086 | candidate1.set_protocol("udp"); |
| 3087 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 3088 | candidate1); |
| 3089 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 3090 | |
| 3091 | // Second audio candidate. |
| 3092 | cricket::Candidate candidate2; |
| 3093 | candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001)); |
| 3094 | candidate2.set_component(1); |
| 3095 | candidate2.set_protocol("udp"); |
| 3096 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 3097 | candidate2); |
| 3098 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 3099 | |
| 3100 | EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000); |
| 3101 | EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000); |
| 3102 | |
| 3103 | // No need here for a _WAIT check since we are checking that state hasn't |
| 3104 | // changed: if this is false we would be doing waits for nothing and if this |
| 3105 | // is true then there will be no messages processed anyways. |
| 3106 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 3107 | } |
| 3108 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3109 | // kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3110 | TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) { |
| 3111 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3112 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3113 | |
| 3114 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3115 | options.use_rtp_mux = true; |
| 3116 | |
| 3117 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3118 | SetLocalDescriptionWithoutError(offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3119 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3120 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3121 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3122 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3123 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3124 | SessionDescriptionInterface* answer = |
| 3125 | CreateRemoteAnswer(session_->local_description()); |
| 3126 | SetRemoteDescriptionWithoutError(answer); |
| 3127 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3128 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3129 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3130 | } |
| 3131 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3132 | // kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3133 | TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) { |
| 3134 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3135 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3136 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3137 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3138 | options.use_rtp_mux = true; |
| 3139 | |
| 3140 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3141 | SetLocalDescriptionWithoutError(offer); |
| 3142 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3143 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3144 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3145 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3146 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3147 | |
| 3148 | // Remove BUNDLE from the answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3149 | std::unique_ptr<SessionDescriptionInterface> answer( |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3150 | CreateRemoteAnswer(session_->local_description())); |
| 3151 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3152 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 3153 | JsepSessionDescription* modified_answer = |
| 3154 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 3155 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 3156 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 3157 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3158 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3159 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer. |
| 3163 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) { |
| 3164 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3165 | SendAudioVideoStream1(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3166 | |
| 3167 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3168 | options.use_rtp_mux = true; |
| 3169 | |
| 3170 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3171 | SetLocalDescriptionWithoutError(offer); |
| 3172 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3173 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3174 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3175 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3176 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3177 | SessionDescriptionInterface* answer = |
| 3178 | CreateRemoteAnswer(session_->local_description()); |
| 3179 | SetRemoteDescriptionWithoutError(answer); |
| 3180 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3181 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3182 | session_->video_rtp_transport_channel()); |
| 3183 | } |
| 3184 | |
| 3185 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no |
| 3186 | // audio content in the answer. |
| 3187 | TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) { |
| 3188 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3189 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3190 | |
| 3191 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3192 | options.use_rtp_mux = true; |
| 3193 | |
| 3194 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3195 | SetLocalDescriptionWithoutError(offer); |
| 3196 | |
| 3197 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3198 | session_->video_rtp_transport_channel()); |
| 3199 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3200 | SendAudioVideoStream2(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3201 | cricket::MediaSessionOptions recv_options; |
| 3202 | recv_options.recv_audio = false; |
| 3203 | recv_options.recv_video = true; |
| 3204 | SessionDescriptionInterface* answer = |
| 3205 | CreateRemoteAnswer(session_->local_description(), recv_options); |
| 3206 | SetRemoteDescriptionWithoutError(answer); |
| 3207 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3208 | EXPECT_TRUE(nullptr == session_->voice_channel()); |
| 3209 | EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3210 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3211 | session_->Close(); |
| 3212 | EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel()); |
| 3213 | EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel()); |
| 3214 | EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel()); |
| 3215 | EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | // kBundlePolicyMaxBundle policy but no BUNDLE in the answer. |
| 3219 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) { |
| 3220 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3221 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3222 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3223 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3224 | options.use_rtp_mux = true; |
| 3225 | |
| 3226 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3227 | SetLocalDescriptionWithoutError(offer); |
| 3228 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3229 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3230 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3231 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3232 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3233 | |
| 3234 | // Remove BUNDLE from the answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3235 | std::unique_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3236 | CreateRemoteAnswer(session_->local_description())); |
| 3237 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3238 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 3239 | JsepSessionDescription* modified_answer = |
| 3240 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 3241 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 3242 | SetRemoteDescriptionWithoutError(modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3243 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3244 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3245 | session_->video_rtp_transport_channel()); |
| 3246 | } |
| 3247 | |
| 3248 | // kBundlePolicyMaxBundle policy with BUNDLE in the remote offer. |
| 3249 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) { |
| 3250 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3251 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3252 | |
| 3253 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3254 | SetRemoteDescriptionWithoutError(offer); |
| 3255 | |
| 3256 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3257 | session_->video_rtp_transport_channel()); |
| 3258 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3259 | SendAudioVideoStream2(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3260 | SessionDescriptionInterface* answer = CreateAnswer(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3261 | SetLocalDescriptionWithoutError(answer); |
| 3262 | |
| 3263 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3264 | session_->video_rtp_transport_channel()); |
| 3265 | } |
| 3266 | |
| 3267 | // kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer. |
| 3268 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) { |
| 3269 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3270 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3271 | |
| 3272 | // Remove BUNDLE from the offer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3273 | std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3274 | cricket::SessionDescription* offer_copy = offer->description()->Copy(); |
| 3275 | offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 3276 | JsepSessionDescription* modified_offer = |
| 3277 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 3278 | modified_offer->Initialize(offer_copy, "1", "1"); |
| 3279 | |
| 3280 | // Expect an error when applying the remote description |
| 3281 | SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer, |
| 3282 | kCreateChannelFailed, modified_offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3283 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3284 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3285 | // kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3286 | TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) { |
| 3287 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3288 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3289 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3290 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3291 | options.use_rtp_mux = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3292 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3293 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3294 | SetLocalDescriptionWithoutError(offer); |
| 3295 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3296 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3297 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3298 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3299 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3300 | SessionDescriptionInterface* answer = |
| 3301 | CreateRemoteAnswer(session_->local_description()); |
| 3302 | SetRemoteDescriptionWithoutError(answer); |
| 3303 | |
| 3304 | // This should lead to an audio-only call but isn't implemented |
| 3305 | // correctly yet. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3306 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3307 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3308 | } |
| 3309 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3310 | // kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3311 | TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) { |
| 3312 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3313 | SendAudioVideoStream1(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3314 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3315 | options.use_rtp_mux = true; |
| 3316 | |
| 3317 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3318 | SetLocalDescriptionWithoutError(offer); |
| 3319 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3320 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3321 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3322 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3323 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3324 | |
| 3325 | // Remove BUNDLE from the answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3326 | std::unique_ptr<SessionDescriptionInterface> answer( |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 3327 | CreateRemoteAnswer(session_->local_description())); |
| 3328 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3329 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 3330 | JsepSessionDescription* modified_answer = |
| 3331 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 3332 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 3333 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 3334 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3335 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3336 | session_->video_rtp_transport_channel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3337 | } |
| 3338 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3339 | // kBundlePolicyMaxbundle and then we call SetRemoteDescription first. |
| 3340 | TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) { |
| 3341 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3342 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3343 | |
| 3344 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3345 | options.use_rtp_mux = true; |
| 3346 | |
| 3347 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3348 | SetRemoteDescriptionWithoutError(offer); |
| 3349 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3350 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 3351 | session_->video_rtp_transport_channel()); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 3352 | } |
| 3353 | |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 3354 | // Adding a new channel to a BUNDLE which is already connected should directly |
| 3355 | // assign the bundle transport to the channel, without first setting a |
| 3356 | // disconnected non-bundle transport and then replacing it. The application |
| 3357 | // should not receive any changes in the ICE state. |
| 3358 | TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) { |
| 3359 | LoopbackNetworkConfiguration config; |
| 3360 | LoopbackNetworkManager loopback_network_manager(this, config); |
| 3361 | // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain |
| 3362 | // connected. Disabling either of these two means that we need to wait for the |
| 3363 | // answer to find out if more transports are needed. |
| 3364 | configuration_.bundle_policy = |
| 3365 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 3366 | options_.disable_encryption = true; |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 3367 | Init(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 3368 | |
| 3369 | // Negotiate an audio channel with MAX_BUNDLE enabled. |
| 3370 | SendAudioOnlyStream2(); |
| 3371 | SessionDescriptionInterface* offer = CreateOffer(); |
| 3372 | SetLocalDescriptionWithoutError(offer); |
| 3373 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 3374 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
| 3375 | std::string sdp; |
| 3376 | offer->ToString(&sdp); |
| 3377 | SessionDescriptionInterface* answer = webrtc::CreateSessionDescription( |
| 3378 | JsepSessionDescription::kAnswer, sdp, nullptr); |
| 3379 | ASSERT_TRUE(answer != NULL); |
| 3380 | SetRemoteDescriptionWithoutError(answer); |
| 3381 | |
| 3382 | // Wait for the ICE state to stabilize. |
| 3383 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 3384 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 3385 | observer_.ice_connection_state_history_.clear(); |
| 3386 | |
| 3387 | // Now add a video channel which should be using the same bundle transport. |
| 3388 | SendAudioVideoStream2(); |
| 3389 | offer = CreateOffer(); |
| 3390 | offer->ToString(&sdp); |
| 3391 | SetLocalDescriptionWithoutError(offer); |
| 3392 | answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, |
| 3393 | sdp, nullptr); |
| 3394 | ASSERT_TRUE(answer != NULL); |
| 3395 | SetRemoteDescriptionWithoutError(answer); |
| 3396 | |
| 3397 | // Wait for ICE state to stabilize |
| 3398 | rtc::Thread::Current()->ProcessMessages(0); |
| 3399 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 3400 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 3401 | |
| 3402 | // No ICE state changes are expected to happen. |
| 3403 | EXPECT_EQ(0, observer_.ice_connection_state_history_.size()); |
| 3404 | } |
| 3405 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3406 | TEST_F(WebRtcSessionTest, TestRequireRtcpMux) { |
| 3407 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3408 | SendAudioVideoStream1(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3409 | |
| 3410 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3411 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3412 | SetLocalDescriptionWithoutError(offer); |
| 3413 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3414 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 3415 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3416 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3417 | SendAudioVideoStream2(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3418 | SessionDescriptionInterface* answer = |
| 3419 | CreateRemoteAnswer(session_->local_description()); |
| 3420 | SetRemoteDescriptionWithoutError(answer); |
| 3421 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3422 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 3423 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) { |
| 3427 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3428 | SendAudioVideoStream1(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3429 | |
| 3430 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3431 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3432 | SetLocalDescriptionWithoutError(offer); |
| 3433 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3434 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL); |
| 3435 | EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3436 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3437 | SendAudioVideoStream2(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3438 | SessionDescriptionInterface* answer = |
| 3439 | CreateRemoteAnswer(session_->local_description()); |
| 3440 | SetRemoteDescriptionWithoutError(answer); |
| 3441 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3442 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 3443 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 3444 | } |
| 3445 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3446 | // This test verifies that SetLocalDescription and SetRemoteDescription fails |
| 3447 | // if BUNDLE is enabled but rtcp-mux is disabled in m-lines. |
| 3448 | TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3449 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3450 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3451 | |
| 3452 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3453 | options.use_rtp_mux = true; |
| 3454 | |
| 3455 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3456 | std::string offer_str; |
| 3457 | offer->ToString(&offer_str); |
| 3458 | // Disable rtcp-mux |
| 3459 | const std::string rtcp_mux = "rtcp-mux"; |
| 3460 | const std::string xrtcp_mux = "xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3461 | rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(), |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3462 | xrtcp_mux.c_str(), xrtcp_mux.length(), |
| 3463 | &offer_str); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3464 | JsepSessionDescription* local_offer = |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3465 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 3466 | EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3467 | SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3468 | JsepSessionDescription* remote_offer = |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3469 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 3470 | EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3471 | SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 3472 | // Trying unmodified SDP. |
| 3473 | SetLocalDescriptionWithoutError(offer); |
| 3474 | } |
| 3475 | |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 3476 | TEST_F(WebRtcSessionTest, SetSetupGcm) { |
| 3477 | InitWithGcm(); |
| 3478 | SendAudioVideoStream1(); |
| 3479 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3480 | } |
| 3481 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3482 | // This test verifies the |initial_offerer| flag when session initiates the |
| 3483 | // call. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3484 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3485 | Init(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3486 | EXPECT_FALSE(session_->initial_offerer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3487 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3488 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 3489 | SetLocalDescriptionWithoutError(offer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3490 | EXPECT_TRUE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3491 | SetRemoteDescriptionWithoutError(answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3492 | EXPECT_TRUE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3493 | } |
| 3494 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3495 | // This test verifies the |initial_offerer| flag when session receives the call. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3496 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3497 | Init(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3498 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3499 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3500 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3501 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3502 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3503 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3504 | SetLocalDescriptionWithoutError(answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3505 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3506 | } |
| 3507 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3508 | // Verifing local offer and remote answer have matching m-lines as per RFC 3264. |
| 3509 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3510 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3511 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3512 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3513 | SetLocalDescriptionWithoutError(offer); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3514 | std::unique_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3515 | CreateRemoteAnswer(session_->local_description())); |
| 3516 | |
| 3517 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3518 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3519 | JsepSessionDescription* modified_answer = |
| 3520 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3521 | |
| 3522 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 3523 | answer->session_id(), |
| 3524 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3525 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3526 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 3527 | // Different content names. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3528 | std::string sdp; |
| 3529 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 3530 | const std::string kAudioMid = "a=mid:audio"; |
| 3531 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3532 | rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3533 | kAudioMidReplaceStr.c_str(), |
| 3534 | kAudioMidReplaceStr.length(), |
| 3535 | &sdp); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3536 | SessionDescriptionInterface* modified_answer1 = |
| 3537 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3538 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3539 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 3540 | // Different media types. |
| 3541 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 3542 | const std::string kAudioMline = "m=audio"; |
| 3543 | const std::string kAudioMlineReplaceStr = "m=video"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3544 | rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(), |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 3545 | kAudioMlineReplaceStr.c_str(), |
| 3546 | kAudioMlineReplaceStr.length(), |
| 3547 | &sdp); |
| 3548 | SessionDescriptionInterface* modified_answer2 = |
| 3549 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
| 3550 | SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2); |
| 3551 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3552 | SetRemoteDescriptionWithoutError(answer.release()); |
| 3553 | } |
| 3554 | |
| 3555 | // Verifying remote offer and local answer have matching m-lines as per |
| 3556 | // RFC 3264. |
| 3557 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3558 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3559 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3560 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3561 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3562 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3563 | |
| 3564 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 3565 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3566 | JsepSessionDescription* modified_answer = |
| 3567 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3568 | |
| 3569 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 3570 | answer->session_id(), |
| 3571 | answer->session_version())); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3572 | SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3573 | SetLocalDescriptionWithoutError(answer); |
| 3574 | } |
| 3575 | |
| 3576 | // This test verifies that WebRtcSession does not start candidate allocation |
| 3577 | // before SetLocalDescription is called. |
| 3578 | TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3579 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3580 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3581 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 3582 | cricket::Candidate candidate; |
| 3583 | candidate.set_component(1); |
| 3584 | JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 3585 | candidate); |
| 3586 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 3587 | cricket::Candidate candidate1; |
| 3588 | candidate1.set_component(1); |
| 3589 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 3590 | candidate1); |
| 3591 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate1)); |
| 3592 | SetRemoteDescriptionWithoutError(offer); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3593 | ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL); |
| 3594 | ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3595 | |
| 3596 | // Pump for 1 second and verify that no candidates are generated. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 3597 | rtc::Thread::Current()->ProcessMessages(1000); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3598 | EXPECT_TRUE(observer_.mline_0_candidates_.empty()); |
| 3599 | EXPECT_TRUE(observer_.mline_1_candidates_.empty()); |
| 3600 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3601 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3602 | SetLocalDescriptionWithoutError(answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3603 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 3604 | } |
| 3605 | |
| 3606 | // This test verifies that crypto parameter is updated in local session |
| 3607 | // description as per security policy set in MediaSessionDescriptionFactory. |
| 3608 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3609 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3610 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3611 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3612 | |
| 3613 | // Making sure SetLocalDescription correctly sets crypto value in |
| 3614 | // SessionDescription object after de-serialization of sdp string. The value |
| 3615 | // will be set as per MediaSessionDescriptionFactory. |
| 3616 | std::string offer_str; |
| 3617 | offer->ToString(&offer_str); |
| 3618 | SessionDescriptionInterface* jsep_offer_str = |
| 3619 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 3620 | SetLocalDescriptionWithoutError(jsep_offer_str); |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 3621 | EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing()); |
| 3622 | EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3623 | } |
| 3624 | |
| 3625 | // This test verifies the crypto parameter when security is disabled. |
| 3626 | TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3627 | options_.disable_encryption = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3628 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3629 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3630 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3631 | |
| 3632 | // Making sure SetLocalDescription correctly sets crypto value in |
| 3633 | // SessionDescription object after de-serialization of sdp string. The value |
| 3634 | // will be set as per MediaSessionDescriptionFactory. |
| 3635 | std::string offer_str; |
| 3636 | offer->ToString(&offer_str); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3637 | SessionDescriptionInterface* jsep_offer_str = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3638 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL); |
| 3639 | SetLocalDescriptionWithoutError(jsep_offer_str); |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 3640 | EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing()); |
| 3641 | EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | // This test verifies that an answer contains new ufrag and password if an offer |
| 3645 | // with new ufrag and password is received. |
| 3646 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3647 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3648 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3649 | options.recv_video = true; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3650 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3651 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3652 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3653 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3654 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3655 | SetLocalDescriptionWithoutError(answer.release()); |
| 3656 | |
| 3657 | // Receive an offer with new ufrag and password. |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3658 | for (const cricket::ContentInfo& content : |
| 3659 | session_->local_description()->description()->contents()) { |
| 3660 | options.transport_options[content.name].ice_restart = true; |
| 3661 | } |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3662 | std::unique_ptr<JsepSessionDescription> updated_offer1( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3663 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3664 | SetRemoteDescriptionWithoutError(updated_offer1.release()); |
| 3665 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3666 | std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3667 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3668 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(), |
| 3669 | session_->local_description()->description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3670 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3671 | // Even a second answer (created before the description is set) should have |
| 3672 | // a new ufrag/password. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3673 | std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3674 | |
| 3675 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(), |
| 3676 | session_->local_description()->description())); |
| 3677 | |
| 3678 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
| 3679 | } |
| 3680 | |
| 3681 | // This test verifies that an answer contains new ufrag and password if an offer |
| 3682 | // that changes either the ufrag or password (but not both) is received. |
| 3683 | // RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or |
| 3684 | // a=ice-pwd attributes compared to the previous SDP from the peer, it |
| 3685 | // indicates that ICE is restarting for this media stream." |
| 3686 | TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) { |
| 3687 | Init(); |
| 3688 | cricket::MediaSessionOptions options; |
| 3689 | options.recv_audio = true; |
| 3690 | options.recv_video = true; |
| 3691 | // Create an offer with audio and video. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3692 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3693 | SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345"); |
| 3694 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3695 | |
| 3696 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3697 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3698 | SetLocalDescriptionWithoutError(answer.release()); |
| 3699 | |
| 3700 | // Receive an offer with a new ufrag but stale password. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3701 | std::unique_ptr<JsepSessionDescription> ufrag_changed_offer( |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3702 | CreateRemoteOffer(options, session_->remote_description())); |
| 3703 | SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag", |
| 3704 | "original_password12345"); |
| 3705 | SetRemoteDescriptionWithoutError(ufrag_changed_offer.release()); |
| 3706 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3707 | std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3708 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(), |
| 3709 | session_->local_description()->description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3710 | SetLocalDescriptionWithoutError(updated_answer1.release()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3711 | |
| 3712 | // Receive an offer with a new password but stale ufrag. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3713 | std::unique_ptr<JsepSessionDescription> password_changed_offer( |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3714 | CreateRemoteOffer(options, session_->remote_description())); |
| 3715 | SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag", |
| 3716 | "modified_password12345"); |
| 3717 | SetRemoteDescriptionWithoutError(password_changed_offer.release()); |
| 3718 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3719 | std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3720 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(), |
| 3721 | session_->local_description()->description())); |
| 3722 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3723 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3724 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3725 | // This test verifies that an answer contains old ufrag and password if an offer |
| 3726 | // with old ufrag and password is received. |
| 3727 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3728 | Init(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3729 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 3730 | options.recv_video = true; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3731 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3732 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3733 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3734 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3735 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3736 | SetLocalDescriptionWithoutError(answer.release()); |
| 3737 | |
| 3738 | // Receive an offer without changed ufrag or password. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3739 | std::unique_ptr<JsepSessionDescription> updated_offer2( |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3740 | CreateRemoteOffer(options, session_->remote_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3741 | SetRemoteDescriptionWithoutError(updated_offer2.release()); |
| 3742 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3743 | std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3744 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3745 | EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(), |
| 3746 | session_->local_description()->description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3747 | |
| 3748 | SetLocalDescriptionWithoutError(updated_answer2.release()); |
| 3749 | } |
| 3750 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3751 | // This test verifies that if an offer does an ICE restart on some, but not all |
| 3752 | // media sections, the answer will change the ufrag/password in the correct |
| 3753 | // media sections. |
| 3754 | TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) { |
| 3755 | Init(); |
| 3756 | cricket::MediaSessionOptions options; |
| 3757 | options.recv_video = true; |
| 3758 | options.recv_audio = true; |
| 3759 | options.bundle_enabled = false; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3760 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3761 | |
| 3762 | SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa", |
| 3763 | "aaaaaaaaaaaaaaaaaaaaaa"); |
| 3764 | SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb", |
| 3765 | "bbbbbbbbbbbbbbbbbbbbbb"); |
| 3766 | SetRemoteDescriptionWithoutError(offer.release()); |
| 3767 | |
| 3768 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3769 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3770 | SetLocalDescriptionWithoutError(answer.release()); |
| 3771 | |
| 3772 | // Receive an offer with new ufrag and password, but only for the video media |
| 3773 | // section. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3774 | std::unique_ptr<JsepSessionDescription> updated_offer( |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3775 | CreateRemoteOffer(options, session_->remote_description())); |
| 3776 | SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc", |
| 3777 | "cccccccccccccccccccccc"); |
| 3778 | SetRemoteDescriptionWithoutError(updated_offer.release()); |
| 3779 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3780 | std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer()); |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 3781 | |
| 3782 | EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(), |
| 3783 | session_->local_description()->description(), |
| 3784 | cricket::MEDIA_TYPE_AUDIO)); |
| 3785 | |
| 3786 | EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(), |
| 3787 | session_->local_description()->description(), |
| 3788 | cricket::MEDIA_TYPE_VIDEO)); |
| 3789 | |
| 3790 | SetLocalDescriptionWithoutError(updated_answer.release()); |
| 3791 | } |
| 3792 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3793 | TEST_F(WebRtcSessionTest, TestSessionContentError) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3794 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3795 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 3796 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3797 | const std::string session_id_orig = offer->session_id(); |
| 3798 | const std::string session_version_orig = offer->session_version(); |
| 3799 | SetLocalDescriptionWithoutError(offer); |
| 3800 | |
| 3801 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 3802 | video_channel_->set_fail_set_send_codecs(true); |
| 3803 | |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 3804 | SessionDescriptionInterface* answer = |
| 3805 | CreateRemoteAnswer(session_->local_description()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 3806 | SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 3807 | |
| 3808 | // Test that after a content error, setting any description will |
| 3809 | // result in an error. |
| 3810 | video_channel_->set_fail_set_send_codecs(false); |
| 3811 | answer = CreateRemoteAnswer(session_->local_description()); |
| 3812 | SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer); |
| 3813 | offer = CreateRemoteOffer(); |
| 3814 | SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3815 | } |
| 3816 | |
| 3817 | // Runs the loopback call test with BUNDLE and STUN disabled. |
| 3818 | TEST_F(WebRtcSessionTest, TestIceStatesBasic) { |
| 3819 | // Lets try with only UDP ports. |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 3820 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 3821 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 3822 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3823 | TestLoopbackCall(); |
| 3824 | } |
| 3825 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 3826 | TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) { |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 3827 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 3828 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 3829 | cricket::PORTALLOCATOR_ENABLE_IPV6 | |
| 3830 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 3831 | |
| 3832 | // best connection is IPv6 since it has higher network preference. |
| 3833 | LoopbackNetworkConfiguration config; |
| 3834 | config.test_ipv6_network_ = true; |
| 3835 | config.best_connection_after_initial_ice_converged_ = |
| 3836 | LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1); |
| 3837 | |
| 3838 | TestLoopbackCall(config); |
| 3839 | } |
| 3840 | |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 3841 | // Runs the loopback call test with BUNDLE and STUN enabled. |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 3842 | TEST_F(WebRtcSessionTest, TestIceStatesBundle) { |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 3843 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 3844 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 3845 | TestLoopbackCall(); |
| 3846 | } |
| 3847 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3848 | TEST_F(WebRtcSessionTest, TestRtpDataChannel) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3849 | configuration_.enable_rtp_data_channel = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 3850 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3851 | SetLocalDescriptionWithDataChannel(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3852 | ASSERT_TRUE(data_engine_); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3853 | EXPECT_NE(nullptr, data_engine_->GetChannel(0)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3854 | } |
| 3855 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3856 | TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3857 | configuration_.enable_rtp_data_channel = true; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3858 | options_.disable_sctp_data_channels = false; |
| 3859 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3860 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3861 | |
| 3862 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3863 | EXPECT_NE(nullptr, data_engine_->GetChannel(0)); |
| 3864 | } |
| 3865 | |
| 3866 | // Test that sctp_content_name/sctp_transport_name (used for stats) are correct |
| 3867 | // before and after BUNDLE is negotiated. |
| 3868 | TEST_P(WebRtcSessionTest, SctpContentAndTransportName) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3869 | SetFactoryDtlsSrtp(); |
| 3870 | InitWithDtls(GetParam()); |
| 3871 | |
| 3872 | // Initially these fields should be empty. |
| 3873 | EXPECT_FALSE(session_->sctp_content_name()); |
| 3874 | EXPECT_FALSE(session_->sctp_transport_name()); |
| 3875 | |
| 3876 | // Create offer with audio/video/data. |
| 3877 | // Default bundle policy is "balanced", so data should be using its own |
| 3878 | // transport. |
| 3879 | SendAudioVideoStream1(); |
| 3880 | CreateDataChannel(); |
| 3881 | InitiateCall(); |
| 3882 | ASSERT_TRUE(session_->sctp_content_name()); |
| 3883 | ASSERT_TRUE(session_->sctp_transport_name()); |
| 3884 | EXPECT_EQ("data", *session_->sctp_content_name()); |
| 3885 | EXPECT_EQ("data", *session_->sctp_transport_name()); |
| 3886 | |
| 3887 | // Create answer that finishes BUNDLE negotiation, which means everything |
| 3888 | // should be bundled on the first transport (audio). |
| 3889 | cricket::MediaSessionOptions answer_options; |
| 3890 | answer_options.recv_video = true; |
| 3891 | answer_options.bundle_enabled = true; |
| 3892 | answer_options.data_channel_type = cricket::DCT_SCTP; |
| 3893 | SetRemoteDescriptionWithoutError(CreateRemoteAnswer( |
| 3894 | session_->local_description(), answer_options, cricket::SEC_DISABLED)); |
| 3895 | ASSERT_TRUE(session_->sctp_content_name()); |
| 3896 | ASSERT_TRUE(session_->sctp_transport_name()); |
| 3897 | EXPECT_EQ("data", *session_->sctp_content_name()); |
| 3898 | EXPECT_EQ("audio", *session_->sctp_transport_name()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3899 | } |
| 3900 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3901 | TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3902 | InitWithDtls(GetParam()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3903 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3904 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3905 | EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3906 | EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); |
| 3907 | } |
| 3908 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3909 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3910 | SetFactoryDtlsSrtp(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3911 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3912 | |
| 3913 | // Create remote offer with SCTP. |
| 3914 | cricket::MediaSessionOptions options; |
| 3915 | options.data_channel_type = cricket::DCT_SCTP; |
| 3916 | JsepSessionDescription* offer = |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 3917 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3918 | SetRemoteDescriptionWithoutError(offer); |
| 3919 | |
| 3920 | // Verifies the answer contains SCTP. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 3921 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 3922 | EXPECT_TRUE(answer != NULL); |
| 3923 | EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); |
| 3924 | EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 3925 | } |
| 3926 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3927 | // Test that if DTLS is disabled, we don't end up with an SctpTransport |
| 3928 | // created (or an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3929 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3930 | configuration_.enable_dtls_srtp = rtc::Optional<bool>(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3931 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3932 | |
| 3933 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3934 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 3935 | EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3936 | } |
| 3937 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3938 | // Test that if DTLS is enabled, we end up with an SctpTransport created |
| 3939 | // (and not an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3940 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3941 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3942 | |
| 3943 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3944 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 3945 | EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3946 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 3947 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3948 | // Test that if SCTP is disabled, we don't end up with an SctpTransport |
| 3949 | // created (or an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3950 | TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3951 | options_.disable_sctp_data_channels = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3952 | InitWithDtls(GetParam()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3953 | |
| 3954 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3955 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 3956 | EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 3957 | } |
| 3958 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3959 | TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3960 | const int new_send_port = 9998; |
| 3961 | const int new_recv_port = 7775; |
| 3962 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3963 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3964 | SetFactoryDtlsSrtp(); |
| 3965 | |
| 3966 | // By default, don't actually add the codecs to desc_factory_; they don't |
| 3967 | // actually get serialized for SCTP in BuildMediaDescription(). Instead, |
| 3968 | // let the session description get parsed. That'll get the proper codecs |
| 3969 | // into the stream. |
| 3970 | cricket::MediaSessionOptions options; |
| 3971 | JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort( |
| 3972 | "stream1", new_send_port, options); |
| 3973 | |
| 3974 | // SetRemoteDescription will take the ownership of the offer. |
| 3975 | SetRemoteDescriptionWithoutError(offer); |
| 3976 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3977 | SessionDescriptionInterface* answer = |
| 3978 | ChangeSDPSctpPort(new_recv_port, CreateAnswer()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3979 | ASSERT_TRUE(answer != NULL); |
| 3980 | |
| 3981 | // Now set the local description, which'll take ownership of the answer. |
| 3982 | SetLocalDescriptionWithoutError(answer); |
| 3983 | |
| 3984 | // TEST PLAN: Set the port number to something new, set it in the SDP, |
| 3985 | // and pass it all the way down. |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3986 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3987 | CreateDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3988 | ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
| 3989 | EXPECT_EQ( |
| 3990 | new_recv_port, |
| 3991 | fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port()); |
| 3992 | EXPECT_EQ( |
| 3993 | new_send_port, |
| 3994 | fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 3995 | } |
| 3996 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 3997 | // Verifies that when a session's SctpTransport receives an OPEN message, |
| 3998 | // WebRtcSession signals the SctpTransport creation request with the expected |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3999 | // config. |
| 4000 | TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4001 | InitWithDtls(GetParam()); |
| 4002 | |
| 4003 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 4004 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 4005 | ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4006 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 4007 | // Make the fake SCTP transport pretend it received an OPEN message. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4008 | webrtc::DataChannelInit config; |
| 4009 | config.id = 1; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 4010 | rtc::CopyOnWriteBuffer payload; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4011 | webrtc::WriteDataChannelOpenMessage("a", config, &payload); |
| 4012 | cricket::ReceiveDataParams params; |
| 4013 | params.ssrc = config.id; |
| 4014 | params.type = cricket::DMT_CONTROL; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 4015 | fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived( |
| 4016 | params, payload); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4017 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 4018 | EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4019 | EXPECT_EQ(config.id, last_data_channel_config_.id); |
| 4020 | EXPECT_FALSE(last_data_channel_config_.negotiated); |
| 4021 | EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker, |
| 4022 | last_data_channel_config_.open_handshake_role); |
| 4023 | } |
| 4024 | |
| 4025 | TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) { |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 4026 | rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 4027 | FakeRTCCertificateGenerator::GenerateCertificate(); |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 4028 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4029 | configuration_.certificates.push_back(certificate); |
| 4030 | Init(); |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 4031 | EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); |
| 4032 | |
| 4033 | EXPECT_EQ(session_->certificate_for_testing(), certificate); |
| 4034 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4035 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4036 | // Verifies that CreateOffer succeeds when CreateOffer is called before async |
| 4037 | // identity generation is finished (even if a certificate is provided this is |
| 4038 | // an async op). |
| 4039 | TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4040 | InitWithDtls(GetParam()); |
| 4041 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 4042 | EXPECT_TRUE(session_->waiting_for_certificate_for_testing()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4043 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 4044 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 4045 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4046 | EXPECT_TRUE(offer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 4047 | VerifyNoCryptoParams(offer->description(), true); |
| 4048 | VerifyFingerprintStatus(offer->description(), true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | // Verifies that CreateAnswer succeeds when CreateOffer is called before async |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4052 | // identity generation is finished (even if a certificate is provided this is |
| 4053 | // an async op). |
| 4054 | TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4055 | InitWithDtls(GetParam()); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 4056 | SetFactoryDtlsSrtp(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4057 | |
| 4058 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 4059 | options.recv_video = true; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 4060 | std::unique_ptr<JsepSessionDescription> offer( |
| 4061 | CreateRemoteOffer(options, cricket::SEC_DISABLED)); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4062 | ASSERT_TRUE(offer.get() != NULL); |
| 4063 | SetRemoteDescriptionWithoutError(offer.release()); |
| 4064 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 4065 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4066 | EXPECT_TRUE(answer != NULL); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 4067 | VerifyNoCryptoParams(answer->description(), true); |
| 4068 | VerifyFingerprintStatus(answer->description(), true); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4069 | } |
| 4070 | |
| 4071 | // Verifies that CreateOffer succeeds when CreateOffer is called after async |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4072 | // identity generation is finished (even if a certificate is provided this is |
| 4073 | // an async op). |
| 4074 | TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4075 | InitWithDtls(GetParam()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4076 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 4077 | EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 4078 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 4079 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4080 | EXPECT_TRUE(offer != NULL); |
| 4081 | } |
| 4082 | |
| 4083 | // Verifies that CreateOffer fails when CreateOffer is called after async |
| 4084 | // identity generation fails. |
| 4085 | TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4086 | InitWithDtlsIdentityGenFail(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4087 | |
Henrik Boström | d828198 | 2015-08-27 10:12:24 +0200 | [diff] [blame] | 4088 | EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 4089 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 4090 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4091 | EXPECT_TRUE(offer == NULL); |
| 4092 | } |
| 4093 | |
| 4094 | // Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made |
| 4095 | // before async identity generation is finished. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4096 | TEST_P(WebRtcSessionTest, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4097 | TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4098 | VerifyMultipleAsyncCreateDescription(GetParam(), |
| 4099 | CreateSessionDescriptionRequest::kOffer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | // Verifies that CreateOffer fails when Multiple CreateOffer calls are made |
| 4103 | // before async identity generation fails. |
| 4104 | TEST_F(WebRtcSessionTest, |
| 4105 | TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4106 | VerifyMultipleAsyncCreateDescriptionIdentityGenFailure( |
| 4107 | CreateSessionDescriptionRequest::kOffer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4108 | } |
| 4109 | |
| 4110 | // Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made |
| 4111 | // before async identity generation is finished. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4112 | TEST_P(WebRtcSessionTest, |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4113 | TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) { |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4114 | VerifyMultipleAsyncCreateDescription( |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4115 | GetParam(), CreateSessionDescriptionRequest::kAnswer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4116 | } |
| 4117 | |
| 4118 | // Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made |
| 4119 | // before async identity generation fails. |
| 4120 | TEST_F(WebRtcSessionTest, |
| 4121 | TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4122 | VerifyMultipleAsyncCreateDescriptionIdentityGenFailure( |
| 4123 | CreateSessionDescriptionRequest::kAnswer); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 4124 | } |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 4125 | |
| 4126 | // Verifies that setRemoteDescription fails when DTLS is disabled and the remote |
| 4127 | // offer has no SDES crypto but only DTLS fingerprint. |
| 4128 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) { |
| 4129 | // Init without DTLS. |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 4130 | Init(); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 4131 | // Create a remote offer with secured transport disabled. |
| 4132 | cricket::MediaSessionOptions options; |
| 4133 | JsepSessionDescription* offer(CreateRemoteOffer( |
| 4134 | options, cricket::SEC_DISABLED)); |
| 4135 | // Adds a DTLS fingerprint to the remote offer. |
| 4136 | cricket::SessionDescription* sdp = offer->description(); |
| 4137 | TransportInfo* audio = sdp->GetTransportInfoByName("audio"); |
| 4138 | ASSERT_TRUE(audio != NULL); |
| 4139 | ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL); |
| 4140 | audio->description.identity_fingerprint.reset( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4141 | rtc::SSLFingerprint::CreateFromRfc4572( |
| 4142 | rtc::DIGEST_SHA_256, kFakeDtlsFingerprint)); |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 4143 | SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 4144 | offer); |
mallinath@webrtc.org | a27be8e | 2013-09-27 23:04:10 +0000 | [diff] [blame] | 4145 | } |
| 4146 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 4147 | TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4148 | configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 4149 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4150 | SendAudioVideoStream1(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 4151 | SessionDescriptionInterface* offer = CreateOffer(); |
| 4152 | |
| 4153 | SetLocalDescriptionWithoutError(offer); |
| 4154 | |
| 4155 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 4156 | |
| 4157 | ASSERT_TRUE(voice_channel_ != NULL); |
solenberg | 66f4339 | 2015-09-09 01:36:22 -0700 | [diff] [blame] | 4158 | const cricket::AudioOptions& audio_options = voice_channel_->options(); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 4159 | EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 4160 | } |
| 4161 | |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4162 | // Tests that we can renegotiate new media content with ICE candidates in the |
| 4163 | // new remote SDP. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4164 | TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4165 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4166 | SetFactoryDtlsSrtp(); |
| 4167 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4168 | SendAudioOnlyStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 4169 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4170 | SetLocalDescriptionWithoutError(offer); |
| 4171 | |
| 4172 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 4173 | SetRemoteDescriptionWithoutError(answer); |
| 4174 | |
| 4175 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 4176 | options.recv_video = true; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4177 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 4178 | |
| 4179 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4180 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4181 | candidate1.set_component(1); |
| 4182 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 4183 | candidate1); |
| 4184 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 4185 | SetRemoteDescriptionWithoutError(offer); |
| 4186 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4187 | answer = CreateAnswer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4188 | SetLocalDescriptionWithoutError(answer); |
| 4189 | } |
| 4190 | |
| 4191 | // Tests that we can renegotiate new media content with ICE candidates separated |
| 4192 | // from the remote SDP. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4193 | TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4194 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4195 | SetFactoryDtlsSrtp(); |
| 4196 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4197 | SendAudioOnlyStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 4198 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4199 | SetLocalDescriptionWithoutError(offer); |
| 4200 | |
| 4201 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 4202 | SetRemoteDescriptionWithoutError(answer); |
| 4203 | |
| 4204 | cricket::MediaSessionOptions options; |
jiayl@webrtc.org | 742922b | 2014-10-07 21:32:43 +0000 | [diff] [blame] | 4205 | options.recv_video = true; |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4206 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 4207 | SetRemoteDescriptionWithoutError(offer); |
| 4208 | |
| 4209 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 4210 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4211 | candidate1.set_component(1); |
| 4212 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 4213 | candidate1); |
| 4214 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate)); |
| 4215 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4216 | answer = CreateAnswer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4217 | SetLocalDescriptionWithoutError(answer); |
| 4218 | } |
honghaiz | 7f77749 | 2016-02-02 21:54:01 -0800 | [diff] [blame] | 4219 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 4220 | #ifdef HAVE_QUIC |
| 4221 | TEST_P(WebRtcSessionTest, TestNegotiateQuic) { |
| 4222 | configuration_.enable_quic = true; |
| 4223 | InitWithDtls(GetParam()); |
| 4224 | EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC); |
| 4225 | SessionDescriptionInterface* offer = CreateOffer(); |
| 4226 | ASSERT_TRUE(offer); |
| 4227 | ASSERT_TRUE(offer->description()); |
| 4228 | SetLocalDescriptionWithoutError(offer); |
| 4229 | cricket::MediaSessionOptions options; |
| 4230 | options.recv_audio = true; |
| 4231 | options.recv_video = true; |
| 4232 | SessionDescriptionInterface* answer = |
| 4233 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 4234 | ASSERT_TRUE(answer); |
| 4235 | ASSERT_TRUE(answer->description()); |
| 4236 | SetRemoteDescriptionWithoutError(answer); |
| 4237 | } |
| 4238 | #endif // HAVE_QUIC |
| 4239 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 4240 | // Tests that RTX codec is removed from the answer when it isn't supported |
| 4241 | // by local side. |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 4242 | TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) { |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 4243 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4244 | SendAudioVideoStream1(); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 4245 | std::string offer_sdp(kSdpWithRtx); |
| 4246 | |
| 4247 | SessionDescriptionInterface* offer = |
| 4248 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL); |
| 4249 | EXPECT_TRUE(offer->ToString(&offer_sdp)); |
| 4250 | |
| 4251 | // Offer SDP contains the RTX codec. |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 4252 | EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx")); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 4253 | SetRemoteDescriptionWithoutError(offer); |
| 4254 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 4255 | SessionDescriptionInterface* answer = CreateAnswer(); |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 4256 | // Answer SDP does not contain the RTX codec. |
| 4257 | EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx")); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 4258 | SetLocalDescriptionWithoutError(answer); |
| 4259 | } |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 4260 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4261 | // This verifies that the voice channel after bundle has both options from video |
| 4262 | // and voice channels. |
| 4263 | TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) { |
| 4264 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4265 | SendAudioVideoStream1(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4266 | |
| 4267 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4268 | options.use_rtp_mux = true; |
| 4269 | |
| 4270 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 4271 | SetLocalDescriptionWithoutError(offer); |
| 4272 | |
| 4273 | session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 4274 | rtc::Socket::Option::OPT_SNDBUF, 4000); |
| 4275 | |
| 4276 | session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 4277 | rtc::Socket::Option::OPT_RCVBUF, 8000); |
| 4278 | |
| 4279 | int option_val; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4280 | EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4281 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 4282 | EXPECT_EQ(4000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4283 | EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4284 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 4285 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4286 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4287 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 4288 | EXPECT_EQ(8000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4289 | EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4290 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 4291 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4292 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 4293 | session_->video_rtp_transport_channel()); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4294 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4295 | SendAudioVideoStream2(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4296 | SessionDescriptionInterface* answer = |
| 4297 | CreateRemoteAnswer(session_->local_description()); |
| 4298 | SetRemoteDescriptionWithoutError(answer); |
| 4299 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4300 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4301 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 4302 | EXPECT_EQ(4000, option_val); |
| 4303 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4304 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 4305 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 4306 | EXPECT_EQ(8000, option_val); |
| 4307 | } |
| 4308 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 4309 | // Test creating a session, request multiple offers, destroy the session |
| 4310 | // and make sure we got success/failure callbacks for all of the requests. |
| 4311 | // Background: crbug.com/507307 |
| 4312 | TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) { |
| 4313 | Init(); |
| 4314 | |
| 4315 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100]; |
| 4316 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 4317 | options.offer_to_receive_audio = |
| 4318 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4319 | cricket::MediaSessionOptions session_options; |
| 4320 | session_options.recv_audio = true; |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 4321 | |
| 4322 | for (auto& o : observers) { |
| 4323 | o = new WebRtcSessionCreateSDPObserverForTest(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 4324 | session_->CreateOffer(o, options, session_options); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | session_.reset(); |
| 4328 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 4329 | for (auto& o : observers) { |
| 4330 | // We expect to have received a notification now even if the session was |
| 4331 | // terminated. The offer creation may or may not have succeeded, but we |
| 4332 | // must have received a notification which, so the only invalid state |
| 4333 | // is kInit. |
| 4334 | EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); |
| 4335 | } |
| 4336 | } |
| 4337 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 4338 | TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) { |
| 4339 | TestPacketOptions(); |
| 4340 | } |
| 4341 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4342 | // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 4343 | // currently fails because upon disconnection and reconnection OnIceComplete is |
| 4344 | // called more than once without returning to IceGatheringGathering. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 4345 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 4346 | INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
| 4347 | WebRtcSessionTest, |
| 4348 | testing::Values(ALREADY_GENERATED, |
| 4349 | DTLS_IDENTITY_STORE)); |