OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/simple_test_tick_clock.h" |
| 6 #include "media/base/wall_clock_time_source.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 namespace media { |
| 10 |
| 11 class WallClockTimeSourceTest : public testing::Test { |
| 12 public: |
| 13 WallClockTimeSourceTest() : tick_clock_(new base::SimpleTestTickClock()) { |
| 14 time_source_.SetTickClockForTesting( |
| 15 scoped_ptr<base::TickClock>(tick_clock_)); |
| 16 } |
| 17 virtual ~WallClockTimeSourceTest() {} |
| 18 |
| 19 void AdvanceTimeInSeconds(int seconds) { |
| 20 tick_clock_->Advance(base::TimeDelta::FromSeconds(seconds)); |
| 21 } |
| 22 |
| 23 int CurrentMediaTimeInSeconds() { |
| 24 return time_source_.CurrentMediaTime().InSeconds(); |
| 25 } |
| 26 |
| 27 void SetMediaTimeInSeconds(int seconds) { |
| 28 return time_source_.SetMediaTime(base::TimeDelta::FromSeconds(seconds)); |
| 29 } |
| 30 |
| 31 WallClockTimeSource time_source_; |
| 32 |
| 33 private: |
| 34 base::SimpleTestTickClock* tick_clock_; // Owned by |time_source_|. |
| 35 |
| 36 DISALLOW_COPY_AND_ASSIGN(WallClockTimeSourceTest); |
| 37 }; |
| 38 |
| 39 TEST_F(WallClockTimeSourceTest, InitialTimeIsZero) { |
| 40 EXPECT_EQ(0, CurrentMediaTimeInSeconds()); |
| 41 } |
| 42 |
| 43 TEST_F(WallClockTimeSourceTest, InitialTimeIsNotTicking) { |
| 44 EXPECT_EQ(0, CurrentMediaTimeInSeconds()); |
| 45 AdvanceTimeInSeconds(100); |
| 46 EXPECT_EQ(0, CurrentMediaTimeInSeconds()); |
| 47 } |
| 48 |
| 49 TEST_F(WallClockTimeSourceTest, InitialPlaybackRateIsOne) { |
| 50 time_source_.StartTicking(); |
| 51 |
| 52 EXPECT_EQ(0, CurrentMediaTimeInSeconds()); |
| 53 AdvanceTimeInSeconds(100); |
| 54 EXPECT_EQ(100, CurrentMediaTimeInSeconds()); |
| 55 } |
| 56 |
| 57 TEST_F(WallClockTimeSourceTest, SetMediaTime) { |
| 58 EXPECT_EQ(0, CurrentMediaTimeInSeconds()); |
| 59 SetMediaTimeInSeconds(10); |
| 60 EXPECT_EQ(10, CurrentMediaTimeInSeconds()); |
| 61 } |
| 62 |
| 63 TEST_F(WallClockTimeSourceTest, SetPlaybackRate) { |
| 64 time_source_.StartTicking(); |
| 65 |
| 66 time_source_.SetPlaybackRate(0.5); |
| 67 EXPECT_EQ(0, CurrentMediaTimeInSeconds()); |
| 68 AdvanceTimeInSeconds(10); |
| 69 EXPECT_EQ(5, CurrentMediaTimeInSeconds()); |
| 70 |
| 71 time_source_.SetPlaybackRate(2); |
| 72 EXPECT_EQ(5, CurrentMediaTimeInSeconds()); |
| 73 AdvanceTimeInSeconds(10); |
| 74 EXPECT_EQ(25, CurrentMediaTimeInSeconds()); |
| 75 } |
| 76 |
| 77 TEST_F(WallClockTimeSourceTest, StopTicking) { |
| 78 time_source_.StartTicking(); |
| 79 |
| 80 EXPECT_EQ(0, CurrentMediaTimeInSeconds()); |
| 81 AdvanceTimeInSeconds(10); |
| 82 EXPECT_EQ(10, CurrentMediaTimeInSeconds()); |
| 83 |
| 84 time_source_.StopTicking(); |
| 85 |
| 86 AdvanceTimeInSeconds(10); |
| 87 EXPECT_EQ(10, CurrentMediaTimeInSeconds()); |
| 88 } |
| 89 |
| 90 } // namespace media |
OLD | NEW |