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

Side by Side Diff: content/renderer/media/media_stream_impl_unittest.cc

Issue 12086092: Implement audio constraints for PeerConneciton API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove one spa Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "content/renderer/media/media_stream_extra_data.h" 8 #include "content/renderer/media/media_stream_extra_data.h"
9 #include "content/renderer/media/media_stream_impl.h" 9 #include "content/renderer/media/media_stream_impl.h"
10 #include "content/renderer/media/mock_media_stream_dependency_factory.h" 10 #include "content/renderer/media/mock_media_stream_dependency_factory.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 dependency_factory_.reset(new MockMediaStreamDependencyFactory()); 84 dependency_factory_.reset(new MockMediaStreamDependencyFactory());
85 ms_impl_.reset(new MediaStreamImplUnderTest(ms_dispatcher_.get(), 85 ms_impl_.reset(new MediaStreamImplUnderTest(ms_dispatcher_.get(),
86 vc_manager.get(), 86 vc_manager.get(),
87 dependency_factory_.get())); 87 dependency_factory_.get()));
88 } 88 }
89 89
90 WebKit::WebMediaStreamDescriptor RequestLocalMediaStream(bool audio, 90 WebKit::WebMediaStreamDescriptor RequestLocalMediaStream(bool audio,
91 bool video) { 91 bool video) {
92 ms_impl_->RequestUserMedia(audio, video); 92 ms_impl_->RequestUserMedia(audio, video);
93 FakeMediaStreamDispatcherComplete(); 93 FakeMediaStreamDispatcherComplete();
94 if (video) { 94 if (video)
95 // TODO(perkj): Only change the video source at the moment since audio 95 ChangeVideoSourceStateToLive();
96 // sources are not implemented. 96 if (audio)
97 ChangeSourceStateToLive(); 97 ChangeAudioSourceStateToLive();
98 } 98
99 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_SUCCEEDED, 99 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_SUCCEEDED,
100 ms_impl_->request_state()); 100 ms_impl_->request_state());
101 101
102 WebKit::WebMediaStreamDescriptor desc = ms_impl_->last_generated_stream(); 102 WebKit::WebMediaStreamDescriptor desc = ms_impl_->last_generated_stream();
103 content::MediaStreamExtraData* extra_data = 103 content::MediaStreamExtraData* extra_data =
104 static_cast<content::MediaStreamExtraData*>(desc.extraData()); 104 static_cast<content::MediaStreamExtraData*>(desc.extraData());
105 if (!extra_data || !extra_data->local_stream()) { 105 if (!extra_data || !extra_data->local_stream()) {
106 ADD_FAILURE(); 106 ADD_FAILURE();
107 return desc; 107 return desc;
108 } 108 }
(...skipping 10 matching lines...) Expand all
119 } 119 }
120 120
121 121
122 void FakeMediaStreamDispatcherComplete() { 122 void FakeMediaStreamDispatcherComplete() {
123 ms_impl_->OnStreamGenerated(ms_dispatcher_->request_id(), 123 ms_impl_->OnStreamGenerated(ms_dispatcher_->request_id(),
124 ms_dispatcher_->stream_label(), 124 ms_dispatcher_->stream_label(),
125 ms_dispatcher_->audio_array(), 125 ms_dispatcher_->audio_array(),
126 ms_dispatcher_->video_array()); 126 ms_dispatcher_->video_array());
127 } 127 }
128 128
129 void ChangeSourceStateToLive() { 129 void ChangeVideoSourceStateToLive() {
130 if (dependency_factory_->last_video_source() != NULL) { 130 if (dependency_factory_->last_video_source() != NULL) {
131 dependency_factory_->last_video_source()->SetLive(); 131 dependency_factory_->last_video_source()->SetLive();
132 } 132 }
133 } 133 }
134 134
135 void ChangeSourceStateToEnded() { 135 void ChangeAudioSourceStateToLive() {
136 if (dependency_factory_->last_audio_source() != NULL) {
137 dependency_factory_->last_audio_source()->SetLive();
138 }
139 }
140
141 void ChangeVideoSourceStateToEnded() {
136 if (dependency_factory_->last_video_source() != NULL) { 142 if (dependency_factory_->last_video_source() != NULL) {
137 dependency_factory_->last_video_source()->SetEnded(); 143 dependency_factory_->last_video_source()->SetEnded();
138 } 144 }
139 } 145 }
140 146
147 void ChangeAudioSourceStateToEnded() {
148 if (dependency_factory_->last_audio_source() != NULL) {
149 dependency_factory_->last_audio_source()->SetEnded();
150 }
151 }
152
141 protected: 153 protected:
142 scoped_ptr<MockMediaStreamDispatcher> ms_dispatcher_; 154 scoped_ptr<MockMediaStreamDispatcher> ms_dispatcher_;
143 scoped_ptr<MediaStreamImplUnderTest> ms_impl_; 155 scoped_ptr<MediaStreamImplUnderTest> ms_impl_;
144 scoped_ptr<MockMediaStreamDependencyFactory> dependency_factory_; 156 scoped_ptr<MockMediaStreamDependencyFactory> dependency_factory_;
145 }; 157 };
146 158
147 TEST_F(MediaStreamImplTest, LocalMediaStream) { 159 TEST_F(MediaStreamImplTest, LocalMediaStream) {
148 // Test a stream with both audio and video. 160 // Test a stream with both audio and video.
149 WebKit::WebMediaStreamDescriptor mixed_desc = RequestLocalMediaStream(true, 161 WebKit::WebMediaStreamDescriptor mixed_desc = RequestLocalMediaStream(true,
150 true); 162 true);
(...skipping 25 matching lines...) Expand all
176 // Test that the MediaStreams are deleted if the owning WebFrame is deleted. 188 // Test that the MediaStreams are deleted if the owning WebFrame is deleted.
177 // In the unit test the owning frame is NULL. 189 // In the unit test the owning frame is NULL.
178 ms_impl_->FrameWillClose(NULL); 190 ms_impl_->FrameWillClose(NULL);
179 EXPECT_EQ(3, ms_dispatcher_->stop_stream_counter()); 191 EXPECT_EQ(3, ms_dispatcher_->stop_stream_counter());
180 } 192 }
181 193
182 // This test what happens if a source to a MediaSteam fails to start. 194 // This test what happens if a source to a MediaSteam fails to start.
183 TEST_F(MediaStreamImplTest, MediaSourceFailToStart) { 195 TEST_F(MediaStreamImplTest, MediaSourceFailToStart) {
184 ms_impl_->RequestUserMedia(true, true); 196 ms_impl_->RequestUserMedia(true, true);
185 FakeMediaStreamDispatcherComplete(); 197 FakeMediaStreamDispatcherComplete();
186 ChangeSourceStateToEnded(); 198 ChangeVideoSourceStateToEnded();
199 ChangeAudioSourceStateToEnded();
187 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_FAILED, 200 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_FAILED,
188 ms_impl_->request_state()); 201 ms_impl_->request_state());
189 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 202 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
190 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter()); 203 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter());
191 } 204 }
192 205
193 // This test what happens if MediaStreamImpl is deleted while the sources of a 206 // This test what happens if MediaStreamImpl is deleted while the sources of a
194 // MediaStream is being started. 207 // MediaStream is being started.
195 TEST_F(MediaStreamImplTest, MediaStreamImplShutDown) { 208 TEST_F(MediaStreamImplTest, MediaStreamImplShutDown) {
196 ms_impl_->RequestUserMedia(true, true); 209 ms_impl_->RequestUserMedia(true, true);
197 FakeMediaStreamDispatcherComplete(); 210 FakeMediaStreamDispatcherComplete();
198 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 211 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
199 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE, 212 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE,
200 ms_impl_->request_state()); 213 ms_impl_->request_state());
201 ms_impl_.reset(); 214 ms_impl_.reset();
202 ChangeSourceStateToLive(); 215 ChangeAudioSourceStateToLive();
216 ChangeVideoSourceStateToLive();
203 } 217 }
204 218
205 // This test what happens if the WebFrame is closed while the MediaStream is 219 // This test what happens if the WebFrame is closed while the MediaStream is
206 // being generated by the MediaStreamDispatcher. 220 // being generated by the MediaStreamDispatcher.
207 TEST_F(MediaStreamImplTest, ReloadFrameWhileGeneratingStream) { 221 TEST_F(MediaStreamImplTest, ReloadFrameWhileGeneratingStream) {
208 ms_impl_->RequestUserMedia(true, true); 222 ms_impl_->RequestUserMedia(true, true);
209 ms_impl_->FrameWillClose(NULL); 223 ms_impl_->FrameWillClose(NULL);
210 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 224 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
211 EXPECT_EQ(0, ms_dispatcher_->stop_stream_counter()); 225 EXPECT_EQ(0, ms_dispatcher_->stop_stream_counter());
212 ChangeSourceStateToLive(); 226 ChangeAudioSourceStateToLive();
227 ChangeVideoSourceStateToLive();
213 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE, 228 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE,
214 ms_impl_->request_state()); 229 ms_impl_->request_state());
215 } 230 }
216 231
217 // This test what happens if the WebFrame is closed while the sources are being 232 // This test what happens if the WebFrame is closed while the sources are being
218 // started by MediaStreamDependencyFactory. 233 // started by MediaStreamDependencyFactory.
219 TEST_F(MediaStreamImplTest, ReloadFrameWhileGeneratingSources) { 234 TEST_F(MediaStreamImplTest, ReloadFrameWhileGeneratingSources) {
220 ms_impl_->RequestUserMedia(true, true); 235 ms_impl_->RequestUserMedia(true, true);
221 FakeMediaStreamDispatcherComplete(); 236 FakeMediaStreamDispatcherComplete();
222 EXPECT_EQ(0, ms_dispatcher_->stop_stream_counter()); 237 EXPECT_EQ(0, ms_dispatcher_->stop_stream_counter());
223 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 238 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
224 ms_impl_->FrameWillClose(NULL); 239 ms_impl_->FrameWillClose(NULL);
225 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter()); 240 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter());
226 ChangeSourceStateToLive(); 241 ChangeAudioSourceStateToLive();
242 ChangeVideoSourceStateToLive();
227 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE, 243 EXPECT_EQ(MediaStreamImplUnderTest::REQUEST_NOT_COMPLETE,
228 ms_impl_->request_state()); 244 ms_impl_->request_state());
229 } 245 }
230 246
231 // This test what happens if stop is called on a stream after the frame has 247 // This test what happens if stop is called on a stream after the frame has
232 // been reloaded. 248 // been reloaded.
233 TEST_F(MediaStreamImplTest, StopStreamAfterReload) { 249 TEST_F(MediaStreamImplTest, StopStreamAfterReload) {
234 WebKit::WebMediaStreamDescriptor mixed_desc = RequestLocalMediaStream(true, 250 WebKit::WebMediaStreamDescriptor mixed_desc = RequestLocalMediaStream(true,
235 true); 251 true);
236 EXPECT_EQ(0, ms_dispatcher_->stop_stream_counter()); 252 EXPECT_EQ(0, ms_dispatcher_->stop_stream_counter());
237 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 253 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
238 ms_impl_->FrameWillClose(NULL); 254 ms_impl_->FrameWillClose(NULL);
239 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter()); 255 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter());
240 ms_impl_->OnLocalMediaStreamStop(mixed_desc.label().utf8()); 256 ms_impl_->OnLocalMediaStreamStop(mixed_desc.label().utf8());
241 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter()); 257 EXPECT_EQ(1, ms_dispatcher_->stop_stream_counter());
242 } 258 }
243 259
244 } // namespace content 260 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698