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 is_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 is_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 is_triggered = true; | |
514 } | |
515 | |
516 void OnIceCandidatesRemoved( | |
517 const std::vector<cricket::Candidate>& candidates) override { | |
518 is_triggered = true; | |
519 } | |
520 | |
521 void OnIceConnectionReceivingChange(bool receiving) override { | |
522 is_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 is_triggered = false; | |
Taylor Brandstetter
2016/06/21 23:50:02
Maybe rename to "callback_triggered"?
Zhi Huang
2016/06/22 22:01:08
OK. This is more readable.
| |
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_F(PeerConnectionInterfaceTest, CloseAndTestCallbackFunctions) { | |
Taylor Brandstetter
2016/06/21 23:50:02
You could add a comment explaining that this is te
| |
1053 scoped_refptr<PeerConnectionInterface> pc( | |
1054 pc_factory_for_test_->CreatePeerConnection( | |
1055 PeerConnectionInterface::RTCConfiguration(), nullptr, nullptr, | |
1056 nullptr, &observer_)); | |
1057 observer_.SetPeerConnectionInterface(pc.get()); | |
1058 pc->Close(); | |
1059 | |
1060 observer_.is_triggered = false; | |
1061 std::vector<cricket::Candidate> candidates; | |
1062 pc_factory_for_test_->transport_controller->SignalGatheringState( | |
1063 cricket::IceGatheringState{}); | |
1064 pc_factory_for_test_->transport_controller->SignalCandidatesGathered( | |
1065 "", candidates); | |
1066 pc_factory_for_test_->transport_controller->SignalConnectionState( | |
1067 cricket::IceConnectionState{}); | |
1068 pc_factory_for_test_->transport_controller->SignalCandidatesRemoved( | |
1069 candidates); | |
1070 pc_factory_for_test_->transport_controller->SignalReceiving(false); | |
1071 EXPECT_FALSE(observer_.is_triggered); | |
1072 } | |
1073 | |
1002 // Generate different CNAMEs when PeerConnections are created. | 1074 // Generate different CNAMEs when PeerConnections are created. |
1003 // The CNAMEs are expected to be generated randomly. It is possible | 1075 // The CNAMEs are expected to be generated randomly. It is possible |
1004 // that the test fails, though the possibility is very low. | 1076 // that the test fails, though the possibility is very low. |
1005 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { | 1077 TEST_F(PeerConnectionInterfaceTest, CnameGenerationInOffer) { |
1006 std::unique_ptr<SessionDescriptionInterface> offer1 = | 1078 std::unique_ptr<SessionDescriptionInterface> offer1 = |
1007 CreateOfferWithOneAudioStream(); | 1079 CreateOfferWithOneAudioStream(); |
1008 std::unique_ptr<SessionDescriptionInterface> offer2 = | 1080 std::unique_ptr<SessionDescriptionInterface> offer2 = |
1009 CreateOfferWithOneAudioStream(); | 1081 CreateOfferWithOneAudioStream(); |
1010 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), | 1082 EXPECT_NE(GetFirstAudioStreamCname(offer1.get()), |
1011 GetFirstAudioStreamCname(offer2.get())); | 1083 GetFirstAudioStreamCname(offer2.get())); |
(...skipping 1512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2524 | 2596 |
2525 auto new_senders = pc_->GetSenders(); | 2597 auto new_senders = pc_->GetSenders(); |
2526 // Should be the same senders as before, but with updated stream id. | 2598 // Should be the same senders as before, but with updated stream id. |
2527 // Note that this behavior is subject to change in the future. | 2599 // Note that this behavior is subject to change in the future. |
2528 // We may decide the PC should ignore existing tracks in AddStream. | 2600 // We may decide the PC should ignore existing tracks in AddStream. |
2529 EXPECT_EQ(senders, new_senders); | 2601 EXPECT_EQ(senders, new_senders); |
2530 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); | 2602 EXPECT_TRUE(ContainsSender(new_senders, kAudioTracks[0], kStreams[1])); |
2531 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); | 2603 EXPECT_TRUE(ContainsSender(new_senders, kVideoTracks[0], kStreams[1])); |
2532 } | 2604 } |
2533 | 2605 |
2534 // The PeerConnectionMediaConfig tests below verify that configuration | |
2535 // and constraints are propagated into the MediaConfig passed to | |
2536 // CreateMediaController. These settings are intended for MediaChannel | |
2537 // constructors, but that is not exercised by these unittest. | |
2538 class PeerConnectionFactoryForTest : public webrtc::PeerConnectionFactory { | |
2539 public: | |
2540 webrtc::MediaControllerInterface* CreateMediaController( | |
2541 const cricket::MediaConfig& config) const override { | |
2542 create_media_controller_called_ = true; | |
2543 create_media_controller_config_ = config; | |
2544 | |
2545 webrtc::MediaControllerInterface* mc = | |
2546 PeerConnectionFactory::CreateMediaController(config); | |
2547 EXPECT_TRUE(mc != nullptr); | |
2548 return mc; | |
2549 } | |
2550 | |
2551 // Mutable, so they can be modified in the above const-declared method. | |
2552 mutable bool create_media_controller_called_ = false; | |
2553 mutable cricket::MediaConfig create_media_controller_config_; | |
2554 }; | |
2555 | |
2556 class PeerConnectionMediaConfigTest : public testing::Test { | 2606 class PeerConnectionMediaConfigTest : public testing::Test { |
2557 protected: | 2607 protected: |
2558 void SetUp() override { | 2608 void SetUp() override { |
2559 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); | 2609 pcf_ = new rtc::RefCountedObject<PeerConnectionFactoryForTest>(); |
2560 pcf_->Initialize(); | 2610 pcf_->Initialize(); |
2561 } | 2611 } |
2562 const cricket::MediaConfig& TestCreatePeerConnection( | 2612 const cricket::MediaConfig& TestCreatePeerConnection( |
2563 const PeerConnectionInterface::RTCConfiguration& config, | 2613 const PeerConnectionInterface::RTCConfiguration& config, |
2564 const MediaConstraintsInterface *constraints) { | 2614 const MediaConstraintsInterface *constraints) { |
2565 pcf_->create_media_controller_called_ = false; | 2615 pcf_->create_media_controller_called_ = false; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2810 FakeConstraints updated_answer_c; | 2860 FakeConstraints updated_answer_c; |
2811 answer_c.SetMandatoryReceiveAudio(false); | 2861 answer_c.SetMandatoryReceiveAudio(false); |
2812 answer_c.SetMandatoryReceiveVideo(false); | 2862 answer_c.SetMandatoryReceiveVideo(false); |
2813 | 2863 |
2814 cricket::MediaSessionOptions updated_answer_options; | 2864 cricket::MediaSessionOptions updated_answer_options; |
2815 EXPECT_TRUE( | 2865 EXPECT_TRUE( |
2816 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); | 2866 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); |
2817 EXPECT_TRUE(updated_answer_options.has_audio()); | 2867 EXPECT_TRUE(updated_answer_options.has_audio()); |
2818 EXPECT_TRUE(updated_answer_options.has_video()); | 2868 EXPECT_TRUE(updated_answer_options.has_video()); |
2819 } | 2869 } |
OLD | NEW |