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