Policy: check MustRemainInstalled in addition to UserMayModifySettings before offerin...
[chromium-blink-merge.git] / cc / test / scheduler_test_common.cc
blob03e65ab2dd3d99d9ee5b6c05832f9581db45eabe
1 // Copyright 2012 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 #include "cc/test/scheduler_test_common.h"
7 #include <string>
9 #include "base/logging.h"
11 namespace cc {
13 void FakeTimeSourceClient::OnTimerTick() {
14 tick_called_ = true;
17 base::TimeTicks FakeDelayBasedTimeSource::Now() const { return now_; }
19 TestDelayBasedTimeSource::TestDelayBasedTimeSource(
20 scoped_refptr<TestNowSource> now_src,
21 base::TimeDelta interval,
22 OrderedSimpleTaskRunner* task_runner)
23 : DelayBasedTimeSource(interval, task_runner), now_src_(now_src) {
26 base::TimeTicks TestDelayBasedTimeSource::Now() const {
27 return now_src_->Now();
30 std::string TestDelayBasedTimeSource::TypeString() const {
31 return "TestDelayBasedTimeSource";
34 TestDelayBasedTimeSource::~TestDelayBasedTimeSource() {
37 void FakeBeginFrameSource::DidFinishFrame(size_t remaining_frames) {
38 remaining_frames_ = remaining_frames;
40 void FakeBeginFrameSource::AsValueInto(base::debug::TracedValue* dict) const {
41 dict->SetString("type", "FakeBeginFrameSource");
42 BeginFrameSourceMixIn::AsValueInto(dict);
45 TestBackToBackBeginFrameSource::TestBackToBackBeginFrameSource(
46 scoped_refptr<TestNowSource> now_src,
47 base::SingleThreadTaskRunner* task_runner)
48 : BackToBackBeginFrameSource(task_runner), now_src_(now_src) {
51 TestBackToBackBeginFrameSource::~TestBackToBackBeginFrameSource() {
54 base::TimeTicks TestBackToBackBeginFrameSource::Now() {
55 return now_src_->Now();
58 TestSyntheticBeginFrameSource::TestSyntheticBeginFrameSource(
59 scoped_refptr<DelayBasedTimeSource> time_source)
60 : SyntheticBeginFrameSource(time_source) {
63 TestSyntheticBeginFrameSource::~TestSyntheticBeginFrameSource() {
66 TestSchedulerFrameSourcesConstructor::TestSchedulerFrameSourcesConstructor(
67 OrderedSimpleTaskRunner* test_task_runner,
68 TestNowSource* now_src)
69 : test_task_runner_(test_task_runner), now_src_(now_src) {
71 TestSchedulerFrameSourcesConstructor::~TestSchedulerFrameSourcesConstructor() {
74 BeginFrameSource*
75 TestSchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource(
76 Scheduler* scheduler) {
77 if (scheduler->settings_.use_external_begin_frame_source) {
78 return SchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource(
79 scheduler);
80 } else {
81 TRACE_EVENT1(
82 "cc",
83 "TestSchedulerFrameSourcesConstructor::ConstructPrimaryFrameSource",
84 "source",
85 "TestSyntheticBeginFrameSource");
86 scoped_ptr<TestSyntheticBeginFrameSource> synthetic_source =
87 TestSyntheticBeginFrameSource::Create(
88 now_src_, test_task_runner_, BeginFrameArgs::DefaultInterval());
90 DCHECK(!scheduler->vsync_observer_);
91 scheduler->vsync_observer_ = synthetic_source.get();
93 DCHECK(!scheduler->primary_frame_source_internal_);
94 scheduler->primary_frame_source_internal_ = synthetic_source.Pass();
95 return scheduler->primary_frame_source_internal_.get();
99 BeginFrameSource*
100 TestSchedulerFrameSourcesConstructor::ConstructBackgroundFrameSource(
101 Scheduler* scheduler) {
102 TRACE_EVENT1(
103 "cc",
104 "TestSchedulerFrameSourcesConstructor::ConstructBackgroundFrameSource",
105 "source",
106 "TestSyntheticBeginFrameSource");
107 DCHECK(!(scheduler->background_frame_source_internal_));
108 scheduler->background_frame_source_internal_ =
109 TestSyntheticBeginFrameSource::Create(
110 now_src_, test_task_runner_, base::TimeDelta::FromSeconds(1));
111 return scheduler->background_frame_source_internal_.get();
114 BeginFrameSource*
115 TestSchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource(
116 Scheduler* scheduler) {
117 TRACE_EVENT1(
118 "cc",
119 "TestSchedulerFrameSourcesConstructor::ConstructUnthrottledFrameSource",
120 "source", "TestBackToBackBeginFrameSource");
121 DCHECK(!scheduler->unthrottled_frame_source_internal_);
122 scheduler->unthrottled_frame_source_internal_ =
123 TestBackToBackBeginFrameSource::Create(now_src_, test_task_runner_);
124 return scheduler->unthrottled_frame_source_internal_.get();
127 TestScheduler::TestScheduler(
128 scoped_refptr<TestNowSource> now_src,
129 SchedulerClient* client,
130 const SchedulerSettings& scheduler_settings,
131 int layer_tree_host_id,
132 const scoped_refptr<OrderedSimpleTaskRunner>& test_task_runner,
133 base::PowerMonitor* power_monitor,
134 TestSchedulerFrameSourcesConstructor* frame_sources_constructor,
135 scoped_ptr<BeginFrameSource> external_begin_frame_source)
136 : Scheduler(client,
137 scheduler_settings,
138 layer_tree_host_id,
139 test_task_runner,
140 power_monitor,
141 external_begin_frame_source.Pass(),
142 frame_sources_constructor),
143 now_src_(now_src) {
146 base::TimeTicks TestScheduler::Now() const {
147 return now_src_->Now();
150 TestScheduler::~TestScheduler() {
153 } // namespace cc