| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "webrtc/base/gunit.h" | 13 #include "webrtc/base/gunit.h" |
| 14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 15 #include "webrtc/base/ssladapter.h" | 15 #include "webrtc/base/ssladapter.h" |
| 16 #include "webrtc/base/thread.h" | 16 #include "webrtc/base/thread.h" |
| 17 #include "webrtc/base/sslstreamadapter.h" | 17 #include "webrtc/base/sslstreamadapter.h" |
| 18 #include "webrtc/base/stringencode.h" | 18 #include "webrtc/base/stringencode.h" |
| 19 #include "webrtc/base/stringutils.h" | 19 #include "webrtc/base/stringutils.h" |
| 20 #ifdef WEBRTC_ANDROID | 20 #ifdef WEBRTC_ANDROID |
| 21 #include "webrtc/pc/test/androidtestinitializer.h" | 21 #include "webrtc/pc/test/androidtestinitializer.h" |
| 22 #endif | 22 #endif |
| 23 #include "webrtc/pc/test/peerconnectiontestwrapper.h" | 23 #include "webrtc/pc/test/peerconnectiontestwrapper.h" |
| 24 // Notice that mockpeerconnectionobservers.h must be included after the above! | 24 // Notice that mockpeerconnectionobservers.h must be included after the above! |
| 25 #include "webrtc/pc/test/mockpeerconnectionobservers.h" | 25 #include "webrtc/pc/test/mockpeerconnectionobservers.h" |
| 26 | 26 |
| 27 #define MAYBE_SKIP_TEST(feature) \ | |
| 28 if (!(feature())) { \ | |
| 29 LOG(LS_INFO) << "Feature disabled... skipping"; \ | |
| 30 return; \ | |
| 31 } | |
| 32 | |
| 33 using webrtc::DataChannelInterface; | 27 using webrtc::DataChannelInterface; |
| 34 using webrtc::FakeConstraints; | 28 using webrtc::FakeConstraints; |
| 35 using webrtc::MediaConstraintsInterface; | 29 using webrtc::MediaConstraintsInterface; |
| 36 using webrtc::MediaStreamInterface; | 30 using webrtc::MediaStreamInterface; |
| 37 using webrtc::PeerConnectionInterface; | 31 using webrtc::PeerConnectionInterface; |
| 38 | 32 |
| 39 namespace { | 33 namespace { |
| 40 | 34 |
| 41 const int kMaxWait = 10000; | 35 const int kMaxWait = 10000; |
| 42 | 36 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 GetAndAddUserMedia(); | 185 GetAndAddUserMedia(); |
| 192 Negotiate(); | 186 Negotiate(); |
| 193 WaitForCallEstablished(); | 187 WaitForCallEstablished(); |
| 194 } | 188 } |
| 195 #endif // !defined(ADDRESS_SANITIZER) | 189 #endif // !defined(ADDRESS_SANITIZER) |
| 196 | 190 |
| 197 #ifdef HAVE_SCTP | 191 #ifdef HAVE_SCTP |
| 198 // Verifies that a DataChannel created before the negotiation can transition to | 192 // Verifies that a DataChannel created before the negotiation can transition to |
| 199 // "OPEN" and transfer data. | 193 // "OPEN" and transfer data. |
| 200 TEST_F(PeerConnectionEndToEndTest, CreateDataChannelBeforeNegotiate) { | 194 TEST_F(PeerConnectionEndToEndTest, CreateDataChannelBeforeNegotiate) { |
| 201 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
| 202 | |
| 203 CreatePcs(); | 195 CreatePcs(); |
| 204 | 196 |
| 205 webrtc::DataChannelInit init; | 197 webrtc::DataChannelInit init; |
| 206 rtc::scoped_refptr<DataChannelInterface> caller_dc( | 198 rtc::scoped_refptr<DataChannelInterface> caller_dc( |
| 207 caller_->CreateDataChannel("data", init)); | 199 caller_->CreateDataChannel("data", init)); |
| 208 rtc::scoped_refptr<DataChannelInterface> callee_dc( | 200 rtc::scoped_refptr<DataChannelInterface> callee_dc( |
| 209 callee_->CreateDataChannel("data", init)); | 201 callee_->CreateDataChannel("data", init)); |
| 210 | 202 |
| 211 Negotiate(); | 203 Negotiate(); |
| 212 WaitForConnection(); | 204 WaitForConnection(); |
| 213 | 205 |
| 214 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); | 206 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); |
| 215 WaitForDataChannelsToOpen(callee_dc, caller_signaled_data_channels_, 0); | 207 WaitForDataChannelsToOpen(callee_dc, caller_signaled_data_channels_, 0); |
| 216 | 208 |
| 217 TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[0]); | 209 TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[0]); |
| 218 TestDataChannelSendAndReceive(callee_dc, caller_signaled_data_channels_[0]); | 210 TestDataChannelSendAndReceive(callee_dc, caller_signaled_data_channels_[0]); |
| 219 | 211 |
| 220 CloseDataChannels(caller_dc, callee_signaled_data_channels_, 0); | 212 CloseDataChannels(caller_dc, callee_signaled_data_channels_, 0); |
| 221 CloseDataChannels(callee_dc, caller_signaled_data_channels_, 0); | 213 CloseDataChannels(callee_dc, caller_signaled_data_channels_, 0); |
| 222 } | 214 } |
| 223 | 215 |
| 224 // Verifies that a DataChannel created after the negotiation can transition to | 216 // Verifies that a DataChannel created after the negotiation can transition to |
| 225 // "OPEN" and transfer data. | 217 // "OPEN" and transfer data. |
| 226 TEST_F(PeerConnectionEndToEndTest, CreateDataChannelAfterNegotiate) { | 218 TEST_F(PeerConnectionEndToEndTest, CreateDataChannelAfterNegotiate) { |
| 227 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
| 228 | |
| 229 CreatePcs(); | 219 CreatePcs(); |
| 230 | 220 |
| 231 webrtc::DataChannelInit init; | 221 webrtc::DataChannelInit init; |
| 232 | 222 |
| 233 // This DataChannel is for creating the data content in the negotiation. | 223 // This DataChannel is for creating the data content in the negotiation. |
| 234 rtc::scoped_refptr<DataChannelInterface> dummy( | 224 rtc::scoped_refptr<DataChannelInterface> dummy( |
| 235 caller_->CreateDataChannel("data", init)); | 225 caller_->CreateDataChannel("data", init)); |
| 236 Negotiate(); | 226 Negotiate(); |
| 237 WaitForConnection(); | 227 WaitForConnection(); |
| 238 | 228 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 250 | 240 |
| 251 TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[1]); | 241 TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[1]); |
| 252 TestDataChannelSendAndReceive(callee_dc, caller_signaled_data_channels_[0]); | 242 TestDataChannelSendAndReceive(callee_dc, caller_signaled_data_channels_[0]); |
| 253 | 243 |
| 254 CloseDataChannels(caller_dc, callee_signaled_data_channels_, 1); | 244 CloseDataChannels(caller_dc, callee_signaled_data_channels_, 1); |
| 255 CloseDataChannels(callee_dc, caller_signaled_data_channels_, 0); | 245 CloseDataChannels(callee_dc, caller_signaled_data_channels_, 0); |
| 256 } | 246 } |
| 257 | 247 |
| 258 // Verifies that DataChannel IDs are even/odd based on the DTLS roles. | 248 // Verifies that DataChannel IDs are even/odd based on the DTLS roles. |
| 259 TEST_F(PeerConnectionEndToEndTest, DataChannelIdAssignment) { | 249 TEST_F(PeerConnectionEndToEndTest, DataChannelIdAssignment) { |
| 260 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
| 261 | |
| 262 CreatePcs(); | 250 CreatePcs(); |
| 263 | 251 |
| 264 webrtc::DataChannelInit init; | 252 webrtc::DataChannelInit init; |
| 265 rtc::scoped_refptr<DataChannelInterface> caller_dc_1( | 253 rtc::scoped_refptr<DataChannelInterface> caller_dc_1( |
| 266 caller_->CreateDataChannel("data", init)); | 254 caller_->CreateDataChannel("data", init)); |
| 267 rtc::scoped_refptr<DataChannelInterface> callee_dc_1( | 255 rtc::scoped_refptr<DataChannelInterface> callee_dc_1( |
| 268 callee_->CreateDataChannel("data", init)); | 256 callee_->CreateDataChannel("data", init)); |
| 269 | 257 |
| 270 Negotiate(); | 258 Negotiate(); |
| 271 WaitForConnection(); | 259 WaitForConnection(); |
| 272 | 260 |
| 273 EXPECT_EQ(1U, caller_dc_1->id() % 2); | 261 EXPECT_EQ(1U, caller_dc_1->id() % 2); |
| 274 EXPECT_EQ(0U, callee_dc_1->id() % 2); | 262 EXPECT_EQ(0U, callee_dc_1->id() % 2); |
| 275 | 263 |
| 276 rtc::scoped_refptr<DataChannelInterface> caller_dc_2( | 264 rtc::scoped_refptr<DataChannelInterface> caller_dc_2( |
| 277 caller_->CreateDataChannel("data", init)); | 265 caller_->CreateDataChannel("data", init)); |
| 278 rtc::scoped_refptr<DataChannelInterface> callee_dc_2( | 266 rtc::scoped_refptr<DataChannelInterface> callee_dc_2( |
| 279 callee_->CreateDataChannel("data", init)); | 267 callee_->CreateDataChannel("data", init)); |
| 280 | 268 |
| 281 EXPECT_EQ(1U, caller_dc_2->id() % 2); | 269 EXPECT_EQ(1U, caller_dc_2->id() % 2); |
| 282 EXPECT_EQ(0U, callee_dc_2->id() % 2); | 270 EXPECT_EQ(0U, callee_dc_2->id() % 2); |
| 283 } | 271 } |
| 284 | 272 |
| 285 // Verifies that the message is received by the right remote DataChannel when | 273 // Verifies that the message is received by the right remote DataChannel when |
| 286 // there are multiple DataChannels. | 274 // there are multiple DataChannels. |
| 287 TEST_F(PeerConnectionEndToEndTest, | 275 TEST_F(PeerConnectionEndToEndTest, |
| 288 MessageTransferBetweenTwoPairsOfDataChannels) { | 276 MessageTransferBetweenTwoPairsOfDataChannels) { |
| 289 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
| 290 | |
| 291 CreatePcs(); | 277 CreatePcs(); |
| 292 | 278 |
| 293 webrtc::DataChannelInit init; | 279 webrtc::DataChannelInit init; |
| 294 | 280 |
| 295 rtc::scoped_refptr<DataChannelInterface> caller_dc_1( | 281 rtc::scoped_refptr<DataChannelInterface> caller_dc_1( |
| 296 caller_->CreateDataChannel("data", init)); | 282 caller_->CreateDataChannel("data", init)); |
| 297 rtc::scoped_refptr<DataChannelInterface> caller_dc_2( | 283 rtc::scoped_refptr<DataChannelInterface> caller_dc_2( |
| 298 caller_->CreateDataChannel("data", init)); | 284 caller_->CreateDataChannel("data", init)); |
| 299 | 285 |
| 300 Negotiate(); | 286 Negotiate(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 // Verifies that a DataChannel added from an OPEN message functions after | 388 // Verifies that a DataChannel added from an OPEN message functions after |
| 403 // a channel has been previously closed (webrtc issue 3778). | 389 // a channel has been previously closed (webrtc issue 3778). |
| 404 // This previously failed because the new channel re-uses the ID of the closed | 390 // This previously failed because the new channel re-uses the ID of the closed |
| 405 // channel, and the closed channel was incorrectly still assigned to the id. | 391 // channel, and the closed channel was incorrectly still assigned to the id. |
| 406 // TODO(deadbeef): This is disabled because there's currently a race condition | 392 // TODO(deadbeef): This is disabled because there's currently a race condition |
| 407 // caused by the fact that a data channel signals that it's closed before it | 393 // caused by the fact that a data channel signals that it's closed before it |
| 408 // really is. Re-enable this test once that's fixed. | 394 // really is. Re-enable this test once that's fixed. |
| 409 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4453 | 395 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4453 |
| 410 TEST_F(PeerConnectionEndToEndTest, | 396 TEST_F(PeerConnectionEndToEndTest, |
| 411 DISABLED_DataChannelFromOpenWorksAfterClose) { | 397 DISABLED_DataChannelFromOpenWorksAfterClose) { |
| 412 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
| 413 | |
| 414 CreatePcs(); | 398 CreatePcs(); |
| 415 | 399 |
| 416 webrtc::DataChannelInit init; | 400 webrtc::DataChannelInit init; |
| 417 rtc::scoped_refptr<DataChannelInterface> caller_dc( | 401 rtc::scoped_refptr<DataChannelInterface> caller_dc( |
| 418 caller_->CreateDataChannel("data", init)); | 402 caller_->CreateDataChannel("data", init)); |
| 419 | 403 |
| 420 Negotiate(); | 404 Negotiate(); |
| 421 WaitForConnection(); | 405 WaitForConnection(); |
| 422 | 406 |
| 423 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); | 407 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); |
| 424 CloseDataChannels(caller_dc, callee_signaled_data_channels_, 0); | 408 CloseDataChannels(caller_dc, callee_signaled_data_channels_, 0); |
| 425 | 409 |
| 426 // Create a new channel and ensure it works after closing the previous one. | 410 // Create a new channel and ensure it works after closing the previous one. |
| 427 caller_dc = caller_->CreateDataChannel("data2", init); | 411 caller_dc = caller_->CreateDataChannel("data2", init); |
| 428 | 412 |
| 429 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 1); | 413 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 1); |
| 430 TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[1]); | 414 TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[1]); |
| 431 | 415 |
| 432 CloseDataChannels(caller_dc, callee_signaled_data_channels_, 1); | 416 CloseDataChannels(caller_dc, callee_signaled_data_channels_, 1); |
| 433 } | 417 } |
| 434 | 418 |
| 435 // This tests that if a data channel is closed remotely while not referenced | 419 // This tests that if a data channel is closed remotely while not referenced |
| 436 // by the application (meaning only the PeerConnection contributes to its | 420 // by the application (meaning only the PeerConnection contributes to its |
| 437 // reference count), no memory access violation will occur. | 421 // reference count), no memory access violation will occur. |
| 438 // See: https://code.google.com/p/chromium/issues/detail?id=565048 | 422 // See: https://code.google.com/p/chromium/issues/detail?id=565048 |
| 439 TEST_F(PeerConnectionEndToEndTest, CloseDataChannelRemotelyWhileNotReferenced) { | 423 TEST_F(PeerConnectionEndToEndTest, CloseDataChannelRemotelyWhileNotReferenced) { |
| 440 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); | |
| 441 | |
| 442 CreatePcs(); | 424 CreatePcs(); |
| 443 | 425 |
| 444 webrtc::DataChannelInit init; | 426 webrtc::DataChannelInit init; |
| 445 rtc::scoped_refptr<DataChannelInterface> caller_dc( | 427 rtc::scoped_refptr<DataChannelInterface> caller_dc( |
| 446 caller_->CreateDataChannel("data", init)); | 428 caller_->CreateDataChannel("data", init)); |
| 447 | 429 |
| 448 Negotiate(); | 430 Negotiate(); |
| 449 WaitForConnection(); | 431 WaitForConnection(); |
| 450 | 432 |
| 451 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); | 433 WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); |
| 452 // This removes the reference to the remote data channel that we hold. | 434 // This removes the reference to the remote data channel that we hold. |
| 453 callee_signaled_data_channels_.clear(); | 435 callee_signaled_data_channels_.clear(); |
| 454 caller_dc->Close(); | 436 caller_dc->Close(); |
| 455 EXPECT_EQ_WAIT(DataChannelInterface::kClosed, caller_dc->state(), kMaxWait); | 437 EXPECT_EQ_WAIT(DataChannelInterface::kClosed, caller_dc->state(), kMaxWait); |
| 456 | 438 |
| 457 // Wait for a bit longer so the remote data channel will receive the | 439 // Wait for a bit longer so the remote data channel will receive the |
| 458 // close message and be destroyed. | 440 // close message and be destroyed. |
| 459 rtc::Thread::Current()->ProcessMessages(100); | 441 rtc::Thread::Current()->ProcessMessages(100); |
| 460 } | 442 } |
| 461 #endif // HAVE_SCTP | 443 #endif // HAVE_SCTP |
| OLD | NEW |