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/message_loop/message_loop_proxy.h" |
| 6 #include "base/run_loop.h" | |
| 6 #include "cc/output/begin_frame_args.h" | 7 #include "cc/output/begin_frame_args.h" |
| 7 #include "cc/test/begin_frame_args_test.h" | 8 #include "cc/test/begin_frame_args_test.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/compositor/compositor.h" | 11 #include "ui/compositor/compositor.h" |
| 11 #include "ui/compositor/test/context_factories_for_test.h" | 12 #include "ui/compositor/test/context_factories_for_test.h" |
| 12 | 13 |
| 13 using testing::Mock; | 14 using testing::Mock; |
| 14 using testing::_; | 15 using testing::_; |
| 15 | 16 |
| 16 namespace ui { | 17 namespace ui { |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 20 // This number is copied from ui::Compositor. | |
| 21 const int kCompositorLockTimeoutMs = 67; | |
|
piman
2015/04/16 00:10:03
nit: maybe you can move it to the header?
| |
| 22 | |
| 19 class MockCompositorBeginFrameObserver : public CompositorBeginFrameObserver { | 23 class MockCompositorBeginFrameObserver : public CompositorBeginFrameObserver { |
| 20 public: | 24 public: |
| 21 MOCK_METHOD1(OnSendBeginFrame, void(const cc::BeginFrameArgs&)); | 25 MOCK_METHOD1(OnSendBeginFrame, void(const cc::BeginFrameArgs&)); |
| 22 }; | 26 }; |
| 23 | 27 |
| 24 // Test fixture for tests that require a ui::Compositor with a real task | 28 // Test fixture for tests that require a ui::Compositor with a real task |
| 25 // runner. | 29 // runner. |
| 26 class CompositorTest : public testing::Test { | 30 class CompositorTest : public testing::Test { |
| 27 public: | 31 public: |
| 28 CompositorTest() {} | 32 CompositorTest() {} |
| 29 ~CompositorTest() override {} | 33 ~CompositorTest() override {} |
| 30 | 34 |
| 31 void SetUp() override { | 35 void SetUp() override { |
| 32 task_runner_ = new base::TestSimpleTaskRunner; | 36 task_runner_ = base::MessageLoopProxy::current(); |
| 33 | 37 |
| 34 ui::ContextFactory* context_factory = | 38 ui::ContextFactory* context_factory = |
| 35 ui::InitializeContextFactoryForTests(false); | 39 ui::InitializeContextFactoryForTests(false); |
| 36 | 40 |
| 37 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, | 41 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, |
| 38 context_factory, task_runner_)); | 42 context_factory, task_runner_)); |
| 39 } | 43 } |
| 40 void TearDown() override { | 44 void TearDown() override { |
| 41 compositor_.reset(); | 45 compositor_.reset(); |
| 42 ui::TerminateContextFactoryForTests(); | 46 ui::TerminateContextFactoryForTests(); |
| 43 } | 47 } |
| 44 | 48 |
| 45 protected: | 49 protected: |
| 46 base::TestSimpleTaskRunner* task_runner() { return task_runner_.get(); } | 50 base::MessageLoopProxy* task_runner() { return task_runner_.get(); } |
| 47 ui::Compositor* compositor() { return compositor_.get(); } | 51 ui::Compositor* compositor() { return compositor_.get(); } |
| 48 | 52 |
| 49 private: | 53 private: |
| 50 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; | 54 scoped_refptr<base::MessageLoopProxy> task_runner_; |
| 51 scoped_ptr<ui::Compositor> compositor_; | 55 scoped_ptr<ui::Compositor> compositor_; |
| 52 | 56 |
| 53 DISALLOW_COPY_AND_ASSIGN(CompositorTest); | 57 DISALLOW_COPY_AND_ASSIGN(CompositorTest); |
| 54 }; | 58 }; |
| 55 | 59 |
| 56 } // namespace | 60 } // namespace |
| 57 | 61 |
| 58 TEST_F(CompositorTest, LocksTimeOut) { | 62 TEST_F(CompositorTest, LocksTimeOut) { |
| 59 scoped_refptr<ui::CompositorLock> lock; | 63 scoped_refptr<ui::CompositorLock> lock; |
| 64 { | |
| 65 base::RunLoop run_loop; | |
| 66 // Ensure that the lock times out by default. | |
| 67 lock = compositor()->GetCompositorLock(); | |
| 68 EXPECT_TRUE(compositor()->IsLocked()); | |
| 69 task_runner()->PostDelayedTask( | |
| 70 FROM_HERE, run_loop.QuitClosure(), | |
| 71 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); | |
| 72 run_loop.Run(); | |
| 73 EXPECT_FALSE(compositor()->IsLocked()); | |
| 74 } | |
| 60 | 75 |
| 61 // Ensure that the lock times out by default. | 76 { |
| 62 lock = compositor()->GetCompositorLock(); | 77 base::RunLoop run_loop; |
| 63 EXPECT_TRUE(compositor()->IsLocked()); | 78 // Ensure that the lock does not time out when set. |
| 64 task_runner()->RunUntilIdle(); | 79 compositor()->SetLocksWillTimeOut(false); |
| 65 EXPECT_FALSE(compositor()->IsLocked()); | 80 lock = compositor()->GetCompositorLock(); |
| 66 | 81 EXPECT_TRUE(compositor()->IsLocked()); |
| 67 // Ensure that the lock does not time out when set. | 82 task_runner()->PostDelayedTask( |
| 68 compositor()->SetLocksWillTimeOut(false); | 83 FROM_HERE, run_loop.QuitClosure(), |
| 69 lock = compositor()->GetCompositorLock(); | 84 base::TimeDelta::FromMilliseconds(kCompositorLockTimeoutMs)); |
| 70 EXPECT_TRUE(compositor()->IsLocked()); | 85 run_loop.Run(); |
| 71 task_runner()->RunUntilIdle(); | 86 EXPECT_TRUE(compositor()->IsLocked()); |
| 72 EXPECT_TRUE(compositor()->IsLocked()); | 87 } |
| 73 } | 88 } |
| 74 | 89 |
| 75 TEST_F(CompositorTest, AddAndRemoveBeginFrameObserver) { | 90 TEST_F(CompositorTest, AddAndRemoveBeginFrameObserver) { |
| 76 cc::BeginFrameArgs args = | 91 cc::BeginFrameArgs args = |
| 77 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, | 92 cc::CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, |
| 78 base::TimeTicks::FromInternalValue(33)); | 93 base::TimeTicks::FromInternalValue(33)); |
| 79 | 94 |
| 80 // Simulate to trigger new BeginFrame by using |args|. | 95 // Simulate to trigger new BeginFrame by using |args|. |
| 81 compositor()->SendBeginFramesToChildren(args); | 96 compositor()->SendBeginFramesToChildren(args); |
| 82 | 97 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 107 EXPECT_CALL(test_observer2, OnSendBeginFrame(_)).Times(0); | 122 EXPECT_CALL(test_observer2, OnSendBeginFrame(_)).Times(0); |
| 108 compositor()->RemoveBeginFrameObserver(&test_observer); | 123 compositor()->RemoveBeginFrameObserver(&test_observer); |
| 109 compositor()->RemoveBeginFrameObserver(&test_observer2); | 124 compositor()->RemoveBeginFrameObserver(&test_observer2); |
| 110 compositor()->AddBeginFrameObserver(&test_observer2); | 125 compositor()->AddBeginFrameObserver(&test_observer2); |
| 111 Mock::VerifyAndClearExpectations(&test_observer2); | 126 Mock::VerifyAndClearExpectations(&test_observer2); |
| 112 | 127 |
| 113 compositor()->RemoveBeginFrameObserver(&test_observer2); | 128 compositor()->RemoveBeginFrameObserver(&test_observer2); |
| 114 } | 129 } |
| 115 | 130 |
| 116 } // namespace ui | 131 } // namespace ui |
| OLD | NEW |