OLD | NEW |
1 // Copyright 2012 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 |
| 5 #ifndef CCSchedulerTestCommon_h |
| 6 #define CCSchedulerTestCommon_h |
| 7 |
| 8 #include "CCDelayBasedTimeSource.h" |
| 9 #include "CCFrameRateController.h" |
| 10 #include "CCThread.h" |
| 11 #include "base/threading/platform_thread.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include <wtf/OwnPtr.h> |
| 14 |
| 15 namespace WebKitTests { |
| 16 |
| 17 class FakeCCTimeSourceClient : public cc::CCTimeSourceClient { |
| 18 public: |
| 19 FakeCCTimeSourceClient() { reset(); } |
| 20 void reset() { m_tickCalled = false; } |
| 21 bool tickCalled() const { return m_tickCalled; } |
| 22 |
| 23 virtual void onTimerTick() OVERRIDE; |
| 24 |
| 25 protected: |
| 26 bool m_tickCalled; |
| 27 }; |
| 28 |
| 29 class FakeCCThread : public cc::CCThread { |
| 30 public: |
| 31 FakeCCThread(); |
| 32 virtual ~FakeCCThread(); |
| 33 |
| 34 void reset() |
| 35 { |
| 36 m_pendingTaskDelay = 0; |
| 37 m_pendingTask.clear(); |
| 38 m_runPendingTaskOnOverwrite = false; |
| 39 } |
| 40 |
| 41 void runPendingTaskOnOverwrite(bool enable) |
| 42 { |
| 43 m_runPendingTaskOnOverwrite = enable; |
| 44 } |
| 45 |
| 46 bool hasPendingTask() const { return m_pendingTask; } |
| 47 void runPendingTask() |
| 48 { |
| 49 ASSERT(m_pendingTask); |
| 50 OwnPtr<Task> task = m_pendingTask.release(); |
| 51 task->performTask(); |
| 52 } |
| 53 |
| 54 long long pendingDelayMs() const |
| 55 { |
| 56 EXPECT_TRUE(hasPendingTask()); |
| 57 return m_pendingTaskDelay; |
| 58 } |
| 59 |
| 60 virtual void postTask(PassOwnPtr<Task>) OVERRIDE; |
| 61 virtual void postDelayedTask(PassOwnPtr<Task> task, long long delay) OVERRID
E; |
| 62 virtual base::PlatformThreadId threadID() const OVERRIDE; |
| 63 |
| 64 protected: |
| 65 OwnPtr<Task> m_pendingTask; |
| 66 long long m_pendingTaskDelay; |
| 67 bool m_runPendingTaskOnOverwrite; |
| 68 }; |
| 69 |
| 70 class FakeCCTimeSource : public cc::CCTimeSource { |
| 71 public: |
| 72 FakeCCTimeSource() |
| 73 : m_active(false) |
| 74 , m_client(0) |
| 75 { |
| 76 turnOffVerifier(); |
| 77 } |
| 78 |
| 79 virtual ~FakeCCTimeSource() { } |
| 80 |
| 81 virtual void setClient(cc::CCTimeSourceClient* client) OVERRIDE; |
| 82 virtual void setActive(bool b) OVERRIDE; |
| 83 virtual bool active() const OVERRIDE; |
| 84 virtual void setTimebaseAndInterval(base::TimeTicks timebase, base::TimeDelt
a interval) OVERRIDE { } |
| 85 virtual base::TimeTicks lastTickTime() OVERRIDE; |
| 86 virtual base::TimeTicks nextTickTime() OVERRIDE; |
| 87 |
| 88 void tick() |
| 89 { |
| 90 ASSERT(m_active); |
| 91 if (m_client) |
| 92 m_client->onTimerTick(); |
| 93 } |
| 94 |
| 95 void setNextTickTime(base::TimeTicks nextTickTime) { m_nextTickTime = nextTi
ckTime; } |
| 96 |
| 97 protected: |
| 98 bool m_active; |
| 99 base::TimeTicks m_nextTickTime; |
| 100 cc::CCTimeSourceClient* m_client; |
| 101 }; |
| 102 |
| 103 class FakeCCDelayBasedTimeSource : public cc::CCDelayBasedTimeSource { |
| 104 public: |
| 105 static PassRefPtr<FakeCCDelayBasedTimeSource> create(base::TimeDelta interva
l, cc::CCThread* thread) |
| 106 { |
| 107 return adoptRef(new FakeCCDelayBasedTimeSource(interval, thread)); |
| 108 } |
| 109 |
| 110 void setNow(base::TimeTicks time) { m_now = time; } |
| 111 virtual base::TimeTicks now() const OVERRIDE; |
| 112 |
| 113 protected: |
| 114 FakeCCDelayBasedTimeSource(base::TimeDelta interval, cc::CCThread* thread) |
| 115 : CCDelayBasedTimeSource(interval, thread) |
| 116 { |
| 117 } |
| 118 |
| 119 base::TimeTicks m_now; |
| 120 }; |
| 121 |
| 122 class FakeCCFrameRateController : public cc::CCFrameRateController { |
| 123 public: |
| 124 FakeCCFrameRateController(PassRefPtr<cc::CCTimeSource> timer) : cc::CCFrameR
ateController(timer) { } |
| 125 |
| 126 int numFramesPending() const { return m_numFramesPending; } |
| 127 }; |
| 128 |
| 129 } |
| 130 |
| 131 #endif // CCSchedulerTestCommon_h |
OLD | NEW |