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

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

Issue 549153002: MediaStream tests need to call WebHeap::collectGarbage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 // 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/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "content/child/child_process.h" 8 #include "content/child/child_process.h"
9 #include "content/renderer/media/media_stream.h" 9 #include "content/renderer/media/media_stream.h"
10 #include "content/renderer/media/media_stream_track.h" 10 #include "content/renderer/media/media_stream_track.h"
11 #include "content/renderer/media/mock_media_stream_dispatcher.h" 11 #include "content/renderer/media/mock_media_stream_dispatcher.h"
12 #include "content/renderer/media/mock_media_stream_video_source.h" 12 #include "content/renderer/media/mock_media_stream_video_source.h"
13 #include "content/renderer/media/user_media_client_impl.h" 13 #include "content/renderer/media/user_media_client_impl.h"
14 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h" 14 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" 16 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h"
17 #include "third_party/WebKit/public/platform/WebMediaStream.h" 17 #include "third_party/WebKit/public/platform/WebMediaStream.h"
18 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 18 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
19 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 19 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
20 #include "third_party/WebKit/public/platform/WebString.h" 20 #include "third_party/WebKit/public/platform/WebString.h"
21 #include "third_party/WebKit/public/platform/WebVector.h" 21 #include "third_party/WebKit/public/platform/WebVector.h"
22 #include "third_party/WebKit/public/web/WebHeap.h"
22 23
23 namespace content { 24 namespace content {
24 25
25 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource { 26 class MockMediaStreamVideoCapturerSource : public MockMediaStreamVideoSource {
26 public: 27 public:
27 MockMediaStreamVideoCapturerSource( 28 MockMediaStreamVideoCapturerSource(
28 const StreamDeviceInfo& device, 29 const StreamDeviceInfo& device,
29 const SourceStoppedCallback& stop_callback, 30 const SourceStoppedCallback& stop_callback,
30 PeerConnectionDependencyFactory* factory) 31 PeerConnectionDependencyFactory* factory)
31 : MockMediaStreamVideoSource(false) { 32 : MockMediaStreamVideoSource(false) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 virtual void SetUp() { 144 virtual void SetUp() {
144 // Create our test object. 145 // Create our test object.
145 child_process_.reset(new ChildProcess()); 146 child_process_.reset(new ChildProcess());
146 dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); 147 dependency_factory_.reset(new MockPeerConnectionDependencyFactory());
147 ms_dispatcher_ = new MockMediaStreamDispatcher(); 148 ms_dispatcher_ = new MockMediaStreamDispatcher();
148 used_media_impl_.reset(new UserMediaClientImplUnderTest( 149 used_media_impl_.reset(new UserMediaClientImplUnderTest(
149 dependency_factory_.get(), 150 dependency_factory_.get(),
150 scoped_ptr<MediaStreamDispatcher>(ms_dispatcher_).Pass())); 151 scoped_ptr<MediaStreamDispatcher>(ms_dispatcher_).Pass()));
151 } 152 }
152 153
154 virtual void TearDown() OVERRIDE {
155 used_media_impl_.reset();
156 blink::WebHeap::collectAllGarbageForTesting();
157 }
158
153 blink::WebMediaStream RequestLocalMediaStream() { 159 blink::WebMediaStream RequestLocalMediaStream() {
154 used_media_impl_->RequestUserMedia(); 160 used_media_impl_->RequestUserMedia();
155 FakeMediaStreamDispatcherRequestUserMediaComplete(); 161 FakeMediaStreamDispatcherRequestUserMediaComplete();
156 StartMockedVideoSource(); 162 StartMockedVideoSource();
157 163
158 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED, 164 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_SUCCEEDED,
159 used_media_impl_->request_state()); 165 used_media_impl_->request_state());
160 166
161 blink::WebMediaStream desc = used_media_impl_->last_generated_stream(); 167 blink::WebMediaStream desc = used_media_impl_->last_generated_stream();
162 content::MediaStream* native_stream = 168 content::MediaStream* native_stream =
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 used_media_impl_->last_created_video_source(); 209 used_media_impl_->last_created_video_source();
204 if (video_source->SourceHasAttemptedToStart()) 210 if (video_source->SourceHasAttemptedToStart())
205 video_source->StartMockedSource(); 211 video_source->StartMockedSource();
206 } 212 }
207 213
208 void FailToStartMockedVideoSource() { 214 void FailToStartMockedVideoSource() {
209 MockMediaStreamVideoCapturerSource* video_source = 215 MockMediaStreamVideoCapturerSource* video_source =
210 used_media_impl_->last_created_video_source(); 216 used_media_impl_->last_created_video_source();
211 if (video_source->SourceHasAttemptedToStart()) 217 if (video_source->SourceHasAttemptedToStart())
212 video_source->FailToStartMockedSource(); 218 video_source->FailToStartMockedSource();
219 blink::WebHeap::collectGarbageForTesting();
213 } 220 }
214 221
215 void FailToCreateNextAudioCapturer() { 222 void FailToCreateNextAudioCapturer() {
216 dependency_factory_->FailToCreateNextAudioCapturer(); 223 dependency_factory_->FailToCreateNextAudioCapturer();
224 blink::WebHeap::collectGarbageForTesting();
217 } 225 }
218 226
219 protected: 227 protected:
220 base::MessageLoop message_loop_; 228 base::MessageLoop message_loop_;
221 scoped_ptr<ChildProcess> child_process_; 229 scoped_ptr<ChildProcess> child_process_;
222 MockMediaStreamDispatcher* ms_dispatcher_; // Owned by |used_media_impl_|. 230 MockMediaStreamDispatcher* ms_dispatcher_; // Owned by |used_media_impl_|.
223 scoped_ptr<UserMediaClientImplUnderTest> used_media_impl_; 231 scoped_ptr<UserMediaClientImplUnderTest> used_media_impl_;
224 scoped_ptr<MockPeerConnectionDependencyFactory> dependency_factory_; 232 scoped_ptr<MockPeerConnectionDependencyFactory> dependency_factory_;
225 }; 233 };
226 234
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 video_track2->Stop(); 344 video_track2->Stop();
337 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 345 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
338 } 346 }
339 347
340 TEST_F(UserMediaClientImplTest, StopSourceWhenMediaStreamGoesOutOfScope) { 348 TEST_F(UserMediaClientImplTest, StopSourceWhenMediaStreamGoesOutOfScope) {
341 // Generate a stream with both audio and video. 349 // Generate a stream with both audio and video.
342 RequestLocalMediaStream(); 350 RequestLocalMediaStream();
343 // Makes sure the test itself don't hold a reference to the created 351 // Makes sure the test itself don't hold a reference to the created
344 // MediaStream. 352 // MediaStream.
345 used_media_impl_->ClearLastGeneratedStream(); 353 used_media_impl_->ClearLastGeneratedStream();
354 blink::WebHeap::collectGarbageForTesting();
346 355
347 // Expect the sources to be stopped when the MediaStream goes out of scope. 356 // Expect the sources to be stopped when the MediaStream goes out of scope.
348 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 357 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
349 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 358 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
350 } 359 }
351 360
352 // Test that the MediaStreams are deleted if the owning WebFrame is closing. 361 // Test that the MediaStreams are deleted if the owning WebFrame is closing.
353 // In the unit test the owning frame is NULL. 362 // In the unit test the owning frame is NULL.
354 TEST_F(UserMediaClientImplTest, FrameWillClose) { 363 TEST_F(UserMediaClientImplTest, FrameWillClose) {
355 // Test a stream with both audio and video. 364 // Test a stream with both audio and video.
356 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); 365 blink::WebMediaStream mixed_desc = RequestLocalMediaStream();
357 blink::WebMediaStream desc2 = RequestLocalMediaStream(); 366 blink::WebMediaStream desc2 = RequestLocalMediaStream();
358 used_media_impl_->FrameWillClose(); 367 used_media_impl_->FrameWillClose();
359 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 368 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
360 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 369 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
361 } 370 }
362 371
363 // This test what happens if a video source to a MediaSteam fails to start. 372 // This test what happens if a video source to a MediaSteam fails to start.
364 TEST_F(UserMediaClientImplTest, MediaVideoSourceFailToStart) { 373 TEST_F(UserMediaClientImplTest, MediaVideoSourceFailToStart) {
365 used_media_impl_->RequestUserMedia(); 374 used_media_impl_->RequestUserMedia();
366 FakeMediaStreamDispatcherRequestUserMediaComplete(); 375 FakeMediaStreamDispatcherRequestUserMediaComplete();
367 FailToStartMockedVideoSource(); 376 FailToStartMockedVideoSource();
368 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED, 377 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED,
369 used_media_impl_->request_state()); 378 used_media_impl_->request_state());
370 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, 379 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
371 used_media_impl_->error_reason()); 380 used_media_impl_->error_reason());
381 blink::WebHeap::collectGarbageForTesting();
372 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 382 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
373 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 383 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
374 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 384 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
375 } 385 }
376 386
377 // This test what happens if an audio source fail to initialize. 387 // This test what happens if an audio source fail to initialize.
378 TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) { 388 TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) {
379 FailToCreateNextAudioCapturer(); 389 FailToCreateNextAudioCapturer();
380 used_media_impl_->RequestUserMedia(); 390 used_media_impl_->RequestUserMedia();
381 FakeMediaStreamDispatcherRequestUserMediaComplete(); 391 FakeMediaStreamDispatcherRequestUserMediaComplete();
382 StartMockedVideoSource(); 392 StartMockedVideoSource();
383 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED, 393 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED,
384 used_media_impl_->request_state()); 394 used_media_impl_->request_state());
385 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, 395 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
386 used_media_impl_->error_reason()); 396 used_media_impl_->error_reason());
397 blink::WebHeap::collectGarbageForTesting();
387 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 398 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
388 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 399 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
389 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 400 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
390 } 401 }
391 402
392 // This test what happens if UserMediaClientImpl is deleted before a source has 403 // This test what happens if UserMediaClientImpl is deleted before a source has
393 // started. 404 // started.
394 TEST_F(UserMediaClientImplTest, MediaStreamImplShutDown) { 405 TEST_F(UserMediaClientImplTest, MediaStreamImplShutDown) {
395 used_media_impl_->RequestUserMedia(); 406 used_media_impl_->RequestUserMedia();
396 FakeMediaStreamDispatcherRequestUserMediaComplete(); 407 FakeMediaStreamDispatcherRequestUserMediaComplete();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 EXPECT_FALSE(used_media_impl_->last_devices()[3].groupId().isEmpty()); 494 EXPECT_FALSE(used_media_impl_->last_devices()[3].groupId().isEmpty());
484 495
485 // Verfify group IDs. 496 // Verfify group IDs.
486 EXPECT_TRUE(used_media_impl_->last_devices()[0].groupId().equals( 497 EXPECT_TRUE(used_media_impl_->last_devices()[0].groupId().equals(
487 used_media_impl_->last_devices()[3].groupId())); 498 used_media_impl_->last_devices()[3].groupId()));
488 EXPECT_FALSE(used_media_impl_->last_devices()[1].groupId().equals( 499 EXPECT_FALSE(used_media_impl_->last_devices()[1].groupId().equals(
489 used_media_impl_->last_devices()[3].groupId())); 500 used_media_impl_->last_devices()[3].groupId()));
490 } 501 }
491 502
492 } // namespace content 503 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698