Chromium Code Reviews| 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/workspace/workspace_layout_manager.h" | 5 #include "ash/wm/workspace/workspace_layout_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/accessibility_delegate.h" | 10 #include "ash/accessibility_delegate.h" |
| 11 #include "ash/frame/custom_frame_view_ash.h" | |
| 11 #include "ash/public/cpp/config.h" | 12 #include "ash/public/cpp/config.h" |
| 12 #include "ash/public/cpp/shell_window_ids.h" | 13 #include "ash/public/cpp/shell_window_ids.h" |
| 13 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
| 14 #include "ash/screen_util.h" | 15 #include "ash/screen_util.h" |
| 15 #include "ash/session/session_controller.h" | 16 #include "ash/session/session_controller.h" |
| 16 #include "ash/shared/app_types.h" | 17 #include "ash/shared/app_types.h" |
| 17 #include "ash/shelf/shelf_constants.h" | 18 #include "ash/shelf/shelf_constants.h" |
| 18 #include "ash/shelf/shelf_layout_manager.h" | 19 #include "ash/shelf/shelf_layout_manager.h" |
| 19 #include "ash/shelf/wm_shelf.h" | 20 #include "ash/shelf/wm_shelf.h" |
| 20 #include "ash/shell.h" | 21 #include "ash/shell.h" |
| 21 #include "ash/shell_observer.h" | 22 #include "ash/shell_observer.h" |
| 22 #include "ash/shell_port.h" | 23 #include "ash/shell_port.h" |
| 23 #include "ash/system/tray/system_tray_notifier.h" | 24 #include "ash/system/tray/system_tray_notifier.h" |
| 24 #include "ash/test/ash_test_base.h" | 25 #include "ash/test/ash_test_base.h" |
| 25 #include "ash/test/shell_test_api.h" | 26 #include "ash/test/shell_test_api.h" |
| 26 #include "ash/test/test_accessibility_delegate.h" | 27 #include "ash/test/test_accessibility_delegate.h" |
| 27 #include "ash/test/test_session_controller_client.h" | 28 #include "ash/test/test_session_controller_client.h" |
| 28 #include "ash/test/wm_window_test_api.h" | |
| 29 #include "ash/test/workspace_controller_test_api.h" | 29 #include "ash/test/workspace_controller_test_api.h" |
| 30 #include "ash/wm/fullscreen_window_finder.h" | 30 #include "ash/wm/fullscreen_window_finder.h" |
| 31 #include "ash/wm/maximize_mode/maximize_mode_backdrop_delegate_impl.h" | 31 #include "ash/wm/maximize_mode/maximize_mode_backdrop_delegate_impl.h" |
| 32 #include "ash/wm/overview/window_selector_controller.h" | 32 #include "ash/wm/overview/window_selector_controller.h" |
| 33 #include "ash/wm/window_state.h" | 33 #include "ash/wm/window_state.h" |
| 34 #include "ash/wm/window_util.h" | 34 #include "ash/wm/window_util.h" |
| 35 #include "ash/wm/wm_event.h" | 35 #include "ash/wm/wm_event.h" |
| 36 #include "ash/wm/workspace/backdrop_delegate.h" | 36 #include "ash/wm/workspace/backdrop_delegate.h" |
| 37 #include "ash/wm/workspace/workspace_window_resizer.h" | 37 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 38 #include "ash/wm_window.h" | 38 #include "ash/wm_window.h" |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 52 #include "ui/display/manager/display_manager.h" | 52 #include "ui/display/manager/display_manager.h" |
| 53 #include "ui/display/screen.h" | 53 #include "ui/display/screen.h" |
| 54 #include "ui/display/test/display_manager_test_api.h" | 54 #include "ui/display/test/display_manager_test_api.h" |
| 55 #include "ui/events/base_event_utils.h" | 55 #include "ui/events/base_event_utils.h" |
| 56 #include "ui/events/test/event_generator.h" | 56 #include "ui/events/test/event_generator.h" |
| 57 #include "ui/gfx/geometry/insets.h" | 57 #include "ui/gfx/geometry/insets.h" |
| 58 #include "ui/views/widget/widget.h" | 58 #include "ui/views/widget/widget.h" |
| 59 #include "ui/views/widget/widget_delegate.h" | 59 #include "ui/views/widget/widget_delegate.h" |
| 60 #include "ui/wm/core/window_util.h" | 60 #include "ui/wm/core/window_util.h" |
| 61 | 61 |
| 62 // NOTE: many of these tests use GlobalMinimumSizeLock. This is needed as the | 62 // NOTE: many of these tests use CustomFrameViewAshSizeLock. This is needed as |
|
msw
2017/05/23 05:46:55
q: I wonder if we could just increase the sizes fo
sky
2017/05/23 17:14:39
Yes, I think that would be good.
| |
| 63 // tests assume a minimum size of 0x0. In mash the minimum size, for top-level | 63 // the tests assume a minimum size of 0x0. In mash the minimum size, for |
| 64 // windows, is not 0x0, so without this the tests fails. | 64 // top-level windows, is not 0x0, so without this the tests fails. |
| 65 | 65 |
| 66 namespace ash { | 66 namespace ash { |
| 67 namespace { | 67 namespace { |
| 68 | 68 |
| 69 class MaximizeDelegateView : public views::WidgetDelegateView { | 69 class MaximizeDelegateView : public views::WidgetDelegateView { |
| 70 public: | 70 public: |
| 71 explicit MaximizeDelegateView(const gfx::Rect& initial_bounds) | 71 explicit MaximizeDelegateView(const gfx::Rect& initial_bounds) |
| 72 : initial_bounds_(initial_bounds) {} | 72 : initial_bounds_(initial_bounds) {} |
| 73 ~MaximizeDelegateView() override {} | 73 ~MaximizeDelegateView() override {} |
| 74 | 74 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 return display::Screen::GetScreen()->GetDisplayNearestWindow(window); | 115 return display::Screen::GetScreen()->GetDisplayNearestWindow(window); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void DisableNewVKMode() { | 118 void DisableNewVKMode() { |
| 119 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 119 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 120 command_line->AppendSwitch(::switches::kDisableNewVirtualKeyboardBehavior); | 120 command_line->AppendSwitch(::switches::kDisableNewVirtualKeyboardBehavior); |
| 121 } | 121 } |
| 122 | 122 |
| 123 } // namespace | 123 } // namespace |
| 124 | 124 |
| 125 class CustomFrameViewAshSizeLock { | |
|
msw
2017/05/23 05:46:55
nit: comment; maybe move the one from above down h
sky
2017/05/23 17:14:39
Done.
| |
| 126 public: | |
| 127 CustomFrameViewAshSizeLock() { | |
| 128 CustomFrameViewAsh::use_empty_minimum_size_for_test_ = true; | |
| 129 } | |
| 130 ~CustomFrameViewAshSizeLock() { | |
| 131 CustomFrameViewAsh::use_empty_minimum_size_for_test_ = false; | |
| 132 } | |
| 133 | |
| 134 private: | |
| 135 DISALLOW_COPY_AND_ASSIGN(CustomFrameViewAshSizeLock); | |
| 136 }; | |
| 137 | |
| 125 using WorkspaceLayoutManagerTest = test::AshTestBase; | 138 using WorkspaceLayoutManagerTest = test::AshTestBase; |
| 126 | 139 |
| 127 // Verifies that a window containing a restore coordinate will be restored to | 140 // Verifies that a window containing a restore coordinate will be restored to |
| 128 // to the size prior to minimize, keeping the restore rectangle in tact (if | 141 // to the size prior to minimize, keeping the restore rectangle in tact (if |
| 129 // there is one). | 142 // there is one). |
| 130 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { | 143 TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) { |
| 131 // See comment at top of file for why this is needed. | 144 // See comment at top of file for why this is needed. |
| 132 WmWindowTestApi::GlobalMinimumSizeLock min_size_lock; | 145 CustomFrameViewAshSizeLock min_size_lock; |
| 133 std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); | 146 std::unique_ptr<aura::Window> window(CreateTestWindow(gfx::Rect(1, 2, 3, 4))); |
| 134 gfx::Rect bounds(10, 15, 25, 35); | 147 gfx::Rect bounds(10, 15, 25, 35); |
| 135 window->SetBounds(bounds); | 148 window->SetBounds(bounds); |
| 136 | 149 |
| 137 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 150 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 138 | 151 |
| 139 // This will not be used for un-minimizing window. | 152 // This will not be used for un-minimizing window. |
| 140 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); | 153 window_state->SetRestoreBoundsInScreen(gfx::Rect(0, 0, 100, 100)); |
| 141 window_state->Minimize(); | 154 window_state->Minimize(); |
| 142 window_state->Restore(); | 155 window_state->Restore(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 | 205 |
| 193 // Create a popup window out of display boundaries and make sure it is not | 206 // Create a popup window out of display boundaries and make sure it is not |
| 194 // moved to have minimum visibility. | 207 // moved to have minimum visibility. |
| 195 std::unique_ptr<aura::Window> window( | 208 std::unique_ptr<aura::Window> window( |
| 196 CreateTestWindow(gfx::Rect(400, 100, 50, 50), ui::wm::WINDOW_TYPE_POPUP)); | 209 CreateTestWindow(gfx::Rect(400, 100, 50, 50), ui::wm::WINDOW_TYPE_POPUP)); |
| 197 EXPECT_EQ("400,100 50x50", window->GetBoundsInScreen().ToString()); | 210 EXPECT_EQ("400,100 50x50", window->GetBoundsInScreen().ToString()); |
| 198 } | 211 } |
| 199 | 212 |
| 200 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { | 213 TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) { |
| 201 // See comment at top of file for why this is needed. | 214 // See comment at top of file for why this is needed. |
| 202 WmWindowTestApi::GlobalMinimumSizeLock min_size_lock; | 215 CustomFrameViewAshSizeLock min_size_lock; |
| 203 std::unique_ptr<aura::Window> window( | 216 std::unique_ptr<aura::Window> window( |
| 204 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); | 217 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
| 205 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 218 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 206 | 219 |
| 207 // Maximized -> Normal transition. | 220 // Maximized -> Normal transition. |
| 208 window_state->Maximize(); | 221 window_state->Maximize(); |
| 209 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); | 222 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); |
| 210 window_state->Restore(); | 223 window_state->Restore(); |
| 211 EXPECT_TRUE( | 224 EXPECT_TRUE( |
| 212 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 225 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 232 EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds()); | 245 EXPECT_EQ(window->bounds(), window->GetRootWindow()->bounds()); |
| 233 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); | 246 window_state->SetRestoreBoundsInScreen(gfx::Rect(-100, -100, 30, 40)); |
| 234 window_state->Restore(); | 247 window_state->Restore(); |
| 235 EXPECT_TRUE( | 248 EXPECT_TRUE( |
| 236 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); | 249 Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds())); |
| 237 // Y bounds should not be negative. | 250 // Y bounds should not be negative. |
| 238 EXPECT_EQ("-5,0 30x40", window->bounds().ToString()); | 251 EXPECT_EQ("-5,0 30x40", window->bounds().ToString()); |
| 239 } | 252 } |
| 240 | 253 |
| 241 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) { | 254 TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) { |
| 255 // See comment at top of file for why this is needed. | |
| 256 CustomFrameViewAshSizeLock min_size_lock; | |
| 242 UpdateDisplay("300x400,400x500"); | 257 UpdateDisplay("300x400,400x500"); |
| 243 | 258 |
| 244 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); | 259 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
| 245 | 260 |
| 246 std::unique_ptr<aura::Window> window( | 261 std::unique_ptr<aura::Window> window( |
| 247 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); | 262 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
| 248 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 263 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 249 | 264 |
| 250 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 265 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 251 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); | 266 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 EXPECT_TRUE(w1->IsMaximized()); | 299 EXPECT_TRUE(w1->IsMaximized()); |
| 285 EXPECT_EQ(root_windows[1], w1->GetNativeWindow()->GetRootWindow()); | 300 EXPECT_EQ(root_windows[1], w1->GetNativeWindow()->GetRootWindow()); |
| 286 EXPECT_EQ(gfx::Rect(300, 0, 400, 500 - kShelfSize).ToString(), | 301 EXPECT_EQ(gfx::Rect(300, 0, 400, 500 - kShelfSize).ToString(), |
| 287 w1->GetWindowBoundsInScreen().ToString()); | 302 w1->GetWindowBoundsInScreen().ToString()); |
| 288 w1->Restore(); | 303 w1->Restore(); |
| 289 EXPECT_EQ(root_windows[1], w1->GetNativeWindow()->GetRootWindow()); | 304 EXPECT_EQ(root_windows[1], w1->GetNativeWindow()->GetRootWindow()); |
| 290 EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString()); | 305 EXPECT_EQ("400,0 30x40", w1->GetWindowBoundsInScreen().ToString()); |
| 291 } | 306 } |
| 292 | 307 |
| 293 TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) { | 308 TEST_F(WorkspaceLayoutManagerTest, FullscreenInDisplayToBeRestored) { |
| 309 // See comment at top of file for why this is needed. | |
| 310 CustomFrameViewAshSizeLock min_size_lock; | |
| 294 UpdateDisplay("300x400,400x500"); | 311 UpdateDisplay("300x400,400x500"); |
| 295 | 312 |
| 296 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); | 313 aura::Window::Windows root_windows = Shell::Get()->GetAllRootWindows(); |
| 297 | 314 |
| 298 std::unique_ptr<aura::Window> window( | 315 std::unique_ptr<aura::Window> window( |
| 299 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); | 316 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
| 300 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 317 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 301 | 318 |
| 302 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 319 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 303 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); | 320 window_state->SetRestoreBoundsInScreen(gfx::Rect(400, 0, 30, 40)); |
| (...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1418 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); | 1435 DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManagerKeyboardTest); |
| 1419 }; | 1436 }; |
| 1420 | 1437 |
| 1421 // Tests that when a child window gains focus the top level window containing it | 1438 // Tests that when a child window gains focus the top level window containing it |
| 1422 // is resized to fit the remaining workspace area. | 1439 // is resized to fit the remaining workspace area. |
| 1423 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) { | 1440 TEST_F(WorkspaceLayoutManagerKeyboardTest, ChildWindowFocused) { |
| 1424 // Append the flag to cause work area change in non-sticky mode. | 1441 // Append the flag to cause work area change in non-sticky mode. |
| 1425 DisableNewVKMode(); | 1442 DisableNewVKMode(); |
| 1426 | 1443 |
| 1427 // See comment at top of file for why this is needed. | 1444 // See comment at top of file for why this is needed. |
| 1428 WmWindowTestApi::GlobalMinimumSizeLock min_size_lock; | 1445 CustomFrameViewAshSizeLock min_size_lock; |
| 1429 | 1446 |
| 1430 InitKeyboardBounds(); | 1447 InitKeyboardBounds(); |
| 1431 | 1448 |
| 1432 gfx::Rect work_area( | 1449 gfx::Rect work_area( |
| 1433 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1450 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
| 1434 | 1451 |
| 1435 std::unique_ptr<aura::Window> parent_window( | 1452 std::unique_ptr<aura::Window> parent_window( |
| 1436 CreateToplevelTestWindow(work_area)); | 1453 CreateToplevelTestWindow(work_area)); |
| 1437 std::unique_ptr<aura::Window> window(CreateTestWindow(work_area)); | 1454 std::unique_ptr<aura::Window> window(CreateTestWindow(work_area)); |
| 1438 parent_window->AddChild(window.get()); | 1455 parent_window->AddChild(window.get()); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1453 HideKeyboard(); | 1470 HideKeyboard(); |
| 1454 EXPECT_EQ(initial_window_bounds.ToString(), | 1471 EXPECT_EQ(initial_window_bounds.ToString(), |
| 1455 parent_window->bounds().ToString()); | 1472 parent_window->bounds().ToString()); |
| 1456 } | 1473 } |
| 1457 | 1474 |
| 1458 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { | 1475 TEST_F(WorkspaceLayoutManagerKeyboardTest, AdjustWindowForA11yKeyboard) { |
| 1459 // Append the flag to cause work area change in non-sticky mode. | 1476 // Append the flag to cause work area change in non-sticky mode. |
| 1460 DisableNewVKMode(); | 1477 DisableNewVKMode(); |
| 1461 | 1478 |
| 1462 // See comment at top of file for why this is needed. | 1479 // See comment at top of file for why this is needed. |
| 1463 WmWindowTestApi::GlobalMinimumSizeLock min_size_lock; | 1480 CustomFrameViewAshSizeLock min_size_lock; |
| 1464 InitKeyboardBounds(); | 1481 InitKeyboardBounds(); |
| 1465 gfx::Rect work_area( | 1482 gfx::Rect work_area( |
| 1466 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); | 1483 display::Screen::GetScreen()->GetPrimaryDisplay().work_area()); |
| 1467 | 1484 |
| 1468 std::unique_ptr<aura::Window> window(CreateToplevelTestWindow(work_area)); | 1485 std::unique_ptr<aura::Window> window(CreateToplevelTestWindow(work_area)); |
| 1469 // The additional SetBounds() is needed as the aura-mus case uses Widget, | 1486 // The additional SetBounds() is needed as the aura-mus case uses Widget, |
| 1470 // which alters the supplied bounds. | 1487 // which alters the supplied bounds. |
| 1471 window->SetBounds(work_area); | 1488 window->SetBounds(work_area); |
| 1472 | 1489 |
| 1473 int available_height = | 1490 int available_height = |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1521 window->SetBounds(keyboard_bounds()); | 1538 window->SetBounds(keyboard_bounds()); |
| 1522 wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true); | 1539 wm::GetWindowState(window.get())->set_ignore_keyboard_bounds_change(true); |
| 1523 wm::ActivateWindow(window.get()); | 1540 wm::ActivateWindow(window.get()); |
| 1524 | 1541 |
| 1525 EXPECT_EQ(keyboard_bounds(), window->bounds()); | 1542 EXPECT_EQ(keyboard_bounds(), window->bounds()); |
| 1526 ShowKeyboard(); | 1543 ShowKeyboard(); |
| 1527 EXPECT_EQ(keyboard_bounds(), window->bounds()); | 1544 EXPECT_EQ(keyboard_bounds(), window->bounds()); |
| 1528 } | 1545 } |
| 1529 | 1546 |
| 1530 } // namespace ash | 1547 } // namespace ash |
| OLD | NEW |