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 #ifndef CC_TEST_SCHEDULER_TEST_COMMON_H_ 6 #define CC_TEST_SCHEDULER_TEST_COMMON_H_ 7 8 #include "base/basictypes.h" 9 #include "base/memory/scoped_ptr.h" 10 #include "base/time/time.h" 11 #include "cc/scheduler/delay_based_time_source.h" 12 #include "cc/scheduler/frame_rate_controller.h" 13 #include "testing/gtest/include/gtest/gtest.h" 14 15 namespace cc { 16 17 class FakeTimeSourceClient : public TimeSourceClient { 18 public: 19 FakeTimeSourceClient() { Reset(); } 20 void Reset() { tick_called_ = false; } 21 bool TickCalled() const { return tick_called_; } 22 23 // TimeSourceClient implementation. 24 virtual void OnTimerTick() OVERRIDE; 25 26 protected: 27 bool tick_called_; 28 }; 29 30 class FakeDelayBasedTimeSource : public DelayBasedTimeSource { 31 public: 32 static scoped_refptr<FakeDelayBasedTimeSource> Create( 33 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner) { 34 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, 35 task_runner)); 36 } 37 38 void SetNow(base::TimeTicks time) { now_ = time; } 39 virtual base::TimeTicks Now() const OVERRIDE; 40 41 protected: 42 FakeDelayBasedTimeSource(base::TimeDelta interval, 43 base::SingleThreadTaskRunner* task_runner) 44 : DelayBasedTimeSource(interval, task_runner) {} 45 virtual ~FakeDelayBasedTimeSource() {} 46 47 base::TimeTicks now_; 48 }; 49 50 class FakeFrameRateController : public FrameRateController { 51 public: 52 explicit FakeFrameRateController(scoped_refptr<TimeSource> timer) 53 : FrameRateController(timer) {} 54 55 int NumFramesPending() const { return num_frames_pending_; } 56 }; 57 58 } // namespace cc 59 60 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ 61