OLD | NEW |
---|---|
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_TEST_SCHEDULER_TEST_COMMON_H_ | 5 #ifndef CC_TEST_SCHEDULER_TEST_COMMON_H_ |
6 #define CC_TEST_SCHEDULER_TEST_COMMON_H_ | 6 #define CC_TEST_SCHEDULER_TEST_COMMON_H_ |
7 | 7 |
8 #include <string> | |
9 | |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "base/time/time.h" | 12 #include "base/time/time.h" |
11 #include "cc/scheduler/delay_based_time_source.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" | |
12 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
13 | 17 |
14 namespace cc { | 18 namespace cc { |
15 | 19 |
16 class FakeTimeSourceClient : public TimeSourceClient { | 20 class FakeTimeSourceClient : public TimeSourceClient { |
17 public: | 21 public: |
18 FakeTimeSourceClient() { Reset(); } | 22 FakeTimeSourceClient() { Reset(); } |
19 void Reset() { tick_called_ = false; } | 23 void Reset() { tick_called_ = false; } |
20 bool TickCalled() const { return tick_called_; } | 24 bool TickCalled() const { return tick_called_; } |
21 | 25 |
(...skipping 17 matching lines...) Expand all Loading... | |
39 | 43 |
40 protected: | 44 protected: |
41 FakeDelayBasedTimeSource(base::TimeDelta interval, | 45 FakeDelayBasedTimeSource(base::TimeDelta interval, |
42 base::SingleThreadTaskRunner* task_runner) | 46 base::SingleThreadTaskRunner* task_runner) |
43 : DelayBasedTimeSource(interval, task_runner) {} | 47 : DelayBasedTimeSource(interval, task_runner) {} |
44 virtual ~FakeDelayBasedTimeSource() {} | 48 virtual ~FakeDelayBasedTimeSource() {} |
45 | 49 |
46 base::TimeTicks now_; | 50 base::TimeTicks now_; |
47 }; | 51 }; |
48 | 52 |
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)); | |
61 } | |
62 | |
63 protected: | |
64 TestDelayBasedTimeSource(scoped_refptr<TestNowSource> now_src, | |
65 base::TimeDelta interval, | |
66 OrderedSimpleTaskRunner* task_runner); | |
67 | |
68 // Overridden from DelayBasedTimeSource | |
69 virtual ~TestDelayBasedTimeSource(); | |
70 virtual base::TimeTicks Now() const OVERRIDE; | |
71 virtual std::string TypeString() const OVERRIDE; | |
72 | |
73 scoped_refptr<TestNowSource> now_src_; | |
74 }; | |
75 | |
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) { | |
brianderson
2014/08/21 21:48:52
Should this body move to the cc file?
| |
83 // A bunch of tests require Now() to be > BeginFrameArgs::DefaultInterval() | |
brianderson
2014/08/21 21:48:52
Please describe why in the comment.
| |
84 now_src->AdvanceNow(base::TimeDelta::FromMilliseconds(100)); | |
85 | |
86 scoped_refptr<OrderedSimpleTaskRunner> test_task_runner = | |
87 new OrderedSimpleTaskRunner(now_src, true); | |
brianderson
2014/08/21 21:48:52
bool automatically_advance_now = true;
...
new Ord
| |
88 return make_scoped_ptr(new TestScheduler(now_src, | |
89 client, | |
90 scheduler_settings, | |
91 layer_tree_host_id, | |
92 test_task_runner)); | |
93 } | |
94 | |
95 // Extra test helper functionality | |
96 bool IsBeginRetroFrameArgsEmpty() const { | |
97 return begin_retro_frame_args_.empty(); | |
98 } | |
99 | |
100 bool IsSyntheticBeginFrameSourceActive() const { | |
101 return synthetic_begin_frame_source_->IsActive(); | |
102 } | |
103 | |
104 OrderedSimpleTaskRunner& task_runner() { return *test_task_runner_; } | |
105 | |
106 virtual ~TestScheduler(); | |
107 | |
108 protected: | |
109 // Overridden from Scheduler. | |
110 virtual base::TimeTicks Now() const OVERRIDE; | |
111 | |
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); | |
118 | |
119 scoped_refptr<TestNowSource> now_src_; | |
120 OrderedSimpleTaskRunner* test_task_runner_; | |
121 }; | |
122 | |
49 } // namespace cc | 123 } // namespace cc |
50 | 124 |
51 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ | 125 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ |
OLD | NEW |