OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "cc/scheduler/vsync_time_source.h" | 5 #include "cc/scheduler/vsync_time_source.h" |
6 | 6 |
7 #include "cc/test/scheduler_test_common.h" | 7 #include "cc/test/scheduler_test_common.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace cc { | 10 namespace cc { |
(...skipping 17 matching lines...) Expand all Loading... |
28 } | 28 } |
29 | 29 |
30 private: | 30 private: |
31 VSyncClient* client_; | 31 VSyncClient* client_; |
32 }; | 32 }; |
33 | 33 |
34 class VSyncTimeSourceTest : public testing::Test { | 34 class VSyncTimeSourceTest : public testing::Test { |
35 public: | 35 public: |
36 VSyncTimeSourceTest() | 36 VSyncTimeSourceTest() |
37 : timer_(VSyncTimeSource::create(&provider_)) { | 37 : timer_(VSyncTimeSource::create(&provider_)) { |
38 timer_->setClient(&client_); | 38 timer_->SetClient(&client_); |
39 } | 39 } |
40 | 40 |
41 protected: | 41 protected: |
42 FakeTimeSourceClient client_; | 42 FakeTimeSourceClient client_; |
43 FakeVSyncProvider provider_; | 43 FakeVSyncProvider provider_; |
44 scoped_refptr<VSyncTimeSource> timer_; | 44 scoped_refptr<VSyncTimeSource> timer_; |
45 }; | 45 }; |
46 | 46 |
47 TEST_F(VSyncTimeSourceTest, TaskPostedAndTickCalled) | 47 TEST_F(VSyncTimeSourceTest, TaskPostedAndTickCalled) |
48 { | 48 { |
49 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled()); | 49 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled()); |
50 | 50 |
51 timer_->setActive(true); | 51 timer_->SetActive(true); |
52 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); | 52 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); |
53 | 53 |
54 base::TimeTicks frame_time = base::TimeTicks::Now(); | 54 base::TimeTicks frame_time = base::TimeTicks::Now(); |
55 provider_.Trigger(frame_time); | 55 provider_.Trigger(frame_time); |
56 EXPECT_TRUE(client_.tickCalled()); | 56 EXPECT_TRUE(client_.tickCalled()); |
57 EXPECT_EQ(timer_->lastTickTime(), frame_time); | 57 EXPECT_EQ(timer_->LastTickTime(), frame_time); |
58 } | 58 } |
59 | 59 |
60 TEST_F(VSyncTimeSourceTest, NotificationDisabledLazily) | 60 TEST_F(VSyncTimeSourceTest, NotificationDisabledLazily) |
61 { | 61 { |
62 base::TimeTicks frame_time = base::TimeTicks::Now(); | 62 base::TimeTicks frame_time = base::TimeTicks::Now(); |
63 | 63 |
64 // Enable timer and trigger sync once. | 64 // Enable timer and trigger sync once. |
65 timer_->setActive(true); | 65 timer_->SetActive(true); |
66 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); | 66 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); |
67 provider_.Trigger(frame_time); | 67 provider_.Trigger(frame_time); |
68 EXPECT_TRUE(client_.tickCalled()); | 68 EXPECT_TRUE(client_.tickCalled()); |
69 | 69 |
70 // Disabling the timer should not disable vsync notification immediately. | 70 // Disabling the timer should not disable vsync notification immediately. |
71 client_.reset(); | 71 client_.reset(); |
72 timer_->setActive(false); | 72 timer_->SetActive(false); |
73 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); | 73 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); |
74 | 74 |
75 // At the next vsync the notification is disabled, but the timer isn't ticked. | 75 // At the next vsync the notification is disabled, but the timer isn't ticked. |
76 provider_.Trigger(frame_time); | 76 provider_.Trigger(frame_time); |
77 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled()); | 77 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled()); |
78 EXPECT_FALSE(client_.tickCalled()); | 78 EXPECT_FALSE(client_.tickCalled()); |
79 | 79 |
80 // The notification should not be disabled multiple times. | 80 // The notification should not be disabled multiple times. |
81 provider_.RequestVSyncNotification(timer_.get()); | 81 provider_.RequestVSyncNotification(timer_.get()); |
82 provider_.Trigger(frame_time); | 82 provider_.Trigger(frame_time); |
83 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); | 83 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); |
84 EXPECT_FALSE(client_.tickCalled()); | 84 EXPECT_FALSE(client_.tickCalled()); |
85 } | 85 } |
86 | 86 |
87 TEST_F(VSyncTimeSourceTest, ValidNextTickTime) | 87 TEST_F(VSyncTimeSourceTest, ValidNextTickTime) |
88 { | 88 { |
89 base::TimeTicks frame_time = base::TimeTicks::Now(); | 89 base::TimeTicks frame_time = base::TimeTicks::Now(); |
90 base::TimeDelta interval = base::TimeDelta::FromSeconds(1); | 90 base::TimeDelta interval = base::TimeDelta::FromSeconds(1); |
91 | 91 |
92 ASSERT_EQ(timer_->nextTickTime(), base::TimeTicks()); | 92 ASSERT_EQ(timer_->NextTickTime(), base::TimeTicks()); |
93 | 93 |
94 timer_->setActive(true); | 94 timer_->SetActive(true); |
95 provider_.Trigger(frame_time); | 95 provider_.Trigger(frame_time); |
96 ASSERT_EQ(timer_->nextTickTime(), frame_time); | 96 ASSERT_EQ(timer_->NextTickTime(), frame_time); |
97 | 97 |
98 timer_->setTimebaseAndInterval(frame_time, interval); | 98 timer_->SetTimebaseAndInterval(frame_time, interval); |
99 ASSERT_EQ(timer_->nextTickTime(), frame_time + interval); | 99 ASSERT_EQ(timer_->NextTickTime(), frame_time + interval); |
100 } | 100 } |
101 | 101 |
102 } // namespace | 102 } // namespace |
103 } // namespace cc | 103 } // namespace cc |
OLD | NEW |