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 { |
13 | 17 |
14 TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) { | 18 TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) { |
15 LayerOwner owner; | 19 LayerOwner owner; |
16 Layer* layer = new Layer; | 20 Layer* layer = new Layer; |
17 layer->SetVisible(true); | 21 layer->SetVisible(true); |
18 layer->SetOpacity(1.0f); | 22 layer->SetOpacity(1.0f); |
19 | 23 |
20 owner.SetLayer(layer); | 24 owner.SetLayer(layer); |
21 | 25 |
22 ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 26 ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
23 layer->SetVisible(false); | 27 layer->SetVisible(false); |
24 layer->SetOpacity(0.0f); | 28 layer->SetOpacity(0.0f); |
25 EXPECT_TRUE(layer->visible()); | 29 EXPECT_TRUE(layer->visible()); |
26 EXPECT_EQ(1.0f, layer->opacity()); | 30 EXPECT_EQ(1.0f, layer->opacity()); |
27 | 31 |
28 scoped_ptr<Layer> old_layer(owner.RecreateLayer()); | 32 scoped_ptr<Layer> old_layer(owner.RecreateLayer()); |
29 EXPECT_FALSE(owner.layer()->visible()); | 33 EXPECT_FALSE(owner.layer()->visible()); |
30 EXPECT_EQ(0.0f, owner.layer()->opacity()); | 34 EXPECT_EQ(0.0f, owner.layer()->opacity()); |
31 } | 35 } |
32 | 36 |
| 37 TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) { |
| 38 LayerOwner owner; |
| 39 Layer* layer = new Layer; |
| 40 owner.SetLayer(layer); |
| 41 |
| 42 scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); |
| 43 |
| 44 EXPECT_EQ(nullptr, owner.layer()->GetCompositor()); |
| 45 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); |
| 46 } |
| 47 |
| 48 TEST(LayerOwnerTest, RecreateRootLayerWithCompositor) { |
| 49 LayerOwner owner; |
| 50 Layer* layer = new Layer; |
| 51 owner.SetLayer(layer); |
| 52 |
| 53 ui::ContextFactory* context_factory = |
| 54 ui::InitializeContextFactoryForTests(false); |
| 55 scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| 56 new base::NullTaskRunner(); |
| 57 scoped_ptr<ui::Compositor> compositor(new ui::Compositor( |
| 58 gfx::kNullAcceleratedWidget, context_factory, task_runner)); |
| 59 compositor->SetRootLayer(layer); |
| 60 |
| 61 scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); |
| 62 |
| 63 EXPECT_EQ(compositor.get(), owner.layer()->GetCompositor()); |
| 64 EXPECT_EQ(nullptr, layer_copy->GetCompositor()); |
| 65 } |
| 66 |
33 } // namespace ui | 67 } // namespace ui |
OLD | NEW |