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.
5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h"
7 #include "cc/test/layer_tree_test.h"
8 #include "cc/trees/thread_proxy.h"
10 #define THREAD_PROXY_TEST_F(TEST_FIXTURE_NAME) \
11 TEST_F(TEST_FIXTURE_NAME, MultiThread) { Run(true); }
13 // Do common tests for single thread proxy and thread proxy.
14 // TODO(simonhong): Add SINGLE_THREAD_PROXY_TEST_F
15 #define PROXY_TEST_SCHEDULED_ACTION(TEST_FIXTURE_NAME) \
16 THREAD_PROXY_TEST_F(TEST_FIXTURE_NAME);
20 class ProxyTest
: public LayerTreeTest
{
23 ~ProxyTest() override
{}
25 void Run(bool threaded
) {
26 // We don't need to care about delegating mode.
27 bool delegating_renderer
= true;
29 RunTest(threaded
, delegating_renderer
);
32 void BeginTest() override
{}
33 void AfterTest() override
{}
36 DISALLOW_COPY_AND_ASSIGN(ProxyTest
);
39 class ProxyTestScheduledActionsBasic
: public ProxyTest
{
41 void BeginTest() override
{ proxy()->SetNeedsCommit(); }
43 void ScheduledActionBeginOutputSurfaceCreation() override
{
44 EXPECT_EQ(0, action_phase_
++);
47 void ScheduledActionSendBeginMainFrame() override
{
48 EXPECT_EQ(1, action_phase_
++);
51 void ScheduledActionCommit() override
{ EXPECT_EQ(2, action_phase_
++); }
53 void ScheduledActionDrawAndSwapIfPossible() override
{
54 EXPECT_EQ(3, action_phase_
++);
58 void AfterTest() override
{ EXPECT_EQ(4, action_phase_
); }
60 ProxyTestScheduledActionsBasic() : action_phase_(0) {
62 ~ProxyTestScheduledActionsBasic() override
{}
67 DISALLOW_COPY_AND_ASSIGN(ProxyTestScheduledActionsBasic
);
70 PROXY_TEST_SCHEDULED_ACTION(ProxyTestScheduledActionsBasic
);
72 class ThreadProxyTest
: public ProxyTest
{
75 ~ThreadProxyTest() override
{}
77 const ThreadProxy::MainThreadOnly
& ThreadProxyMainOnly() const {
79 DCHECK(proxy()->HasImplThread());
80 return static_cast<const ThreadProxy
*>(proxy())->main();
83 const ThreadProxy::CompositorThreadOnly
& ThreadProxyImplOnly() const {
85 DCHECK(proxy()->HasImplThread());
86 return static_cast<const ThreadProxy
*>(proxy())->impl();
90 DISALLOW_COPY_AND_ASSIGN(ThreadProxyTest
);
93 class ThreadProxyTestSetNeedsCommit
: public ThreadProxyTest
{
95 ThreadProxyTestSetNeedsCommit() {}
96 ~ThreadProxyTestSetNeedsCommit() override
{}
98 void BeginTest() override
{
99 EXPECT_FALSE(ThreadProxyMainOnly().commit_requested
);
100 EXPECT_FALSE(ThreadProxyMainOnly().commit_request_sent_to_impl_thread
);
102 proxy()->SetNeedsCommit();
104 EXPECT_TRUE(ThreadProxyMainOnly().commit_requested
);
105 EXPECT_TRUE(ThreadProxyMainOnly().commit_request_sent_to_impl_thread
);
108 void DidBeginMainFrame() override
{
109 EXPECT_FALSE(ThreadProxyMainOnly().commit_requested
);
110 EXPECT_FALSE(ThreadProxyMainOnly().commit_request_sent_to_impl_thread
);
116 DISALLOW_COPY_AND_ASSIGN(ThreadProxyTestSetNeedsCommit
);
119 THREAD_PROXY_TEST_F(ThreadProxyTestSetNeedsCommit
);