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