| 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 GetProxyImpl()->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(events.Pass()); | 262 GetProxyImpl()->PostAnimationEventsToMainThreadOnImplThread(events.Pass()); |
| 270 } | 263 } |
| 271 | 264 |
| 272 void ReceivedSetAnimationEvents() override { | 265 void ReceivedSetAnimationEvents() override { |
| 273 calls_received_++; | 266 calls_received_++; |
| 274 EndTest(); | 267 EndTest(); |
| 275 } | 268 } |
| 276 | 269 |
| 277 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | 270 void AfterTest() override { EXPECT_EQ(1, calls_received_); } |
| 278 }; | 271 }; |
| 279 | 272 |
| 280 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestSetAnimationEvents); | 273 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestSetAnimationEvents); |
| 281 | 274 |
| 282 class ThreadedChannelTestLoseOutputSurface : public ThreadedChannelTest { | 275 class ThreadedChannelTestLoseOutputSurface : public ThreadedChannelTest { |
| 283 void BeginChannelTest() override { PostOnImplThread(); } | 276 void BeginChannelTest() override { PostOnImplThread(); } |
| 284 | 277 |
| 285 void StartTestOnImplThread() override { | 278 void StartTestOnImplThread() override { |
| 286 thread_proxy_->DidLoseOutputSurfaceOnImplThread(); | 279 GetProxyImpl()->DidLoseOutputSurfaceOnImplThread(); |
| 287 } | 280 } |
| 288 | 281 |
| 289 void ReceivedDidLoseOutputSurface() override { | 282 void ReceivedDidLoseOutputSurface() override { |
| 290 calls_received_++; | 283 calls_received_++; |
| 291 EndTest(); | 284 EndTest(); |
| 292 } | 285 } |
| 293 | 286 |
| 294 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | 287 void AfterTest() override { EXPECT_EQ(1, calls_received_); } |
| 295 }; | 288 }; |
| 296 | 289 |
| 297 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestLoseOutputSurface); | 290 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestLoseOutputSurface); |
| 298 | 291 |
| 299 class ThreadedChannelTestPageScaleAnimation : public ThreadedChannelTest { | 292 class ThreadedChannelTestPageScaleAnimation : public ThreadedChannelTest { |
| 300 void BeginChannelTest() override { PostOnImplThread(); } | 293 void BeginChannelTest() override { PostOnImplThread(); } |
| 301 | 294 |
| 302 void StartTestOnImplThread() override { | 295 void StartTestOnImplThread() override { |
| 303 thread_proxy_->DidCompletePageScaleAnimationOnImplThread(); | 296 GetProxyImpl()->DidCompletePageScaleAnimationOnImplThread(); |
| 304 } | 297 } |
| 305 | 298 |
| 306 void ReceivedDidCompletePageScaleAnimation() override { | 299 void ReceivedDidCompletePageScaleAnimation() override { |
| 307 calls_received_++; | 300 calls_received_++; |
| 308 EndTest(); | 301 EndTest(); |
| 309 } | 302 } |
| 310 | 303 |
| 311 void AfterTest() override { EXPECT_EQ(1, calls_received_); } | 304 void AfterTest() override { EXPECT_EQ(1, calls_received_); } |
| 312 }; | 305 }; |
| 313 | 306 |
| 314 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestPageScaleAnimation); | 307 MULTI_THREAD_DIRECT_RENDERER_TEST_F(ThreadedChannelTestPageScaleAnimation); |
| 315 | 308 |
| 316 } // namespace cc | 309 } // namespace cc |
| OLD | NEW |