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.
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"
11 class WallClockTimeSourceTest
: public testing::Test
{
13 WallClockTimeSourceTest() : tick_clock_(new base::SimpleTestTickClock()) {
14 time_source_
.SetTickClockForTesting(
15 scoped_ptr
<base::TickClock
>(tick_clock_
));
17 ~WallClockTimeSourceTest() override
{}
19 void AdvanceTimeInSeconds(int seconds
) {
20 tick_clock_
->Advance(base::TimeDelta::FromSeconds(seconds
));
23 int CurrentMediaTimeInSeconds() {
24 return time_source_
.CurrentMediaTime().InSeconds();
27 void SetMediaTimeInSeconds(int seconds
) {
28 return time_source_
.SetMediaTime(base::TimeDelta::FromSeconds(seconds
));
31 WallClockTimeSource time_source_
;
34 base::SimpleTestTickClock
* tick_clock_
; // Owned by |time_source_|.
36 DISALLOW_COPY_AND_ASSIGN(WallClockTimeSourceTest
);
39 TEST_F(WallClockTimeSourceTest
, InitialTimeIsZero
) {
40 EXPECT_EQ(0, CurrentMediaTimeInSeconds());
43 TEST_F(WallClockTimeSourceTest
, InitialTimeIsNotTicking
) {
44 EXPECT_EQ(0, CurrentMediaTimeInSeconds());
45 AdvanceTimeInSeconds(100);
46 EXPECT_EQ(0, CurrentMediaTimeInSeconds());
49 TEST_F(WallClockTimeSourceTest
, InitialPlaybackRateIsOne
) {
50 time_source_
.StartTicking();
52 EXPECT_EQ(0, CurrentMediaTimeInSeconds());
53 AdvanceTimeInSeconds(100);
54 EXPECT_EQ(100, CurrentMediaTimeInSeconds());
57 TEST_F(WallClockTimeSourceTest
, SetMediaTime
) {
58 EXPECT_EQ(0, CurrentMediaTimeInSeconds());
59 SetMediaTimeInSeconds(10);
60 EXPECT_EQ(10, CurrentMediaTimeInSeconds());
63 TEST_F(WallClockTimeSourceTest
, SetPlaybackRate
) {
64 time_source_
.StartTicking();
66 time_source_
.SetPlaybackRate(0.5);
67 EXPECT_EQ(0, CurrentMediaTimeInSeconds());
68 AdvanceTimeInSeconds(10);
69 EXPECT_EQ(5, CurrentMediaTimeInSeconds());
71 time_source_
.SetPlaybackRate(2);
72 EXPECT_EQ(5, CurrentMediaTimeInSeconds());
73 AdvanceTimeInSeconds(10);
74 EXPECT_EQ(25, CurrentMediaTimeInSeconds());
77 TEST_F(WallClockTimeSourceTest
, StopTicking
) {
78 time_source_
.StartTicking();
80 EXPECT_EQ(0, CurrentMediaTimeInSeconds());
81 AdvanceTimeInSeconds(10);
82 EXPECT_EQ(10, CurrentMediaTimeInSeconds());
84 time_source_
.StopTicking();
86 AdvanceTimeInSeconds(10);
87 EXPECT_EQ(10, CurrentMediaTimeInSeconds());