Add ICU message format support
[chromium-blink-merge.git] / cc / test / scheduler_test_common.h
blobce6ccc4789107ff75f2d888b0ab167d47eba5923
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/compositor_timing_history.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 RenderingStatsInstrumentation;
22 class FakeDelayBasedTimeSourceClient : public DelayBasedTimeSourceClient {
23 public:
24 FakeDelayBasedTimeSourceClient() : tick_called_(false) {}
25 void Reset() { tick_called_ = false; }
26 bool TickCalled() const { return tick_called_; }
28 // DelayBasedTimeSourceClient implementation.
29 void OnTimerTick() override;
31 protected:
32 bool tick_called_;
34 private:
35 DISALLOW_COPY_AND_ASSIGN(FakeDelayBasedTimeSourceClient);
38 class FakeDelayBasedTimeSource : public DelayBasedTimeSource {
39 public:
40 static scoped_ptr<FakeDelayBasedTimeSource> Create(
41 base::TimeDelta interval,
42 base::SingleThreadTaskRunner* task_runner) {
43 return make_scoped_ptr(new FakeDelayBasedTimeSource(interval, task_runner));
46 ~FakeDelayBasedTimeSource() override {}
48 void SetNow(base::TimeTicks time) { now_ = time; }
49 base::TimeTicks Now() const override;
51 protected:
52 FakeDelayBasedTimeSource(base::TimeDelta interval,
53 base::SingleThreadTaskRunner* task_runner)
54 : DelayBasedTimeSource(interval, task_runner) {}
56 base::TimeTicks now_;
58 private:
59 DISALLOW_COPY_AND_ASSIGN(FakeDelayBasedTimeSource);
62 class TestDelayBasedTimeSource : public DelayBasedTimeSource {
63 public:
64 static scoped_ptr<TestDelayBasedTimeSource> Create(
65 base::SimpleTestTickClock* now_src,
66 base::TimeDelta interval,
67 OrderedSimpleTaskRunner* task_runner) {
68 return make_scoped_ptr(
69 new TestDelayBasedTimeSource(now_src, interval, task_runner));
72 ~TestDelayBasedTimeSource() override;
74 protected:
75 TestDelayBasedTimeSource(base::SimpleTestTickClock* now_src,
76 base::TimeDelta interval,
77 OrderedSimpleTaskRunner* task_runner);
79 // Overridden from DelayBasedTimeSource
80 base::TimeTicks Now() const override;
81 std::string TypeString() const override;
83 // Not owned.
84 base::SimpleTestTickClock* now_src_;
86 private:
87 DISALLOW_COPY_AND_ASSIGN(TestDelayBasedTimeSource);
90 class FakeBeginFrameSource : public BeginFrameSourceBase {
91 public:
92 FakeBeginFrameSource() : remaining_frames_(false) {}
93 ~FakeBeginFrameSource() override {}
95 BeginFrameObserver* GetObserver() { return observer_; }
97 BeginFrameArgs TestLastUsedBeginFrameArgs() {
98 if (observer_) {
99 return observer_->LastUsedBeginFrameArgs();
101 return BeginFrameArgs();
104 void TestOnBeginFrame(const BeginFrameArgs& args) {
105 return CallOnBeginFrame(args);
108 // BeginFrameSource
109 void DidFinishFrame(size_t remaining_frames) override;
110 void AsValueInto(base::trace_event::TracedValue* dict) const override;
112 private:
113 bool remaining_frames_;
115 DISALLOW_COPY_AND_ASSIGN(FakeBeginFrameSource);
118 class TestBackToBackBeginFrameSource : public BackToBackBeginFrameSource {
119 public:
120 ~TestBackToBackBeginFrameSource() override;
122 static scoped_ptr<TestBackToBackBeginFrameSource> Create(
123 base::SimpleTestTickClock* now_src,
124 base::SingleThreadTaskRunner* task_runner) {
125 return make_scoped_ptr(
126 new TestBackToBackBeginFrameSource(now_src, task_runner));
129 protected:
130 TestBackToBackBeginFrameSource(base::SimpleTestTickClock* now_src,
131 base::SingleThreadTaskRunner* task_runner);
133 base::TimeTicks Now() override;
134 // Not owned.
135 base::SimpleTestTickClock* now_src_;
137 private:
138 DISALLOW_COPY_AND_ASSIGN(TestBackToBackBeginFrameSource);
141 class TestSyntheticBeginFrameSource : public SyntheticBeginFrameSource {
142 public:
143 ~TestSyntheticBeginFrameSource() override;
145 static scoped_ptr<TestSyntheticBeginFrameSource> Create(
146 base::SimpleTestTickClock* now_src,
147 OrderedSimpleTaskRunner* task_runner,
148 base::TimeDelta initial_interval) {
149 scoped_ptr<TestDelayBasedTimeSource> time_source =
150 TestDelayBasedTimeSource::Create(now_src, initial_interval,
151 task_runner);
152 return make_scoped_ptr(
153 new TestSyntheticBeginFrameSource(time_source.Pass()));
156 protected:
157 explicit TestSyntheticBeginFrameSource(
158 scoped_ptr<DelayBasedTimeSource> time_source);
160 private:
161 DISALLOW_COPY_AND_ASSIGN(TestSyntheticBeginFrameSource);
164 class FakeCompositorTimingHistory : public CompositorTimingHistory {
165 public:
166 static scoped_ptr<FakeCompositorTimingHistory> Create();
167 ~FakeCompositorTimingHistory() override;
169 void SetAllEstimatesTo(base::TimeDelta duration);
171 void SetBeginMainFrameToCommitDurationEstimate(base::TimeDelta duration);
172 void SetCommitToReadyToActivateDurationEstimate(base::TimeDelta duration);
173 void SetPrepareTilesDurationEstimate(base::TimeDelta duration);
174 void SetActivateDurationEstimate(base::TimeDelta duration);
175 void SetDrawDurationEstimate(base::TimeDelta duration);
177 base::TimeDelta BeginMainFrameToCommitDurationEstimate() const override;
178 base::TimeDelta CommitToReadyToActivateDurationEstimate() const override;
179 base::TimeDelta PrepareTilesDurationEstimate() const override;
180 base::TimeDelta ActivateDurationEstimate() const override;
181 base::TimeDelta DrawDurationEstimate() const override;
183 protected:
184 FakeCompositorTimingHistory(scoped_ptr<RenderingStatsInstrumentation>
185 rendering_stats_instrumentation_owned);
187 scoped_ptr<RenderingStatsInstrumentation>
188 rendering_stats_instrumentation_owned_;
190 base::TimeDelta begin_main_frame_to_commit_duration_;
191 base::TimeDelta commit_to_ready_to_activate_duration_;
192 base::TimeDelta prepare_tiles_duration_;
193 base::TimeDelta activate_duration_;
194 base::TimeDelta draw_duration_;
196 private:
197 DISALLOW_COPY_AND_ASSIGN(FakeCompositorTimingHistory);
200 class TestScheduler : public Scheduler {
201 public:
202 static scoped_ptr<TestScheduler> Create(
203 base::SimpleTestTickClock* now_src,
204 SchedulerClient* client,
205 const SchedulerSettings& scheduler_settings,
206 int layer_tree_host_id,
207 OrderedSimpleTaskRunner* task_runner,
208 BeginFrameSource* external_frame_source,
209 scoped_ptr<CompositorTimingHistory> compositor_timing_history);
211 // Extra test helper functionality
212 bool IsBeginRetroFrameArgsEmpty() const {
213 return begin_retro_frame_args_.empty();
216 bool SwapThrottled() const { return state_machine_.SwapThrottled(); }
218 bool CanStart() const { return state_machine_.CanStartForTesting(); }
220 bool NeedsBeginMainFrame() const {
221 return state_machine_.needs_begin_main_frame();
224 BeginFrameSource& frame_source() { return *frame_source_; }
225 bool FrameProductionThrottled() { return throttle_frame_production_; }
227 bool MainThreadMissedLastDeadline() const {
228 return state_machine_.main_thread_missed_last_deadline();
231 ~TestScheduler() override;
233 base::TimeDelta BeginImplFrameInterval() {
234 return begin_impl_frame_tracker_.Interval();
237 protected:
238 // Overridden from Scheduler.
239 base::TimeTicks Now() const override;
241 private:
242 TestScheduler(
243 base::SimpleTestTickClock* now_src,
244 SchedulerClient* client,
245 const SchedulerSettings& scheduler_settings,
246 int layer_tree_host_id,
247 OrderedSimpleTaskRunner* task_runner,
248 BeginFrameSource* external_frame_source,
249 scoped_ptr<TestSyntheticBeginFrameSource> synthetic_frame_source,
250 scoped_ptr<TestBackToBackBeginFrameSource> unthrottled_frame_source,
251 scoped_ptr<CompositorTimingHistory> compositor_timing_history);
253 base::SimpleTestTickClock* now_src_;
255 DISALLOW_COPY_AND_ASSIGN(TestScheduler);
258 } // namespace cc
260 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_