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 2cb84159a03b1ca621f2f73ef757c42f90563374..804a14cbb73b6bebc88a774428cfc85688db157c 100644 |
| --- a/ui/compositor/layer_owner_unittest.cc |
| +++ b/ui/compositor/layer_owner_unittest.cc |
| @@ -8,7 +8,9 @@ |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/compositor/compositor.h" |
| #include "ui/compositor/layer.h" |
| +#include "ui/compositor/layer_animation_observer.h" |
| #include "ui/compositor/layer_animator.h" |
| +#include "ui/compositor/scoped_animation_duration_scale_mode.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" |
| @@ -16,6 +18,24 @@ |
| namespace ui { |
| namespace { |
| +// An animation observer that confirms upon animation completion, that the |
| +// compositor is not null. |
| +class TestLayerAnimationObserver : public ImplicitAnimationObserver { |
| + public: |
| + TestLayerAnimationObserver(Layer* layer) : layer_(layer) {} |
| + ~TestLayerAnimationObserver() override {} |
| + |
| + // ImplicitAnimationObserver: |
| + void OnImplicitAnimationsCompleted() override { |
| + EXPECT_NE(nullptr, layer_->GetCompositor()); |
| + } |
| + |
| + private: |
| + Layer* layer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(TestLayerAnimationObserver); |
| +}; |
| + |
| // Test fixture for LayerOwner tests that require a ui::Compositor. |
| class LayerOwnerTestWithCompositor : public testing::Test { |
| public: |
| @@ -106,4 +126,36 @@ TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerWithCompositor) { |
| EXPECT_EQ(nullptr, layer_copy->GetCompositor()); |
| } |
| +// Tests that recreating the root layer, while one of its children is animating, |
| +// properly updates the compositor. So that compositor is not null for observers |
| +// of animations being cancelled. |
| +TEST_F(LayerOwnerTestWithCompositor, RecreateRootLayerDuringAnimation) { |
|
danakj
2015/05/12 16:57:40
Would you mind adding a test for a non-root layer
jonross
2015/05/12 17:26:25
Done.
|
| + LayerOwner owner; |
| + Layer* layer = new Layer; |
| + owner.SetLayer(layer); |
| + compositor()->SetRootLayer(layer); |
| + |
| + Layer* child = new Layer; |
|
danakj
2015/05/12 16:57:39
does this test leak the layer? i think so, can you
jonross
2015/05/12 17:26:24
Done.
|
| + child->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| + layer->Add(child); |
| + |
| + // This observer checks that the compositor of |child| is not null upon |
| + // animation completion. |
| + scoped_ptr<TestLayerAnimationObserver> observer( |
| + new TestLayerAnimationObserver(child)); |
| + scoped_ptr<ui::ScopedAnimationDurationScaleMode> long_duration_animation( |
| + new ui::ScopedAnimationDurationScaleMode( |
| + ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); |
| + { |
| + ui::ScopedLayerAnimationSettings animation(child->GetAnimator()); |
| + animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(1000)); |
| + animation.AddObserver(observer.get()); |
| + gfx::Transform transform; |
| + transform.Scale(0.5f, 0.5f); |
| + child->SetTransform(transform); |
| + } |
| + |
| + scoped_ptr<Layer> layer_copy = owner.RecreateLayer(); |
| +} |
| + |
| } // namespace ui |