OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/wm/shelf_layout_manager.h" | 5 #include "ash/wm/shelf_layout_manager.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 10 #include "ash/shell_window_ids.h" |
11 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
12 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
13 #include "ui/aura/monitor.h" | 13 #include "ui/aura/monitor.h" |
14 #include "ui/aura/monitor_manager.h" | 14 #include "ui/aura/monitor_manager.h" |
15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
| 16 #include "ui/aura/test/event_generator.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/base/animation/animation_container_element.h" | 18 #include "ui/base/animation/animation_container_element.h" |
18 #include "ui/gfx/compositor/layer_animator.h" | 19 #include "ui/gfx/compositor/layer_animator.h" |
19 #include "ui/gfx/compositor/layer.h" | 20 #include "ui/gfx/compositor/layer.h" |
20 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
22 | 23 |
23 namespace ash { | 24 namespace ash { |
24 namespace internal { | 25 namespace internal { |
25 | 26 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 aura::Env::GetInstance()->monitor_manager(); | 59 aura::Env::GetInstance()->monitor_manager(); |
59 const aura::Monitor* monitor = | 60 const aura::Monitor* monitor = |
60 manager->GetMonitorNearestWindow(Shell::GetRootWindow()); | 61 manager->GetMonitorNearestWindow(Shell::GetRootWindow()); |
61 ASSERT_TRUE(monitor); | 62 ASSERT_TRUE(monitor); |
62 // Bottom inset should be the max of widget heights. | 63 // Bottom inset should be the max of widget heights. |
63 EXPECT_EQ(shelf->shelf_height() + | 64 EXPECT_EQ(shelf->shelf_height() + |
64 ShelfLayoutManager::kWorkspaceAreaBottomInset, | 65 ShelfLayoutManager::kWorkspaceAreaBottomInset, |
65 monitor->work_area_insets().bottom()); | 66 monitor->work_area_insets().bottom()); |
66 | 67 |
67 // Hide the shelf. | 68 // Hide the shelf. |
68 shelf->SetState(ShelfLayoutManager::HIDDEN, | 69 shelf->SetState(ShelfLayoutManager::HIDDEN); |
69 ShelfLayoutManager::AUTO_HIDE_HIDDEN); | |
70 // Run the animation to completion. | 70 // Run the animation to completion. |
71 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); | 71 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); |
72 StepWidgetLayerAnimatorToEnd(shelf->status()); | 72 StepWidgetLayerAnimatorToEnd(shelf->status()); |
73 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); | 73 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); |
74 EXPECT_EQ(0, monitor->work_area_insets().bottom()); | 74 EXPECT_EQ(0, monitor->work_area_insets().bottom()); |
75 | 75 |
76 // Make sure the bounds of the two widgets changed. | 76 // Make sure the bounds of the two widgets changed. |
77 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), | 77 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), |
78 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 78 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
79 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 79 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), |
80 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 80 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
81 | 81 |
82 // And show it again. | 82 // And show it again. |
83 shelf->SetState(ShelfLayoutManager::VISIBLE, | 83 shelf->SetState(ShelfLayoutManager::VISIBLE); |
84 ShelfLayoutManager::AUTO_HIDE_HIDDEN); | |
85 // Run the animation to completion. | 84 // Run the animation to completion. |
86 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); | 85 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); |
87 StepWidgetLayerAnimatorToEnd(shelf->status()); | 86 StepWidgetLayerAnimatorToEnd(shelf->status()); |
88 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 87 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
89 EXPECT_EQ(shelf->shelf_height() + | 88 EXPECT_EQ(shelf->shelf_height() + |
90 ShelfLayoutManager::kWorkspaceAreaBottomInset, | 89 ShelfLayoutManager::kWorkspaceAreaBottomInset, |
91 monitor->work_area_insets().bottom()); | 90 monitor->work_area_insets().bottom()); |
92 | 91 |
93 // Make sure the bounds of the two widgets changed. | 92 // Make sure the bounds of the two widgets changed. |
94 gfx::Rect launcher_bounds( | 93 gfx::Rect launcher_bounds( |
(...skipping 13 matching lines...) Expand all Loading... |
108 // Force an initial layout. | 107 // Force an initial layout. |
109 shelf->LayoutShelf(); | 108 shelf->LayoutShelf(); |
110 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 109 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
111 | 110 |
112 const aura::MonitorManager* manager = | 111 const aura::MonitorManager* manager = |
113 aura::Env::GetInstance()->monitor_manager(); | 112 aura::Env::GetInstance()->monitor_manager(); |
114 const aura::Monitor* monitor = | 113 const aura::Monitor* monitor = |
115 manager->GetMonitorNearestWindow(Shell::GetRootWindow()); | 114 manager->GetMonitorNearestWindow(Shell::GetRootWindow()); |
116 | 115 |
117 // Hide the shelf. | 116 // Hide the shelf. |
118 shelf->SetState(ShelfLayoutManager::HIDDEN, | 117 shelf->SetState(ShelfLayoutManager::HIDDEN); |
119 ShelfLayoutManager::AUTO_HIDE_HIDDEN); | |
120 shelf->LayoutShelf(); | 118 shelf->LayoutShelf(); |
121 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); | 119 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); |
122 EXPECT_EQ(0, monitor->work_area_insets().bottom()); | 120 EXPECT_EQ(0, monitor->work_area_insets().bottom()); |
123 // Make sure the bounds of the two widgets changed. | 121 // Make sure the bounds of the two widgets changed. |
124 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), | 122 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), |
125 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 123 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
126 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 124 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), |
127 gfx::Screen::GetPrimaryMonitorBounds().bottom()); | 125 gfx::Screen::GetPrimaryMonitorBounds().bottom()); |
128 } | 126 } |
129 | 127 |
(...skipping 26 matching lines...) Expand all Loading... |
156 // crash. This test is here as originally the crash was in ShelfLayoutManager. | 154 // crash. This test is here as originally the crash was in ShelfLayoutManager. |
157 TEST_F(ShelfLayoutManagerTest, DontReferenceLauncherAfterDeletion) { | 155 TEST_F(ShelfLayoutManagerTest, DontReferenceLauncherAfterDeletion) { |
158 views::Widget* widget = new views::Widget; | 156 views::Widget* widget = new views::Widget; |
159 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 157 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
160 params.bounds = gfx::Rect(0, 0, 200, 200); | 158 params.bounds = gfx::Rect(0, 0, 200, 200); |
161 // Widget is now owned by the parent window. | 159 // Widget is now owned by the parent window. |
162 widget->Init(params); | 160 widget->Init(params); |
163 widget->SetFullscreen(true); | 161 widget->SetFullscreen(true); |
164 } | 162 } |
165 | 163 |
| 164 // Various assertions around auto-hide. |
| 165 TEST_F(ShelfLayoutManagerTest, AutoHide) { |
| 166 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
| 167 views::Widget* widget = new views::Widget; |
| 168 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 169 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 170 // Widget is now owned by the parent window. |
| 171 widget->Init(params); |
| 172 widget->Maximize(); |
| 173 widget->Show(); |
| 174 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); |
| 175 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 176 |
| 177 aura::RootWindow* root = Shell::GetRootWindow(); |
| 178 // LayoutShelf() forces the animation to completion, at which point the |
| 179 // launcher should go off the screen. |
| 180 shelf->LayoutShelf(); |
| 181 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideHeight, |
| 182 shelf->launcher_widget()->GetWindowScreenBounds().y()); |
| 183 |
| 184 // Move the mouse to the bottom of the screen. |
| 185 aura::test::EventGenerator generator(root, root); |
| 186 generator.MoveMouseTo(gfx::Point(0, root->bounds().bottom() - 1)); |
| 187 |
| 188 // Shelf should be shown again. |
| 189 shelf->SetState(ShelfLayoutManager::AUTO_HIDE); |
| 190 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
| 191 shelf->LayoutShelf(); |
| 192 EXPECT_EQ(root->bounds().bottom() - shelf->shelf_height(), |
| 193 shelf->launcher_widget()->GetWindowScreenBounds().y()); |
| 194 |
| 195 // Move mouse back up. |
| 196 generator.MoveMouseTo(gfx::Point(0, 0)); |
| 197 shelf->SetState(ShelfLayoutManager::AUTO_HIDE); |
| 198 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
| 199 shelf->LayoutShelf(); |
| 200 EXPECT_EQ(root->bounds().bottom() - ShelfLayoutManager::kAutoHideHeight, |
| 201 shelf->launcher_widget()->GetWindowScreenBounds().y()); |
| 202 } |
| 203 |
166 } // namespace internal | 204 } // namespace internal |
167 } // namespace ash | 205 } // namespace ash |
OLD | NEW |