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