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 "ui/aura_shell/shadow_controller.h" | |
6 | |
7 #include <algorithm> | |
8 #include <vector> | |
9 | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "ui/aura/root_window.h" | |
12 #include "ui/aura/window.h" | |
13 #include "ui/aura_shell/shadow.h" | |
14 #include "ui/aura_shell/shadow_types.h" | |
15 #include "ui/aura_shell/shell.h" | |
16 #include "ui/aura_shell/test/aura_shell_test_base.h" | |
17 #include "ui/aura_shell/window_properties.h" | |
18 #include "ui/gfx/compositor/layer.h" | |
19 | |
20 namespace aura_shell { | |
21 namespace test { | |
22 | |
23 typedef aura_shell::test::AuraShellTestBase ShadowControllerTest; | |
24 | |
25 // Tests that various methods in Window update the Shadow object as expected. | |
26 TEST_F(ShadowControllerTest, Shadow) { | |
27 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | |
28 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | |
29 window->Init(ui::Layer::LAYER_HAS_TEXTURE); | |
30 window->SetParent(NULL); | |
31 | |
32 // We should create the shadow before the window is visible (the shadow's | |
33 // layer won't get drawn yet since it's a child of the window's layer). | |
34 internal::ShadowController::TestApi api( | |
35 aura_shell::Shell::GetInstance()->shadow_controller()); | |
36 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); | |
37 ASSERT_TRUE(shadow != NULL); | |
38 EXPECT_TRUE(shadow->layer()->visible()); | |
39 | |
40 // The shadow should remain visible after window visibility changes. | |
41 window->Show(); | |
42 EXPECT_TRUE(shadow->layer()->visible()); | |
43 window->Hide(); | |
44 EXPECT_TRUE(shadow->layer()->visible()); | |
45 | |
46 // If the shadow is disabled, it should be hidden. | |
47 internal::SetShadowType(window.get(), internal::SHADOW_TYPE_NONE); | |
48 window->Show(); | |
49 EXPECT_FALSE(shadow->layer()->visible()); | |
50 internal::SetShadowType(window.get(), internal::SHADOW_TYPE_RECTANGULAR); | |
51 EXPECT_TRUE(shadow->layer()->visible()); | |
52 | |
53 // The shadow's layer should be a child of the window's layer. | |
54 EXPECT_EQ(window->layer(), shadow->layer()->parent()); | |
55 | |
56 window->parent()->RemoveChild(window.get()); | |
57 aura::Window* window_ptr = window.get(); | |
58 window.reset(); | |
59 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); | |
60 } | |
61 | |
62 // Tests that the window's shadow's bounds are updated correctly. | |
63 TEST_F(ShadowControllerTest, ShadowBounds) { | |
64 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | |
65 window->SetType(aura::client::WINDOW_TYPE_NORMAL); | |
66 window->Init(ui::Layer::LAYER_HAS_TEXTURE); | |
67 window->SetParent(NULL); | |
68 window->Show(); | |
69 | |
70 const gfx::Rect kOldBounds(20, 30, 400, 300); | |
71 window->SetBounds(kOldBounds); | |
72 | |
73 // When the shadow is first created, it should use the window's size (but | |
74 // remain at the origin, since it's a child of the window's layer). | |
75 internal::SetShadowType(window.get(), internal::SHADOW_TYPE_RECTANGULAR); | |
76 internal::ShadowController::TestApi api( | |
77 aura_shell::Shell::GetInstance()->shadow_controller()); | |
78 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); | |
79 ASSERT_TRUE(shadow != NULL); | |
80 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(), | |
81 shadow->content_bounds().ToString()); | |
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(gfx::Rect(kNewBounds.size()).ToString(), | |
87 shadow->content_bounds().ToString()); | |
88 } | |
89 | |
90 } // namespace test | |
91 } // namespace aura_shell | |
OLD | NEW |