OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/test/test_simple_task_runner.h" | 5 #include "base/test/test_simple_task_runner.h" |
| 6 #include "cc/output/begin_frame_args.h" |
| 7 #include "cc/test/begin_frame_args_test.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "ui/compositor/compositor.h" | 10 #include "ui/compositor/compositor.h" |
8 #include "ui/compositor/test/context_factories_for_test.h" | 11 #include "ui/compositor/test/context_factories_for_test.h" |
9 | 12 |
| 13 using testing::Mock; |
| 14 using testing::_; |
| 15 |
10 namespace ui { | 16 namespace ui { |
11 namespace { | 17 namespace { |
12 | 18 |
| 19 class MockCompositorBeginFrameObserver : public CompositorBeginFrameObserver { |
| 20 public: |
| 21 MOCK_METHOD1(OnSendBeginFrame, void(const cc::BeginFrameArgs&)); |
| 22 }; |
| 23 |
13 // Test fixture for tests that require a ui::Compositor with a real task | 24 // Test fixture for tests that require a ui::Compositor with a real task |
14 // runner. | 25 // runner. |
15 class CompositorTest : public testing::Test { | 26 class CompositorTest : public testing::Test { |
16 public: | 27 public: |
17 CompositorTest() {} | 28 CompositorTest() {} |
18 ~CompositorTest() override {} | 29 ~CompositorTest() override {} |
19 | 30 |
20 void SetUp() override { | 31 void SetUp() override { |
21 task_runner_ = new base::TestSimpleTaskRunner; | 32 task_runner_ = new base::TestSimpleTaskRunner; |
22 | 33 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 EXPECT_FALSE(compositor()->IsLocked()); | 65 EXPECT_FALSE(compositor()->IsLocked()); |
55 | 66 |
56 // Ensure that the lock does not time out when set. | 67 // Ensure that the lock does not time out when set. |
57 compositor()->SetLocksWillTimeOut(false); | 68 compositor()->SetLocksWillTimeOut(false); |
58 lock = compositor()->GetCompositorLock(); | 69 lock = compositor()->GetCompositorLock(); |
59 EXPECT_TRUE(compositor()->IsLocked()); | 70 EXPECT_TRUE(compositor()->IsLocked()); |
60 task_runner()->RunUntilIdle(); | 71 task_runner()->RunUntilIdle(); |
61 EXPECT_TRUE(compositor()->IsLocked()); | 72 EXPECT_TRUE(compositor()->IsLocked()); |
62 } | 73 } |
63 | 74 |
| 75 TEST_F(CompositorTest, AddAndRemoveBeginFrameObserver) { |
| 76 cc::BeginFrameArgs args = |
| 77 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, |
| 78 base::TimeTicks::FromInternalValue(33)); |
| 79 |
| 80 // Simulate to trigger new BeginFrame by using |args|. |
| 81 compositor()->SendBeginFramesToChildren(args); |
| 82 |
| 83 // When |missed_begin_frame_args_| is sent, its type is set to MISSED. |
| 84 cc::BeginFrameArgs expected_args(args); |
| 85 expected_args.type = cc::BeginFrameArgs::MISSED; |
| 86 |
| 87 MockCompositorBeginFrameObserver test_observer; |
| 88 MockCompositorBeginFrameObserver test_observer2; |
| 89 EXPECT_CALL(test_observer, OnSendBeginFrame(expected_args)); |
| 90 EXPECT_CALL(test_observer2, OnSendBeginFrame(expected_args)); |
| 91 |
| 92 // When new observer is added, Compositor immediately calls OnSendBeginFrame |
| 93 // with |missed_begin_frame_args_|. |
| 94 compositor()->AddBeginFrameObserver(&test_observer); |
| 95 compositor()->AddBeginFrameObserver(&test_observer2); |
| 96 Mock::VerifyAndClearExpectations(&test_observer); |
| 97 Mock::VerifyAndClearExpectations(&test_observer2); |
| 98 |
| 99 // When |test_observer2| is removed and added again, it will be called again. |
| 100 EXPECT_CALL(test_observer2, OnSendBeginFrame(expected_args)); |
| 101 compositor()->RemoveBeginFrameObserver(&test_observer2); |
| 102 compositor()->AddBeginFrameObserver(&test_observer2); |
| 103 Mock::VerifyAndClearExpectations(&test_observer2); |
| 104 |
| 105 // When all observer is removed, |missed_begin_frame_args_| is invalidated. |
| 106 // So, it is not used for newly added observer. |
| 107 EXPECT_CALL(test_observer2, OnSendBeginFrame(_)).Times(0); |
| 108 compositor()->RemoveBeginFrameObserver(&test_observer); |
| 109 compositor()->RemoveBeginFrameObserver(&test_observer2); |
| 110 compositor()->AddBeginFrameObserver(&test_observer2); |
| 111 Mock::VerifyAndClearExpectations(&test_observer2); |
| 112 |
| 113 compositor()->RemoveBeginFrameObserver(&test_observer2); |
| 114 } |
| 115 |
64 } // namespace ui | 116 } // namespace ui |
OLD | NEW |