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_
10 #include "base/basictypes.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/time/time.h"
13 #include "cc/scheduler/delay_based_time_source.h"
14 #include "cc/scheduler/scheduler.h"
15 #include "cc/test/ordered_simple_task_runner.h"
16 #include "testing/gtest/include/gtest/gtest.h"
20 class FakeTimeSourceClient
: public TimeSourceClient
{
22 FakeTimeSourceClient() { Reset(); }
23 void Reset() { tick_called_
= false; }
24 bool TickCalled() const { return tick_called_
; }
26 // TimeSourceClient implementation.
27 virtual void OnTimerTick() OVERRIDE
;
33 class FakeDelayBasedTimeSource
: public DelayBasedTimeSource
{
35 static scoped_refptr
<FakeDelayBasedTimeSource
> Create(
36 base::TimeDelta interval
, base::SingleThreadTaskRunner
* task_runner
) {
37 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval
,
41 void SetNow(base::TimeTicks time
) { now_
= time
; }
42 virtual base::TimeTicks
Now() const OVERRIDE
;
45 FakeDelayBasedTimeSource(base::TimeDelta interval
,
46 base::SingleThreadTaskRunner
* task_runner
)
47 : DelayBasedTimeSource(interval
, task_runner
) {}
48 virtual ~FakeDelayBasedTimeSource() {}
53 class TestDelayBasedTimeSource
: public DelayBasedTimeSource
{
55 static scoped_refptr
<TestDelayBasedTimeSource
> Create(
56 scoped_refptr
<TestNowSource
> now_src
,
57 base::TimeDelta interval
,
58 OrderedSimpleTaskRunner
* task_runner
) {
59 return make_scoped_refptr(
60 new TestDelayBasedTimeSource(now_src
, interval
, task_runner
));
64 TestDelayBasedTimeSource(scoped_refptr
<TestNowSource
> now_src
,
65 base::TimeDelta interval
,
66 OrderedSimpleTaskRunner
* task_runner
);
68 // Overridden from DelayBasedTimeSource
69 virtual ~TestDelayBasedTimeSource();
70 virtual base::TimeTicks
Now() const OVERRIDE
;
71 virtual std::string
TypeString() const OVERRIDE
;
73 scoped_refptr
<TestNowSource
> now_src_
;
76 class TestScheduler
: public Scheduler
{
78 static scoped_ptr
<TestScheduler
> Create(
79 scoped_refptr
<TestNowSource
> now_src
,
80 SchedulerClient
* client
,
81 const SchedulerSettings
& scheduler_settings
,
82 int layer_tree_host_id
) {
83 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval()
84 now_src
->AdvanceNow(base::TimeDelta::FromMilliseconds(100));
86 scoped_refptr
<OrderedSimpleTaskRunner
> test_task_runner
=
87 new OrderedSimpleTaskRunner(now_src
, true);
88 return make_scoped_ptr(new TestScheduler(now_src
,
95 // Extra test helper functionality
96 bool IsBeginRetroFrameArgsEmpty() const {
97 return begin_retro_frame_args_
.empty();
100 bool IsSyntheticBeginFrameSourceActive() const {
101 return synthetic_begin_frame_source_
->IsActive();
104 OrderedSimpleTaskRunner
& task_runner() { return *test_task_runner_
; }
106 virtual ~TestScheduler();
109 // Overridden from Scheduler.
110 virtual base::TimeTicks
Now() const OVERRIDE
;
113 TestScheduler(scoped_refptr
<TestNowSource
> now_src
,
114 SchedulerClient
* client
,
115 const SchedulerSettings
& scheduler_settings
,
116 int layer_tree_host_id
,
117 const scoped_refptr
<OrderedSimpleTaskRunner
>& test_task_runner
);
119 scoped_refptr
<TestNowSource
> now_src_
;
120 OrderedSimpleTaskRunner
* test_task_runner_
;
125 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_