| 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 // Add kTelephoneEventCodec for dtmf test. | 448 // Add kTelephoneEventCodec for dtmf test. |
| 449 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, | 449 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, |
| 450 0, 1); | 450 0, 1); |
| 451 std::vector<cricket::AudioCodec> codecs; | 451 std::vector<cricket::AudioCodec> codecs; |
| 452 codecs.push_back(kTelephoneEventCodec); | 452 codecs.push_back(kTelephoneEventCodec); |
| 453 media_engine_->SetAudioCodecs(codecs); | 453 media_engine_->SetAudioCodecs(codecs); |
| 454 desc_factory_->set_audio_codecs(codecs, codecs); | 454 desc_factory_->set_audio_codecs(codecs, codecs); |
| 455 Init(); | 455 Init(); |
| 456 } | 456 } |
| 457 | 457 |
| 458 void InitWithGcm() { |
| 459 rtc::CryptoOptions crypto_options; |
| 460 crypto_options.enable_gcm_crypto_suites = true; |
| 461 channel_manager_->SetCryptoOptions(crypto_options); |
| 462 with_gcm_ = true; |
| 463 Init(); |
| 464 } |
| 465 |
| 458 void SendAudioVideoStream1() { | 466 void SendAudioVideoStream1() { |
| 459 send_stream_1_ = true; | 467 send_stream_1_ = true; |
| 460 send_stream_2_ = false; | 468 send_stream_2_ = false; |
| 461 send_audio_ = true; | 469 send_audio_ = true; |
| 462 send_video_ = true; | 470 send_video_ = true; |
| 463 } | 471 } |
| 464 | 472 |
| 465 void SendAudioVideoStream2() { | 473 void SendAudioVideoStream2() { |
| 466 send_stream_1_ = false; | 474 send_stream_1_ = false; |
| 467 send_stream_2_ = true; | 475 send_stream_2_ = true; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO); | 546 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO); |
| 539 } | 547 } |
| 540 session_options->bundle_enabled = | 548 session_options->bundle_enabled = |
| 541 session_options->bundle_enabled && | 549 session_options->bundle_enabled && |
| 542 (session_options->has_audio() || session_options->has_video() || | 550 (session_options->has_audio() || session_options->has_video() || |
| 543 session_options->has_data()); | 551 session_options->has_data()); |
| 544 | 552 |
| 545 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) { | 553 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) { |
| 546 session_options->data_channel_type = cricket::DCT_SCTP; | 554 session_options->data_channel_type = cricket::DCT_SCTP; |
| 547 } | 555 } |
| 556 |
| 557 if (with_gcm_) { |
| 558 session_options->crypto_options.enable_gcm_crypto_suites = true; |
| 559 } |
| 548 } | 560 } |
| 549 | 561 |
| 550 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { | 562 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) { |
| 551 // ParseConstraintsForAnswer is used to set some defaults. | 563 // ParseConstraintsForAnswer is used to set some defaults. |
| 552 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options)); | 564 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options)); |
| 553 | 565 |
| 554 AddStreamsToOptions(session_options); | 566 AddStreamsToOptions(session_options); |
| 555 session_options->bundle_enabled = | 567 session_options->bundle_enabled = |
| 556 session_options->bundle_enabled && | 568 session_options->bundle_enabled && |
| 557 (session_options->has_audio() || session_options->has_video() || | 569 (session_options->has_audio() || session_options->has_video() || |
| 558 session_options->has_data()); | 570 session_options->has_data()); |
| 559 | 571 |
| 560 if (session_->data_channel_type() == cricket::DCT_SCTP) { | 572 if (session_->data_channel_type() == cricket::DCT_SCTP) { |
| 561 session_options->data_channel_type = cricket::DCT_SCTP; | 573 session_options->data_channel_type = cricket::DCT_SCTP; |
| 562 } | 574 } |
| 575 |
| 576 if (with_gcm_) { |
| 577 session_options->crypto_options.enable_gcm_crypto_suites = true; |
| 578 } |
| 563 } | 579 } |
| 564 | 580 |
| 565 // Creates a local offer and applies it. Starts ICE. | 581 // Creates a local offer and applies it. Starts ICE. |
| 566 // Call SendAudioVideoStreamX() before this function | 582 // Call SendAudioVideoStreamX() before this function |
| 567 // to decide which streams to create. | 583 // to decide which streams to create. |
| 568 void InitiateCall() { | 584 void InitiateCall() { |
| 569 SessionDescriptionInterface* offer = CreateOffer(); | 585 SessionDescriptionInterface* offer = CreateOffer(); |
| 570 SetLocalDescriptionWithoutError(offer); | 586 SetLocalDescriptionWithoutError(offer); |
| 571 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != | 587 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew != |
| 572 observer_.ice_gathering_state_, | 588 observer_.ice_gathering_state_, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 options.recv_video = true; | 631 options.recv_video = true; |
| 616 options.recv_audio = true; | 632 options.recv_audio = true; |
| 617 return CreateAnswer(options); | 633 return CreateAnswer(options); |
| 618 } | 634 } |
| 619 | 635 |
| 620 bool ChannelsExist() const { | 636 bool ChannelsExist() const { |
| 621 return (session_->voice_channel() != NULL && | 637 return (session_->voice_channel() != NULL && |
| 622 session_->video_channel() != NULL); | 638 session_->video_channel() != NULL); |
| 623 } | 639 } |
| 624 | 640 |
| 625 void VerifyCryptoParams(const cricket::SessionDescription* sdp) { | 641 void VerifyCryptoParams(const cricket::SessionDescription* sdp, |
| 642 bool gcm_enabled = false) { |
| 626 ASSERT_TRUE(session_.get() != NULL); | 643 ASSERT_TRUE(session_.get() != NULL); |
| 627 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); | 644 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 628 ASSERT_TRUE(content != NULL); | 645 ASSERT_TRUE(content != NULL); |
| 629 const cricket::AudioContentDescription* audio_content = | 646 const cricket::AudioContentDescription* audio_content = |
| 630 static_cast<const cricket::AudioContentDescription*>( | 647 static_cast<const cricket::AudioContentDescription*>( |
| 631 content->description); | 648 content->description); |
| 632 ASSERT_TRUE(audio_content != NULL); | 649 ASSERT_TRUE(audio_content != NULL); |
| 633 ASSERT_EQ(1U, audio_content->cryptos().size()); | 650 if (!gcm_enabled) { |
| 634 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size()); | 651 ASSERT_EQ(1U, audio_content->cryptos().size()); |
| 635 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", | 652 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size()); |
| 636 audio_content->cryptos()[0].cipher_suite); | 653 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 637 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), | 654 audio_content->cryptos()[0].cipher_suite); |
| 638 audio_content->protocol()); | 655 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 656 audio_content->protocol()); |
| 657 } else { |
| 658 // The offer contains 3 possible crypto suites, the answer 1. |
| 659 EXPECT_LE(1U, audio_content->cryptos().size()); |
| 660 EXPECT_NE(2U, audio_content->cryptos().size()); |
| 661 EXPECT_GE(3U, audio_content->cryptos().size()); |
| 662 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size()); |
| 663 ASSERT_EQ("AEAD_AES_256_GCM", |
| 664 audio_content->cryptos()[0].cipher_suite); |
| 665 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 666 audio_content->protocol()); |
| 667 } |
| 639 | 668 |
| 640 content = cricket::GetFirstVideoContent(sdp); | 669 content = cricket::GetFirstVideoContent(sdp); |
| 641 ASSERT_TRUE(content != NULL); | 670 ASSERT_TRUE(content != NULL); |
| 642 const cricket::VideoContentDescription* video_content = | 671 const cricket::VideoContentDescription* video_content = |
| 643 static_cast<const cricket::VideoContentDescription*>( | 672 static_cast<const cricket::VideoContentDescription*>( |
| 644 content->description); | 673 content->description); |
| 645 ASSERT_TRUE(video_content != NULL); | 674 ASSERT_TRUE(video_content != NULL); |
| 646 ASSERT_EQ(1U, video_content->cryptos().size()); | 675 if (!gcm_enabled) { |
| 647 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", | 676 ASSERT_EQ(1U, video_content->cryptos().size()); |
| 648 video_content->cryptos()[0].cipher_suite); | 677 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80", |
| 649 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size()); | 678 video_content->cryptos()[0].cipher_suite); |
| 650 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), | 679 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size()); |
| 651 video_content->protocol()); | 680 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 681 video_content->protocol()); |
| 682 } else { |
| 683 // The offer contains 3 possible crypto suites, the answer 1. |
| 684 EXPECT_LE(1U, video_content->cryptos().size()); |
| 685 EXPECT_NE(2U, video_content->cryptos().size()); |
| 686 EXPECT_GE(3U, video_content->cryptos().size()); |
| 687 ASSERT_EQ("AEAD_AES_256_GCM", |
| 688 video_content->cryptos()[0].cipher_suite); |
| 689 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size()); |
| 690 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), |
| 691 video_content->protocol()); |
| 692 } |
| 652 } | 693 } |
| 653 | 694 |
| 654 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) { | 695 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) { |
| 655 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); | 696 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp); |
| 656 ASSERT_TRUE(content != NULL); | 697 ASSERT_TRUE(content != NULL); |
| 657 const cricket::AudioContentDescription* audio_content = | 698 const cricket::AudioContentDescription* audio_content = |
| 658 static_cast<const cricket::AudioContentDescription*>( | 699 static_cast<const cricket::AudioContentDescription*>( |
| 659 content->description); | 700 content->description); |
| 660 ASSERT_TRUE(audio_content != NULL); | 701 ASSERT_TRUE(audio_content != NULL); |
| 661 ASSERT_EQ(0U, audio_content->cryptos().size()); | 702 ASSERT_EQ(0U, audio_content->cryptos().size()); |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 // The following flags affect options created for CreateOffer/CreateAnswer. | 1498 // The following flags affect options created for CreateOffer/CreateAnswer. |
| 1458 bool send_stream_1_ = false; | 1499 bool send_stream_1_ = false; |
| 1459 bool send_stream_2_ = false; | 1500 bool send_stream_2_ = false; |
| 1460 bool send_audio_ = false; | 1501 bool send_audio_ = false; |
| 1461 bool send_video_ = false; | 1502 bool send_video_ = false; |
| 1462 rtc::scoped_refptr<DataChannel> data_channel_; | 1503 rtc::scoped_refptr<DataChannel> data_channel_; |
| 1463 // Last values received from data channel creation signal. | 1504 // Last values received from data channel creation signal. |
| 1464 std::string last_data_channel_label_; | 1505 std::string last_data_channel_label_; |
| 1465 InternalDataChannelInit last_data_channel_config_; | 1506 InternalDataChannelInit last_data_channel_config_; |
| 1466 bool session_destroyed_ = false; | 1507 bool session_destroyed_ = false; |
| 1508 bool with_gcm_ = false; |
| 1467 }; | 1509 }; |
| 1468 | 1510 |
| 1469 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { | 1511 TEST_P(WebRtcSessionTest, TestInitializeWithDtls) { |
| 1470 InitWithDtls(GetParam()); | 1512 InitWithDtls(GetParam()); |
| 1471 // SDES is disabled when DTLS is on. | 1513 // SDES is disabled when DTLS is on. |
| 1472 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); | 1514 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy()); |
| 1473 } | 1515 } |
| 1474 | 1516 |
| 1475 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { | 1517 TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) { |
| 1476 Init(); | 1518 Init(); |
| (...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2755 TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { | 2797 TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) { |
| 2756 Init(); | 2798 Init(); |
| 2757 SendAudioVideoStream1(); | 2799 SendAudioVideoStream1(); |
| 2758 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); | 2800 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2759 VerifyCryptoParams(offer->description()); | 2801 VerifyCryptoParams(offer->description()); |
| 2760 SetRemoteDescriptionWithoutError(offer.release()); | 2802 SetRemoteDescriptionWithoutError(offer.release()); |
| 2761 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); | 2803 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
| 2762 VerifyCryptoParams(answer->description()); | 2804 VerifyCryptoParams(answer->description()); |
| 2763 } | 2805 } |
| 2764 | 2806 |
| 2807 TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) { |
| 2808 InitWithGcm(); |
| 2809 SendAudioVideoStream1(); |
| 2810 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2811 VerifyCryptoParams(offer->description(), true); |
| 2812 SetRemoteDescriptionWithoutError(offer.release()); |
| 2813 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer()); |
| 2814 VerifyCryptoParams(answer->description(), true); |
| 2815 } |
| 2816 |
| 2765 TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { | 2817 TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) { |
| 2766 options_.disable_encryption = true; | 2818 options_.disable_encryption = true; |
| 2767 Init(); | 2819 Init(); |
| 2768 SendAudioVideoStream1(); | 2820 SendAudioVideoStream1(); |
| 2769 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); | 2821 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2770 VerifyNoCryptoParams(offer->description(), false); | 2822 VerifyNoCryptoParams(offer->description(), false); |
| 2771 } | 2823 } |
| 2772 | 2824 |
| 2773 TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { | 2825 TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) { |
| 2774 Init(); | 2826 Init(); |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3380 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); | 3432 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL)); |
| 3381 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); | 3433 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer); |
| 3382 JsepSessionDescription* remote_offer = | 3434 JsepSessionDescription* remote_offer = |
| 3383 new JsepSessionDescription(JsepSessionDescription::kOffer); | 3435 new JsepSessionDescription(JsepSessionDescription::kOffer); |
| 3384 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); | 3436 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL)); |
| 3385 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); | 3437 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer); |
| 3386 // Trying unmodified SDP. | 3438 // Trying unmodified SDP. |
| 3387 SetLocalDescriptionWithoutError(offer); | 3439 SetLocalDescriptionWithoutError(offer); |
| 3388 } | 3440 } |
| 3389 | 3441 |
| 3442 TEST_F(WebRtcSessionTest, SetSetupGcm) { |
| 3443 InitWithGcm(); |
| 3444 SendAudioVideoStream1(); |
| 3445 CreateAndSetRemoteOfferAndLocalAnswer(); |
| 3446 } |
| 3447 |
| 3390 TEST_F(WebRtcSessionTest, CanNotInsertDtmf) { | 3448 TEST_F(WebRtcSessionTest, CanNotInsertDtmf) { |
| 3391 TestCanInsertDtmf(false); | 3449 TestCanInsertDtmf(false); |
| 3392 } | 3450 } |
| 3393 | 3451 |
| 3394 TEST_F(WebRtcSessionTest, CanInsertDtmf) { | 3452 TEST_F(WebRtcSessionTest, CanInsertDtmf) { |
| 3395 TestCanInsertDtmf(true); | 3453 TestCanInsertDtmf(true); |
| 3396 } | 3454 } |
| 3397 | 3455 |
| 3398 TEST_F(WebRtcSessionTest, InsertDtmf) { | 3456 TEST_F(WebRtcSessionTest, InsertDtmf) { |
| 3399 // Setup | 3457 // Setup |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4257 } | 4315 } |
| 4258 | 4316 |
| 4259 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test | 4317 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 4260 // currently fails because upon disconnection and reconnection OnIceComplete is | 4318 // currently fails because upon disconnection and reconnection OnIceComplete is |
| 4261 // called more than once without returning to IceGatheringGathering. | 4319 // called more than once without returning to IceGatheringGathering. |
| 4262 | 4320 |
| 4263 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, | 4321 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
| 4264 WebRtcSessionTest, | 4322 WebRtcSessionTest, |
| 4265 testing::Values(ALREADY_GENERATED, | 4323 testing::Values(ALREADY_GENERATED, |
| 4266 DTLS_IDENTITY_STORE)); | 4324 DTLS_IDENTITY_STORE)); |
| OLD | NEW |