| Index: cc/vsync_time_source_unittest.cc
|
| diff --git a/cc/vsync_time_source_unittest.cc b/cc/vsync_time_source_unittest.cc
|
| index 9833614e7a13c9241675e8719b301f47645bc8a2..f3af85f75742e901f9a812f6e183af6431c893c3 100644
|
| --- a/cc/vsync_time_source_unittest.cc
|
| +++ b/cc/vsync_time_source_unittest.cc
|
| @@ -31,17 +31,34 @@ class FakeVSyncProvider : public VSyncProvider {
|
| VSyncClient* client_;
|
| };
|
|
|
| +class FakeVSyncTimeSource : public cc::VSyncTimeSource {
|
| + public:
|
| + static scoped_refptr<FakeVSyncTimeSource> create(VSyncProvider* provider) {
|
| + return make_scoped_refptr(new FakeVSyncTimeSource(provider));
|
| + }
|
| +
|
| + void SetNow(base::TimeTicks time) { now_ = time; }
|
| + virtual base::TimeTicks Now() const OVERRIDE { return now_; }
|
| +
|
| + protected:
|
| + explicit FakeVSyncTimeSource(VSyncProvider* provider)
|
| + : VSyncTimeSource(provider) {}
|
| + virtual ~FakeVSyncTimeSource() {}
|
| +
|
| + base::TimeTicks now_;
|
| +};
|
| +
|
| class VSyncTimeSourceTest : public testing::Test {
|
| public:
|
| VSyncTimeSourceTest()
|
| - : timer_(VSyncTimeSource::create(&provider_)) {
|
| + : timer_(FakeVSyncTimeSource::create(&provider_)) {
|
| timer_->setClient(&client_);
|
| }
|
|
|
| protected:
|
| FakeTimeSourceClient client_;
|
| FakeVSyncProvider provider_;
|
| - scoped_refptr<VSyncTimeSource> timer_;
|
| + scoped_refptr<FakeVSyncTimeSource> timer_;
|
| };
|
|
|
| TEST_F(VSyncTimeSourceTest, TaskPostedAndTickCalled)
|
| @@ -99,5 +116,47 @@ TEST_F(VSyncTimeSourceTest, ValidNextTickTime)
|
| ASSERT_EQ(timer_->nextTickTime(), frame_time + interval);
|
| }
|
|
|
| +TEST_F(VSyncTimeSourceTest, SynthesizeVSyncFromInput)
|
| +{
|
| + base::TimeTicks current_time;
|
| + base::TimeDelta interval = base::TimeDelta::FromSeconds(1);
|
| +
|
| + // Establish a time base and interval.
|
| + timer_->setTimebaseAndInterval(current_time, interval);
|
| +
|
| + // An input event when the timer is inactive should do nothing.
|
| + timer_->DidReceiveLastInputEventForVSync();
|
| + EXPECT_FALSE(client_.tickCalled());
|
| + ASSERT_EQ(timer_->lastTickTime(), base::TimeTicks());
|
| +
|
| + // An input event should synthesize a vsync event with a frame time estimated
|
| + // from the current time.
|
| + current_time += interval;
|
| + timer_->SetNow(current_time);
|
| + timer_->setActive(true);
|
| + timer_->DidReceiveLastInputEventForVSync();
|
| + EXPECT_TRUE(client_.tickCalled());
|
| + ASSERT_EQ(timer_->lastTickTime(), current_time);
|
| + client_.reset();
|
| +
|
| + // A vsync notification immediately following the input should be ignored.
|
| + provider_.Trigger(current_time);
|
| + EXPECT_FALSE(client_.tickCalled());
|
| +
|
| + // A vsync notification for the next frame should not be ignored.
|
| + current_time += interval;
|
| + provider_.Trigger(current_time);
|
| + EXPECT_TRUE(client_.tickCalled());
|
| + ASSERT_EQ(timer_->lastTickTime(), current_time);
|
| + client_.reset();
|
| +
|
| + // The next input event should also trigger a tick, because it signifies a
|
| + // start of a new frame.
|
| + current_time += interval;
|
| + provider_.Trigger(current_time);
|
| + EXPECT_TRUE(client_.tickCalled());
|
| + ASSERT_EQ(timer_->lastTickTime(), current_time);
|
| +}
|
| +
|
| } // namespace
|
| } // namespace cc
|
|
|