OLD | NEW |
| (Empty) |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "config.h" | |
6 | |
7 #include <public/WebLayerTreeView.h> | |
8 | |
9 #include "CompositorFakeWebGraphicsContext3D.h" | |
10 #include "FakeWebCompositorOutputSurface.h" | |
11 #include "WebLayerTreeViewTestCommon.h" | |
12 #include <gmock/gmock.h> | |
13 #include <public/Platform.h> | |
14 #include <public/WebCompositor.h> | |
15 #include <public/WebLayer.h> | |
16 #include <public/WebLayerTreeViewClient.h> | |
17 #include <public/WebThread.h> | |
18 #include <wtf/RefCounted.h> | |
19 #include <wtf/RefPtr.h> | |
20 | |
21 using namespace WebKit; | |
22 using testing::Mock; | |
23 using testing::Test; | |
24 | |
25 namespace { | |
26 | |
27 class MockWebLayerTreeViewClientForThreadedTests : public MockWebLayerTreeViewCl
ient { | |
28 public: | |
29 virtual void didBeginFrame() OVERRIDE | |
30 { | |
31 WebKit::Platform::current()->currentThread()->exitRunLoop(); | |
32 MockWebLayerTreeViewClient::didBeginFrame(); | |
33 } | |
34 }; | |
35 | |
36 class WebLayerTreeViewTestBase : public Test { | |
37 protected: | |
38 virtual void initializeCompositor() = 0; | |
39 virtual WebLayerTreeViewClient* client() = 0; | |
40 | |
41 public: | |
42 virtual void SetUp() | |
43 { | |
44 initializeCompositor(); | |
45 m_rootLayer = adoptPtr(WebLayer::create()); | |
46 ASSERT_TRUE(m_view = adoptPtr(WebLayerTreeView::create(client(), *m_root
Layer, WebLayerTreeView::Settings()))); | |
47 m_view->setSurfaceReady(); | |
48 } | |
49 | |
50 virtual void TearDown() | |
51 { | |
52 Mock::VerifyAndClearExpectations(client()); | |
53 | |
54 m_rootLayer.clear(); | |
55 m_view.clear(); | |
56 WebKit::WebCompositor::shutdown(); | |
57 } | |
58 | |
59 protected: | |
60 OwnPtr<WebLayer> m_rootLayer; | |
61 OwnPtr<WebLayerTreeView> m_view; | |
62 }; | |
63 | |
64 class WebLayerTreeViewSingleThreadTest : public WebLayerTreeViewTestBase { | |
65 protected: | |
66 void composite() | |
67 { | |
68 m_view->composite(); | |
69 } | |
70 | |
71 virtual void initializeCompositor() OVERRIDE | |
72 { | |
73 WebKit::WebCompositor::initialize(0); | |
74 } | |
75 | |
76 virtual WebLayerTreeViewClient* client() OVERRIDE | |
77 { | |
78 return &m_client; | |
79 } | |
80 | |
81 MockWebLayerTreeViewClient m_client; | |
82 }; | |
83 | |
84 class CancelableTaskWrapper : public RefCounted<CancelableTaskWrapper> { | |
85 class Task : public WebThread::Task { | |
86 public: | |
87 Task(CancelableTaskWrapper* cancelableTask) | |
88 : m_cancelableTask(cancelableTask) | |
89 { | |
90 } | |
91 | |
92 private: | |
93 virtual void run() OVERRIDE | |
94 { | |
95 m_cancelableTask->runIfNotCanceled(); | |
96 } | |
97 | |
98 RefPtr<CancelableTaskWrapper> m_cancelableTask; | |
99 }; | |
100 | |
101 public: | |
102 CancelableTaskWrapper(PassOwnPtr<WebThread::Task> task) | |
103 : m_task(task) | |
104 { | |
105 } | |
106 | |
107 void cancel() | |
108 { | |
109 m_task.clear(); | |
110 } | |
111 | |
112 WebThread::Task* createTask() | |
113 { | |
114 ASSERT(m_task); | |
115 return new Task(this); | |
116 } | |
117 | |
118 void runIfNotCanceled() | |
119 { | |
120 if (!m_task) | |
121 return; | |
122 m_task->run(); | |
123 m_task.clear(); | |
124 } | |
125 | |
126 private: | |
127 OwnPtr<WebThread::Task> m_task; | |
128 }; | |
129 | |
130 class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase { | |
131 protected: | |
132 class TimeoutTask : public WebThread::Task { | |
133 virtual void run() OVERRIDE | |
134 { | |
135 WebKit::Platform::current()->currentThread()->exitRunLoop(); | |
136 } | |
137 }; | |
138 | |
139 void composite() | |
140 { | |
141 m_view->setNeedsRedraw(); | |
142 RefPtr<CancelableTaskWrapper> timeoutTask = adoptRef(new CancelableTaskW
rapper(adoptPtr(new TimeoutTask()))); | |
143 WebKit::Platform::current()->currentThread()->postDelayedTask(timeoutTas
k->createTask(), 5000); | |
144 WebKit::Platform::current()->currentThread()->enterRunLoop(); | |
145 timeoutTask->cancel(); | |
146 m_view->finishAllRendering(); | |
147 } | |
148 | |
149 virtual void initializeCompositor() OVERRIDE | |
150 { | |
151 m_webThread = adoptPtr(WebKit::Platform::current()->createThread("WebLay
erTreeViewTest")); | |
152 WebCompositor::initialize(m_webThread.get()); | |
153 } | |
154 | |
155 virtual WebLayerTreeViewClient* client() OVERRIDE | |
156 { | |
157 return &m_client; | |
158 } | |
159 | |
160 MockWebLayerTreeViewClientForThreadedTests m_client; | |
161 OwnPtr<WebThread> m_webThread; | |
162 }; | |
163 | |
164 TEST_F(WebLayerTreeViewSingleThreadTest, InstrumentationCallbacks) | |
165 { | |
166 ::testing::InSequence dummy; | |
167 | |
168 EXPECT_CALL(m_client, willCommit()); | |
169 EXPECT_CALL(m_client, didCommit()); | |
170 EXPECT_CALL(m_client, didBeginFrame()); | |
171 | |
172 composite(); | |
173 } | |
174 | |
175 TEST_F(WebLayerTreeViewThreadedTest, InstrumentationCallbacks) | |
176 { | |
177 ::testing::InSequence dummy; | |
178 | |
179 EXPECT_CALL(m_client, willBeginFrame()); | |
180 EXPECT_CALL(m_client, willCommit()); | |
181 EXPECT_CALL(m_client, didCommit()); | |
182 EXPECT_CALL(m_client, didBeginFrame()); | |
183 | |
184 composite(); | |
185 } | |
186 | |
187 } // namespace | |
OLD | NEW |