Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(117)

Side by Side Diff: webrtc/pc/peerconnectioninterface_unittest.cc

Issue 2990683002: Add PeerConnectionObserver::OnRemoveTrack callback.
Patch Set: Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/pc/peerconnection.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 599
600 void OnAddTrack( 600 void OnAddTrack(
601 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver, 601 rtc::scoped_refptr<webrtc::RtpReceiverInterface> receiver,
602 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>& 602 const std::vector<rtc::scoped_refptr<webrtc::MediaStreamInterface>>&
603 streams) override { 603 streams) override {
604 EXPECT_TRUE(receiver != nullptr); 604 EXPECT_TRUE(receiver != nullptr);
605 num_added_tracks_++; 605 num_added_tracks_++;
606 last_added_track_label_ = receiver->id(); 606 last_added_track_label_ = receiver->id();
607 } 607 }
608 608
609 void OnRemoveTrack(
610 rtc::scoped_refptr<RtpReceiverInterface> receiver,
611 const std::vector<rtc::scoped_refptr<MediaStreamInterface>> &
612 streams) override {
613 EXPECT_TRUE(receiver != nullptr);
614 num_removed_tracks_++;
615 last_removed_track_label_ = receiver->id();
616 }
617
609 // Returns the label of the last added stream. 618 // Returns the label of the last added stream.
610 // Empty string if no stream have been added. 619 // Empty string if no stream have been added.
611 std::string GetLastAddedStreamLabel() { 620 std::string GetLastAddedStreamLabel() {
612 if (last_added_stream_.get()) 621 if (last_added_stream_.get())
613 return last_added_stream_->label(); 622 return last_added_stream_->label();
614 return ""; 623 return "";
615 } 624 }
616 std::string GetLastRemovedStreamLabel() { 625 std::string GetLastRemovedStreamLabel() {
617 if (last_removed_stream_.get()) 626 if (last_removed_stream_.get())
618 return last_removed_stream_->label(); 627 return last_removed_stream_->label();
619 return ""; 628 return "";
620 } 629 }
621 630
622 rtc::scoped_refptr<PeerConnectionInterface> pc_; 631 rtc::scoped_refptr<PeerConnectionInterface> pc_;
623 PeerConnectionInterface::SignalingState state_; 632 PeerConnectionInterface::SignalingState state_;
624 std::unique_ptr<IceCandidateInterface> last_candidate_; 633 std::unique_ptr<IceCandidateInterface> last_candidate_;
625 rtc::scoped_refptr<DataChannelInterface> last_datachannel_; 634 rtc::scoped_refptr<DataChannelInterface> last_datachannel_;
626 rtc::scoped_refptr<StreamCollection> remote_streams_; 635 rtc::scoped_refptr<StreamCollection> remote_streams_;
627 bool renegotiation_needed_ = false; 636 bool renegotiation_needed_ = false;
628 bool ice_complete_ = false; 637 bool ice_complete_ = false;
629 bool callback_triggered_ = false; 638 bool callback_triggered_ = false;
630 int num_added_tracks_ = 0; 639 int num_added_tracks_ = 0;
631 std::string last_added_track_label_; 640 std::string last_added_track_label_;
641 int num_removed_tracks_ = 0;
642 std::string last_removed_track_label_;
632 643
633 private: 644 private:
634 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_; 645 rtc::scoped_refptr<MediaStreamInterface> last_added_stream_;
635 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_; 646 rtc::scoped_refptr<MediaStreamInterface> last_removed_stream_;
636 }; 647 };
637 648
638 } // namespace 649 } // namespace
639 650
640 // The PeerConnectionMediaConfig tests below verify that configuration and 651 // The PeerConnectionMediaConfig tests below verify that configuration and
641 // constraints are propagated into the PeerConnection's MediaConfig. These 652 // constraints are propagated into the PeerConnection's MediaConfig. These
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 rtc::scoped_refptr<MediaStreamInterface> stream( 868 rtc::scoped_refptr<MediaStreamInterface> stream(
858 pc_factory_->CreateLocalMediaStream(label)); 869 pc_factory_->CreateLocalMediaStream(label));
859 rtc::scoped_refptr<AudioTrackInterface> audio_track( 870 rtc::scoped_refptr<AudioTrackInterface> audio_track(
860 pc_factory_->CreateAudioTrack(label + "a0", NULL)); 871 pc_factory_->CreateAudioTrack(label + "a0", NULL));
861 stream->AddTrack(audio_track.get()); 872 stream->AddTrack(audio_track.get());
862 EXPECT_TRUE(pc_->AddStream(stream)); 873 EXPECT_TRUE(pc_->AddStream(stream));
863 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); 874 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
864 observer_.renegotiation_needed_ = false; 875 observer_.renegotiation_needed_ = false;
865 } 876 }
866 877
867 void AddAudioVideoStream(const std::string& stream_label, 878 rtc::scoped_refptr<MediaStreamInterface> AddAudioVideoStream(
868 const std::string& audio_track_label, 879 const std::string& stream_label,
869 const std::string& video_track_label) { 880 const std::string& audio_track_label,
881 const std::string& video_track_label) {
870 // Create a local stream. 882 // Create a local stream.
871 rtc::scoped_refptr<MediaStreamInterface> stream( 883 rtc::scoped_refptr<MediaStreamInterface> stream(
872 pc_factory_->CreateLocalMediaStream(stream_label)); 884 pc_factory_->CreateLocalMediaStream(stream_label));
873 rtc::scoped_refptr<AudioTrackInterface> audio_track( 885 rtc::scoped_refptr<AudioTrackInterface> audio_track(
874 pc_factory_->CreateAudioTrack( 886 pc_factory_->CreateAudioTrack(
875 audio_track_label, static_cast<AudioSourceInterface*>(NULL))); 887 audio_track_label, static_cast<AudioSourceInterface*>(NULL)));
876 stream->AddTrack(audio_track.get()); 888 stream->AddTrack(audio_track.get());
877 rtc::scoped_refptr<VideoTrackInterface> video_track( 889 rtc::scoped_refptr<VideoTrackInterface> video_track(
878 pc_factory_->CreateVideoTrack( 890 pc_factory_->CreateVideoTrack(
879 video_track_label, pc_factory_->CreateVideoSource( 891 video_track_label, pc_factory_->CreateVideoSource(
880 std::unique_ptr<cricket::VideoCapturer>( 892 std::unique_ptr<cricket::VideoCapturer>(
881 new cricket::FakeVideoCapturer())))); 893 new cricket::FakeVideoCapturer()))));
882 stream->AddTrack(video_track.get()); 894 stream->AddTrack(video_track.get());
883 EXPECT_TRUE(pc_->AddStream(stream)); 895 EXPECT_TRUE(pc_->AddStream(stream));
884 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); 896 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
885 observer_.renegotiation_needed_ = false; 897 observer_.renegotiation_needed_ = false;
898 return stream;
886 } 899 }
887 900
888 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc, 901 bool DoCreateOfferAnswer(std::unique_ptr<SessionDescriptionInterface>* desc,
889 bool offer, 902 bool offer,
890 MediaConstraintsInterface* constraints) { 903 MediaConstraintsInterface* constraints) {
891 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> 904 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
892 observer(new rtc::RefCountedObject< 905 observer(new rtc::RefCountedObject<
893 MockCreateSessionDescriptionObserver>()); 906 MockCreateSessionDescriptionObserver>());
894 if (offer) { 907 if (offer) {
895 pc_->CreateOffer(observer, constraints); 908 pc_->CreateOffer(observer, constraints);
(...skipping 2867 matching lines...) Expand 10 before | Expand all | Expand 10 after
3763 observer_.renegotiation_needed_ = false; 3776 observer_.renegotiation_needed_ = false;
3764 3777
3765 stream->RemoveTrack(audio_track); 3778 stream->RemoveTrack(audio_track);
3766 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); 3779 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3767 observer_.renegotiation_needed_ = false; 3780 observer_.renegotiation_needed_ = false;
3768 3781
3769 stream->RemoveTrack(video_track); 3782 stream->RemoveTrack(video_track);
3770 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout); 3783 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3771 observer_.renegotiation_needed_ = false; 3784 observer_.renegotiation_needed_ = false;
3772 } 3785 }
3786
3787 // This tests that PeerConnectionObserver::OnRemoveTrack is correctly called.
3788 TEST_F(PeerConnectionInterfaceTest, OnRemoveTrackCallback) {
3789 CreatePeerConnectionWithoutDtls();
3790 auto stream = AddAudioVideoStream(
3791 kStreamLabel1, "audio_label", "video_label");
3792 CreateOfferReceiveAnswer();
3793
3794 auto audio_track = stream->GetAudioTracks()[0];
3795 EXPECT_TRUE(stream->RemoveTrack(audio_track));
3796 EXPECT_TRUE_WAIT(observer_.renegotiation_needed_, kTimeout);
3797 observer_.renegotiation_needed_ = false;
3798
3799 CreateOfferReceiveAnswer();
3800
3801 EXPECT_EQ(observer_.num_removed_tracks_, 1u);
3802 EXPECT_EQ(observer_.last_removed_track_label_, audio_track->id());
3803 }
OLDNEW
« no previous file with comments | « webrtc/pc/peerconnection.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698