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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "api/fakemetricsobserver.h" |
| 16 | #include "api/jsepicecandidate.h" |
| 17 | #include "api/jsepsessiondescription.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "media/base/fakemediaengine.h" |
| 19 | #include "media/base/fakevideorenderer.h" |
| 20 | #include "media/base/mediachannel.h" |
| 21 | #include "media/engine/fakewebrtccall.h" |
| 22 | #include "media/sctp/sctptransportinternal.h" |
| 23 | #include "p2p/base/packettransportinternal.h" |
| 24 | #include "p2p/base/stunserver.h" |
| 25 | #include "p2p/base/teststunserver.h" |
| 26 | #include "p2p/base/testturnserver.h" |
| 27 | #include "p2p/client/basicportallocator.h" |
| 28 | #include "pc/audiotrack.h" |
| 29 | #include "pc/channelmanager.h" |
| 30 | #include "pc/mediasession.h" |
| 31 | #include "pc/peerconnection.h" |
| 32 | #include "pc/sctputils.h" |
| 33 | #include "pc/test/fakertccertificategenerator.h" |
| 34 | #include "pc/videotrack.h" |
| 35 | #include "pc/webrtcsession.h" |
| 36 | #include "pc/webrtcsessiondescriptionfactory.h" |
| 37 | #include "rtc_base/checks.h" |
| 38 | #include "rtc_base/fakenetwork.h" |
| 39 | #include "rtc_base/firewallsocketserver.h" |
| 40 | #include "rtc_base/gunit.h" |
| 41 | #include "rtc_base/logging.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 42 | #include "rtc_base/stringutils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "rtc_base/virtualsocketserver.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | using cricket::FakeVoiceMediaChannel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | using cricket::TransportInfo; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 47 | using rtc::SocketAddress; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 48 | using rtc::Thread; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | using webrtc::CreateSessionDescription; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 50 | using webrtc::CreateSessionDescriptionObserver; |
| 51 | using webrtc::CreateSessionDescriptionRequest; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 52 | using webrtc::DataChannel; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 53 | using webrtc::FakeMetricsObserver; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 54 | using webrtc::IceCandidateCollection; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 55 | using webrtc::InternalDataChannelInit; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | using webrtc::JsepIceCandidate; |
| 57 | using webrtc::JsepSessionDescription; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 58 | using webrtc::PeerConnectionFactoryInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | using webrtc::PeerConnectionInterface; |
| 60 | using webrtc::SessionDescriptionInterface; |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 61 | using webrtc::SessionStats; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | using webrtc::StreamCollection; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 63 | using webrtc::WebRtcSession; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 64 | using webrtc::kBundleWithoutRtcpMux; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 65 | using webrtc::kCreateChannelFailed; |
| 66 | using webrtc::kInvalidSdp; |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 67 | using webrtc::kMlineMismatchInAnswer; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 68 | using webrtc::kPushDownTDFailed; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 69 | using webrtc::kSdpWithoutIceUfragPwd; |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 70 | using webrtc::kSdpWithoutDtlsFingerprint; |
| 71 | using webrtc::kSdpWithoutSdesCrypto; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 72 | using webrtc::kSessionError; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 73 | using webrtc::kSessionErrorDesc; |
buildbot@webrtc.org | 53df88c | 2014-08-07 22:46:01 +0000 | [diff] [blame] | 74 | using webrtc::kMaxUnsignalledRecvStreams; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 76 | typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions; |
| 77 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 78 | static const int kClientAddrPort = 0; |
| 79 | static const char kClientAddrHost1[] = "11.11.11.11"; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 80 | static const char kClientIPv6AddrHost1[] = |
| 81 | "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff"; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 82 | static const char kClientAddrHost2[] = "22.22.22.22"; |
| 83 | static const char kStunAddrHost[] = "99.99.99.1"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 84 | |
| 85 | static const char kSessionVersion[] = "1"; |
| 86 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | // Media index of candidates belonging to the first media content. |
| 88 | static const int kMediaContentIndex0 = 0; |
| 89 | static const char kMediaContentName0[] = "audio"; |
| 90 | |
| 91 | // Media index of candidates belonging to the second media content. |
| 92 | static const int kMediaContentIndex1 = 1; |
| 93 | static const char kMediaContentName1[] = "video"; |
| 94 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 95 | static const int kDefaultTimeout = 10000; // 10 seconds. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | static const int kIceCandidatesTimeout = 10000; |
| 97 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 98 | static const char kSdpWithRtx[] = |
| 99 | "v=0\r\n" |
| 100 | "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n" |
| 101 | "s=-\r\n" |
| 102 | "t=0 0\r\n" |
| 103 | "a=msid-semantic: WMS stream1\r\n" |
| 104 | "m=video 9 RTP/SAVPF 0 96\r\n" |
| 105 | "c=IN IP4 0.0.0.0\r\n" |
| 106 | "a=rtcp:9 IN IP4 0.0.0.0\r\n" |
| 107 | "a=ice-ufrag:CerjGp19G7wpXwl7\r\n" |
| 108 | "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n" |
| 109 | "a=mid:video\r\n" |
| 110 | "a=sendrecv\r\n" |
| 111 | "a=rtcp-mux\r\n" |
| 112 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 113 | "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n" |
| 114 | "a=rtpmap:0 fake_video_codec/90000\r\n" |
| 115 | "a=rtpmap:96 rtx/90000\r\n" |
| 116 | "a=fmtp:96 apt=0\r\n"; |
| 117 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 118 | static const char kStream1[] = "stream1"; |
| 119 | static const char kVideoTrack1[] = "video1"; |
| 120 | static const char kAudioTrack1[] = "audio1"; |
| 121 | |
| 122 | static const char kStream2[] = "stream2"; |
| 123 | static const char kVideoTrack2[] = "video2"; |
| 124 | static const char kAudioTrack2[] = "audio2"; |
| 125 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 126 | static constexpr bool kStopped = true; |
| 127 | static constexpr bool kActive = false; |
| 128 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 129 | enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE }; |
| 130 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 131 | class MockIceObserver : public webrtc::IceObserver { |
| 132 | public: |
| 133 | MockIceObserver() |
| 134 | : oncandidatesready_(false), |
| 135 | ice_connection_state_(PeerConnectionInterface::kIceConnectionNew), |
| 136 | ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) { |
| 137 | } |
| 138 | |
Henrik Kjellander | 3fe372d | 2016-05-12 08:10:52 +0200 | [diff] [blame] | 139 | virtual ~MockIceObserver() = default; |
| 140 | |
zstein | 6dfd53a | 2017-03-06 13:49:03 -0800 | [diff] [blame] | 141 | void OnIceConnectionStateChange( |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 142 | PeerConnectionInterface::IceConnectionState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | ice_connection_state_ = new_state; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 144 | ice_connection_state_history_.push_back(new_state); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | } |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 146 | void OnIceGatheringChange( |
| 147 | PeerConnectionInterface::IceGatheringState new_state) override { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 148 | // We can never transition back to "new". |
| 149 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state); |
| 150 | ice_gathering_state_ = new_state; |
perkj | dfb769d | 2016-02-09 03:09:43 -0800 | [diff] [blame] | 151 | oncandidatesready_ = |
| 152 | new_state == PeerConnectionInterface::kIceGatheringComplete; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | // Found a new candidate. |
jbauch | 81bf7b0 | 2017-03-25 08:31:12 -0700 | [diff] [blame] | 156 | void OnIceCandidate( |
| 157 | std::unique_ptr<webrtc::IceCandidateInterface> candidate) override { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 158 | switch (candidate->sdp_mline_index()) { |
| 159 | case kMediaContentIndex0: |
| 160 | mline_0_candidates_.push_back(candidate->candidate()); |
| 161 | break; |
| 162 | case kMediaContentIndex1: |
| 163 | mline_1_candidates_.push_back(candidate->candidate()); |
| 164 | break; |
| 165 | default: |
nisse | c80e741 | 2017-01-11 05:56:46 -0800 | [diff] [blame] | 166 | RTC_NOTREACHED(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 167 | } |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 168 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 169 | // The ICE gathering state should always be Gathering when a candidate is |
| 170 | // received (or possibly Completed in the case of the final candidate). |
| 171 | EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_); |
| 172 | } |
| 173 | |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 174 | // Some local candidates are removed. |
| 175 | void OnIceCandidatesRemoved( |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 176 | const std::vector<cricket::Candidate>& candidates) override { |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 177 | num_candidates_removed_ += candidates.size(); |
| 178 | } |
| 179 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | bool oncandidatesready_; |
| 181 | std::vector<cricket::Candidate> mline_0_candidates_; |
| 182 | std::vector<cricket::Candidate> mline_1_candidates_; |
| 183 | PeerConnectionInterface::IceConnectionState ice_connection_state_; |
| 184 | PeerConnectionInterface::IceGatheringState ice_gathering_state_; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 185 | std::vector<PeerConnectionInterface::IceConnectionState> |
| 186 | ice_connection_state_history_; |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 187 | size_t num_candidates_removed_ = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 190 | // Used for tests in this file to verify that WebRtcSession responds to signals |
| 191 | // from the SctpTransport correctly, and calls Start with the correct |
| 192 | // local/remote ports. |
| 193 | class FakeSctpTransport : public cricket::SctpTransportInternal { |
| 194 | public: |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 195 | void SetTransportChannel(rtc::PacketTransportInternal* channel) override {} |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 196 | bool Start(int local_port, int remote_port) override { |
| 197 | local_port_ = local_port; |
| 198 | remote_port_ = remote_port; |
| 199 | return true; |
| 200 | } |
| 201 | bool OpenStream(int sid) override { return true; } |
| 202 | bool ResetStream(int sid) override { return true; } |
| 203 | bool SendData(const cricket::SendDataParams& params, |
| 204 | const rtc::CopyOnWriteBuffer& payload, |
| 205 | cricket::SendDataResult* result = nullptr) override { |
| 206 | return true; |
| 207 | } |
| 208 | bool ReadyToSendData() override { return true; } |
| 209 | void set_debug_name_for_testing(const char* debug_name) override {} |
| 210 | |
| 211 | int local_port() const { return local_port_; } |
| 212 | int remote_port() const { return remote_port_; } |
| 213 | |
| 214 | private: |
| 215 | int local_port_ = -1; |
| 216 | int remote_port_ = -1; |
| 217 | }; |
| 218 | |
| 219 | class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory { |
| 220 | public: |
| 221 | std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport( |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 222 | rtc::PacketTransportInternal*) override { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 223 | last_fake_sctp_transport_ = new FakeSctpTransport(); |
| 224 | return std::unique_ptr<cricket::SctpTransportInternal>( |
| 225 | last_fake_sctp_transport_); |
| 226 | } |
| 227 | |
| 228 | FakeSctpTransport* last_fake_sctp_transport() { |
| 229 | return last_fake_sctp_transport_; |
| 230 | } |
| 231 | |
| 232 | private: |
| 233 | FakeSctpTransport* last_fake_sctp_transport_ = nullptr; |
| 234 | }; |
| 235 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 236 | class WebRtcSessionForTest : public webrtc::WebRtcSession { |
| 237 | public: |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 238 | WebRtcSessionForTest( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 239 | webrtc::Call* fake_call, |
| 240 | cricket::ChannelManager* channel_manager, |
| 241 | const cricket::MediaConfig& media_config, |
| 242 | webrtc::RtcEventLog* event_log, |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 243 | rtc::Thread* network_thread, |
| 244 | rtc::Thread* worker_thread, |
| 245 | rtc::Thread* signaling_thread, |
| 246 | cricket::PortAllocator* port_allocator, |
| 247 | webrtc::IceObserver* ice_observer, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 248 | std::unique_ptr<cricket::TransportController> transport_controller, |
| 249 | std::unique_ptr<FakeSctpTransportFactory> sctp_factory) |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 250 | : WebRtcSession(fake_call, channel_manager, media_config, event_log, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 251 | network_thread, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 252 | worker_thread, |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 253 | signaling_thread, |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 254 | port_allocator, |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 255 | std::move(transport_controller), |
| 256 | std::move(sctp_factory)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 257 | RegisterIceObserver(ice_observer); |
| 258 | } |
| 259 | virtual ~WebRtcSessionForTest() {} |
| 260 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 261 | // Note that these methods are only safe to use if the signaling thread |
| 262 | // is the same as the worker thread |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 263 | rtc::PacketTransportInternal* voice_rtp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 264 | return rtp_transport_channel(voice_channel()); |
| 265 | } |
| 266 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 267 | rtc::PacketTransportInternal* voice_rtcp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 268 | return rtcp_transport_channel(voice_channel()); |
| 269 | } |
| 270 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 271 | rtc::PacketTransportInternal* video_rtp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 272 | return rtp_transport_channel(video_channel()); |
| 273 | } |
| 274 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 275 | rtc::PacketTransportInternal* video_rtcp_transport_channel() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 276 | return rtcp_transport_channel(video_channel()); |
| 277 | } |
| 278 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 279 | private: |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 280 | rtc::PacketTransportInternal* rtp_transport_channel( |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 281 | cricket::BaseChannel* ch) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 282 | if (!ch) { |
| 283 | return nullptr; |
| 284 | } |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 285 | return ch->rtp_dtls_transport(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 286 | } |
| 287 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 288 | rtc::PacketTransportInternal* rtcp_transport_channel( |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 289 | cricket::BaseChannel* ch) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 290 | if (!ch) { |
| 291 | return nullptr; |
| 292 | } |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 293 | return ch->rtcp_dtls_transport(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 294 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 295 | }; |
| 296 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 297 | class WebRtcSessionCreateSDPObserverForTest |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 298 | : public rtc::RefCountedObject<CreateSessionDescriptionObserver> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 299 | public: |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 300 | enum State { |
| 301 | kInit, |
| 302 | kFailed, |
| 303 | kSucceeded, |
| 304 | }; |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 305 | WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {} |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 306 | |
| 307 | // CreateSessionDescriptionObserver implementation. |
| 308 | virtual void OnSuccess(SessionDescriptionInterface* desc) { |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 309 | description_.reset(desc); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 310 | state_ = kSucceeded; |
| 311 | } |
| 312 | virtual void OnFailure(const std::string& error) { |
| 313 | state_ = kFailed; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 314 | } |
| 315 | |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 316 | SessionDescriptionInterface* description() { return description_.get(); } |
| 317 | |
| 318 | SessionDescriptionInterface* ReleaseDescription() { |
| 319 | return description_.release(); |
| 320 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 321 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 322 | State state() const { return state_; } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 323 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 324 | protected: |
| 325 | ~WebRtcSessionCreateSDPObserverForTest() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 326 | |
| 327 | private: |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 328 | std::unique_ptr<SessionDescriptionInterface> description_; |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 329 | State state_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 330 | }; |
| 331 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 332 | class WebRtcSessionTest |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 333 | : public testing::TestWithParam<RTCCertificateGenerationMethod>, |
| 334 | public sigslot::has_slots<> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 335 | protected: |
| 336 | // TODO Investigate why ChannelManager crashes, if it's created |
| 337 | // after stun_server. |
| 338 | WebRtcSessionTest() |
deadbeef | 98e186c | 2017-05-16 18:00:06 -0700 | [diff] [blame] | 339 | : vss_(new rtc::VirtualSocketServer()), |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 340 | fss_(new rtc::FirewallSocketServer(vss_.get())), |
| 341 | thread_(fss_.get()), |
| 342 | media_engine_(new cricket::FakeMediaEngine()), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 343 | data_engine_(new cricket::FakeDataEngine()), |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 344 | channel_manager_(new cricket::ChannelManager( |
| 345 | std::unique_ptr<cricket::MediaEngineInterface>(media_engine_), |
| 346 | std::unique_ptr<cricket::DataEngineInterface>(data_engine_), |
| 347 | rtc::Thread::Current())), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 348 | fake_call_(webrtc::Call::Config(&event_log_)), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 349 | tdesc_factory_(new cricket::TransportDescriptionFactory()), |
| 350 | desc_factory_( |
| 351 | new cricket::MediaSessionDescriptionFactory(channel_manager_.get(), |
| 352 | tdesc_factory_.get())), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 353 | stun_socket_addr_( |
| 354 | rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)), |
| 355 | stun_server_(cricket::TestStunServer::Create(Thread::Current(), |
| 356 | stun_socket_addr_)), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 357 | metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) { |
buildbot@webrtc.org | 51c5508 | 2014-07-28 22:26:15 +0000 | [diff] [blame] | 358 | cricket::ServerAddresses stun_servers; |
| 359 | stun_servers.insert(stun_socket_addr_); |
| 360 | allocator_.reset(new cricket::BasicPortAllocator( |
| 361 | &network_manager_, |
| 362 | stun_servers, |
| 363 | SocketAddress(), SocketAddress(), SocketAddress())); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 364 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 365 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 366 | EXPECT_TRUE(channel_manager_->Init()); |
buildbot@webrtc.org | 41451d4 | 2014-05-03 05:39:45 +0000 | [diff] [blame] | 367 | allocator_->set_step_delay(cricket::kMinimumStepDelay); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | void AddInterface(const SocketAddress& addr) { |
| 371 | network_manager_.AddInterface(addr); |
| 372 | } |
Honghai Zhang | 7fb69db | 2016-03-14 11:59:18 -0700 | [diff] [blame] | 373 | void RemoveInterface(const SocketAddress& addr) { |
| 374 | network_manager_.RemoveInterface(addr); |
| 375 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 376 | |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 377 | // If |cert_generator| != null or |rtc_configuration| contains |certificates| |
| 378 | // then DTLS will be enabled unless explicitly disabled by |rtc_configuration| |
| 379 | // options. When DTLS is enabled a certificate will be used if provided, |
| 380 | // otherwise one will be generated using the |cert_generator|. |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 381 | void Init( |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 382 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 383 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy, |
| 384 | const rtc::CryptoOptions& crypto_options) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 385 | ASSERT_TRUE(session_.get() == NULL); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 386 | fake_sctp_transport_factory_ = new FakeSctpTransportFactory(); |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 387 | session_.reset(new WebRtcSessionForTest(&fake_call_, |
| 388 | channel_manager_.get(), cricket::MediaConfig(), &event_log_, |
| 389 | rtc::Thread::Current(), rtc::Thread::Current(), |
zhihuang | 29ff844 | 2016-07-27 11:07:25 -0700 | [diff] [blame] | 390 | rtc::Thread::Current(), allocator_.get(), &observer_, |
| 391 | std::unique_ptr<cricket::TransportController>( |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 392 | new cricket::TransportController( |
| 393 | rtc::Thread::Current(), rtc::Thread::Current(), |
| 394 | allocator_.get(), |
| 395 | /*redetermine_role_on_ice_restart=*/true, crypto_options)), |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 396 | std::unique_ptr<FakeSctpTransportFactory>( |
| 397 | fake_sctp_transport_factory_))); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 398 | session_->SignalDataChannelOpenMessage.connect( |
| 399 | this, &WebRtcSessionTest::OnDataChannelOpenMessage); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 400 | |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 401 | configuration_.rtcp_mux_policy = rtcp_mux_policy; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 402 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 403 | observer_.ice_connection_state_); |
| 404 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 405 | observer_.ice_gathering_state_); |
| 406 | |
Henrik Boström | d03c23b | 2016-06-01 11:44:18 +0200 | [diff] [blame] | 407 | EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator), |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 408 | configuration_)); |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 409 | session_->set_metrics_observer(metrics_observer_); |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 410 | crypto_options_ = crypto_options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 411 | } |
| 412 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 413 | void OnDataChannelOpenMessage(const std::string& label, |
| 414 | const InternalDataChannelInit& config) { |
| 415 | last_data_channel_label_ = label; |
| 416 | last_data_channel_config_ = config; |
| 417 | } |
| 418 | |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 419 | void Init() { |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 420 | Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 421 | rtc::CryptoOptions()); |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 422 | } |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 423 | |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 424 | void InitWithBundlePolicy( |
| 425 | PeerConnectionInterface::BundlePolicy bundle_policy) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 426 | configuration_.bundle_policy = bundle_policy; |
| 427 | Init(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | void InitWithRtcpMuxPolicy( |
| 431 | PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
| 432 | PeerConnectionInterface::RTCConfiguration configuration; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 433 | Init(nullptr, rtcp_mux_policy, rtc::CryptoOptions()); |
| 434 | } |
| 435 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 436 | // Successfully init with DTLS; with a certificate generated and supplied or |
| 437 | // with a store that generates it for us. |
| 438 | void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 439 | std::unique_ptr<FakeRTCCertificateGenerator> cert_generator; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 440 | if (cert_gen_method == ALREADY_GENERATED) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 441 | configuration_.certificates.push_back( |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 442 | FakeRTCCertificateGenerator::GenerateCertificate()); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 443 | } else if (cert_gen_method == DTLS_IDENTITY_STORE) { |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 444 | cert_generator.reset(new FakeRTCCertificateGenerator()); |
| 445 | cert_generator->set_should_fail(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 446 | } else { |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 447 | RTC_CHECK(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 448 | } |
zhihuang | 4dfb8ce | 2016-11-23 10:30:12 -0800 | [diff] [blame] | 449 | Init(std::move(cert_generator), |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 450 | PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 451 | rtc::CryptoOptions()); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 452 | } |
| 453 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 454 | // The following convenience functions can be applied for both local side and |
| 455 | // remote side. The flags can be overwritten for different use cases. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 456 | void SendAudioVideoStream1() { |
| 457 | send_stream_1_ = true; |
| 458 | send_stream_2_ = false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 459 | local_send_audio_ = true; |
| 460 | local_send_video_ = true; |
| 461 | remote_send_audio_ = true; |
| 462 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void SendAudioVideoStream2() { |
| 466 | send_stream_1_ = false; |
| 467 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 468 | local_send_audio_ = true; |
| 469 | local_send_video_ = true; |
| 470 | remote_send_audio_ = true; |
| 471 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | void SendAudioVideoStream1And2() { |
| 475 | send_stream_1_ = true; |
| 476 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 477 | local_send_audio_ = true; |
| 478 | local_send_video_ = true; |
| 479 | remote_send_audio_ = true; |
| 480 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | void SendNothing() { |
| 484 | send_stream_1_ = false; |
| 485 | send_stream_2_ = false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 486 | local_send_audio_ = false; |
| 487 | local_send_video_ = false; |
| 488 | remote_send_audio_ = false; |
| 489 | remote_send_video_ = false; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | void SendAudioOnlyStream2() { |
| 493 | send_stream_1_ = false; |
| 494 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 495 | local_send_audio_ = true; |
| 496 | local_send_video_ = false; |
| 497 | remote_send_audio_ = true; |
| 498 | remote_send_video_ = false; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | void SendVideoOnlyStream2() { |
| 502 | send_stream_1_ = false; |
| 503 | send_stream_2_ = true; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 504 | local_send_audio_ = false; |
| 505 | local_send_video_ = true; |
| 506 | remote_send_audio_ = false; |
| 507 | remote_send_video_ = true; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 508 | } |
| 509 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 510 | // Helper function used to add a specific media section to the |
| 511 | // |session_options|. |
| 512 | void AddMediaSection(cricket::MediaType type, |
| 513 | const std::string& mid, |
| 514 | cricket::MediaContentDirection direction, |
| 515 | bool stopped, |
| 516 | cricket::MediaSessionOptions* opts) { |
| 517 | opts->media_description_options.push_back(cricket::MediaDescriptionOptions( |
| 518 | type, mid, |
| 519 | cricket::RtpTransceiverDirection::FromMediaContentDirection(direction), |
| 520 | stopped)); |
| 521 | } |
| 522 | |
| 523 | // Add the media sections to the options from |offered_media_sections_| when |
| 524 | // creating an answer or a new offer. |
| 525 | // This duplicates a lot of logic from PeerConnection but this can be fixed |
| 526 | // when PeerConnection and WebRtcSession are merged. |
| 527 | void AddExistingMediaSectionsAndSendersToOptions( |
| 528 | cricket::MediaSessionOptions* session_options, |
| 529 | bool send_audio, |
| 530 | bool recv_audio, |
| 531 | bool send_video, |
| 532 | bool recv_video) { |
| 533 | int num_sim_layer = 1; |
| 534 | for (auto media_description_options : offered_media_sections_) { |
| 535 | if (media_description_options.type == cricket::MEDIA_TYPE_AUDIO) { |
| 536 | bool stopped = !send_audio && !recv_audio; |
| 537 | auto media_desc_options = cricket::MediaDescriptionOptions( |
| 538 | cricket::MEDIA_TYPE_AUDIO, media_description_options.mid, |
| 539 | cricket::RtpTransceiverDirection(send_audio, recv_audio), stopped); |
| 540 | if (send_stream_1_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 541 | media_desc_options.AddAudioSender(kAudioTrack1, {kStream1}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 542 | } |
| 543 | if (send_stream_2_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 544 | media_desc_options.AddAudioSender(kAudioTrack2, {kStream2}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 545 | } |
| 546 | session_options->media_description_options.push_back( |
| 547 | media_desc_options); |
| 548 | } else if (media_description_options.type == cricket::MEDIA_TYPE_VIDEO) { |
| 549 | bool stopped = !send_video && !recv_video; |
| 550 | auto media_desc_options = cricket::MediaDescriptionOptions( |
| 551 | cricket::MEDIA_TYPE_VIDEO, media_description_options.mid, |
| 552 | cricket::RtpTransceiverDirection(send_video, recv_video), stopped); |
| 553 | if (send_stream_1_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 554 | media_desc_options.AddVideoSender(kVideoTrack1, {kStream1}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 555 | num_sim_layer); |
| 556 | } |
| 557 | if (send_stream_2_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 558 | media_desc_options.AddVideoSender(kVideoTrack2, {kStream2}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 559 | num_sim_layer); |
| 560 | } |
| 561 | session_options->media_description_options.push_back( |
| 562 | media_desc_options); |
| 563 | } else if (media_description_options.type == cricket::MEDIA_TYPE_DATA) { |
| 564 | session_options->media_description_options.push_back( |
| 565 | cricket::MediaDescriptionOptions( |
| 566 | cricket::MEDIA_TYPE_DATA, media_description_options.mid, |
| 567 | // Direction for data sections is meaningless, but legacy |
| 568 | // endpoints might expect sendrecv. |
| 569 | cricket::RtpTransceiverDirection(true, true), false)); |
| 570 | } else { |
| 571 | RTC_NOTREACHED(); |
| 572 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 573 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | // Add the existing media sections first and then add new media sections if |
| 577 | // needed. |
| 578 | void AddMediaSectionsAndSendersToOptions( |
| 579 | cricket::MediaSessionOptions* session_options, |
| 580 | bool send_audio, |
| 581 | bool recv_audio, |
| 582 | bool send_video, |
| 583 | bool recv_video) { |
| 584 | AddExistingMediaSectionsAndSendersToOptions( |
| 585 | session_options, send_audio, recv_audio, send_video, recv_video); |
| 586 | |
| 587 | if (!session_options->has_audio() && (send_audio || recv_audio)) { |
| 588 | cricket::MediaDescriptionOptions media_desc_options = |
| 589 | cricket::MediaDescriptionOptions( |
| 590 | cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO, |
| 591 | cricket::RtpTransceiverDirection(send_audio, recv_audio), |
| 592 | kActive); |
| 593 | if (send_stream_1_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 594 | media_desc_options.AddAudioSender(kAudioTrack1, {kStream1}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 595 | } |
| 596 | if (send_stream_2_ && send_audio) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 597 | media_desc_options.AddAudioSender(kAudioTrack2, {kStream2}); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 598 | } |
| 599 | session_options->media_description_options.push_back(media_desc_options); |
| 600 | offered_media_sections_.push_back(media_desc_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 601 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 602 | |
| 603 | if (!session_options->has_video() && (send_video || recv_video)) { |
| 604 | cricket::MediaDescriptionOptions media_desc_options = |
| 605 | cricket::MediaDescriptionOptions( |
| 606 | cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, |
| 607 | cricket::RtpTransceiverDirection(send_video, recv_video), |
| 608 | kActive); |
| 609 | int num_sim_layer = 1; |
| 610 | if (send_stream_1_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 611 | media_desc_options.AddVideoSender(kVideoTrack1, {kStream1}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 612 | num_sim_layer); |
| 613 | } |
| 614 | if (send_stream_2_ && send_video) { |
Steve Anton | 8ffb9c3 | 2017-08-31 15:45:38 -0700 | [diff] [blame] | 615 | media_desc_options.AddVideoSender(kVideoTrack2, {kStream2}, |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 616 | num_sim_layer); |
| 617 | } |
| 618 | session_options->media_description_options.push_back(media_desc_options); |
| 619 | offered_media_sections_.push_back(media_desc_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 620 | } |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 621 | |
| 622 | if (!session_options->has_data() && |
| 623 | (data_channel_ || |
| 624 | session_options->data_channel_type != cricket::DCT_NONE)) { |
| 625 | cricket::MediaDescriptionOptions media_desc_options = |
| 626 | cricket::MediaDescriptionOptions( |
| 627 | cricket::MEDIA_TYPE_DATA, cricket::CN_DATA, |
| 628 | cricket::RtpTransceiverDirection(true, true), kActive); |
| 629 | if (session_options->data_channel_type == cricket::DCT_RTP) { |
| 630 | media_desc_options.AddRtpDataChannel(data_channel_->label(), |
| 631 | data_channel_->label()); |
| 632 | } |
| 633 | session_options->media_description_options.push_back(media_desc_options); |
| 634 | offered_media_sections_.push_back(media_desc_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
| 638 | void GetOptionsForOffer( |
| 639 | const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options, |
| 640 | cricket::MediaSessionOptions* session_options) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 641 | ExtractSharedMediaSessionOptions(rtc_options, session_options); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 642 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 643 | // |recv_X| is true by default if |offer_to_receive_X| is undefined. |
| 644 | bool recv_audio = rtc_options.offer_to_receive_audio != 0; |
| 645 | bool recv_video = rtc_options.offer_to_receive_video != 0; |
| 646 | |
| 647 | AddMediaSectionsAndSendersToOptions(session_options, local_send_audio_, |
| 648 | recv_audio, local_send_video_, |
| 649 | recv_video); |
deadbeef | c80741f | 2015-10-22 13:14:45 -0700 | [diff] [blame] | 650 | session_options->bundle_enabled = |
| 651 | session_options->bundle_enabled && |
| 652 | (session_options->has_audio() || session_options->has_video() || |
| 653 | session_options->has_data()); |
| 654 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 655 | session_options->crypto_options = crypto_options_; |
| 656 | } |
| 657 | |
| 658 | void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { |
| 659 | AddExistingMediaSectionsAndSendersToOptions( |
| 660 | session_options, local_send_audio_, local_recv_audio_, |
| 661 | local_send_video_, local_recv_video_); |
| 662 | |
| 663 | session_options->bundle_enabled = |
| 664 | session_options->bundle_enabled && |
| 665 | (session_options->has_audio() || session_options->has_video() || |
| 666 | session_options->has_data()); |
| 667 | |
| 668 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 669 | session_options->data_channel_type = session_->data_channel_type(); |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 670 | } |
| 671 | |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 672 | session_options->crypto_options = crypto_options_; |
| 673 | } |
| 674 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 675 | void GetOptionsForRemoteAnswer( |
| 676 | cricket::MediaSessionOptions* session_options) { |
| 677 | bool recv_audio = local_send_audio_ || remote_recv_audio_; |
| 678 | bool recv_video = local_send_video_ || remote_recv_video_; |
| 679 | bool send_audio = false; |
| 680 | bool send_video = false; |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 681 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 682 | AddExistingMediaSectionsAndSendersToOptions( |
| 683 | session_options, send_audio, recv_audio, send_video, recv_video); |
| 684 | |
zhihuang | a77e6bb | 2017-08-14 18:17:48 -0700 | [diff] [blame] | 685 | session_options->bundle_enabled = |
| 686 | session_options->bundle_enabled && |
| 687 | (session_options->has_audio() || session_options->has_video() || |
| 688 | session_options->has_data()); |
| 689 | |
| 690 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 691 | session_options->data_channel_type = session_->data_channel_type(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 692 | } |
jbauch | cb56065 | 2016-08-04 05:20:32 -0700 | [diff] [blame] | 693 | |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 694 | session_options->crypto_options = crypto_options_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 695 | } |
| 696 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 697 | void GetOptionsForAudioOnlyRemoteOffer( |
| 698 | cricket::MediaSessionOptions* session_options) { |
| 699 | remote_recv_audio_ = true; |
| 700 | remote_recv_video_ = false; |
| 701 | GetOptionsForRemoteOffer(session_options); |
| 702 | } |
| 703 | |
| 704 | void GetOptionsForRemoteOffer(cricket::MediaSessionOptions* session_options) { |
| 705 | AddMediaSectionsAndSendersToOptions(session_options, remote_send_audio_, |
| 706 | remote_recv_audio_, remote_send_video_, |
| 707 | remote_recv_video_); |
| 708 | session_options->bundle_enabled = |
| 709 | (session_options->has_audio() || session_options->has_video() || |
| 710 | session_options->has_data()); |
| 711 | |
| 712 | if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 713 | session_options->data_channel_type = session_->data_channel_type(); |
| 714 | } |
| 715 | |
| 716 | session_options->crypto_options = crypto_options_; |
| 717 | } |
| 718 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 719 | // Creates a local offer and applies it. Starts ICE. |
| 720 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 721 | // to decide which streams to create. |
| 722 | void InitiateCall() { |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 723 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 724 | SetLocalDescriptionWithoutError(offer); |
| 725 | EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 726 | observer_.ice_gathering_state_, |
| 727 | kIceCandidatesTimeout); |
| 728 | } |
| 729 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 730 | SessionDescriptionInterface* CreateOffer() { |
| 731 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 732 | options.offer_to_receive_audio = |
| 733 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 734 | return CreateOffer(options); |
| 735 | } |
| 736 | |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 737 | SessionDescriptionInterface* CreateOffer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 738 | const PeerConnectionInterface::RTCOfferAnswerOptions options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 739 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 740 | observer = new WebRtcSessionCreateSDPObserverForTest(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 741 | cricket::MediaSessionOptions session_options; |
| 742 | GetOptionsForOffer(options, &session_options); |
| 743 | session_->CreateOffer(observer, options, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 744 | EXPECT_TRUE_WAIT( |
| 745 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 746 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 747 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 748 | } |
| 749 | |
| 750 | SessionDescriptionInterface* CreateAnswer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 751 | const cricket::MediaSessionOptions& options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 752 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 753 | = new WebRtcSessionCreateSDPObserverForTest(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 754 | cricket::MediaSessionOptions session_options = options; |
| 755 | GetOptionsForAnswer(&session_options); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 756 | session_->CreateAnswer(observer, session_options); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 757 | EXPECT_TRUE_WAIT( |
| 758 | observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 759 | 2000); |
mallinath@webrtc.org | a550669 | 2013-08-12 21:18:15 +0000 | [diff] [blame] | 760 | return observer->ReleaseDescription(); |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 761 | } |
| 762 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 763 | SessionDescriptionInterface* CreateAnswer() { |
| 764 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 765 | options.bundle_enabled = true; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 766 | return CreateAnswer(options); |
| 767 | } |
| 768 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 769 | // Set the internal fake description factories to do DTLS-SRTP. |
| 770 | void SetFactoryDtlsSrtp() { |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 771 | desc_factory_->set_secure(cricket::SEC_DISABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 772 | std::string identity_name = "WebRTC" + |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 773 | rtc::ToString(rtc::CreateRandomId()); |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 774 | // Confirmed to work with KT_RSA and KT_ECDSA. |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 775 | tdesc_factory_->set_certificate( |
jbauch | 555604a | 2016-04-26 03:13:22 -0700 | [diff] [blame] | 776 | rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 777 | rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 778 | tdesc_factory_->set_secure(cricket::SEC_REQUIRED); |
| 779 | } |
| 780 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 781 | // Compares ufrag/password only for the specified |media_type|. |
| 782 | bool IceUfragPwdEqual(const cricket::SessionDescription* desc1, |
| 783 | const cricket::SessionDescription* desc2, |
| 784 | cricket::MediaType media_type) { |
| 785 | if (desc1->contents().size() != desc2->contents().size()) { |
| 786 | return false; |
| 787 | } |
| 788 | |
| 789 | const cricket::ContentInfo* cinfo = |
| 790 | cricket::GetFirstMediaContent(desc1->contents(), media_type); |
| 791 | const cricket::TransportDescription* transport_desc1 = |
| 792 | desc1->GetTransportDescriptionByName(cinfo->name); |
| 793 | const cricket::TransportDescription* transport_desc2 = |
| 794 | desc2->GetTransportDescriptionByName(cinfo->name); |
| 795 | if (!transport_desc1 || !transport_desc2) { |
| 796 | return false; |
| 797 | } |
| 798 | if (transport_desc1->ice_pwd != transport_desc2->ice_pwd || |
| 799 | transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) { |
| 800 | return false; |
| 801 | } |
| 802 | return true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 803 | } |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 804 | |
deadbeef | 0ed85b2 | 2016-02-23 17:24:52 -0800 | [diff] [blame] | 805 | // Sets ufrag/pwd for specified |media_type|. |
| 806 | void SetIceUfragPwd(SessionDescriptionInterface* current_desc, |
| 807 | cricket::MediaType media_type, |
| 808 | const std::string& ufrag, |
| 809 | const std::string& pwd) { |
| 810 | cricket::SessionDescription* desc = current_desc->description(); |
| 811 | const cricket::ContentInfo* cinfo = |
| 812 | cricket::GetFirstMediaContent(desc->contents(), media_type); |
| 813 | TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name); |
| 814 | cricket::TransportDescription* transport_desc = |
| 815 | &transport_info->description; |
| 816 | transport_desc->ice_ufrag = ufrag; |
| 817 | transport_desc->ice_pwd = pwd; |
| 818 | } |
| 819 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 820 | // Creates a remote offer and and applies it as a remote description, |
| 821 | // creates a local answer and applies is as a local description. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 822 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 823 | // to decide which local and remote streams to create. |
| 824 | void CreateAndSetRemoteOfferAndLocalAnswer() { |
| 825 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 826 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 827 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 828 | SetLocalDescriptionWithoutError(answer); |
| 829 | } |
| 830 | void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 831 | ASSERT_TRUE(session_->SetLocalDescription(desc, nullptr)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 832 | session_->MaybeStartGathering(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 833 | } |
| 834 | void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 835 | WebRtcSession::State expected_state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 836 | SetLocalDescriptionWithoutError(desc); |
| 837 | EXPECT_EQ(expected_state, session_->state()); |
| 838 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 839 | void SetLocalDescriptionExpectError(const std::string& action, |
| 840 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 841 | SessionDescriptionInterface* desc) { |
| 842 | std::string error; |
| 843 | EXPECT_FALSE(session_->SetLocalDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 844 | std::string sdp_type = "local "; |
| 845 | sdp_type.append(action); |
| 846 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 847 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 848 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 849 | void SetLocalDescriptionOfferExpectError(const std::string& expected_error, |
| 850 | SessionDescriptionInterface* desc) { |
| 851 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 852 | expected_error, desc); |
| 853 | } |
| 854 | void SetLocalDescriptionAnswerExpectError(const std::string& expected_error, |
| 855 | SessionDescriptionInterface* desc) { |
| 856 | SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 857 | expected_error, desc); |
| 858 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 859 | void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) { |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 860 | ASSERT_TRUE(session_->SetRemoteDescription(desc, nullptr)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 861 | } |
| 862 | void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 863 | WebRtcSession::State expected_state) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 864 | SetRemoteDescriptionWithoutError(desc); |
| 865 | EXPECT_EQ(expected_state, session_->state()); |
| 866 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 867 | void SetRemoteDescriptionExpectError(const std::string& action, |
| 868 | const std::string& expected_error, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 869 | SessionDescriptionInterface* desc) { |
| 870 | std::string error; |
| 871 | EXPECT_FALSE(session_->SetRemoteDescription(desc, &error)); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 872 | std::string sdp_type = "remote "; |
| 873 | sdp_type.append(action); |
| 874 | EXPECT_NE(std::string::npos, error.find(sdp_type)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 875 | EXPECT_NE(std::string::npos, error.find(expected_error)); |
| 876 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 877 | void SetRemoteDescriptionOfferExpectError( |
| 878 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 879 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer, |
| 880 | expected_error, desc); |
| 881 | } |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 882 | void SetRemoteDescriptionAnswerExpectError( |
| 883 | const std::string& expected_error, SessionDescriptionInterface* desc) { |
| 884 | SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer, |
| 885 | expected_error, desc); |
| 886 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 887 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 888 | JsepSessionDescription* CreateRemoteOfferWithVersion( |
| 889 | cricket::MediaSessionOptions options, |
| 890 | cricket::SecurePolicy secure_policy, |
| 891 | const std::string& session_version, |
| 892 | const SessionDescriptionInterface* current_desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 893 | std::string session_id = rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 894 | const cricket::SessionDescription* cricket_desc = NULL; |
| 895 | if (current_desc) { |
| 896 | cricket_desc = current_desc->description(); |
| 897 | session_id = current_desc->session_id(); |
| 898 | } |
| 899 | |
| 900 | desc_factory_->set_secure(secure_policy); |
| 901 | JsepSessionDescription* offer( |
| 902 | new JsepSessionDescription(JsepSessionDescription::kOffer)); |
| 903 | if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc), |
| 904 | session_id, session_version)) { |
| 905 | delete offer; |
| 906 | offer = NULL; |
| 907 | } |
| 908 | return offer; |
| 909 | } |
| 910 | JsepSessionDescription* CreateRemoteOffer( |
| 911 | cricket::MediaSessionOptions options) { |
| 912 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 913 | kSessionVersion, NULL); |
| 914 | } |
| 915 | JsepSessionDescription* CreateRemoteOffer( |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 916 | cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) { |
| 917 | return CreateRemoteOfferWithVersion( |
| 918 | options, sdes_policy, kSessionVersion, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 919 | } |
| 920 | JsepSessionDescription* CreateRemoteOffer( |
| 921 | cricket::MediaSessionOptions options, |
| 922 | const SessionDescriptionInterface* current_desc) { |
| 923 | return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED, |
| 924 | kSessionVersion, current_desc); |
| 925 | } |
| 926 | |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 927 | SessionDescriptionInterface* CreateRemoteOfferWithSctpPort( |
| 928 | const char* sctp_stream_name, |
| 929 | int new_port, |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 930 | cricket::MediaSessionOptions options) { |
| 931 | options.data_channel_type = cricket::DCT_SCTP; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 932 | GetOptionsForRemoteOffer(&options); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 933 | return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options)); |
| 934 | } |
| 935 | |
| 936 | // Takes ownership of offer_basis (and deletes it). |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 937 | SessionDescriptionInterface* ChangeSDPSctpPort( |
| 938 | int new_port, |
| 939 | webrtc::SessionDescriptionInterface* offer_basis) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 940 | // Stringify the input SDP, swap the 5000 for 'new_port' and create a new |
| 941 | // SessionDescription from the mutated string. |
| 942 | const char* default_port_str = "5000"; |
| 943 | char new_port_str[16]; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 944 | 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] | 945 | std::string offer_str; |
| 946 | offer_basis->ToString(&offer_str); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 947 | rtc::replace_substrs(default_port_str, strlen(default_port_str), |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 948 | new_port_str, strlen(new_port_str), |
| 949 | &offer_str); |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 950 | SessionDescriptionInterface* offer = |
| 951 | CreateSessionDescription(offer_basis->type(), offer_str, nullptr); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 952 | delete offer_basis; |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 953 | return offer; |
| 954 | } |
| 955 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 956 | // Create a remote offer. Call SendAudioVideoStreamX() |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 957 | // before this function to decide which streams to create. |
| 958 | JsepSessionDescription* CreateRemoteOffer() { |
| 959 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 960 | GetOptionsForRemoteOffer(&options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 961 | return CreateRemoteOffer(options, session_->remote_description()); |
| 962 | } |
| 963 | |
| 964 | JsepSessionDescription* CreateRemoteAnswer( |
| 965 | const SessionDescriptionInterface* offer, |
| 966 | cricket::MediaSessionOptions options, |
| 967 | cricket::SecurePolicy policy) { |
| 968 | desc_factory_->set_secure(policy); |
| 969 | const std::string session_id = |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 970 | rtc::ToString(rtc::CreateRandomId64()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 971 | JsepSessionDescription* answer( |
| 972 | new JsepSessionDescription(JsepSessionDescription::kAnswer)); |
| 973 | if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(), |
| 974 | options, NULL), |
| 975 | session_id, kSessionVersion)) { |
| 976 | delete answer; |
| 977 | answer = NULL; |
| 978 | } |
| 979 | return answer; |
| 980 | } |
| 981 | |
| 982 | JsepSessionDescription* CreateRemoteAnswer( |
| 983 | const SessionDescriptionInterface* offer, |
| 984 | cricket::MediaSessionOptions options) { |
| 985 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 986 | } |
| 987 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 988 | // Creates an answer session description. |
| 989 | // Call SendAudioVideoStreamX() before this function |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 990 | // to decide which streams to create. |
| 991 | JsepSessionDescription* CreateRemoteAnswer( |
| 992 | const SessionDescriptionInterface* offer) { |
| 993 | cricket::MediaSessionOptions options; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 994 | GetOptionsForAnswer(&options); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 995 | options.bundle_enabled = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 996 | return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED); |
| 997 | } |
| 998 | |
| 999 | void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1000 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1001 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1002 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1003 | |
| 1004 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1005 | options.use_rtp_mux = bundle; |
| 1006 | |
| 1007 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1008 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 1009 | // and answer. |
| 1010 | SetLocalDescriptionWithoutError(offer); |
| 1011 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1012 | std::unique_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 1013 | CreateRemoteAnswer(session_->local_description())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1014 | std::string sdp; |
| 1015 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 1016 | |
| 1017 | size_t expected_candidate_num = 2; |
| 1018 | if (!rtcp_mux) { |
| 1019 | // If rtcp_mux is enabled we should expect 4 candidates - host and srflex |
| 1020 | // for rtp and rtcp. |
| 1021 | expected_candidate_num = 4; |
| 1022 | // Disable rtcp-mux from the answer |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1023 | const std::string kRtcpMux = "a=rtcp-mux"; |
| 1024 | const std::string kXRtcpMux = "a=xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1025 | rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1026 | kXRtcpMux.c_str(), kXRtcpMux.length(), |
| 1027 | &sdp); |
| 1028 | } |
| 1029 | |
| 1030 | SessionDescriptionInterface* new_answer = CreateSessionDescription( |
| 1031 | JsepSessionDescription::kAnswer, sdp, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1032 | |
| 1033 | // SetRemoteDescription to enable rtcp mux. |
henrike@webrtc.org | 723d683 | 2013-07-12 16:04:50 +0000 | [diff] [blame] | 1034 | SetRemoteDescriptionWithoutError(new_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1035 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1036 | EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1037 | if (bundle) { |
| 1038 | EXPECT_EQ(0, observer_.mline_1_candidates_.size()); |
| 1039 | } else { |
| 1040 | EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1041 | } |
| 1042 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1043 | |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 1044 | bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc, |
| 1045 | const std::string& codec_name) { |
| 1046 | for (const auto& content : desc->description()->contents()) { |
| 1047 | if (static_cast<cricket::MediaContentDescription*>(content.description) |
| 1048 | ->type() == cricket::MEDIA_TYPE_VIDEO) { |
| 1049 | const auto* mdesc = |
| 1050 | static_cast<cricket::VideoContentDescription*>(content.description); |
| 1051 | for (const auto& codec : mdesc->codecs()) { |
| 1052 | if (codec.name == codec_name) { |
| 1053 | return true; |
| 1054 | } |
| 1055 | } |
| 1056 | } |
| 1057 | } |
| 1058 | return false; |
| 1059 | } |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1060 | // Helper class to configure loopback network and verify Best |
| 1061 | // Connection using right IP protocol for TestLoopbackCall |
| 1062 | // method. LoopbackNetworkManager applies firewall rules to block |
| 1063 | // all ping traffic once ICE completed, and remove them to observe |
| 1064 | // ICE reconnected again. This LoopbackNetworkConfiguration struct |
| 1065 | // verifies the best connection is using the right IP protocol after |
| 1066 | // initial ICE convergences. |
| 1067 | |
| 1068 | class LoopbackNetworkConfiguration { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1069 | public: |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1070 | LoopbackNetworkConfiguration() |
| 1071 | : test_ipv6_network_(false), |
| 1072 | test_extra_ipv4_network_(false), |
| 1073 | best_connection_after_initial_ice_converged_(1, 0) {} |
| 1074 | |
| 1075 | // Used to track the expected best connection count in each IP protocol. |
| 1076 | struct ExpectedBestConnection { |
| 1077 | ExpectedBestConnection(int ipv4_count, int ipv6_count) |
| 1078 | : ipv4_count_(ipv4_count), |
| 1079 | ipv6_count_(ipv6_count) {} |
| 1080 | |
| 1081 | int ipv4_count_; |
| 1082 | int ipv6_count_; |
| 1083 | }; |
| 1084 | |
| 1085 | bool test_ipv6_network_; |
| 1086 | bool test_extra_ipv4_network_; |
| 1087 | ExpectedBestConnection best_connection_after_initial_ice_converged_; |
| 1088 | |
| 1089 | void VerifyBestConnectionAfterIceConverge( |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1090 | const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const { |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1091 | Verify(metrics_observer, best_connection_after_initial_ice_converged_); |
| 1092 | } |
| 1093 | |
| 1094 | private: |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1095 | void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer, |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1096 | const ExpectedBestConnection& expected) const { |
| 1097 | EXPECT_EQ( |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1098 | metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily, |
| 1099 | webrtc::kBestConnections_IPv4), |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1100 | expected.ipv4_count_); |
| 1101 | EXPECT_EQ( |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1102 | metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily, |
| 1103 | webrtc::kBestConnections_IPv6), |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1104 | expected.ipv6_count_); |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1105 | // This is used in the loopback call so there is only single host to host |
| 1106 | // candidate pair. |
| 1107 | EXPECT_EQ(metrics_observer->GetEnumCounter( |
| 1108 | webrtc::kEnumCounterIceCandidatePairTypeUdp, |
| 1109 | webrtc::kIceCandidatePairHostHost), |
Guo-wei Shieh | 3cc834a | 2015-09-04 15:52:14 -0700 | [diff] [blame] | 1110 | 0); |
| 1111 | EXPECT_EQ(metrics_observer->GetEnumCounter( |
| 1112 | webrtc::kEnumCounterIceCandidatePairTypeUdp, |
| 1113 | webrtc::kIceCandidatePairHostPublicHostPublic), |
Guo-wei Shieh | 3d564c1 | 2015-08-19 16:51:15 -0700 | [diff] [blame] | 1114 | 1); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1115 | } |
| 1116 | }; |
| 1117 | |
| 1118 | class LoopbackNetworkManager { |
| 1119 | public: |
| 1120 | LoopbackNetworkManager(WebRtcSessionTest* session, |
| 1121 | const LoopbackNetworkConfiguration& config) |
| 1122 | : config_(config) { |
| 1123 | session->AddInterface( |
| 1124 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1125 | if (config_.test_extra_ipv4_network_) { |
| 1126 | session->AddInterface( |
| 1127 | rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
| 1128 | } |
| 1129 | if (config_.test_ipv6_network_) { |
| 1130 | session->AddInterface( |
| 1131 | rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort)); |
| 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | void ApplyFirewallRules(rtc::FirewallSocketServer* fss) { |
| 1136 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1137 | rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 1138 | if (config_.test_extra_ipv4_network_) { |
| 1139 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1140 | rtc::SocketAddress(kClientAddrHost2, kClientAddrPort)); |
| 1141 | } |
| 1142 | if (config_.test_ipv6_network_) { |
| 1143 | fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, |
| 1144 | rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort)); |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); } |
| 1149 | |
| 1150 | private: |
| 1151 | LoopbackNetworkConfiguration config_; |
| 1152 | }; |
| 1153 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1154 | // The method sets up a call from the session to itself, in a loopback |
| 1155 | // arrangement. It also uses a firewall rule to create a temporary |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1156 | // disconnection, and then a permanent disconnection. |
| 1157 | // 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] | 1158 | // by multiple tests with different allocators (e.g. with and without BUNDLE). |
| 1159 | // While running the call, this method also checks if the session goes through |
| 1160 | // the correct sequence of ICE states when a connection is established, |
| 1161 | // broken, and re-established. |
| 1162 | // The Connection state should go: |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1163 | // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed |
| 1164 | // -> Failed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1165 | // The Gathering state should go: New -> Gathering -> Completed. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1166 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1167 | void SetupLoopbackCall() { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1168 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1169 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1170 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1171 | |
| 1172 | EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 1173 | observer_.ice_gathering_state_); |
| 1174 | SetLocalDescriptionWithoutError(offer); |
| 1175 | EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 1176 | observer_.ice_connection_state_); |
| 1177 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1178 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1179 | EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
| 1180 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1181 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1182 | |
| 1183 | std::string sdp; |
| 1184 | offer->ToString(&sdp); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1185 | SessionDescriptionInterface* desc = webrtc::CreateSessionDescription( |
| 1186 | JsepSessionDescription::kAnswer, sdp, nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1187 | ASSERT_TRUE(desc != NULL); |
| 1188 | SetRemoteDescriptionWithoutError(desc); |
| 1189 | |
| 1190 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1191 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 1192 | |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1193 | // The ice connection state is "Connected" too briefly to catch in a test. |
| 1194 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1195 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 1196 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1197 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1198 | void TestLoopbackCall(const LoopbackNetworkConfiguration& config) { |
| 1199 | LoopbackNetworkManager loopback_network_manager(this, config); |
| 1200 | SetupLoopbackCall(); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1201 | config.VerifyBestConnectionAfterIceConverge(metrics_observer_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1202 | // Adding firewall rule to block ping requests, which should cause |
| 1203 | // transport channel failure. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1204 | |
| 1205 | loopback_network_manager.ApplyFirewallRules(fss_.get()); |
| 1206 | |
| 1207 | LOG(LS_INFO) << "Firewall Rules applied"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1208 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 1209 | observer_.ice_connection_state_, |
| 1210 | kIceCandidatesTimeout); |
| 1211 | |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1212 | metrics_observer_->Reset(); |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1213 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1214 | // Clearing the rules, session should move back to completed state. |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1215 | loopback_network_manager.ClearRules(fss_.get()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1216 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1217 | LOG(LS_INFO) << "Firewall Rules cleared"; |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1218 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1219 | observer_.ice_connection_state_, |
| 1220 | kIceCandidatesTimeout); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1221 | |
| 1222 | // Now we block ping requests and wait until the ICE connection transitions |
| 1223 | // to the Failed state. This will take at least 30 seconds because it must |
| 1224 | // wait for the Port to timeout. |
| 1225 | int port_timeout = 30000; |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1226 | |
| 1227 | loopback_network_manager.ApplyFirewallRules(fss_.get()); |
| 1228 | LOG(LS_INFO) << "Firewall Rules applied again"; |
jlmiller@webrtc.org | 804eb46 | 2015-02-20 02:20:03 +0000 | [diff] [blame] | 1229 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1230 | observer_.ice_connection_state_, |
| 1231 | kIceCandidatesTimeout + port_timeout); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 1234 | void TestLoopbackCall() { |
| 1235 | LoopbackNetworkConfiguration config; |
| 1236 | TestLoopbackCall(config); |
| 1237 | } |
| 1238 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1239 | void TestPacketOptions() { |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1240 | LoopbackNetworkConfiguration config; |
| 1241 | LoopbackNetworkManager loopback_network_manager(this, config); |
| 1242 | |
| 1243 | SetupLoopbackCall(); |
| 1244 | |
Danil Chapovalov | 33b01f2 | 2016-05-11 19:55:27 +0200 | [diff] [blame] | 1245 | // Wait for channel to be ready for sending. |
| 1246 | EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1247 | uint8_t test_packet[15] = {0}; |
| 1248 | rtc::PacketOptions options; |
| 1249 | options.packet_id = 10; |
| 1250 | media_engine_->GetVideoChannel(0) |
| 1251 | ->SendRtp(test_packet, sizeof(test_packet), options); |
| 1252 | |
| 1253 | const int kPacketTimeout = 2000; |
deadbeef | 14461d4 | 2016-06-15 11:06:57 -0700 | [diff] [blame] | 1254 | EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(), |
| 1255 | kPacketTimeout); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1256 | EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1); |
| 1257 | } |
| 1258 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1259 | // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory. |
| 1260 | void AddCNCodecs() { |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 1261 | const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1); |
| 1262 | const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1263 | |
| 1264 | // Add kCNCodec for dtmf test. |
ossu | dedfd28 | 2016-06-14 07:12:39 -0700 | [diff] [blame] | 1265 | std::vector<cricket::AudioCodec> codecs = |
| 1266 | media_engine_->audio_send_codecs(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1267 | codecs.push_back(kCNCodec1); |
| 1268 | codecs.push_back(kCNCodec2); |
| 1269 | media_engine_->SetAudioCodecs(codecs); |
ossu | 075af92 | 2016-06-14 03:29:38 -0700 | [diff] [blame] | 1270 | desc_factory_->set_audio_codecs(codecs, codecs); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
| 1274 | const cricket::ContentDescription* description = content->description; |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1275 | RTC_CHECK(description != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1276 | const cricket::AudioContentDescription* audio_content_desc = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1277 | static_cast<const cricket::AudioContentDescription*>(description); |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1278 | RTC_CHECK(audio_content_desc != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1279 | for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
| 1280 | if (audio_content_desc->codecs()[i].name == "CN") |
| 1281 | return false; |
| 1282 | } |
| 1283 | return true; |
| 1284 | } |
| 1285 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1286 | void CreateDataChannel() { |
deadbeef | fc648b6 | 2015-10-13 16:42:33 -0700 | [diff] [blame] | 1287 | webrtc::InternalDataChannelInit dci; |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 1288 | RTC_CHECK(session_.get()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1289 | dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP; |
| 1290 | data_channel_ = DataChannel::Create( |
| 1291 | session_.get(), session_->data_channel_type(), "datachannel", dci); |
| 1292 | } |
| 1293 | |
| 1294 | void SetLocalDescriptionWithDataChannel() { |
| 1295 | CreateDataChannel(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1296 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1297 | SetLocalDescriptionWithoutError(offer); |
| 1298 | } |
| 1299 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 1300 | webrtc::RtcEventLogNullImpl event_log_; |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 1301 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 1302 | std::unique_ptr<rtc::FirewallSocketServer> fss_; |
| 1303 | rtc::AutoSocketServerThread thread_; |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 1304 | // |media_engine_| and |data_engine_| are actually owned by |
| 1305 | // |channel_manager_|. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1306 | cricket::FakeMediaEngine* media_engine_; |
| 1307 | cricket::FakeDataEngine* data_engine_; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 1308 | // Actually owned by session_. |
| 1309 | FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1310 | std::unique_ptr<cricket::ChannelManager> channel_manager_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1311 | cricket::FakeCall fake_call_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1312 | std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_; |
| 1313 | std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1314 | rtc::SocketAddress stun_socket_addr_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1315 | std::unique_ptr<cricket::TestStunServer> stun_server_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1316 | rtc::FakeNetworkManager network_manager_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1317 | std::unique_ptr<cricket::BasicPortAllocator> allocator_; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1318 | PeerConnectionFactoryInterface::Options options_; |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1319 | PeerConnectionInterface::RTCConfiguration configuration_; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1320 | std::unique_ptr<WebRtcSessionForTest> session_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1321 | MockIceObserver observer_; |
| 1322 | cricket::FakeVideoMediaChannel* video_channel_; |
| 1323 | cricket::FakeVoiceMediaChannel* voice_channel_; |
jbauch | ac8869e | 2015-07-03 01:36:14 -0700 | [diff] [blame] | 1324 | rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1325 | // The following flags affect options created for CreateOffer/CreateAnswer. |
| 1326 | bool send_stream_1_ = false; |
| 1327 | bool send_stream_2_ = false; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1328 | bool local_send_audio_ = false; |
| 1329 | bool local_send_video_ = false; |
| 1330 | bool local_recv_audio_ = true; |
| 1331 | bool local_recv_video_ = true; |
| 1332 | bool remote_send_audio_ = false; |
| 1333 | bool remote_send_video_ = false; |
| 1334 | bool remote_recv_audio_ = true; |
| 1335 | bool remote_recv_video_ = true; |
| 1336 | std::vector<cricket::MediaDescriptionOptions> offered_media_sections_; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1337 | rtc::scoped_refptr<DataChannel> data_channel_; |
| 1338 | // Last values received from data channel creation signal. |
| 1339 | std::string last_data_channel_label_; |
| 1340 | InternalDataChannelInit last_data_channel_config_; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 1341 | rtc::CryptoOptions crypto_options_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1342 | }; |
| 1343 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1344 | TEST_F(WebRtcSessionTest, TestSessionCandidates) { |
| 1345 | TestSessionCandidatesWithBundleRtcpMux(false, false); |
| 1346 | } |
| 1347 | |
| 1348 | // Below test cases (TestSessionCandidatesWith*) verify the candidates gathered |
| 1349 | // with rtcp-mux and/or bundle. |
| 1350 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) { |
| 1351 | TestSessionCandidatesWithBundleRtcpMux(false, true); |
| 1352 | } |
| 1353 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1354 | TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) { |
| 1355 | TestSessionCandidatesWithBundleRtcpMux(true, true); |
| 1356 | } |
| 1357 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1358 | TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1359 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1360 | SessionDescriptionInterface* offer = NULL; |
| 1361 | // Since |offer| is NULL, there's no way to tell if it's an offer or answer. |
| 1362 | std::string unknown_action; |
| 1363 | SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1364 | SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer); |
| 1365 | } |
| 1366 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1367 | // Test creating offers and receive answers and make sure the |
| 1368 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1369 | TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1370 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1371 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1372 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1373 | const std::string session_id_orig = offer->session_id(); |
| 1374 | const std::string session_version_orig = offer->session_version(); |
| 1375 | SetLocalDescriptionWithoutError(offer); |
| 1376 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1377 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1378 | SessionDescriptionInterface* answer = |
| 1379 | CreateRemoteAnswer(session_->local_description()); |
| 1380 | SetRemoteDescriptionWithoutError(answer); |
| 1381 | |
| 1382 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1383 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1384 | |
| 1385 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1386 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1387 | |
| 1388 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1389 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1390 | |
| 1391 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1392 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1393 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1394 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1395 | |
| 1396 | // Create new offer without send streams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1397 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1398 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1399 | |
| 1400 | // Verify the session id is the same and the session version is |
| 1401 | // increased. |
| 1402 | EXPECT_EQ(session_id_orig, offer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1403 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1404 | rtc::FromString<uint64_t>(offer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1405 | |
| 1406 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1407 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1408 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1409 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1410 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1411 | answer = CreateRemoteAnswer(session_->local_description()); |
| 1412 | SetRemoteDescriptionWithoutError(answer); |
| 1413 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1414 | // Make sure the receive streams have not changed. |
| 1415 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1416 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1417 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1418 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1419 | } |
| 1420 | |
| 1421 | // Test receiving offers and creating answers and make sure the |
| 1422 | // media engine creates the expected send and receive streams. |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 1423 | TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1424 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1425 | SendAudioVideoStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1426 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1427 | SetRemoteDescriptionWithoutError(offer); |
| 1428 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1429 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1430 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1431 | SetLocalDescriptionWithoutError(answer); |
| 1432 | |
| 1433 | const std::string session_id_orig = answer->session_id(); |
| 1434 | const std::string session_version_orig = answer->session_version(); |
| 1435 | |
| 1436 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 1437 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 1438 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1439 | ASSERT_TRUE(video_channel_); |
| 1440 | ASSERT_TRUE(voice_channel_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1441 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 1442 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id); |
| 1443 | |
| 1444 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 1445 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id); |
| 1446 | |
| 1447 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 1448 | EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id); |
| 1449 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 1450 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id); |
| 1451 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1452 | SendAudioVideoStream1And2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1453 | offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1454 | SetRemoteDescriptionWithoutError(offer); |
| 1455 | |
| 1456 | // Answer by turning off all send streams. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1457 | SendNothing(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1458 | answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1459 | |
| 1460 | // Verify the session id is the same and the session version is |
| 1461 | // increased. |
| 1462 | EXPECT_EQ(session_id_orig, answer->session_id()); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1463 | EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig), |
| 1464 | rtc::FromString<uint64_t>(answer->session_version())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1465 | SetLocalDescriptionWithoutError(answer); |
| 1466 | |
| 1467 | ASSERT_EQ(2u, video_channel_->recv_streams().size()); |
| 1468 | EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id); |
| 1469 | EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id); |
| 1470 | ASSERT_EQ(2u, voice_channel_->recv_streams().size()); |
| 1471 | EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id); |
| 1472 | EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id); |
| 1473 | |
| 1474 | // Make sure we have no send streams. |
| 1475 | EXPECT_EQ(0u, video_channel_->send_streams().size()); |
| 1476 | EXPECT_EQ(0u, voice_channel_->send_streams().size()); |
| 1477 | } |
| 1478 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1479 | TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1480 | Init(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1481 | media_engine_->set_fail_create_channel(true); |
| 1482 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1483 | SessionDescriptionInterface* offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1484 | ASSERT_TRUE(offer != NULL); |
| 1485 | // SetRemoteDescription and SetLocalDescription will take the ownership of |
| 1486 | // the offer. |
| 1487 | SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1488 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1489 | ASSERT_TRUE(offer != NULL); |
| 1490 | SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer); |
| 1491 | } |
| 1492 | |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1493 | // Test that we can create and set an answer correctly when different |
| 1494 | // SSL roles have been negotiated for different transports. |
| 1495 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525 |
| 1496 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) { |
| 1497 | SendAudioVideoStream1(); |
| 1498 | InitWithDtls(GetParam()); |
| 1499 | SetFactoryDtlsSrtp(); |
| 1500 | |
| 1501 | SessionDescriptionInterface* offer = CreateOffer(); |
| 1502 | SetLocalDescriptionWithoutError(offer); |
| 1503 | |
| 1504 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1505 | GetOptionsForAnswer(&options); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1506 | |
| 1507 | // First, negotiate different SSL roles. |
| 1508 | SessionDescriptionInterface* answer = |
| 1509 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 1510 | TransportInfo* audio_transport_info = |
| 1511 | answer->description()->GetTransportInfoByName("audio"); |
| 1512 | audio_transport_info->description.connection_role = |
| 1513 | cricket::CONNECTIONROLE_ACTIVE; |
| 1514 | TransportInfo* video_transport_info = |
| 1515 | answer->description()->GetTransportInfoByName("video"); |
| 1516 | video_transport_info->description.connection_role = |
| 1517 | cricket::CONNECTIONROLE_PASSIVE; |
| 1518 | SetRemoteDescriptionWithoutError(answer); |
| 1519 | |
| 1520 | // Now create an offer in the reverse direction, and ensure the initial |
| 1521 | // offerer responds with an answer with correct SSL roles. |
| 1522 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 1523 | kSessionVersion, |
| 1524 | session_->remote_description()); |
| 1525 | SetRemoteDescriptionWithoutError(offer); |
| 1526 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1527 | cricket::MediaSessionOptions answer_options; |
| 1528 | answer_options.bundle_enabled = true; |
| 1529 | answer = CreateAnswer(answer_options); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1530 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 1531 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1532 | audio_transport_info->description.connection_role); |
| 1533 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 1534 | EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE, |
| 1535 | video_transport_info->description.connection_role); |
| 1536 | SetLocalDescriptionWithoutError(answer); |
| 1537 | |
| 1538 | // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of |
| 1539 | // audio is transferred over to video in the answer that completes the BUNDLE |
| 1540 | // negotiation. |
| 1541 | options.bundle_enabled = true; |
| 1542 | offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED, |
| 1543 | kSessionVersion, |
| 1544 | session_->remote_description()); |
| 1545 | SetRemoteDescriptionWithoutError(offer); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1546 | answer = CreateAnswer(answer_options); |
Taylor Brandstetter | f475d36 | 2016-01-08 15:35:57 -0800 | [diff] [blame] | 1547 | audio_transport_info = answer->description()->GetTransportInfoByName("audio"); |
| 1548 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1549 | audio_transport_info->description.connection_role); |
| 1550 | video_transport_info = answer->description()->GetTransportInfoByName("video"); |
| 1551 | EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE, |
| 1552 | video_transport_info->description.connection_role); |
| 1553 | SetLocalDescriptionWithoutError(answer); |
| 1554 | } |
| 1555 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1556 | TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1557 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1558 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1559 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1560 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1561 | SetLocalDescriptionWithoutError(offer); |
| 1562 | |
| 1563 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1564 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1565 | SetLocalDescriptionWithoutError(offer2); |
| 1566 | } |
| 1567 | |
| 1568 | TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1569 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1570 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1571 | // SetLocalDescription take ownership of offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1572 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1573 | SetRemoteDescriptionWithoutError(offer); |
| 1574 | |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1575 | SessionDescriptionInterface* offer2 = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1576 | SetRemoteDescriptionWithoutError(offer2); |
| 1577 | } |
| 1578 | |
| 1579 | TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1580 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1581 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1582 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1583 | SetLocalDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1584 | offer = CreateOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1585 | SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER", |
| 1586 | offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1590 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1591 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1592 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1593 | SetRemoteDescriptionWithoutError(offer); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1594 | offer = CreateOffer(); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1595 | SetLocalDescriptionOfferExpectError( |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1596 | "Called in wrong state: STATE_RECEIVEDOFFER", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1600 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1601 | SendNothing(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1602 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1603 | SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1604 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1605 | JsepSessionDescription* pranswer = |
| 1606 | static_cast<JsepSessionDescription*>(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1607 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1608 | SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1609 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1610 | SendAudioVideoStream1(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1611 | JsepSessionDescription* pranswer2 = |
| 1612 | static_cast<JsepSessionDescription*>(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1613 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1614 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1615 | SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1616 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1617 | SendAudioVideoStream2(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1618 | SessionDescriptionInterface* answer = CreateAnswer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1619 | SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1623 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1624 | SendNothing(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1625 | SessionDescriptionInterface* offer = CreateOffer(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1626 | SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1627 | |
| 1628 | JsepSessionDescription* pranswer = |
| 1629 | CreateRemoteAnswer(session_->local_description()); |
| 1630 | pranswer->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1631 | |
| 1632 | SetRemoteDescriptionExpectState(pranswer, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1633 | WebRtcSession::STATE_RECEIVEDPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1634 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1635 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1636 | JsepSessionDescription* pranswer2 = |
| 1637 | CreateRemoteAnswer(session_->local_description()); |
| 1638 | pranswer2->set_type(SessionDescriptionInterface::kPrAnswer); |
| 1639 | |
| 1640 | SetRemoteDescriptionExpectState(pranswer2, |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1641 | WebRtcSession::STATE_RECEIVEDPRANSWER); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1642 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1643 | SendAudioVideoStream2(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1644 | SessionDescriptionInterface* answer = |
| 1645 | CreateRemoteAnswer(session_->local_description()); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1646 | SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1650 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1651 | SendNothing(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1652 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1653 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1654 | SessionDescriptionInterface* answer = |
| 1655 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1656 | SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT", |
| 1657 | answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1661 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1662 | SendNothing(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1663 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1664 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1665 | SessionDescriptionInterface* answer = |
| 1666 | CreateRemoteAnswer(offer.get()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1667 | SetRemoteDescriptionAnswerExpectError( |
| 1668 | "Called in wrong state: STATE_INIT", answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1669 | } |
| 1670 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1671 | // Verifies TransportProxy and media channels are created with content names |
| 1672 | // present in the SessionDescription. |
| 1673 | TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1674 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1675 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1676 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1677 | |
| 1678 | // CreateOffer creates session description with the content names "audio" and |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 1679 | // "video". Goal is to modify these content names and verify transport |
| 1680 | // channels |
| 1681 | // in the WebRtcSession, as channels are created with the content names |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1682 | // present in SDP. |
| 1683 | std::string sdp; |
| 1684 | EXPECT_TRUE(offer->ToString(&sdp)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1685 | |
| 1686 | SessionDescriptionInterface* modified_offer = |
| 1687 | CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL); |
| 1688 | |
| 1689 | SetRemoteDescriptionWithoutError(modified_offer); |
| 1690 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1691 | cricket::MediaSessionOptions answer_options; |
| 1692 | answer_options.bundle_enabled = false; |
| 1693 | SessionDescriptionInterface* answer = CreateAnswer(answer_options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1694 | SetLocalDescriptionWithoutError(answer); |
| 1695 | |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 1696 | rtc::PacketTransportInternal* voice_transport_channel = |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1697 | session_->voice_rtp_transport_channel(); |
| 1698 | EXPECT_TRUE(voice_transport_channel != NULL); |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 1699 | EXPECT_EQ(voice_transport_channel->debug_name(), |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1700 | "audio " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
deadbeef | 5bd5ca3 | 2017-02-10 11:31:50 -0800 | [diff] [blame] | 1701 | rtc::PacketTransportInternal* video_transport_channel = |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1702 | session_->video_rtp_transport_channel(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1703 | ASSERT_TRUE(video_transport_channel != NULL); |
johan | 669d69b | 2016-11-08 14:14:08 -0800 | [diff] [blame] | 1704 | EXPECT_EQ(video_transport_channel->debug_name(), |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1705 | "video " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1706 | EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL); |
| 1707 | EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL); |
| 1708 | } |
| 1709 | |
| 1710 | // Test that an offer contains the correct media content descriptions based on |
| 1711 | // the send streams when no constraints have been set. |
| 1712 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1713 | Init(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1714 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1715 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1716 | ASSERT_TRUE(offer != NULL); |
| 1717 | const cricket::ContentInfo* content = |
| 1718 | cricket::GetFirstAudioContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1719 | ASSERT_TRUE(content != NULL); |
| 1720 | EXPECT_EQ( |
| 1721 | cricket::MD_RECVONLY, |
| 1722 | static_cast<const cricket::AudioContentDescription*>(content->description) |
| 1723 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1724 | content = cricket::GetFirstVideoContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1725 | ASSERT_TRUE(content != NULL); |
| 1726 | EXPECT_EQ( |
| 1727 | cricket::MD_RECVONLY, |
| 1728 | static_cast<const cricket::VideoContentDescription*>(content->description) |
| 1729 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | // Test that an offer contains the correct media content descriptions based on |
| 1733 | // the send streams when no constraints have been set. |
| 1734 | TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1735 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1736 | // Test Audio only offer. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1737 | SendAudioOnlyStream2(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1738 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1739 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1740 | const cricket::ContentInfo* content = |
| 1741 | cricket::GetFirstAudioContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1742 | ASSERT_TRUE(content != NULL); |
| 1743 | EXPECT_EQ( |
| 1744 | cricket::MD_SENDRECV, |
| 1745 | static_cast<const cricket::AudioContentDescription*>(content->description) |
| 1746 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1747 | content = cricket::GetFirstVideoContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1748 | ASSERT_TRUE(content != NULL); |
| 1749 | EXPECT_EQ( |
| 1750 | cricket::MD_RECVONLY, |
| 1751 | static_cast<const cricket::VideoContentDescription*>(content->description) |
| 1752 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1753 | |
| 1754 | // Test Audio / Video offer. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1755 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1756 | offer.reset(CreateOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1757 | content = cricket::GetFirstAudioContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1758 | ASSERT_TRUE(content != NULL); |
| 1759 | EXPECT_EQ( |
| 1760 | cricket::MD_SENDRECV, |
| 1761 | static_cast<const cricket::AudioContentDescription*>(content->description) |
| 1762 | ->direction()); |
| 1763 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1764 | content = cricket::GetFirstVideoContent(offer->description()); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1765 | ASSERT_TRUE(content != NULL); |
| 1766 | EXPECT_EQ( |
| 1767 | cricket::MD_SENDRECV, |
| 1768 | static_cast<const cricket::VideoContentDescription*>(content->description) |
| 1769 | ->direction()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
| 1772 | // Test that an offer contains no media content descriptions if |
| 1773 | // kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false. |
| 1774 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1775 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1776 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1777 | options.offer_to_receive_audio = 0; |
| 1778 | options.offer_to_receive_video = 0; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1779 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1780 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1781 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1782 | ASSERT_TRUE(offer != NULL); |
| 1783 | const cricket::ContentInfo* content = |
| 1784 | cricket::GetFirstAudioContent(offer->description()); |
| 1785 | EXPECT_TRUE(content == NULL); |
| 1786 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1787 | EXPECT_TRUE(content == NULL); |
| 1788 | } |
| 1789 | |
| 1790 | // Test that an offer contains only audio media content descriptions if |
| 1791 | // kOfferToReceiveAudio constraints are set to true. |
| 1792 | TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1793 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1794 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1795 | options.offer_to_receive_audio = |
| 1796 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1797 | options.offer_to_receive_video = 0; |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1798 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1799 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1800 | |
| 1801 | const cricket::ContentInfo* content = |
| 1802 | cricket::GetFirstAudioContent(offer->description()); |
| 1803 | EXPECT_TRUE(content != NULL); |
| 1804 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1805 | EXPECT_TRUE(content == NULL); |
| 1806 | } |
| 1807 | |
| 1808 | // Test that an offer contains audio and video media content descriptions if |
| 1809 | // kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true. |
| 1810 | TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1811 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1812 | // Test Audio / Video offer. |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1813 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1814 | options.offer_to_receive_audio = |
| 1815 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 1816 | options.offer_to_receive_video = |
| 1817 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 1818 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1819 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1820 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1821 | const cricket::ContentInfo* content = |
| 1822 | cricket::GetFirstAudioContent(offer->description()); |
jiayl@webrtc.org | c172320 | 2014-09-08 20:44:36 +0000 | [diff] [blame] | 1823 | EXPECT_TRUE(content != NULL); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1824 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1825 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1826 | EXPECT_TRUE(content != NULL); |
| 1827 | |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1828 | // Sets constraints to false and verifies that audio/video contents are |
| 1829 | // removed. |
| 1830 | options.offer_to_receive_audio = 0; |
| 1831 | options.offer_to_receive_video = 0; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1832 | // Remove the media sections added in previous offer. |
| 1833 | offered_media_sections_.clear(); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1834 | offer.reset(CreateOffer(options)); |
| 1835 | |
| 1836 | content = cricket::GetFirstAudioContent(offer->description()); |
| 1837 | EXPECT_TRUE(content == NULL); |
| 1838 | content = cricket::GetFirstVideoContent(offer->description()); |
| 1839 | EXPECT_TRUE(content == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | // Test that an answer can not be created if the last remote description is not |
| 1843 | // an offer. |
| 1844 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1845 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1846 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1847 | SetLocalDescriptionWithoutError(offer); |
| 1848 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 1849 | SetRemoteDescriptionWithoutError(answer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1850 | EXPECT_TRUE(CreateAnswer() == NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | // Test that an answer contains the correct media content descriptions when no |
| 1854 | // constraints have been set. |
| 1855 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1856 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1857 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1858 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1859 | SetRemoteDescriptionWithoutError(offer.release()); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1860 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1861 | const cricket::ContentInfo* content = |
| 1862 | cricket::GetFirstAudioContent(answer->description()); |
| 1863 | ASSERT_TRUE(content != NULL); |
| 1864 | EXPECT_FALSE(content->rejected); |
| 1865 | |
| 1866 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1867 | ASSERT_TRUE(content != NULL); |
| 1868 | EXPECT_FALSE(content->rejected); |
| 1869 | } |
| 1870 | |
| 1871 | // Test that an answer contains the correct media content descriptions when no |
| 1872 | // constraints have been set and the offer only contain audio. |
| 1873 | TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1874 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1875 | // Create a remote offer with audio only. |
| 1876 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1877 | GetOptionsForAudioOnlyRemoteOffer(&options); |
jiayl@webrtc.org | 7d4891d | 2014-09-09 21:43:15 +0000 | [diff] [blame] | 1878 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1879 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1880 | ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL); |
| 1881 | ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL); |
| 1882 | |
| 1883 | SetRemoteDescriptionWithoutError(offer.release()); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1884 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1885 | const cricket::ContentInfo* content = |
| 1886 | cricket::GetFirstAudioContent(answer->description()); |
| 1887 | ASSERT_TRUE(content != NULL); |
| 1888 | EXPECT_FALSE(content->rejected); |
| 1889 | |
| 1890 | EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL); |
| 1891 | } |
| 1892 | |
| 1893 | // Test that an answer contains the correct media content descriptions when no |
| 1894 | // constraints have been set. |
| 1895 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1896 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1897 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1898 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1899 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1900 | // Test with a stream with tracks. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1901 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1902 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1903 | const cricket::ContentInfo* content = |
| 1904 | cricket::GetFirstAudioContent(answer->description()); |
| 1905 | ASSERT_TRUE(content != NULL); |
| 1906 | EXPECT_FALSE(content->rejected); |
| 1907 | |
| 1908 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1909 | ASSERT_TRUE(content != NULL); |
| 1910 | EXPECT_FALSE(content->rejected); |
| 1911 | } |
| 1912 | |
| 1913 | // Test that an answer contains the correct media content descriptions when |
| 1914 | // constraints have been set but no stream is sent. |
| 1915 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1916 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1917 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1918 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1919 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1920 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1921 | cricket::MediaSessionOptions session_options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 1922 | remote_send_audio_ = false; |
| 1923 | remote_send_video_ = false; |
| 1924 | local_recv_audio_ = false; |
| 1925 | local_recv_video_ = false; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1926 | std::unique_ptr<SessionDescriptionInterface> answer( |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1927 | CreateAnswer(session_options)); |
| 1928 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1929 | const cricket::ContentInfo* content = |
| 1930 | cricket::GetFirstAudioContent(answer->description()); |
| 1931 | ASSERT_TRUE(content != NULL); |
| 1932 | EXPECT_TRUE(content->rejected); |
| 1933 | |
| 1934 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1935 | ASSERT_TRUE(content != NULL); |
| 1936 | EXPECT_TRUE(content->rejected); |
| 1937 | } |
| 1938 | |
| 1939 | // Test that an answer contains the correct media content descriptions when |
| 1940 | // constraints have been set and streams are sent. |
| 1941 | TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1942 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1943 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1944 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1945 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1946 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1947 | cricket::MediaSessionOptions options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1948 | // Test with a stream with tracks. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 1949 | SendAudioVideoStream1(); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1950 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1951 | |
| 1952 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 1953 | const cricket::ContentInfo* content = |
| 1954 | cricket::GetFirstAudioContent(answer->description()); |
| 1955 | ASSERT_TRUE(content != NULL); |
| 1956 | EXPECT_FALSE(content->rejected); |
| 1957 | |
| 1958 | // TODO(perkj): Should the direction be set to SEND_ONLY? |
| 1959 | content = cricket::GetFirstVideoContent(answer->description()); |
| 1960 | ASSERT_TRUE(content != NULL); |
| 1961 | EXPECT_FALSE(content->rejected); |
| 1962 | } |
| 1963 | |
| 1964 | TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) { |
| 1965 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1966 | Init(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1967 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 1968 | options.offer_to_receive_audio = |
| 1969 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
| 1970 | options.voice_activity_detection = false; |
| 1971 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1972 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options)); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 1973 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1974 | const cricket::ContentInfo* content = |
| 1975 | cricket::GetFirstAudioContent(offer->description()); |
| 1976 | EXPECT_TRUE(content != NULL); |
| 1977 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 1978 | } |
| 1979 | |
| 1980 | TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) { |
| 1981 | AddCNCodecs(); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1982 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1983 | // Create a remote offer with audio and video content. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1984 | std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1985 | SetRemoteDescriptionWithoutError(offer.release()); |
| 1986 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 1987 | cricket::MediaSessionOptions options; |
| 1988 | options.vad_enabled = false; |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 1989 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1990 | const cricket::ContentInfo* content = |
| 1991 | cricket::GetFirstAudioContent(answer->description()); |
| 1992 | ASSERT_TRUE(content != NULL); |
| 1993 | EXPECT_TRUE(VerifyNoCNCodecs(content)); |
| 1994 | } |
| 1995 | |
| 1996 | // This test verifies the call setup when remote answer with audio only and |
| 1997 | // later updates with video. |
| 1998 | TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 1999 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2000 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2001 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
| 2002 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2003 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2004 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2005 | |
| 2006 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2007 | AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO, |
| 2008 | cricket::MD_RECVONLY, kActive, &options); |
| 2009 | AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, |
| 2010 | cricket::MD_INACTIVE, kStopped, &options); |
| 2011 | local_recv_video_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2012 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options); |
| 2013 | |
| 2014 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2015 | // and answer; |
| 2016 | SetLocalDescriptionWithoutError(offer); |
| 2017 | SetRemoteDescriptionWithoutError(answer); |
| 2018 | |
| 2019 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2020 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2021 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2022 | ASSERT_TRUE(video_channel_ == nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2023 | |
| 2024 | ASSERT_EQ(0u, voice_channel_->recv_streams().size()); |
| 2025 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2026 | EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id); |
| 2027 | |
| 2028 | // Let the remote end update the session descriptions, with Audio and Video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2029 | SendAudioVideoStream2(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2030 | local_recv_video_ = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2031 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2032 | |
| 2033 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2034 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2035 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2036 | ASSERT_TRUE(video_channel_ != nullptr); |
| 2037 | ASSERT_TRUE(voice_channel_ != nullptr); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2038 | |
| 2039 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2040 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2041 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2042 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2043 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2044 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2045 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2046 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2047 | |
| 2048 | // Change session back to audio only. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2049 | // The remote side doesn't send and recv video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2050 | SendAudioOnlyStream2(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2051 | remote_recv_video_ = false; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2052 | CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2053 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2054 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2055 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2056 | |
| 2057 | // The audio is expected to be rejected. |
| 2058 | EXPECT_TRUE(video_channel_ == nullptr); |
| 2059 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2060 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2061 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2062 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2063 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2064 | } |
| 2065 | |
| 2066 | // This test verifies the call setup when remote answer with video only and |
| 2067 | // later updates with audio. |
| 2068 | TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2069 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2070 | EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL); |
| 2071 | EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2072 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2073 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2074 | |
| 2075 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2076 | AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO, |
| 2077 | cricket::MD_INACTIVE, kStopped, &options); |
| 2078 | AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, |
| 2079 | cricket::MD_RECVONLY, kActive, &options); |
| 2080 | local_recv_audio_ = false; |
| 2081 | SessionDescriptionInterface* answer = |
| 2082 | CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2083 | |
| 2084 | // SetLocalDescription and SetRemoteDescriptions takes ownership of offer |
| 2085 | // and answer. |
| 2086 | SetLocalDescriptionWithoutError(offer); |
| 2087 | SetRemoteDescriptionWithoutError(answer); |
| 2088 | |
| 2089 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2090 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2091 | |
| 2092 | ASSERT_TRUE(voice_channel_ == NULL); |
| 2093 | ASSERT_TRUE(video_channel_ != NULL); |
| 2094 | |
| 2095 | EXPECT_EQ(0u, video_channel_->recv_streams().size()); |
| 2096 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2097 | EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id); |
| 2098 | |
| 2099 | // Update the session descriptions, with Audio and Video. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2100 | SendAudioVideoStream2(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2101 | local_recv_audio_ = true; |
| 2102 | SessionDescriptionInterface* offer2 = CreateRemoteOffer(); |
| 2103 | SetRemoteDescriptionWithoutError(offer2); |
| 2104 | cricket::MediaSessionOptions answer_options; |
| 2105 | // Disable the bundling here. If the media is bundled on audio |
| 2106 | // transport, then we can't reject the audio because switching the bundled |
| 2107 | // transport is not currently supported. |
| 2108 | // (https://bugs.chromium.org/p/webrtc/issues/detail?id=6704) |
| 2109 | answer_options.bundle_enabled = false; |
| 2110 | SessionDescriptionInterface* answer2 = CreateAnswer(answer_options); |
| 2111 | SetLocalDescriptionWithoutError(answer2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2112 | |
| 2113 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
olka | 3c74766 | 2017-08-17 06:50:32 -0700 | [diff] [blame] | 2114 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2115 | ASSERT_TRUE(voice_channel_ != NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2116 | ASSERT_EQ(1u, voice_channel_->recv_streams().size()); |
| 2117 | ASSERT_EQ(1u, voice_channel_->send_streams().size()); |
| 2118 | EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id); |
| 2119 | EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id); |
| 2120 | |
| 2121 | // Change session back to video only. |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2122 | // The remote side doesn't send and recv audio. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2123 | SendVideoOnlyStream2(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2124 | remote_recv_audio_ = false; |
| 2125 | SessionDescriptionInterface* offer3 = CreateRemoteOffer(); |
| 2126 | SetRemoteDescriptionWithoutError(offer3); |
| 2127 | SessionDescriptionInterface* answer3 = CreateAnswer(answer_options); |
| 2128 | SetLocalDescriptionWithoutError(answer3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2129 | |
| 2130 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2131 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2132 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2133 | // The video is expected to be rejected. |
| 2134 | EXPECT_TRUE(voice_channel_ == nullptr); |
| 2135 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2136 | ASSERT_EQ(1u, video_channel_->recv_streams().size()); |
| 2137 | EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id); |
| 2138 | ASSERT_EQ(1u, video_channel_->send_streams().size()); |
| 2139 | EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id); |
| 2140 | } |
| 2141 | |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2142 | // 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] | 2143 | // the "audio" transport channel when bundling. |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2144 | TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) { |
| 2145 | AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 2146 | |
| 2147 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2148 | SendAudioVideoStream1(); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2149 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2150 | cricket::MediaSessionOptions offer_options; |
| 2151 | GetOptionsForRemoteOffer(&offer_options); |
| 2152 | offer_options.bundle_enabled = true; |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2153 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2154 | SessionDescriptionInterface* offer = CreateRemoteOffer(offer_options); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2155 | SetRemoteDescriptionWithoutError(offer); |
| 2156 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2157 | cricket::MediaSessionOptions answer_options; |
| 2158 | answer_options.bundle_enabled = true; |
| 2159 | SessionDescriptionInterface* answer = CreateAnswer(answer_options); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2160 | SetLocalDescriptionWithoutError(answer); |
| 2161 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2162 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2163 | session_->video_rtp_transport_channel()); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2164 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2165 | cricket::BaseChannel* voice_channel = session_->voice_channel(); |
nisse | c8ee882 | 2017-01-18 07:20:55 -0800 | [diff] [blame] | 2166 | ASSERT_TRUE(voice_channel != NULL); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2167 | |
| 2168 | // Checks if one of the transport channels contains a connection using a given |
| 2169 | // port. |
eladalon | 1cc5fc3 | 2017-08-23 04:15:18 -0700 | [diff] [blame] | 2170 | auto connection_with_remote_port = [this](int port) { |
hbos | df6075a | 2016-12-19 04:58:02 -0800 | [diff] [blame] | 2171 | std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s(); |
| 2172 | for (auto& kv : stats->transport_stats) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2173 | for (auto& chan_stat : kv.second.channel_stats) { |
| 2174 | for (auto& conn_info : chan_stat.connection_infos) { |
| 2175 | if (conn_info.remote_candidate.address().port() == port) { |
| 2176 | return true; |
| 2177 | } |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2178 | } |
| 2179 | } |
| 2180 | } |
| 2181 | return false; |
| 2182 | }; |
| 2183 | |
| 2184 | EXPECT_FALSE(connection_with_remote_port(5000)); |
| 2185 | EXPECT_FALSE(connection_with_remote_port(5001)); |
| 2186 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 2187 | |
| 2188 | // The way the *_WAIT checks work is they only wait if the condition fails, |
| 2189 | // which does not help in the case where state is not changing. This is |
| 2190 | // problematic in this test since we want to verify that adding a video |
| 2191 | // candidate does _not_ change state. So we interleave candidates and assume |
| 2192 | // that messages are executed in the order they were posted. |
| 2193 | |
| 2194 | // First audio candidate. |
| 2195 | cricket::Candidate candidate0; |
| 2196 | candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
| 2197 | candidate0.set_component(1); |
| 2198 | candidate0.set_protocol("udp"); |
zhihuang | 38989e5 | 2017-03-21 11:04:53 -0700 | [diff] [blame] | 2199 | candidate0.set_type("local"); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2200 | JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0, |
| 2201 | candidate0); |
| 2202 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0)); |
| 2203 | |
| 2204 | // Video candidate. |
| 2205 | cricket::Candidate candidate1; |
| 2206 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000)); |
| 2207 | candidate1.set_component(1); |
| 2208 | candidate1.set_protocol("udp"); |
zhihuang | 38989e5 | 2017-03-21 11:04:53 -0700 | [diff] [blame] | 2209 | candidate1.set_type("local"); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2210 | JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1, |
| 2211 | candidate1); |
| 2212 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2213 | |
| 2214 | // Second audio candidate. |
| 2215 | cricket::Candidate candidate2; |
| 2216 | candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001)); |
| 2217 | candidate2.set_component(1); |
| 2218 | candidate2.set_protocol("udp"); |
zhihuang | 38989e5 | 2017-03-21 11:04:53 -0700 | [diff] [blame] | 2219 | candidate2.set_type("local"); |
Donald Curtis | d4f769d | 2015-05-28 09:48:21 -0700 | [diff] [blame] | 2220 | JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0, |
| 2221 | candidate2); |
| 2222 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2223 | |
| 2224 | EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000); |
| 2225 | EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000); |
| 2226 | |
| 2227 | // No need here for a _WAIT check since we are checking that state hasn't |
| 2228 | // changed: if this is false we would be doing waits for nothing and if this |
| 2229 | // is true then there will be no messages processed anyways. |
| 2230 | EXPECT_FALSE(connection_with_remote_port(6000)); |
| 2231 | } |
| 2232 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2233 | // kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2234 | TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) { |
| 2235 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2236 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2237 | |
| 2238 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2239 | options.use_rtp_mux = true; |
| 2240 | |
| 2241 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2242 | SetLocalDescriptionWithoutError(offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2243 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2244 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2245 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2246 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2247 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2248 | SessionDescriptionInterface* answer = |
| 2249 | CreateRemoteAnswer(session_->local_description()); |
| 2250 | SetRemoteDescriptionWithoutError(answer); |
| 2251 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2252 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2253 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2254 | } |
| 2255 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2256 | // kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2257 | TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) { |
| 2258 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2259 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2260 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2261 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2262 | options.use_rtp_mux = true; |
| 2263 | |
| 2264 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2265 | SetLocalDescriptionWithoutError(offer); |
| 2266 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2267 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2268 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2269 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2270 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2271 | |
| 2272 | // Remove BUNDLE from the answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2273 | std::unique_ptr<SessionDescriptionInterface> answer( |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2274 | CreateRemoteAnswer(session_->local_description())); |
| 2275 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2276 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2277 | JsepSessionDescription* modified_answer = |
| 2278 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2279 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2280 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 2281 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2282 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2283 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer. |
| 2287 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) { |
| 2288 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2289 | SendAudioVideoStream1(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2290 | |
| 2291 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2292 | options.use_rtp_mux = true; |
| 2293 | |
| 2294 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2295 | SetLocalDescriptionWithoutError(offer); |
| 2296 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2297 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2298 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2299 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2300 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2301 | SessionDescriptionInterface* answer = |
| 2302 | CreateRemoteAnswer(session_->local_description()); |
| 2303 | SetRemoteDescriptionWithoutError(answer); |
| 2304 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2305 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2306 | session_->video_rtp_transport_channel()); |
| 2307 | } |
| 2308 | |
| 2309 | // kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no |
| 2310 | // audio content in the answer. |
| 2311 | TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) { |
| 2312 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2313 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2314 | |
| 2315 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2316 | options.use_rtp_mux = true; |
| 2317 | |
| 2318 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2319 | SetLocalDescriptionWithoutError(offer); |
| 2320 | |
| 2321 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2322 | session_->video_rtp_transport_channel()); |
| 2323 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2324 | SendVideoOnlyStream2(); |
| 2325 | local_send_audio_ = false; |
| 2326 | remote_recv_audio_ = false; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2327 | cricket::MediaSessionOptions recv_options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2328 | GetOptionsForRemoteAnswer(&recv_options); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2329 | SessionDescriptionInterface* answer = |
| 2330 | CreateRemoteAnswer(session_->local_description(), recv_options); |
| 2331 | SetRemoteDescriptionWithoutError(answer); |
| 2332 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2333 | EXPECT_TRUE(nullptr == session_->voice_channel()); |
| 2334 | EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2335 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2336 | session_->Close(); |
| 2337 | EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel()); |
| 2338 | EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel()); |
| 2339 | EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel()); |
| 2340 | EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | // kBundlePolicyMaxBundle policy but no BUNDLE in the answer. |
| 2344 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) { |
| 2345 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2346 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2347 | |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2348 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2349 | options.use_rtp_mux = true; |
| 2350 | |
| 2351 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2352 | SetLocalDescriptionWithoutError(offer); |
| 2353 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2354 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2355 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2356 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2357 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2358 | |
| 2359 | // Remove BUNDLE from the answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2360 | std::unique_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2361 | CreateRemoteAnswer(session_->local_description())); |
| 2362 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2363 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2364 | JsepSessionDescription* modified_answer = |
| 2365 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2366 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2367 | SetRemoteDescriptionWithoutError(modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2368 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2369 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2370 | session_->video_rtp_transport_channel()); |
| 2371 | } |
| 2372 | |
| 2373 | // kBundlePolicyMaxBundle policy with BUNDLE in the remote offer. |
| 2374 | TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) { |
| 2375 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2376 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2377 | |
| 2378 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2379 | SetRemoteDescriptionWithoutError(offer); |
| 2380 | |
| 2381 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2382 | session_->video_rtp_transport_channel()); |
| 2383 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2384 | SendAudioVideoStream2(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2385 | SessionDescriptionInterface* answer = CreateAnswer(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2386 | SetLocalDescriptionWithoutError(answer); |
| 2387 | |
| 2388 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2389 | session_->video_rtp_transport_channel()); |
| 2390 | } |
| 2391 | |
| 2392 | // kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer. |
| 2393 | TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) { |
| 2394 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2395 | SendAudioVideoStream1(); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2396 | |
| 2397 | // Remove BUNDLE from the offer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2398 | std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2399 | cricket::SessionDescription* offer_copy = offer->description()->Copy(); |
| 2400 | offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2401 | JsepSessionDescription* modified_offer = |
| 2402 | new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 2403 | modified_offer->Initialize(offer_copy, "1", "1"); |
| 2404 | |
| 2405 | // Expect an error when applying the remote description |
| 2406 | SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer, |
| 2407 | kCreateChannelFailed, modified_offer); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2408 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2409 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2410 | // kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2411 | TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) { |
| 2412 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2413 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2414 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2415 | PeerConnectionInterface::RTCOfferAnswerOptions rtc_options; |
| 2416 | rtc_options.use_rtp_mux = true; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2417 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2418 | SessionDescriptionInterface* offer = CreateOffer(rtc_options); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2419 | SetLocalDescriptionWithoutError(offer); |
| 2420 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2421 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2422 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2423 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2424 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2425 | SessionDescriptionInterface* answer = |
| 2426 | CreateRemoteAnswer(session_->local_description()); |
| 2427 | SetRemoteDescriptionWithoutError(answer); |
| 2428 | |
| 2429 | // This should lead to an audio-only call but isn't implemented |
| 2430 | // correctly yet. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2431 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2432 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2435 | // kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer. |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2436 | TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) { |
| 2437 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2438 | SendAudioVideoStream1(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2439 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2440 | options.use_rtp_mux = true; |
| 2441 | |
| 2442 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2443 | SetLocalDescriptionWithoutError(offer); |
| 2444 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2445 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2446 | session_->video_rtp_transport_channel()); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2447 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2448 | SendAudioVideoStream2(); |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2449 | |
| 2450 | // Remove BUNDLE from the answer. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2451 | std::unique_ptr<SessionDescriptionInterface> answer( |
Donald Curtis | 0e209b0 | 2015-03-24 09:29:54 -0700 | [diff] [blame] | 2452 | CreateRemoteAnswer(session_->local_description())); |
| 2453 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2454 | answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE); |
| 2455 | JsepSessionDescription* modified_answer = |
| 2456 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
| 2457 | modified_answer->Initialize(answer_copy, "1", "1"); |
| 2458 | SetRemoteDescriptionWithoutError(modified_answer); // |
| 2459 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2460 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 2461 | session_->video_rtp_transport_channel()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2464 | // kBundlePolicyMaxbundle and then we call SetRemoteDescription first. |
| 2465 | TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) { |
| 2466 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2467 | SendAudioVideoStream1(); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2468 | |
| 2469 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2470 | options.use_rtp_mux = true; |
| 2471 | |
| 2472 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2473 | SetRemoteDescriptionWithoutError(offer); |
| 2474 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2475 | EXPECT_EQ(session_->voice_rtp_transport_channel(), |
| 2476 | session_->video_rtp_transport_channel()); |
Peter Thatcher | 4eddf18 | 2015-04-30 10:55:59 -0700 | [diff] [blame] | 2477 | } |
| 2478 | |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 2479 | // Adding a new channel to a BUNDLE which is already connected should directly |
| 2480 | // assign the bundle transport to the channel, without first setting a |
| 2481 | // disconnected non-bundle transport and then replacing it. The application |
| 2482 | // should not receive any changes in the ICE state. |
| 2483 | TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) { |
| 2484 | LoopbackNetworkConfiguration config; |
| 2485 | LoopbackNetworkManager loopback_network_manager(this, config); |
| 2486 | // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain |
| 2487 | // connected. Disabling either of these two means that we need to wait for the |
| 2488 | // answer to find out if more transports are needed. |
| 2489 | configuration_.bundle_policy = |
| 2490 | PeerConnectionInterface::kBundlePolicyMaxBundle; |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 2491 | options_.disable_encryption = true; |
deadbeef | 7914b8c | 2017-04-21 03:23:33 -0700 | [diff] [blame] | 2492 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
skvlad | 6c87a67 | 2016-05-17 17:49:52 -0700 | [diff] [blame] | 2493 | |
| 2494 | // Negotiate an audio channel with MAX_BUNDLE enabled. |
| 2495 | SendAudioOnlyStream2(); |
| 2496 | SessionDescriptionInterface* offer = CreateOffer(); |
| 2497 | SetLocalDescriptionWithoutError(offer); |
| 2498 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 2499 | observer_.ice_gathering_state_, kIceCandidatesTimeout); |
| 2500 | std::string sdp; |
| 2501 | offer->ToString(&sdp); |
| 2502 | SessionDescriptionInterface* answer = webrtc::CreateSessionDescription( |
| 2503 | JsepSessionDescription::kAnswer, sdp, nullptr); |
| 2504 | ASSERT_TRUE(answer != NULL); |
| 2505 | SetRemoteDescriptionWithoutError(answer); |
| 2506 | |
| 2507 | // Wait for the ICE state to stabilize. |
| 2508 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 2509 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 2510 | observer_.ice_connection_state_history_.clear(); |
| 2511 | |
| 2512 | // Now add a video channel which should be using the same bundle transport. |
| 2513 | SendAudioVideoStream2(); |
| 2514 | offer = CreateOffer(); |
| 2515 | offer->ToString(&sdp); |
| 2516 | SetLocalDescriptionWithoutError(offer); |
| 2517 | answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, |
| 2518 | sdp, nullptr); |
| 2519 | ASSERT_TRUE(answer != NULL); |
| 2520 | SetRemoteDescriptionWithoutError(answer); |
| 2521 | |
| 2522 | // Wait for ICE state to stabilize |
| 2523 | rtc::Thread::Current()->ProcessMessages(0); |
| 2524 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted, |
| 2525 | observer_.ice_connection_state_, kIceCandidatesTimeout); |
| 2526 | |
| 2527 | // No ICE state changes are expected to happen. |
| 2528 | EXPECT_EQ(0, observer_.ice_connection_state_history_.size()); |
| 2529 | } |
| 2530 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2531 | TEST_F(WebRtcSessionTest, TestRequireRtcpMux) { |
| 2532 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2533 | SendAudioVideoStream1(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2534 | |
| 2535 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2536 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2537 | SetLocalDescriptionWithoutError(offer); |
| 2538 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2539 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 2540 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2541 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2542 | SendAudioVideoStream2(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2543 | SessionDescriptionInterface* answer = |
| 2544 | CreateRemoteAnswer(session_->local_description()); |
| 2545 | SetRemoteDescriptionWithoutError(answer); |
| 2546 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2547 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 2548 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2549 | } |
| 2550 | |
| 2551 | TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) { |
| 2552 | InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2553 | SendAudioVideoStream1(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2554 | |
| 2555 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2556 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 2557 | SetLocalDescriptionWithoutError(offer); |
| 2558 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2559 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL); |
| 2560 | EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2561 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2562 | SendAudioVideoStream2(); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2563 | SessionDescriptionInterface* answer = |
| 2564 | CreateRemoteAnswer(session_->local_description()); |
| 2565 | SetRemoteDescriptionWithoutError(answer); |
| 2566 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2567 | EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL); |
| 2568 | EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2569 | } |
| 2570 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2571 | // This test verifies that SetLocalDescription and SetRemoteDescription fails |
| 2572 | // if BUNDLE is enabled but rtcp-mux is disabled in m-lines. |
| 2573 | TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2574 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2575 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2576 | |
| 2577 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 2578 | options.use_rtp_mux = true; |
| 2579 | |
| 2580 | SessionDescriptionInterface* offer = CreateOffer(options); |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2581 | std::string offer_str; |
| 2582 | offer->ToString(&offer_str); |
| 2583 | // Disable rtcp-mux |
| 2584 | const std::string rtcp_mux = "rtcp-mux"; |
| 2585 | const std::string xrtcp_mux = "xrtcp-mux"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2586 | rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(), |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2587 | xrtcp_mux.c_str(), xrtcp_mux.length(), |
| 2588 | &offer_str); |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 2589 | SessionDescriptionInterface* local_offer = CreateSessionDescription( |
| 2590 | SessionDescriptionInterface::kOffer, offer_str, nullptr); |
| 2591 | ASSERT_TRUE(local_offer); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2592 | SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 2593 | |
| 2594 | SessionDescriptionInterface* remote_offer = CreateSessionDescription( |
| 2595 | SessionDescriptionInterface::kOffer, offer_str, nullptr); |
| 2596 | ASSERT_TRUE(remote_offer); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2597 | SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 2598 | |
henrike@webrtc.org | 1e09a71 | 2013-07-26 19:17:59 +0000 | [diff] [blame] | 2599 | // Trying unmodified SDP. |
| 2600 | SetLocalDescriptionWithoutError(offer); |
| 2601 | } |
| 2602 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2603 | // This test verifies the |initial_offerer| flag when session initiates the |
| 2604 | // call. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2605 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2606 | Init(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2607 | EXPECT_FALSE(session_->initial_offerer()); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2608 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2609 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2610 | SetLocalDescriptionWithoutError(offer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2611 | EXPECT_TRUE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2612 | SetRemoteDescriptionWithoutError(answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2613 | EXPECT_TRUE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2616 | // 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] | 2617 | TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2618 | Init(); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2619 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2620 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2621 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2622 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2623 | |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2624 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2625 | SetLocalDescriptionWithoutError(answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2626 | EXPECT_FALSE(session_->initial_offerer()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2629 | // Verifing local offer and remote answer have matching m-lines as per RFC 3264. |
| 2630 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2631 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2632 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2633 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2634 | SetLocalDescriptionWithoutError(offer); |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2635 | std::unique_ptr<SessionDescriptionInterface> answer( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2636 | CreateRemoteAnswer(session_->local_description())); |
| 2637 | |
| 2638 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2639 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2640 | JsepSessionDescription* modified_answer = |
| 2641 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2642 | |
| 2643 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2644 | answer->session_id(), |
| 2645 | answer->session_version())); |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 2646 | SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer, |
| 2647 | modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2648 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2649 | // Different content names. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2650 | std::string sdp; |
| 2651 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2652 | const std::string kAudioMid = "a=mid:audio"; |
| 2653 | const std::string kAudioMidReplaceStr = "a=mid:audio_content_name"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2654 | rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2655 | kAudioMidReplaceStr.c_str(), |
| 2656 | kAudioMidReplaceStr.length(), |
| 2657 | &sdp); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2658 | SessionDescriptionInterface* modified_answer1 = |
| 2659 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 2660 | SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer, |
| 2661 | modified_answer1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2662 | |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2663 | // Different media types. |
| 2664 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 2665 | const std::string kAudioMline = "m=audio"; |
| 2666 | const std::string kAudioMlineReplaceStr = "m=video"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2667 | rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(), |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2668 | kAudioMlineReplaceStr.c_str(), |
| 2669 | kAudioMlineReplaceStr.length(), |
| 2670 | &sdp); |
| 2671 | SessionDescriptionInterface* modified_answer2 = |
| 2672 | CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL); |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 2673 | SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer, |
| 2674 | modified_answer2); |
wu@webrtc.org | 4e39307 | 2014-04-07 17:04:35 +0000 | [diff] [blame] | 2675 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2676 | SetRemoteDescriptionWithoutError(answer.release()); |
| 2677 | } |
| 2678 | |
| 2679 | // Verifying remote offer and local answer have matching m-lines as per |
| 2680 | // RFC 3264. |
| 2681 | TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2682 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2683 | SendAudioVideoStream1(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2684 | SessionDescriptionInterface* offer = CreateRemoteOffer(); |
| 2685 | SetRemoteDescriptionWithoutError(offer); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2686 | SessionDescriptionInterface* answer = CreateAnswer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2687 | |
| 2688 | cricket::SessionDescription* answer_copy = answer->description()->Copy(); |
| 2689 | answer_copy->RemoveContentByName("video"); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2690 | JsepSessionDescription* modified_answer = |
| 2691 | new JsepSessionDescription(JsepSessionDescription::kAnswer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2692 | |
| 2693 | EXPECT_TRUE(modified_answer->Initialize(answer_copy, |
| 2694 | answer->session_id(), |
| 2695 | answer->session_version())); |
Zhi Huang | 2a5e426 | 2017-09-14 01:15:03 -0700 | [diff] [blame] | 2696 | SetLocalDescriptionAnswerExpectError(kMlineMismatchInAnswer, modified_answer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2697 | SetLocalDescriptionWithoutError(answer); |
| 2698 | } |
| 2699 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2700 | TEST_F(WebRtcSessionTest, TestSessionContentError) { |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2701 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2702 | SendAudioVideoStream1(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2703 | SessionDescriptionInterface* offer = CreateOffer(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2704 | const std::string session_id_orig = offer->session_id(); |
| 2705 | const std::string session_version_orig = offer->session_version(); |
| 2706 | SetLocalDescriptionWithoutError(offer); |
| 2707 | |
| 2708 | video_channel_ = media_engine_->GetVideoChannel(0); |
| 2709 | video_channel_->set_fail_set_send_codecs(true); |
| 2710 | |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 2711 | SessionDescriptionInterface* answer = |
| 2712 | CreateRemoteAnswer(session_->local_description()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 2713 | SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer); |
deadbeef | d59daf8 | 2015-10-14 15:02:44 -0700 | [diff] [blame] | 2714 | |
| 2715 | // Test that after a content error, setting any description will |
| 2716 | // result in an error. |
| 2717 | video_channel_->set_fail_set_send_codecs(false); |
| 2718 | answer = CreateRemoteAnswer(session_->local_description()); |
| 2719 | SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer); |
| 2720 | offer = CreateRemoteOffer(); |
| 2721 | SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | // Runs the loopback call test with BUNDLE and STUN disabled. |
| 2725 | TEST_F(WebRtcSessionTest, TestIceStatesBasic) { |
| 2726 | // Lets try with only UDP ports. |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 2727 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 2728 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 2729 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2730 | TestLoopbackCall(); |
| 2731 | } |
| 2732 | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 2733 | TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) { |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 2734 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
guoweis@webrtc.org | 7169afd | 2014-12-04 17:59:29 +0000 | [diff] [blame] | 2735 | cricket::PORTALLOCATOR_DISABLE_STUN | |
| 2736 | cricket::PORTALLOCATOR_ENABLE_IPV6 | |
| 2737 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 2738 | |
| 2739 | // best connection is IPv6 since it has higher network preference. |
| 2740 | LoopbackNetworkConfiguration config; |
| 2741 | config.test_ipv6_network_ = true; |
| 2742 | config.best_connection_after_initial_ice_converged_ = |
| 2743 | LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1); |
| 2744 | |
| 2745 | TestLoopbackCall(config); |
| 2746 | } |
| 2747 | |
mallinath@webrtc.org | d3dc424 | 2014-03-01 00:05:52 +0000 | [diff] [blame] | 2748 | // Runs the loopback call test with BUNDLE and STUN enabled. |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 2749 | TEST_F(WebRtcSessionTest, TestIceStatesBundle) { |
Peter Thatcher | 7cbd188 | 2015-09-17 18:54:52 -0700 | [diff] [blame] | 2750 | allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 2751 | cricket::PORTALLOCATOR_DISABLE_RELAY); |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 2752 | TestLoopbackCall(); |
| 2753 | } |
| 2754 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2755 | TEST_F(WebRtcSessionTest, TestRtpDataChannel) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2756 | configuration_.enable_rtp_data_channel = true; |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2757 | Init(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2758 | SetLocalDescriptionWithDataChannel(); |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2759 | ASSERT_TRUE(data_engine_); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2760 | EXPECT_NE(nullptr, data_engine_->GetChannel(0)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2761 | } |
| 2762 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2763 | TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2764 | configuration_.enable_rtp_data_channel = true; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2765 | options_.disable_sctp_data_channels = false; |
| 2766 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2767 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2768 | |
| 2769 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2770 | EXPECT_NE(nullptr, data_engine_->GetChannel(0)); |
| 2771 | } |
| 2772 | |
| 2773 | // Test that sctp_content_name/sctp_transport_name (used for stats) are correct |
| 2774 | // before and after BUNDLE is negotiated. |
| 2775 | TEST_P(WebRtcSessionTest, SctpContentAndTransportName) { |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2776 | SetFactoryDtlsSrtp(); |
| 2777 | InitWithDtls(GetParam()); |
| 2778 | |
| 2779 | // Initially these fields should be empty. |
| 2780 | EXPECT_FALSE(session_->sctp_content_name()); |
| 2781 | EXPECT_FALSE(session_->sctp_transport_name()); |
| 2782 | |
| 2783 | // Create offer with audio/video/data. |
| 2784 | // Default bundle policy is "balanced", so data should be using its own |
| 2785 | // transport. |
| 2786 | SendAudioVideoStream1(); |
| 2787 | CreateDataChannel(); |
| 2788 | InitiateCall(); |
| 2789 | ASSERT_TRUE(session_->sctp_content_name()); |
| 2790 | ASSERT_TRUE(session_->sctp_transport_name()); |
| 2791 | EXPECT_EQ("data", *session_->sctp_content_name()); |
| 2792 | EXPECT_EQ("data", *session_->sctp_transport_name()); |
| 2793 | |
| 2794 | // Create answer that finishes BUNDLE negotiation, which means everything |
| 2795 | // should be bundled on the first transport (audio). |
| 2796 | cricket::MediaSessionOptions answer_options; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2797 | answer_options.bundle_enabled = true; |
| 2798 | answer_options.data_channel_type = cricket::DCT_SCTP; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2799 | GetOptionsForAnswer(&answer_options); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2800 | SetRemoteDescriptionWithoutError(CreateRemoteAnswer( |
| 2801 | session_->local_description(), answer_options, cricket::SEC_DISABLED)); |
| 2802 | ASSERT_TRUE(session_->sctp_content_name()); |
| 2803 | ASSERT_TRUE(session_->sctp_transport_name()); |
| 2804 | EXPECT_EQ("data", *session_->sctp_content_name()); |
| 2805 | EXPECT_EQ("audio", *session_->sctp_transport_name()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2806 | } |
| 2807 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2808 | TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2809 | InitWithDtls(GetParam()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2810 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2811 | std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2812 | EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2813 | EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL); |
| 2814 | } |
| 2815 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2816 | TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) { |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2817 | SetFactoryDtlsSrtp(); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2818 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2819 | |
| 2820 | // Create remote offer with SCTP. |
| 2821 | cricket::MediaSessionOptions options; |
| 2822 | options.data_channel_type = cricket::DCT_SCTP; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2823 | GetOptionsForRemoteOffer(&options); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2824 | JsepSessionDescription* offer = |
henrike@webrtc.org | b90991d | 2014-03-04 19:54:57 +0000 | [diff] [blame] | 2825 | CreateRemoteOffer(options, cricket::SEC_DISABLED); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2826 | SetRemoteDescriptionWithoutError(offer); |
| 2827 | |
| 2828 | // Verifies the answer contains SCTP. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 2829 | std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
mallinath@webrtc.org | 1112c30 | 2013-09-23 20:34:45 +0000 | [diff] [blame] | 2830 | EXPECT_TRUE(answer != NULL); |
| 2831 | EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL); |
| 2832 | EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL); |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 2833 | } |
| 2834 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2835 | // Test that if DTLS is disabled, we don't end up with an SctpTransport |
| 2836 | // created (or an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2837 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2838 | configuration_.enable_dtls_srtp = rtc::Optional<bool>(false); |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2839 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2840 | |
| 2841 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2842 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 2843 | EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2844 | } |
| 2845 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2846 | // Test that if DTLS is enabled, we end up with an SctpTransport created |
| 2847 | // (and not an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2848 | TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2849 | InitWithDtls(GetParam()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2850 | |
| 2851 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2852 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 2853 | EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2854 | } |
wu@webrtc.org | 91053e7 | 2013-08-10 07:18:04 +0000 | [diff] [blame] | 2855 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2856 | // Test that if SCTP is disabled, we don't end up with an SctpTransport |
| 2857 | // created (or an RtpDataChannel). |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2858 | TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) { |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2859 | options_.disable_sctp_data_channels = true; |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2860 | InitWithDtls(GetParam()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2861 | |
| 2862 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2863 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 2864 | EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 2865 | } |
| 2866 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2867 | TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2868 | const int new_send_port = 9998; |
| 2869 | const int new_recv_port = 7775; |
| 2870 | |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2871 | InitWithDtls(GetParam()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2872 | SetFactoryDtlsSrtp(); |
| 2873 | |
| 2874 | // By default, don't actually add the codecs to desc_factory_; they don't |
| 2875 | // actually get serialized for SCTP in BuildMediaDescription(). Instead, |
| 2876 | // let the session description get parsed. That'll get the proper codecs |
| 2877 | // into the stream. |
| 2878 | cricket::MediaSessionOptions options; |
Steve Anton | 6d64e9a | 2017-09-12 09:44:05 -0700 | [diff] [blame] | 2879 | SessionDescriptionInterface* offer = |
| 2880 | CreateRemoteOfferWithSctpPort("stream1", new_send_port, options); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2881 | |
| 2882 | // SetRemoteDescription will take the ownership of the offer. |
| 2883 | SetRemoteDescriptionWithoutError(offer); |
| 2884 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2885 | SessionDescriptionInterface* answer = |
| 2886 | ChangeSDPSctpPort(new_recv_port, CreateAnswer()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2887 | ASSERT_TRUE(answer != NULL); |
| 2888 | |
| 2889 | // Now set the local description, which'll take ownership of the answer. |
| 2890 | SetLocalDescriptionWithoutError(answer); |
| 2891 | |
| 2892 | // TEST PLAN: Set the port number to something new, set it in the SDP, |
| 2893 | // and pass it all the way down. |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2894 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2895 | CreateDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2896 | ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
| 2897 | EXPECT_EQ( |
| 2898 | new_recv_port, |
| 2899 | fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port()); |
| 2900 | EXPECT_EQ( |
| 2901 | new_send_port, |
| 2902 | fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port()); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 2903 | } |
| 2904 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2905 | // Verifies that when a session's SctpTransport receives an OPEN message, |
| 2906 | // WebRtcSession signals the SctpTransport creation request with the expected |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2907 | // config. |
| 2908 | TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) { |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2909 | InitWithDtls(GetParam()); |
| 2910 | |
| 2911 | SetLocalDescriptionWithDataChannel(); |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2912 | EXPECT_EQ(nullptr, data_engine_->GetChannel(0)); |
| 2913 | ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2914 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2915 | // Make the fake SCTP transport pretend it received an OPEN message. |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2916 | webrtc::DataChannelInit config; |
| 2917 | config.id = 1; |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 2918 | rtc::CopyOnWriteBuffer payload; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2919 | webrtc::WriteDataChannelOpenMessage("a", config, &payload); |
| 2920 | cricket::ReceiveDataParams params; |
| 2921 | params.ssrc = config.id; |
| 2922 | params.type = cricket::DMT_CONTROL; |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2923 | fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived( |
| 2924 | params, payload); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2925 | |
deadbeef | 953c2ce | 2017-01-09 14:53:41 -0800 | [diff] [blame] | 2926 | EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2927 | EXPECT_EQ(config.id, last_data_channel_config_.id); |
| 2928 | EXPECT_FALSE(last_data_channel_config_.negotiated); |
| 2929 | EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker, |
| 2930 | last_data_channel_config_.open_handshake_role); |
| 2931 | } |
| 2932 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 2933 | TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) { |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2934 | configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true); |
pthatcher@webrtc.org | 877ac76 | 2015-02-04 22:03:09 +0000 | [diff] [blame] | 2935 | Init(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2936 | SendAudioVideoStream1(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 2937 | SessionDescriptionInterface* offer = CreateOffer(); |
| 2938 | |
| 2939 | SetLocalDescriptionWithoutError(offer); |
| 2940 | |
| 2941 | voice_channel_ = media_engine_->GetVoiceChannel(0); |
| 2942 | |
| 2943 | ASSERT_TRUE(voice_channel_ != NULL); |
solenberg | 66f4339 | 2015-09-09 01:36:22 -0700 | [diff] [blame] | 2944 | const cricket::AudioOptions& audio_options = voice_channel_->options(); |
Karl Wiberg | be57983 | 2015-11-10 22:34:18 +0100 | [diff] [blame] | 2945 | 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] | 2946 | } |
| 2947 | |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2948 | // Tests that we can renegotiate new media content with ICE candidates in the |
| 2949 | // new remote SDP. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2950 | TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2951 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2952 | SetFactoryDtlsSrtp(); |
| 2953 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2954 | SendAudioOnlyStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2955 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2956 | SetLocalDescriptionWithoutError(offer); |
| 2957 | |
| 2958 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2959 | SetRemoteDescriptionWithoutError(answer); |
| 2960 | |
| 2961 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2962 | GetOptionsForRemoteOffer(&options); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2963 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 2964 | |
| 2965 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2966 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2967 | candidate1.set_component(1); |
| 2968 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 2969 | candidate1); |
| 2970 | EXPECT_TRUE(offer->AddCandidate(&ice_candidate)); |
| 2971 | SetRemoteDescriptionWithoutError(offer); |
| 2972 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 2973 | answer = CreateAnswer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2974 | SetLocalDescriptionWithoutError(answer); |
| 2975 | } |
| 2976 | |
| 2977 | // Tests that we can renegotiate new media content with ICE candidates separated |
| 2978 | // from the remote SDP. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2979 | TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) { |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 2980 | InitWithDtls(GetParam()); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2981 | SetFactoryDtlsSrtp(); |
| 2982 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 2983 | SendAudioOnlyStream2(); |
jiayl@webrtc.org | b18bf5e | 2014-08-04 18:34:16 +0000 | [diff] [blame] | 2984 | SessionDescriptionInterface* offer = CreateOffer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2985 | SetLocalDescriptionWithoutError(offer); |
| 2986 | |
| 2987 | SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
| 2988 | SetRemoteDescriptionWithoutError(answer); |
| 2989 | |
| 2990 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 2991 | GetOptionsForRemoteOffer(&options); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2992 | offer = CreateRemoteOffer(options, cricket::SEC_DISABLED); |
| 2993 | SetRemoteDescriptionWithoutError(offer); |
| 2994 | |
| 2995 | cricket::Candidate candidate1; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2996 | candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000)); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 2997 | candidate1.set_component(1); |
| 2998 | JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1, |
| 2999 | candidate1); |
| 3000 | EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate)); |
| 3001 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3002 | answer = CreateAnswer(); |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3003 | SetLocalDescriptionWithoutError(answer); |
| 3004 | } |
honghaiz | 7f77749 | 2016-02-02 21:54:01 -0800 | [diff] [blame] | 3005 | |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 3006 | #ifdef HAVE_QUIC |
| 3007 | TEST_P(WebRtcSessionTest, TestNegotiateQuic) { |
| 3008 | configuration_.enable_quic = true; |
| 3009 | InitWithDtls(GetParam()); |
| 3010 | EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC); |
| 3011 | SessionDescriptionInterface* offer = CreateOffer(); |
| 3012 | ASSERT_TRUE(offer); |
| 3013 | ASSERT_TRUE(offer->description()); |
| 3014 | SetLocalDescriptionWithoutError(offer); |
| 3015 | cricket::MediaSessionOptions options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3016 | GetOptionsForAnswer(&options); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 3017 | SessionDescriptionInterface* answer = |
| 3018 | CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED); |
| 3019 | ASSERT_TRUE(answer); |
| 3020 | ASSERT_TRUE(answer->description()); |
| 3021 | SetRemoteDescriptionWithoutError(answer); |
| 3022 | } |
| 3023 | #endif // HAVE_QUIC |
| 3024 | |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3025 | // Tests that RTX codec is removed from the answer when it isn't supported |
| 3026 | // by local side. |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 3027 | TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) { |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3028 | Init(); |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3029 | // Send video only to match the |kSdpWithRtx|. |
| 3030 | SendVideoOnlyStream2(); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3031 | std::string offer_sdp(kSdpWithRtx); |
| 3032 | |
| 3033 | SessionDescriptionInterface* offer = |
| 3034 | CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL); |
| 3035 | EXPECT_TRUE(offer->ToString(&offer_sdp)); |
| 3036 | |
| 3037 | // Offer SDP contains the RTX codec. |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 3038 | EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx")); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3039 | SetRemoteDescriptionWithoutError(offer); |
| 3040 | |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3041 | // |offered_media_sections_| is used when creating answer. |
| 3042 | offered_media_sections_.push_back(cricket::MediaDescriptionOptions( |
| 3043 | cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO, |
| 3044 | cricket::RtpTransceiverDirection(true, true), false)); |
| 3045 | // Don't create media section for audio in the answer. |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 3046 | SessionDescriptionInterface* answer = CreateAnswer(); |
zhihuang | 3a33465 | 2016-05-05 18:37:49 -0700 | [diff] [blame] | 3047 | // Answer SDP does not contain the RTX codec. |
| 3048 | EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx")); |
changbin.shao@webrtc.org | 2d25b44 | 2015-03-16 04:14:34 +0000 | [diff] [blame] | 3049 | SetLocalDescriptionWithoutError(answer); |
| 3050 | } |
jiayl@webrtc.org | e10d28c | 2014-07-17 17:07:49 +0000 | [diff] [blame] | 3051 | |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3052 | // This verifies that the voice channel after bundle has both options from video |
| 3053 | // and voice channels. |
| 3054 | TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) { |
| 3055 | InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3056 | SendAudioVideoStream1(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3057 | |
| 3058 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3059 | options.use_rtp_mux = true; |
| 3060 | |
| 3061 | SessionDescriptionInterface* offer = CreateOffer(options); |
| 3062 | SetLocalDescriptionWithoutError(offer); |
| 3063 | |
| 3064 | session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 3065 | rtc::Socket::Option::OPT_SNDBUF, 4000); |
| 3066 | |
| 3067 | session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP, |
| 3068 | rtc::Socket::Option::OPT_RCVBUF, 8000); |
| 3069 | |
| 3070 | int option_val; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3071 | EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3072 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 3073 | EXPECT_EQ(4000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3074 | EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3075 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 3076 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3077 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3078 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 3079 | EXPECT_EQ(8000, option_val); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3080 | EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3081 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 3082 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3083 | EXPECT_NE(session_->voice_rtp_transport_channel(), |
| 3084 | session_->video_rtp_transport_channel()); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3085 | |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3086 | SendAudioVideoStream2(); |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3087 | SessionDescriptionInterface* answer = |
| 3088 | CreateRemoteAnswer(session_->local_description()); |
| 3089 | SetRemoteDescriptionWithoutError(answer); |
| 3090 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3091 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3092 | rtc::Socket::Option::OPT_SNDBUF, &option_val)); |
| 3093 | EXPECT_EQ(4000, option_val); |
| 3094 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3095 | EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption( |
guoweis@webrtc.org | 4f85288 | 2015-03-12 20:09:44 +0000 | [diff] [blame] | 3096 | rtc::Socket::Option::OPT_RCVBUF, &option_val)); |
| 3097 | EXPECT_EQ(8000, option_val); |
| 3098 | } |
| 3099 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 3100 | // Test creating a session, request multiple offers, destroy the session |
| 3101 | // and make sure we got success/failure callbacks for all of the requests. |
| 3102 | // Background: crbug.com/507307 |
| 3103 | TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) { |
| 3104 | Init(); |
| 3105 | |
| 3106 | rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100]; |
| 3107 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 3108 | options.offer_to_receive_audio = |
| 3109 | RTCOfferAnswerOptions::kOfferToReceiveMediaTrue; |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3110 | cricket::MediaSessionOptions session_options; |
zhihuang | 1c378ed | 2017-08-17 14:10:50 -0700 | [diff] [blame] | 3111 | GetOptionsForOffer(options, &session_options); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 3112 | for (auto& o : observers) { |
| 3113 | o = new WebRtcSessionCreateSDPObserverForTest(); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 3114 | session_->CreateOffer(o, options, session_options); |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 3115 | } |
| 3116 | |
| 3117 | session_.reset(); |
| 3118 | |
tommi | 0f620f4 | 2015-07-09 03:25:02 -0700 | [diff] [blame] | 3119 | for (auto& o : observers) { |
| 3120 | // We expect to have received a notification now even if the session was |
| 3121 | // terminated. The offer creation may or may not have succeeded, but we |
| 3122 | // must have received a notification which, so the only invalid state |
| 3123 | // is kInit. |
| 3124 | EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); |
| 3125 | } |
| 3126 | } |
| 3127 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 3128 | TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) { |
| 3129 | TestPacketOptions(); |
| 3130 | } |
| 3131 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3132 | // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 3133 | // currently fails because upon disconnection and reconnection OnIceComplete is |
| 3134 | // called more than once without returning to IceGatheringGathering. |
Henrik Boström | 87713d0 | 2015-08-25 09:53:21 +0200 | [diff] [blame] | 3135 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 3136 | INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
| 3137 | WebRtcSessionTest, |
| 3138 | testing::Values(ALREADY_GENERATED, |
| 3139 | DTLS_IDENTITY_STORE)); |