mac: Add the flag "-gline-tables-only" to reduce dSYM size. (attempt #2)
[chromium-blink-merge.git] / ui / compositor / layer_owner_unittest.cc
blob60e10389ffc38e1aee702c8da022cba965f1d39c
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
3 // found in the LICENSE file.
5 #include "ui/compositor/layer_owner.h"
7 #include "base/test/null_task_runner.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/compositor/compositor.h"
10 #include "ui/compositor/layer.h"
11 #include "ui/compositor/layer_animator.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"
16 namespace ui {
17 namespace {
19 // Test fixture for LayerOwner tests that require a ui::Compositor.
20 class LayerOwnerTestWithCompositor : public testing::Test {
21 public:
22 LayerOwnerTestWithCompositor();
23 ~LayerOwnerTestWithCompositor() override;
25 void SetUp() override;
26 void TearDown() override;
28 protected:
29 ui::Compositor* compositor() { return compositor_.get(); }
31 private:
32 scoped_ptr<ui::Compositor> compositor_;
34 DISALLOW_COPY_AND_ASSIGN(LayerOwnerTestWithCompositor);
37 LayerOwnerTestWithCompositor::LayerOwnerTestWithCompositor() {
40 LayerOwnerTestWithCompositor::~LayerOwnerTestWithCompositor() {
43 void LayerOwnerTestWithCompositor::SetUp() {
44 scoped_refptr<base::SingleThreadTaskRunner> task_runner =
45 new base::NullTaskRunner();
47 ui::ContextFactory* context_factory =
48 ui::InitializeContextFactoryForTests(false);
50 compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget,
51 context_factory, task_runner));
54 void LayerOwnerTestWithCompositor::TearDown() {
55 compositor_.reset();
56 ui::TerminateContextFactoryForTests();
59 } // namespace
61 TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) {
62 LayerOwner owner;
63 Layer* layer = new Layer;
64 layer->SetVisible(true);
65 layer->SetOpacity(1.0f);
67 owner.SetLayer(layer);
69 ScopedLayerAnimationSettings settings(layer->GetAnimator());
70 layer->SetVisible(false);
71 layer->SetOpacity(0.0f);
72 EXPECT_TRUE(layer->visible());
73 EXPECT_EQ(1.0f, layer->opacity());
75 scoped_ptr<Layer> old_layer(owner.RecreateLayer());
76 EXPECT_FALSE(owner.layer()->visible());
77 EXPECT_EQ(0.0f, owner.layer()->opacity());
80 TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) {
81 LayerOwner owner;
82 Layer* layer = new Layer;
83 owner.SetLayer(layer);
85 scoped_ptr<Layer> layer_copy = owner.RecreateLayer();
87 EXPECT_EQ(nullptr, owner.layer()->GetCompositor());
88 EXPECT_EQ(nullptr, layer_copy->GetCompositor());
91 TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) {
92 LayerOwner owner;
93 Layer* layer = new Layer;
94 owner.SetLayer(layer);
96 compositor()->SetRootLayer(layer);
98 scoped_ptr<Layer> layer_copy = owner.RecreateLayer();
100 EXPECT_EQ(compositor(), owner.layer()->GetCompositor());
101 EXPECT_EQ(owner.layer(), compositor()->root_layer());
102 EXPECT_EQ(nullptr, layer_copy->GetCompositor());
105 } // namespace ui