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.
5 #ifndef CC_TEST_SCHEDULER_TEST_COMMON_H_
6 #define CC_TEST_SCHEDULER_TEST_COMMON_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time.h"
11 #include "cc/base/thread.h"
12 #include "cc/scheduler/delay_based_time_source.h"
13 #include "cc/scheduler/frame_rate_controller.h"
14 #include "testing/gtest/include/gtest/gtest.h"
18 class FakeTimeSourceClient
: public cc::TimeSourceClient
{
20 FakeTimeSourceClient() { Reset(); }
21 void Reset() { tick_called_
= false; }
22 bool TickCalled() const { return tick_called_
; }
24 // TimeSourceClient implementation.
25 virtual void OnTimerTick() OVERRIDE
;
31 class FakeThread
: public cc::Thread
{
34 virtual ~FakeThread();
37 pending_task_delay_
= 0;
38 pending_task_
.reset();
39 run_pending_task_on_overwrite_
= false;
42 void RunPendingTaskOnOverwrite(bool enable
) {
43 run_pending_task_on_overwrite_
= enable
;
46 bool HasPendingTask() const { return pending_task_
; }
47 void RunPendingTask();
49 int64
PendingDelayMs() const {
50 EXPECT_TRUE(HasPendingTask());
51 return pending_task_delay_
;
54 virtual void PostTask(base::Closure cb
) OVERRIDE
;
55 virtual void PostDelayedTask(base::Closure cb
, base::TimeDelta delay
)
57 virtual bool BelongsToCurrentThread() const OVERRIDE
;
60 scoped_ptr
<base::Closure
> pending_task_
;
61 int64 pending_task_delay_
;
62 bool run_pending_task_on_overwrite_
;
65 class FakeTimeSource
: public cc::TimeSource
{
67 FakeTimeSource() : active_(false), client_(0) {}
69 virtual void SetClient(cc::TimeSourceClient
* client
) OVERRIDE
;
70 virtual void SetActive(bool b
) OVERRIDE
;
71 virtual bool Active() const OVERRIDE
;
72 virtual void SetTimebaseAndInterval(base::TimeTicks timebase
,
73 base::TimeDelta interval
) OVERRIDE
{}
74 virtual base::TimeTicks
LastTickTime() OVERRIDE
;
75 virtual base::TimeTicks
NextTickTime() OVERRIDE
;
80 client_
->OnTimerTick();
83 void SetNextTickTime(base::TimeTicks next_tick_time
) {
84 next_tick_time_
= next_tick_time
;
88 virtual ~FakeTimeSource() {}
91 base::TimeTicks next_tick_time_
;
92 cc::TimeSourceClient
* client_
;
95 class FakeDelayBasedTimeSource
: public cc::DelayBasedTimeSource
{
97 static scoped_refptr
<FakeDelayBasedTimeSource
> Create(
98 base::TimeDelta interval
, cc::Thread
* thread
) {
99 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval
, thread
));
102 void SetNow(base::TimeTicks time
) { now_
= time
; }
103 virtual base::TimeTicks
Now() const OVERRIDE
;
106 FakeDelayBasedTimeSource(base::TimeDelta interval
, cc::Thread
* thread
)
107 : DelayBasedTimeSource(interval
, thread
) {}
108 virtual ~FakeDelayBasedTimeSource() {}
110 base::TimeTicks now_
;
113 class FakeFrameRateController
: public cc::FrameRateController
{
115 explicit FakeFrameRateController(scoped_refptr
<cc::TimeSource
> timer
)
116 : cc::FrameRateController(timer
) {}
118 int NumFramesPending() const { return num_frames_pending_
; }
123 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_