Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: ui/aura_shell/shadow_controller_unittest.cc

Issue 8785005: aura: Make shadows be children of window layers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura_shell/shadow_controller.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura_shell/shadow_controller.h" 5 #include "ui/aura_shell/shadow_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 12 matching lines...) Expand all
23 typedef aura_shell::test::AuraShellTestBase ShadowControllerTest; 23 typedef aura_shell::test::AuraShellTestBase ShadowControllerTest;
24 24
25 // Tests that various methods in Window update the Shadow object as expected. 25 // Tests that various methods in Window update the Shadow object as expected.
26 TEST_F(ShadowControllerTest, Shadow) { 26 TEST_F(ShadowControllerTest, Shadow) {
27 scoped_ptr<aura::Window> window(new aura::Window(NULL)); 27 scoped_ptr<aura::Window> window(new aura::Window(NULL));
28 window->SetType(aura::WINDOW_TYPE_NORMAL); 28 window->SetType(aura::WINDOW_TYPE_NORMAL);
29 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); 29 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR);
30 window->Init(ui::Layer::LAYER_HAS_TEXTURE); 30 window->Init(ui::Layer::LAYER_HAS_TEXTURE);
31 window->SetParent(NULL); 31 window->SetParent(NULL);
32 32
33 // We shouldn't create the shadow before the window is visible. 33 // We should create the shadow before the window is visible (the shadow's
34 // layer won't get drawn yet since it's a child of the window's layer).
34 internal::ShadowController::TestApi api( 35 internal::ShadowController::TestApi api(
35 aura_shell::Shell::GetInstance()->shadow_controller()); 36 aura_shell::Shell::GetInstance()->shadow_controller());
36 EXPECT_TRUE(api.GetShadowForWindow(window.get()) == NULL);
37
38 // The shadow's visibility should be updated along with the window's.
39 window->Show();
40 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); 37 const internal::Shadow* shadow = api.GetShadowForWindow(window.get());
41 ASSERT_TRUE(shadow != NULL); 38 ASSERT_TRUE(shadow != NULL);
42 EXPECT_TRUE(shadow->layer()->visible()); 39 EXPECT_TRUE(shadow->layer()->visible());
40
41 // The shadow should remain visible after window visibility changes.
42 window->Show();
43 EXPECT_TRUE(shadow->layer()->visible());
43 window->Hide(); 44 window->Hide();
44 EXPECT_FALSE(shadow->layer()->visible()); 45 EXPECT_TRUE(shadow->layer()->visible());
45 46
46 // If the shadow is disabled, it shouldn't be shown even when the window is. 47 // If the shadow is disabled, it should be hidden.
47 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_NONE); 48 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_NONE);
48 window->Show(); 49 window->Show();
49 EXPECT_FALSE(shadow->layer()->visible()); 50 EXPECT_FALSE(shadow->layer()->visible());
50 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); 51 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR);
51 EXPECT_TRUE(shadow->layer()->visible()); 52 EXPECT_TRUE(shadow->layer()->visible());
52 53
53 // The shadow's layer should have the same parent as the window's. 54 // The shadow's layer should be a child of the window's layer.
54 EXPECT_EQ(window->parent()->layer(), shadow->layer()->parent()); 55 EXPECT_EQ(window->layer(), shadow->layer()->parent());
55 56
56 // When we remove the window from the hierarchy, its shadow should be removed
57 // too.
58 window->parent()->RemoveChild(window.get()); 57 window->parent()->RemoveChild(window.get());
59 EXPECT_TRUE(shadow->layer()->parent() == NULL);
60
61 aura::Window* window_ptr = window.get(); 58 aura::Window* window_ptr = window.get();
62 window.reset(); 59 window.reset();
63 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); 60 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL);
64 } 61 }
65 62
66 // Tests that the window's shadow's bounds are updated correctly. 63 // Tests that the window's shadow's bounds are updated correctly.
67 TEST_F(ShadowControllerTest, ShadowBounds) { 64 TEST_F(ShadowControllerTest, ShadowBounds) {
68 scoped_ptr<aura::Window> window(new aura::Window(NULL)); 65 scoped_ptr<aura::Window> window(new aura::Window(NULL));
69 window->SetType(aura::WINDOW_TYPE_NORMAL); 66 window->SetType(aura::WINDOW_TYPE_NORMAL);
70 window->Init(ui::Layer::LAYER_HAS_TEXTURE); 67 window->Init(ui::Layer::LAYER_HAS_TEXTURE);
71 window->SetParent(NULL); 68 window->SetParent(NULL);
72 window->Show(); 69 window->Show();
73 70
74 const gfx::Rect kOldBounds(20, 30, 400, 300); 71 const gfx::Rect kOldBounds(20, 30, 400, 300);
75 window->SetBounds(kOldBounds); 72 window->SetBounds(kOldBounds);
76 73
77 // When the shadow is first created, it should use the window's bounds. 74 // When the shadow is first created, it should use the window's size (but
75 // remain at the origin, since it's a child of the window's layer).
78 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); 76 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR);
79 internal::ShadowController::TestApi api( 77 internal::ShadowController::TestApi api(
80 aura_shell::Shell::GetInstance()->shadow_controller()); 78 aura_shell::Shell::GetInstance()->shadow_controller());
81 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); 79 const internal::Shadow* shadow = api.GetShadowForWindow(window.get());
82 ASSERT_TRUE(shadow != NULL); 80 ASSERT_TRUE(shadow != NULL);
83 EXPECT_EQ(kOldBounds, shadow->content_bounds()); 81 EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(),
82 shadow->content_bounds().ToString());
84 83
85 // When we change the window's bounds, the shadow's should be updated too. 84 // When we change the window's bounds, the shadow's should be updated too.
86 gfx::Rect kNewBounds(50, 60, 500, 400); 85 gfx::Rect kNewBounds(50, 60, 500, 400);
87 window->SetBounds(kNewBounds); 86 window->SetBounds(kNewBounds);
88 EXPECT_EQ(kNewBounds, shadow->content_bounds()); 87 EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(),
89 } 88 shadow->content_bounds().ToString());
90
91 // Test that shadows are stacked correctly.
92 TEST_F(ShadowControllerTest, Stacking) {
93 scoped_ptr<aura::Window> window(new aura::Window(NULL));
94 window->SetType(aura::WINDOW_TYPE_NORMAL);
95 window->Init(ui::Layer::LAYER_HAS_TEXTURE);
96 window->SetParent(NULL);
97 window->Show();
98
99 // Create a second window. It will appear above the first window.
100 scoped_ptr<aura::Window> window2(new aura::Window(NULL));
101 window2->SetType(aura::WINDOW_TYPE_NORMAL);
102 window2->Init(ui::Layer::LAYER_HAS_TEXTURE);
103 window2->SetParent(NULL);
104 window2->Show();
105
106 // Enable a shadow on the first window.
107 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR);
108 internal::ShadowController::TestApi api(
109 aura_shell::Shell::GetInstance()->shadow_controller());
110 const internal::Shadow* shadow = api.GetShadowForWindow(window.get());
111 ASSERT_TRUE(shadow != NULL);
112
113 // Check that the second window is above the first window and that the first
114 // window is above its shadow.
115 ui::Layer* parent_layer = window->layer()->parent();
116 ASSERT_EQ(parent_layer, shadow->layer()->parent());
117 ASSERT_EQ(parent_layer, window2->layer()->parent());
118 const std::vector<ui::Layer*>& layers = parent_layer->children();
119 EXPECT_GT(std::find(layers.begin(), layers.end(), window2->layer()),
120 std::find(layers.begin(), layers.end(), window->layer()));
121 EXPECT_GT(std::find(layers.begin(), layers.end(), window->layer()),
122 std::find(layers.begin(), layers.end(), shadow->layer()));
123
124 // Raise the first window to the top and check that its shadow comes with it.
125 window->parent()->StackChildAtTop(window.get());
126 EXPECT_GT(std::find(layers.begin(), layers.end(), window->layer()),
127 std::find(layers.begin(), layers.end(), shadow->layer()));
128 EXPECT_GT(std::find(layers.begin(), layers.end(), shadow->layer()),
129 std::find(layers.begin(), layers.end(), window2->layer()));
130 } 89 }
131 90
132 } // namespace test 91 } // namespace test
133 } // namespace aura_shell 92 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/shadow_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698