OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
427 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(), | 427 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(), |
428 rtc::Thread::Current(), allocator_.get(), &observer_, | 428 rtc::Thread::Current(), allocator_.get(), &observer_, |
429 std::unique_ptr<cricket::TransportController>( | 429 std::unique_ptr<cricket::TransportController>( |
430 new cricket::TransportController(rtc::Thread::Current(), | 430 new cricket::TransportController(rtc::Thread::Current(), |
431 rtc::Thread::Current(), | 431 rtc::Thread::Current(), |
432 allocator_.get())), | 432 allocator_.get())), |
433 std::unique_ptr<FakeSctpTransportFactory>( | 433 std::unique_ptr<FakeSctpTransportFactory>( |
434 fake_sctp_transport_factory_))); | 434 fake_sctp_transport_factory_))); |
435 session_->SignalDataChannelOpenMessage.connect( | 435 session_->SignalDataChannelOpenMessage.connect( |
436 this, &WebRtcSessionTest::OnDataChannelOpenMessage); | 436 this, &WebRtcSessionTest::OnDataChannelOpenMessage); |
437 session_->GetOnDestroyedSignal()->connect( | |
438 this, &WebRtcSessionTest::OnSessionDestroyed); | |
439 | 437 |
440 configuration_.rtcp_mux_policy = rtcp_mux_policy; | 438 configuration_.rtcp_mux_policy = rtcp_mux_policy; |
441 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, | 439 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
442 observer_.ice_connection_state_); | 440 observer_.ice_connection_state_); |
443 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, | 441 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
444 observer_.ice_gathering_state_); | 442 observer_.ice_gathering_state_); |
445 | 443 |
446 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator), | 444 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator), |
447 configuration_)); | 445 configuration_)); |
448 session_->set_metrics_observer(metrics_observer_); | 446 session_->set_metrics_observer(metrics_observer_); |
449 } | 447 } |
450 | 448 |
451 void OnDataChannelOpenMessage(const std::string& label, | 449 void OnDataChannelOpenMessage(const std::string& label, |
452 const InternalDataChannelInit& config) { | 450 const InternalDataChannelInit& config) { |
453 last_data_channel_label_ = label; | 451 last_data_channel_label_ = label; |
454 last_data_channel_config_ = config; | 452 last_data_channel_config_ = config; |
455 } | 453 } |
456 | 454 |
457 void OnSessionDestroyed() { session_destroyed_ = true; } | |
458 | |
459 void Init() { | 455 void Init() { |
460 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate); | 456 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
461 } | 457 } |
462 | 458 |
463 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { | 459 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
464 Init(nullptr, rtcp_mux_policy); | 460 Init(nullptr, rtcp_mux_policy); |
465 } | 461 } |
466 | 462 |
467 void InitWithBundlePolicy( | 463 void InitWithBundlePolicy( |
468 PeerConnectionInterface::BundlePolicy bundle_policy) { | 464 PeerConnectionInterface::BundlePolicy bundle_policy) { |
(...skipping 26 matching lines...) Expand all Loading... | |
495 | 491 |
496 // Init with DTLS with a store that will fail to generate a certificate. | 492 // Init with DTLS with a store that will fail to generate a certificate. |
497 void InitWithDtlsIdentityGenFail() { | 493 void InitWithDtlsIdentityGenFail() { |
498 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( | 494 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
499 new FakeRTCCertificateGenerator()); | 495 new FakeRTCCertificateGenerator()); |
500 cert_generator->set_should_fail(true); | 496 cert_generator->set_should_fail(true); |
501 Init(std::move(cert_generator), | 497 Init(std::move(cert_generator), |
502 PeerConnectionInterface::kRtcpMuxPolicyNegotiate); | 498 PeerConnectionInterface::kRtcpMuxPolicyNegotiate); |
503 } | 499 } |
504 | 500 |
505 void InitWithDtmfCodec() { | |
506 // Add kTelephoneEventCodec for dtmf test. | |
507 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, | |
508 0, 1); | |
509 std::vector<cricket::AudioCodec> codecs; | |
510 codecs.push_back(kTelephoneEventCodec); | |
511 media_engine_->SetAudioCodecs(codecs); | |
512 desc_factory_->set_audio_codecs(codecs, codecs); | |
513 Init(); | |
514 } | |
515 | |
516 void InitWithGcm() { | 501 void InitWithGcm() { |
517 rtc::CryptoOptions crypto_options; | 502 rtc::CryptoOptions crypto_options; |
518 crypto_options.enable_gcm_crypto_suites = true; | 503 crypto_options.enable_gcm_crypto_suites = true; |
519 channel_manager_->SetCryptoOptions(crypto_options); | 504 channel_manager_->SetCryptoOptions(crypto_options); |
520 with_gcm_ = true; | 505 with_gcm_ = true; |
521 Init(); | 506 Init(); |
522 } | 507 } |
523 | 508 |
524 void SendAudioVideoStream1() { | 509 void SendAudioVideoStream1() { |
525 send_stream_1_ = true; | 510 send_stream_1_ = true; |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1190 // SetRemoteDescription to enable rtcp mux. | 1175 // SetRemoteDescription to enable rtcp mux. |
1191 SetRemoteDescriptionWithoutError(new_answer); | 1176 SetRemoteDescriptionWithoutError(new_answer); |
1192 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); | 1177 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout); |
1193 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); | 1178 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size()); |
1194 if (bundle) { | 1179 if (bundle) { |
1195 EXPECT_EQ(0, observer_.mline_1_candidates_.size()); | 1180 EXPECT_EQ(0, observer_.mline_1_candidates_.size()); |
1196 } else { | 1181 } else { |
1197 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); | 1182 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size()); |
1198 } | 1183 } |
1199 } | 1184 } |
1200 // Tests that we can only send DTMF when the dtmf codec is supported. | |
1201 void TestCanInsertDtmf(bool can) { | |
1202 if (can) { | |
1203 InitWithDtmfCodec(); | |
1204 } else { | |
1205 Init(); | |
1206 } | |
1207 SendAudioVideoStream1(); | |
1208 CreateAndSetRemoteOfferAndLocalAnswer(); | |
1209 EXPECT_FALSE(session_->CanInsertDtmf("")); | |
1210 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1)); | |
1211 } | |
1212 | 1185 |
1213 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc, | 1186 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc, |
1214 const std::string& codec_name) { | 1187 const std::string& codec_name) { |
1215 for (const auto& content : desc->description()->contents()) { | 1188 for (const auto& content : desc->description()->contents()) { |
1216 if (static_cast<cricket::MediaContentDescription*>(content.description) | 1189 if (static_cast<cricket::MediaContentDescription*>(content.description) |
1217 ->type() == cricket::MEDIA_TYPE_VIDEO) { | 1190 ->type() == cricket::MEDIA_TYPE_VIDEO) { |
1218 const auto* mdesc = | 1191 const auto* mdesc = |
1219 static_cast<cricket::VideoContentDescription*>(content.description); | 1192 static_cast<cricket::VideoContentDescription*>(content.description); |
1220 for (const auto& codec : mdesc->codecs()) { | 1193 for (const auto& codec : mdesc->codecs()) { |
1221 if (codec.name == codec_name) { | 1194 if (codec.name == codec_name) { |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1560 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; | 1533 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
1561 // The following flags affect options created for CreateOffer/CreateAnswer. | 1534 // The following flags affect options created for CreateOffer/CreateAnswer. |
1562 bool send_stream_1_ = false; | 1535 bool send_stream_1_ = false; |
1563 bool send_stream_2_ = false; | 1536 bool send_stream_2_ = false; |
1564 bool send_audio_ = false; | 1537 bool send_audio_ = false; |
1565 bool send_video_ = false; | 1538 bool send_video_ = false; |
1566 rtc::scoped_refptr<DataChannel> data_channel_; | 1539 rtc::scoped_refptr<DataChannel> data_channel_; |
1567 // Last values received from data channel creation signal. | 1540 // Last values received from data channel creation signal. |
1568 std::string last_data_channel_label_; | 1541 std::string last_data_channel_label_; |
1569 InternalDataChannelInit last_data_channel_config_; | 1542 InternalDataChannelInit last_data_channel_config_; |
1570 bool session_destroyed_ = false; | |
1571 bool with_gcm_ = false; | 1543 bool with_gcm_ = false; |
1572 }; | 1544 }; |
1573 | 1545 |
1574 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { | 1546 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { |
1575 InitWithDtls(GetParam()); | 1547 InitWithDtls(GetParam()); |
1576 // SDES is disabled when DTLS is on. | 1548 // SDES is disabled when DTLS is on. |
1577 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); | 1549 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); |
1578 } | 1550 } |
1579 | 1551 |
1580 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { | 1552 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { |
(...skipping 1919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3500 // Trying unmodified SDP. | 3472 // Trying unmodified SDP. |
3501 SetLocalDescriptionWithoutError(offer); | 3473 SetLocalDescriptionWithoutError(offer); |
3502 } | 3474 } |
3503 | 3475 |
3504 TEST_F(WebRtcSessionTest, SetSetupGcm) { | 3476 TEST_F(WebRtcSessionTest, SetSetupGcm) { |
3505 InitWithGcm(); | 3477 InitWithGcm(); |
3506 SendAudioVideoStream1(); | 3478 SendAudioVideoStream1(); |
3507 CreateAndSetRemoteOfferAndLocalAnswer(); | 3479 CreateAndSetRemoteOfferAndLocalAnswer(); |
3508 } | 3480 } |
3509 | 3481 |
3510 TEST_F(WebRtcSessionTest, CanNotInsertDtmf) { | |
3511 TestCanInsertDtmf(false); | |
3512 } | |
3513 | |
3514 TEST_F(WebRtcSessionTest, CanInsertDtmf) { | |
3515 TestCanInsertDtmf(true); | |
3516 } | |
3517 | |
3518 TEST_F(WebRtcSessionTest, InsertDtmf) { | |
3519 // Setup | |
3520 Init(); | |
3521 SendAudioVideoStream1(); | |
3522 CreateAndSetRemoteOfferAndLocalAnswer(); | |
3523 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); | |
3524 EXPECT_EQ(0U, channel->dtmf_info_queue().size()); | |
3525 | |
3526 // Insert DTMF | |
3527 const int expected_duration = 90; | |
3528 session_->InsertDtmf(kAudioTrack1, 0, expected_duration); | |
3529 session_->InsertDtmf(kAudioTrack1, 1, expected_duration); | |
3530 session_->InsertDtmf(kAudioTrack1, 2, expected_duration); | |
3531 | |
3532 // Verify | |
3533 ASSERT_EQ(3U, channel->dtmf_info_queue().size()); | |
3534 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); | |
3535 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0, | |
3536 expected_duration)); | |
3537 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1, | |
3538 expected_duration)); | |
3539 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2, | |
3540 expected_duration)); | |
3541 } | |
Taylor Brandstetter
2017/02/01 22:10:00
Moved to RtpSender tests.
| |
3542 | |
3543 // This test verifies the |initial_offerer| flag when session initiates the | 3482 // This test verifies the |initial_offerer| flag when session initiates the |
3544 // call. | 3483 // call. |
3545 TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { | 3484 TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) { |
3546 Init(); | 3485 Init(); |
3547 EXPECT_FALSE(session_->initial_offerer()); | 3486 EXPECT_FALSE(session_->initial_offerer()); |
3548 SessionDescriptionInterface* offer = CreateOffer(); | 3487 SessionDescriptionInterface* offer = CreateOffer(); |
3549 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); | 3488 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer); |
3550 SetLocalDescriptionWithoutError(offer); | 3489 SetLocalDescriptionWithoutError(offer); |
3551 EXPECT_TRUE(session_->initial_offerer()); | 3490 EXPECT_TRUE(session_->initial_offerer()); |
3552 SetRemoteDescriptionWithoutError(answer); | 3491 SetRemoteDescriptionWithoutError(answer); |
(...skipping 840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4393 // must have received a notification which, so the only invalid state | 4332 // must have received a notification which, so the only invalid state |
4394 // is kInit. | 4333 // is kInit. |
4395 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); | 4334 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state()); |
4396 } | 4335 } |
4397 } | 4336 } |
4398 | 4337 |
4399 TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) { | 4338 TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) { |
4400 TestPacketOptions(); | 4339 TestPacketOptions(); |
4401 } | 4340 } |
4402 | 4341 |
4403 // Make sure the signal from "GetOnDestroyedSignal()" fires when the session | |
4404 // is destroyed. | |
4405 TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) { | |
4406 Init(); | |
4407 session_.reset(); | |
4408 EXPECT_TRUE(session_destroyed_); | |
4409 } | |
4410 | |
4411 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test | 4342 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
4412 // currently fails because upon disconnection and reconnection OnIceComplete is | 4343 // currently fails because upon disconnection and reconnection OnIceComplete is |
4413 // called more than once without returning to IceGatheringGathering. | 4344 // called more than once without returning to IceGatheringGathering. |
4414 | 4345 |
4415 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, | 4346 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
4416 WebRtcSessionTest, | 4347 WebRtcSessionTest, |
4417 testing::Values(ALREADY_GENERATED, | 4348 testing::Values(ALREADY_GENERATED, |
4418 DTLS_IDENTITY_STORE)); | 4349 DTLS_IDENTITY_STORE)); |
OLD | NEW |