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

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

Issue 1383803003: content/renderer/media: Use collectAllGarbageForTesting in tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 video_track2->Stop(); 364 video_track2->Stop();
365 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 365 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
366 } 366 }
367 367
368 TEST_F(UserMediaClientImplTest, StopSourceWhenMediaStreamGoesOutOfScope) { 368 TEST_F(UserMediaClientImplTest, StopSourceWhenMediaStreamGoesOutOfScope) {
369 // Generate a stream with both audio and video. 369 // Generate a stream with both audio and video.
370 RequestLocalMediaStream(); 370 RequestLocalMediaStream();
371 // Makes sure the test itself don't hold a reference to the created 371 // Makes sure the test itself don't hold a reference to the created
372 // MediaStream. 372 // MediaStream.
373 used_media_impl_->ClearLastGeneratedStream(); 373 used_media_impl_->ClearLastGeneratedStream();
374 blink::WebHeap::collectGarbageForTesting(); 374 blink::WebHeap::collectAllGarbageForTesting();
375 375
376 // Expect the sources to be stopped when the MediaStream goes out of scope. 376 // Expect the sources to be stopped when the MediaStream goes out of scope.
377 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 377 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
378 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 378 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
379 } 379 }
380 380
381 // Test that the MediaStreams are deleted if the owning WebFrame is closing. 381 // Test that the MediaStreams are deleted if the owning WebFrame is closing.
382 // In the unit test the owning frame is NULL. 382 // In the unit test the owning frame is NULL.
383 TEST_F(UserMediaClientImplTest, FrameWillClose) { 383 TEST_F(UserMediaClientImplTest, FrameWillClose) {
384 // Test a stream with both audio and video. 384 // Test a stream with both audio and video.
385 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); 385 blink::WebMediaStream mixed_desc = RequestLocalMediaStream();
386 blink::WebMediaStream desc2 = RequestLocalMediaStream(); 386 blink::WebMediaStream desc2 = RequestLocalMediaStream();
387 used_media_impl_->FrameWillClose(); 387 used_media_impl_->FrameWillClose();
388 blink::WebHeap::collectAllGarbageForTesting();
388 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 389 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
389 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 390 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
390 } 391 }
391 392
392 // This test what happens if a video source to a MediaSteam fails to start. 393 // This test what happens if a video source to a MediaSteam fails to start.
393 TEST_F(UserMediaClientImplTest, MediaVideoSourceFailToStart) { 394 TEST_F(UserMediaClientImplTest, MediaVideoSourceFailToStart) {
394 used_media_impl_->RequestUserMedia(); 395 used_media_impl_->RequestUserMedia();
395 FakeMediaStreamDispatcherRequestUserMediaComplete(); 396 FakeMediaStreamDispatcherRequestUserMediaComplete();
396 FailToStartMockedVideoSource(); 397 FailToStartMockedVideoSource();
397 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED, 398 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED,
398 used_media_impl_->request_state()); 399 used_media_impl_->request_state());
399 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, 400 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
400 used_media_impl_->error_reason()); 401 used_media_impl_->error_reason());
401 blink::WebHeap::collectGarbageForTesting(); 402 blink::WebHeap::collectAllGarbageForTesting();
402 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 403 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
403 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 404 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
404 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 405 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
405 } 406 }
406 407
407 // This test what happens if an audio source fail to initialize. 408 // This test what happens if an audio source fail to initialize.
408 TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) { 409 TEST_F(UserMediaClientImplTest, MediaAudioSourceFailToInitialize) {
409 FailToCreateNextAudioCapturer(); 410 FailToCreateNextAudioCapturer();
410 used_media_impl_->RequestUserMedia(); 411 used_media_impl_->RequestUserMedia();
411 FakeMediaStreamDispatcherRequestUserMediaComplete(); 412 FakeMediaStreamDispatcherRequestUserMediaComplete();
412 StartMockedVideoSource(); 413 StartMockedVideoSource();
413 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED, 414 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_FAILED,
414 used_media_impl_->request_state()); 415 used_media_impl_->request_state());
415 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE, 416 EXPECT_EQ(MEDIA_DEVICE_TRACK_START_FAILURE,
416 used_media_impl_->error_reason()); 417 used_media_impl_->error_reason());
417 blink::WebHeap::collectGarbageForTesting(); 418 blink::WebHeap::collectAllGarbageForTesting();
418 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 419 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
419 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 420 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
420 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 421 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
421 } 422 }
422 423
423 // This test what happens if UserMediaClientImpl is deleted before a source has 424 // This test what happens if UserMediaClientImpl is deleted before a source has
424 // started. 425 // started.
425 TEST_F(UserMediaClientImplTest, MediaStreamImplShutDown) { 426 TEST_F(UserMediaClientImplTest, MediaStreamImplShutDown) {
426 used_media_impl_->RequestUserMedia(); 427 used_media_impl_->RequestUserMedia();
427 FakeMediaStreamDispatcherRequestUserMediaComplete(); 428 FakeMediaStreamDispatcherRequestUserMediaComplete();
(...skipping 27 matching lines...) Expand all
455 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_NOT_COMPLETE, 456 EXPECT_EQ(UserMediaClientImplUnderTest::REQUEST_NOT_COMPLETE,
456 used_media_impl_->request_state()); 457 used_media_impl_->request_state());
457 } 458 }
458 459
459 // This test what happens if stop is called on a track after the frame has 460 // This test what happens if stop is called on a track after the frame has
460 // been reloaded. 461 // been reloaded.
461 TEST_F(UserMediaClientImplTest, StopTrackAfterReload) { 462 TEST_F(UserMediaClientImplTest, StopTrackAfterReload) {
462 blink::WebMediaStream mixed_desc = RequestLocalMediaStream(); 463 blink::WebMediaStream mixed_desc = RequestLocalMediaStream();
463 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter()); 464 EXPECT_EQ(1, ms_dispatcher_->request_stream_counter());
464 used_media_impl_->FrameWillClose(); 465 used_media_impl_->FrameWillClose();
466 blink::WebHeap::collectAllGarbageForTesting();
465 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 467 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
466 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter()); 468 EXPECT_EQ(1, ms_dispatcher_->stop_video_device_counter());
467 469
468 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks; 470 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks;
469 mixed_desc.audioTracks(audio_tracks); 471 mixed_desc.audioTracks(audio_tracks);
470 MediaStreamTrack* audio_track = MediaStreamTrack::GetTrack(audio_tracks[0]); 472 MediaStreamTrack* audio_track = MediaStreamTrack::GetTrack(audio_tracks[0]);
471 audio_track->Stop(); 473 audio_track->Stop();
472 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter()); 474 EXPECT_EQ(1, ms_dispatcher_->stop_audio_device_counter());
473 475
474 blink::WebVector<blink::WebMediaStreamTrack> video_tracks; 476 blink::WebVector<blink::WebMediaStreamTrack> video_tracks;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 565
564 // Video input device environment facing. 566 // Video input device environment facing.
565 source = &used_media_impl_->last_sources()[3]; 567 source = &used_media_impl_->last_sources()[3];
566 EXPECT_FALSE(source->id().isEmpty()); 568 EXPECT_FALSE(source->id().isEmpty());
567 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind()); 569 EXPECT_EQ(blink::WebSourceInfo::SourceKindVideo, source->kind());
568 EXPECT_FALSE(source->label().isEmpty()); 570 EXPECT_FALSE(source->label().isEmpty());
569 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeEnvironment, source->facing()); 571 EXPECT_EQ(blink::WebSourceInfo::VideoFacingModeEnvironment, source->facing());
570 } 572 }
571 573
572 } // namespace content 574 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698