2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef CCSchedulerTestCommon_h
26 #define CCSchedulerTestCommon_h
28 #include "cc/CCDelayBasedTimeSource.h"
29 #include "cc/CCThread.h"
30 #include <gtest/gtest.h>
31 #include <wtf/OwnPtr.h>
33 namespace WebKitTests {
35 class FakeCCTimeSourceClient : public WebCore::CCTimeSourceClient {
37 FakeCCTimeSourceClient() { reset(); }
38 void reset() { m_tickCalled = false; }
39 bool tickCalled() const { return m_tickCalled; }
41 virtual void onTimerTick() { m_tickCalled = true; }
47 class FakeCCThread : public WebCore::CCThread {
49 FakeCCThread() { reset(); }
52 m_pendingTaskDelay = 0;
53 m_pendingTask.clear();
56 bool hasPendingTask() const { return m_pendingTask; }
59 ASSERT(m_pendingTask);
60 OwnPtr<Task> task = m_pendingTask.release();
64 long long pendingDelay() const
66 EXPECT_TRUE(hasPendingTask());
67 return m_pendingTaskDelay;
70 virtual void postTask(PassOwnPtr<Task>) { ASSERT_NOT_REACHED(); }
71 virtual void postDelayedTask(PassOwnPtr<Task> task, long long delay)
73 EXPECT_TRUE(!hasPendingTask());
75 m_pendingTaskDelay = delay;
77 virtual WTF::ThreadIdentifier threadID() const { ASSERT_NOT_REACHED(); return 0; }
80 OwnPtr<Task> m_pendingTask;
81 long long m_pendingTaskDelay;
84 class FakeCCTimeSource : public WebCore::CCTimeSource {
90 virtual ~FakeCCTimeSource() { }
92 virtual void setClient(WebCore::CCTimeSourceClient* client) { m_client = client; }
93 virtual void setActive(bool b) { m_active = b; }
99 m_client->onTimerTick();
104 WebCore::CCTimeSourceClient* m_client;
107 class FakeCCDelayBasedTimeSource : public WebCore::CCDelayBasedTimeSource {
109 static PassRefPtr<FakeCCDelayBasedTimeSource> create(double intervalMs, WebCore::CCThread* thread)
111 return adoptRef(new FakeCCDelayBasedTimeSource(intervalMs, thread));
114 void setMonotonicallyIncreasingTimeMs(double time) { m_monotonicallyIncreasingTimeMs = time; }
115 virtual double monotonicallyIncreasingTimeMs() const { return m_monotonicallyIncreasingTimeMs; }
118 FakeCCDelayBasedTimeSource(double intervalMs, WebCore::CCThread* thread)
119 : CCDelayBasedTimeSource(intervalMs, thread)
120 , m_monotonicallyIncreasingTimeMs(0) { }
122 double m_monotonicallyIncreasingTimeMs;
127 #endif // CCSchedulerTestCommon_h