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

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

Issue 11142031: Remove WTF dependencies from webkit_compositor_bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased 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
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 <public/WebLayerTreeView.h> 7 #include "WebLayerImpl.h"
8 8 #include "WebLayerTreeViewImpl.h"
9 #include "WebLayerTreeViewTestCommon.h"
10 #include "base/memory/ref_counted.h"
9 #include "cc/test/compositor_fake_web_graphics_context_3d.h" 11 #include "cc/test/compositor_fake_web_graphics_context_3d.h"
10 #include "cc/test/fake_web_compositor_output_surface.h" 12 #include "cc/test/fake_web_compositor_output_surface.h"
11 #include "WebLayerTreeViewTestCommon.h" 13 #include "testing/gmock/include/gmock/gmock.h"
12 #include <gmock/gmock.h> 14 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
13 #include <public/Platform.h> 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebCompositorSuppor t.h"
14 #include <public/WebCompositorSupport.h> 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayer.h"
15 #include <public/WebLayer.h> 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeView.h"
16 #include <public/WebLayerTreeViewClient.h> 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebLayerTreeViewCli ent.h"
17 #include <public/WebThread.h> 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebThread.h"
18 #include <wtf/RefCounted.h>
19 #include <wtf/RefPtr.h>
20 20
21 using namespace WebKit; 21 using namespace WebKit;
22 using testing::Mock; 22 using testing::Mock;
23 using testing::Test; 23 using testing::Test;
24 24
25 namespace { 25 namespace {
26 26
27 class MockWebLayerTreeViewClientForThreadedTests : public MockWebLayerTreeViewCl ient { 27 class MockWebLayerTreeViewClientForThreadedTests : public MockWebLayerTreeViewCl ient {
28 public: 28 public:
29 virtual void didBeginFrame() OVERRIDE 29 virtual void didBeginFrame() OVERRIDE
30 { 30 {
31 WebKit::Platform::current()->currentThread()->exitRunLoop(); 31 WebKit::Platform::current()->currentThread()->exitRunLoop();
32 MockWebLayerTreeViewClient::didBeginFrame(); 32 MockWebLayerTreeViewClient::didBeginFrame();
33 } 33 }
34 }; 34 };
35 35
36 class WebLayerTreeViewTestBase : public Test { 36 class WebLayerTreeViewTestBase : public Test {
37 protected: 37 protected:
38 virtual void initializeCompositor() = 0; 38 virtual void initializeCompositor() = 0;
39 virtual WebLayerTreeViewClient* client() = 0; 39 virtual WebLayerTreeViewClient* client() = 0;
40 40
41 public: 41 public:
42 virtual void SetUp() 42 virtual void SetUp()
43 { 43 {
44 initializeCompositor(); 44 initializeCompositor();
45 m_rootLayer = adoptPtr(WebLayer::create()); 45 m_rootLayer.reset(new WebLayerImpl);
46 ASSERT_TRUE(m_view = adoptPtr(WebLayerTreeView::create(client(), *m_root Layer, WebLayerTreeView::Settings()))); 46 m_view.reset(new WebLayerTreeViewImpl(client()));
47 ASSERT_TRUE(m_view->initialize(WebLayerTreeView::Settings()));
48 m_view->setRootLayer(*m_rootLayer);
47 m_view->setSurfaceReady(); 49 m_view->setSurfaceReady();
48 } 50 }
49 51
50 virtual void TearDown() 52 virtual void TearDown()
51 { 53 {
52 Mock::VerifyAndClearExpectations(client()); 54 Mock::VerifyAndClearExpectations(client());
53 55
54 m_rootLayer.clear(); 56 m_rootLayer.reset();
55 m_view.clear(); 57 m_view.reset();
56 WebKit::Platform::current()->compositorSupport()->shutdown(); 58 WebKit::Platform::current()->compositorSupport()->shutdown();
57 } 59 }
58 60
59 protected: 61 protected:
60 OwnPtr<WebLayer> m_rootLayer; 62 scoped_ptr<WebLayer> m_rootLayer;
61 OwnPtr<WebLayerTreeView> m_view; 63 scoped_ptr<WebLayerTreeViewImpl> m_view;
62 }; 64 };
63 65
64 class WebLayerTreeViewSingleThreadTest : public WebLayerTreeViewTestBase { 66 class WebLayerTreeViewSingleThreadTest : public WebLayerTreeViewTestBase {
65 protected: 67 protected:
66 void composite() 68 void composite()
67 { 69 {
68 m_view->composite(); 70 m_view->composite();
69 } 71 }
70 72
71 virtual void initializeCompositor() OVERRIDE 73 virtual void initializeCompositor() OVERRIDE
72 { 74 {
73 WebKit::Platform::current()->compositorSupport()->initialize(0); 75 WebKit::Platform::current()->compositorSupport()->initialize(0);
74 } 76 }
75 77
76 virtual WebLayerTreeViewClient* client() OVERRIDE 78 virtual WebLayerTreeViewClient* client() OVERRIDE
77 { 79 {
78 return &m_client; 80 return &m_client;
79 } 81 }
80 82
81 MockWebLayerTreeViewClient m_client; 83 MockWebLayerTreeViewClient m_client;
82 }; 84 };
83 85
84 class CancelableTaskWrapper : public RefCounted<CancelableTaskWrapper> { 86 class CancelableTaskWrapper : public base::RefCounted<CancelableTaskWrapper> {
85 class Task : public WebThread::Task { 87 class Task : public WebThread::Task {
86 public: 88 public:
87 Task(CancelableTaskWrapper* cancelableTask) 89 Task(CancelableTaskWrapper* cancelableTask)
88 : m_cancelableTask(cancelableTask) 90 : m_cancelableTask(cancelableTask)
89 { 91 {
90 } 92 }
91 93
92 private: 94 private:
93 virtual void run() OVERRIDE 95 virtual void run() OVERRIDE
94 { 96 {
95 m_cancelableTask->runIfNotCanceled(); 97 m_cancelableTask->runIfNotCanceled();
96 } 98 }
97 99
98 RefPtr<CancelableTaskWrapper> m_cancelableTask; 100 scoped_refptr<CancelableTaskWrapper> m_cancelableTask;
99 }; 101 };
100 102
101 public: 103 public:
102 CancelableTaskWrapper(PassOwnPtr<WebThread::Task> task) 104 CancelableTaskWrapper(PassOwnPtr<WebThread::Task> task)
103 : m_task(task) 105 : m_task(task)
104 { 106 {
105 turnOffVerifier();
106 } 107 }
107 108
108 void cancel() 109 void cancel()
109 { 110 {
110 m_task.clear(); 111 m_task.clear();
111 } 112 }
112 113
113 WebThread::Task* createTask() 114 WebThread::Task* createTask()
114 { 115 {
115 ASSERT(m_task); 116 ASSERT(m_task);
116 return new Task(this); 117 return new Task(this);
117 } 118 }
118 119
119 void runIfNotCanceled() 120 void runIfNotCanceled()
120 { 121 {
121 if (!m_task) 122 if (!m_task)
122 return; 123 return;
123 m_task->run(); 124 m_task->run();
124 m_task.clear(); 125 m_task.clear();
125 } 126 }
126 127
127 private: 128 private:
129 friend class base::RefCounted<CancelableTaskWrapper>;
130 ~CancelableTaskWrapper() { }
131
128 OwnPtr<WebThread::Task> m_task; 132 OwnPtr<WebThread::Task> m_task;
129 }; 133 };
130 134
131 class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase { 135 class WebLayerTreeViewThreadedTest : public WebLayerTreeViewTestBase {
132 protected: 136 protected:
133 class TimeoutTask : public WebThread::Task { 137 class TimeoutTask : public WebThread::Task {
134 virtual void run() OVERRIDE 138 virtual void run() OVERRIDE
135 { 139 {
136 WebKit::Platform::current()->currentThread()->exitRunLoop(); 140 WebKit::Platform::current()->currentThread()->exitRunLoop();
137 } 141 }
138 }; 142 };
139 143
140 void composite() 144 void composite()
141 { 145 {
142 m_view->setNeedsRedraw(); 146 m_view->setNeedsRedraw();
143 RefPtr<CancelableTaskWrapper> timeoutTask = adoptRef(new CancelableTaskW rapper(adoptPtr(new TimeoutTask()))); 147 scoped_refptr<CancelableTaskWrapper> timeoutTask(new CancelableTaskWrapp er(adoptPtr(new TimeoutTask())));
144 WebKit::Platform::current()->currentThread()->postDelayedTask(timeoutTas k->createTask(), 5000); 148 WebKit::Platform::current()->currentThread()->postDelayedTask(timeoutTas k->createTask(), 5000);
145 WebKit::Platform::current()->currentThread()->enterRunLoop(); 149 WebKit::Platform::current()->currentThread()->enterRunLoop();
146 timeoutTask->cancel(); 150 timeoutTask->cancel();
147 m_view->finishAllRendering(); 151 m_view->finishAllRendering();
148 } 152 }
149 153
150 virtual void initializeCompositor() OVERRIDE 154 virtual void initializeCompositor() OVERRIDE
151 { 155 {
152 m_webThread = adoptPtr(WebKit::Platform::current()->createThread("WebLay erTreeViewTest")); 156 m_webThread.reset(WebKit::Platform::current()->createThread("WebLayerTre eViewTest"));
153 WebKit::Platform::current()->compositorSupport()->initialize(m_webThread .get()); 157 WebKit::Platform::current()->compositorSupport()->initialize(m_webThread .get());
154 } 158 }
155 159
156 virtual WebLayerTreeViewClient* client() OVERRIDE 160 virtual WebLayerTreeViewClient* client() OVERRIDE
157 { 161 {
158 return &m_client; 162 return &m_client;
159 } 163 }
160 164
161 MockWebLayerTreeViewClientForThreadedTests m_client; 165 MockWebLayerTreeViewClientForThreadedTests m_client;
162 OwnPtr<WebThread> m_webThread; 166 scoped_ptr<WebThread> m_webThread;
163 }; 167 };
164 168
165 TEST_F(WebLayerTreeViewSingleThreadTest, InstrumentationCallbacks) 169 TEST_F(WebLayerTreeViewSingleThreadTest, InstrumentationCallbacks)
166 { 170 {
167 ::testing::InSequence dummy; 171 ::testing::InSequence dummy;
168 172
169 EXPECT_CALL(m_client, willCommit()); 173 EXPECT_CALL(m_client, willCommit());
170 EXPECT_CALL(m_client, didCommit()); 174 EXPECT_CALL(m_client, didCommit());
171 EXPECT_CALL(m_client, didBeginFrame()); 175 EXPECT_CALL(m_client, didBeginFrame());
172 176
173 composite(); 177 composite();
174 } 178 }
175 179
176 TEST_F(WebLayerTreeViewThreadedTest, InstrumentationCallbacks) 180 TEST_F(WebLayerTreeViewThreadedTest, InstrumentationCallbacks)
177 { 181 {
178 ::testing::InSequence dummy; 182 ::testing::InSequence dummy;
179 183
180 EXPECT_CALL(m_client, willBeginFrame()); 184 EXPECT_CALL(m_client, willBeginFrame());
181 EXPECT_CALL(m_client, willCommit()); 185 EXPECT_CALL(m_client, willCommit());
182 EXPECT_CALL(m_client, didCommit()); 186 EXPECT_CALL(m_client, didCommit());
183 EXPECT_CALL(m_client, didBeginFrame()); 187 EXPECT_CALL(m_client, didBeginFrame());
184 188
185 composite(); 189 composite();
186 } 190 }
187 191
188 } // namespace 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