| 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 FakeTimeSource : public cc::TimeSource { | 31 class FakeTimeSource : public cc::TimeSource { |
| 66 public: | 32 public: |
| 67 FakeTimeSource() : active_(false), client_(0) {} | 33 FakeTimeSource() : active_(false), client_(0) {} |
| 68 | 34 |
| 69 virtual void SetClient(cc::TimeSourceClient* client) OVERRIDE; | 35 virtual void SetClient(cc::TimeSourceClient* client) OVERRIDE; |
| 70 virtual void SetActive(bool b) OVERRIDE; | 36 virtual void SetActive(bool b) OVERRIDE; |
| 71 virtual bool Active() const OVERRIDE; | 37 virtual bool Active() const OVERRIDE; |
| 72 virtual void SetTimebaseAndInterval(base::TimeTicks timebase, | 38 virtual void SetTimebaseAndInterval(base::TimeTicks timebase, |
| 73 base::TimeDelta interval) OVERRIDE {} | 39 base::TimeDelta interval) OVERRIDE {} |
| 74 virtual base::TimeTicks LastTickTime() OVERRIDE; | 40 virtual base::TimeTicks LastTickTime() OVERRIDE; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 88 virtual ~FakeTimeSource() {} | 54 virtual ~FakeTimeSource() {} |
| 89 | 55 |
| 90 bool active_; | 56 bool active_; |
| 91 base::TimeTicks next_tick_time_; | 57 base::TimeTicks next_tick_time_; |
| 92 cc::TimeSourceClient* client_; | 58 cc::TimeSourceClient* client_; |
| 93 }; | 59 }; |
| 94 | 60 |
| 95 class FakeDelayBasedTimeSource : public cc::DelayBasedTimeSource { | 61 class FakeDelayBasedTimeSource : public cc::DelayBasedTimeSource { |
| 96 public: | 62 public: |
| 97 static scoped_refptr<FakeDelayBasedTimeSource> Create( | 63 static scoped_refptr<FakeDelayBasedTimeSource> Create( |
| 98 base::TimeDelta interval, cc::Thread* thread) { | 64 base::TimeDelta interval, base::SingleThreadTaskRunner* task_runner) { |
| 99 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, thread)); | 65 return make_scoped_refptr(new FakeDelayBasedTimeSource(interval, |
| 66 task_runner)); |
| 100 } | 67 } |
| 101 | 68 |
| 102 void SetNow(base::TimeTicks time) { now_ = time; } | 69 void SetNow(base::TimeTicks time) { now_ = time; } |
| 103 virtual base::TimeTicks Now() const OVERRIDE; | 70 virtual base::TimeTicks Now() const OVERRIDE; |
| 104 | 71 |
| 105 protected: | 72 protected: |
| 106 FakeDelayBasedTimeSource(base::TimeDelta interval, cc::Thread* thread) | 73 FakeDelayBasedTimeSource(base::TimeDelta interval, |
| 107 : DelayBasedTimeSource(interval, thread) {} | 74 base::SingleThreadTaskRunner* task_runner) |
| 75 : DelayBasedTimeSource(interval, task_runner) {} |
| 108 virtual ~FakeDelayBasedTimeSource() {} | 76 virtual ~FakeDelayBasedTimeSource() {} |
| 109 | 77 |
| 110 base::TimeTicks now_; | 78 base::TimeTicks now_; |
| 111 }; | 79 }; |
| 112 | 80 |
| 113 class FakeFrameRateController : public cc::FrameRateController { | 81 class FakeFrameRateController : public cc::FrameRateController { |
| 114 public: | 82 public: |
| 115 explicit FakeFrameRateController(scoped_refptr<cc::TimeSource> timer) | 83 explicit FakeFrameRateController(scoped_refptr<cc::TimeSource> timer) |
| 116 : cc::FrameRateController(timer) {} | 84 : cc::FrameRateController(timer) {} |
| 117 | 85 |
| 118 int NumFramesPending() const { return num_frames_pending_; } | 86 int NumFramesPending() const { return num_frames_pending_; } |
| 119 }; | 87 }; |
| 120 | 88 |
| 121 } // namespace cc | 89 } // namespace cc |
| 122 | 90 |
| 123 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ | 91 #endif // CC_TEST_SCHEDULER_TEST_COMMON_H_ |
| OLD | NEW |