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

Unified Diff: media/base/test_helpers.cc

Issue 11316293: Replace WaitableEvents and ConditionalVariables in VideoRendererBase tests with MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bustage Created 8 years 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
« no previous file with comments | « media/base/test_helpers.h ('k') | media/filters/audio_renderer_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/test_helpers.cc
diff --git a/media/base/test_helpers.cc b/media/base/test_helpers.cc
new file mode 100644
index 0000000000000000000000000000000000000000..862c9d45c55a04ce77c0b620211fe233827d2b05
--- /dev/null
+++ b/media/base/test_helpers.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/base/test_helpers.h"
+
+#include "base/bind.h"
+#include "base/message_loop.h"
+#include "base/test/test_timeouts.h"
+#include "base/timer.h"
+#include "media/base/bind_to_loop.h"
+
+using ::testing::_;
+using ::testing::StrictMock;
+
+namespace media {
+
+// Utility mock for testing methods expecting Closures and PipelineStatusCBs.
+class MockCallback : public base::RefCountedThreadSafe<MockCallback> {
+ public:
+ MockCallback();
+ MOCK_METHOD0(Run, void());
+ MOCK_METHOD1(RunWithStatus, void(PipelineStatus));
+
+ protected:
+ friend class base::RefCountedThreadSafe<MockCallback>;
+ virtual ~MockCallback();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockCallback);
+};
+
+MockCallback::MockCallback() {}
+MockCallback::~MockCallback() {}
+
+base::Closure NewExpectedClosure() {
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ EXPECT_CALL(*callback, Run());
+ return base::Bind(&MockCallback::Run, callback);
+}
+
+PipelineStatusCB NewExpectedStatusCB(PipelineStatus status) {
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ EXPECT_CALL(*callback, RunWithStatus(status));
+ return base::Bind(&MockCallback::RunWithStatus, callback);
+}
+
+WaitableMessageLoopEvent::WaitableMessageLoopEvent()
+ : message_loop_(MessageLoop::current()),
+ signaled_(false),
+ status_(PIPELINE_OK) {
+ DCHECK(message_loop_);
+}
+
+WaitableMessageLoopEvent::~WaitableMessageLoopEvent() {}
+
+base::Closure WaitableMessageLoopEvent::GetClosure() {
+ DCHECK_EQ(message_loop_, MessageLoop::current());
+ return BindToLoop(message_loop_->message_loop_proxy(), base::Bind(
+ &WaitableMessageLoopEvent::OnCallback, base::Unretained(this),
+ PIPELINE_OK));
+}
+
+PipelineStatusCB WaitableMessageLoopEvent::GetPipelineStatusCB() {
+ DCHECK_EQ(message_loop_, MessageLoop::current());
+ return BindToLoop(message_loop_->message_loop_proxy(), base::Bind(
+ &WaitableMessageLoopEvent::OnCallback, base::Unretained(this)));
+}
+
+void WaitableMessageLoopEvent::RunAndWait() {
+ RunAndWaitForStatus(PIPELINE_OK);
+}
+
+void WaitableMessageLoopEvent::RunAndWaitForStatus(PipelineStatus expected) {
+ DCHECK_EQ(message_loop_, MessageLoop::current());
+ base::Timer timer(false, false);
+ timer.Start(FROM_HERE, TestTimeouts::action_timeout(), base::Bind(
+ &WaitableMessageLoopEvent::OnTimeout, base::Unretained(this)));
+
+ DCHECK(!signaled_) << "Already signaled";
+ message_loop_->Run();
+ EXPECT_TRUE(signaled_);
+ EXPECT_EQ(expected, status_);
+}
+
+void WaitableMessageLoopEvent::OnCallback(PipelineStatus status) {
+ DCHECK_EQ(message_loop_, MessageLoop::current());
+ signaled_ = true;
+ status_ = status;
+ message_loop_->QuitWhenIdle();
+}
+
+void WaitableMessageLoopEvent::OnTimeout() {
+ DCHECK_EQ(message_loop_, MessageLoop::current());
+ ADD_FAILURE() << "Timed out waiting for message loop to quit";
+ message_loop_->QuitWhenIdle();
+}
+
+} // namespace media
« no previous file with comments | « media/base/test_helpers.h ('k') | media/filters/audio_renderer_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698