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 "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 void Reset() { tick_called_ = false; } | 21 void Reset() { tick_called_ = false; } |
22 bool TickCalled() const { return tick_called_; } | 22 bool TickCalled() const { return tick_called_; } |
23 | 23 |
24 // TimeSourceClient implementation. | 24 // TimeSourceClient implementation. |
25 virtual void OnTimerTick() OVERRIDE; | 25 virtual void OnTimerTick() OVERRIDE; |
26 | 26 |
27 protected: | 27 protected: |
28 bool tick_called_; | 28 bool tick_called_; |
29 }; | 29 }; |
30 | 30 |
31 class FakeThread : public cc::Thread { | |
32 public: | |
33 FakeThread(); | |
34 virtual ~FakeThread(); | |
35 | |
36 void Reset() { | |
37 pending_task_delay_ = 0; | |
38 pending_task_.reset(); | |
39 run_pending_task_on_overwrite_ = false; | |
40 } | |
41 | |
42 void RunPendingTaskOnOverwrite(bool enable) { | |
43 run_pending_task_on_overwrite_ = enable; | |
44 } | |
45 | |
46 bool HasPendingTask() const { return pending_task_; } | |
47 void RunPendingTask(); | |
48 | |
49 int64 PendingDelayMs() const { | |
50 EXPECT_TRUE(HasPendingTask()); | |
51 return pending_task_delay_; | |
52 } | |
53 | |
54 virtual void PostTask(base::Closure cb) OVERRIDE; | |
55 virtual void PostDelayedTask(base::Closure cb, base::TimeDelta delay) | |
56 OVERRIDE; | |
57 virtual bool BelongsToCurrentThread() const OVERRIDE; | |
58 | |
59 protected: | |
60 scoped_ptr<base::Closure> pending_task_; | |
61 int64 pending_task_delay_; | |
62 bool run_pending_task_on_overwrite_; | |
63 }; | |
64 | |
65 class FakeDelayBasedTimeSource : public cc::DelayBasedTimeSource { | 31 class FakeDelayBasedTimeSource : public cc::DelayBasedTimeSource { |
66 public: | 32 public: |
67 static scoped_refptr<FakeDelayBasedTimeSource> Create( | 33 static scoped_refptr<FakeDelayBasedTimeSource> Create( |
68 base::TimeDelta interval, cc::Thread* thread) { | 34 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner) { |
69 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, thread)); | 35 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, |
| 36 task_runner)); |
70 } | 37 } |
71 | 38 |
72 void SetNow(base::TimeTicks time) { now_ = time; } | 39 void SetNow(base::TimeTicks time) { now_ = time; } |
73 virtual base::TimeTicks Now() const OVERRIDE; | 40 virtual base::TimeTicks Now() const OVERRIDE; |
74 | 41 |
75 protected: | 42 protected: |
76 FakeDelayBasedTimeSource(base::TimeDelta interval, cc::Thread* thread) | 43 FakeDelayBasedTimeSource(base::TimeDelta interval, |
77 : DelayBasedTimeSource(interval, thread) {} | 44 base::SingleThreadTaskRunner* task_runner) |
| 45 : DelayBasedTimeSource(interval, task_runner) {} |
78 virtual ~FakeDelayBasedTimeSource() {} | 46 virtual ~FakeDelayBasedTimeSource() {} |
79 | 47 |
80 base::TimeTicks now_; | 48 base::TimeTicks now_; |
81 }; | 49 }; |
82 | 50 |
83 class FakeFrameRateController : public cc::FrameRateController { | 51 class FakeFrameRateController : public cc::FrameRateController { |
84 public: | 52 public: |
85 explicit FakeFrameRateController(scoped_refptr<cc::TimeSource> timer) | 53 explicit FakeFrameRateController(scoped_refptr<cc::TimeSource> timer) |
86 : cc::FrameRateController(timer) {} | 54 : cc::FrameRateController(timer) {} |
87 | 55 |
88 int NumFramesPending() const { return num_frames_pending_; } | 56 int NumFramesPending() const { return num_frames_pending_; } |
89 }; | 57 }; |
90 | 58 |
91 } // namespace cc | 59 } // namespace cc |
92 | 60 |
93 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ | 61 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ |
OLD | NEW |