Adding binary files for platform_keys tests.
[chromium-blink-merge.git] / cc / test / scheduler_test_common.h
blob00cdd75646512dd1412618bc7478b92f99a0f213
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 <string>
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"
18 namespace cc {
20 class FakeTimeSourceClient : public TimeSourceClient {
21 public:
22 FakeTimeSourceClient() : tick_called_(false) {}
23 void Reset() { tick_called_ = false; }
24 bool TickCalled() const { return tick_called_; }
26 // TimeSourceClient implementation.
27 void OnTimerTick() override;
29 protected:
30 bool tick_called_;
33 class FakeDelayBasedTimeSource : public DelayBasedTimeSource {
34 public:
35 static scoped_refptr<FakeDelayBasedTimeSource> Create(
36 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner) {
37 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval,
38 task_runner));
41 void SetNow(base::TimeTicks time) { now_ = time; }
42 base::TimeTicks Now() const override;
44 protected:
45 FakeDelayBasedTimeSource(base::TimeDelta interval,
46 base::SingleThreadTaskRunner* task_runner)
47 : DelayBasedTimeSource(interval, task_runner) {}
48 ~FakeDelayBasedTimeSource() override {}
50 base::TimeTicks now_;
53 class TestDelayBasedTimeSource : public DelayBasedTimeSource {
54 public:
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));
63 protected:
64 TestDelayBasedTimeSource(scoped_refptr<TestNowSource> now_src,
65 base::TimeDelta interval,
66 OrderedSimpleTaskRunner* task_runner);
68 // Overridden from DelayBasedTimeSource
69 ~TestDelayBasedTimeSource() override;
70 base::TimeTicks Now() const override;
71 std::string TypeString() const override;
73 scoped_refptr<TestNowSource> now_src_;
76 struct FakeBeginFrameSource : public BeginFrameSourceMixIn {
77 bool remaining_frames_ = false;
79 BeginFrameObserver* GetObserver() { return observer_; }
81 BeginFrameArgs TestLastUsedBeginFrameArgs() {
82 if (observer_) {
83 return observer_->LastUsedBeginFrameArgs();
85 return BeginFrameArgs();
87 void TestOnBeginFrame(const BeginFrameArgs& args) {
88 return CallOnBeginFrame(args);
91 // BeginFrameSource
92 void DidFinishFrame(size_t remaining_frames) override;
93 void AsValueInto(base::trace_event::TracedValue* dict) const override;
95 ~FakeBeginFrameSource() override {}
98 class TestBackToBackBeginFrameSource : public BackToBackBeginFrameSource {
99 public:
100 ~TestBackToBackBeginFrameSource() override;
102 static scoped_ptr<TestBackToBackBeginFrameSource> Create(
103 scoped_refptr<TestNowSource> now_src,
104 base::SingleThreadTaskRunner* task_runner) {
105 return make_scoped_ptr(
106 new TestBackToBackBeginFrameSource(now_src, task_runner));
109 protected:
110 TestBackToBackBeginFrameSource(scoped_refptr<TestNowSource> now_src,
111 base::SingleThreadTaskRunner* task_runner);
113 base::TimeTicks Now() override;
115 scoped_refptr<TestNowSource> now_src_;
118 class TestSyntheticBeginFrameSource : public SyntheticBeginFrameSource {
119 public:
120 ~TestSyntheticBeginFrameSource() override;
122 static scoped_ptr<TestSyntheticBeginFrameSource> Create(
123 scoped_refptr<TestNowSource> now_src,
124 OrderedSimpleTaskRunner* task_runner,
125 base::TimeDelta initial_interval) {
126 return make_scoped_ptr(
127 new TestSyntheticBeginFrameSource(TestDelayBasedTimeSource::Create(
128 now_src, initial_interval, task_runner)));
131 protected:
132 TestSyntheticBeginFrameSource(
133 scoped_refptr<DelayBasedTimeSource> time_source);
136 class TestScheduler;
137 class TestSchedulerFrameSourcesConstructor
138 : public SchedulerFrameSourcesConstructor {
139 public:
140 ~TestSchedulerFrameSourcesConstructor() override;
142 protected:
143 BeginFrameSource* ConstructPrimaryFrameSource(Scheduler* scheduler) override;
144 BeginFrameSource* ConstructBackgroundFrameSource(
145 Scheduler* scheduler) override;
146 BeginFrameSource* ConstructUnthrottledFrameSource(
147 Scheduler* scheduler) override;
149 OrderedSimpleTaskRunner* test_task_runner_;
150 TestNowSource* now_src_;
152 protected:
153 explicit TestSchedulerFrameSourcesConstructor(
154 OrderedSimpleTaskRunner* test_task_runner,
155 TestNowSource* now_src);
156 friend class TestScheduler;
159 class TestScheduler : public Scheduler {
160 public:
161 static scoped_ptr<TestScheduler> Create(
162 scoped_refptr<TestNowSource> now_src,
163 SchedulerClient* client,
164 const SchedulerSettings& scheduler_settings,
165 int layer_tree_host_id,
166 const scoped_refptr<OrderedSimpleTaskRunner>& task_runner,
167 base::PowerMonitor* power_monitor,
168 scoped_ptr<BeginFrameSource> external_begin_frame_source) {
169 TestSchedulerFrameSourcesConstructor frame_sources_constructor(
170 task_runner.get(), now_src.get());
171 return make_scoped_ptr(new TestScheduler(
172 now_src,
173 client,
174 scheduler_settings,
175 layer_tree_host_id,
176 task_runner,
177 power_monitor,
178 &frame_sources_constructor,
179 external_begin_frame_source.Pass()));
182 // Extra test helper functionality
183 bool IsBeginRetroFrameArgsEmpty() const {
184 return begin_retro_frame_args_.empty();
187 bool CanStart() const { return state_machine_.CanStartForTesting(); }
189 BeginFrameSource& frame_source() { return *frame_source_; }
190 bool FrameProductionThrottled() { return throttle_frame_production_; }
192 ~TestScheduler() override;
194 void NotifyReadyToCommitThenActivateIfNeeded() {
195 NotifyReadyToCommit();
196 if (settings_.impl_side_painting) {
197 NotifyReadyToActivate();
201 protected:
202 // Overridden from Scheduler.
203 base::TimeTicks Now() const override;
205 private:
206 TestScheduler(
207 scoped_refptr<TestNowSource> now_src,
208 SchedulerClient* client,
209 const SchedulerSettings& scheduler_settings,
210 int layer_tree_host_id,
211 const scoped_refptr<OrderedSimpleTaskRunner>& test_task_runner,
212 base::PowerMonitor* power_monitor,
213 TestSchedulerFrameSourcesConstructor* frame_sources_constructor,
214 scoped_ptr<BeginFrameSource> external_begin_frame_source);
216 scoped_refptr<TestNowSource> now_src_;
219 } // namespace cc
221 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_