| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include <algorithm> | |
| 6 #include <list> | |
| 7 | |
| 8 #include "base/compiler_specific.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/test/test_simple_task_runner.h" | |
| 11 #include "cc/output/begin_frame_args.h" | |
| 12 #include "cc/test/begin_frame_args_test.h" | |
| 13 #include "content/browser/renderer_host/begin_frame_observer_proxy.h" | |
| 14 #include "testing/gmock/include/gmock/gmock.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 #include "ui/compositor/compositor.h" | |
| 17 #include "ui/compositor/test/context_factories_for_test.h" | |
| 18 | |
| 19 using testing::Mock; | |
| 20 using testing::_; | |
| 21 | |
| 22 namespace content { | |
| 23 namespace { | |
| 24 | |
| 25 class MockBeginFrameObserverProxyClient : public BeginFrameObserverProxyClient { | |
| 26 public: | |
| 27 MOCK_METHOD1(SendBeginFrame, void(const cc::BeginFrameArgs&)); | |
| 28 }; | |
| 29 | |
| 30 class BeginFrameObserverProxyTest : public testing::Test { | |
| 31 public: | |
| 32 BeginFrameObserverProxyTest() {} | |
| 33 ~BeginFrameObserverProxyTest() override {} | |
| 34 | |
| 35 void SetUp() override { | |
| 36 bool enable_pixel_output = false; | |
| 37 ui::ContextFactory* context_factory = | |
| 38 ui::InitializeContextFactoryForTests(enable_pixel_output); | |
| 39 compositor_task_runner_ = new base::TestSimpleTaskRunner(); | |
| 40 compositor_.reset( | |
| 41 new ui::Compositor(context_factory, compositor_task_runner_)); | |
| 42 compositor_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget); | |
| 43 } | |
| 44 | |
| 45 void TearDown() override { | |
| 46 compositor_.reset(); | |
| 47 ui::TerminateContextFactoryForTests(); | |
| 48 } | |
| 49 | |
| 50 ui::Compositor* compositor() { return compositor_.get(); } | |
| 51 | |
| 52 private: | |
| 53 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
| 54 scoped_ptr<ui::Compositor> compositor_; | |
| 55 }; | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 59 TEST_F(BeginFrameObserverProxyTest, BeginFrameScheduling) { | |
| 60 MockBeginFrameObserverProxyClient client; | |
| 61 BeginFrameObserverProxy begin_frame_observer(&client); | |
| 62 begin_frame_observer.SetCompositor(compositor()); | |
| 63 begin_frame_observer.SetNeedsBeginFrames(true); | |
| 64 | |
| 65 // SendBeginFrame is called when new |args| is delivered. | |
| 66 cc::BeginFrameArgs args = | |
| 67 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, | |
| 68 base::TimeTicks::FromInternalValue(33)); | |
| 69 EXPECT_CALL(client, SendBeginFrame(args)); | |
| 70 compositor()->SendBeginFramesToChildren(args); | |
| 71 Mock::VerifyAndClearExpectations(&client); | |
| 72 | |
| 73 // SendBeginFrame is called when new |args2| is delivered. | |
| 74 cc::BeginFrameArgs args2 = | |
| 75 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, | |
| 76 base::TimeTicks::FromInternalValue(66)); | |
| 77 EXPECT_CALL(client, SendBeginFrame(args2)); | |
| 78 compositor()->SendBeginFramesToChildren(args2); | |
| 79 Mock::VerifyAndClearExpectations(&client); | |
| 80 | |
| 81 // SendBeginFrame is not called when used |args2| is delivered. | |
| 82 EXPECT_CALL(client, SendBeginFrame(_)).Times(0); | |
| 83 compositor()->SendBeginFramesToChildren(args2); | |
| 84 Mock::VerifyAndClearExpectations(&client); | |
| 85 | |
| 86 // SendBeginFrame is not called when compositor is reset. | |
| 87 begin_frame_observer.ResetCompositor(); | |
| 88 cc::BeginFrameArgs args3 = | |
| 89 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, | |
| 90 base::TimeTicks::FromInternalValue(99)); | |
| 91 EXPECT_CALL(client, SendBeginFrame(_)).Times(0); | |
| 92 compositor()->SendBeginFramesToChildren(args3); | |
| 93 Mock::VerifyAndClearExpectations(&client); | |
| 94 } | |
| 95 | |
| 96 } // namespace content | |
| OLD | NEW |