OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "config.h" | 5 #include "config.h" |
6 | 6 |
| 7 #include "base/cancelable_callback.h" |
7 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/threading/thread.h" |
| 10 #include "cc/proxy.h" |
| 11 #include "cc/thread_impl.h" |
8 #include "cc/test/compositor_fake_web_graphics_context_3d.h" | 12 #include "cc/test/compositor_fake_web_graphics_context_3d.h" |
9 #include "cc/test/fake_web_compositor_output_surface.h" | 13 #include "cc/test/fake_web_compositor_output_surface.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
11 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" | |
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor
t.h" | |
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" | 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h" |
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli
ent.h" | 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli
ent.h" |
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h" | 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h" |
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebThread.h" | 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebThread.h" |
17 #include "web_layer_impl.h" | 19 #include "webkit/compositor_bindings/test/web_layer_tree_view_test_common.h" |
18 #include "web_layer_tree_view_impl.h" | 20 #include "webkit/compositor_bindings/web_layer_impl.h" |
19 #include "web_layer_tree_view_test_common.h" | 21 #include "webkit/compositor_bindings/web_layer_tree_view_impl.h" |
20 | 22 |
21 using namespace WebKit; | 23 using namespace WebKit; |
22 using testing::Mock; | 24 using testing::Mock; |
23 using testing::Test; | 25 using testing::Test; |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 class MockWebLayerTreeViewClientForThreadedTests : public MockWebLayerTreeViewCl
ient { | 29 class MockWebLayerTreeViewClientForThreadedTests : public MockWebLayerTreeViewCl
ient { |
28 public: | 30 public: |
29 virtual void didBeginFrame() OVERRIDE | 31 virtual void didBeginFrame() OVERRIDE |
30 { | 32 { |
31 WebKit::Platform::current()->currentThread()->exitRunLoop(); | 33 MessageLoop::current()->Quit(); |
32 MockWebLayerTreeViewClient::didBeginFrame(); | 34 MockWebLayerTreeViewClient::didBeginFrame(); |
33 } | 35 } |
34 }; | 36 }; |
35 | 37 |
36 class WebLayerTreeViewTestBase : public Test { | 38 class WebLayerTreeViewTestBase : public Test { |
37 protected: | 39 protected: |
38 virtual void initializeCompositor() = 0; | 40 virtual void initializeCompositor() = 0; |
39 virtual WebLayerTreeViewClient* client() = 0; | 41 virtual WebLayerTreeViewClient* client() = 0; |
40 | 42 |
41 public: | 43 public: |
42 virtual void SetUp() | 44 virtual void SetUp() |
43 { | 45 { |
44 initializeCompositor(); | 46 initializeCompositor(); |
45 m_rootLayer.reset(new WebLayerImpl); | 47 m_rootLayer.reset(new WebLayerImpl); |
46 m_view.reset(new WebLayerTreeViewImpl(client())); | 48 m_view.reset(new WebLayerTreeViewImpl(client())); |
47 ASSERT_TRUE(m_view->initialize(WebLayerTreeView::Settings())); | 49 ASSERT_TRUE(m_view->initialize(WebLayerTreeView::Settings())); |
48 m_view->setRootLayer(*m_rootLayer); | 50 m_view->setRootLayer(*m_rootLayer); |
49 m_view->setSurfaceReady(); | 51 m_view->setSurfaceReady(); |
50 } | 52 } |
51 | 53 |
52 virtual void TearDown() | 54 virtual void TearDown() |
53 { | 55 { |
54 Mock::VerifyAndClearExpectations(client()); | 56 Mock::VerifyAndClearExpectations(client()); |
55 | 57 |
56 m_rootLayer.reset(); | 58 m_rootLayer.reset(); |
57 m_view.reset(); | 59 m_view.reset(); |
58 WebKit::Platform::current()->compositorSupport()->shutdown(); | |
59 } | 60 } |
60 | 61 |
61 protected: | 62 protected: |
62 scoped_ptr<WebLayer> m_rootLayer; | 63 scoped_ptr<WebLayer> m_rootLayer; |
63 scoped_ptr<WebLayerTreeViewImpl> m_view; | 64 scoped_ptr<WebLayerTreeViewImpl> m_view; |
64 }; | 65 }; |
65 | 66 |
66 class WebLayerTreeViewSingleThreadTest : public WebLayerTreeViewTestBase { | 67 class WebLayerTreeViewSingleThreadTest : public WebLayerTreeViewTestBase { |
67 protected: | 68 protected: |
68 void composite() | 69 void composite() |
69 { | 70 { |
70 m_view->composite(); | 71 m_view->composite(); |
71 } | 72 } |
72 | 73 |
73 virtual void initializeCompositor() OVERRIDE | 74 virtual void initializeCompositor() OVERRIDE |
74 { | 75 { |
75 WebKit::Platform::current()->compositorSupport()->initialize(0); | |
76 } | 76 } |
77 | 77 |
78 virtual WebLayerTreeViewClient* client() OVERRIDE | 78 virtual WebLayerTreeViewClient* client() OVERRIDE |
79 { | 79 { |
80 return &m_client; | 80 return &m_client; |
81 } | 81 } |
82 | 82 |
83 MockWebLayerTreeViewClient m_client; | 83 MockWebLayerTreeViewClient m_client; |
84 }; | 84 }; |
85 | 85 |
86 class CancelableTaskWrapper : public base::RefCounted<CancelableTaskWrapper> { | |
87 class Task : public WebThread::Task { | |
88 public: | |
89 Task(CancelableTaskWrapper* cancelableTask) | |
90 : m_cancelableTask(cancelableTask) | |
91 { | |
92 } | |
93 | |
94 private: | |
95 virtual void run() OVERRIDE | |
96 { | |
97 m_cancelableTask->runIfNotCanceled(); | |
98 } | |
99 | |
100 scoped_refptr<CancelableTaskWrapper> m_cancelableTask; | |
101 }; | |
102 | |
103 public: | |
104 CancelableTaskWrapper(scoped_ptr<WebThread::Task> task) | |
105 : m_task(task.Pass()) | |
106 { | |
107 } | |
108 | |
109 void cancel() | |
110 { | |
111 m_task.reset(); | |
112 } | |
113 | |
114 WebThread::Task* createTask() | |
115 { | |
116 ASSERT(m_task); | |
117 return new Task(this); | |
118 } | |
119 | |
120 void runIfNotCanceled() | |
121 { | |
122 if (!m_task) | |
123 return; | |
124 m_task->run(); | |
125 m_task.reset(); | |
126 } | |
127 | |
128 private: | |
129 friend class base::RefCounted<CancelableTaskWrapper>; | |
130 ~CancelableTaskWrapper() { } | |
131 | |
132 scoped_ptr<WebThread::Task> m_task; | |
133 }; | |
134 | |
135 class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase { | 86 class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase { |
136 protected: | 87 protected: |
137 class TimeoutTask : public WebThread::Task { | 88 virtual ~WebLayerTreeViewThreadedTest() |
138 virtual void run() OVERRIDE | 89 { |
139 { | 90 cc::Proxy::setImplThread(0); |
140 WebKit::Platform::current()->currentThread()->exitRunLoop(); | 91 } |
141 } | |
142 }; | |
143 | 92 |
144 void composite() | 93 void composite() |
145 { | 94 { |
146 m_view->setNeedsRedraw(); | 95 m_view->setNeedsRedraw(); |
147 scoped_refptr<CancelableTaskWrapper> timeoutTask(new CancelableTaskWrapp
er(scoped_ptr<WebThread::Task>(new TimeoutTask()))); | 96 base::CancelableClosure timeout(base::Bind(&MessageLoop::Quit, base::Unr
etained(MessageLoop::current()))); |
148 WebKit::Platform::current()->currentThread()->postDelayedTask(timeoutTas
k->createTask(), 5000); | 97 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
149 WebKit::Platform::current()->currentThread()->enterRunLoop(); | 98 timeout.callback(), |
150 timeoutTask->cancel(); | 99 base::TimeDelta::FromSeconds(5))
; |
| 100 MessageLoop::current()->Run(); |
151 m_view->finishAllRendering(); | 101 m_view->finishAllRendering(); |
152 } | 102 } |
153 | 103 |
154 virtual void initializeCompositor() OVERRIDE | 104 virtual void initializeCompositor() OVERRIDE |
155 { | 105 { |
156 m_webThread.reset(WebKit::Platform::current()->createThread("WebLayerTre
eViewTest")); | 106 m_implThread.reset(new base::Thread("ThreadedTest")); |
157 WebKit::Platform::current()->compositorSupport()->initialize(m_webThread
.get()); | 107 ASSERT_TRUE(m_implThread->Start()); |
| 108 m_implCCThread = cc::ThreadImpl::createForDifferentThread(m_implThread->
message_loop_proxy()); |
| 109 cc::Proxy::setImplThread(m_implCCThread.get()); |
158 } | 110 } |
159 | 111 |
160 virtual WebLayerTreeViewClient* client() OVERRIDE | 112 virtual WebLayerTreeViewClient* client() OVERRIDE |
161 { | 113 { |
162 return &m_client; | 114 return &m_client; |
163 } | 115 } |
164 | 116 |
165 MockWebLayerTreeViewClientForThreadedTests m_client; | 117 MockWebLayerTreeViewClientForThreadedTests m_client; |
166 scoped_ptr<WebThread> m_webThread; | 118 scoped_ptr<base::Thread> m_implThread; |
| 119 scoped_ptr<cc::Thread> m_implCCThread; |
| 120 base::CancelableClosure m_timeout; |
167 }; | 121 }; |
168 | 122 |
169 TEST_F(WebLayerTreeViewSingleThreadTest, InstrumentationCallbacks) | 123 TEST_F(WebLayerTreeViewSingleThreadTest, InstrumentationCallbacks) |
170 { | 124 { |
171 ::testing::InSequence dummy; | 125 ::testing::InSequence dummy; |
172 | 126 |
173 EXPECT_CALL(m_client, willCommit()); | 127 EXPECT_CALL(m_client, willCommit()); |
174 EXPECT_CALL(m_client, didCommit()); | 128 EXPECT_CALL(m_client, didCommit()); |
175 EXPECT_CALL(m_client, didBeginFrame()); | 129 EXPECT_CALL(m_client, didBeginFrame()); |
176 | 130 |
177 composite(); | 131 composite(); |
178 } | 132 } |
179 | 133 |
180 TEST_F(WebLayerTreeViewThreadedTest, InstrumentationCallbacks) | 134 TEST_F(WebLayerTreeViewThreadedTest, InstrumentationCallbacks) |
181 { | 135 { |
182 ::testing::InSequence dummy; | 136 ::testing::InSequence dummy; |
183 | 137 |
184 EXPECT_CALL(m_client, willBeginFrame()); | 138 EXPECT_CALL(m_client, willBeginFrame()); |
185 EXPECT_CALL(m_client, willCommit()); | 139 EXPECT_CALL(m_client, willCommit()); |
186 EXPECT_CALL(m_client, didCommit()); | 140 EXPECT_CALL(m_client, didCommit()); |
187 EXPECT_CALL(m_client, didBeginFrame()); | 141 EXPECT_CALL(m_client, didBeginFrame()); |
188 | 142 |
189 composite(); | 143 composite(); |
190 } | 144 } |
191 | 145 |
192 } // namespace | 146 } // namespace |
OLD | NEW |