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