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