| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011 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. | |
| 4 | |
| 5 #include "cc/scheduler/frame_rate_controller.h" | |
| 6 | |
| 7 #include "base/test/test_simple_task_runner.h" | |
| 8 #include "cc/test/scheduler_test_common.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace cc { | |
| 12 namespace { | |
| 13 | |
| 14 class FakeFrameRateControllerClient : public FrameRateControllerClient { | |
| 15 public: | |
| 16 FakeFrameRateControllerClient() { Reset(); } | |
| 17 | |
| 18 void Reset() { frame_count_ = 0; } | |
| 19 bool BeganFrame() const { return frame_count_ > 0; } | |
| 20 int frame_count() const { return frame_count_; } | |
| 21 | |
| 22 virtual void FrameRateControllerTick(const BeginFrameArgs& args) OVERRIDE { | |
| 23 frame_count_ += 1; | |
| 24 } | |
| 25 | |
| 26 protected: | |
| 27 int frame_count_; | |
| 28 }; | |
| 29 | |
| 30 TEST(FrameRateControllerTest, TestFrameThrottling_ImmediateAck) { | |
| 31 scoped_refptr<base::TestSimpleTaskRunner> task_runner = | |
| 32 new base::TestSimpleTaskRunner; | |
| 33 FakeFrameRateControllerClient client; | |
| 34 base::TimeDelta interval = base::TimeDelta::FromMicroseconds( | |
| 35 base::Time::kMicrosecondsPerSecond / 60); | |
| 36 scoped_refptr<FakeDelayBasedTimeSource> time_source = | |
| 37 FakeDelayBasedTimeSource::Create(interval, task_runner.get()); | |
| 38 FrameRateController controller(time_source); | |
| 39 | |
| 40 controller.SetClient(&client); | |
| 41 controller.SetActive(true); | |
| 42 | |
| 43 base::TimeTicks elapsed; // Muck around with time a bit | |
| 44 | |
| 45 // Trigger one frame, make sure the BeginFrame callback is called | |
| 46 elapsed += task_runner->NextPendingTaskDelay(); | |
| 47 time_source->SetNow(elapsed); | |
| 48 task_runner->RunPendingTasks(); | |
| 49 EXPECT_TRUE(client.BeganFrame()); | |
| 50 client.Reset(); | |
| 51 | |
| 52 // Trigger another frame, make sure BeginFrame runs again | |
| 53 elapsed += task_runner->NextPendingTaskDelay(); | |
| 54 // Sanity check that previous code didn't move time backward. | |
| 55 EXPECT_GE(elapsed, time_source->Now()); | |
| 56 time_source->SetNow(elapsed); | |
| 57 task_runner->RunPendingTasks(); | |
| 58 EXPECT_TRUE(client.BeganFrame()); | |
| 59 } | |
| 60 | |
| 61 } // namespace | |
| 62 } // namespace cc | |
| OLD | NEW |