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