| 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/common/wm/workspace/workspace_event_handler.h" | 5 #include "ash/common/wm/workspace/workspace_event_handler.h" |
| 6 | 6 |
| 7 #include "ash/common/wm/window_state.h" | 7 #include "ash/common/wm/window_state.h" |
| 8 #include "ash/common/wm/wm_event.h" | 8 #include "ash/common/wm/wm_event.h" |
| 9 #include "ash/common/wm/workspace_controller.h" | 9 #include "ash/common/wm/workspace_controller.h" |
| 10 #include "ash/common/wm_shell.h" |
| 10 #include "ash/screen_util.h" | 11 #include "ash/screen_util.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/wm/window_state_aura.h" | 14 #include "ash/wm/window_state_aura.h" |
| 14 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm/workspace_controller_test_helper.h" | 16 #include "ash/wm/workspace_controller_test_helper.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" | 18 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" |
| 18 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/test/test_window_delegate.h" | 20 #include "ui/aura/test/test_window_delegate.h" |
| 20 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 22 #include "ui/base/hit_test.h" | 23 #include "ui/base/hit_test.h" |
| 23 #include "ui/display/manager/display_manager.h" | |
| 24 #include "ui/display/screen.h" | 24 #include "ui/display/screen.h" |
| 25 #include "ui/events/event_processor.h" | 25 #include "ui/events/event_processor.h" |
| 26 #include "ui/events/event_utils.h" | 26 #include "ui/events/event_utils.h" |
| 27 #include "ui/events/test/event_generator.h" | 27 #include "ui/events/test/event_generator.h" |
| 28 #include "ui/wm/core/window_util.h" | 28 #include "ui/wm/core/window_util.h" |
| 29 #include "ui/wm/public/window_move_client.h" | 29 #include "ui/wm/public/window_move_client.h" |
| 30 | 30 |
| 31 namespace ash { | 31 namespace ash { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 properties_changed_.push_back(key); | 89 properties_changed_.push_back(key); |
| 90 } | 90 } |
| 91 | 91 |
| 92 aura::Window* window_; | 92 aura::Window* window_; |
| 93 std::vector<const void*> properties_changed_; | 93 std::vector<const void*> properties_changed_; |
| 94 | 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(WindowPropertyObserver); | 95 DISALLOW_COPY_AND_ASSIGN(WindowPropertyObserver); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) { | 98 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisResizeEdge) { |
| 99 // TODO: investigate failure. http://crbug.com/699175. |
| 100 if (WmShell::Get()->IsRunningInMash()) |
| 101 return; |
| 102 |
| 99 // Double clicking the vertical resize edge of a window should maximize it | 103 // Double clicking the vertical resize edge of a window should maximize it |
| 100 // vertically. | 104 // vertically. |
| 101 gfx::Rect restored_bounds(10, 10, 50, 50); | 105 gfx::Rect restored_bounds(10, 10, 50, 50); |
| 102 aura::test::TestWindowDelegate delegate; | 106 aura::test::TestWindowDelegate delegate; |
| 103 std::unique_ptr<aura::Window> window( | 107 std::unique_ptr<aura::Window> window( |
| 104 CreateTestWindow(&delegate, restored_bounds)); | 108 CreateTestWindow(&delegate, restored_bounds)); |
| 105 | 109 |
| 106 wm::ActivateWindow(window.get()); | 110 wm::ActivateWindow(window.get()); |
| 107 | 111 |
| 108 gfx::Rect work_area = display::Screen::GetScreen() | 112 gfx::Rect work_area = display::Screen::GetScreen() |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 EXPECT_EQ(work_area.width(), bounds_in_screen.width()); | 155 EXPECT_EQ(work_area.width(), bounds_in_screen.width()); |
| 152 // Single-axis maximization is not considered real maximization. | 156 // Single-axis maximization is not considered real maximization. |
| 153 EXPECT_FALSE(window_state->IsMaximized()); | 157 EXPECT_FALSE(window_state->IsMaximized()); |
| 154 | 158 |
| 155 // Restore. | 159 // Restore. |
| 156 generator.DoubleClickLeftButton(); | 160 generator.DoubleClickLeftButton(); |
| 157 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 161 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 158 | 162 |
| 159 // Verify the double clicking the resize edge works on 2nd display too. | 163 // Verify the double clicking the resize edge works on 2nd display too. |
| 160 UpdateDisplay("200x200,400x300"); | 164 UpdateDisplay("200x200,400x300"); |
| 161 gfx::Rect work_area2 = display_manager()->GetSecondaryDisplay().work_area(); | 165 gfx::Rect work_area2 = GetSecondaryDisplay().work_area(); |
| 162 restored_bounds.SetRect(220, 20, 50, 50); | 166 restored_bounds.SetRect(220, 20, 50, 50); |
| 163 window->SetBoundsInScreen(restored_bounds, | 167 window->SetBoundsInScreen(restored_bounds, GetSecondaryDisplay()); |
| 164 display_manager()->GetSecondaryDisplay()); | |
| 165 aura::Window* second_root = Shell::GetAllRootWindows()[1]; | 168 aura::Window* second_root = Shell::GetAllRootWindows()[1]; |
| 166 EXPECT_EQ(second_root, window->GetRootWindow()); | 169 EXPECT_EQ(second_root, window->GetRootWindow()); |
| 167 ui::test::EventGenerator generator2(second_root, window.get()); | 170 ui::test::EventGenerator generator2(second_root, window.get()); |
| 168 | 171 |
| 169 // Y-axis maximization. | 172 // Y-axis maximization. |
| 170 delegate.set_window_component(HTTOP); | 173 delegate.set_window_component(HTTOP); |
| 171 generator2.PressLeftButton(); | 174 generator2.PressLeftButton(); |
| 172 generator2.ReleaseLeftButton(); | 175 generator2.ReleaseLeftButton(); |
| 173 generator2.set_flags(ui::EF_IS_DOUBLE_CLICK); | 176 generator2.set_flags(ui::EF_IS_DOUBLE_CLICK); |
| 174 generator2.PressLeftButton(); | 177 generator2.PressLeftButton(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 196 EXPECT_EQ(work_area2.width(), bounds_in_screen.width()); | 199 EXPECT_EQ(work_area2.width(), bounds_in_screen.width()); |
| 197 EXPECT_FALSE(window_state->IsMaximized()); | 200 EXPECT_FALSE(window_state->IsMaximized()); |
| 198 | 201 |
| 199 // Restore. | 202 // Restore. |
| 200 generator2.DoubleClickLeftButton(); | 203 generator2.DoubleClickLeftButton(); |
| 201 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); | 204 EXPECT_EQ(restored_bounds.ToString(), window->GetBoundsInScreen().ToString()); |
| 202 } | 205 } |
| 203 | 206 |
| 204 // Tests the behavior when double clicking the border of a side snapped window. | 207 // Tests the behavior when double clicking the border of a side snapped window. |
| 205 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) { | 208 TEST_F(WorkspaceEventHandlerTest, DoubleClickSingleAxisWhenSideSnapped) { |
| 209 // TODO: investigate failure. http://crbug.com/699175. |
| 210 if (WmShell::Get()->IsRunningInMash()) |
| 211 return; |
| 212 |
| 206 gfx::Rect restored_bounds(10, 10, 50, 50); | 213 gfx::Rect restored_bounds(10, 10, 50, 50); |
| 207 aura::test::TestWindowDelegate delegate; | 214 aura::test::TestWindowDelegate delegate; |
| 208 std::unique_ptr<aura::Window> window( | 215 std::unique_ptr<aura::Window> window( |
| 209 CreateTestWindow(&delegate, restored_bounds)); | 216 CreateTestWindow(&delegate, restored_bounds)); |
| 210 | 217 |
| 211 gfx::Rect work_area_in_screen = display::Screen::GetScreen() | 218 gfx::Rect work_area_in_screen = display::Screen::GetScreen() |
| 212 ->GetDisplayNearestWindow(window.get()) | 219 ->GetDisplayNearestWindow(window.get()) |
| 213 .work_area(); | 220 .work_area(); |
| 214 | 221 |
| 215 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 222 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 318 |
| 312 generator.GestureTapAt(gfx::Point(25, 25)); | 319 generator.GestureTapAt(gfx::Point(25, 25)); |
| 313 generator.GestureTapAt(gfx::Point(25, 25)); | 320 generator.GestureTapAt(gfx::Point(25, 25)); |
| 314 RunAllPendingInMessageLoop(); | 321 RunAllPendingInMessageLoop(); |
| 315 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); | 322 EXPECT_EQ("10,20 30x40", window->bounds().ToString()); |
| 316 EXPECT_FALSE(window_state->IsMaximized()); | 323 EXPECT_FALSE(window_state->IsMaximized()); |
| 317 } | 324 } |
| 318 | 325 |
| 319 // Test the behavior as a result of double clicking the window header. | 326 // Test the behavior as a result of double clicking the window header. |
| 320 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { | 327 TEST_F(WorkspaceEventHandlerTest, DoubleClickCaptionTogglesMaximize) { |
| 328 // TODO: investigate failure. http://crbug.com/699175. |
| 329 if (WmShell::Get()->IsRunningInMash()) |
| 330 return; |
| 331 |
| 321 aura::test::TestWindowDelegate delegate; | 332 aura::test::TestWindowDelegate delegate; |
| 322 std::unique_ptr<aura::Window> window( | 333 std::unique_ptr<aura::Window> window( |
| 323 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); | 334 CreateTestWindow(&delegate, gfx::Rect(1, 2, 30, 40))); |
| 324 window->SetProperty(aura::client::kResizeBehaviorKey, | 335 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 325 ui::mojom::kResizeBehaviorCanMaximize); | 336 ui::mojom::kResizeBehaviorCanMaximize); |
| 326 | 337 |
| 327 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 338 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 328 gfx::Rect restore_bounds = window->bounds(); | 339 gfx::Rect restore_bounds = window->bounds(); |
| 329 gfx::Rect work_area_in_parent = | 340 gfx::Rect work_area_in_parent = |
| 330 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); | 341 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window.get()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_NONE); | 401 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_NONE); |
| 391 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON, | 402 ClickButtonWithFlags(&generator, ui::EF_MIDDLE_MOUSE_BUTTON, |
| 392 ui::EF_IS_DOUBLE_CLICK); | 403 ui::EF_IS_DOUBLE_CLICK); |
| 393 | 404 |
| 394 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); | 405 EXPECT_FALSE(wm::GetWindowState(window.get())->IsMaximized()); |
| 395 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); | 406 EXPECT_EQ("1,2 30x40", window->bounds().ToString()); |
| 396 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey)); | 407 EXPECT_FALSE(observer.DidPropertyChange(aura::client::kShowStateKey)); |
| 397 } | 408 } |
| 398 | 409 |
| 399 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) { | 410 TEST_F(WorkspaceEventHandlerTest, DoubleTapCaptionTogglesMaximize) { |
| 411 // TODO: investigate failure. http://crbug.com/699175. |
| 412 if (WmShell::Get()->IsRunningInMash()) |
| 413 return; |
| 414 |
| 400 aura::test::TestWindowDelegate delegate; | 415 aura::test::TestWindowDelegate delegate; |
| 401 gfx::Rect bounds(10, 20, 30, 40); | 416 gfx::Rect bounds(10, 20, 30, 40); |
| 402 std::unique_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds)); | 417 std::unique_ptr<aura::Window> window(CreateTestWindow(&delegate, bounds)); |
| 403 window->SetProperty(aura::client::kResizeBehaviorKey, | 418 window->SetProperty(aura::client::kResizeBehaviorKey, |
| 404 ui::mojom::kResizeBehaviorCanMaximize); | 419 ui::mojom::kResizeBehaviorCanMaximize); |
| 405 delegate.set_window_component(HTCAPTION); | 420 delegate.set_window_component(HTCAPTION); |
| 406 | 421 |
| 407 wm::WindowState* window_state = wm::GetWindowState(window.get()); | 422 wm::WindowState* window_state = wm::GetWindowState(window.get()); |
| 408 EXPECT_FALSE(window_state->IsMaximized()); | 423 EXPECT_FALSE(window_state->IsMaximized()); |
| 409 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 424 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 delegate.set_window_component(HTCAPTION); | 544 delegate.set_window_component(HTCAPTION); |
| 530 generator.PressRightButton(); | 545 generator.PressRightButton(); |
| 531 generator.ReleaseRightButton(); | 546 generator.ReleaseRightButton(); |
| 532 EXPECT_FALSE(window_state->IsMaximized()); | 547 EXPECT_FALSE(window_state->IsMaximized()); |
| 533 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON, | 548 ClickButtonWithFlags(&generator, ui::EF_LEFT_MOUSE_BUTTON, |
| 534 ui::EF_IS_DOUBLE_CLICK); | 549 ui::EF_IS_DOUBLE_CLICK); |
| 535 EXPECT_FALSE(window_state->IsMaximized()); | 550 EXPECT_FALSE(window_state->IsMaximized()); |
| 536 } | 551 } |
| 537 | 552 |
| 538 } // namespace ash | 553 } // namespace ash |
| OLD | NEW |