Chromium Code Reviews| Index: ui/aura_shell/shadow_controller_unittest.cc |
| diff --git a/ui/aura_shell/shadow_controller_unittest.cc b/ui/aura_shell/shadow_controller_unittest.cc |
| index 523543f9430ca3c99a1023a23d10bb5df81b178a..ce8cc52de8756205fe7d7553e6a124bf509b20c0 100644 |
| --- a/ui/aura_shell/shadow_controller_unittest.cc |
| +++ b/ui/aura_shell/shadow_controller_unittest.cc |
| @@ -2,6 +2,9 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <algorithm> |
| +#include <vector> |
| + |
| #include "base/memory/scoped_ptr.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/client/shadow_types.h" |
| @@ -11,6 +14,7 @@ |
| #include "ui/aura_shell/shadow_controller.h" |
|
sky
2011/11/22 22:44:54
nit: test files should have headers organized like
Daniel Erat
2011/11/22 22:58:43
Done.
|
| #include "ui/aura_shell/shell.h" |
| #include "ui/aura_shell/test/aura_shell_test_base.h" |
| +#include "ui/gfx/compositor/layer.h" |
| namespace aura_shell { |
| namespace test { |
| @@ -48,9 +52,6 @@ TEST_F(ShadowControllerTest, Shadow) { |
| // The shadow's layer should have the same parent as the window's. |
| EXPECT_EQ(window->parent()->layer(), shadow->layer()->parent()); |
| - // TODO(derat): Test stacking (after adding additional methods to ui::Layer so |
| - // that stacking order can be queried). |
| - |
| // When we remove the window from the hierarchy, its shadow should be removed |
| // too. |
| window->parent()->RemoveChild(window.get()); |
| @@ -86,5 +87,46 @@ TEST_F(ShadowControllerTest, ShadowBounds) { |
| EXPECT_EQ(kNewBounds, shadow->content_bounds()); |
| } |
| +// Test that shadows are stacked correctly. |
| +TEST_F(ShadowControllerTest, Stacking) { |
| + scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
| + window->SetType(aura::WINDOW_TYPE_NORMAL); |
| + window->Init(ui::Layer::LAYER_HAS_TEXTURE); |
| + window->SetParent(NULL); |
| + window->Show(); |
| + |
| + // Create a second window. It will appear above the first window. |
| + scoped_ptr<aura::Window> window2(new aura::Window(NULL)); |
| + window2->SetType(aura::WINDOW_TYPE_NORMAL); |
| + window2->Init(ui::Layer::LAYER_HAS_TEXTURE); |
| + window2->SetParent(NULL); |
| + window2->Show(); |
| + |
| + // Enable a shadow on the first window. |
| + window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); |
| + internal::ShadowController::TestApi api( |
| + aura_shell::Shell::GetInstance()->shadow_controller()); |
| + const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); |
| + ASSERT_TRUE(shadow != NULL); |
| + |
| + // Check that the second window is above the first window and that the first |
| + // window is above its shadow. |
| + ui::Layer* parent_layer = window->layer()->parent(); |
| + ASSERT_EQ(parent_layer, shadow->layer()->parent()); |
| + ASSERT_EQ(parent_layer, window2->layer()->parent()); |
| + const std::vector<ui::Layer*>& layers = parent_layer->children(); |
| + EXPECT_GT(std::find(layers.begin(), layers.end(), window2->layer()), |
| + std::find(layers.begin(), layers.end(), window->layer())); |
| + EXPECT_GT(std::find(layers.begin(), layers.end(), window->layer()), |
| + std::find(layers.begin(), layers.end(), shadow->layer())); |
| + |
| + // Raise the first window to the top and check that its shadow comes with it. |
| + window->parent()->StackChildAtTop(window.get()); |
| + EXPECT_GT(std::find(layers.begin(), layers.end(), window->layer()), |
| + std::find(layers.begin(), layers.end(), shadow->layer())); |
| + EXPECT_GT(std::find(layers.begin(), layers.end(), shadow->layer()), |
| + std::find(layers.begin(), layers.end(), window2->layer())); |
| +} |
| + |
| } // namespace test |
| } // namespace aura_shell |