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/memory/scoped_ptr.h"
9 #include "cc/delay_based_time_source.h"
10 #include "cc/frame_rate_controller.h"
11 #include "cc/thread.h"
12 #include "testing/gtest/include/gtest/gtest.h"
16 class FakeTimeSourceClient
: public cc::TimeSourceClient
{
18 FakeTimeSourceClient() { reset(); }
19 void reset() { m_tickCalled
= false; }
20 bool tickCalled() const { return m_tickCalled
; }
22 virtual void onTimerTick() OVERRIDE
;
28 class FakeThread
: public cc::Thread
{
31 virtual ~FakeThread();
35 m_pendingTaskDelay
= 0;
36 m_pendingTask
.reset();
37 m_runPendingTaskOnOverwrite
= false;
40 void runPendingTaskOnOverwrite(bool enable
)
42 m_runPendingTaskOnOverwrite
= enable
;
45 bool hasPendingTask() const { return m_pendingTask
; }
46 void runPendingTask();
48 long long pendingDelayMs() const
50 EXPECT_TRUE(hasPendingTask());
51 return m_pendingTaskDelay
;
54 virtual void postTask(base::Closure cb
) OVERRIDE
;
55 virtual void postDelayedTask(base::Closure cb
, long long delay
) OVERRIDE
;
56 virtual bool belongsToCurrentThread() const OVERRIDE
;
59 scoped_ptr
<base::Closure
> m_pendingTask
;
60 long long m_pendingTaskDelay
;
61 bool m_runPendingTaskOnOverwrite
;
64 class FakeTimeSource
: public cc::TimeSource
{
72 virtual void setClient(cc::TimeSourceClient
* client
) OVERRIDE
;
73 virtual void setActive(bool b
) OVERRIDE
;
74 virtual bool active() const OVERRIDE
;
75 virtual void setTimebaseAndInterval(base::TimeTicks timebase
, base::TimeDelta interval
) OVERRIDE
{ }
76 virtual base::TimeTicks
lastTickTime() OVERRIDE
;
77 virtual base::TimeTicks
nextTickTime() OVERRIDE
;
81 ASSERT_TRUE(m_active
);
83 m_client
->onTimerTick();
86 void setNextTickTime(base::TimeTicks nextTickTime
) { m_nextTickTime
= nextTickTime
; }
89 virtual ~FakeTimeSource() { }
92 base::TimeTicks m_nextTickTime
;
93 cc::TimeSourceClient
* m_client
;
96 class FakeDelayBasedTimeSource
: public cc::DelayBasedTimeSource
{
98 static scoped_refptr
<FakeDelayBasedTimeSource
> create(base::TimeDelta interval
, cc::Thread
* thread
)
100 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval
, thread
));
103 void setNow(base::TimeTicks time
) { m_now
= time
; }
104 virtual base::TimeTicks
now() const OVERRIDE
;
107 FakeDelayBasedTimeSource(base::TimeDelta interval
, cc::Thread
* thread
)
108 : DelayBasedTimeSource(interval
, thread
)
111 virtual ~FakeDelayBasedTimeSource() { }
113 base::TimeTicks m_now
;
116 class FakeFrameRateController
: public cc::FrameRateController
{
118 FakeFrameRateController(scoped_refptr
<cc::TimeSource
> timer
) : cc::FrameRateController(timer
) { }
120 int numFramesPending() const { return m_numFramesPending
; }
125 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_