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

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

Issue 1816143002: Removed MediaStreamTrackInterface::set_state (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@track_state_listen_on_source2
Patch Set: Rebased Created 4 years, 9 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/api/peerconnection.cc ('k') | webrtc/api/rtpreceiver.h » ('j') | 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
11 #include <string> 11 #include <string>
12 #include <utility> 12 #include <utility>
13 13
14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "webrtc/api/audiotrack.h" 15 #include "webrtc/api/audiotrack.h"
15 #include "webrtc/api/jsepsessiondescription.h" 16 #include "webrtc/api/jsepsessiondescription.h"
16 #include "webrtc/api/mediastream.h" 17 #include "webrtc/api/mediastream.h"
17 #include "webrtc/api/mediastreaminterface.h" 18 #include "webrtc/api/mediastreaminterface.h"
18 #include "webrtc/api/peerconnection.h" 19 #include "webrtc/api/peerconnection.h"
19 #include "webrtc/api/peerconnectioninterface.h" 20 #include "webrtc/api/peerconnectioninterface.h"
20 #include "webrtc/api/rtpreceiverinterface.h" 21 #include "webrtc/api/rtpreceiverinterface.h"
21 #include "webrtc/api/rtpsenderinterface.h" 22 #include "webrtc/api/rtpsenderinterface.h"
22 #include "webrtc/api/streamcollection.h" 23 #include "webrtc/api/streamcollection.h"
23 #ifdef WEBRTC_ANDROID 24 #ifdef WEBRTC_ANDROID
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 "a=ssrc:4 msid:stream1 videotrack1\r\n"; 234 "a=ssrc:4 msid:stream1 videotrack1\r\n";
234 235
235 #define MAYBE_SKIP_TEST(feature) \ 236 #define MAYBE_SKIP_TEST(feature) \
236 if (!(feature())) { \ 237 if (!(feature())) { \
237 LOG(LS_INFO) << "Feature disabled... skipping"; \ 238 LOG(LS_INFO) << "Feature disabled... skipping"; \
238 return; \ 239 return; \
239 } 240 }
240 241
241 using rtc::scoped_ptr; 242 using rtc::scoped_ptr;
242 using rtc::scoped_refptr; 243 using rtc::scoped_refptr;
244 using ::testing::Exactly;
243 using webrtc::AudioSourceInterface; 245 using webrtc::AudioSourceInterface;
244 using webrtc::AudioTrack; 246 using webrtc::AudioTrack;
245 using webrtc::AudioTrackInterface; 247 using webrtc::AudioTrackInterface;
246 using webrtc::DataBuffer; 248 using webrtc::DataBuffer;
247 using webrtc::DataChannelInterface; 249 using webrtc::DataChannelInterface;
248 using webrtc::FakeConstraints; 250 using webrtc::FakeConstraints;
249 using webrtc::IceCandidateInterface; 251 using webrtc::IceCandidateInterface;
250 using webrtc::MediaConstraintsInterface; 252 using webrtc::MediaConstraintsInterface;
251 using webrtc::MediaStream; 253 using webrtc::MediaStream;
252 using webrtc::MediaStreamInterface; 254 using webrtc::MediaStreamInterface;
253 using webrtc::MediaStreamTrackInterface; 255 using webrtc::MediaStreamTrackInterface;
254 using webrtc::MockCreateSessionDescriptionObserver; 256 using webrtc::MockCreateSessionDescriptionObserver;
255 using webrtc::MockDataChannelObserver; 257 using webrtc::MockDataChannelObserver;
256 using webrtc::MockSetSessionDescriptionObserver; 258 using webrtc::MockSetSessionDescriptionObserver;
257 using webrtc::MockStatsObserver; 259 using webrtc::MockStatsObserver;
260 using webrtc::NotifierInterface;
261 using webrtc::ObserverInterface;
258 using webrtc::PeerConnectionInterface; 262 using webrtc::PeerConnectionInterface;
259 using webrtc::PeerConnectionObserver; 263 using webrtc::PeerConnectionObserver;
260 using webrtc::RtpReceiverInterface; 264 using webrtc::RtpReceiverInterface;
261 using webrtc::RtpSenderInterface; 265 using webrtc::RtpSenderInterface;
262 using webrtc::SdpParseError; 266 using webrtc::SdpParseError;
263 using webrtc::SessionDescriptionInterface; 267 using webrtc::SessionDescriptionInterface;
264 using webrtc::StreamCollection; 268 using webrtc::StreamCollection;
265 using webrtc::StreamCollectionInterface; 269 using webrtc::StreamCollectionInterface;
266 using webrtc::VideoTrackSourceInterface; 270 using webrtc::VideoTrackSourceInterface;
267 using webrtc::VideoTrack; 271 using webrtc::VideoTrack;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 384 }
381 for (size_t j = 0; j != video_tracks1.size(); ++j) { 385 for (size_t j = 0; j != video_tracks1.size(); ++j) {
382 if (video_tracks1[j]->id() != video_tracks2[j]->id()) { 386 if (video_tracks1[j]->id() != video_tracks2[j]->id()) {
383 return false; 387 return false;
384 } 388 }
385 } 389 }
386 } 390 }
387 return true; 391 return true;
388 } 392 }
389 393
394 // Helper class to test Observer.
395 class MockTrackObserver : public ObserverInterface {
396 public:
397 explicit MockTrackObserver(NotifierInterface* notifier)
398 : notifier_(notifier) {
399 notifier_->RegisterObserver(this);
400 }
401
402 ~MockTrackObserver() { Unregister(); }
403
404 void Unregister() {
405 if (notifier_) {
406 notifier_->UnregisterObserver(this);
407 notifier_ = nullptr;
408 }
409 }
410
411 MOCK_METHOD0(OnChanged, void());
412
413 private:
414 NotifierInterface* notifier_;
415 };
416
390 class MockPeerConnectionObserver : public PeerConnectionObserver { 417 class MockPeerConnectionObserver : public PeerConnectionObserver {
391 public: 418 public:
392 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {} 419 MockPeerConnectionObserver() : remote_streams_(StreamCollection::Create()) {}
393 ~MockPeerConnectionObserver() { 420 ~MockPeerConnectionObserver() {
394 } 421 }
395 void SetPeerConnectionInterface(PeerConnectionInterface* pc) { 422 void SetPeerConnectionInterface(PeerConnectionInterface* pc) {
396 pc_ = pc; 423 pc_ = pc;
397 if (pc) { 424 if (pc) {
398 state_ = pc_->signaling_state(); 425 state_ = pc_->signaling_state();
399 } 426 }
(...skipping 1436 matching lines...) Expand 10 before | Expand all | Expand 10 after
1836 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete, 1863 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
1837 pc_->ice_gathering_state()); 1864 pc_->ice_gathering_state());
1838 1865
1839 EXPECT_EQ(1u, pc_->local_streams()->count()); 1866 EXPECT_EQ(1u, pc_->local_streams()->count());
1840 EXPECT_EQ(1u, pc_->remote_streams()->count()); 1867 EXPECT_EQ(1u, pc_->remote_streams()->count());
1841 1868
1842 scoped_refptr<MediaStreamInterface> remote_stream = 1869 scoped_refptr<MediaStreamInterface> remote_stream =
1843 pc_->remote_streams()->at(0); 1870 pc_->remote_streams()->at(0);
1844 EXPECT_EQ(MediaStreamTrackInterface::kEnded, 1871 EXPECT_EQ(MediaStreamTrackInterface::kEnded,
1845 remote_stream->GetVideoTracks()[0]->state()); 1872 remote_stream->GetVideoTracks()[0]->state());
1846 EXPECT_EQ(MediaStreamTrackInterface::kEnded, 1873 // Audio source state changes are posted.
1847 remote_stream->GetAudioTracks()[0]->state()); 1874 EXPECT_EQ_WAIT(MediaStreamTrackInterface::kEnded,
1875 remote_stream->GetAudioTracks()[0]->state(), 1);
1848 } 1876 }
1849 1877
1850 // Test that PeerConnection methods fails gracefully after 1878 // Test that PeerConnection methods fails gracefully after
1851 // PeerConnection::Close has been called. 1879 // PeerConnection::Close has been called.
1852 TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) { 1880 TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) {
1853 CreatePeerConnection(); 1881 CreatePeerConnection();
1854 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); 1882 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1855 CreateOfferAsRemoteDescription(); 1883 CreateOfferAsRemoteDescription();
1856 CreateAnswerAsLocalDescription(); 1884 CreateAnswerAsLocalDescription();
1857 1885
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release())); 1970 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release()));
1943 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), 1971 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
1944 reference_collection_)); 1972 reference_collection_));
1945 1973
1946 // Add extra audio and video tracks to the same MediaStream. 1974 // Add extra audio and video tracks to the same MediaStream.
1947 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1_two_tracks = 1975 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
1948 CreateSessionDescriptionAndReference(2, 2); 1976 CreateSessionDescriptionAndReference(2, 2);
1949 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release())); 1977 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release()));
1950 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), 1978 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
1951 reference_collection_)); 1979 reference_collection_));
1980 scoped_refptr<AudioTrackInterface> audio_track2 =
1981 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
1982 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
1983 scoped_refptr<VideoTrackInterface> video_track2 =
1984 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
1985 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
1952 1986
1953 // Remove the extra audio and video tracks. 1987 // Remove the extra audio and video tracks.
1954 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms2 = 1988 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms2 =
1955 CreateSessionDescriptionAndReference(1, 1); 1989 CreateSessionDescriptionAndReference(1, 1);
1990 MockTrackObserver audio_track_observer(audio_track2);
1991 MockTrackObserver video_track_observer(video_track2);
1992
1993 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
1994 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
1956 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release())); 1995 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release()));
1957 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), 1996 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
1958 reference_collection_)); 1997 reference_collection_));
1998 // Audio source state changes are posted.
1999 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2000 audio_track2->state(), 1);
2001 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, video_track2->state());
1959 } 2002 }
1960 2003
1961 // This tests that remote tracks are ended if a local session description is set 2004 // This tests that remote tracks are ended if a local session description is set
1962 // that rejects the media content type. 2005 // that rejects the media content type.
1963 TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) { 2006 TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) {
1964 FakeConstraints constraints; 2007 FakeConstraints constraints;
1965 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, 2008 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1966 true); 2009 true);
1967 CreatePeerConnection(&constraints); 2010 CreatePeerConnection(&constraints);
1968 // First create and set a remote offer, then reject its video content in our 2011 // First create and set a remote offer, then reject its video content in our
(...skipping 25 matching lines...) Expand all
1994 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr)); 2037 EXPECT_TRUE(DoCreateOffer(&local_offer, nullptr));
1995 video_info = local_offer->description()->GetContentByName("video"); 2038 video_info = local_offer->description()->GetContentByName("video");
1996 ASSERT_TRUE(video_info != nullptr); 2039 ASSERT_TRUE(video_info != nullptr);
1997 video_info->rejected = true; 2040 video_info->rejected = true;
1998 cricket::ContentInfo* audio_info = 2041 cricket::ContentInfo* audio_info =
1999 local_offer->description()->GetContentByName("audio"); 2042 local_offer->description()->GetContentByName("audio");
2000 ASSERT_TRUE(audio_info != nullptr); 2043 ASSERT_TRUE(audio_info != nullptr);
2001 audio_info->rejected = true; 2044 audio_info->rejected = true;
2002 EXPECT_TRUE(DoSetLocalDescription(local_offer.release())); 2045 EXPECT_TRUE(DoSetLocalDescription(local_offer.release()));
2003 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state()); 2046 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_video->state());
2004 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, remote_audio->state()); 2047 // Audio source state changes are posted.
2048 EXPECT_EQ_WAIT(webrtc::MediaStreamTrackInterface::kEnded,
2049 remote_audio->state(), 1);
2005 } 2050 }
2006 2051
2007 // This tests that we won't crash if the remote track has been removed outside 2052 // This tests that we won't crash if the remote track has been removed outside
2008 // of PeerConnection and then PeerConnection tries to reject the track. 2053 // of PeerConnection and then PeerConnection tries to reject the track.
2009 TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) { 2054 TEST_F(PeerConnectionInterfaceTest, RemoveTrackThenRejectMediaContent) {
2010 FakeConstraints constraints; 2055 FakeConstraints constraints;
2011 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, 2056 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
2012 true); 2057 true);
2013 CreatePeerConnection(&constraints); 2058 CreatePeerConnection(&constraints);
2014 CreateAndSetRemoteOffer(kSdpStringWithStream1); 2059 CreateAndSetRemoteOffer(kSdpStringWithStream1);
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
2691 FakeConstraints updated_answer_c; 2736 FakeConstraints updated_answer_c;
2692 answer_c.SetMandatoryReceiveAudio(false); 2737 answer_c.SetMandatoryReceiveAudio(false);
2693 answer_c.SetMandatoryReceiveVideo(false); 2738 answer_c.SetMandatoryReceiveVideo(false);
2694 2739
2695 cricket::MediaSessionOptions updated_answer_options; 2740 cricket::MediaSessionOptions updated_answer_options;
2696 EXPECT_TRUE( 2741 EXPECT_TRUE(
2697 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); 2742 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
2698 EXPECT_TRUE(updated_answer_options.has_audio()); 2743 EXPECT_TRUE(updated_answer_options.has_audio());
2699 EXPECT_TRUE(updated_answer_options.has_video()); 2744 EXPECT_TRUE(updated_answer_options.has_video());
2700 } 2745 }
OLDNEW
« no previous file with comments | « webrtc/api/peerconnection.cc ('k') | webrtc/api/rtpreceiver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698