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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 remote_streams_->RemoveStream(stream); | 483 remote_streams_->RemoveStream(stream); |
483 } | 484 } |
484 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; } | 485 void OnRenegotiationNeeded() override { renegotiation_needed_ = true; } |
485 void OnDataChannel(DataChannelInterface* data_channel) override { | 486 void OnDataChannel(DataChannelInterface* data_channel) override { |
486 last_datachannel_ = data_channel; | 487 last_datachannel_ = data_channel; |
487 } | 488 } |
488 | 489 |
489 void OnIceConnectionChange( | 490 void OnIceConnectionChange( |
490 PeerConnectionInterface::IceConnectionState new_state) override { | 491 PeerConnectionInterface::IceConnectionState new_state) override { |
491 EXPECT_EQ(pc_->ice_connection_state(), new_state); | 492 EXPECT_EQ(pc_->ice_connection_state(), new_state); |
| 493 is_triggered = true; |
492 } | 494 } |
493 void OnIceGatheringChange( | 495 void OnIceGatheringChange( |
494 PeerConnectionInterface::IceGatheringState new_state) override { | 496 PeerConnectionInterface::IceGatheringState new_state) override { |
495 EXPECT_EQ(pc_->ice_gathering_state(), new_state); | 497 EXPECT_EQ(pc_->ice_gathering_state(), new_state); |
496 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete; | 498 ice_complete_ = new_state == PeerConnectionInterface::kIceGatheringComplete; |
| 499 is_triggered = true; |
497 } | 500 } |
498 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { | 501 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
499 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, | 502 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, |
500 pc_->ice_gathering_state()); | 503 pc_->ice_gathering_state()); |
501 | 504 |
502 std::string sdp; | 505 std::string sdp; |
503 EXPECT_TRUE(candidate->ToString(&sdp)); | 506 EXPECT_TRUE(candidate->ToString(&sdp)); |
504 EXPECT_LT(0u, sdp.size()); | 507 EXPECT_LT(0u, sdp.size()); |
505 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(), | 508 last_candidate_.reset(webrtc::CreateIceCandidate(candidate->sdp_mid(), |
506 candidate->sdp_mline_index(), sdp, NULL)); | 509 candidate->sdp_mline_index(), sdp, NULL)); |
507 EXPECT_TRUE(last_candidate_.get() != NULL); | 510 EXPECT_TRUE(last_candidate_.get() != NULL); |
| 511 is_triggered = true; |
| 512 } |
| 513 |
| 514 void OnIceCandidatesRemoved( |
| 515 const std::vector<cricket::Candidate>& candidates) override { |
| 516 is_triggered = true; |
| 517 } |
| 518 |
| 519 void OnIceConnectionReceivingChange(bool receiving) override { |
| 520 is_triggered = true; |
508 } | 521 } |
509 | 522 |
510 // Returns the label of the last added stream. | 523 // Returns the label of the last added stream. |
511 // Empty string if no stream have been added. | 524 // Empty string if no stream have been added. |
512 std::string GetLastAddedStreamLabel() { | 525 std::string GetLastAddedStreamLabel() { |
513 if (last_added_stream_.get()) | 526 if (last_added_stream_.get()) |
514 return last_added_stream_->label(); | 527 return last_added_stream_->label(); |
515 return ""; | 528 return ""; |
516 } | 529 } |
517 std::string GetLastRemovedStreamLabel() { | 530 std::string GetLastRemovedStreamLabel() { |
518 if (last_removed_stream_.get()) | 531 if (last_removed_stream_.get()) |
519 return last_removed_stream_->label(); | 532 return last_removed_stream_->label(); |
520 return ""; | 533 return ""; |
521 } | 534 } |
522 | 535 |
523 scoped_refptr<PeerConnectionInterface> pc_; | 536 scoped_refptr<PeerConnectionInterface> pc_; |
524 PeerConnectionInterface::SignalingState state_; | 537 PeerConnectionInterface::SignalingState state_; |
525 std::unique_ptr<IceCandidateInterface> last_candidate_; | 538 std::unique_ptr<IceCandidateInterface> last_candidate_; |
526 scoped_refptr<DataChannelInterface> last_datachannel_; | 539 scoped_refptr<DataChannelInterface> last_datachannel_; |
527 rtc::scoped_refptr<StreamCollection> remote_streams_; | 540 rtc::scoped_refptr<StreamCollection> remote_streams_; |
528 bool renegotiation_needed_ = false; | 541 bool renegotiation_needed_ = false; |
529 bool ice_complete_ = false; | 542 bool ice_complete_ = false; |
| 543 bool is_triggered = false; |
530 | 544 |
531 private: | 545 private: |
532 scoped_refptr<MediaStreamInterface> last_added_stream_; | 546 scoped_refptr<MediaStreamInterface> last_added_stream_; |
533 scoped_refptr<MediaStreamInterface> last_removed_stream_; | 547 scoped_refptr<MediaStreamInterface> last_removed_stream_; |
534 }; | 548 }; |
535 | 549 |
536 } // namespace | 550 } // namespace |
537 | 551 |
| 552 // The PeerConnectionMediaConfig tests below verify that configuration |
| 553 // and constraints are propagated into the MediaConfig passed to |
| 554 // CreateMediaController. These settings are intended for MediaChannel |
| 555 // constructors, but that is not exercised by these unittest. |
| 556 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { |
| 557 public: |
| 558 webrtc::MediaControllerInterface* CreateMediaController( |
| 559 const cricket::MediaConfig& config) const override { |
| 560 create_media_controller_called_ = true; |
| 561 create_media_controller_config_ = config; |
| 562 |
| 563 webrtc::MediaControllerInterface* mc = |
| 564 PeerConnectionFactory::CreateMediaController(config); |
| 565 EXPECT_TRUE(mc != nullptr); |
| 566 return mc; |
| 567 } |
| 568 |
| 569 cricket::TransportController* CreateTransportController( |
| 570 cricket::PortAllocator* port_allocator) override { |
| 571 transport_controller = new cricket::TransportController( |
| 572 rtc::Thread::Current(), rtc::Thread::Current(), port_allocator); |
| 573 return transport_controller; |
| 574 } |
| 575 |
| 576 cricket::TransportController* transport_controller; |
| 577 // Mutable, so they can be modified in the above const-declared method. |
| 578 mutable bool create_media_controller_called_ = false; |
| 579 mutable cricket::MediaConfig create_media_controller_config_; |
| 580 }; |
| 581 |
538 class PeerConnectionInterfaceTest : public testing::Test { | 582 class PeerConnectionInterfaceTest : public testing::Test { |
539 protected: | 583 protected: |
540 PeerConnectionInterfaceTest() { | 584 PeerConnectionInterfaceTest() { |
541 #ifdef WEBRTC_ANDROID | 585 #ifdef WEBRTC_ANDROID |
542 webrtc::InitializeAndroidObjects(); | 586 webrtc::InitializeAndroidObjects(); |
543 #endif | 587 #endif |
544 } | 588 } |
545 | 589 |
| 590 protected: |
546 virtual void SetUp() { | 591 virtual void SetUp() { |
547 pc_factory_ = webrtc::CreatePeerConnectionFactory( | 592 pc_factory_ = webrtc::CreatePeerConnectionFactory( |
548 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), | 593 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), |
549 nullptr, nullptr, nullptr); | 594 nullptr, nullptr, nullptr); |
550 ASSERT_TRUE(pc_factory_); | 595 ASSERT_TRUE(pc_factory_); |
| 596 pc_factory_for_test_ = |
| 597 new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); |
| 598 pc_factory_for_test_->Initialize(); |
551 } | 599 } |
552 | 600 |
553 void CreatePeerConnection() { | 601 void CreatePeerConnection() { |
554 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr); | 602 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), nullptr); |
555 } | 603 } |
556 | 604 |
557 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { | 605 void CreatePeerConnection(webrtc::MediaConstraintsInterface* constraints) { |
558 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), | 606 CreatePeerConnection(PeerConnectionInterface::RTCConfiguration(), |
559 constraints); | 607 constraints); |
560 } | 608 } |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 | 771 |
724 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) { | 772 bool DoSetSessionDescription(SessionDescriptionInterface* desc, bool local) { |
725 rtc::scoped_refptr<MockSetSessionDescriptionObserver> | 773 rtc::scoped_refptr<MockSetSessionDescriptionObserver> |
726 observer(new rtc::RefCountedObject< | 774 observer(new rtc::RefCountedObject< |
727 MockSetSessionDescriptionObserver>()); | 775 MockSetSessionDescriptionObserver>()); |
728 if (local) { | 776 if (local) { |
729 pc_->SetLocalDescription(observer, desc); | 777 pc_->SetLocalDescription(observer, desc); |
730 } else { | 778 } else { |
731 pc_->SetRemoteDescription(observer, desc); | 779 pc_->SetRemoteDescription(observer, desc); |
732 } | 780 } |
733 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); | 781 if (pc_->signaling_state() != PeerConnectionInterface::kClosed) { |
| 782 EXPECT_EQ_WAIT(true, observer->called(), kTimeout); |
| 783 } |
734 return observer->result(); | 784 return observer->result(); |
735 } | 785 } |
736 | 786 |
737 bool DoSetLocalDescription(SessionDescriptionInterface* desc) { | 787 bool DoSetLocalDescription(SessionDescriptionInterface* desc) { |
738 return DoSetSessionDescription(desc, true); | 788 return DoSetSessionDescription(desc, true); |
739 } | 789 } |
740 | 790 |
741 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { | 791 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { |
742 return DoSetSessionDescription(desc, false); | 792 return DoSetSessionDescription(desc, false); |
743 } | 793 } |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 const cricket::ContentInfo* audio_content = | 1035 const cricket::ContentInfo* audio_content = |
986 cricket::GetFirstAudioContent(desc->description()); | 1036 cricket::GetFirstAudioContent(desc->description()); |
987 const cricket::AudioContentDescription* audio_desc = | 1037 const cricket::AudioContentDescription* audio_desc = |
988 static_cast<const cricket::AudioContentDescription*>( | 1038 static_cast<const cricket::AudioContentDescription*>( |
989 audio_content->description); | 1039 audio_content->description); |
990 return audio_desc->streams()[0].cname; | 1040 return audio_desc->streams()[0].cname; |
991 } | 1041 } |
992 | 1042 |
993 cricket::FakePortAllocator* port_allocator_ = nullptr; | 1043 cricket::FakePortAllocator* port_allocator_ = nullptr; |
994 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | 1044 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
| 1045 scoped_refptr<PeerConnectionFactoryForTest> pc_factory_for_test_; |
995 scoped_refptr<PeerConnectionInterface> pc_; | 1046 scoped_refptr<PeerConnectionInterface> pc_; |
996 MockPeerConnectionObserver observer_; | 1047 MockPeerConnectionObserver observer_; |
997 rtc::scoped_refptr<StreamCollection> reference_collection_; | 1048 rtc::scoped_refptr<StreamCollection> reference_collection_; |
998 }; | 1049 }; |
999 | 1050 |
| 1051 TEST_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) { |
| 1052 scoped_refptr<PeerConnectionInterface> pc( |
| 1053 pc_factory_for_test_->CreatePeerConnection( |
| 1054 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr, |
| 1055 nullptr, &observer_)); |
| 1056 observer_.SetPeerConnectionInterface(pc.get()); |
| 1057 pc->Close(); |
| 1058 |
| 1059 observer_.is_triggered = false; |
| 1060 std::vector<cricket::Candidate> candidates; |
| 1061 pc_factory_for_test_->transport_controller->SignalGatheringState( |
| 1062 cricket::IceGatheringState{}); |
| 1063 pc_factory_for_test_->transport_controller->SignalCandidatesGathered( |
| 1064 "", candidates); |
| 1065 pc_factory_for_test_->transport_controller->SignalConnectionState( |
| 1066 cricket::IceConnectionState{}); |
| 1067 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved( |
| 1068 candidates); |
| 1069 pc_factory_for_test_->transport_controller->SignalReceiving(false); |
| 1070 EXPECT_FALSE(observer_.is_triggered); |
| 1071 } |
| 1072 |
1000 // Generate different CNAMEs when PeerConnections are created. | 1073 // Generate different CNAMEs when PeerConnections are created. |
1001 // The CNAMEs are expected to be generated randomly. It is possible | 1074 // The CNAMEs are expected to be generated randomly. It is possible |
1002 // that the test fails, though the possibility is very low. | 1075 // that the test fails, though the possibility is very low. |
1003 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { | 1076 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { |
1004 std::unique_ptr<SessionDescriptionInterface> offer1 = | 1077 std::unique_ptr<SessionDescriptionInterface> offer1 = |
1005 CreateOfferWithOneAudioStream(); | 1078 CreateOfferWithOneAudioStream(); |
1006 std::unique_ptr<SessionDescriptionInterface> offer2 = | 1079 std::unique_ptr<SessionDescriptionInterface> offer2 = |
1007 CreateOfferWithOneAudioStream(); | 1080 CreateOfferWithOneAudioStream(); |
1008 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), | 1081 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), |
1009 GetFirstAudioStreamCname(offer2.get())); | 1082 GetFirstAudioStreamCname(offer2.get())); |
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2518 | 2591 |
2519 auto new_senders = pc_->GetSenders(); | 2592 auto new_senders = pc_->GetSenders(); |
2520 // Should be the same senders as before, but with updated stream id. | 2593 // Should be the same senders as before, but with updated stream id. |
2521 // Note that this behavior is subject to change in the future. | 2594 // Note that this behavior is subject to change in the future. |
2522 // We may decide the PC should ignore existing tracks in AddStream. | 2595 // We may decide the PC should ignore existing tracks in AddStream. |
2523 EXPECT_EQ(senders, new_senders); | 2596 EXPECT_EQ(senders, new_senders); |
2524 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); | 2597 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); |
2525 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); | 2598 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); |
2526 } | 2599 } |
2527 | 2600 |
2528 // The PeerConnectionMediaConfig tests below verify that configuration | |
2529 // and constraints are propagated into the MediaConfig passed to | |
2530 // CreateMediaController. These settings are intended for MediaChannel | |
2531 // constructors, but that is not exercised by these unittest. | |
2532 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { | |
2533 public: | |
2534 webrtc::MediaControllerInterface* CreateMediaController( | |
2535 const cricket::MediaConfig& config) const override { | |
2536 create_media_controller_called_ = true; | |
2537 create_media_controller_config_ = config; | |
2538 | |
2539 webrtc::MediaControllerInterface* mc = | |
2540 PeerConnectionFactory::CreateMediaController(config); | |
2541 EXPECT_TRUE(mc != nullptr); | |
2542 return mc; | |
2543 } | |
2544 | |
2545 // Mutable, so they can be modified in the above const-declared method. | |
2546 mutable bool create_media_controller_called_ = false; | |
2547 mutable cricket::MediaConfig create_media_controller_config_; | |
2548 }; | |
2549 | |
2550 class PeerConnectionMediaConfigTest : public testing::Test { | 2601 class PeerConnectionMediaConfigTest : public testing::Test { |
2551 protected: | 2602 protected: |
2552 void SetUp() override { | 2603 void SetUp() override { |
2553 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); | 2604 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); |
2554 pcf_->Initialize(); | 2605 pcf_->Initialize(); |
2555 } | 2606 } |
2556 const cricket::MediaConfig& TestCreatePeerConnection( | 2607 const cricket::MediaConfig& TestCreatePeerConnection( |
2557 const PeerConnectionInterface::RTCConfiguration& config, | 2608 const PeerConnectionInterface::RTCConfiguration& config, |
2558 const MediaConstraintsInterface *constraints) { | 2609 const MediaConstraintsInterface *constraints) { |
2559 pcf_->create_media_controller_called_ = false; | 2610 pcf_->create_media_controller_called_ = false; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2804 FakeConstraints updated_answer_c; | 2855 FakeConstraints updated_answer_c; |
2805 answer_c.SetMandatoryReceiveAudio(false); | 2856 answer_c.SetMandatoryReceiveAudio(false); |
2806 answer_c.SetMandatoryReceiveVideo(false); | 2857 answer_c.SetMandatoryReceiveVideo(false); |
2807 | 2858 |
2808 cricket::MediaSessionOptions updated_answer_options; | 2859 cricket::MediaSessionOptions updated_answer_options; |
2809 EXPECT_TRUE( | 2860 EXPECT_TRUE( |
2810 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | 2861 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
2811 EXPECT_TRUE(updated_answer_options.has_audio()); | 2862 EXPECT_TRUE(updated_answer_options.has_audio()); |
2812 EXPECT_TRUE(updated_answer_options.has_video()); | 2863 EXPECT_TRUE(updated_answer_options.has_video()); |
2813 } | 2864 } |
OLD | NEW |