| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 void RemoveInterface(const SocketAddress& addr) { | 413 void RemoveInterface(const SocketAddress& addr) { |
| 414 network_manager_.RemoveInterface(addr); | 414 network_manager_.RemoveInterface(addr); |
| 415 } | 415 } |
| 416 | 416 |
| 417 // If |cert_generator| != null or |rtc_configuration| contains |certificates| | 417 // If |cert_generator| != null or |rtc_configuration| contains |certificates| |
| 418 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration| | 418 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration| |
| 419 // options. When DTLS is enabled a certificate will be used if provided, | 419 // options. When DTLS is enabled a certificate will be used if provided, |
| 420 // otherwise one will be generated using the |cert_generator|. | 420 // otherwise one will be generated using the |cert_generator|. |
| 421 void Init( | 421 void Init( |
| 422 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, | 422 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, |
| 423 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { | 423 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy, |
| 424 const rtc::CryptoOptions& crypto_options) { |
| 424 ASSERT_TRUE(session_.get() == NULL); | 425 ASSERT_TRUE(session_.get() == NULL); |
| 425 fake_sctp_transport_factory_ = new FakeSctpTransportFactory(); | 426 fake_sctp_transport_factory_ = new FakeSctpTransportFactory(); |
| 426 session_.reset(new WebRtcSessionForTest( | 427 session_.reset(new WebRtcSessionForTest( |
| 427 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(), | 428 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(), |
| 428 rtc::Thread::Current(), allocator_.get(), &observer_, | 429 rtc::Thread::Current(), allocator_.get(), &observer_, |
| 429 std::unique_ptr<cricket::TransportController>( | 430 std::unique_ptr<cricket::TransportController>( |
| 430 new cricket::TransportController(rtc::Thread::Current(), | 431 new cricket::TransportController( |
| 431 rtc::Thread::Current(), | 432 rtc::Thread::Current(), rtc::Thread::Current(), |
| 432 allocator_.get())), | 433 allocator_.get(), |
| 434 /*redetermine_role_on_ice_restart=*/true, crypto_options)), |
| 433 std::unique_ptr<FakeSctpTransportFactory>( | 435 std::unique_ptr<FakeSctpTransportFactory>( |
| 434 fake_sctp_transport_factory_))); | 436 fake_sctp_transport_factory_))); |
| 435 session_->SignalDataChannelOpenMessage.connect( | 437 session_->SignalDataChannelOpenMessage.connect( |
| 436 this, &WebRtcSessionTest::OnDataChannelOpenMessage); | 438 this, &WebRtcSessionTest::OnDataChannelOpenMessage); |
| 437 | 439 |
| 438 configuration_.rtcp_mux_policy = rtcp_mux_policy; | 440 configuration_.rtcp_mux_policy = rtcp_mux_policy; |
| 439 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, | 441 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew, |
| 440 observer_.ice_connection_state_); | 442 observer_.ice_connection_state_); |
| 441 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, | 443 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew, |
| 442 observer_.ice_gathering_state_); | 444 observer_.ice_gathering_state_); |
| 443 | 445 |
| 444 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator), | 446 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator), |
| 445 configuration_)); | 447 configuration_)); |
| 446 session_->set_metrics_observer(metrics_observer_); | 448 session_->set_metrics_observer(metrics_observer_); |
| 449 crypto_options_ = crypto_options; |
| 447 } | 450 } |
| 448 | 451 |
| 449 void OnDataChannelOpenMessage(const std::string& label, | 452 void OnDataChannelOpenMessage(const std::string& label, |
| 450 const InternalDataChannelInit& config) { | 453 const InternalDataChannelInit& config) { |
| 451 last_data_channel_label_ = label; | 454 last_data_channel_label_ = label; |
| 452 last_data_channel_config_ = config; | 455 last_data_channel_config_ = config; |
| 453 } | 456 } |
| 454 | 457 |
| 455 void Init() { | 458 void Init() { |
| 456 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate); | 459 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 457 } | 460 rtc::CryptoOptions()); |
| 458 | |
| 459 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { | |
| 460 Init(nullptr, rtcp_mux_policy); | |
| 461 } | 461 } |
| 462 | 462 |
| 463 void InitWithBundlePolicy( | 463 void InitWithBundlePolicy( |
| 464 PeerConnectionInterface::BundlePolicy bundle_policy) { | 464 PeerConnectionInterface::BundlePolicy bundle_policy) { |
| 465 configuration_.bundle_policy = bundle_policy; | 465 configuration_.bundle_policy = bundle_policy; |
| 466 Init(); | 466 Init(); |
| 467 } | 467 } |
| 468 | 468 |
| 469 void InitWithRtcpMuxPolicy( | 469 void InitWithRtcpMuxPolicy( |
| 470 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { | 470 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) { |
| 471 PeerConnectionInterface::RTCConfiguration configuration; | 471 PeerConnectionInterface::RTCConfiguration configuration; |
| 472 Init(rtcp_mux_policy); | 472 Init(nullptr, rtcp_mux_policy, rtc::CryptoOptions()); |
| 473 } |
| 474 |
| 475 void InitWithCryptoOptions(const rtc::CryptoOptions& crypto_options) { |
| 476 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 477 crypto_options); |
| 473 } | 478 } |
| 474 | 479 |
| 475 // Successfully init with DTLS; with a certificate generated and supplied or | 480 // Successfully init with DTLS; with a certificate generated and supplied or |
| 476 // with a store that generates it for us. | 481 // with a store that generates it for us. |
| 477 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) { | 482 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) { |
| 478 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator; | 483 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator; |
| 479 if (cert_gen_method == ALREADY_GENERATED) { | 484 if (cert_gen_method == ALREADY_GENERATED) { |
| 480 configuration_.certificates.push_back( | 485 configuration_.certificates.push_back( |
| 481 FakeRTCCertificateGenerator::GenerateCertificate()); | 486 FakeRTCCertificateGenerator::GenerateCertificate()); |
| 482 } else if (cert_gen_method == DTLS_IDENTITY_STORE) { | 487 } else if (cert_gen_method == DTLS_IDENTITY_STORE) { |
| 483 cert_generator.reset(new FakeRTCCertificateGenerator()); | 488 cert_generator.reset(new FakeRTCCertificateGenerator()); |
| 484 cert_generator->set_should_fail(false); | 489 cert_generator->set_should_fail(false); |
| 485 } else { | 490 } else { |
| 486 RTC_CHECK(false); | 491 RTC_CHECK(false); |
| 487 } | 492 } |
| 488 Init(std::move(cert_generator), | 493 Init(std::move(cert_generator), |
| 489 PeerConnectionInterface::kRtcpMuxPolicyNegotiate); | 494 PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 495 rtc::CryptoOptions()); |
| 490 } | 496 } |
| 491 | 497 |
| 492 // Init with DTLS with a store that will fail to generate a certificate. | 498 // Init with DTLS with a store that will fail to generate a certificate. |
| 493 void InitWithDtlsIdentityGenFail() { | 499 void InitWithDtlsIdentityGenFail() { |
| 494 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( | 500 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator( |
| 495 new FakeRTCCertificateGenerator()); | 501 new FakeRTCCertificateGenerator()); |
| 496 cert_generator->set_should_fail(true); | 502 cert_generator->set_should_fail(true); |
| 497 Init(std::move(cert_generator), | 503 Init(std::move(cert_generator), |
| 498 PeerConnectionInterface::kRtcpMuxPolicyNegotiate); | 504 PeerConnectionInterface::kRtcpMuxPolicyNegotiate, |
| 505 rtc::CryptoOptions()); |
| 499 } | 506 } |
| 500 | 507 |
| 501 void InitWithGcm() { | 508 void InitWithGcm() { |
| 502 rtc::CryptoOptions crypto_options; | 509 rtc::CryptoOptions crypto_options; |
| 503 crypto_options.enable_gcm_crypto_suites = true; | 510 crypto_options.enable_gcm_crypto_suites = true; |
| 504 channel_manager_->SetCryptoOptions(crypto_options); | 511 InitWithCryptoOptions(crypto_options); |
| 505 with_gcm_ = true; | |
| 506 Init(); | |
| 507 } | 512 } |
| 508 | 513 |
| 509 void SendAudioVideoStream1() { | 514 void SendAudioVideoStream1() { |
| 510 send_stream_1_ = true; | 515 send_stream_1_ = true; |
| 511 send_stream_2_ = false; | 516 send_stream_2_ = false; |
| 512 send_audio_ = true; | 517 send_audio_ = true; |
| 513 send_video_ = true; | 518 send_video_ = true; |
| 514 } | 519 } |
| 515 | 520 |
| 516 void SendAudioVideoStream2() { | 521 void SendAudioVideoStream2() { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 session_options->bundle_enabled && | 597 session_options->bundle_enabled && |
| 593 (session_options->has_audio() || session_options->has_video() || | 598 (session_options->has_audio() || session_options->has_video() || |
| 594 session_options->has_data()); | 599 session_options->has_data()); |
| 595 | 600 |
| 596 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) { | 601 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) { |
| 597 session_options->data_channel_type = cricket::DCT_SCTP; | 602 session_options->data_channel_type = cricket::DCT_SCTP; |
| 598 } else if (session_->data_channel_type() == cricket::DCT_QUIC) { | 603 } else if (session_->data_channel_type() == cricket::DCT_QUIC) { |
| 599 session_options->data_channel_type = cricket::DCT_QUIC; | 604 session_options->data_channel_type = cricket::DCT_QUIC; |
| 600 } | 605 } |
| 601 | 606 |
| 602 if (with_gcm_) { | 607 session_options->crypto_options = crypto_options_; |
| 603 session_options->crypto_options.enable_gcm_crypto_suites = true; | |
| 604 } | |
| 605 } | 608 } |
| 606 | 609 |
| 607 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { | 610 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { |
| 608 // ParseConstraintsForAnswer is used to set some defaults. | 611 // ParseConstraintsForAnswer is used to set some defaults. |
| 609 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options)); | 612 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options)); |
| 610 | 613 |
| 611 AddStreamsToOptions(session_options); | 614 AddStreamsToOptions(session_options); |
| 612 session_options->bundle_enabled = | 615 session_options->bundle_enabled = |
| 613 session_options->bundle_enabled && | 616 session_options->bundle_enabled && |
| 614 (session_options->has_audio() || session_options->has_video() || | 617 (session_options->has_audio() || session_options->has_video() || |
| 615 session_options->has_data()); | 618 session_options->has_data()); |
| 616 | 619 |
| 617 if (session_->data_channel_type() != cricket::DCT_RTP) { | 620 if (session_->data_channel_type() != cricket::DCT_RTP) { |
| 618 session_options->data_channel_type = session_->data_channel_type(); | 621 session_options->data_channel_type = session_->data_channel_type(); |
| 619 } | 622 } |
| 620 | 623 |
| 621 if (with_gcm_) { | 624 session_options->crypto_options = crypto_options_; |
| 622 session_options->crypto_options.enable_gcm_crypto_suites = true; | |
| 623 } | |
| 624 } | 625 } |
| 625 | 626 |
| 626 // Creates a local offer and applies it. Starts ICE. | 627 // Creates a local offer and applies it. Starts ICE. |
| 627 // Call SendAudioVideoStreamX() before this function | 628 // Call SendAudioVideoStreamX() before this function |
| 628 // to decide which streams to create. | 629 // to decide which streams to create. |
| 629 void InitiateCall() { | 630 void InitiateCall() { |
| 630 SessionDescriptionInterface* offer = CreateOffer(); | 631 SessionDescriptionInterface* offer = CreateOffer(); |
| 631 SetLocalDescriptionWithoutError(offer); | 632 SetLocalDescriptionWithoutError(offer); |
| 632 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != | 633 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 633 observer_.ice_gathering_state_, | 634 observer_.ice_gathering_state_, |
| (...skipping 901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; | 1536 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_; |
| 1536 // The following flags affect options created for CreateOffer/CreateAnswer. | 1537 // The following flags affect options created for CreateOffer/CreateAnswer. |
| 1537 bool send_stream_1_ = false; | 1538 bool send_stream_1_ = false; |
| 1538 bool send_stream_2_ = false; | 1539 bool send_stream_2_ = false; |
| 1539 bool send_audio_ = false; | 1540 bool send_audio_ = false; |
| 1540 bool send_video_ = false; | 1541 bool send_video_ = false; |
| 1541 rtc::scoped_refptr<DataChannel> data_channel_; | 1542 rtc::scoped_refptr<DataChannel> data_channel_; |
| 1542 // Last values received from data channel creation signal. | 1543 // Last values received from data channel creation signal. |
| 1543 std::string last_data_channel_label_; | 1544 std::string last_data_channel_label_; |
| 1544 InternalDataChannelInit last_data_channel_config_; | 1545 InternalDataChannelInit last_data_channel_config_; |
| 1545 bool with_gcm_ = false; | 1546 rtc::CryptoOptions crypto_options_; |
| 1546 }; | 1547 }; |
| 1547 | 1548 |
| 1548 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { | 1549 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { |
| 1549 InitWithDtls(GetParam()); | 1550 InitWithDtls(GetParam()); |
| 1550 // SDES is disabled when DTLS is on. | 1551 // SDES is disabled when DTLS is on. |
| 1551 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); | 1552 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); |
| 1552 } | 1553 } |
| 1553 | 1554 |
| 1554 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { | 1555 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { |
| 1555 Init(); | 1556 Init(); |
| (...skipping 1807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3363 // should not receive any changes in the ICE state. | 3364 // should not receive any changes in the ICE state. |
| 3364 TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) { | 3365 TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) { |
| 3365 LoopbackNetworkConfiguration config; | 3366 LoopbackNetworkConfiguration config; |
| 3366 LoopbackNetworkManager loopback_network_manager(this, config); | 3367 LoopbackNetworkManager loopback_network_manager(this, config); |
| 3367 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain | 3368 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain |
| 3368 // connected. Disabling either of these two means that we need to wait for the | 3369 // connected. Disabling either of these two means that we need to wait for the |
| 3369 // answer to find out if more transports are needed. | 3370 // answer to find out if more transports are needed. |
| 3370 configuration_.bundle_policy = | 3371 configuration_.bundle_policy = |
| 3371 PeerConnectionInterface::kBundlePolicyMaxBundle; | 3372 PeerConnectionInterface::kBundlePolicyMaxBundle; |
| 3372 options_.disable_encryption = true; | 3373 options_.disable_encryption = true; |
| 3373 Init(PeerConnectionInterface::kRtcpMuxPolicyRequire); | 3374 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire); |
| 3374 | 3375 |
| 3375 // Negotiate an audio channel with MAX_BUNDLE enabled. | 3376 // Negotiate an audio channel with MAX_BUNDLE enabled. |
| 3376 SendAudioOnlyStream2(); | 3377 SendAudioOnlyStream2(); |
| 3377 SessionDescriptionInterface* offer = CreateOffer(); | 3378 SessionDescriptionInterface* offer = CreateOffer(); |
| 3378 SetLocalDescriptionWithoutError(offer); | 3379 SetLocalDescriptionWithoutError(offer); |
| 3379 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, | 3380 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete, |
| 3380 observer_.ice_gathering_state_, kIceCandidatesTimeout); | 3381 observer_.ice_gathering_state_, kIceCandidatesTimeout); |
| 3381 std::string sdp; | 3382 std::string sdp; |
| 3382 offer->ToString(&sdp); | 3383 offer->ToString(&sdp); |
| 3383 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription( | 3384 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription( |
| (...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4346 } | 4347 } |
| 4347 | 4348 |
| 4348 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test | 4349 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 4349 // currently fails because upon disconnection and reconnection OnIceComplete is | 4350 // currently fails because upon disconnection and reconnection OnIceComplete is |
| 4350 // called more than once without returning to IceGatheringGathering. | 4351 // called more than once without returning to IceGatheringGathering. |
| 4351 | 4352 |
| 4352 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, | 4353 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
| 4353 WebRtcSessionTest, | 4354 WebRtcSessionTest, |
| 4354 testing::Values(ALREADY_GENERATED, | 4355 testing::Values(ALREADY_GENERATED, |
| 4355 DTLS_IDENTITY_STORE)); | 4356 DTLS_IDENTITY_STORE)); |
| OLD | NEW |