| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #include "ui/wm/core/visibility_controller.h" | |
| 6 | |
| 7 #include "ui/aura/test/aura_test_base.h" | |
| 8 #include "ui/aura/test/test_window_delegate.h" | |
| 9 #include "ui/aura/test/test_windows.h" | |
| 10 #include "ui/aura/window.h" | |
| 11 #include "ui/aura/window_event_dispatcher.h" | |
| 12 #include "ui/compositor/layer.h" | |
| 13 #include "ui/compositor/layer_animator.h" | |
| 14 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | |
| 15 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 16 | |
| 17 namespace views { | |
| 18 namespace corewm { | |
| 19 | |
| 20 typedef aura::test::AuraTestBase VisibilityControllerTest; | |
| 21 | |
| 22 // Hiding a window in an animatable container should not hide the window's layer | |
| 23 // immediately. | |
| 24 TEST_F(VisibilityControllerTest, AnimateHideDoesntHideWindowLayer) { | |
| 25 // We cannot disable animations for this test. | |
| 26 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | |
| 27 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | |
| 28 | |
| 29 VisibilityController controller; | |
| 30 aura::client::SetVisibilityClient(root_window(), &controller); | |
| 31 | |
| 32 SetChildWindowVisibilityChangesAnimated(root_window()); | |
| 33 | |
| 34 aura::test::TestWindowDelegate d; | |
| 35 scoped_ptr<aura::Window> animatable(aura::test::CreateTestWindowWithDelegate( | |
| 36 &d, -2, gfx::Rect(0, 0, 50, 50), root_window())); | |
| 37 scoped_ptr<aura::Window> non_animatable( | |
| 38 aura::test::CreateTestWindowWithDelegateAndType( | |
| 39 &d, | |
| 40 ui::wm::WINDOW_TYPE_CONTROL, | |
| 41 -3, | |
| 42 gfx::Rect(51, 51, 50, 50), | |
| 43 root_window())); | |
| 44 EXPECT_TRUE(animatable->IsVisible()); | |
| 45 EXPECT_TRUE(animatable->layer()->visible()); | |
| 46 animatable->Hide(); | |
| 47 EXPECT_FALSE(animatable->IsVisible()); | |
| 48 EXPECT_TRUE(animatable->layer()->visible()); | |
| 49 | |
| 50 EXPECT_TRUE(non_animatable->IsVisible()); | |
| 51 EXPECT_TRUE(non_animatable->layer()->visible()); | |
| 52 non_animatable->Hide(); | |
| 53 EXPECT_FALSE(non_animatable->IsVisible()); | |
| 54 EXPECT_FALSE(non_animatable->layer()->visible()); | |
| 55 | |
| 56 aura::client::SetVisibilityClient(root_window(), NULL); | |
| 57 } | |
| 58 | |
| 59 // Check that a transparency change to 0 will not cause a hide call to be | |
| 60 // ignored. | |
| 61 TEST_F(VisibilityControllerTest, AnimateTransparencyToZeroAndHideHides) { | |
| 62 // We cannot disable animations for this test. | |
| 63 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | |
| 64 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | |
| 65 | |
| 66 VisibilityController controller; | |
| 67 aura::client::SetVisibilityClient(root_window(), &controller); | |
| 68 | |
| 69 SetChildWindowVisibilityChangesAnimated(root_window()); | |
| 70 | |
| 71 aura::test::TestWindowDelegate d; | |
| 72 scoped_ptr<aura::Window> window(aura::test::CreateTestWindowWithDelegate( | |
| 73 &d, -2, gfx::Rect(0, 0, 50, 50), root_window())); | |
| 74 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | |
| 75 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(5)); | |
| 76 | |
| 77 EXPECT_TRUE(window->layer()->visible()); | |
| 78 EXPECT_TRUE(window->IsVisible()); | |
| 79 | |
| 80 window->layer()->SetOpacity(0.0); | |
| 81 EXPECT_TRUE(window->layer()->visible()); | |
| 82 EXPECT_TRUE(window->IsVisible()); | |
| 83 EXPECT_TRUE(window->layer()->GetAnimator()-> | |
| 84 IsAnimatingProperty(ui::LayerAnimationElement::OPACITY)); | |
| 85 EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); | |
| 86 | |
| 87 // Check that the visibility is correct after the hide animation has finished. | |
| 88 window->Hide(); | |
| 89 window->layer()->GetAnimator()->StopAnimating(); | |
| 90 EXPECT_FALSE(window->layer()->visible()); | |
| 91 EXPECT_FALSE(window->IsVisible()); | |
| 92 } | |
| 93 | |
| 94 } // namespace corewm | |
| 95 } // namespace views | |
| OLD | NEW |