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

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: 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 side-by-side diff with in-line comments
Download patch
Index: media/base/pipeline_unittest.cc
diff --git a/media/base/pipeline_unittest.cc b/media/base/pipeline_unittest.cc
index a12f91cc35616199a138f41f06bfa12523237be5..32040f8002db7ab1f0776adaecb663359984582f 100644
--- a/media/base/pipeline_unittest.cc
+++ b/media/base/pipeline_unittest.cc
@@ -5,8 +5,10 @@
#include <vector>
#include "base/bind.h"
+#include "base/clock.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 "media/base/clock.h"
#include "media/base/gmock_callback_support.h"
@@ -278,6 +280,7 @@ class PipelineTest : public ::testing::Test {
// Fixture members.
StrictMock<CallbackHelper> callbacks_;
+ base::SimpleTestClock test_clock_;
MessageLoop message_loop_;
scoped_refptr<Pipeline> pipeline_;
scoped_ptr<media::MockFilterCollection> mocks_;
@@ -581,12 +584,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);
@@ -598,7 +595,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);
@@ -619,8 +616,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.
@@ -629,8 +625,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.

Powered by Google App Engine
This is Rietveld 408576698