OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/compositor/layer_owner.h" | 5 #include "ui/compositor/layer_owner.h" |
6 | 6 |
7 #include "base/test/null_task_runner.h" | |
7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/compositor/compositor.h" | |
8 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
9 #include "ui/compositor/layer_animator.h" | 11 #include "ui/compositor/layer_animator.h" |
10 #include "ui/compositor/scoped_layer_animation_settings.h" | 12 #include "ui/compositor/scoped_layer_animation_settings.h" |
13 #include "ui/compositor/test/context_factories_for_test.h" | |
14 #include "ui/gfx/native_widget_types.h" | |
11 | 15 |
12 namespace ui { | 16 namespace ui { |
17 namespace { | |
18 | |
19 // Test fixture for LayerOwner tests that require a ui::Compositor. | |
20 class LayerOwnerTestWithCompositor : public testing::Test { | |
21 public: | |
22 LayerOwnerTestWithCompositor(); | |
23 ~LayerOwnerTestWithCompositor() override; | |
24 | |
25 void SetUp() override; | |
26 void TearDown() override; | |
27 | |
28 protected: | |
29 scoped_ptr<ui::Compositor> compositor_; | |
sadrul
2015/03/09 15:31:25
Make this private and add a public/protected acces
bruthig
2015/03/09 15:59:21
Done.
| |
30 | |
31 private: | |
32 DISALLOW_COPY_AND_ASSIGN(LayerOwnerTestWithCompositor); | |
33 }; | |
34 | |
35 LayerOwnerTestWithCompositor::LayerOwnerTestWithCompositor() { | |
36 } | |
37 | |
38 LayerOwnerTestWithCompositor::~LayerOwnerTestWithCompositor() { | |
39 } | |
40 | |
41 void LayerOwnerTestWithCompositor::SetUp() { | |
42 scoped_refptr<base::SingleThreadTaskRunner> task_runner = | |
43 new base::NullTaskRunner(); | |
44 | |
45 ui::ContextFactory* context_factory = | |
46 ui::InitializeContextFactoryForTests(false); | |
47 | |
48 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, | |
49 context_factory, task_runner)); | |
50 } | |
51 | |
52 void LayerOwnerTestWithCompositor::TearDown() { | |
53 compositor_.reset(); | |
54 ui::TerminateContextFactoryForTests(); | |
55 } | |
56 | |
57 } // namespace | |
13 | 58 |
14 TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) { | 59 TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) { |
15 LayerOwner owner; | 60 LayerOwner owner; |
16 Layer* layer = new Layer; | 61 Layer* layer = new Layer; |
17 layer->SetVisible(true); | 62 layer->SetVisible(true); |
18 layer->SetOpacity(1.0f); | 63 layer->SetOpacity(1.0f); |
19 | 64 |
20 owner.SetLayer(layer); | 65 owner.SetLayer(layer); |
21 | 66 |
22 ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 67 ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
23 layer->SetVisible(false); | 68 layer->SetVisible(false); |
24 layer->SetOpacity(0.0f); | 69 layer->SetOpacity(0.0f); |
25 EXPECT_TRUE(layer->visible()); | 70 EXPECT_TRUE(layer->visible()); |
26 EXPECT_EQ(1.0f, layer->opacity()); | 71 EXPECT_EQ(1.0f, layer->opacity()); |
27 | 72 |
28 scoped_ptr<Layer> old_layer(owner.RecreateLayer()); | 73 scoped_ptr<Layer> old_layer(owner.RecreateLayer()); |
29 EXPECT_FALSE(owner.layer()->visible()); | 74 EXPECT_FALSE(owner.layer()->visible()); |
30 EXPECT_EQ(0.0f, owner.layer()->opacity()); | 75 EXPECT_EQ(0.0f, owner.layer()->opacity()); |
31 } | 76 } |
32 | 77 |
78 TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) { | |
79 LayerOwner owner; | |
80 Layer* layer = new Layer; | |
81 owner.SetLayer(layer); | |
82 | |
83 scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); | |
84 | |
85 EXPECT_EQ(nullptr, owner.layer()->GetCompositor()); | |
86 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); | |
87 } | |
88 | |
89 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) { | |
90 LayerOwner owner; | |
91 Layer* layer = new Layer; | |
92 owner.SetLayer(layer); | |
93 | |
94 compositor_->SetRootLayer(layer); | |
95 | |
96 scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); | |
97 | |
98 EXPECT_EQ(compositor_.get(), owner.layer()->GetCompositor()); | |
99 EXPECT_EQ(owner.layer(), compositor_->root_layer()); | |
100 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); | |
101 } | |
102 | |
33 } // namespace ui | 103 } // namespace ui |
OLD | NEW |