tizen beta release
[framework/web/webkit-efl.git] / Source / WebKit / chromium / tests / CCSchedulerTestCommon.h
1 /*
2  * Copyright (C) 2011 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
23  */
24
25 #ifndef CCSchedulerTestCommon_h
26 #define CCSchedulerTestCommon_h
27
28 #include "cc/CCDelayBasedTimeSource.h"
29 #include "cc/CCThread.h"
30 #include <gtest/gtest.h>
31 #include <wtf/OwnPtr.h>
32
33 namespace WebKitTests {
34
35 class FakeCCTimeSourceClient : public WebCore::CCTimeSourceClient {
36 public:
37     FakeCCTimeSourceClient() { reset(); }
38     void reset() { m_tickCalled = false; }
39     bool tickCalled() const { return m_tickCalled; }
40
41     virtual void onTimerTick() { m_tickCalled = true; }
42
43 protected:
44     bool m_tickCalled;
45 };
46
47 class FakeCCThread : public WebCore::CCThread {
48 public:
49     FakeCCThread() { reset(); }
50     void reset()
51     {
52         m_pendingTaskDelay = 0;
53         m_pendingTask.clear();
54     }
55
56     bool hasPendingTask() const { return m_pendingTask; }
57     void runPendingTask()
58     {
59         ASSERT(m_pendingTask);
60         OwnPtr<Task> task = m_pendingTask.release();
61         task->performTask();
62     }
63
64     long long pendingDelay() const
65     {
66         EXPECT_TRUE(hasPendingTask());
67         return m_pendingTaskDelay;
68     }
69
70     virtual void postTask(PassOwnPtr<Task>) { ASSERT_NOT_REACHED(); }
71     virtual void postDelayedTask(PassOwnPtr<Task> task, long long delay)
72     {
73         EXPECT_TRUE(!hasPendingTask());
74         m_pendingTask = task;
75         m_pendingTaskDelay = delay;
76     }
77     virtual WTF::ThreadIdentifier threadID() const { ASSERT_NOT_REACHED(); return 0; }
78
79 protected:
80     OwnPtr<Task> m_pendingTask;
81     long long m_pendingTaskDelay;
82 };
83
84 class FakeCCTimeSource : public WebCore::CCTimeSource {
85 public:
86     FakeCCTimeSource()
87         : m_active(false)
88         , m_client(0) { }
89
90     virtual ~FakeCCTimeSource() { }
91
92     virtual void setClient(WebCore::CCTimeSourceClient* client) { m_client = client; }
93     virtual void setActive(bool b) { m_active = b; }
94
95     void tick()
96     {
97         ASSERT(m_active);
98         if (m_client)
99             m_client->onTimerTick();
100     }
101
102 protected:
103     bool m_active;
104     WebCore::CCTimeSourceClient* m_client;
105 };
106
107 class FakeCCDelayBasedTimeSource : public WebCore::CCDelayBasedTimeSource {
108 public:
109     static PassRefPtr<FakeCCDelayBasedTimeSource> create(double intervalMs, WebCore::CCThread* thread)
110     {
111         return adoptRef(new FakeCCDelayBasedTimeSource(intervalMs, thread));
112     }
113
114     void setMonotonicallyIncreasingTimeMs(double time) { m_monotonicallyIncreasingTimeMs = time; }
115     virtual double monotonicallyIncreasingTimeMs() const { return m_monotonicallyIncreasingTimeMs; }
116
117 protected:
118     FakeCCDelayBasedTimeSource(double intervalMs, WebCore::CCThread* thread)
119         : CCDelayBasedTimeSource(intervalMs, thread)
120         , m_monotonicallyIncreasingTimeMs(0) { }
121
122     double m_monotonicallyIncreasingTimeMs;
123 };
124
125 }
126
127 #endif // CCSchedulerTestCommon_h