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 22 matching lines...) Expand all Loading... |
33 #include "webrtc/api/videocapturertracksource.h" | 33 #include "webrtc/api/videocapturertracksource.h" |
34 #include "webrtc/api/videotrack.h" | 34 #include "webrtc/api/videotrack.h" |
35 #include "webrtc/base/gunit.h" | 35 #include "webrtc/base/gunit.h" |
36 #include "webrtc/base/ssladapter.h" | 36 #include "webrtc/base/ssladapter.h" |
37 #include "webrtc/base/sslstreamadapter.h" | 37 #include "webrtc/base/sslstreamadapter.h" |
38 #include "webrtc/base/stringutils.h" | 38 #include "webrtc/base/stringutils.h" |
39 #include "webrtc/base/thread.h" | 39 #include "webrtc/base/thread.h" |
40 #include "webrtc/media/base/fakevideocapturer.h" | 40 #include "webrtc/media/base/fakevideocapturer.h" |
41 #include "webrtc/media/sctp/sctpdataengine.h" | 41 #include "webrtc/media/sctp/sctpdataengine.h" |
42 #include "webrtc/p2p/base/fakeportallocator.h" | 42 #include "webrtc/p2p/base/fakeportallocator.h" |
| 43 #include "webrtc/p2p/base/faketransportcontroller.h" |
43 #include "webrtc/pc/mediasession.h" | 44 #include "webrtc/pc/mediasession.h" |
44 | 45 |
45 static const char kStreamLabel1[] = "local_stream_1"; | 46 static const char kStreamLabel1[] = "local_stream_1"; |
46 static const char kStreamLabel2[] = "local_stream_2"; | 47 static const char kStreamLabel2[] = "local_stream_2"; |
47 static const char kStreamLabel3[] = "local_stream_3"; | 48 static const char kStreamLabel3[] = "local_stream_3"; |
48 static const int kDefaultStunPort = 3478; | 49 static const int kDefaultStunPort = 3478; |
49 static const char kStunAddressOnly[] = "stun:address"; | 50 static const char kStunAddressOnly[] = "stun:address"; |
50 static const char kStunInvalidPort[] = "stun:address:-1"; | 51 static const char kStunInvalidPort[] = "stun:address:-1"; |
51 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; | 52 static const char kStunAddressPortAndMore1[] = "stun:address:port:more"; |
52 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; | 53 static const char kStunAddressPortAndMore2[] = "stun:address:port more"; |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 485 } |
485 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; } | 486 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; } |
486 void OnDataChannel( | 487 void OnDataChannel( |
487 rtc::scoped_refptr<DataChannelInterface> data_channel) override { | 488 rtc::scoped_refptr<DataChannelInterface> data_channel) override { |
488 last_datachannel_ = data_channel; | 489 last_datachannel_ = data_channel; |
489 } | 490 } |
490 | 491 |
491 void OnIceConnectionChange( | 492 void OnIceConnectionChange( |
492 PeerConnectionInterface::IceConnectionState new_state) override { | 493 PeerConnectionInterface::IceConnectionState new_state) override { |
493 EXPECT_EQ(pc_->ice_connection_state(), new_state); | 494 EXPECT_EQ(pc_->ice_connection_state(), new_state); |
| 495 callback_triggered = true; |
494 } | 496 } |
495 void OnIceGatheringChange( | 497 void OnIceGatheringChange( |
496 PeerConnectionInterface::IceGatheringState new_state) override { | 498 PeerConnectionInterface::IceGatheringState new_state) override { |
497 EXPECT_EQ(pc_->ice_gathering_state(), new_state); | 499 EXPECT_EQ(pc_->ice_gathering_state(), new_state); |
498 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete; | 500 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete; |
| 501 callback_triggered = true; |
499 } | 502 } |
500 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { | 503 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
501 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, | 504 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, |
502 pc_->ice_gathering_state()); | 505 pc_->ice_gathering_state()); |
503 | 506 |
504 std::string sdp; | 507 std::string sdp; |
505 EXPECT_TRUE(candidate->ToString(&sdp)); | 508 EXPECT_TRUE(candidate->ToString(&sdp)); |
506 EXPECT_LT(0u, sdp.size()); | 509 EXPECT_LT(0u, sdp.size()); |
507 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(), | 510 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(), |
508 candidate->sdp_mline_index(), sdp, NULL)); | 511 candidate->sdp_mline_index(), sdp, NULL)); |
509 EXPECT_TRUE(last_candidate_.get() != NULL); | 512 EXPECT_TRUE(last_candidate_.get() != NULL); |
| 513 callback_triggered = true; |
| 514 } |
| 515 |
| 516 void OnIceCandidatesRemoved( |
| 517 const std::vector<cricket::Candidate>& candidates) override { |
| 518 callback_triggered = true; |
| 519 } |
| 520 |
| 521 void OnIceConnectionReceivingChange(bool receiving) override { |
| 522 callback_triggered = true; |
510 } | 523 } |
511 | 524 |
512 // Returns the label of the last added stream. | 525 // Returns the label of the last added stream. |
513 // Empty string if no stream have been added. | 526 // Empty string if no stream have been added. |
514 std::string GetLastAddedStreamLabel() { | 527 std::string GetLastAddedStreamLabel() { |
515 if (last_added_stream_.get()) | 528 if (last_added_stream_.get()) |
516 return last_added_stream_->label(); | 529 return last_added_stream_->label(); |
517 return ""; | 530 return ""; |
518 } | 531 } |
519 std::string GetLastRemovedStreamLabel() { | 532 std::string GetLastRemovedStreamLabel() { |
520 if (last_removed_stream_.get()) | 533 if (last_removed_stream_.get()) |
521 return last_removed_stream_->label(); | 534 return last_removed_stream_->label(); |
522 return ""; | 535 return ""; |
523 } | 536 } |
524 | 537 |
525 scoped_refptr<PeerConnectionInterface> pc_; | 538 scoped_refptr<PeerConnectionInterface> pc_; |
526 PeerConnectionInterface::SignalingState state_; | 539 PeerConnectionInterface::SignalingState state_; |
527 std::unique_ptr<IceCandidateInterface> last_candidate_; | 540 std::unique_ptr<IceCandidateInterface> last_candidate_; |
528 scoped_refptr<DataChannelInterface> last_datachannel_; | 541 scoped_refptr<DataChannelInterface> last_datachannel_; |
529 rtc::scoped_refptr<StreamCollection> remote_streams_; | 542 rtc::scoped_refptr<StreamCollection> remote_streams_; |
530 bool renegotiation_needed_ = false; | 543 bool renegotiation_needed_ = false; |
531 bool ice_complete_ = false; | 544 bool ice_complete_ = false; |
| 545 bool callback_triggered = false; |
532 | 546 |
533 private: | 547 private: |
534 scoped_refptr<MediaStreamInterface> last_added_stream_; | 548 scoped_refptr<MediaStreamInterface> last_added_stream_; |
535 scoped_refptr<MediaStreamInterface> last_removed_stream_; | 549 scoped_refptr<MediaStreamInterface> last_removed_stream_; |
536 }; | 550 }; |
537 | 551 |
538 } // namespace | 552 } // namespace |
539 | 553 |
| 554 // The PeerConnectionMediaConfig tests below verify that configuration |
| 555 // and constraints are propagated into the MediaConfig passed to |
| 556 // CreateMediaController. These settings are intended for MediaChannel |
| 557 // constructors, but that is not exercised by these unittest. |
| 558 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { |
| 559 public: |
| 560 webrtc::MediaControllerInterface* CreateMediaController( |
| 561 const cricket::MediaConfig& config) const override { |
| 562 create_media_controller_called_ = true; |
| 563 create_media_controller_config_ = config; |
| 564 |
| 565 webrtc::MediaControllerInterface* mc = |
| 566 PeerConnectionFactory::CreateMediaController(config); |
| 567 EXPECT_TRUE(mc != nullptr); |
| 568 return mc; |
| 569 } |
| 570 |
| 571 cricket::TransportController* CreateTransportController( |
| 572 cricket::PortAllocator* port_allocator) override { |
| 573 transport_controller = new cricket::TransportController( |
| 574 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator); |
| 575 return transport_controller; |
| 576 } |
| 577 |
| 578 cricket::TransportController* transport_controller; |
| 579 // Mutable, so they can be modified in the above const-declared method. |
| 580 mutable bool create_media_controller_called_ = false; |
| 581 mutable cricket::MediaConfig create_media_controller_config_; |
| 582 }; |
| 583 |
540 class PeerConnectionInterfaceTest : public testing::Test { | 584 class PeerConnectionInterfaceTest : public testing::Test { |
541 protected: | 585 protected: |
542 PeerConnectionInterfaceTest() { | 586 PeerConnectionInterfaceTest() { |
543 #ifdef WEBRTC_ANDROID | 587 #ifdef WEBRTC_ANDROID |
544 webrtc::InitializeAndroidObjects(); | 588 webrtc::InitializeAndroidObjects(); |
545 #endif | 589 #endif |
546 } | 590 } |
547 | 591 |
548 virtual void SetUp() { | 592 virtual void SetUp() { |
549 pc_factory_ = webrtc::CreatePeerConnectionFactory( | 593 pc_factory_ = webrtc::CreatePeerConnectionFactory( |
550 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), | 594 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), |
551 nullptr, nullptr, nullptr); | 595 nullptr, nullptr, nullptr); |
552 ASSERT_TRUE(pc_factory_); | 596 ASSERT_TRUE(pc_factory_); |
| 597 pc_factory_for_test_ = |
| 598 new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); |
| 599 pc_factory_for_test_->Initialize(); |
553 } | 600 } |
554 | 601 |
555 void CreatePeerConnection() { | 602 void CreatePeerConnection() { |
556 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr); | 603 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr); |
557 } | 604 } |
558 | 605 |
559 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { | 606 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { |
560 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), | 607 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), |
561 constraints); | 608 constraints); |
562 } | 609 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 | 772 |
726 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) { | 773 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) { |
727 rtc::scoped_refptr<MockSetSessionDescriptionObserver> | 774 rtc::scoped_refptr<MockSetSessionDescriptionObserver> |
728 observer(new rtc::RefCountedObject< | 775 observer(new rtc::RefCountedObject< |
729 MockSetSessionDescriptionObserver>()); | 776 MockSetSessionDescriptionObserver>()); |
730 if (local) { | 777 if (local) { |
731 pc_->SetLocalDescription(observer, desc); | 778 pc_->SetLocalDescription(observer, desc); |
732 } else { | 779 } else { |
733 pc_->SetRemoteDescription(observer, desc); | 780 pc_->SetRemoteDescription(observer, desc); |
734 } | 781 } |
735 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); | 782 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) { |
| 783 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
| 784 } |
736 return observer->result(); | 785 return observer->result(); |
737 } | 786 } |
738 | 787 |
739 bool DoSetLocalDescription(SessionDescriptionInterface* desc) { | 788 bool DoSetLocalDescription(SessionDescriptionInterface* desc) { |
740 return DoSetSessionDescription(desc, true); | 789 return DoSetSessionDescription(desc, true); |
741 } | 790 } |
742 | 791 |
743 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { | 792 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { |
744 return DoSetSessionDescription(desc, false); | 793 return DoSetSessionDescription(desc, false); |
745 } | 794 } |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 const cricket::ContentInfo* audio_content = | 1036 const cricket::ContentInfo* audio_content = |
988 cricket::GetFirstAudioContent(desc->description()); | 1037 cricket::GetFirstAudioContent(desc->description()); |
989 const cricket::AudioContentDescription* audio_desc = | 1038 const cricket::AudioContentDescription* audio_desc = |
990 static_cast<const cricket::AudioContentDescription*>( | 1039 static_cast<const cricket::AudioContentDescription*>( |
991 audio_content->description); | 1040 audio_content->description); |
992 return audio_desc->streams()[0].cname; | 1041 return audio_desc->streams()[0].cname; |
993 } | 1042 } |
994 | 1043 |
995 cricket::FakePortAllocator* port_allocator_ = nullptr; | 1044 cricket::FakePortAllocator* port_allocator_ = nullptr; |
996 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | 1045 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
| 1046 scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_; |
997 scoped_refptr<PeerConnectionInterface> pc_; | 1047 scoped_refptr<PeerConnectionInterface> pc_; |
998 MockPeerConnectionObserver observer_; | 1048 MockPeerConnectionObserver observer_; |
999 rtc::scoped_refptr<StreamCollection> reference_collection_; | 1049 rtc::scoped_refptr<StreamCollection> reference_collection_; |
1000 }; | 1050 }; |
1001 | 1051 |
| 1052 // Test that no callbacks on the PeerConnectionObserver are called after the |
| 1053 // PeerConnection is closed. |
| 1054 TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) { |
| 1055 scoped_refptr<PeerConnectionInterface> pc( |
| 1056 pc_factory_for_test_->CreatePeerConnection( |
| 1057 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr, |
| 1058 nullptr, &observer_)); |
| 1059 observer_.SetPeerConnectionInterface(pc.get()); |
| 1060 pc->Close(); |
| 1061 |
| 1062 // No callbacks is expected to be called. |
| 1063 observer_.callback_triggered = false; |
| 1064 std::vector<cricket::Candidate> candidates; |
| 1065 pc_factory_for_test_->transport_controller->SignalGatheringState( |
| 1066 cricket::IceGatheringState{}); |
| 1067 pc_factory_for_test_->transport_controller->SignalCandidatesGathered( |
| 1068 "", candidates); |
| 1069 pc_factory_for_test_->transport_controller->SignalConnectionState( |
| 1070 cricket::IceConnectionState{}); |
| 1071 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved( |
| 1072 candidates); |
| 1073 pc_factory_for_test_->transport_controller->SignalReceiving(false); |
| 1074 EXPECT_FALSE(observer_.callback_triggered); |
| 1075 } |
| 1076 |
1002 // Generate different CNAMEs when PeerConnections are created. | 1077 // Generate different CNAMEs when PeerConnections are created. |
1003 // The CNAMEs are expected to be generated randomly. It is possible | 1078 // The CNAMEs are expected to be generated randomly. It is possible |
1004 // that the test fails, though the possibility is very low. | 1079 // that the test fails, though the possibility is very low. |
1005 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { | 1080 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { |
1006 std::unique_ptr<SessionDescriptionInterface> offer1 = | 1081 std::unique_ptr<SessionDescriptionInterface> offer1 = |
1007 CreateOfferWithOneAudioStream(); | 1082 CreateOfferWithOneAudioStream(); |
1008 std::unique_ptr<SessionDescriptionInterface> offer2 = | 1083 std::unique_ptr<SessionDescriptionInterface> offer2 = |
1009 CreateOfferWithOneAudioStream(); | 1084 CreateOfferWithOneAudioStream(); |
1010 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), | 1085 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), |
1011 GetFirstAudioStreamCname(offer2.get())); | 1086 GetFirstAudioStreamCname(offer2.get())); |
(...skipping 1514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2526 | 2601 |
2527 auto new_senders = pc_->GetSenders(); | 2602 auto new_senders = pc_->GetSenders(); |
2528 // Should be the same senders as before, but with updated stream id. | 2603 // Should be the same senders as before, but with updated stream id. |
2529 // Note that this behavior is subject to change in the future. | 2604 // Note that this behavior is subject to change in the future. |
2530 // We may decide the PC should ignore existing tracks in AddStream. | 2605 // We may decide the PC should ignore existing tracks in AddStream. |
2531 EXPECT_EQ(senders, new_senders); | 2606 EXPECT_EQ(senders, new_senders); |
2532 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); | 2607 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); |
2533 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); | 2608 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); |
2534 } | 2609 } |
2535 | 2610 |
2536 // The PeerConnectionMediaConfig tests below verify that configuration | |
2537 // and constraints are propagated into the MediaConfig passed to | |
2538 // CreateMediaController. These settings are intended for MediaChannel | |
2539 // constructors, but that is not exercised by these unittest. | |
2540 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { | |
2541 public: | |
2542 webrtc::MediaControllerInterface* CreateMediaController( | |
2543 const cricket::MediaConfig& config) const override { | |
2544 create_media_controller_called_ = true; | |
2545 create_media_controller_config_ = config; | |
2546 | |
2547 webrtc::MediaControllerInterface* mc = | |
2548 PeerConnectionFactory::CreateMediaController(config); | |
2549 EXPECT_TRUE(mc != nullptr); | |
2550 return mc; | |
2551 } | |
2552 | |
2553 // Mutable, so they can be modified in the above const-declared method. | |
2554 mutable bool create_media_controller_called_ = false; | |
2555 mutable cricket::MediaConfig create_media_controller_config_; | |
2556 }; | |
2557 | |
2558 class PeerConnectionMediaConfigTest : public testing::Test { | 2611 class PeerConnectionMediaConfigTest : public testing::Test { |
2559 protected: | 2612 protected: |
2560 void SetUp() override { | 2613 void SetUp() override { |
2561 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); | 2614 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); |
2562 pcf_->Initialize(); | 2615 pcf_->Initialize(); |
2563 } | 2616 } |
2564 const cricket::MediaConfig& TestCreatePeerConnection( | 2617 const cricket::MediaConfig& TestCreatePeerConnection( |
2565 const PeerConnectionInterface::RTCConfiguration& config, | 2618 const PeerConnectionInterface::RTCConfiguration& config, |
2566 const MediaConstraintsInterface *constraints) { | 2619 const MediaConstraintsInterface *constraints) { |
2567 pcf_->create_media_controller_called_ = false; | 2620 pcf_->create_media_controller_called_ = false; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2812 FakeConstraints updated_answer_c; | 2865 FakeConstraints updated_answer_c; |
2813 answer_c.SetMandatoryReceiveAudio(false); | 2866 answer_c.SetMandatoryReceiveAudio(false); |
2814 answer_c.SetMandatoryReceiveVideo(false); | 2867 answer_c.SetMandatoryReceiveVideo(false); |
2815 | 2868 |
2816 cricket::MediaSessionOptions updated_answer_options; | 2869 cricket::MediaSessionOptions updated_answer_options; |
2817 EXPECT_TRUE( | 2870 EXPECT_TRUE( |
2818 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | 2871 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
2819 EXPECT_TRUE(updated_answer_options.has_audio()); | 2872 EXPECT_TRUE(updated_answer_options.has_audio()); |
2820 EXPECT_TRUE(updated_answer_options.has_video()); | 2873 EXPECT_TRUE(updated_answer_options.has_video()); |
2821 } | 2874 } |
OLD | NEW |