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

Side by Side Diff: media/base/clock_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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/base/clock.cc ('k') | media/base/pipeline.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/compiler_specific.h"
5 #include "base/logging.h" 6 #include "base/logging.h"
6 #include "base/test/mock_time_provider.h" 7 #include "base/test/simple_test_clock.h"
8 #include "base/time/clock.h"
7 #include "media/base/clock.h" 9 #include "media/base/clock.h"
8 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
9 11
10 using ::testing::InSequence; 12 using ::testing::InSequence;
11 using ::testing::Return; 13 using ::testing::Return;
12 using ::testing::StrictMock; 14 using ::testing::StrictMock;
13 15
14 namespace base { 16 namespace base {
15 17
16 // Provide a stream output operator so we can use EXPECT_EQ(...) with TimeDelta. 18 // Provide a stream output operator so we can use EXPECT_EQ(...) with TimeDelta.
17 // 19 //
18 // TODO(scherkus): move this into the testing package. 20 // TODO(scherkus): move this into the testing package.
19 static std::ostream& operator<<(std::ostream& stream, const TimeDelta& time) { 21 static std::ostream& operator<<(std::ostream& stream, const TimeDelta& time) {
20 return (stream << time.ToInternalValue()); 22 return (stream << time.ToInternalValue());
21 } 23 }
22 24
23 } // namespace 25 } // namespace
24 26
25 namespace media { 27 namespace media {
26 28
27 static const int kDurationInSeconds = 120; 29 static const int kDurationInSeconds = 120;
28 30
29 class ClockTest : public ::testing::Test { 31 class ClockTest : public ::testing::Test {
30 public: 32 public:
31 ClockTest() 33 ClockTest() : clock_(&test_clock_) {
32 : clock_(&base::MockTimeProvider::StaticNow) {
33 SetDuration(); 34 SetDuration();
34 EXPECT_CALL(mock_time_, Now())
35 .WillRepeatedly(Return(base::Time::UnixEpoch()));
36 } 35 }
37 36
38 protected: 37 protected:
39 void SetDuration() { 38 void SetDuration() {
40 const base::TimeDelta kDuration = 39 const base::TimeDelta kDuration =
41 base::TimeDelta::FromSeconds(kDurationInSeconds); 40 base::TimeDelta::FromSeconds(kDurationInSeconds);
42 clock_.SetDuration(kDuration); 41 clock_.SetDuration(kDuration);
43 EXPECT_EQ(kDuration, clock_.Duration()); 42 EXPECT_EQ(kDuration, clock_.Duration());
44 } 43 }
45 44
46 void AdvanceSystemTime(base::TimeDelta delta) { 45 void AdvanceSystemTime(base::TimeDelta delta) {
47 time_elapsed_ += delta; 46 test_clock_.Advance(delta);
48 EXPECT_CALL(mock_time_, Now())
49 .WillRepeatedly(Return(base::Time::UnixEpoch() + time_elapsed_));
50 } 47 }
51 48
49 base::SimpleTestClock test_clock_;
52 Clock clock_; 50 Clock clock_;
53 StrictMock<base::MockTimeProvider> mock_time_;
54 base::TimeDelta time_elapsed_; 51 base::TimeDelta time_elapsed_;
55 }; 52 };
56 53
57 TEST_F(ClockTest, Created) { 54 TEST_F(ClockTest, Created) {
58 const base::TimeDelta kExpected = base::TimeDelta::FromSeconds(0); 55 const base::TimeDelta kExpected = base::TimeDelta::FromSeconds(0);
59 EXPECT_EQ(kExpected, clock_.Elapsed()); 56 EXPECT_EQ(kExpected, clock_.Elapsed());
60 } 57 }
61 58
62 TEST_F(ClockTest, Play_NormalSpeed) { 59 TEST_F(ClockTest, Play_NormalSpeed) {
63 const base::TimeDelta kZero; 60 const base::TimeDelta kZero;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 EXPECT_EQ(kMaxTime1, clock_.Elapsed()); 244 EXPECT_EQ(kMaxTime1, clock_.Elapsed());
248 245
249 AdvanceSystemTime(kTimeInterval); 246 AdvanceSystemTime(kTimeInterval);
250 EXPECT_EQ(kMaxTime1 + kTimeInterval, clock_.Elapsed()); 247 EXPECT_EQ(kMaxTime1 + kTimeInterval, clock_.Elapsed());
251 248
252 AdvanceSystemTime(kTimeInterval); 249 AdvanceSystemTime(kTimeInterval);
253 EXPECT_EQ(kMaxTime2, clock_.Elapsed()); 250 EXPECT_EQ(kMaxTime2, clock_.Elapsed());
254 } 251 }
255 252
256 } // namespace media 253 } // namespace media
OLDNEW
« no previous file with comments | « media/base/clock.cc ('k') | media/base/pipeline.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698