Chromium Code Reviews| Index: ui/compositor/compositor_unittest.cc |
| diff --git a/ui/compositor/compositor_unittest.cc b/ui/compositor/compositor_unittest.cc |
| index 810f1c96d0875938de0b2460aaddcb4eaf4568f4..781745d809afd2a80ba133b701498a54a026e558 100644 |
| --- a/ui/compositor/compositor_unittest.cc |
| +++ b/ui/compositor/compositor_unittest.cc |
| @@ -3,13 +3,24 @@ |
| // found in the LICENSE file. |
| #include "base/test/test_simple_task_runner.h" |
| +#include "cc/output/begin_frame_args.h" |
| +#include "cc/test/begin_frame_args_test.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/compositor/compositor.h" |
| #include "ui/compositor/test/context_factories_for_test.h" |
| +using testing::Mock; |
| +using testing::_; |
| + |
| namespace ui { |
| namespace { |
| +class MockCompositorBeginFrameObserver : public CompositorBeginFrameObserver { |
| + public: |
| + MOCK_METHOD1(OnSendBeginFrame, void(const cc::BeginFrameArgs&)); |
| +}; |
| + |
| // Test fixture for tests that require a ui::Compositor with a real task |
| // runner. |
| class CompositorTest : public testing::Test { |
| @@ -61,4 +72,28 @@ TEST_F(CompositorTest, LocksTimeOut) { |
| EXPECT_TRUE(compositor()->IsLocked()); |
| } |
| +TEST_F(CompositorTest, AddAndRemoveBeginFrameObserver) { |
| + cc::BeginFrameArgs args = |
| + cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, |
| + base::TimeTicks::FromInternalValue(33)); |
| + |
| + // Simulate to trigger new BeginFrame by using |args|. |
| + compositor()->SendBeginFramesToChildren(args); |
| + |
| + // When |missed_begin_frame_args_| is sent, its type is set to MISSED. |
| + cc::BeginFrameArgs expected_args(args); |
| + expected_args.type = cc::BeginFrameArgs::MISSED; |
| + |
| + MockCompositorBeginFrameObserver test_observer; |
| + EXPECT_CALL(test_observer, OnSendBeginFrame(expected_args)); |
| + // When new observer is added, Compositor immediately calls OnSendBeginFrame |
| + // with |missed_begin_frame_args_|. |
| + compositor()->AddBeginFrameObserver(&test_observer); |
| + Mock::VerifyAndClearExpectations(&test_observer); |
| + |
| + // |missed_begin_frame_args_| should be invalidated. |
| + compositor()->RemoveBeginFrameObserver(&test_observer); |
| + 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!
|
| +} |
| + |
| } // namespace ui |