Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <algorithm> | |
| 6 #include <vector> | |
| 7 | |
| 5 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 6 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
| 7 #include "ui/aura/client/shadow_types.h" | 10 #include "ui/aura/client/shadow_types.h" |
| 8 #include "ui/aura/desktop.h" | 11 #include "ui/aura/desktop.h" |
| 9 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 10 #include "ui/aura_shell/shadow.h" | 13 #include "ui/aura_shell/shadow.h" |
| 11 #include "ui/aura_shell/shadow_controller.h" | 14 #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.
| |
| 12 #include "ui/aura_shell/shell.h" | 15 #include "ui/aura_shell/shell.h" |
| 13 #include "ui/aura_shell/test/aura_shell_test_base.h" | 16 #include "ui/aura_shell/test/aura_shell_test_base.h" |
| 17 #include "ui/gfx/compositor/layer.h" | |
| 14 | 18 |
| 15 namespace aura_shell { | 19 namespace aura_shell { |
| 16 namespace test { | 20 namespace test { |
| 17 | 21 |
| 18 typedef aura_shell::test::AuraShellTestBase ShadowControllerTest; | 22 typedef aura_shell::test::AuraShellTestBase ShadowControllerTest; |
| 19 | 23 |
| 20 // Tests that various methods in Window update the Shadow object as expected. | 24 // Tests that various methods in Window update the Shadow object as expected. |
| 21 TEST_F(ShadowControllerTest, Shadow) { | 25 TEST_F(ShadowControllerTest, Shadow) { |
| 22 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | 26 scoped_ptr<aura::Window> window(new aura::Window(NULL)); |
| 23 window->SetType(aura::WINDOW_TYPE_NORMAL); | 27 window->SetType(aura::WINDOW_TYPE_NORMAL); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 41 // If the shadow is disabled, it shouldn't be shown even when the window is. | 45 // If the shadow is disabled, it shouldn't be shown even when the window is. |
| 42 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_NONE); | 46 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_NONE); |
| 43 window->Show(); | 47 window->Show(); |
| 44 EXPECT_FALSE(shadow->layer()->visible()); | 48 EXPECT_FALSE(shadow->layer()->visible()); |
| 45 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); | 49 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); |
| 46 EXPECT_TRUE(shadow->layer()->visible()); | 50 EXPECT_TRUE(shadow->layer()->visible()); |
| 47 | 51 |
| 48 // The shadow's layer should have the same parent as the window's. | 52 // The shadow's layer should have the same parent as the window's. |
| 49 EXPECT_EQ(window->parent()->layer(), shadow->layer()->parent()); | 53 EXPECT_EQ(window->parent()->layer(), shadow->layer()->parent()); |
| 50 | 54 |
| 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 // When we remove the window from the hierarchy, its shadow should be removed |
| 55 // too. | 56 // too. |
| 56 window->parent()->RemoveChild(window.get()); | 57 window->parent()->RemoveChild(window.get()); |
| 57 EXPECT_TRUE(shadow->layer()->parent() == NULL); | 58 EXPECT_TRUE(shadow->layer()->parent() == NULL); |
| 58 | 59 |
| 59 aura::Window* window_ptr = window.get(); | 60 aura::Window* window_ptr = window.get(); |
| 60 window.reset(); | 61 window.reset(); |
| 61 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); | 62 EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); |
| 62 } | 63 } |
| 63 | 64 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 79 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); | 80 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); |
| 80 ASSERT_TRUE(shadow != NULL); | 81 ASSERT_TRUE(shadow != NULL); |
| 81 EXPECT_EQ(kOldBounds, shadow->content_bounds()); | 82 EXPECT_EQ(kOldBounds, shadow->content_bounds()); |
| 82 | 83 |
| 83 // 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. |
| 84 gfx::Rect kNewBounds(50, 60, 500, 400); | 85 gfx::Rect kNewBounds(50, 60, 500, 400); |
| 85 window->SetBounds(kNewBounds); | 86 window->SetBounds(kNewBounds); |
| 86 EXPECT_EQ(kNewBounds, shadow->content_bounds()); | 87 EXPECT_EQ(kNewBounds, shadow->content_bounds()); |
| 87 } | 88 } |
| 88 | 89 |
| 90 // Test that shadows are stacked correctly. | |
| 91 TEST_F(ShadowControllerTest, Stacking) { | |
| 92 scoped_ptr<aura::Window> window(new aura::Window(NULL)); | |
| 93 window->SetType(aura::WINDOW_TYPE_NORMAL); | |
| 94 window->Init(ui::Layer::LAYER_HAS_TEXTURE); | |
| 95 window->SetParent(NULL); | |
| 96 window->Show(); | |
| 97 | |
| 98 // Create a second window. It will appear above the first window. | |
| 99 scoped_ptr<aura::Window> window2(new aura::Window(NULL)); | |
| 100 window2->SetType(aura::WINDOW_TYPE_NORMAL); | |
| 101 window2->Init(ui::Layer::LAYER_HAS_TEXTURE); | |
| 102 window2->SetParent(NULL); | |
| 103 window2->Show(); | |
| 104 | |
| 105 // Enable a shadow on the first window. | |
| 106 window->SetIntProperty(aura::kShadowTypeKey, aura::SHADOW_TYPE_RECTANGULAR); | |
| 107 internal::ShadowController::TestApi api( | |
| 108 aura_shell::Shell::GetInstance()->shadow_controller()); | |
| 109 const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); | |
| 110 ASSERT_TRUE(shadow != NULL); | |
| 111 | |
| 112 // Check that the second window is above the first window and that the first | |
| 113 // window is above its shadow. | |
| 114 ui::Layer* parent_layer = window->layer()->parent(); | |
| 115 ASSERT_EQ(parent_layer, shadow->layer()->parent()); | |
| 116 ASSERT_EQ(parent_layer, window2->layer()->parent()); | |
| 117 const std::vector<ui::Layer*>& layers = parent_layer->children(); | |
| 118 EXPECT_GT(std::find(layers.begin(), layers.end(), window2->layer()), | |
| 119 std::find(layers.begin(), layers.end(), window->layer())); | |
| 120 EXPECT_GT(std::find(layers.begin(), layers.end(), window->layer()), | |
| 121 std::find(layers.begin(), layers.end(), shadow->layer())); | |
| 122 | |
| 123 // Raise the first window to the top and check that its shadow comes with it. | |
| 124 window->parent()->StackChildAtTop(window.get()); | |
| 125 EXPECT_GT(std::find(layers.begin(), layers.end(), window->layer()), | |
| 126 std::find(layers.begin(), layers.end(), shadow->layer())); | |
| 127 EXPECT_GT(std::find(layers.begin(), layers.end(), shadow->layer()), | |
| 128 std::find(layers.begin(), layers.end(), window2->layer())); | |
| 129 } | |
| 130 | |
| 89 } // namespace test | 131 } // namespace test |
| 90 } // namespace aura_shell | 132 } // namespace aura_shell |
| OLD | NEW |