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/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/compositor_begin_frame_observer_impl.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" |
| 19 |
| 20 using testing::Mock; |
| 21 using testing::_; |
| 22 |
| 23 namespace content { |
| 24 namespace { |
| 25 |
| 26 class MockCompositorBeginFrameObserverImplClient |
| 27 : public CompositorBeginFrameObserverImplClient { |
| 28 public: |
| 29 MOCK_METHOD1(SendBeginFrame, void(const cc::BeginFrameArgs&)); |
| 30 }; |
| 31 |
| 32 class CompositorBeginFrameObserverImplTest : public testing::Test { |
| 33 public: |
| 34 CompositorBeginFrameObserverImplTest() {} |
| 35 ~CompositorBeginFrameObserverImplTest() override {} |
| 36 |
| 37 void SetUp() override { |
| 38 bool enable_pixel_output = false; |
| 39 ui::ContextFactory* context_factory = |
| 40 ui::InitializeContextFactoryForTests(enable_pixel_output); |
| 41 compositor_task_runner_ = new base::TestSimpleTaskRunner(); |
| 42 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, |
| 43 context_factory, |
| 44 compositor_task_runner_)); |
| 45 } |
| 46 |
| 47 void TearDown() override { |
| 48 compositor_.reset(); |
| 49 ui::TerminateContextFactoryForTests(); |
| 50 } |
| 51 |
| 52 ui::Compositor* compositor() { return compositor_.get(); } |
| 53 |
| 54 private: |
| 55 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| 56 scoped_ptr<ui::Compositor> compositor_; |
| 57 }; |
| 58 |
| 59 } // namespace |
| 60 |
| 61 TEST_F(CompositorBeginFrameObserverImplTest, BeginFrameScheduling) { |
| 62 MockCompositorBeginFrameObserverImplClient client; |
| 63 CompositorBeginFrameObserverImpl begin_frame_observer(&client); |
| 64 begin_frame_observer.SetCompositor(compositor()); |
| 65 begin_frame_observer.SetNeedsBeginFrames(true); |
| 66 |
| 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); |
| 74 |
| 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); |
| 82 |
| 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); |
| 87 |
| 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); |
| 96 } |
| 97 |
| 98 } // namespace content |
OLD | NEW |