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
3 // found in the LICENSE file.
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/test/test_simple_task_runner.h"
12 #include "cc/output/begin_frame_args.h"
13 #include "cc/test/begin_frame_args_test.h"
14 #include "content/browser/renderer_host/begin_frame_observer_proxy.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/compositor/compositor.h"
18 #include "ui/compositor/test/context_factories_for_test.h"
26 class MockBeginFrameObserverProxyClient
: public BeginFrameObserverProxyClient
{
28 MOCK_METHOD1(SendBeginFrame
, void(const cc::BeginFrameArgs
&));
31 class BeginFrameObserverProxyTest
: public testing::Test
{
33 BeginFrameObserverProxyTest() {}
34 ~BeginFrameObserverProxyTest() override
{}
36 void SetUp() override
{
37 bool enable_pixel_output
= false;
38 ui::ContextFactory
* context_factory
=
39 ui::InitializeContextFactoryForTests(enable_pixel_output
);
40 compositor_task_runner_
= new base::TestSimpleTaskRunner();
42 new ui::Compositor(context_factory
, compositor_task_runner_
));
43 compositor_
->SetAcceleratedWidgetAndStartCompositor(
44 gfx::kNullAcceleratedWidget
);
47 void TearDown() override
{
49 ui::TerminateContextFactoryForTests();
52 ui::Compositor
* compositor() { return compositor_
.get(); }
55 scoped_refptr
<base::SingleThreadTaskRunner
> compositor_task_runner_
;
56 scoped_ptr
<ui::Compositor
> compositor_
;
61 TEST_F(BeginFrameObserverProxyTest
, BeginFrameScheduling
) {
62 MockBeginFrameObserverProxyClient client
;
63 BeginFrameObserverProxy
begin_frame_observer(&client
);
64 begin_frame_observer
.SetCompositor(compositor());
65 begin_frame_observer
.SetNeedsBeginFrames(true);
67 // SendBeginFrame is called when new |args| is delivered.
68 cc::BeginFrameArgs args
=
69 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
,
70 base::TimeTicks::FromInternalValue(33));
71 EXPECT_CALL(client
, SendBeginFrame(args
));
72 compositor()->SendBeginFramesToChildren(args
);
73 Mock::VerifyAndClearExpectations(&client
);
75 // SendBeginFrame is called when new |args2| is delivered.
76 cc::BeginFrameArgs args2
=
77 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
,
78 base::TimeTicks::FromInternalValue(66));
79 EXPECT_CALL(client
, SendBeginFrame(args2
));
80 compositor()->SendBeginFramesToChildren(args2
);
81 Mock::VerifyAndClearExpectations(&client
);
83 // SendBeginFrame is not called when used |args2| is delivered.
84 EXPECT_CALL(client
, SendBeginFrame(_
)).Times(0);
85 compositor()->SendBeginFramesToChildren(args2
);
86 Mock::VerifyAndClearExpectations(&client
);
88 // SendBeginFrame is not called when compositor is reset.
89 begin_frame_observer
.ResetCompositor();
90 cc::BeginFrameArgs args3
=
91 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE
,
92 base::TimeTicks::FromInternalValue(99));
93 EXPECT_CALL(client
, SendBeginFrame(_
)).Times(0);
94 compositor()->SendBeginFramesToChildren(args3
);
95 Mock::VerifyAndClearExpectations(&client
);
98 } // namespace content