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

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: 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
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());
1873 rtc::Thread::Current()->ProcessMessages(
1874 0); // Audio source state changes are posted.
1846 EXPECT_EQ(MediaStreamTrackInterface::kEnded, 1875 EXPECT_EQ(MediaStreamTrackInterface::kEnded,
1847 remote_stream->GetAudioTracks()[0]->state()); 1876 remote_stream->GetAudioTracks()[0]->state());
1848 } 1877 }
1849 1878
1850 // Test that PeerConnection methods fails gracefully after 1879 // Test that PeerConnection methods fails gracefully after
1851 // PeerConnection::Close has been called. 1880 // PeerConnection::Close has been called.
1852 TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) { 1881 TEST_F(PeerConnectionInterfaceTest, CloseAndTestMethods) {
1853 CreatePeerConnection(); 1882 CreatePeerConnection();
1854 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label"); 1883 AddAudioVideoStream(kStreamLabel1, "audio_label", "video_label");
1855 CreateOfferAsRemoteDescription(); 1884 CreateOfferAsRemoteDescription();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release())); 1971 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1.release()));
1943 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), 1972 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
1944 reference_collection_)); 1973 reference_collection_));
1945 1974
1946 // Add extra audio and video tracks to the same MediaStream. 1975 // Add extra audio and video tracks to the same MediaStream.
1947 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1_two_tracks = 1976 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms1_two_tracks =
1948 CreateSessionDescriptionAndReference(2, 2); 1977 CreateSessionDescriptionAndReference(2, 2);
1949 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release())); 1978 EXPECT_TRUE(DoSetRemoteDescription(desc_ms1_two_tracks.release()));
1950 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), 1979 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
1951 reference_collection_)); 1980 reference_collection_));
1981 scoped_refptr<AudioTrackInterface> audio_track2 =
1982 observer_.remote_streams()->at(0)->GetAudioTracks()[1];
1983 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, audio_track2->state());
1984 scoped_refptr<VideoTrackInterface> video_track2 =
1985 observer_.remote_streams()->at(0)->GetVideoTracks()[1];
1986 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track2->state());
1952 1987
1953 // Remove the extra audio and video tracks. 1988 // Remove the extra audio and video tracks.
1954 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms2 = 1989 rtc::scoped_ptr<SessionDescriptionInterface> desc_ms2 =
1955 CreateSessionDescriptionAndReference(1, 1); 1990 CreateSessionDescriptionAndReference(1, 1);
1991 MockTrackObserver audio_track_observer(audio_track2);
1992 MockTrackObserver video_track_observer(video_track2);
1993
1994 EXPECT_CALL(audio_track_observer, OnChanged()).Times(Exactly(1));
1995 EXPECT_CALL(video_track_observer, OnChanged()).Times(Exactly(1));
1956 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release())); 1996 EXPECT_TRUE(DoSetRemoteDescription(desc_ms2.release()));
1957 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(), 1997 EXPECT_TRUE(CompareStreamCollections(observer_.remote_streams(),
1958 reference_collection_)); 1998 reference_collection_));
1999 rtc::Thread::Current()->ProcessMessages(
2000 0); // Audio source state changes are posted.
2001 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, audio_track2->state());
2002 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, video_track2->state());
1959 } 2003 }
1960 2004
1961 // This tests that remote tracks are ended if a local session description is set 2005 // This tests that remote tracks are ended if a local session description is set
1962 // that rejects the media content type. 2006 // that rejects the media content type.
1963 TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) { 2007 TEST_F(PeerConnectionInterfaceTest, RejectMediaContent) {
1964 FakeConstraints constraints; 2008 FakeConstraints constraints;
1965 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, 2009 constraints.AddMandatory(webrtc::MediaConstraintsInterface::kEnableDtlsSrtp,
1966 true); 2010 true);
1967 CreatePeerConnection(&constraints); 2011 CreatePeerConnection(&constraints);
1968 // First create and set a remote offer, then reject its video content in our 2012 // First create and set a remote offer, then reject its video content in our
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
2691 FakeConstraints updated_answer_c; 2735 FakeConstraints updated_answer_c;
2692 answer_c.SetMandatoryReceiveAudio(false); 2736 answer_c.SetMandatoryReceiveAudio(false);
2693 answer_c.SetMandatoryReceiveVideo(false); 2737 answer_c.SetMandatoryReceiveVideo(false);
2694 2738
2695 cricket::MediaSessionOptions updated_answer_options; 2739 cricket::MediaSessionOptions updated_answer_options;
2696 EXPECT_TRUE( 2740 EXPECT_TRUE(
2697 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options)); 2741 ParseConstraintsForAnswer(&updated_answer_c, &updated_answer_options));
2698 EXPECT_TRUE(updated_answer_options.has_audio()); 2742 EXPECT_TRUE(updated_answer_options.has_audio());
2699 EXPECT_TRUE(updated_answer_options.has_video()); 2743 EXPECT_TRUE(updated_answer_options.has_video());
2700 } 2744 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698