OLD | NEW |
---|---|
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 "media/base/test_helpers.h" | 5 #include "media/base/test_helpers.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/message_loop/message_loop.h" | |
13 #include "base/pickle.h" | 12 #include "base/pickle.h" |
14 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
15 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
16 #include "base/time/time.h" | 15 #include "base/time/time.h" |
17 #include "base/timer/timer.h" | 16 #include "base/timer/timer.h" |
18 #include "media/base/audio_buffer.h" | 17 #include "media/base/audio_buffer.h" |
19 #include "media/base/bind_to_current_loop.h" | 18 #include "media/base/bind_to_current_loop.h" |
20 #include "media/base/decoder_buffer.h" | 19 #include "media/base/decoder_buffer.h" |
21 #include "media/base/media_util.h" | 20 #include "media/base/media_util.h" |
22 #include "ui/gfx/geometry/rect.h" | 21 #include "ui/gfx/geometry/rect.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 PipelineStatusCB NewExpectedStatusCB(PipelineStatus status) { | 59 PipelineStatusCB NewExpectedStatusCB(PipelineStatus status) { |
61 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); | 60 StrictMock<MockCallback>* callback = new StrictMock<MockCallback>(); |
62 EXPECT_CALL(*callback, RunWithStatus(status)); | 61 EXPECT_CALL(*callback, RunWithStatus(status)); |
63 return base::Bind(&MockCallback::RunWithStatus, callback); | 62 return base::Bind(&MockCallback::RunWithStatus, callback); |
64 } | 63 } |
65 | 64 |
66 WaitableMessageLoopEvent::WaitableMessageLoopEvent() | 65 WaitableMessageLoopEvent::WaitableMessageLoopEvent() |
67 : WaitableMessageLoopEvent(TestTimeouts::action_timeout()) {} | 66 : WaitableMessageLoopEvent(TestTimeouts::action_timeout()) {} |
68 | 67 |
69 WaitableMessageLoopEvent::WaitableMessageLoopEvent(base::TimeDelta timeout) | 68 WaitableMessageLoopEvent::WaitableMessageLoopEvent(base::TimeDelta timeout) |
70 : message_loop_(base::MessageLoop::current()), | 69 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
71 signaled_(false), | 70 signaled_(false), |
72 status_(PIPELINE_OK), | 71 status_(PIPELINE_OK), |
73 timeout_(timeout) { | 72 timeout_(timeout) { |
74 DCHECK(message_loop_); | 73 DCHECK(!!task_runner_); |
chcunningham
2016/06/21 01:34:36
Is the !! needed?
fdoray
2016/06/29 15:44:31
no, removed it
| |
75 } | 74 } |
76 | 75 |
77 WaitableMessageLoopEvent::~WaitableMessageLoopEvent() {} | 76 WaitableMessageLoopEvent::~WaitableMessageLoopEvent() {} |
78 | 77 |
79 base::Closure WaitableMessageLoopEvent::GetClosure() { | 78 base::Closure WaitableMessageLoopEvent::GetClosure() { |
80 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 79 DCHECK(task_runner_->BelongsToCurrentThread()); |
81 return BindToCurrentLoop(base::Bind( | 80 return BindToCurrentLoop(base::Bind( |
82 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this), | 81 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this), |
83 PIPELINE_OK)); | 82 PIPELINE_OK)); |
84 } | 83 } |
85 | 84 |
86 PipelineStatusCB WaitableMessageLoopEvent::GetPipelineStatusCB() { | 85 PipelineStatusCB WaitableMessageLoopEvent::GetPipelineStatusCB() { |
87 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 86 DCHECK(task_runner_->BelongsToCurrentThread()); |
88 return BindToCurrentLoop(base::Bind( | 87 return BindToCurrentLoop(base::Bind( |
89 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this))); | 88 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this))); |
90 } | 89 } |
91 | 90 |
92 void WaitableMessageLoopEvent::RunAndWait() { | 91 void WaitableMessageLoopEvent::RunAndWait() { |
93 RunAndWaitForStatus(PIPELINE_OK); | 92 RunAndWaitForStatus(PIPELINE_OK); |
94 } | 93 } |
95 | 94 |
96 void WaitableMessageLoopEvent::RunAndWaitForStatus(PipelineStatus expected) { | 95 void WaitableMessageLoopEvent::RunAndWaitForStatus(PipelineStatus expected) { |
97 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 96 DCHECK(task_runner_->BelongsToCurrentThread()); |
98 if (signaled_) { | 97 if (signaled_) { |
99 EXPECT_EQ(expected, status_); | 98 EXPECT_EQ(expected, status_); |
100 return; | 99 return; |
101 } | 100 } |
102 | 101 |
103 run_loop_.reset(new base::RunLoop()); | 102 run_loop_.reset(new base::RunLoop()); |
104 base::Timer timer(false, false); | 103 base::Timer timer(false, false); |
105 timer.Start( | 104 timer.Start( |
106 FROM_HERE, timeout_, | 105 FROM_HERE, timeout_, |
107 base::Bind(&WaitableMessageLoopEvent::OnTimeout, base::Unretained(this))); | 106 base::Bind(&WaitableMessageLoopEvent::OnTimeout, base::Unretained(this))); |
108 | 107 |
109 run_loop_->Run(); | 108 run_loop_->Run(); |
110 EXPECT_TRUE(signaled_); | 109 EXPECT_TRUE(signaled_); |
111 EXPECT_EQ(expected, status_); | 110 EXPECT_EQ(expected, status_); |
112 run_loop_.reset(); | 111 run_loop_.reset(); |
113 } | 112 } |
114 | 113 |
115 void WaitableMessageLoopEvent::OnCallback(PipelineStatus status) { | 114 void WaitableMessageLoopEvent::OnCallback(PipelineStatus status) { |
116 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 115 DCHECK(task_runner_->BelongsToCurrentThread()); |
117 signaled_ = true; | 116 signaled_ = true; |
118 status_ = status; | 117 status_ = status; |
119 | 118 |
120 // |run_loop_| may be null if the callback fires before RunAndWaitForStatus(). | 119 // |run_loop_| may be null if the callback fires before RunAndWaitForStatus(). |
121 if (run_loop_) | 120 if (run_loop_) |
122 run_loop_->Quit(); | 121 run_loop_->Quit(); |
123 } | 122 } |
124 | 123 |
125 void WaitableMessageLoopEvent::OnTimeout() { | 124 void WaitableMessageLoopEvent::OnTimeout() { |
126 DCHECK_EQ(message_loop_, base::MessageLoop::current()); | 125 DCHECK(task_runner_->BelongsToCurrentThread()); |
127 ADD_FAILURE() << "Timed out waiting for message loop to quit"; | 126 ADD_FAILURE() << "Timed out waiting for message loop to quit"; |
128 run_loop_->Quit(); | 127 run_loop_->Quit(); |
129 } | 128 } |
130 | 129 |
131 static VideoDecoderConfig GetTestConfig(VideoCodec codec, | 130 static VideoDecoderConfig GetTestConfig(VideoCodec codec, |
132 gfx::Size coded_size, | 131 gfx::Size coded_size, |
133 bool is_encrypted) { | 132 bool is_encrypted) { |
134 gfx::Rect visible_rect(coded_size.width(), coded_size.height()); | 133 gfx::Rect visible_rect(coded_size.width(), coded_size.height()); |
135 gfx::Size natural_size = coded_size; | 134 gfx::Size natural_size = coded_size; |
136 | 135 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
275 int width = 0; | 274 int width = 0; |
276 int height = 0; | 275 int height = 0; |
277 bool success = pickle.ReadString(&header) && pickle.ReadInt(&width) && | 276 bool success = pickle.ReadString(&header) && pickle.ReadInt(&width) && |
278 pickle.ReadInt(&height); | 277 pickle.ReadInt(&height); |
279 return (success && header == kFakeVideoBufferHeader && | 278 return (success && header == kFakeVideoBufferHeader && |
280 width == config.coded_size().width() && | 279 width == config.coded_size().width() && |
281 height == config.coded_size().height()); | 280 height == config.coded_size().height()); |
282 } | 281 } |
283 | 282 |
284 } // namespace media | 283 } // namespace media |
OLD | NEW |