Chromium Code Reviews| Index: ui/compositor/layer_owner_unittest.cc |
| diff --git a/ui/compositor/layer_owner_unittest.cc b/ui/compositor/layer_owner_unittest.cc |
| index 6390ecaf4633f026c409573114a6defb216f003e..4640e9747f185e10f25074a8fa71498605e2c484 100644 |
| --- a/ui/compositor/layer_owner_unittest.cc |
| +++ b/ui/compositor/layer_owner_unittest.cc |
| @@ -4,12 +4,57 @@ |
| #include "ui/compositor/layer_owner.h" |
| +#include "base/test/null_task_runner.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/compositor/compositor.h" |
| #include "ui/compositor/layer.h" |
| #include "ui/compositor/layer_animator.h" |
| #include "ui/compositor/scoped_layer_animation_settings.h" |
| +#include "ui/compositor/test/context_factories_for_test.h" |
| +#include "ui/gfx/native_widget_types.h" |
| namespace ui { |
| +namespace { |
| + |
| +// Test fixture for LayerOwner tests that require a ui::Compositor. |
| +class LayerOwnerTestWithCompositor : public testing::Test { |
| + public: |
| + LayerOwnerTestWithCompositor(); |
| + ~LayerOwnerTestWithCompositor() override; |
| + |
| + void SetUp() override; |
| + void TearDown() override; |
| + |
| + protected: |
| + 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.
|
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(LayerOwnerTestWithCompositor); |
| +}; |
| + |
| +LayerOwnerTestWithCompositor::LayerOwnerTestWithCompositor() { |
| +} |
| + |
| +LayerOwnerTestWithCompositor::~LayerOwnerTestWithCompositor() { |
| +} |
| + |
| +void LayerOwnerTestWithCompositor::SetUp() { |
| + scoped_refptr<base::SingleThreadTaskRunner> task_runner = |
| + new base::NullTaskRunner(); |
| + |
| + ui::ContextFactory* context_factory = |
| + ui::InitializeContextFactoryForTests(false); |
| + |
| + compositor_.reset(new ui::Compositor(gfx::kNullAcceleratedWidget, |
| + context_factory, task_runner)); |
| +} |
| + |
| +void LayerOwnerTestWithCompositor::TearDown() { |
| + compositor_.reset(); |
| + ui::TerminateContextFactoryForTests(); |
| +} |
| + |
| +} // namespace |
| TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) { |
| LayerOwner owner; |
| @@ -30,4 +75,29 @@ TEST(LayerOwnerTest, RecreateLayerHonorsTargetVisibilityAndOpacity) { |
| EXPECT_EQ(0.0f, owner.layer()->opacity()); |
| } |
| +TEST(LayerOwnerTest, RecreateRootLayerWithNullCompositor) { |
| + LayerOwner owner; |
| + Layer* layer = new Layer; |
| + owner.SetLayer(layer); |
| + |
| + scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); |
| + |
| + EXPECT_EQ(nullptr, owner.layer()->GetCompositor()); |
| + EXPECT_EQ(nullptr, layer_copy->GetCompositor()); |
| +} |
| + |
| +TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) { |
| + LayerOwner owner; |
| + Layer* layer = new Layer; |
| + owner.SetLayer(layer); |
| + |
| + compositor_->SetRootLayer(layer); |
| + |
| + scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); |
| + |
| + EXPECT_EQ(compositor_.get(), owner.layer()->GetCompositor()); |
| + EXPECT_EQ(owner.layer(), compositor_->root_layer()); |
| + EXPECT_EQ(nullptr, layer_copy->GetCompositor()); |
| +} |
| + |
| } // namespace ui |