Chromium Code Reviews| Index: content/browser/renderer_host/media/video_capture_host_unittest.cc |
| diff --git a/content/browser/renderer_host/media/video_capture_host_unittest.cc b/content/browser/renderer_host/media/video_capture_host_unittest.cc |
| index f7f31e66f2b251fd1d6d785c1e853eda91f2e6e1..4ecca4e1d1a3131b20182641b06d175cee8c41fc 100644 |
| --- a/content/browser/renderer_host/media/video_capture_host_unittest.cc |
| +++ b/content/browser/renderer_host/media/video_capture_host_unittest.cc |
| @@ -12,13 +12,14 @@ |
| #include "base/process_util.h" |
| #include "base/stl_util.h" |
| #include "base/stringprintf.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "base/test/test_timeouts.h" |
| #include "content/browser/browser_thread_impl.h" |
| #include "content/browser/renderer_host/media/media_stream_manager.h" |
| #include "content/browser/renderer_host/media/video_capture_host.h" |
| #include "content/browser/renderer_host/media/video_capture_manager.h" |
| #include "content/common/media/video_capture_messages.h" |
| #include "content/public/test/mock_resource_context.h" |
| -#include "media/audio/audio_manager.h" |
| #include "media/video/capture/video_capture_types.h" |
| #include "net/url_request/url_request_context.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| @@ -29,6 +30,7 @@ using ::testing::AtLeast; |
| using ::testing::AnyNumber; |
| using ::testing::DoAll; |
| using ::testing::InSequence; |
| +using ::testing::InvokeWithoutArgs; |
| using ::testing::Mock; |
| using ::testing::Return; |
| using content::BrowserThread; |
| @@ -71,9 +73,8 @@ class DumpVideo { |
| class MockVideoCaptureHost : public VideoCaptureHost { |
| public: |
| - MockVideoCaptureHost(content::ResourceContext* resource_context, |
| - media::AudioManager* audio_manager) |
| - : VideoCaptureHost(resource_context, audio_manager), |
| + MockVideoCaptureHost(content::ResourceContext* resource_context) |
|
mflodman_chromium_OOO
2012/06/29 14:46:04
Explicit.
no longer working on chromium
2012/07/02 08:40:49
Done.
|
| + : VideoCaptureHost(resource_context), |
| return_buffers_(false), |
| dump_video_(false) {} |
| @@ -208,14 +209,12 @@ class VideoCaptureHostTest : public testing::Test { |
| io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
| message_loop_.get())); |
| - audio_manager_.reset(media::AudioManager::Create()); |
| - |
| #ifndef TEST_REAL_CAPTURE_DEVICE |
| media_stream::MediaStreamManager::GetForResourceContext( |
| - &resource_context_, audio_manager_.get())->UseFakeDevice(); |
| + &resource_context_)->UseFakeDevice(); |
| #endif |
| - host_ = new MockVideoCaptureHost(&resource_context_, audio_manager_.get()); |
| + host_ = new MockVideoCaptureHost(&resource_context_); |
| // Simulate IPC channel connected. |
| host_->OnChannelConnected(base::GetCurrentProcId()); |
| @@ -238,36 +237,7 @@ class VideoCaptureHostTest : public testing::Test { |
| host_ = NULL; |
| // We need to continue running message_loop_ to complete all destructions. |
| - SyncWithVideoCaptureManagerThread(); |
| - } |
| - |
| - // Called on the VideoCaptureManager thread. |
| - static void PostQuitMessageLoop(MessageLoop* message_loop) { |
| - message_loop->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| - } |
| - |
| - // Called on the main thread. |
| - static void PostQuitOnVideoCaptureManagerThread( |
| - MessageLoop* message_loop, content::ResourceContext* resource_context, |
| - media:: AudioManager* audio_manager) { |
| - media_stream::MediaStreamManager* manager = |
| - media_stream::MediaStreamManager::GetForResourceContext( |
| - resource_context, audio_manager); |
| - manager->video_capture_manager()->GetMessageLoop()->PostTask( |
| - FROM_HERE, base::Bind(&PostQuitMessageLoop, message_loop)); |
| - } |
| - |
| - // SyncWithVideoCaptureManagerThread() waits until all pending tasks on the |
| - // video_capture_manager thread are executed while also processing pending |
| - // task in message_loop_ on the current thread. It is used to synchronize |
| - // with the video capture manager thread when we are stopping a video |
| - // capture device. |
| - void SyncWithVideoCaptureManagerThread() { |
| - message_loop_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&PostQuitOnVideoCaptureManagerThread, message_loop_.get(), |
| - &resource_context_, audio_manager_.get())); |
| - message_loop_->Run(); |
| + message_loop_->RunAllPending(); |
| } |
| void StartCapture() { |
| @@ -323,15 +293,17 @@ class VideoCaptureHostTest : public testing::Test { |
| } |
| void StopCapture() { |
| + base::WaitableEvent event(false, false); |
| EXPECT_CALL(*host_, OnStateChanged(kDeviceId, |
| video_capture::kStopped)) |
| - .Times(AtLeast(1)); |
| + .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); |
| host_->OnStopCapture(kDeviceId); |
| host_->SetReturnReceviedDibs(true); |
| host_->ReturnReceivedDibs(kDeviceId); |
| - SyncWithVideoCaptureManagerThread(); |
| + EXPECT_TRUE(event.TimedWait(TestTimeouts::action_timeout())); |
|
mflodman_chromium_OOO
2012/06/29 14:46:04
Not sure if there is a prefered Chromium way for t
no longer working on chromium
2012/07/02 08:40:49
Done.
|
| + |
| host_->SetReturnReceviedDibs(false); |
| // Expect the VideoCaptureDevice has been stopped |
| EXPECT_EQ(0u, host_->entries_.size()); |
| @@ -356,7 +328,8 @@ class VideoCaptureHostTest : public testing::Test { |
| .Times(1); |
| VideoCaptureControllerID id(kDeviceId); |
| host_->OnError(id); |
| - SyncWithVideoCaptureManagerThread(); |
| + // Wait for the error callback. |
| + message_loop_->RunAllPending(); |
| } |
| scoped_refptr<MockVideoCaptureHost> host_; |
| @@ -365,7 +338,6 @@ class VideoCaptureHostTest : public testing::Test { |
| scoped_ptr<MessageLoop> message_loop_; |
| scoped_ptr<BrowserThreadImpl> ui_thread_; |
| scoped_ptr<BrowserThreadImpl> io_thread_; |
| - scoped_ptr<media::AudioManager> audio_manager_; |
| content::MockResourceContext resource_context_; |
| DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest); |