diff options
Diffstat (limited to 'ui/aura_shell/shadow_controller_unittest.cc')
-rw-r--r-- | ui/aura_shell/shadow_controller_unittest.cc | 51 |
1 files changed, 47 insertions, 4 deletions
diff --git a/ui/aura_shell/shadow_controller_unittest.cc b/ui/aura_shell/shadow_controller_unittest.cc index 523543f..d045741 100644 --- a/ui/aura_shell/shadow_controller_unittest.cc +++ b/ui/aura_shell/shadow_controller_unittest.cc @@ -2,15 +2,20 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "ui/aura_shell/shadow_controller.h" + +#include <algorithm> +#include <vector> + #include "base/memory/scoped_ptr.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/shadow_types.h" #include "ui/aura/desktop.h" #include "ui/aura/window.h" #include "ui/aura_shell/shadow.h" -#include "ui/aura_shell/shadow_controller.h" #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 +53,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 +88,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 |