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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/test_helpers.h ('k') | media/filters/audio_renderer_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "media/base/test_helpers.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "base/test/test_timeouts.h"
10 #include "base/timer.h"
11 #include "media/base/bind_to_loop.h"
12
13 using ::testing::_;
14 using ::testing::StrictMock;
15
16 namespace media {
17
18 // Utility mock for testing methods expecting Closures and PipelineStatusCBs.
19 class MockCallback : public base::RefCountedThreadSafe<MockCallback> {
20 public:
21 MockCallback();
22 MOCK_METHOD0(Run, void());
23 MOCK_METHOD1(RunWithStatus, void(PipelineStatus));
24
25 protected:
26 friend class base::RefCountedThreadSafe<MockCallback>;
27 virtual ~MockCallback();
28
29 private:
30 DISALLOW_COPY_AND_ASSIGN(MockCallback);
31 };
32
33 MockCallback::MockCallback() {}
34 MockCallback::~MockCallback() {}
35
36 base::Closure NewExpectedClosure() {
37 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
38 EXPECT_CALL(*callback, Run());
39 return base::Bind(&MockCallback::Run, callback);
40 }
41
42 PipelineStatusCB NewExpectedStatusCB(PipelineStatus status) {
43 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
44 EXPECT_CALL(*callback, RunWithStatus(status));
45 return base::Bind(&MockCallback::RunWithStatus, callback);
46 }
47
48 WaitableMessageLoopEvent::WaitableMessageLoopEvent()
49 : message_loop_(MessageLoop::current()),
50 signaled_(false),
51 status_(PIPELINE_OK) {
52 DCHECK(message_loop_);
53 }
54
55 WaitableMessageLoopEvent::~WaitableMessageLoopEvent() {}
56
57 base::Closure WaitableMessageLoopEvent::GetClosure() {
58 DCHECK_EQ(message_loop_, MessageLoop::current());
59 return BindToLoop(message_loop_->message_loop_proxy(), base::Bind(
60 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this),
61 PIPELINE_OK));
62 }
63
64 PipelineStatusCB WaitableMessageLoopEvent::GetPipelineStatusCB() {
65 DCHECK_EQ(message_loop_, MessageLoop::current());
66 return BindToLoop(message_loop_->message_loop_proxy(), base::Bind(
67 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this)));
68 }
69
70 void WaitableMessageLoopEvent::RunAndWait() {
71 RunAndWaitForStatus(PIPELINE_OK);
72 }
73
74 void WaitableMessageLoopEvent::RunAndWaitForStatus(PipelineStatus expected) {
75 DCHECK_EQ(message_loop_, MessageLoop::current());
76 base::Timer timer(false, false);
77 timer.Start(FROM_HERE, TestTimeouts::action_timeout(), base::Bind(
78 &WaitableMessageLoopEvent::OnTimeout, base::Unretained(this)));
79
80 DCHECK(!signaled_) << "Already signaled";
81 message_loop_->Run();
82 EXPECT_TRUE(signaled_);
83 EXPECT_EQ(expected, status_);
84 }
85
86 void WaitableMessageLoopEvent::OnCallback(PipelineStatus status) {
87 DCHECK_EQ(message_loop_, MessageLoop::current());
88 signaled_ = true;
89 status_ = status;
90 message_loop_->QuitWhenIdle();
91 }
92
93 void WaitableMessageLoopEvent::OnTimeout() {
94 DCHECK_EQ(message_loop_, MessageLoop::current());
95 ADD_FAILURE() << "Timed out waiting for message loop to quit";
96 message_loop_->QuitWhenIdle();
97 }
98
99 } // namespace media
OLDNEW
« 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