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

Side by Side Diff: talk/app/webrtc/mediastream_unittest.cc

Issue 1522903002: Add a 'remote' property to MediaSourceInterface. Also adding an implementation to the relevant sour… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Address comments Created 5 years 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 | « talk/app/webrtc/localaudiosource.h ('k') | talk/app/webrtc/mediastreaminterface.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 * libjingle 2 * libjingle
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 30 matching lines...) Expand all
41 static const char kAudioTrackId[] = "dummy_microphone_1"; 41 static const char kAudioTrackId[] = "dummy_microphone_1";
42 42
43 using rtc::scoped_refptr; 43 using rtc::scoped_refptr;
44 using ::testing::Exactly; 44 using ::testing::Exactly;
45 45
46 namespace webrtc { 46 namespace webrtc {
47 47
48 // Helper class to test Observer. 48 // Helper class to test Observer.
49 class MockObserver : public ObserverInterface { 49 class MockObserver : public ObserverInterface {
50 public: 50 public:
51 MockObserver() {} 51 explicit MockObserver(NotifierInterface* notifier) : notifier_(notifier) {
52 notifier_->RegisterObserver(this);
53 }
54
55 ~MockObserver() { Unregister(); }
56
57 void Unregister() {
58 if (notifier_) {
59 notifier_->UnregisterObserver(this);
60 notifier_ = nullptr;
61 }
62 }
52 63
53 MOCK_METHOD0(OnChanged, void()); 64 MOCK_METHOD0(OnChanged, void());
65
66 private:
67 NotifierInterface* notifier_;
54 }; 68 };
55 69
56 class MediaStreamTest: public testing::Test { 70 class MediaStreamTest: public testing::Test {
57 protected: 71 protected:
58 virtual void SetUp() { 72 virtual void SetUp() {
59 stream_ = MediaStream::Create(kStreamLabel1); 73 stream_ = MediaStream::Create(kStreamLabel1);
60 ASSERT_TRUE(stream_.get() != NULL); 74 ASSERT_TRUE(stream_.get() != NULL);
61 75
62 video_track_ = VideoTrack::Create(kVideoTrackId, NULL); 76 video_track_ = VideoTrack::Create(kVideoTrackId, NULL);
63 ASSERT_TRUE(video_track_.get() != NULL); 77 ASSERT_TRUE(video_track_.get() != NULL);
64 EXPECT_EQ(MediaStreamTrackInterface::kInitializing, video_track_->state()); 78 EXPECT_EQ(MediaStreamTrackInterface::kInitializing, video_track_->state());
65 79
66 audio_track_ = AudioTrack::Create(kAudioTrackId, NULL); 80 audio_track_ = AudioTrack::Create(kAudioTrackId, NULL);
67 81
68 ASSERT_TRUE(audio_track_.get() != NULL); 82 ASSERT_TRUE(audio_track_.get() != NULL);
69 EXPECT_EQ(MediaStreamTrackInterface::kInitializing, audio_track_->state()); 83 EXPECT_EQ(MediaStreamTrackInterface::kInitializing, audio_track_->state());
70 84
71 EXPECT_TRUE(stream_->AddTrack(video_track_)); 85 EXPECT_TRUE(stream_->AddTrack(video_track_));
72 EXPECT_FALSE(stream_->AddTrack(video_track_)); 86 EXPECT_FALSE(stream_->AddTrack(video_track_));
73 EXPECT_TRUE(stream_->AddTrack(audio_track_)); 87 EXPECT_TRUE(stream_->AddTrack(audio_track_));
74 EXPECT_FALSE(stream_->AddTrack(audio_track_)); 88 EXPECT_FALSE(stream_->AddTrack(audio_track_));
75 } 89 }
76 90
77 void ChangeTrack(MediaStreamTrackInterface* track) { 91 void ChangeTrack(MediaStreamTrackInterface* track) {
78 MockObserver observer; 92 MockObserver observer(track);
79 track->RegisterObserver(&observer);
80 93
81 EXPECT_CALL(observer, OnChanged()) 94 EXPECT_CALL(observer, OnChanged())
82 .Times(Exactly(1)); 95 .Times(Exactly(1));
83 track->set_enabled(false); 96 track->set_enabled(false);
84 EXPECT_FALSE(track->enabled()); 97 EXPECT_FALSE(track->enabled());
85 98
86 EXPECT_CALL(observer, OnChanged()) 99 EXPECT_CALL(observer, OnChanged())
87 .Times(Exactly(1)); 100 .Times(Exactly(1));
88 track->set_state(MediaStreamTrackInterface::kLive); 101 track->set_state(MediaStreamTrackInterface::kLive);
89 EXPECT_EQ(MediaStreamTrackInterface::kLive, track->state()); 102 EXPECT_EQ(MediaStreamTrackInterface::kLive, track->state());
(...skipping 30 matching lines...) Expand all
120 ASSERT_EQ(1u, stream_->GetAudioTracks().size()); 133 ASSERT_EQ(1u, stream_->GetAudioTracks().size());
121 EXPECT_TRUE(stream_->GetAudioTracks()[0].get() == audio_track.get()); 134 EXPECT_TRUE(stream_->GetAudioTracks()[0].get() == audio_track.get());
122 EXPECT_TRUE(stream_->FindAudioTrack(audio_track->id()).get() 135 EXPECT_TRUE(stream_->FindAudioTrack(audio_track->id()).get()
123 == audio_track.get()); 136 == audio_track.get());
124 audio_track = stream_->GetAudioTracks()[0]; 137 audio_track = stream_->GetAudioTracks()[0];
125 EXPECT_EQ(0, audio_track->id().compare(kAudioTrackId)); 138 EXPECT_EQ(0, audio_track->id().compare(kAudioTrackId));
126 EXPECT_TRUE(audio_track->enabled()); 139 EXPECT_TRUE(audio_track->enabled());
127 } 140 }
128 141
129 TEST_F(MediaStreamTest, RemoveTrack) { 142 TEST_F(MediaStreamTest, RemoveTrack) {
130 MockObserver observer; 143 MockObserver observer(stream_);
131 stream_->RegisterObserver(&observer);
132 144
133 EXPECT_CALL(observer, OnChanged()) 145 EXPECT_CALL(observer, OnChanged())
134 .Times(Exactly(2)); 146 .Times(Exactly(2));
135 147
136 EXPECT_TRUE(stream_->RemoveTrack(audio_track_)); 148 EXPECT_TRUE(stream_->RemoveTrack(audio_track_));
137 EXPECT_FALSE(stream_->RemoveTrack(audio_track_)); 149 EXPECT_FALSE(stream_->RemoveTrack(audio_track_));
138 EXPECT_EQ(0u, stream_->GetAudioTracks().size()); 150 EXPECT_EQ(0u, stream_->GetAudioTracks().size());
139 EXPECT_EQ(0u, stream_->GetAudioTracks().size()); 151 EXPECT_EQ(0u, stream_->GetAudioTracks().size());
140 152
141 EXPECT_TRUE(stream_->RemoveTrack(video_track_)); 153 EXPECT_TRUE(stream_->RemoveTrack(video_track_));
(...skipping 12 matching lines...) Expand all
154 ChangeTrack(video_track.get()); 166 ChangeTrack(video_track.get());
155 } 167 }
156 168
157 TEST_F(MediaStreamTest, ChangeAudioTrack) { 169 TEST_F(MediaStreamTest, ChangeAudioTrack) {
158 scoped_refptr<webrtc::AudioTrackInterface> audio_track( 170 scoped_refptr<webrtc::AudioTrackInterface> audio_track(
159 stream_->GetAudioTracks()[0]); 171 stream_->GetAudioTracks()[0]);
160 ChangeTrack(audio_track.get()); 172 ChangeTrack(audio_track.get());
161 } 173 }
162 174
163 } // namespace webrtc 175 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/localaudiosource.h ('k') | talk/app/webrtc/mediastreaminterface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698