| 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 14 matching lines...) Expand all Loading... |
| 25 if (client_) | 25 if (client_) |
| 26 client_->DidVSync(frame_time); | 26 client_->DidVSync(frame_time); |
| 27 } | 27 } |
| 28 | 28 |
| 29 private: | 29 private: |
| 30 VSyncClient* client_; | 30 VSyncClient* client_; |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 class VSyncTimeSourceTest : public testing::Test { | 33 class VSyncTimeSourceTest : public testing::Test { |
| 34 public: | 34 public: |
| 35 VSyncTimeSourceTest() : timer_(VSyncTimeSource::Create(&provider_)) { | 35 VSyncTimeSourceTest() : timer_(VSyncTimeSource::Create(&provider_, true)) { |
| 36 timer_->SetClient(&client_); | 36 timer_->SetClient(&client_); |
| 37 } | 37 } |
| 38 | 38 |
| 39 protected: | 39 protected: |
| 40 FakeTimeSourceClient client_; | 40 FakeTimeSourceClient client_; |
| 41 FakeVSyncProvider provider_; | 41 FakeVSyncProvider provider_; |
| 42 scoped_refptr<VSyncTimeSource> timer_; | 42 scoped_refptr<VSyncTimeSource> timer_; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 TEST_F(VSyncTimeSourceTest, TaskPostedAndTickCalled) { | 45 TEST_F(VSyncTimeSourceTest, TaskPostedAndTickCalled) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 73 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled()); | 73 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled()); |
| 74 EXPECT_FALSE(client_.TickCalled()); | 74 EXPECT_FALSE(client_.TickCalled()); |
| 75 | 75 |
| 76 // The notification should not be disabled multiple times. | 76 // The notification should not be disabled multiple times. |
| 77 provider_.RequestVSyncNotification(timer_.get()); | 77 provider_.RequestVSyncNotification(timer_.get()); |
| 78 provider_.Trigger(frame_time); | 78 provider_.Trigger(frame_time); |
| 79 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); | 79 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); |
| 80 EXPECT_FALSE(client_.TickCalled()); | 80 EXPECT_FALSE(client_.TickCalled()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 TEST_F(VSyncTimeSourceTest, NotificationDisabledImmediatelyForSetting) { |
| 84 timer_ = VSyncTimeSource::Create(&provider_, false); |
| 85 timer_->SetClient(&client_); |
| 86 base::TimeTicks frame_time = base::TimeTicks::Now(); |
| 87 |
| 88 // Enable timer and trigger sync once. |
| 89 timer_->SetActive(true); |
| 90 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); |
| 91 provider_.Trigger(frame_time); |
| 92 EXPECT_TRUE(client_.TickCalled()); |
| 93 |
| 94 // Disable timer should disable vsync notification immediately. |
| 95 timer_->SetActive(false); |
| 96 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled()); |
| 97 |
| 98 // Enable again and timer can be ticked again. |
| 99 client_.Reset(); |
| 100 timer_->SetActive(true); |
| 101 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled()); |
| 102 provider_.Trigger(frame_time); |
| 103 EXPECT_TRUE(client_.TickCalled()); |
| 104 } |
| 105 |
| 83 TEST_F(VSyncTimeSourceTest, ValidNextTickTime) { | 106 TEST_F(VSyncTimeSourceTest, ValidNextTickTime) { |
| 84 base::TimeTicks frame_time = base::TimeTicks::Now(); | 107 base::TimeTicks frame_time = base::TimeTicks::Now(); |
| 85 base::TimeDelta interval = base::TimeDelta::FromSeconds(1); | 108 base::TimeDelta interval = base::TimeDelta::FromSeconds(1); |
| 86 | 109 |
| 87 ASSERT_EQ(timer_->NextTickTime(), base::TimeTicks()); | 110 ASSERT_EQ(timer_->NextTickTime(), base::TimeTicks()); |
| 88 | 111 |
| 89 timer_->SetActive(true); | 112 timer_->SetActive(true); |
| 90 provider_.Trigger(frame_time); | 113 provider_.Trigger(frame_time); |
| 91 ASSERT_EQ(timer_->NextTickTime(), frame_time); | 114 ASSERT_EQ(timer_->NextTickTime(), frame_time); |
| 92 | 115 |
| 93 timer_->SetTimebaseAndInterval(frame_time, interval); | 116 timer_->SetTimebaseAndInterval(frame_time, interval); |
| 94 ASSERT_EQ(timer_->NextTickTime(), frame_time + interval); | 117 ASSERT_EQ(timer_->NextTickTime(), frame_time + interval); |
| 95 } | 118 } |
| 96 | 119 |
| 97 } // namespace | 120 } // namespace |
| 98 } // namespace cc | 121 } // namespace cc |
| OLD | NEW |