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

Unified Diff: content/browser/renderer_host/media/video_capture_host_unittest.cc

Issue 17444005: Remove MediaStreamDeviceThread in favor of using AudioThread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix one more test. Created 7 years, 6 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 side-by-side diff with in-line comments
Download patch
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 2dcabe56aa3823fad18e43e90de6b55d67b77225..1d8c79a77370b9e0fc325f819de30a75680107d1 100644
--- a/content/browser/renderer_host/media/video_capture_host_unittest.cc
+++ b/content/browser/renderer_host/media/video_capture_host_unittest.cc
@@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/process_util.h"
+#include "base/run_loop.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "content/browser/browser_thread_impl.h"
@@ -18,6 +19,7 @@
#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 "content/public/test/test_browser_thread_bundle.h"
#include "media/audio/audio_manager.h"
#include "media/video/capture/video_capture_types.h"
#include "net/url_request/url_request_context.h"
@@ -184,23 +186,15 @@ class MockVideoCaptureHost : public VideoCaptureHost {
DumpVideo dumper_;
};
-ACTION_P(ExitMessageLoop, message_loop) {
- message_loop->PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
+ACTION_P2(ExitMessageLoop, message_loop, quit_closure) {
+ message_loop->PostTask(FROM_HERE, quit_closure);
}
class VideoCaptureHostTest : public testing::Test {
public:
- VideoCaptureHostTest() {}
-
- protected:
- virtual void SetUp() OVERRIDE {
- // Create a message loop so VideoCaptureHostTest can use it.
- message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_IO));
-
- // MediaStreamManager must be created on the IO thread.
- io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO,
- message_loop_.get()));
-
+ VideoCaptureHostTest()
+ : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
+ message_loop_(base::MessageLoopProxy::current()) {
// Create our own MediaStreamManager.
audio_manager_.reset(media::AudioManager::Create());
media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
@@ -214,7 +208,7 @@ class VideoCaptureHostTest : public testing::Test {
host_->OnChannelConnected(base::GetCurrentProcId());
}
- virtual void TearDown() OVERRIDE {
+ virtual ~VideoCaptureHostTest() {
// Verifies and removes the expectations on host_ and
// returns true iff successful.
Mock::VerifyAndClearExpectations(host_.get());
@@ -227,17 +221,11 @@ class VideoCaptureHostTest : public testing::Test {
host_->OnChannelClosing();
// Release the reference to the mock object. The object will be destructed
- // on message_loop_.
+ // on the current message loop.
host_ = NULL;
-
- // We need to continue running message_loop_ to complete all destructions.
- message_loop_->RunUntilIdle();
-
- // Delete the IO message loop. This will cause the MediaStreamManager to be
- // notified so it will stop its device thread and device managers.
- message_loop_.reset();
}
+ protected:
void StartCapture() {
InSequence s;
// 1. First - get info about the new resolution
@@ -252,8 +240,10 @@ class VideoCaptureHostTest : public testing::Test {
.Times(AnyNumber()).WillRepeatedly(Return());
// 4. First filled buffer will arrive.
+ base::RunLoop run_loop;
EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _))
- .Times(AnyNumber()).WillOnce(ExitMessageLoop(message_loop_.get()));
+ .Times(AnyNumber()).WillOnce(ExitMessageLoop(
+ message_loop_, run_loop.QuitClosure()));
media::VideoCaptureParams params;
params.width = 352;
@@ -261,7 +251,7 @@ class VideoCaptureHostTest : public testing::Test {
params.frame_per_second = 30;
params.session_id = kTestFakeDeviceId;
host_->OnStartCapture(kDeviceId, params);
- message_loop_->Run();
+ run_loop.Run();
}
#ifdef DUMP_VIDEO
@@ -274,9 +264,10 @@ class VideoCaptureHostTest : public testing::Test {
EXPECT_CALL(*host_, OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STARTED));
// 3. First filled buffer will arrive.
+ base::RunLoop run_loop;
EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _))
.Times(AnyNumber())
- .WillOnce(ExitMessageLoop(message_loop_.get()));
+ .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure()));
media::VideoCaptureParams params;
params.width = width;
@@ -285,20 +276,21 @@ class VideoCaptureHostTest : public testing::Test {
params.session_id = kTestFakeDeviceId;
host_->SetDumpVideo(true);
host_->OnStartCapture(kDeviceId, params);
- message_loop_->Run();
+ run_loop.Run();
}
#endif
void StopCapture() {
+ base::RunLoop run_loop;
EXPECT_CALL(*host_.get(),
OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED))
- .WillOnce(ExitMessageLoop(message_loop_.get()));
+ .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure()));
host_->OnStopCapture(kDeviceId);
host_->SetReturnReceviedDibs(true);
host_->ReturnReceivedDibs(kDeviceId);
- message_loop_->Run();
+ run_loop.Run();
host_->SetReturnReceviedDibs(false);
// Expect the VideoCaptureDevice has been stopped
@@ -306,10 +298,12 @@ class VideoCaptureHostTest : public testing::Test {
}
void NotifyPacketReady() {
+ base::RunLoop run_loop;
EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _))
- .Times(AnyNumber()).WillOnce(ExitMessageLoop(message_loop_.get()))
+ .Times(AnyNumber()).WillOnce(ExitMessageLoop(
+ message_loop_, run_loop.QuitClosure()))
.RetiresOnSaturation();
- message_loop_->Run();
+ run_loop.Run();
}
void ReturnReceivedPackets() {
@@ -323,16 +317,16 @@ class VideoCaptureHostTest : public testing::Test {
VideoCaptureControllerID id(kDeviceId);
host_->OnError(id);
// Wait for the error callback.
- message_loop_->RunUntilIdle();
+ base::RunLoop().RunUntilIdle();
}
scoped_refptr<MockVideoCaptureHost> host_;
private:
- scoped_ptr<base::MessageLoop> message_loop_;
- scoped_ptr<BrowserThreadImpl> io_thread_;
scoped_ptr<media::AudioManager> audio_manager_;
scoped_ptr<MediaStreamManager> media_stream_manager_;
+ content::TestBrowserThreadBundle thread_bundle_;
+ scoped_refptr<base::MessageLoopProxy> message_loop_;
DISALLOW_COPY_AND_ASSIGN(VideoCaptureHostTest);
};

Powered by Google App Engine
This is Rietveld 408576698