Adds initial key systems support for Chromecast.
[chromium-blink-merge.git] / cc / test / scheduler_test_common.h
bloba50233653410836c44189d5d53381dfaf0d6d3b3
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() { Reset(); }
23 void Reset() { tick_called_ = false; }
24 bool TickCalled() const { return tick_called_; }
26 // TimeSourceClient implementation.
27 virtual 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 virtual base::TimeTicks Now() const OVERRIDE;
44 protected:
45 FakeDelayBasedTimeSource(base::TimeDelta interval,
46 base::SingleThreadTaskRunner* task_runner)
47 : DelayBasedTimeSource(interval, task_runner) {}
48 virtual ~FakeDelayBasedTimeSource() {}
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 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 {
77 public:
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,
89 client,
90 scheduler_settings,
91 layer_tree_host_id,
92 test_task_runner));
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();
108 protected:
109 // Overridden from Scheduler.
110 virtual base::TimeTicks Now() const OVERRIDE;
112 private:
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_;
123 } // namespace cc
125 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_