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