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

Side by Side Diff: cc/trees/threaded_channel_unittest.cc

Issue 1377063003: Split ThreadProxy methods to ProxyMain and ProxyImpl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Keep ProxyMain and ProxyImpl methods private. Created 5 years, 1 month 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
« no previous file with comments | « cc/trees/threaded_channel.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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 "cc/trees/threaded_channel.h"
6
7 #include "cc/test/layer_tree_test.h"
8 #include "cc/trees/single_thread_proxy.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace cc {
12
13 // The ThreadedChannel tests are run only for threaded and direct mode.
14 class ThreadedChannelTest : public LayerTreeTest {
15 protected:
16 ThreadedChannelTest() : thread_proxy_(nullptr), calls_received_(0) {}
17
18 ~ThreadedChannelTest() override {}
19
20 void BeginTest() override {
21 DCHECK(HasImplThread());
22 thread_proxy_ = static_cast<ThreadProxy*>(proxy());
23 BeginChannelTest();
24 };
25 virtual void BeginChannelTest() {}
26
27 void PostOnImplThread() {
28 ImplThreadTaskRunner()->PostTask(
29 FROM_HERE, base::Bind(&ThreadedChannelTest::StartTestOnImplThread,
30 base::Unretained(this)));
31 }
32
33 virtual void StartTestOnImplThread() { DCHECK(proxy()->IsImplThread()); }
34
35 void AfterTest() override {}
36
37 // TODO(khushalsagar): Remove this once ProxyImpl is added to the
38 // LayerTreeTest.
39 ThreadProxy* thread_proxy_;
40 int calls_received_;
41
42 private:
43 DISALLOW_COPY_AND_ASSIGN(ThreadedChannelTest);
44 };
45
46 class ThreadedChannelTestInitializationAndShutdown
47 : public ThreadedChannelTest {
48 void SetVisibleOnImpl(bool visible) override { calls_received_++; }
49
50 void ReceivedRequestNewOutputSurface() override { calls_received_++; }
51
52 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override {
53 calls_received_++;
54 }
55
56 void ReceivedSetRendererCapabilitiesMainCopy(
57 const RendererCapabilities& capabilities) override {
58 calls_received_++;
59 }
60
61 void ReceivedDidInitializeOutputSurface(
62 bool success,
63 const RendererCapabilities& capabilities) override {
64 calls_received_++;
65 EndTest();
66 }
67
68 void FinishGLOnImpl() override { calls_received_++; }
69
70 void AfterTest() override { EXPECT_EQ(6, calls_received_); }
71 };
72
73 MULTI_THREAD_DIRECT_RENDERER_TEST_F(
74 ThreadedChannelTestInitializationAndShutdown);
75
76 class ThreadedChannelTestThrottleFrameProduction : public ThreadedChannelTest {
77 void BeginChannelTest() override {
78 proxy()->SetThrottleFrameProduction(true);
79 }
80
81 void SetThrottleFrameProductionOnImpl(bool throttle) override {
82 ASSERT_TRUE(throttle);
83 calls_received_++;
84 EndTest();
85 }
86
87 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
88 };
89
90 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestThrottleFrameProduction);
91
92 class ThreadedChannelTestTopControlsState : public ThreadedChannelTest {
93 void BeginChannelTest() override {
94 proxy()->UpdateTopControlsState(TopControlsState::BOTH,
95 TopControlsState::BOTH, true);
96 }
97
98 void UpdateTopControlsStateOnImpl(TopControlsState constraints,
99 TopControlsState current,
100 bool animate) override {
101 calls_received_++;
102 EndTest();
103 }
104
105 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
106 };
107
108 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestTopControlsState);
109
110 class ThreadedChannelTestMainThreadStoppedFlinging
111 : public ThreadedChannelTest {
112 void BeginChannelTest() override { proxy()->MainThreadHasStoppedFlinging(); }
113
114 void MainThreadHasStoppedFlingingOnImpl() override {
115 calls_received_++;
116 EndTest();
117 }
118
119 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
120 };
121
122 MULTI_THREAD_DIRECT_RENDERER_TEST_F(
123 ThreadedChannelTestMainThreadStoppedFlinging);
124
125 class ThreadedChannelTestDeferCommits : public ThreadedChannelTest {
126 void BeginChannelTest() override { DispatchSetDeferCommits(true); }
127
128 void SetDeferCommitsOnImpl(bool defer_commits) override {
129 ASSERT_TRUE(defer_commits);
130 calls_received_++;
131 EndTest();
132 }
133
134 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
135 };
136
137 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestDeferCommits);
138
139 class ThreadedChannelTestInputThrottled : public ThreadedChannelTest {
140 void BeginChannelTest() override {
141 proxy()->NotifyInputThrottledUntilCommit();
142 }
143
144 void SetInputThrottledUntilCommitOnImpl(bool is_throttled) override {
145 calls_received_++;
146 EndTest();
147 }
148
149 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
150 };
151
152 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestInputThrottled);
153
154 class ThreadedChannelTestNeedsRedraw : public ThreadedChannelTest {
155 void BeginChannelTest() override { DispatchSetNeedsRedraw(); }
156
157 void SetNeedsRedrawOnImpl(const gfx::Rect& damage_rect) override {
158 calls_received_++;
159 EndTest();
160 }
161
162 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
163 };
164
165 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestNeedsRedraw);
166
167 class ThreadedChannelTestFinishAllRendering : public ThreadedChannelTest {
168 void BeginChannelTest() override { proxy()->FinishAllRendering(); }
169
170 void FinishAllRenderingOnImpl() override {
171 calls_received_++;
172 EndTest();
173 }
174
175 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
176 };
177
178 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestFinishAllRendering);
179
180 class ThreadedChannelTestReleaseOutputSurface : public ThreadedChannelTest {
181 void BeginChannelTest() override { proxy()->ReleaseOutputSurface(); }
182
183 void ReleaseOutputSurfaceOnImpl() override {
184 calls_received_++;
185 EndTest();
186 }
187
188 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
189 };
190
191 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestReleaseOutputSurface);
192
193 class ThreadedChannelTestCommit : public ThreadedChannelTest {
194 void BeginChannelTest() override { PostSetNeedsCommitToMainThread(); }
195
196 void SetNeedsCommitOnImpl() override { EXPECT_EQ(0, calls_received_++); }
197
198 void ReceivedBeginMainFrame() override { EXPECT_EQ(1, calls_received_++); }
199
200 void StartCommitOnImpl() override { EXPECT_EQ(2, calls_received_++); }
201
202 void ReceivedDidCommitAndDrawFrame() override {
203 EXPECT_EQ(3, calls_received_++);
204 }
205
206 void ReceivedDidCompleteSwapBuffers() override {
207 EXPECT_EQ(4, calls_received_++);
208 EndTest();
209 }
210
211 void AfterTest() override { EXPECT_EQ(5, calls_received_); }
212 };
213
214 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestCommit);
215
216 class ThreadedChannelTestBeginMainFrameAborted : public ThreadedChannelTest {
217 void BeginChannelTest() override { PostSetNeedsCommitToMainThread(); }
218
219 void ScheduledActionWillSendBeginMainFrame() override {
220 // Set visible to false to abort the commit.
221 MainThreadTaskRunner()->PostTask(
222 FROM_HERE,
223 base::Bind(&ThreadedChannelTestBeginMainFrameAborted::SetVisibleFalse,
224 base::Unretained(this)));
225 }
226
227 void SetVisibleFalse() { layer_tree_host()->SetVisible(false); }
228
229 void BeginMainFrameAbortedOnImpl(CommitEarlyOutReason reason) override {
230 calls_received_++;
231 EndTest();
232 }
233
234 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
235 };
236
237 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestBeginMainFrameAborted);
238
239 class ThreadedChannelTestBeginMainFrameNotExpectedSoon
240 : public ThreadedChannelTest {
241 void BeginChannelTest() override { PostOnImplThread(); }
242
243 void StartTestOnImplThread() override {
244 thread_proxy_->SendBeginMainFrameNotExpectedSoon();
245 }
246
247 void ReceivedBeginMainFrameNotExpectedSoon() override {
248 calls_received_++;
249 EndTest();
250 }
251
252 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
253 };
254
255 MULTI_THREAD_DIRECT_RENDERER_TEST_F(
256 ThreadedChannelTestBeginMainFrameNotExpectedSoon);
257
258 class ThreadedChannelTestSetAnimationEvents : public ThreadedChannelTest {
259 void BeginChannelTest() override { PostOnImplThread(); }
260
261 void StartTestOnImplThread() override {
262 scoped_ptr<AnimationEventsVector> events(
263 make_scoped_ptr(new AnimationEventsVector));
264 thread_proxy_->PostAnimationEventsToMainThreadOnImplThread(events.Pass());
265 }
266
267 void ReceivedSetAnimationEvents() override {
268 calls_received_++;
269 EndTest();
270 }
271
272 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
273 };
274
275 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestSetAnimationEvents);
276
277 class ThreadedChannelTestLoseOutputSurface : public ThreadedChannelTest {
278 void BeginChannelTest() override { PostOnImplThread(); }
279
280 void StartTestOnImplThread() override {
281 thread_proxy_->DidLoseOutputSurfaceOnImplThread();
282 }
283
284 void ReceivedDidLoseOutputSurface() override {
285 calls_received_++;
286 EndTest();
287 }
288
289 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
290 };
291
292 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestLoseOutputSurface);
293
294 class ThreadedChannelTestPageScaleAnimation : public ThreadedChannelTest {
295 void BeginChannelTest() override { PostOnImplThread(); }
296
297 void StartTestOnImplThread() override {
298 thread_proxy_->DidCompletePageScaleAnimationOnImplThread();
299 }
300
301 void ReceivedDidCompletePageScaleAnimation() override {
302 calls_received_++;
303 EndTest();
304 }
305
306 void AfterTest() override { EXPECT_EQ(1, calls_received_); }
307 };
308
309 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestPageScaleAnimation);
310
311 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/threaded_channel.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698