Chromium Code Reviews| 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 EXPECT_CALL(test_observer, OnSendBeginFrame(expected_args)); | |
| 89 // When new observer is added, Compositor immediately calls OnSendBeginFrame | |
| 90 // with |missed_begin_frame_args_|. | |
| 91 compositor()->AddBeginFrameObserver(&test_observer); | |
| 92 Mock::VerifyAndClearExpectations(&test_observer); | |
| 93 | |
| 94 // |missed_begin_frame_args_| should be invalidated. | |
| 95 compositor()->RemoveBeginFrameObserver(&test_observer); | |
| 96 EXPECT_FALSE(compositor()->MissedBeginFrameArgsForTesting().IsValid()); | |
|
danakj
2015/03/20 16:46:11
This is testing internal implementation details st
simonhong
2015/03/20 17:24:14
Yep, Thanks!
| |
| 97 } | |
| 98 | |
| 64 } // namespace ui | 99 } // namespace ui |
| OLD | NEW |