OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "cc/trees/threaded_channel.h" | 5 #include "cc/trees/threaded_channel.h" |
6 | 6 |
7 #include "cc/test/layer_tree_test.h" | 7 #include "cc/test/layer_tree_test.h" |
8 #include "cc/trees/single_thread_proxy.h" | 8 #include "cc/trees/single_thread_proxy.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
11 namespace cc { | 11 namespace cc { |
12 | 12 |
13 // The ThreadedChannel tests are run only for threaded and direct mode. | 13 // The ThreadedChannel tests are run only for threaded and direct mode. |
14 class ThreadedChannelTest : public LayerTreeTest { | 14 class ThreadedChannelTest : public LayerTreeTest { |
15 protected: | 15 protected: |
16 ThreadedChannelTest() : thread_proxy_(nullptr), calls_received_(0) {} | 16 ThreadedChannelTest() : calls_received_(0) {} |
17 | 17 |
18 ~ThreadedChannelTest() override {} | 18 ~ThreadedChannelTest() override {} |
19 | 19 |
20 void BeginTest() override { | 20 void BeginTest() override { |
21 DCHECK(HasImplThread()); | 21 DCHECK(HasImplThread()); |
22 thread_proxy_ = static_cast<ThreadProxy*>(proxy()); | |
23 BeginChannelTest(); | 22 BeginChannelTest(); |
24 }; | 23 }; |
25 virtual void BeginChannelTest() {} | 24 virtual void BeginChannelTest() {} |
26 | 25 |
27 void PostOnImplThread() { | 26 void PostOnImplThread() { |
28 ImplThreadTaskRunner()->PostTask( | 27 ImplThreadTaskRunner()->PostTask( |
29 FROM_HERE, base::Bind(&ThreadedChannelTest::StartTestOnImplThread, | 28 FROM_HERE, base::Bind(&ThreadedChannelTest::StartTestOnImplThread, |
30 base::Unretained(this))); | 29 base::Unretained(this))); |
31 } | 30 } |
32 | 31 |
33 virtual void StartTestOnImplThread() { | 32 virtual void StartTestOnImplThread() { |
34 DCHECK(task_runner_provider()->IsImplThread()); | 33 DCHECK(task_runner_provider()->IsImplThread()); |
35 } | 34 } |
36 | 35 |
37 void AfterTest() override {} | 36 void AfterTest() override {} |
38 | 37 |
39 // TODO(khushalsagar): Remove this once ProxyImpl is added to the | |
40 // LayerTreeTest. | |
41 ThreadProxy* thread_proxy_; | |
42 int calls_received_; | 38 int calls_received_; |
43 | 39 |
44 private: | 40 private: |
45 DISALLOW_COPY_AND_ASSIGN(ThreadedChannelTest); | 41 DISALLOW_COPY_AND_ASSIGN(ThreadedChannelTest); |
46 }; | 42 }; |
47 | 43 |
48 class ThreadedChannelTestInitializationAndShutdown | 44 class ThreadedChannelTestInitializationAndShutdown |
49 : public ThreadedChannelTest { | 45 : public ThreadedChannelTest { |
50 void InitializeImplOnImpl() override { calls_received_++; } | |
51 | |
52 void SetVisibleOnImpl(bool visible) override { calls_received_++; } | 46 void SetVisibleOnImpl(bool visible) override { calls_received_++; } |
53 | 47 |
54 void ReceivedRequestNewOutputSurface() override { calls_received_++; } | 48 void ReceivedRequestNewOutputSurface() override { calls_received_++; } |
55 | 49 |
56 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override { | 50 void InitializeOutputSurfaceOnImpl(OutputSurface* output_surface) override { |
57 calls_received_++; | 51 calls_received_++; |
58 } | 52 } |
59 | 53 |
60 void ReceivedSetRendererCapabilitiesMainCopy( | 54 void ReceivedSetRendererCapabilitiesMainCopy( |
61 const RendererCapabilities& capabilities) override { | 55 const RendererCapabilities& capabilities) override { |
62 calls_received_++; | 56 calls_received_++; |
63 } | 57 } |
64 | 58 |
65 void ReceivedDidInitializeOutputSurface( | 59 void ReceivedDidInitializeOutputSurface( |
66 bool success, | 60 bool success, |
67 const RendererCapabilities& capabilities) override { | 61 const RendererCapabilities& capabilities) override { |
68 calls_received_++; | 62 calls_received_++; |
69 EndTest(); | 63 EndTest(); |
70 } | 64 } |
71 | 65 |
72 void WillCloseLayerTreeHostOnImpl() override { calls_received_++; } | |
73 void FinishGLOnImpl() override { calls_received_++; } | 66 void FinishGLOnImpl() override { calls_received_++; } |
74 | 67 |
75 void AfterTest() override { EXPECT_EQ(8, calls_received_); } | 68 void AfterTest() override { EXPECT_EQ(6, calls_received_); } |
76 }; | 69 }; |
77 | 70 |
78 MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 71 MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
79 ThreadedChannelTestInitializationAndShutdown); | 72 ThreadedChannelTestInitializationAndShutdown); |
80 | 73 |
81 class ThreadedChannelTestThrottleFrameProduction : public ThreadedChannelTest { | 74 class ThreadedChannelTestThrottleFrameProduction : public ThreadedChannelTest { |
82 void BeginChannelTest() override { | 75 void BeginChannelTest() override { |
83 proxy()->SetThrottleFrameProduction(true); | 76 proxy()->SetThrottleFrameProduction(true); |
84 } | 77 } |
85 | 78 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | 232 void AfterTest() override { EXPECT_EQ(1, calls_received_); } |
240 }; | 233 }; |
241 | 234 |
242 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestBeginMainFrameAborted); | 235 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestBeginMainFrameAborted); |
243 | 236 |
244 class ThreadedChannelTestBeginMainFrameNotExpectedSoon | 237 class ThreadedChannelTestBeginMainFrameNotExpectedSoon |
245 : public ThreadedChannelTest { | 238 : public ThreadedChannelTest { |
246 void BeginChannelTest() override { PostOnImplThread(); } | 239 void BeginChannelTest() override { PostOnImplThread(); } |
247 | 240 |
248 void StartTestOnImplThread() override { | 241 void StartTestOnImplThread() override { |
249 thread_proxy_->SendBeginMainFrameNotExpectedSoon(); | 242 GetProxyImplForTest()->SendBeginMainFrameNotExpectedSoon(); |
250 } | 243 } |
251 | 244 |
252 void ReceivedBeginMainFrameNotExpectedSoon() override { | 245 void ReceivedBeginMainFrameNotExpectedSoon() override { |
253 calls_received_++; | 246 calls_received_++; |
254 EndTest(); | 247 EndTest(); |
255 } | 248 } |
256 | 249 |
257 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | 250 void AfterTest() override { EXPECT_EQ(1, calls_received_); } |
258 }; | 251 }; |
259 | 252 |
260 MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 253 MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
261 ThreadedChannelTestBeginMainFrameNotExpectedSoon); | 254 ThreadedChannelTestBeginMainFrameNotExpectedSoon); |
262 | 255 |
263 class ThreadedChannelTestSetAnimationEvents : public ThreadedChannelTest { | 256 class ThreadedChannelTestSetAnimationEvents : public ThreadedChannelTest { |
264 void BeginChannelTest() override { PostOnImplThread(); } | 257 void BeginChannelTest() override { PostOnImplThread(); } |
265 | 258 |
266 void StartTestOnImplThread() override { | 259 void StartTestOnImplThread() override { |
267 scoped_ptr<AnimationEventsVector> events( | 260 scoped_ptr<AnimationEventsVector> events( |
268 make_scoped_ptr(new AnimationEventsVector)); | 261 make_scoped_ptr(new AnimationEventsVector)); |
269 thread_proxy_->PostAnimationEventsToMainThreadOnImplThread( | 262 GetProxyImplForTest()->PostAnimationEventsToMainThreadOnImplThread( |
270 std::move(events)); | 263 std::move(events)); |
271 } | 264 } |
272 | 265 |
273 void ReceivedSetAnimationEvents() override { | 266 void ReceivedSetAnimationEvents() override { |
274 calls_received_++; | 267 calls_received_++; |
275 EndTest(); | 268 EndTest(); |
276 } | 269 } |
277 | 270 |
278 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | 271 void AfterTest() override { EXPECT_EQ(1, calls_received_); } |
279 }; | 272 }; |
280 | 273 |
281 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestSetAnimationEvents); | 274 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestSetAnimationEvents); |
282 | 275 |
283 class ThreadedChannelTestLoseOutputSurface : public ThreadedChannelTest { | 276 class ThreadedChannelTestLoseOutputSurface : public ThreadedChannelTest { |
284 void BeginChannelTest() override { PostOnImplThread(); } | 277 void BeginChannelTest() override { PostOnImplThread(); } |
285 | 278 |
286 void StartTestOnImplThread() override { | 279 void StartTestOnImplThread() override { |
287 thread_proxy_->DidLoseOutputSurfaceOnImplThread(); | 280 GetProxyImplForTest()->DidLoseOutputSurfaceOnImplThread(); |
288 } | 281 } |
289 | 282 |
290 void ReceivedDidLoseOutputSurface() override { | 283 void ReceivedDidLoseOutputSurface() override { |
291 calls_received_++; | 284 calls_received_++; |
292 EndTest(); | 285 EndTest(); |
293 } | 286 } |
294 | 287 |
295 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | 288 void AfterTest() override { EXPECT_EQ(1, calls_received_); } |
296 }; | 289 }; |
297 | 290 |
298 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestLoseOutputSurface); | 291 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestLoseOutputSurface); |
299 | 292 |
300 class ThreadedChannelTestPageScaleAnimation : public ThreadedChannelTest { | 293 class ThreadedChannelTestPageScaleAnimation : public ThreadedChannelTest { |
301 void BeginChannelTest() override { PostOnImplThread(); } | 294 void BeginChannelTest() override { PostOnImplThread(); } |
302 | 295 |
303 void StartTestOnImplThread() override { | 296 void StartTestOnImplThread() override { |
304 thread_proxy_->DidCompletePageScaleAnimationOnImplThread(); | 297 GetProxyImplForTest()->DidCompletePageScaleAnimationOnImplThread(); |
305 } | 298 } |
306 | 299 |
307 void ReceivedDidCompletePageScaleAnimation() override { | 300 void ReceivedDidCompletePageScaleAnimation() override { |
308 calls_received_++; | 301 calls_received_++; |
309 EndTest(); | 302 EndTest(); |
310 } | 303 } |
311 | 304 |
312 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | 305 void AfterTest() override { EXPECT_EQ(1, calls_received_); } |
313 }; | 306 }; |
314 | 307 |
315 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestPageScaleAnimation); | 308 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestPageScaleAnimation); |
316 | 309 |
317 } // namespace cc | 310 } // namespace cc |
OLD | NEW |