summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authordalecurtis <dalecurtis@chromium.org>2015-05-04 18:50:29 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-05 01:51:14 +0000
commit754b1b7e9d0993dd0e4cbdbffe7da984bf96d420 (patch)
treeff167d21c7cd6c4d891e6ea830d78b03d2af0720 /media
parent7c17dcdabaacd30035b9c09e76a276ccacae60a1 (diff)
downloadchromium_src-754b1b7e9d0993dd0e4cbdbffe7da984bf96d420.zip
chromium_src-754b1b7e9d0993dd0e4cbdbffe7da984bf96d420.tar.gz
chromium_src-754b1b7e9d0993dd0e4cbdbffe7da984bf96d420.tar.bz2
Switch WaitableMessageLoopEvent to use a RunLoop.
Allows it to quit immediately instead of trying to quit when idle, which on slow platforms with repeating tasks, may be never. BUG=483620 TEST=unittests all pass, don't hang on valgrind Review URL: https://codereview.chromium.org/1119763004 Cr-Commit-Position: refs/heads/master@{#328250}
Diffstat (limited to 'media')
-rw-r--r--media/base/null_video_sink_unittest.cc12
-rw-r--r--media/base/test_helpers.cc12
-rw-r--r--media/base/test_helpers.h2
3 files changed, 15 insertions, 11 deletions
diff --git a/media/base/null_video_sink_unittest.cc b/media/base/null_video_sink_unittest.cc
index f2412e5..aebe328 100644
--- a/media/base/null_video_sink_unittest.cc
+++ b/media/base/null_video_sink_unittest.cc
@@ -5,7 +5,6 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
#include "base/test/simple_test_tick_clock.h"
#include "media/base/null_video_sink.h"
#include "media/base/test_helpers.h"
@@ -123,10 +122,8 @@ TEST_F(NullVideoSinkTest, ClocklessFunctionality) {
const base::TimeTicks now = base::TimeTicks::Now();
const base::TimeTicks current_time = tick_clock_.NowTicks();
- // Use a RunLoop instead of WaitableMessageLoopEvent() since it will only quit
- // the loop when it's idle, instead of quitting immediately which is required
- // when clockless playback is enabled (otherwise the loop is never idle).
- base::RunLoop run_loop;
+ SCOPED_TRACE("Waiting for multiple render callbacks");
+ WaitableMessageLoopEvent event;
for (int i = 0; i < kTestRuns; ++i) {
if (i < kTestRuns - 1) {
EXPECT_CALL(*this, Render(current_time + i * interval,
@@ -135,11 +132,10 @@ TEST_F(NullVideoSinkTest, ClocklessFunctionality) {
} else {
EXPECT_CALL(*this, Render(current_time + i * interval,
current_time + (i + 1) * interval))
- .WillOnce(DoAll(RunClosure(run_loop.QuitClosure()), Return(nullptr)));
+ .WillOnce(DoAll(RunClosure(event.GetClosure()), Return(nullptr)));
}
}
-
- run_loop.Run();
+ event.RunAndWait();
ASSERT_LT(base::TimeTicks::Now() - now, kTestRuns * interval);
sink->Stop();
}
diff --git a/media/base/test_helpers.cc b/media/base/test_helpers.cc
index 60e22df..bde12b4 100644
--- a/media/base/test_helpers.cc
+++ b/media/base/test_helpers.cc
@@ -8,6 +8,7 @@
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/pickle.h"
+#include "base/run_loop.h"
#include "base/test/test_timeouts.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
@@ -84,26 +85,31 @@ void WaitableMessageLoopEvent::RunAndWaitForStatus(PipelineStatus expected) {
return;
}
+ run_loop_.reset(new base::RunLoop());
base::Timer timer(false, false);
timer.Start(FROM_HERE, TestTimeouts::action_timeout(), base::Bind(
&WaitableMessageLoopEvent::OnTimeout, base::Unretained(this)));
- message_loop_->Run();
+ run_loop_->Run();
EXPECT_TRUE(signaled_);
EXPECT_EQ(expected, status_);
+ run_loop_.reset();
}
void WaitableMessageLoopEvent::OnCallback(PipelineStatus status) {
DCHECK_EQ(message_loop_, base::MessageLoop::current());
signaled_ = true;
status_ = status;
- message_loop_->QuitWhenIdle();
+
+ // |run_loop_| may be null if the callback fires before RunAndWaitForStatus().
+ if (run_loop_)
+ run_loop_->Quit();
}
void WaitableMessageLoopEvent::OnTimeout() {
DCHECK_EQ(message_loop_, base::MessageLoop::current());
ADD_FAILURE() << "Timed out waiting for message loop to quit";
- message_loop_->QuitWhenIdle();
+ run_loop_->Quit();
}
static VideoDecoderConfig GetTestConfig(VideoCodec codec,
diff --git a/media/base/test_helpers.h b/media/base/test_helpers.h
index 1c518d9f..712812f 100644
--- a/media/base/test_helpers.h
+++ b/media/base/test_helpers.h
@@ -17,6 +17,7 @@
namespace base {
class MessageLoop;
+class RunLoop;
class TimeDelta;
}
@@ -62,6 +63,7 @@ class WaitableMessageLoopEvent {
base::MessageLoop* message_loop_;
bool signaled_;
PipelineStatus status_;
+ scoped_ptr<base::RunLoop> run_loop_;
DISALLOW_COPY_AND_ASSIGN(WaitableMessageLoopEvent);
};