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/accelerators/accelerator_controller.h" | 7 #include "ash/accelerators/accelerator_controller.h" |
8 #include "ash/accelerators/accelerator_table.h" | 8 #include "ash/accelerators/accelerator_table.h" |
9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
10 #include "ash/focus_cycler.h" | 10 #include "ash/focus_cycler.h" |
11 #include "ash/launcher/launcher.h" | 11 #include "ash/launcher/launcher.h" |
| 12 #include "ash/root_window_controller.h" |
12 #include "ash/screen_ash.h" | 13 #include "ash/screen_ash.h" |
13 #include "ash/shell.h" | 14 #include "ash/shell.h" |
14 #include "ash/shell_delegate.h" | 15 #include "ash/shell_delegate.h" |
15 #include "ash/shell_window_ids.h" | 16 #include "ash/shell_window_ids.h" |
16 #include "ash/system/status_area_widget.h" | 17 #include "ash/system/status_area_widget.h" |
17 #include "ash/system/tray/system_tray.h" | 18 #include "ash/system/tray/system_tray.h" |
18 #include "ash/system/tray/system_tray_item.h" | 19 #include "ash/system/tray/system_tray_item.h" |
19 #include "ash/test/ash_test_base.h" | 20 #include "ash/test/ash_test_base.h" |
20 #include "ash/wm/window_util.h" | 21 #include "ash/wm/window_util.h" |
21 #include "base/command_line.h" | 22 #include "base/command_line.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 | 146 |
146 DISALLOW_COPY_AND_ASSIGN(TestItem); | 147 DISALLOW_COPY_AND_ASSIGN(TestItem); |
147 }; | 148 }; |
148 | 149 |
149 } // namespace | 150 } // namespace |
150 | 151 |
151 class ShelfLayoutManagerTest : public ash::test::AshTestBase { | 152 class ShelfLayoutManagerTest : public ash::test::AshTestBase { |
152 public: | 153 public: |
153 ShelfLayoutManagerTest() {} | 154 ShelfLayoutManagerTest() {} |
154 | 155 |
| 156 ShelfLayoutManager* shelf_layout_manager() { |
| 157 return Shell::GetPrimaryRootWindowController()->shelf(); |
| 158 } |
| 159 |
155 void SetState(ShelfLayoutManager* shelf, | 160 void SetState(ShelfLayoutManager* shelf, |
156 ShelfLayoutManager::VisibilityState state) { | 161 ShelfLayoutManager::VisibilityState state) { |
157 shelf->SetState(state); | 162 shelf->SetState(state); |
158 } | 163 } |
159 | 164 |
160 void UpdateAutoHideStateNow() { | 165 void UpdateAutoHideStateNow() { |
161 GetShelfLayoutManager()->UpdateAutoHideStateNow(); | 166 GetShelfLayoutManager()->UpdateAutoHideStateNow(); |
162 } | 167 } |
163 | 168 |
164 aura::Window* CreateTestWindow() { | 169 aura::Window* CreateTestWindow() { |
(...skipping 21 matching lines...) Expand all Loading... |
186 #else | 191 #else |
187 #define MAYBE_SetVisible SetVisible | 192 #define MAYBE_SetVisible SetVisible |
188 #endif | 193 #endif |
189 // Makes sure SetVisible updates work area and widget appropriately. | 194 // Makes sure SetVisible updates work area and widget appropriately. |
190 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { | 195 TEST_F(ShelfLayoutManagerTest, MAYBE_SetVisible) { |
191 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 196 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
192 // Force an initial layout. | 197 // Force an initial layout. |
193 shelf->LayoutShelf(); | 198 shelf->LayoutShelf(); |
194 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 199 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
195 | 200 |
196 gfx::Rect status_bounds(shelf->status()->GetWindowBoundsInScreen()); | 201 gfx::Rect status_bounds( |
| 202 shelf->status_area_widget()->GetWindowBoundsInScreen()); |
197 gfx::Rect launcher_bounds( | 203 gfx::Rect launcher_bounds( |
198 shelf->launcher_widget()->GetWindowBoundsInScreen()); | 204 shelf->launcher_widget()->GetWindowBoundsInScreen()); |
199 int shelf_height = shelf->GetIdealBounds().height(); | 205 int shelf_height = shelf->GetIdealBounds().height(); |
200 | 206 |
201 const aura::DisplayManager* manager = | 207 const aura::DisplayManager* manager = |
202 aura::Env::GetInstance()->display_manager(); | 208 aura::Env::GetInstance()->display_manager(); |
203 const gfx::Display& display = | 209 const gfx::Display& display = |
204 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 210 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
205 ASSERT_NE(-1, display.id()); | 211 ASSERT_NE(-1, display.id()); |
206 // Bottom inset should be the max of widget heights. | 212 // Bottom inset should be the max of widget heights. |
207 EXPECT_EQ(shelf_height, | 213 EXPECT_EQ(shelf_height, |
208 display.bounds().bottom() - display.work_area().bottom()); | 214 display.bounds().bottom() - display.work_area().bottom()); |
209 | 215 |
210 // Hide the shelf. | 216 // Hide the shelf. |
211 SetState(shelf, ShelfLayoutManager::HIDDEN); | 217 SetState(shelf, ShelfLayoutManager::HIDDEN); |
212 // Run the animation to completion. | 218 // Run the animation to completion. |
213 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); | 219 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); |
214 StepWidgetLayerAnimatorToEnd(shelf->status()); | 220 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget()); |
215 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); | 221 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); |
216 EXPECT_EQ(0, | 222 EXPECT_EQ(0, |
217 display.bounds().bottom() - display.work_area().bottom()); | 223 display.bounds().bottom() - display.work_area().bottom()); |
218 | 224 |
219 // Make sure the bounds of the two widgets changed. | 225 // Make sure the bounds of the two widgets changed. |
220 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), | 226 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), |
221 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); | 227 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); |
222 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 228 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(), |
223 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); | 229 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); |
224 | 230 |
225 // And show it again. | 231 // And show it again. |
226 SetState(shelf, ShelfLayoutManager::VISIBLE); | 232 SetState(shelf, ShelfLayoutManager::VISIBLE); |
227 // Run the animation to completion. | 233 // Run the animation to completion. |
228 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); | 234 StepWidgetLayerAnimatorToEnd(shelf->launcher_widget()); |
229 StepWidgetLayerAnimatorToEnd(shelf->status()); | 235 StepWidgetLayerAnimatorToEnd(shelf->status_area_widget()); |
230 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 236 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
231 EXPECT_EQ(shelf_height, | 237 EXPECT_EQ(shelf_height, |
232 display.bounds().bottom() - display.work_area().bottom()); | 238 display.bounds().bottom() - display.work_area().bottom()); |
233 | 239 |
234 // Make sure the bounds of the two widgets changed. | 240 // Make sure the bounds of the two widgets changed. |
235 launcher_bounds = shelf->launcher_widget()->GetNativeView()->bounds(); | 241 launcher_bounds = shelf->launcher_widget()->GetNativeView()->bounds(); |
236 int bottom = | 242 int bottom = |
237 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom() - shelf_height; | 243 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom() - shelf_height; |
238 EXPECT_EQ(launcher_bounds.y(), | 244 EXPECT_EQ(launcher_bounds.y(), |
239 bottom + (shelf->GetIdealBounds().height() - | 245 bottom + (shelf->GetIdealBounds().height() - |
240 launcher_bounds.height()) / 2); | 246 launcher_bounds.height()) / 2); |
241 status_bounds = shelf->status()->GetNativeView()->bounds(); | 247 status_bounds = shelf->status_area_widget()->GetNativeView()->bounds(); |
242 EXPECT_EQ(status_bounds.y(), | 248 EXPECT_EQ(status_bounds.y(), |
243 bottom + shelf_height - status_bounds.height()); | 249 bottom + shelf_height - status_bounds.height()); |
244 } | 250 } |
245 | 251 |
246 // Makes sure LayoutShelf invoked while animating cleans things up. | 252 // Makes sure LayoutShelf invoked while animating cleans things up. |
247 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { | 253 TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { |
248 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 254 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
249 // Force an initial layout. | 255 // Force an initial layout. |
250 shelf->LayoutShelf(); | 256 shelf->LayoutShelf(); |
251 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 257 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
252 | 258 |
253 const aura::DisplayManager* manager = | 259 const aura::DisplayManager* manager = |
254 aura::Env::GetInstance()->display_manager(); | 260 aura::Env::GetInstance()->display_manager(); |
255 const gfx::Display& display = | 261 const gfx::Display& display = |
256 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 262 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
257 | 263 |
258 // Hide the shelf. | 264 // Hide the shelf. |
259 SetState(shelf, ShelfLayoutManager::HIDDEN); | 265 SetState(shelf, ShelfLayoutManager::HIDDEN); |
260 shelf->LayoutShelf(); | 266 shelf->LayoutShelf(); |
261 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); | 267 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); |
262 EXPECT_EQ(0, display.bounds().bottom() - display.work_area().bottom()); | 268 EXPECT_EQ(0, display.bounds().bottom() - display.work_area().bottom()); |
263 | 269 |
264 // Make sure the bounds of the two widgets changed. | 270 // Make sure the bounds of the two widgets changed. |
265 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), | 271 EXPECT_GE(shelf->launcher_widget()->GetNativeView()->bounds().y(), |
266 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); | 272 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); |
267 EXPECT_GE(shelf->status()->GetNativeView()->bounds().y(), | 273 EXPECT_GE(shelf->status_area_widget()->GetNativeView()->bounds().y(), |
268 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); | 274 Shell::GetScreen()->GetPrimaryDisplay().bounds().bottom()); |
269 } | 275 } |
270 | 276 |
271 // Makes sure the launcher is initially sized correctly. | 277 // Makes sure the launcher is initially sized correctly. |
272 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { | 278 TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { |
273 Launcher* launcher = Shell::GetInstance()->launcher(); | 279 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
274 ASSERT_TRUE(launcher); | 280 ASSERT_TRUE(launcher); |
275 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 281 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); |
276 ASSERT_TRUE(shelf_layout_manager); | 282 ASSERT_TRUE(shelf_layout_manager); |
277 ASSERT_TRUE(shelf_layout_manager->status()); | 283 ASSERT_TRUE(shelf_layout_manager->status_area_widget()); |
278 int status_width = | 284 int status_width = shelf_layout_manager->status_area_widget()-> |
279 shelf_layout_manager->status()->GetWindowBoundsInScreen().width(); | 285 GetWindowBoundsInScreen().width(); |
280 // Test only makes sense if the status is > 0, which is better be. | 286 // Test only makes sense if the status is > 0, which is better be. |
281 EXPECT_GT(status_width, 0); | 287 EXPECT_GT(status_width, 0); |
282 EXPECT_EQ(status_width, launcher->status_size().width()); | 288 EXPECT_EQ(status_width, launcher->status_size().width()); |
283 } | 289 } |
284 | 290 |
285 // Makes sure the launcher is sized when the status area changes size. | 291 // Makes sure the launcher is sized when the status area changes size. |
286 TEST_F(ShelfLayoutManagerTest, LauncherUpdatedWhenStatusAreaChangesSize) { | 292 TEST_F(ShelfLayoutManagerTest, LauncherUpdatedWhenStatusAreaChangesSize) { |
287 Launcher* launcher = Shell::GetInstance()->launcher(); | 293 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
288 ASSERT_TRUE(launcher); | 294 ASSERT_TRUE(launcher); |
289 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); | 295 ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); |
290 ASSERT_TRUE(shelf_layout_manager); | 296 ASSERT_TRUE(shelf_layout_manager); |
291 ASSERT_TRUE(shelf_layout_manager->status()); | 297 ASSERT_TRUE(shelf_layout_manager->status_area_widget()); |
292 shelf_layout_manager->status()->SetBounds(gfx::Rect(0, 0, 200, 200)); | 298 shelf_layout_manager->status_area_widget()->SetBounds( |
| 299 gfx::Rect(0, 0, 200, 200)); |
293 EXPECT_EQ(200, launcher->status_size().width()); | 300 EXPECT_EQ(200, launcher->status_size().width()); |
294 } | 301 } |
295 | 302 |
296 // Verifies when the shell is deleted with a full screen window we don't | 303 // Verifies when the shell is deleted with a full screen window we don't |
297 // crash. This test is here as originally the crash was in ShelfLayoutManager. | 304 // crash. This test is here as originally the crash was in ShelfLayoutManager. |
298 TEST_F(ShelfLayoutManagerTest, DontReferenceLauncherAfterDeletion) { | 305 TEST_F(ShelfLayoutManagerTest, DontReferenceLauncherAfterDeletion) { |
299 views::Widget* widget = new views::Widget; | 306 views::Widget* widget = new views::Widget; |
300 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 307 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
301 params.bounds = gfx::Rect(0, 0, 200, 200); | 308 params.bounds = gfx::Rect(0, 0, 200, 200); |
302 // Widget is now owned by the parent window. | 309 // Widget is now owned by the parent window. |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 // Focus the launcher. Have to go through the focus cycler as normal focus | 493 // Focus the launcher. Have to go through the focus cycler as normal focus |
487 // requests to it do nothing. | 494 // requests to it do nothing. |
488 shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); | 495 shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); |
489 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 496 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
490 | 497 |
491 widget->Activate(); | 498 widget->Activate(); |
492 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 499 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
493 | 500 |
494 // Trying to activate the status should fail, since we only allow activating | 501 // Trying to activate the status should fail, since we only allow activating |
495 // it when the user is using the keyboard (i.e. through FocusCycler). | 502 // it when the user is using the keyboard (i.e. through FocusCycler). |
496 shelf->status()->Activate(); | 503 shelf->status_area_widget()->Activate(); |
497 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); | 504 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_HIDDEN, shelf->auto_hide_state()); |
498 | 505 |
499 shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); | 506 shelf->launcher()->GetFocusCycler()->RotateFocus(FocusCycler::FORWARD); |
500 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state()); | 507 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE_SHOWN, shelf->auto_hide_state()); |
501 } | 508 } |
502 | 509 |
503 // Makes sure shelf will be visible when app list opens as shelf is in VISIBLE | 510 // Makes sure shelf will be visible when app list opens as shelf is in VISIBLE |
504 // state,and toggling app list won't change shelf visibility state. | 511 // state,and toggling app list won't change shelf visibility state. |
505 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) { | 512 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfVisibleState) { |
506 Shell* shell = Shell::GetInstance(); | 513 Shell* shell = Shell::GetInstance(); |
507 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); | 514 ShelfLayoutManager* shelf = shelf_layout_manager(); |
508 shelf->LayoutShelf(); | 515 shelf->LayoutShelf(); |
509 shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 516 shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
510 | 517 |
511 // Create a normal unmaximized windowm shelf should be visible. | 518 // Create a normal unmaximized windowm shelf should be visible. |
512 aura::Window* window = CreateTestWindow(); | 519 aura::Window* window = CreateTestWindow(); |
513 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 520 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
514 window->Show(); | 521 window->Show(); |
515 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 522 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
516 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 523 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
517 | 524 |
518 // Toggle app list to show, and the shelf stays visible. | 525 // Toggle app list to show, and the shelf stays visible. |
519 shell->ToggleAppList(); | 526 shell->ToggleAppList(); |
520 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 527 EXPECT_TRUE(shell->GetAppListTargetVisibility()); |
521 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 528 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
522 | 529 |
523 // Toggle app list to hide, and the shelf stays visible. | 530 // Toggle app list to hide, and the shelf stays visible. |
524 shell->ToggleAppList(); | 531 shell->ToggleAppList(); |
525 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 532 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
526 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 533 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
527 } | 534 } |
528 | 535 |
529 // Makes sure shelf will be shown with AUTO_HIDE_SHOWN state when app list opens | 536 // Makes sure shelf will be shown with AUTO_HIDE_SHOWN state when app list opens |
530 // as shelf is in AUTO_HIDE state, and toggling app list won't change shelf | 537 // as shelf is in AUTO_HIDE state, and toggling app list won't change shelf |
531 // visibility state. | 538 // visibility state. |
532 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) { | 539 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfAutoHideState) { |
533 Shell* shell = Shell::GetInstance(); | 540 Shell* shell = Shell::GetInstance(); |
534 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); | 541 ShelfLayoutManager* shelf = shelf_layout_manager(); |
535 shelf->LayoutShelf(); | 542 shelf->LayoutShelf(); |
536 shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 543 shell->SetShelfAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
537 | 544 |
538 // Create a window and show it in maximized state. | 545 // Create a window and show it in maximized state. |
539 aura::Window* window = CreateTestWindow(); | 546 aura::Window* window = CreateTestWindow(); |
540 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 547 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
541 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 548 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
542 window->Show(); | 549 window->Show(); |
543 wm::ActivateWindow(window); | 550 wm::ActivateWindow(window); |
544 | 551 |
(...skipping 13 matching lines...) Expand all Loading... |
558 // Toggle app list to hide. | 565 // Toggle app list to hide. |
559 shell->ToggleAppList(); | 566 shell->ToggleAppList(); |
560 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 567 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
561 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); | 568 EXPECT_EQ(ShelfLayoutManager::AUTO_HIDE, shelf->visibility_state()); |
562 } | 569 } |
563 | 570 |
564 // Makes sure shelf will be hidden when app list opens as shelf is in HIDDEN | 571 // Makes sure shelf will be hidden when app list opens as shelf is in HIDDEN |
565 // state, and toggling app list won't change shelf visibility state. | 572 // state, and toggling app list won't change shelf visibility state. |
566 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfHiddenState) { | 573 TEST_F(ShelfLayoutManagerTest, OpenAppListWithShelfHiddenState) { |
567 Shell* shell = Shell::GetInstance(); | 574 Shell* shell = Shell::GetInstance(); |
568 ShelfLayoutManager* shelf = Shell::GetInstance()->shelf(); | 575 ShelfLayoutManager* shelf = shelf_layout_manager(); |
569 // For shelf to be visible, app list is not open in initial state. | 576 // For shelf to be visible, app list is not open in initial state. |
570 shelf->LayoutShelf(); | 577 shelf->LayoutShelf(); |
571 | 578 |
572 // Create a window and make it full screen. | 579 // Create a window and make it full screen. |
573 aura::Window* window = CreateTestWindow(); | 580 aura::Window* window = CreateTestWindow(); |
574 window->SetBounds(gfx::Rect(0, 0, 100, 100)); | 581 window->SetBounds(gfx::Rect(0, 0, 100, 100)); |
575 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 582 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
576 window->Show(); | 583 window->Show(); |
577 wm::ActivateWindow(window); | 584 wm::ActivateWindow(window); |
578 | 585 |
579 // App list and shelf is not shown. | 586 // App list and shelf is not shown. |
580 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 587 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
581 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); | 588 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); |
582 | 589 |
583 // Toggle app list to show. | 590 // Toggle app list to show. |
584 shell->ToggleAppList(); | 591 shell->ToggleAppList(); |
585 EXPECT_TRUE(shell->GetAppListTargetVisibility()); | 592 EXPECT_TRUE(shell->GetAppListTargetVisibility()); |
586 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); | 593 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); |
587 | 594 |
588 // Toggle app list to hide. | 595 // Toggle app list to hide. |
589 shell->ToggleAppList(); | 596 shell->ToggleAppList(); |
590 EXPECT_FALSE(shell->GetAppListTargetVisibility()); | 597 EXPECT_FALSE(shell->GetAppListTargetVisibility()); |
591 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); | 598 EXPECT_EQ(ShelfLayoutManager::HIDDEN, shelf->visibility_state()); |
592 } | 599 } |
593 | 600 |
594 // Tests SHELF_ALIGNMENT_LEFT and SHELF_ALIGNMENT_RIGHT. | 601 // Tests SHELF_ALIGNMENT_LEFT and SHELF_ALIGNMENT_RIGHT. |
595 TEST_F(ShelfLayoutManagerTest, SetAlignment) { | 602 TEST_F(ShelfLayoutManagerTest, SetAlignment) { |
596 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 603 ShelfLayoutManager* shelf = shelf_layout_manager(); |
597 // Force an initial layout. | 604 // Force an initial layout. |
598 shelf->LayoutShelf(); | 605 shelf->LayoutShelf(); |
599 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); | 606 EXPECT_EQ(ShelfLayoutManager::VISIBLE, shelf->visibility_state()); |
600 | 607 |
601 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); | 608 shelf->SetAlignment(SHELF_ALIGNMENT_LEFT); |
602 | 609 |
603 gfx::Rect launcher_bounds( | 610 gfx::Rect launcher_bounds( |
604 shelf->launcher_widget()->GetWindowBoundsInScreen()); | 611 shelf->launcher_widget()->GetWindowBoundsInScreen()); |
605 const aura::DisplayManager* manager = | 612 const aura::DisplayManager* manager = |
606 aura::Env::GetInstance()->display_manager(); | 613 aura::Env::GetInstance()->display_manager(); |
607 gfx::Display display = | 614 gfx::Display display = |
608 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 615 manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
609 ASSERT_NE(-1, display.id()); | 616 ASSERT_NE(-1, display.id()); |
610 EXPECT_EQ(shelf->GetIdealBounds().width(), | 617 EXPECT_EQ(shelf->GetIdealBounds().width(), |
611 display.GetWorkAreaInsets().left()); | 618 display.GetWorkAreaInsets().left()); |
612 EXPECT_GE( | 619 EXPECT_GE( |
613 launcher_bounds.width(), | 620 launcher_bounds.width(), |
614 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width()); | 621 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width()); |
615 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, | 622 EXPECT_EQ(SHELF_ALIGNMENT_LEFT, |
616 Shell::GetInstance()->system_tray()->shelf_alignment()); | 623 Shell::GetInstance()->system_tray()->shelf_alignment()); |
617 gfx::Rect status_bounds(shelf->status()->GetWindowBoundsInScreen()); | 624 StatusAreaWidget* status_area_widget = shelf->status_area_widget(); |
| 625 gfx::Rect status_bounds(status_area_widget->GetWindowBoundsInScreen()); |
618 EXPECT_GE(status_bounds.width(), | 626 EXPECT_GE(status_bounds.width(), |
619 shelf->status()->GetContentsView()->GetPreferredSize().width()); | 627 status_area_widget->GetContentsView()->GetPreferredSize().width()); |
620 EXPECT_EQ(shelf->GetIdealBounds().width(), | 628 EXPECT_EQ(shelf->GetIdealBounds().width(), |
621 display.GetWorkAreaInsets().left()); | 629 display.GetWorkAreaInsets().left()); |
622 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); | 630 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); |
623 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 631 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
624 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); | 632 EXPECT_EQ(0, display.GetWorkAreaInsets().right()); |
625 EXPECT_EQ(display.bounds().x(), launcher_bounds.x()); | 633 EXPECT_EQ(display.bounds().x(), launcher_bounds.x()); |
626 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); | 634 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); |
627 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); | 635 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); |
628 | 636 |
629 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); | 637 shelf->SetAlignment(SHELF_ALIGNMENT_RIGHT); |
630 launcher_bounds = shelf->launcher_widget()->GetWindowBoundsInScreen(); | 638 launcher_bounds = shelf->launcher_widget()->GetWindowBoundsInScreen(); |
631 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); | 639 display = manager->GetDisplayNearestWindow(Shell::GetPrimaryRootWindow()); |
632 ASSERT_NE(-1, display.id()); | 640 ASSERT_NE(-1, display.id()); |
633 EXPECT_EQ(shelf->GetIdealBounds().width(), | 641 EXPECT_EQ(shelf->GetIdealBounds().width(), |
634 display.GetWorkAreaInsets().right()); | 642 display.GetWorkAreaInsets().right()); |
635 EXPECT_GE( | 643 EXPECT_GE( |
636 launcher_bounds.width(), | 644 launcher_bounds.width(), |
637 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width()); | 645 shelf->launcher_widget()->GetContentsView()->GetPreferredSize().width()); |
638 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, | 646 EXPECT_EQ(SHELF_ALIGNMENT_RIGHT, |
639 Shell::GetInstance()->system_tray()->shelf_alignment()); | 647 Shell::GetInstance()->system_tray()->shelf_alignment()); |
640 status_bounds = gfx::Rect(shelf->status()->GetWindowBoundsInScreen()); | 648 status_bounds = gfx::Rect(status_area_widget->GetWindowBoundsInScreen()); |
641 EXPECT_GE(status_bounds.width(), | 649 EXPECT_GE(status_bounds.width(), |
642 shelf->status()->GetContentsView()->GetPreferredSize().width()); | 650 status_area_widget->GetContentsView()->GetPreferredSize().width()); |
643 EXPECT_EQ(shelf->GetIdealBounds().width(), | 651 EXPECT_EQ(shelf->GetIdealBounds().width(), |
644 display.GetWorkAreaInsets().right()); | 652 display.GetWorkAreaInsets().right()); |
645 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); | 653 EXPECT_EQ(0, display.GetWorkAreaInsets().top()); |
646 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); | 654 EXPECT_EQ(0, display.GetWorkAreaInsets().bottom()); |
647 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); | 655 EXPECT_EQ(0, display.GetWorkAreaInsets().left()); |
648 EXPECT_EQ(display.work_area().right(), launcher_bounds.x()); | 656 EXPECT_EQ(display.work_area().right(), launcher_bounds.x()); |
649 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); | 657 EXPECT_EQ(display.bounds().y(), launcher_bounds.y()); |
650 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); | 658 EXPECT_EQ(display.bounds().height(), launcher_bounds.height()); |
651 } | 659 } |
652 | 660 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 shelf->LayoutShelf(); | 764 shelf->LayoutShelf(); |
757 | 765 |
758 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 766 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
759 SystemTray* tray = Shell::GetInstance()->system_tray(); | 767 SystemTray* tray = Shell::GetInstance()->system_tray(); |
760 | 768 |
761 // First, make sure the shelf is visible. | 769 // First, make sure the shelf is visible. |
762 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 770 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
763 EXPECT_FALSE(tray->HasSystemBubble()); | 771 EXPECT_FALSE(tray->HasSystemBubble()); |
764 | 772 |
765 // Now, drag up on the tray to show the bubble. | 773 // Now, drag up on the tray to show the bubble. |
766 gfx::Point start = shelf->status()->GetWindowBoundsInScreen().CenterPoint(); | 774 gfx::Point start = |
| 775 shelf->status_area_widget()->GetWindowBoundsInScreen().CenterPoint(); |
767 gfx::Point end(start.x(), start.y() - 100); | 776 gfx::Point end(start.x(), start.y() - 100); |
768 generator.GestureScrollSequence(start, end, | 777 generator.GestureScrollSequence(start, end, |
769 base::TimeDelta::FromMilliseconds(10), 1); | 778 base::TimeDelta::FromMilliseconds(10), 1); |
770 EXPECT_TRUE(tray->HasSystemBubble()); | 779 EXPECT_TRUE(tray->HasSystemBubble()); |
771 tray->CloseBubbleForTest(); | 780 tray->CloseBubbleForTest(); |
772 RunAllPendingInMessageLoop(); | 781 RunAllPendingInMessageLoop(); |
773 EXPECT_FALSE(tray->HasSystemBubble()); | 782 EXPECT_FALSE(tray->HasSystemBubble()); |
774 | 783 |
775 // Drag again, but only a small amount, and slowly. The bubble should not be | 784 // Drag again, but only a small amount, and slowly. The bubble should not be |
776 // visible. | 785 // visible. |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 // Activate the first window. Now, both windows should be of the same size | 881 // Activate the first window. Now, both windows should be of the same size |
873 // again. | 882 // again. |
874 widget_two->Activate(); | 883 widget_two->Activate(); |
875 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(), | 884 EXPECT_EQ(widget_one->GetNativeWindow()->bounds().ToString(), |
876 widget_two->GetNativeWindow()->bounds().ToString()); | 885 widget_two->GetNativeWindow()->bounds().ToString()); |
877 } | 886 } |
878 | 887 |
879 // Confirm that the shelf is dimmed only when content is maximized and | 888 // Confirm that the shelf is dimmed only when content is maximized and |
880 // shelf is not autohidden. | 889 // shelf is not autohidden. |
881 TEST_F(ShelfLayoutManagerTest, Dimming) { | 890 TEST_F(ShelfLayoutManagerTest, Dimming) { |
882 Shell::GetInstance()->shelf()->SetAutoHideBehavior( | 891 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
883 SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | |
884 scoped_ptr<aura::Window> w1(CreateTestWindow()); | 892 scoped_ptr<aura::Window> w1(CreateTestWindow()); |
885 w1->Show(); | 893 w1->Show(); |
886 wm::ActivateWindow(w1.get()); | 894 wm::ActivateWindow(w1.get()); |
887 | 895 |
888 // Normal window doesn't dim shelf. | 896 // Normal window doesn't dim shelf. |
889 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 897 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
890 EXPECT_FALSE(Shell::GetInstance()->launcher()->GetDimsShelf()); | 898 Launcher* launcher = Launcher::ForPrimaryDisplay(); |
| 899 EXPECT_FALSE(launcher->GetDimsShelf()); |
891 | 900 |
892 // Maximized window does. | 901 // Maximized window does. |
893 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 902 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
894 EXPECT_TRUE(Shell::GetInstance()->launcher()->GetDimsShelf()); | 903 EXPECT_TRUE(launcher->GetDimsShelf()); |
895 | 904 |
896 // Change back to normal stops dimming. | 905 // Change back to normal stops dimming. |
897 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); | 906 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
898 EXPECT_FALSE(Shell::GetInstance()->launcher()->GetDimsShelf()); | 907 EXPECT_FALSE(launcher->GetDimsShelf()); |
899 | 908 |
900 // Changing back to maximized dims again. | 909 // Changing back to maximized dims again. |
901 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); | 910 w1->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
902 EXPECT_TRUE(Shell::GetInstance()->launcher()->GetDimsShelf()); | 911 EXPECT_TRUE(launcher->GetDimsShelf()); |
903 | 912 |
904 // Changing shelf to autohide stops dimming. | 913 // Changing shelf to autohide stops dimming. |
905 Shell::GetInstance()->shelf()->SetAutoHideBehavior( | 914 shelf_layout_manager()->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
906 SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 915 EXPECT_FALSE(launcher->GetDimsShelf()); |
907 EXPECT_FALSE(Shell::GetInstance()->launcher()->GetDimsShelf()); | |
908 } | 916 } |
909 | 917 |
910 // Make sure that the shelf will not hide if the mouse is between a bubble and | 918 // Make sure that the shelf will not hide if the mouse is between a bubble and |
911 // the shelf. | 919 // the shelf. |
912 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) { | 920 TEST_F(ShelfLayoutManagerTest, BubbleEnlargesShelfMouseHitArea) { |
913 ShelfLayoutManager* shelf = GetShelfLayoutManager(); | 921 ShelfLayoutManager* shelf = GetShelfLayoutManager(); |
914 StatusAreaWidget* status_area = Shell::GetInstance()->status_area_widget(); | 922 StatusAreaWidget* status_area_widget = |
| 923 Shell::GetPrimaryRootWindowController()->status_area_widget(); |
915 SystemTray* tray = Shell::GetInstance()->system_tray(); | 924 SystemTray* tray = Shell::GetInstance()->system_tray(); |
916 | 925 |
917 shelf->LayoutShelf(); | 926 shelf->LayoutShelf(); |
918 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); | 927 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow()); |
919 | 928 |
920 // Make two iterations - first without a message bubble which should make | 929 // Make two iterations - first without a message bubble which should make |
921 // the shelf disappear and then with a message bubble which should keep it | 930 // the shelf disappear and then with a message bubble which should keep it |
922 // visible. | 931 // visible. |
923 for (int i = 0; i < 2; i++) { | 932 for (int i = 0; i < 2; i++) { |
924 // Make sure the shelf is visible and position the mouse over it. Then | 933 // Make sure the shelf is visible and position the mouse over it. Then |
925 // allow auto hide. | 934 // allow auto hide. |
926 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); | 935 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_NEVER); |
927 EXPECT_FALSE(status_area->IsMessageBubbleShown()); | 936 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); |
928 gfx::Point center = | 937 gfx::Point center = |
929 shelf->status()->GetWindowBoundsInScreen().CenterPoint(); | 938 status_area_widget->GetWindowBoundsInScreen().CenterPoint(); |
930 generator.MoveMouseTo(center.x(), center.y()); | 939 generator.MoveMouseTo(center.x(), center.y()); |
931 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); | 940 shelf->SetAutoHideBehavior(SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS); |
932 EXPECT_TRUE(shelf->IsVisible()); | 941 EXPECT_TRUE(shelf->IsVisible()); |
933 if (!i) { | 942 if (!i) { |
934 // In our first iteration we make sure there is no bubble. | 943 // In our first iteration we make sure there is no bubble. |
935 tray->CloseBubbleForTest(); | 944 tray->CloseBubbleForTest(); |
936 EXPECT_FALSE(status_area->IsMessageBubbleShown()); | 945 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); |
937 } else { | 946 } else { |
938 // In our second iteration we show a bubble. | 947 // In our second iteration we show a bubble. |
939 TestItem *item = new TestItem; | 948 TestItem *item = new TestItem; |
940 tray->AddTrayItem(item); | 949 tray->AddTrayItem(item); |
941 tray->ShowNotificationView(item); | 950 tray->ShowNotificationView(item); |
942 EXPECT_TRUE(status_area->IsMessageBubbleShown()); | 951 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown()); |
943 } | 952 } |
944 // Move the pointer over the edge of the shelf. | 953 // Move the pointer over the edge of the shelf. |
945 generator.MoveMouseTo(center.x(), | 954 generator.MoveMouseTo( |
946 shelf->status()->GetWindowBoundsInScreen().y() - 7); | 955 center.x(), status_area_widget->GetWindowBoundsInScreen().y() - 7); |
947 shelf->UpdateVisibilityState(); | 956 shelf->UpdateVisibilityState(); |
948 if (i) { | 957 if (i) { |
949 EXPECT_TRUE(shelf->IsVisible()); | 958 EXPECT_TRUE(shelf->IsVisible()); |
950 EXPECT_TRUE(status_area->IsMessageBubbleShown()); | 959 EXPECT_TRUE(status_area_widget->IsMessageBubbleShown()); |
951 } else { | 960 } else { |
952 EXPECT_FALSE(shelf->IsVisible()); | 961 EXPECT_FALSE(shelf->IsVisible()); |
953 EXPECT_FALSE(status_area->IsMessageBubbleShown()); | 962 EXPECT_FALSE(status_area_widget->IsMessageBubbleShown()); |
954 } | 963 } |
955 } | 964 } |
956 } | 965 } |
957 | 966 |
958 } // namespace internal | 967 } // namespace internal |
959 } // namespace ash | 968 } // namespace ash |
OLD | NEW |