Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(245)

Side by Side Diff: webkit/compositor_bindings/WebLayerTreeViewTest.cpp

Issue 11192050: Rename compositor bindings filenames to Chromium style (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "WebLayerImpl.h"
8 #include "WebLayerTreeViewImpl.h"
9 #include "WebLayerTreeViewTestCommon.h"
10 #include "base/memory/ref_counted.h"
11 #include "cc/test/compositor_fake_web_graphics_context_3d.h"
12 #include "cc/test/fake_web_compositor_output_surface.h"
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor t.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h"
18 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli ent.h"
19 #include "third_party/WebKit/Source/Platform/chromium/public/WebThread.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.reset(new WebLayerImpl);
46 m_view.reset(new WebLayerTreeViewImpl(client()));
47 ASSERT_TRUE(m_view->initialize(WebLayerTreeView::Settings()));
48 m_view->setRootLayer(*m_rootLayer);
49 m_view->setSurfaceReady();
50 }
51
52 virtual void TearDown()
53 {
54 Mock::VerifyAndClearExpectations(client());
55
56 m_rootLayer.reset();
57 m_view.reset();
58 WebKit::Platform::current()->compositorSupport()->shutdown();
59 }
60
61 protected:
62 scoped_ptr<WebLayer> m_rootLayer;
63 scoped_ptr<WebLayerTreeViewImpl> m_view;
64 };
65
66 class WebLayerTreeViewSingleThreadTest : public WebLayerTreeViewTestBase {
67 protected:
68 void composite()
69 {
70 m_view->composite();
71 }
72
73 virtual void initializeCompositor() OVERRIDE
74 {
75 WebKit::Platform::current()->compositorSupport()->initialize(0);
76 }
77
78 virtual WebLayerTreeViewClient* client() OVERRIDE
79 {
80 return &m_client;
81 }
82
83 MockWebLayerTreeViewClient m_client;
84 };
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(PassOwnPtr<WebThread::Task> task)
105 : m_task(task)
106 {
107 }
108
109 void cancel()
110 {
111 m_task.clear();
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.clear();
126 }
127
128 private:
129 friend class base::RefCounted<CancelableTaskWrapper>;
130 ~CancelableTaskWrapper() { }
131
132 OwnPtr<WebThread::Task> m_task;
133 };
134
135 class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase {
136 protected:
137 class TimeoutTask : public WebThread::Task {
138 virtual void run() OVERRIDE
139 {
140 WebKit::Platform::current()->currentThread()->exitRunLoop();
141 }
142 };
143
144 void composite()
145 {
146 m_view->setNeedsRedraw();
147 scoped_refptr<CancelableTaskWrapper> timeoutTask(new CancelableTaskWrapp er(adoptPtr(new TimeoutTask())));
148 WebKit::Platform::current()->currentThread()->postDelayedTask(timeoutTas k->createTask(), 5000);
149 WebKit::Platform::current()->currentThread()->enterRunLoop();
150 timeoutTask->cancel();
151 m_view->finishAllRendering();
152 }
153
154 virtual void initializeCompositor() OVERRIDE
155 {
156 m_webThread.reset(WebKit::Platform::current()->createThread("WebLayerTre eViewTest"));
157 WebKit::Platform::current()->compositorSupport()->initialize(m_webThread .get());
158 }
159
160 virtual WebLayerTreeViewClient* client() OVERRIDE
161 {
162 return &m_client;
163 }
164
165 MockWebLayerTreeViewClientForThreadedTests m_client;
166 scoped_ptr<WebThread> m_webThread;
167 };
168
169 TEST_F(WebLayerTreeViewSingleThreadTest, InstrumentationCallbacks)
170 {
171 ::testing::InSequence dummy;
172
173 EXPECT_CALL(m_client, willCommit());
174 EXPECT_CALL(m_client, didCommit());
175 EXPECT_CALL(m_client, didBeginFrame());
176
177 composite();
178 }
179
180 TEST_F(WebLayerTreeViewThreadedTest, InstrumentationCallbacks)
181 {
182 ::testing::InSequence dummy;
183
184 EXPECT_CALL(m_client, willBeginFrame());
185 EXPECT_CALL(m_client, willCommit());
186 EXPECT_CALL(m_client, didCommit());
187 EXPECT_CALL(m_client, didBeginFrame());
188
189 composite();
190 }
191
192 } // namespace
OLDNEW
« no previous file with comments | « webkit/compositor_bindings/WebLayerTreeViewImpl.cpp ('k') | webkit/compositor_bindings/WebScrollbarLayerImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698