OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/test/test_simple_task_runner.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 #include "ui/compositor/compositor.h" |
| 8 #include "ui/compositor/test/context_factories_for_test.h" |
| 9 |
| 10 namespace ui { |
| 11 namespace { |
| 12 |
| 13 // Test fixture for tests that require a ui::Compositor with a real task |
| 14 // runner. |
| 15 class CompositorTest : public testing::Test { |
| 16 public: |
| 17 CompositorTest() {} |
| 18 ~CompositorTest() override {} |
| 19 |
| 20 void SetUp() override { |
| 21 task_runner_ = new base::TestSimpleTaskRunner; |
| 22 |
| 23 ui::ContextFactory* context_factory = |
| 24 ui::InitializeContextFactoryForTests(false); |
| 25 |
| 26 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, |
| 27 context_factory, task_runner_)); |
| 28 } |
| 29 void TearDown() override { |
| 30 compositor_.reset(); |
| 31 ui::TerminateContextFactoryForTests(); |
| 32 } |
| 33 |
| 34 protected: |
| 35 base::TestSimpleTaskRunner* task_runner() { return task_runner_.get(); } |
| 36 ui::Compositor* compositor() { return compositor_.get(); } |
| 37 |
| 38 private: |
| 39 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; |
| 40 scoped_ptr<ui::Compositor> compositor_; |
| 41 |
| 42 DISALLOW_COPY_AND_ASSIGN(CompositorTest); |
| 43 }; |
| 44 |
| 45 } // namespace |
| 46 |
| 47 TEST_F(CompositorTest, LocksTimeOut) { |
| 48 scoped_refptr<ui::CompositorLock> lock; |
| 49 |
| 50 // Ensure that the lock times out by default. |
| 51 lock = compositor()->GetCompositorLock(); |
| 52 EXPECT_TRUE(compositor()->IsLocked()); |
| 53 task_runner()->RunUntilIdle(); |
| 54 EXPECT_FALSE(compositor()->IsLocked()); |
| 55 |
| 56 // Ensure that the lock does not time out when set. |
| 57 compositor()->SetLocksWillTimeOut(false); |
| 58 lock = compositor()->GetCompositorLock(); |
| 59 EXPECT_TRUE(compositor()->IsLocked()); |
| 60 task_runner()->RunUntilIdle(); |
| 61 EXPECT_TRUE(compositor()->IsLocked()); |
| 62 } |
| 63 |
| 64 } // namespace ui |
OLD | NEW |