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/shell.h" | 5 #include "ash/shell.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/common/ash_switches.h" | 10 #include "ash/common/ash_switches.h" |
11 #include "ash/common/session/session_state_delegate.h" | 11 #include "ash/common/session/session_state_delegate.h" |
12 #include "ash/common/shelf/shelf_layout_manager.h" | 12 #include "ash/common/shelf/shelf_layout_manager.h" |
13 #include "ash/common/shelf/shelf_widget.h" | 13 #include "ash/common/shelf/shelf_widget.h" |
14 #include "ash/common/shelf/wm_shelf.h" | 14 #include "ash/common/shelf/wm_shelf.h" |
15 #include "ash/common/shell_window_ids.h" | 15 #include "ash/common/shell_window_ids.h" |
16 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
17 #include "ash/desktop_background/desktop_background_widget_controller.h" | |
18 #include "ash/display/mouse_cursor_event_filter.h" | 17 #include "ash/display/mouse_cursor_event_filter.h" |
19 #include "ash/drag_drop/drag_drop_controller.h" | 18 #include "ash/drag_drop/drag_drop_controller.h" |
20 #include "ash/root_window_controller.h" | 19 #include "ash/root_window_controller.h" |
21 #include "ash/test/ash_test_base.h" | 20 #include "ash/test/ash_test_base.h" |
22 #include "ash/test/shell_test_api.h" | 21 #include "ash/test/shell_test_api.h" |
| 22 #include "ash/wallpaper/wallpaper_widget_controller.h" |
23 #include "ash/wm/window_util.h" | 23 #include "ash/wm/window_util.h" |
24 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
26 #include "ui/aura/client/aura_constants.h" | 26 #include "ui/aura/client/aura_constants.h" |
27 #include "ui/aura/env.h" | 27 #include "ui/aura/env.h" |
28 #include "ui/aura/window.h" | 28 #include "ui/aura/window.h" |
29 #include "ui/aura/window_event_dispatcher.h" | 29 #include "ui/aura/window_event_dispatcher.h" |
30 #include "ui/base/models/simple_menu_model.h" | 30 #include "ui/base/models/simple_menu_model.h" |
31 #include "ui/events/test/event_generator.h" | 31 #include "ui/events/test/event_generator.h" |
32 #include "ui/events/test/events_test_utils.h" | 32 #include "ui/events/test/events_test_utils.h" |
(...skipping 17 matching lines...) Expand all Loading... |
50 } | 50 } |
51 | 51 |
52 aura::Window* GetAlwaysOnTopContainer() { | 52 aura::Window* GetAlwaysOnTopContainer() { |
53 return Shell::GetContainer(Shell::GetPrimaryRootWindow(), | 53 return Shell::GetContainer(Shell::GetPrimaryRootWindow(), |
54 kShellWindowId_AlwaysOnTopContainer); | 54 kShellWindowId_AlwaysOnTopContainer); |
55 } | 55 } |
56 | 56 |
57 // Expect ALL the containers! | 57 // Expect ALL the containers! |
58 void ExpectAllContainers() { | 58 void ExpectAllContainers() { |
59 aura::Window* root_window = Shell::GetPrimaryRootWindow(); | 59 aura::Window* root_window = Shell::GetPrimaryRootWindow(); |
60 EXPECT_TRUE(Shell::GetContainer(root_window, | 60 EXPECT_TRUE( |
61 kShellWindowId_DesktopBackgroundContainer)); | 61 Shell::GetContainer(root_window, kShellWindowId_WallpaperContainer)); |
62 EXPECT_TRUE( | 62 EXPECT_TRUE( |
63 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer)); | 63 Shell::GetContainer(root_window, kShellWindowId_DefaultContainer)); |
64 EXPECT_TRUE( | 64 EXPECT_TRUE( |
65 Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer)); | 65 Shell::GetContainer(root_window, kShellWindowId_AlwaysOnTopContainer)); |
66 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_PanelContainer)); | 66 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_PanelContainer)); |
67 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_ShelfContainer)); | 67 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_ShelfContainer)); |
68 EXPECT_TRUE( | 68 EXPECT_TRUE( |
69 Shell::GetContainer(root_window, kShellWindowId_SystemModalContainer)); | 69 Shell::GetContainer(root_window, kShellWindowId_SystemModalContainer)); |
70 EXPECT_TRUE(Shell::GetContainer( | 70 EXPECT_TRUE(Shell::GetContainer(root_window, |
71 root_window, kShellWindowId_LockScreenBackgroundContainer)); | 71 kShellWindowId_LockScreenWallpaperContainer)); |
72 EXPECT_TRUE( | 72 EXPECT_TRUE( |
73 Shell::GetContainer(root_window, kShellWindowId_LockScreenContainer)); | 73 Shell::GetContainer(root_window, kShellWindowId_LockScreenContainer)); |
74 EXPECT_TRUE(Shell::GetContainer(root_window, | 74 EXPECT_TRUE(Shell::GetContainer(root_window, |
75 kShellWindowId_LockSystemModalContainer)); | 75 kShellWindowId_LockSystemModalContainer)); |
76 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_StatusContainer)); | 76 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_StatusContainer)); |
77 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_MenuContainer)); | 77 EXPECT_TRUE(Shell::GetContainer(root_window, kShellWindowId_MenuContainer)); |
78 EXPECT_TRUE(Shell::GetContainer(root_window, | 78 EXPECT_TRUE(Shell::GetContainer(root_window, |
79 kShellWindowId_DragImageAndTooltipContainer)); | 79 kShellWindowId_DragImageAndTooltipContainer)); |
80 EXPECT_TRUE( | 80 EXPECT_TRUE( |
81 Shell::GetContainer(root_window, kShellWindowId_SettingBubbleContainer)); | 81 Shell::GetContainer(root_window, kShellWindowId_SettingBubbleContainer)); |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 EXPECT_TRUE(delegate->IsScreenLocked()); | 339 EXPECT_TRUE(delegate->IsScreenLocked()); |
340 delegate->UnlockScreen(); | 340 delegate->UnlockScreen(); |
341 EXPECT_FALSE(delegate->IsScreenLocked()); | 341 EXPECT_FALSE(delegate->IsScreenLocked()); |
342 } | 342 } |
343 | 343 |
344 TEST_F(ShellTest, LockScreenClosesActiveMenu) { | 344 TEST_F(ShellTest, LockScreenClosesActiveMenu) { |
345 SimpleMenuDelegate menu_delegate; | 345 SimpleMenuDelegate menu_delegate; |
346 std::unique_ptr<ui::SimpleMenuModel> menu_model( | 346 std::unique_ptr<ui::SimpleMenuModel> menu_model( |
347 new ui::SimpleMenuModel(&menu_delegate)); | 347 new ui::SimpleMenuModel(&menu_delegate)); |
348 menu_model->AddItem(0, base::ASCIIToUTF16("Menu item")); | 348 menu_model->AddItem(0, base::ASCIIToUTF16("Menu item")); |
349 views::Widget* widget = | 349 views::Widget* widget = Shell::GetPrimaryRootWindowController() |
350 Shell::GetPrimaryRootWindowController()->wallpaper_controller()->widget(); | 350 ->wallpaper_widget_controller() |
| 351 ->widget(); |
351 std::unique_ptr<views::MenuRunner> menu_runner( | 352 std::unique_ptr<views::MenuRunner> menu_runner( |
352 new views::MenuRunner(menu_model.get(), views::MenuRunner::CONTEXT_MENU)); | 353 new views::MenuRunner(menu_model.get(), views::MenuRunner::CONTEXT_MENU)); |
353 | 354 |
354 // When MenuRunner runs a nested loop the LockScreenAndVerifyMenuClosed | 355 // When MenuRunner runs a nested loop the LockScreenAndVerifyMenuClosed |
355 // command will fire, check the menu state and ensure the nested menu loop | 356 // command will fire, check the menu state and ensure the nested menu loop |
356 // is exited so that the test will terminate. | 357 // is exited so that the test will terminate. |
357 base::ThreadTaskRunnerHandle::Get()->PostTask( | 358 base::ThreadTaskRunnerHandle::Get()->PostTask( |
358 FROM_HERE, base::Bind(&ShellTest::LockScreenAndVerifyMenuClosed, | 359 FROM_HERE, base::Bind(&ShellTest::LockScreenAndVerifyMenuClosed, |
359 base::Unretained(this))); | 360 base::Unretained(this))); |
360 | 361 |
361 EXPECT_EQ(views::MenuRunner::NORMAL_EXIT, | 362 EXPECT_EQ(views::MenuRunner::NORMAL_EXIT, |
362 menu_runner->RunMenuAt(widget, NULL, gfx::Rect(), | 363 menu_runner->RunMenuAt(widget, NULL, gfx::Rect(), |
363 views::MENU_ANCHOR_TOPLEFT, | 364 views::MENU_ANCHOR_TOPLEFT, |
364 ui::MENU_SOURCE_MOUSE)); | 365 ui::MENU_SOURCE_MOUSE)); |
365 } | 366 } |
366 | 367 |
367 TEST_F(ShellTest, ManagedWindowModeBasics) { | 368 TEST_F(ShellTest, ManagedWindowModeBasics) { |
368 if (!SupportsHostWindowResize()) | 369 if (!SupportsHostWindowResize()) |
369 return; | 370 return; |
370 | 371 |
371 // We start with the usual window containers. | 372 // We start with the usual window containers. |
372 ExpectAllContainers(); | 373 ExpectAllContainers(); |
373 // Shelf is visible. | 374 // Shelf is visible. |
374 ShelfWidget* shelf_widget = GetPrimaryShelf()->GetShelfWidgetForTesting(); | 375 ShelfWidget* shelf_widget = GetPrimaryShelf()->GetShelfWidgetForTesting(); |
375 EXPECT_TRUE(shelf_widget->IsVisible()); | 376 EXPECT_TRUE(shelf_widget->IsVisible()); |
376 // Shelf is at bottom-left of screen. | 377 // Shelf is at bottom-left of screen. |
377 EXPECT_EQ(0, shelf_widget->GetWindowBoundsInScreen().x()); | 378 EXPECT_EQ(0, shelf_widget->GetWindowBoundsInScreen().x()); |
378 EXPECT_EQ(Shell::GetPrimaryRootWindow()->GetHost()->GetBounds().height(), | 379 EXPECT_EQ(Shell::GetPrimaryRootWindow()->GetHost()->GetBounds().height(), |
379 shelf_widget->GetWindowBoundsInScreen().bottom()); | 380 shelf_widget->GetWindowBoundsInScreen().bottom()); |
380 // We have a desktop background but not a bare layer. | 381 // We have a wallpaper but not a bare layer. |
381 // TODO (antrim): enable once we find out why it fails component build. | 382 // TODO (antrim): enable once we find out why it fails component build. |
382 // DesktopBackgroundWidgetController* background = | 383 // WallpaperWidgetController* wallpaper = |
383 // Shell::GetPrimaryRootWindow()-> | 384 // Shell::GetPrimaryRootWindow()-> |
384 // GetProperty(kWindowDesktopComponent); | 385 // GetProperty(kWindowDesktopComponent); |
385 // EXPECT_TRUE(background); | 386 // EXPECT_TRUE(wallpaper); |
386 // EXPECT_TRUE(background->widget()); | 387 // EXPECT_TRUE(wallpaper->widget()); |
387 // EXPECT_FALSE(background->layer()); | 388 // EXPECT_FALSE(wallpaper->layer()); |
388 | 389 |
389 // Create a normal window. It is not maximized. | 390 // Create a normal window. It is not maximized. |
390 views::Widget::InitParams widget_params( | 391 views::Widget::InitParams widget_params( |
391 views::Widget::InitParams::TYPE_WINDOW); | 392 views::Widget::InitParams::TYPE_WINDOW); |
392 widget_params.bounds.SetRect(11, 22, 300, 400); | 393 widget_params.bounds.SetRect(11, 22, 300, 400); |
393 views::Widget* widget = CreateTestWindow(widget_params); | 394 views::Widget* widget = CreateTestWindow(widget_params); |
394 widget->Show(); | 395 widget->Show(); |
395 EXPECT_FALSE(widget->IsMaximized()); | 396 EXPECT_FALSE(widget->IsMaximized()); |
396 | 397 |
397 // Clean up. | 398 // Clean up. |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 private: | 504 private: |
504 DISALLOW_COPY_AND_ASSIGN(ShellTest2); | 505 DISALLOW_COPY_AND_ASSIGN(ShellTest2); |
505 }; | 506 }; |
506 | 507 |
507 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { | 508 TEST_F(ShellTest2, DontCrashWhenWindowDeleted) { |
508 window_.reset(new aura::Window(NULL)); | 509 window_.reset(new aura::Window(NULL)); |
509 window_->Init(ui::LAYER_NOT_DRAWN); | 510 window_->Init(ui::LAYER_NOT_DRAWN); |
510 } | 511 } |
511 | 512 |
512 } // namespace ash | 513 } // namespace ash |
OLD | NEW |