Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / cc / scheduler / vsync_time_source_unittest.cc
blobd652017a8cd113c99b35655ee420b0d3973dcb39
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
3 // found in the LICENSE file.
5 #include "cc/scheduler/vsync_time_source.h"
7 #include "cc/test/scheduler_test_common.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace cc {
11 namespace {
13 class FakeVSyncProvider : public VSyncProvider {
14 public:
15 FakeVSyncProvider() : client_(NULL) {}
17 // VSyncProvider implementation.
18 virtual void RequestVSyncNotification(VSyncClient* client) OVERRIDE {
19 client_ = client;
22 bool IsVSyncNotificationEnabled() const { return client_ != NULL; }
24 void Trigger(base::TimeTicks frame_time) {
25 if (client_)
26 client_->DidVSync(frame_time);
29 private:
30 VSyncClient* client_;
33 class VSyncTimeSourceTest : public testing::Test {
34 public:
35 VSyncTimeSourceTest() : timer_(VSyncTimeSource::Create(&provider_)) {
36 timer_->SetClient(&client_);
39 protected:
40 FakeTimeSourceClient client_;
41 FakeVSyncProvider provider_;
42 scoped_refptr<VSyncTimeSource> timer_;
45 TEST_F(VSyncTimeSourceTest, TaskPostedAndTickCalled) {
46 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled());
48 timer_->SetActive(true);
49 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled());
51 base::TimeTicks frame_time = base::TimeTicks::Now();
52 provider_.Trigger(frame_time);
53 EXPECT_TRUE(client_.TickCalled());
54 EXPECT_EQ(timer_->LastTickTime(), frame_time);
57 TEST_F(VSyncTimeSourceTest, NotificationDisabledLazily) {
58 base::TimeTicks frame_time = base::TimeTicks::Now();
60 // Enable timer and trigger sync once.
61 timer_->SetActive(true);
62 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled());
63 provider_.Trigger(frame_time);
64 EXPECT_TRUE(client_.TickCalled());
66 // Disabling the timer should not disable vsync notification immediately.
67 client_.Reset();
68 timer_->SetActive(false);
69 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled());
71 // At the next vsync the notification is disabled, but the timer isn't ticked.
72 provider_.Trigger(frame_time);
73 EXPECT_FALSE(provider_.IsVSyncNotificationEnabled());
74 EXPECT_FALSE(client_.TickCalled());
76 // The notification should not be disabled multiple times.
77 provider_.RequestVSyncNotification(timer_.get());
78 provider_.Trigger(frame_time);
79 EXPECT_TRUE(provider_.IsVSyncNotificationEnabled());
80 EXPECT_FALSE(client_.TickCalled());
83 TEST_F(VSyncTimeSourceTest, ValidNextTickTime) {
84 base::TimeTicks frame_time = base::TimeTicks::Now();
85 base::TimeDelta interval = base::TimeDelta::FromSeconds(1);
87 ASSERT_EQ(timer_->NextTickTime(), base::TimeTicks());
89 timer_->SetActive(true);
90 provider_.Trigger(frame_time);
91 ASSERT_EQ(timer_->NextTickTime(), frame_time);
93 timer_->SetTimebaseAndInterval(frame_time, interval);
94 ASSERT_EQ(timer_->NextTickTime(), frame_time + interval);
97 } // namespace
98 } // namespace cc