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

Unified Diff: media/base/pipeline_unittest.cc

Issue 11607003: Add a Clock and TickClock interface for mocking out time (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix warnings Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/pipeline.cc ('k') | sync/notifier/ack_tracker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/pipeline_unittest.cc
diff --git a/media/base/pipeline_unittest.cc b/media/base/pipeline_unittest.cc
index 320c83a174ea73ff9cfaae9b9df8c4248655bc03..d2d14b2922afbdf61b9ee4211fe548ec55c38bdb 100644
--- a/media/base/pipeline_unittest.cc
+++ b/media/base/pipeline_unittest.cc
@@ -7,7 +7,9 @@
#include "base/bind.h"
#include "base/message_loop.h"
#include "base/stl_util.h"
+#include "base/test/simple_test_clock.h"
#include "base/threading/simple_thread.h"
+#include "base/time/clock.h"
#include "media/base/clock.h"
#include "media/base/gmock_callback_support.h"
#include "media/base/media_log.h"
@@ -298,6 +300,7 @@ class PipelineTest : public ::testing::Test {
// Fixture members.
StrictMock<CallbackHelper> callbacks_;
+ base::SimpleTestClock test_clock_;
MessageLoop message_loop_;
scoped_refptr<Pipeline> pipeline_;
@@ -608,12 +611,6 @@ TEST_F(PipelineTest, EndedCallback) {
message_loop_.RunUntilIdle();
}
-// Static function & time variable used to simulate changes in wallclock time.
-static int64 g_static_clock_time;
-static base::Time StaticClockFunction() {
- return base::Time::FromInternalValue(g_static_clock_time);
-}
-
TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
base::TimeDelta duration = base::TimeDelta::FromSeconds(10);
@@ -625,7 +622,7 @@ TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
// Replace the clock so we can simulate wallclock time advancing w/o using
// Sleep().
- pipeline_->SetClockForTesting(new Clock(&StaticClockFunction));
+ pipeline_->SetClockForTesting(new Clock(&test_clock_));
InitializeDemuxer(&streams, duration);
InitializeAudioRenderer(audio_stream(), false);
@@ -646,8 +643,7 @@ TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
// Verify that the clock doesn't advance since it hasn't been started by
// a time update from the audio stream.
int64 start_time = pipeline_->GetMediaTime().ToInternalValue();
- g_static_clock_time +=
- base::TimeDelta::FromMilliseconds(100).ToInternalValue();
+ test_clock_.Advance(base::TimeDelta::FromMilliseconds(100));
EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time);
// Signal end of audio stream.
@@ -656,8 +652,7 @@ TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
// Verify that the clock advances.
start_time = pipeline_->GetMediaTime().ToInternalValue();
- g_static_clock_time +=
- base::TimeDelta::FromMilliseconds(100).ToInternalValue();
+ test_clock_.Advance(base::TimeDelta::FromMilliseconds(100));
EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time);
// Signal end of video stream and make sure OnEnded() callback occurs.
« no previous file with comments | « media/base/pipeline.cc ('k') | sync/notifier/ack_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698