OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" |
| 6 #include "ui/aura/client/aura_constants.h" |
| 7 #include "ui/aura/client/shadow_types.h" |
| 8 #include "ui/aura/desktop.h" |
| 9 #include "ui/aura/window.h" |
| 10 #include "ui/aura_shell/shadow.h" |
| 11 #include "ui/aura_shell/shadow_controller.h" |
| 12 #include "ui/aura_shell/shell.h" |
| 13 #include "ui/aura_shell/test/aura_shell_test_base.h" |
| 14 |
| 15 namespace aura_shell { |
| 16 namespace test { |
| 17 |
| 18 typedef aura_shell::test::AuraShellTestBase ShadowControllerTest; |
| 19 |
| 20 // Tests that various methods in Window update the Shadow object as expected. |
| 21 TEST_F(ShadowControllerTest, Shadow) { |
| 22 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
| 23 window->SetType(aura::WINDOW_TYPE_NORMAL); |
| 24 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); |
| 25 window->Init(ui::Layer::LAYER_HAS_TEXTURE); |
| 26 window->SetParent(NULL); |
| 27 |
| 28 // We shouldn't create the shadow before the window is visible. |
| 29 internal::ShadowController::TestApi api( |
| 30 aura_shell::Shell::GetInstance()->shadow_controller()); |
| 31 EXPECT_TRUE(api.GetShadowForWindow(window.get()) == NULL); |
| 32 |
| 33 // The shadow's visibility should be updated along with the window's. |
| 34 window->Show(); |
| 35 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); |
| 36 ASSERT_TRUE(shadow != NULL); |
| 37 EXPECT_TRUE(shadow->layer()->visible()); |
| 38 window->Hide(); |
| 39 EXPECT_FALSE(shadow->layer()->visible()); |
| 40 |
| 41 // If the shadow is disabled, it shouldn't be shown even when the window is. |
| 42 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_NONE); |
| 43 window->Show(); |
| 44 EXPECT_FALSE(shadow->layer()->visible()); |
| 45 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); |
| 46 EXPECT_TRUE(shadow->layer()->visible()); |
| 47 |
| 48 // The shadow's layer should have the same parent as the window's. |
| 49 EXPECT_EQ(window->parent()->layer(), shadow->layer()->parent()); |
| 50 |
| 51 // TODO(derat): Test stacking (after adding additional methods to ui::Layer so |
| 52 // that stacking order can be queried). |
| 53 |
| 54 // When we remove the window from the hierarchy, its shadow should be removed |
| 55 // too. |
| 56 window->parent()->RemoveChild(window.get()); |
| 57 EXPECT_TRUE(shadow->layer()->parent() == NULL); |
| 58 |
| 59 aura::Window* window_ptr = window.get(); |
| 60 window.reset(); |
| 61 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); |
| 62 } |
| 63 |
| 64 // Tests that the window's shadow's bounds are updated correctly. |
| 65 TEST_F(ShadowControllerTest, ShadowBounds) { |
| 66 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
| 67 window->SetType(aura::WINDOW_TYPE_NORMAL); |
| 68 window->Init(ui::Layer::LAYER_HAS_TEXTURE); |
| 69 window->SetParent(NULL); |
| 70 window->Show(); |
| 71 |
| 72 const gfx::Rect kOldBounds(20, 30, 400, 300); |
| 73 window->SetBounds(kOldBounds); |
| 74 |
| 75 // When the shadow is first created, it should use the window's bounds. |
| 76 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); |
| 77 internal::ShadowController::TestApi api( |
| 78 aura_shell::Shell::GetInstance()->shadow_controller()); |
| 79 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); |
| 80 ASSERT_TRUE(shadow != NULL); |
| 81 EXPECT_EQ(kOldBounds, shadow->content_bounds()); |
| 82 |
| 83 // When we change the window's bounds, the shadow's should be updated too. |
| 84 gfx::Rect kNewBounds(50, 60, 500, 400); |
| 85 window->SetBounds(kNewBounds); |
| 86 EXPECT_EQ(kNewBounds, shadow->content_bounds()); |
| 87 } |
| 88 |
| 89 } // namespace test |
| 90 } // namespace aura_shell |
OLD | NEW |