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