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