Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / renderer_host / begin_frame_observer_proxy_unittest.cc
blobfe2b5289c00e2feb23e65f9268ff2fcef1c7e65a
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.
5 #include <algorithm>
6 #include <list>
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"
20 using testing::Mock;
21 using testing::_;
23 namespace content {
24 namespace {
26 class MockBeginFrameObserverProxyClient : public BeginFrameObserverProxyClient {
27 public:
28 MOCK_METHOD1(SendBeginFrame, void(const cc::BeginFrameArgs&));
31 class BeginFrameObserverProxyTest : public testing::Test {
32 public:
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();
41 compositor_.reset(
42 new ui::Compositor(context_factory, compositor_task_runner_));
43 compositor_->SetAcceleratedWidgetAndStartCompositor(
44 gfx::kNullAcceleratedWidget);
47 void TearDown() override {
48 compositor_.reset();
49 ui::TerminateContextFactoryForTests();
52 ui::Compositor* compositor() { return compositor_.get(); }
54 private:
55 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_;
56 scoped_ptr<ui::Compositor> compositor_;
59 } // namespace
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