wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2013 Google Inc. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 28 | #include "talk/app/webrtc/test/peerconnectiontestwrapper.h" |
henrike@webrtc.org | d968dd0 | 2014-08-13 18:39:43 +0000 | [diff] [blame] | 29 | #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 30 | #include "webrtc/base/gunit.h" |
| 31 | #include "webrtc/base/logging.h" |
| 32 | #include "webrtc/base/ssladapter.h" |
| 33 | #include "webrtc/base/sslstreamadapter.h" |
| 34 | #include "webrtc/base/stringencode.h" |
| 35 | #include "webrtc/base/stringutils.h" |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 36 | |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 37 | #define MAYBE_SKIP_TEST(feature) \ |
| 38 | if (!(feature())) { \ |
| 39 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 40 | return; \ |
| 41 | } |
| 42 | |
| 43 | using webrtc::DataChannelInterface; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 44 | using webrtc::FakeConstraints; |
| 45 | using webrtc::MediaConstraintsInterface; |
| 46 | using webrtc::MediaStreamInterface; |
| 47 | using webrtc::PeerConnectionInterface; |
| 48 | |
| 49 | namespace { |
| 50 | |
pthatcher | fa30180 | 2015-08-11 04:12:56 -0700 | [diff] [blame] | 51 | const char kExternalGiceUfrag[] = "1234567890123456"; |
| 52 | const char kExternalGicePwd[] = "123456789012345678901234"; |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 53 | const size_t kMaxWait = 10000; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 54 | |
| 55 | void RemoveLinesFromSdp(const std::string& line_start, |
| 56 | std::string* sdp) { |
| 57 | const char kSdpLineEnd[] = "\r\n"; |
| 58 | size_t ssrc_pos = 0; |
| 59 | while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != |
| 60 | std::string::npos) { |
| 61 | size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); |
| 62 | sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // Add |newlines| to the |message| after |line|. |
| 67 | void InjectAfter(const std::string& line, |
| 68 | const std::string& newlines, |
| 69 | std::string* message) { |
| 70 | const std::string tmp = line + newlines; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 71 | rtc::replace_substrs(line.c_str(), line.length(), |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 72 | tmp.c_str(), tmp.length(), message); |
| 73 | } |
| 74 | |
| 75 | void Replace(const std::string& line, |
| 76 | const std::string& newlines, |
| 77 | std::string* message) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 78 | rtc::replace_substrs(line.c_str(), line.length(), |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 79 | newlines.c_str(), newlines.length(), message); |
| 80 | } |
| 81 | |
| 82 | void UseExternalSdes(std::string* sdp) { |
| 83 | // Remove current crypto specification. |
| 84 | RemoveLinesFromSdp("a=crypto", sdp); |
| 85 | RemoveLinesFromSdp("a=fingerprint", sdp); |
| 86 | // Add external crypto. |
| 87 | const char kAudioSdes[] = |
| 88 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 89 | "inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR\r\n"; |
| 90 | const char kVideoSdes[] = |
| 91 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 92 | "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj\r\n"; |
| 93 | const char kDataSdes[] = |
| 94 | "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " |
| 95 | "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj\r\n"; |
| 96 | InjectAfter("a=mid:audio\r\n", kAudioSdes, sdp); |
| 97 | InjectAfter("a=mid:video\r\n", kVideoSdes, sdp); |
| 98 | InjectAfter("a=mid:data\r\n", kDataSdes, sdp); |
| 99 | } |
| 100 | |
pthatcher | fa30180 | 2015-08-11 04:12:56 -0700 | [diff] [blame] | 101 | void UseGice(std::string* sdp) { |
| 102 | InjectAfter("t=0 0\r\n", "a=ice-options:google-ice\r\n", sdp); |
| 103 | |
| 104 | std::string ufragline = "a=ice-ufrag:"; |
| 105 | std::string pwdline = "a=ice-pwd:"; |
| 106 | RemoveLinesFromSdp(ufragline, sdp); |
| 107 | RemoveLinesFromSdp(pwdline, sdp); |
| 108 | ufragline.append(kExternalGiceUfrag); |
| 109 | ufragline.append("\r\n"); |
| 110 | pwdline.append(kExternalGicePwd); |
| 111 | pwdline.append("\r\n"); |
| 112 | const std::string ufrag_pwd = ufragline + pwdline; |
| 113 | |
| 114 | InjectAfter("a=mid:audio\r\n", ufrag_pwd, sdp); |
| 115 | InjectAfter("a=mid:video\r\n", ufrag_pwd, sdp); |
| 116 | InjectAfter("a=mid:data\r\n", ufrag_pwd, sdp); |
| 117 | } |
| 118 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 119 | void RemoveBundle(std::string* sdp) { |
| 120 | RemoveLinesFromSdp("a=group:BUNDLE", sdp); |
| 121 | } |
| 122 | |
| 123 | } // namespace |
| 124 | |
| 125 | class PeerConnectionEndToEndTest |
| 126 | : public sigslot::has_slots<>, |
| 127 | public testing::Test { |
| 128 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 129 | typedef std::vector<rtc::scoped_refptr<DataChannelInterface> > |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 130 | DataChannelList; |
| 131 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 132 | PeerConnectionEndToEndTest() |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 133 | : caller_(new rtc::RefCountedObject<PeerConnectionTestWrapper>( |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 134 | "caller")), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 135 | callee_(new rtc::RefCountedObject<PeerConnectionTestWrapper>( |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 136 | "callee")) { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | void CreatePcs() { |
| 140 | CreatePcs(NULL); |
| 141 | } |
| 142 | |
| 143 | void CreatePcs(const MediaConstraintsInterface* pc_constraints) { |
| 144 | EXPECT_TRUE(caller_->CreatePc(pc_constraints)); |
| 145 | EXPECT_TRUE(callee_->CreatePc(pc_constraints)); |
| 146 | PeerConnectionTestWrapper::Connect(caller_.get(), callee_.get()); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 147 | |
| 148 | caller_->SignalOnDataChannel.connect( |
| 149 | this, &PeerConnectionEndToEndTest::OnCallerAddedDataChanel); |
| 150 | callee_->SignalOnDataChannel.connect( |
| 151 | this, &PeerConnectionEndToEndTest::OnCalleeAddedDataChannel); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | void GetAndAddUserMedia() { |
| 155 | FakeConstraints audio_constraints; |
| 156 | FakeConstraints video_constraints; |
| 157 | GetAndAddUserMedia(true, audio_constraints, true, video_constraints); |
| 158 | } |
| 159 | |
| 160 | void GetAndAddUserMedia(bool audio, FakeConstraints audio_constraints, |
| 161 | bool video, FakeConstraints video_constraints) { |
| 162 | caller_->GetAndAddUserMedia(audio, audio_constraints, |
| 163 | video, video_constraints); |
| 164 | callee_->GetAndAddUserMedia(audio, audio_constraints, |
| 165 | video, video_constraints); |
| 166 | } |
| 167 | |
| 168 | void Negotiate() { |
| 169 | caller_->CreateOffer(NULL); |
| 170 | } |
| 171 | |
| 172 | void WaitForCallEstablished() { |
| 173 | caller_->WaitForCallEstablished(); |
| 174 | callee_->WaitForCallEstablished(); |
| 175 | } |
| 176 | |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 177 | void WaitForConnection() { |
| 178 | caller_->WaitForConnection(); |
| 179 | callee_->WaitForConnection(); |
| 180 | } |
| 181 | |
pthatcher | fa30180 | 2015-08-11 04:12:56 -0700 | [diff] [blame] | 182 | void SetupLegacySdpConverter() { |
| 183 | caller_->SignalOnSdpCreated.connect( |
| 184 | this, &PeerConnectionEndToEndTest::ConvertToLegacySdp); |
| 185 | callee_->SignalOnSdpCreated.connect( |
| 186 | this, &PeerConnectionEndToEndTest::ConvertToLegacySdp); |
| 187 | } |
| 188 | |
| 189 | void ConvertToLegacySdp(std::string* sdp) { |
| 190 | UseExternalSdes(sdp); |
| 191 | UseGice(sdp); |
| 192 | RemoveBundle(sdp); |
| 193 | LOG(LS_INFO) << "ConvertToLegacySdp: " << *sdp; |
| 194 | } |
| 195 | |
| 196 | void SetupGiceConverter() { |
| 197 | caller_->SignalOnIceCandidateCreated.connect( |
| 198 | this, &PeerConnectionEndToEndTest::AddGiceCredsToCandidate); |
| 199 | callee_->SignalOnIceCandidateCreated.connect( |
| 200 | this, &PeerConnectionEndToEndTest::AddGiceCredsToCandidate); |
| 201 | } |
| 202 | |
| 203 | void AddGiceCredsToCandidate(std::string* sdp) { |
| 204 | std::string gice_creds = " username "; |
| 205 | gice_creds.append(kExternalGiceUfrag); |
| 206 | gice_creds.append(" password "); |
| 207 | gice_creds.append(kExternalGicePwd); |
| 208 | gice_creds.append("\r\n"); |
| 209 | Replace("\r\n", gice_creds, sdp); |
| 210 | LOG(LS_INFO) << "AddGiceCredsToCandidate: " << *sdp; |
| 211 | } |
| 212 | |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 213 | void OnCallerAddedDataChanel(DataChannelInterface* dc) { |
| 214 | caller_signaled_data_channels_.push_back(dc); |
| 215 | } |
| 216 | |
| 217 | void OnCalleeAddedDataChannel(DataChannelInterface* dc) { |
| 218 | callee_signaled_data_channels_.push_back(dc); |
| 219 | } |
| 220 | |
| 221 | // Tests that |dc1| and |dc2| can send to and receive from each other. |
| 222 | void TestDataChannelSendAndReceive( |
| 223 | DataChannelInterface* dc1, DataChannelInterface* dc2) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 224 | rtc::scoped_ptr<webrtc::MockDataChannelObserver> dc1_observer( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 225 | new webrtc::MockDataChannelObserver(dc1)); |
| 226 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 227 | rtc::scoped_ptr<webrtc::MockDataChannelObserver> dc2_observer( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 228 | new webrtc::MockDataChannelObserver(dc2)); |
| 229 | |
| 230 | static const std::string kDummyData = "abcdefg"; |
| 231 | webrtc::DataBuffer buffer(kDummyData); |
| 232 | EXPECT_TRUE(dc1->Send(buffer)); |
| 233 | EXPECT_EQ_WAIT(kDummyData, dc2_observer->last_message(), kMaxWait); |
| 234 | |
| 235 | EXPECT_TRUE(dc2->Send(buffer)); |
| 236 | EXPECT_EQ_WAIT(kDummyData, dc1_observer->last_message(), kMaxWait); |
| 237 | |
| 238 | EXPECT_EQ(1U, dc1_observer->received_message_count()); |
| 239 | EXPECT_EQ(1U, dc2_observer->received_message_count()); |
| 240 | } |
| 241 | |
| 242 | void WaitForDataChannelsToOpen(DataChannelInterface* local_dc, |
| 243 | const DataChannelList& remote_dc_list, |
| 244 | size_t remote_dc_index) { |
| 245 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, local_dc->state(), kMaxWait); |
| 246 | |
| 247 | EXPECT_TRUE_WAIT(remote_dc_list.size() > remote_dc_index, kMaxWait); |
| 248 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, |
| 249 | remote_dc_list[remote_dc_index]->state(), |
| 250 | kMaxWait); |
| 251 | EXPECT_EQ(local_dc->id(), remote_dc_list[remote_dc_index]->id()); |
| 252 | } |
| 253 | |
| 254 | void CloseDataChannels(DataChannelInterface* local_dc, |
| 255 | const DataChannelList& remote_dc_list, |
| 256 | size_t remote_dc_index) { |
| 257 | local_dc->Close(); |
| 258 | EXPECT_EQ_WAIT(DataChannelInterface::kClosed, local_dc->state(), kMaxWait); |
| 259 | EXPECT_EQ_WAIT(DataChannelInterface::kClosed, |
| 260 | remote_dc_list[remote_dc_index]->state(), |
| 261 | kMaxWait); |
| 262 | } |
| 263 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 264 | protected: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 265 | rtc::scoped_refptr<PeerConnectionTestWrapper> caller_; |
| 266 | rtc::scoped_refptr<PeerConnectionTestWrapper> callee_; |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 267 | DataChannelList caller_signaled_data_channels_; |
| 268 | DataChannelList callee_signaled_data_channels_; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 269 | }; |
| 270 | |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame^] | 271 | TEST_F(PeerConnectionEndToEndTest, Call) { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 272 | CreatePcs(); |
| 273 | GetAndAddUserMedia(); |
| 274 | Negotiate(); |
| 275 | WaitForCallEstablished(); |
| 276 | } |
| 277 | |
buildbot@webrtc.org | da510c5 | 2014-05-13 22:30:56 +0000 | [diff] [blame] | 278 | // Disabled per b/14899892 |
| 279 | TEST_F(PeerConnectionEndToEndTest, DISABLED_CallWithLegacySdp) { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 280 | FakeConstraints pc_constraints; |
| 281 | pc_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 282 | false); |
| 283 | CreatePcs(&pc_constraints); |
pthatcher | fa30180 | 2015-08-11 04:12:56 -0700 | [diff] [blame] | 284 | SetupLegacySdpConverter(); |
| 285 | SetupGiceConverter(); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 286 | GetAndAddUserMedia(); |
| 287 | Negotiate(); |
| 288 | WaitForCallEstablished(); |
| 289 | } |
wu@webrtc.org | b43202d | 2013-11-22 19:14:25 +0000 | [diff] [blame] | 290 | |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 291 | // Verifies that a DataChannel created before the negotiation can transition to |
| 292 | // "OPEN" and transfer data. |
| 293 | TEST_F(PeerConnectionEndToEndTest, CreateDataChannelBeforeNegotiate) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 294 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 295 | |
| 296 | CreatePcs(); |
| 297 | |
| 298 | webrtc::DataChannelInit init; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 299 | rtc::scoped_refptr<DataChannelInterface> caller_dc( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 300 | caller_->CreateDataChannel("data", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 301 | rtc::scoped_refptr<DataChannelInterface> callee_dc( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 302 | callee_->CreateDataChannel("data", init)); |
| 303 | |
| 304 | Negotiate(); |
| 305 | WaitForConnection(); |
| 306 | |
| 307 | WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); |
| 308 | WaitForDataChannelsToOpen(callee_dc, caller_signaled_data_channels_, 0); |
| 309 | |
| 310 | TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[0]); |
| 311 | TestDataChannelSendAndReceive(callee_dc, caller_signaled_data_channels_[0]); |
| 312 | |
| 313 | CloseDataChannels(caller_dc, callee_signaled_data_channels_, 0); |
| 314 | CloseDataChannels(callee_dc, caller_signaled_data_channels_, 0); |
| 315 | } |
| 316 | |
| 317 | // Verifies that a DataChannel created after the negotiation can transition to |
| 318 | // "OPEN" and transfer data. |
henrik.lundin@webrtc.org | 2236267 | 2014-11-03 13:38:50 +0000 | [diff] [blame] | 319 | #if defined(MEMORY_SANITIZER) |
| 320 | // Fails under MemorySanitizer: |
| 321 | // See https://code.google.com/p/webrtc/issues/detail?id=3980. |
| 322 | #define MAYBE_CreateDataChannelAfterNegotiate DISABLED_CreateDataChannelAfterNegotiate |
| 323 | #else |
| 324 | #define MAYBE_CreateDataChannelAfterNegotiate CreateDataChannelAfterNegotiate |
| 325 | #endif |
| 326 | TEST_F(PeerConnectionEndToEndTest, MAYBE_CreateDataChannelAfterNegotiate) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 327 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 328 | |
| 329 | CreatePcs(); |
| 330 | |
| 331 | webrtc::DataChannelInit init; |
| 332 | |
| 333 | // This DataChannel is for creating the data content in the negotiation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 334 | rtc::scoped_refptr<DataChannelInterface> dummy( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 335 | caller_->CreateDataChannel("data", init)); |
| 336 | Negotiate(); |
| 337 | WaitForConnection(); |
| 338 | |
| 339 | // Creates new DataChannels after the negotiation and verifies their states. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 340 | rtc::scoped_refptr<DataChannelInterface> caller_dc( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 341 | caller_->CreateDataChannel("hello", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 342 | rtc::scoped_refptr<DataChannelInterface> callee_dc( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 343 | callee_->CreateDataChannel("hello", init)); |
| 344 | |
| 345 | WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 1); |
| 346 | WaitForDataChannelsToOpen(callee_dc, caller_signaled_data_channels_, 0); |
| 347 | |
| 348 | TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[1]); |
| 349 | TestDataChannelSendAndReceive(callee_dc, caller_signaled_data_channels_[0]); |
| 350 | |
| 351 | CloseDataChannels(caller_dc, callee_signaled_data_channels_, 1); |
| 352 | CloseDataChannels(callee_dc, caller_signaled_data_channels_, 0); |
| 353 | } |
| 354 | |
| 355 | // Verifies that DataChannel IDs are even/odd based on the DTLS roles. |
| 356 | TEST_F(PeerConnectionEndToEndTest, DataChannelIdAssignment) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 357 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 358 | |
| 359 | CreatePcs(); |
| 360 | |
| 361 | webrtc::DataChannelInit init; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 362 | rtc::scoped_refptr<DataChannelInterface> caller_dc_1( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 363 | caller_->CreateDataChannel("data", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 364 | rtc::scoped_refptr<DataChannelInterface> callee_dc_1( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 365 | callee_->CreateDataChannel("data", init)); |
| 366 | |
| 367 | Negotiate(); |
| 368 | WaitForConnection(); |
| 369 | |
| 370 | EXPECT_EQ(1U, caller_dc_1->id() % 2); |
| 371 | EXPECT_EQ(0U, callee_dc_1->id() % 2); |
| 372 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 373 | rtc::scoped_refptr<DataChannelInterface> caller_dc_2( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 374 | caller_->CreateDataChannel("data", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 375 | rtc::scoped_refptr<DataChannelInterface> callee_dc_2( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 376 | callee_->CreateDataChannel("data", init)); |
| 377 | |
| 378 | EXPECT_EQ(1U, caller_dc_2->id() % 2); |
| 379 | EXPECT_EQ(0U, callee_dc_2->id() % 2); |
| 380 | } |
| 381 | |
| 382 | // Verifies that the message is received by the right remote DataChannel when |
| 383 | // there are multiple DataChannels. |
| 384 | TEST_F(PeerConnectionEndToEndTest, |
| 385 | MessageTransferBetweenTwoPairsOfDataChannels) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 386 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 387 | |
| 388 | CreatePcs(); |
| 389 | |
| 390 | webrtc::DataChannelInit init; |
| 391 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 392 | rtc::scoped_refptr<DataChannelInterface> caller_dc_1( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 393 | caller_->CreateDataChannel("data", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 394 | rtc::scoped_refptr<DataChannelInterface> caller_dc_2( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 395 | caller_->CreateDataChannel("data", init)); |
| 396 | |
| 397 | Negotiate(); |
| 398 | WaitForConnection(); |
| 399 | WaitForDataChannelsToOpen(caller_dc_1, callee_signaled_data_channels_, 0); |
| 400 | WaitForDataChannelsToOpen(caller_dc_2, callee_signaled_data_channels_, 1); |
| 401 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 402 | rtc::scoped_ptr<webrtc::MockDataChannelObserver> dc_1_observer( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 403 | new webrtc::MockDataChannelObserver(callee_signaled_data_channels_[0])); |
| 404 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 405 | rtc::scoped_ptr<webrtc::MockDataChannelObserver> dc_2_observer( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 406 | new webrtc::MockDataChannelObserver(callee_signaled_data_channels_[1])); |
| 407 | |
| 408 | const std::string message_1 = "hello 1"; |
| 409 | const std::string message_2 = "hello 2"; |
| 410 | |
| 411 | caller_dc_1->Send(webrtc::DataBuffer(message_1)); |
| 412 | EXPECT_EQ_WAIT(message_1, dc_1_observer->last_message(), kMaxWait); |
| 413 | |
| 414 | caller_dc_2->Send(webrtc::DataBuffer(message_2)); |
| 415 | EXPECT_EQ_WAIT(message_2, dc_2_observer->last_message(), kMaxWait); |
| 416 | |
| 417 | EXPECT_EQ(1U, dc_1_observer->received_message_count()); |
| 418 | EXPECT_EQ(1U, dc_2_observer->received_message_count()); |
| 419 | } |