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

Side by Side Diff: media/base/test_helpers.cc

Issue 2076423004: Remove calls to MessageLoop::current() in media. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add missing include Created 4 years, 5 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 unified diff | Download patch
OLDNEW
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
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 : signaled_(false), status_(PIPELINE_OK), timeout_(timeout) {
71 signaled_(false), 70 DCHECK(CalledOnValidThread());
chcunningham 2016/06/29 18:10:04 This is sort of tautological right? Thread checker
fdoray 2016/06/29 18:20:17 Done. Removed it, you're right.
72 status_(PIPELINE_OK),
73 timeout_(timeout) {
74 DCHECK(message_loop_);
75 } 71 }
76 72
77 WaitableMessageLoopEvent::~WaitableMessageLoopEvent() {} 73 WaitableMessageLoopEvent::~WaitableMessageLoopEvent() {
74 DCHECK(CalledOnValidThread());
75 }
78 76
79 base::Closure WaitableMessageLoopEvent::GetClosure() { 77 base::Closure WaitableMessageLoopEvent::GetClosure() {
80 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 78 DCHECK(CalledOnValidThread());
81 return BindToCurrentLoop(base::Bind( 79 return BindToCurrentLoop(base::Bind(
82 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this), 80 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this),
83 PIPELINE_OK)); 81 PIPELINE_OK));
84 } 82 }
85 83
86 PipelineStatusCB WaitableMessageLoopEvent::GetPipelineStatusCB() { 84 PipelineStatusCB WaitableMessageLoopEvent::GetPipelineStatusCB() {
87 DCHECK_EQ(message_loop_, base::MessageLoop::current()); 85 DCHECK(CalledOnValidThread());
88 return BindToCurrentLoop(base::Bind( 86 return BindToCurrentLoop(base::Bind(
89 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this))); 87 &WaitableMessageLoopEvent::OnCallback, base::Unretained(this)));
90 } 88 }
91 89
92 void WaitableMessageLoopEvent::RunAndWait() { 90 void WaitableMessageLoopEvent::RunAndWait() {
91 DCHECK(CalledOnValidThread());
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(CalledOnValidThread());
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(CalledOnValidThread());
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(CalledOnValidThread());
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698