| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "ash/common/accessibility_delegate.h" | 8 #include "ash/common/accessibility_delegate.h" |
| 9 #include "ash/common/accessibility_types.h" | 9 #include "ash/common/accessibility_types.h" |
| 10 #include "ash/common/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 void SendCtrlKey(ui::KeyboardCode key) { | 224 void SendCtrlKey(ui::KeyboardCode key) { |
| 225 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); | 225 ui::test::EventGenerator event_generator(Shell::GetPrimaryRootWindow()); |
| 226 event_generator.PressKey(ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN); | 226 event_generator.PressKey(ui::VKEY_CONTROL, ui::EF_CONTROL_DOWN); |
| 227 event_generator.PressKey(key, ui::EF_CONTROL_DOWN); | 227 event_generator.PressKey(key, ui::EF_CONTROL_DOWN); |
| 228 event_generator.ReleaseKey(key, ui::EF_CONTROL_DOWN); | 228 event_generator.ReleaseKey(key, ui::EF_CONTROL_DOWN); |
| 229 event_generator.ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE); | 229 event_generator.ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE); |
| 230 } | 230 } |
| 231 | 231 |
| 232 bool IsSelecting() { return window_selector_controller()->IsSelecting(); } | 232 bool IsSelecting() { return window_selector_controller()->IsSelecting(); } |
| 233 | 233 |
| 234 aura::Window* GetFocusedWindow() { | |
| 235 return aura::client::GetFocusClient(Shell::GetPrimaryRootWindow()) | |
| 236 ->GetFocusedWindow(); | |
| 237 } | |
| 238 | |
| 239 const std::vector<std::unique_ptr<WindowSelectorItem>>& GetWindowItemsForRoot( | 234 const std::vector<std::unique_ptr<WindowSelectorItem>>& GetWindowItemsForRoot( |
| 240 int index) { | 235 int index) { |
| 241 return window_selector()->grid_list_[index]->window_list(); | 236 return window_selector()->grid_list_[index]->window_list(); |
| 242 } | 237 } |
| 243 | 238 |
| 244 WindowSelectorItem* GetWindowItemForWindow(int grid_index, | 239 WindowSelectorItem* GetWindowItemForWindow(int grid_index, |
| 245 aura::Window* window) { | 240 aura::Window* window) { |
| 246 const std::vector<std::unique_ptr<WindowSelectorItem>>& windows = | 241 const std::vector<std::unique_ptr<WindowSelectorItem>>& windows = |
| 247 GetWindowItemsForRoot(grid_index); | 242 GetWindowItemsForRoot(grid_index); |
| 248 auto iter = | 243 auto iter = |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 411 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 417 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 412 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 418 std::unique_ptr<aura::Window> panel1(CreatePanelWindow(bounds)); | 413 std::unique_ptr<aura::Window> panel1(CreatePanelWindow(bounds)); |
| 419 std::unique_ptr<aura::Window> panel2(CreatePanelWindow(bounds)); | 414 std::unique_ptr<aura::Window> panel2(CreatePanelWindow(bounds)); |
| 420 | 415 |
| 421 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); | 416 EXPECT_TRUE(WindowsOverlapping(window1.get(), window2.get())); |
| 422 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get())); | 417 EXPECT_TRUE(WindowsOverlapping(panel1.get(), panel2.get())); |
| 423 wm::ActivateWindow(window2.get()); | 418 wm::ActivateWindow(window2.get()); |
| 424 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 419 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
| 425 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | 420 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 426 EXPECT_EQ(window2.get(), GetFocusedWindow()); | 421 EXPECT_EQ(window2.get(), wm::GetFocusedWindow()); |
| 427 // TODO: mash doesn't support CursorClient. http://crbug.com/637853. | 422 // TODO: mash doesn't support CursorClient. http://crbug.com/637853. |
| 428 if (!WmShell::Get()->IsRunningInMash()) { | 423 if (!WmShell::Get()->IsRunningInMash()) { |
| 429 // Hide the cursor before entering overview to test that it will be shown. | 424 // Hide the cursor before entering overview to test that it will be shown. |
| 430 aura::client::GetCursorClient(root_window)->HideCursor(); | 425 aura::client::GetCursorClient(root_window)->HideCursor(); |
| 431 } | 426 } |
| 432 | 427 |
| 433 // In overview mode the windows should no longer overlap and the text filter | 428 // In overview mode the windows should no longer overlap and the text filter |
| 434 // widget should be focused. | 429 // widget should be focused. |
| 435 ToggleOverview(); | 430 ToggleOverview(); |
| 436 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow()); | 431 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), wm::GetFocusedWindow()); |
| 437 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); | 432 EXPECT_FALSE(WindowsOverlapping(window1.get(), window2.get())); |
| 438 EXPECT_FALSE(WindowsOverlapping(window1.get(), panel1.get())); | 433 EXPECT_FALSE(WindowsOverlapping(window1.get(), panel1.get())); |
| 439 EXPECT_FALSE(WindowsOverlapping(panel1.get(), panel2.get())); | 434 EXPECT_FALSE(WindowsOverlapping(panel1.get(), panel2.get())); |
| 440 | 435 |
| 441 // Clicking window 1 should activate it. | 436 // Clicking window 1 should activate it. |
| 442 ClickWindow(window1.get()); | 437 ClickWindow(window1.get()); |
| 443 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 438 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 444 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | 439 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); |
| 445 EXPECT_EQ(window1.get(), GetFocusedWindow()); | 440 EXPECT_EQ(window1.get(), wm::GetFocusedWindow()); |
| 446 | 441 |
| 447 // TODO: mash doesn't support CursorClient. http://crbug.com/637853. | 442 // TODO: mash doesn't support CursorClient. http://crbug.com/637853. |
| 448 if (!WmShell::Get()->IsRunningInMash()) { | 443 if (!WmShell::Get()->IsRunningInMash()) { |
| 449 // Cursor should have been unlocked. | 444 // Cursor should have been unlocked. |
| 450 EXPECT_FALSE(aura::client::GetCursorClient(root_window)->IsCursorLocked()); | 445 EXPECT_FALSE(aura::client::GetCursorClient(root_window)->IsCursorLocked()); |
| 451 } | 446 } |
| 452 } | 447 } |
| 453 | 448 |
| 454 // Tests activating minimized window. | 449 // Tests activating minimized window. |
| 455 TEST_F(WindowSelectorTest, ActivateMinimized) { | 450 TEST_F(WindowSelectorTest, ActivateMinimized) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 } | 484 } |
| 490 | 485 |
| 491 // Tests that entering overview mode with an App-list active properly focuses | 486 // Tests that entering overview mode with an App-list active properly focuses |
| 492 // and activates the overview text filter window. | 487 // and activates the overview text filter window. |
| 493 TEST_F(WindowSelectorTest, TextFilterActive) { | 488 TEST_F(WindowSelectorTest, TextFilterActive) { |
| 494 gfx::Rect bounds(0, 0, 400, 400); | 489 gfx::Rect bounds(0, 0, 400, 400); |
| 495 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 490 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 496 wm::ActivateWindow(window1.get()); | 491 wm::ActivateWindow(window1.get()); |
| 497 | 492 |
| 498 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 493 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 499 EXPECT_EQ(window1.get(), GetFocusedWindow()); | 494 EXPECT_EQ(window1.get(), wm::GetFocusedWindow()); |
| 500 | 495 |
| 501 Shell::Get()->ToggleAppList(); | 496 Shell::Get()->ToggleAppList(); |
| 502 | 497 |
| 503 // Activating overview cancels the App-list which normally would activate the | 498 // Activating overview cancels the App-list which normally would activate the |
| 504 // previously active |window1|. Overview mode should properly transfer focus | 499 // previously active |window1|. Overview mode should properly transfer focus |
| 505 // and activation to the text filter widget. | 500 // and activation to the text filter widget. |
| 506 ToggleOverview(); | 501 ToggleOverview(); |
| 507 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 502 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
| 508 EXPECT_TRUE(wm::IsActiveWindow(GetFocusedWindow())); | 503 EXPECT_TRUE(wm::IsActiveWindow(wm::GetFocusedWindow())); |
| 509 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow()); | 504 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), wm::GetFocusedWindow()); |
| 510 } | 505 } |
| 511 | 506 |
| 512 // Tests that the ordering of windows is stable across different overview | 507 // Tests that the ordering of windows is stable across different overview |
| 513 // sessions even when the windows have the same bounds. | 508 // sessions even when the windows have the same bounds. |
| 514 TEST_F(WindowSelectorTest, WindowsOrder) { | 509 TEST_F(WindowSelectorTest, WindowsOrder) { |
| 515 gfx::Rect bounds(0, 0, 400, 400); | 510 gfx::Rect bounds(0, 0, 400, 400); |
| 516 std::unique_ptr<aura::Window> window1(CreateWindowWithId(bounds, 1)); | 511 std::unique_ptr<aura::Window> window1(CreateWindowWithId(bounds, 1)); |
| 517 std::unique_ptr<aura::Window> window2(CreateWindowWithId(bounds, 2)); | 512 std::unique_ptr<aura::Window> window2(CreateWindowWithId(bounds, 2)); |
| 518 std::unique_ptr<aura::Window> window3(CreateWindowWithId(bounds, 3)); | 513 std::unique_ptr<aura::Window> window3(CreateWindowWithId(bounds, 3)); |
| 519 | 514 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 539 EXPECT_EQ(3, overview2[2]->GetWindow()->GetShellWindowId()); | 534 EXPECT_EQ(3, overview2[2]->GetWindow()->GetShellWindowId()); |
| 540 ToggleOverview(); | 535 ToggleOverview(); |
| 541 } | 536 } |
| 542 | 537 |
| 543 // Tests selecting a window by tapping on it. | 538 // Tests selecting a window by tapping on it. |
| 544 TEST_F(WindowSelectorTest, BasicGesture) { | 539 TEST_F(WindowSelectorTest, BasicGesture) { |
| 545 gfx::Rect bounds(0, 0, 400, 400); | 540 gfx::Rect bounds(0, 0, 400, 400); |
| 546 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 541 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 547 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 542 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 548 wm::ActivateWindow(window1.get()); | 543 wm::ActivateWindow(window1.get()); |
| 549 EXPECT_EQ(window1.get(), GetFocusedWindow()); | 544 EXPECT_EQ(window1.get(), wm::GetFocusedWindow()); |
| 550 ToggleOverview(); | 545 ToggleOverview(); |
| 551 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow()); | 546 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), wm::GetFocusedWindow()); |
| 552 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 547 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 553 window2.get()); | 548 window2.get()); |
| 554 generator.GestureTapAt( | 549 generator.GestureTapAt( |
| 555 GetTransformedTargetBounds(window2.get()).CenterPoint()); | 550 GetTransformedTargetBounds(window2.get()).CenterPoint()); |
| 556 EXPECT_EQ(window2.get(), GetFocusedWindow()); | 551 EXPECT_EQ(window2.get(), wm::GetFocusedWindow()); |
| 557 } | 552 } |
| 558 | 553 |
| 559 // Tests that the user action WindowSelector_ActiveWindowChanged is | 554 // Tests that the user action WindowSelector_ActiveWindowChanged is |
| 560 // recorded when the mouse/touchscreen/keyboard are used to select a window | 555 // recorded when the mouse/touchscreen/keyboard are used to select a window |
| 561 // in overview mode which is different from the previously-active window. | 556 // in overview mode which is different from the previously-active window. |
| 562 TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionRecorded) { | 557 TEST_F(WindowSelectorTest, ActiveWindowChangedUserActionRecorded) { |
| 563 // TODO: fails because of metrics. http://crbug.com/698129. | 558 // TODO: fails because of metrics. http://crbug.com/698129. |
| 564 if (WmShell::Get()->IsRunningInMash()) | 559 if (WmShell::Get()->IsRunningInMash()) |
| 565 return; | 560 return; |
| 566 | 561 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 | 607 |
| 613 // Tap on |window1| to exit overview. | 608 // Tap on |window1| to exit overview. |
| 614 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), | 609 ui::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), |
| 615 window1.get()); | 610 window1.get()); |
| 616 generator.GestureTapAt( | 611 generator.GestureTapAt( |
| 617 GetTransformedTargetBounds(window1.get()).CenterPoint()); | 612 GetTransformedTargetBounds(window1.get()).CenterPoint()); |
| 618 EXPECT_EQ( | 613 EXPECT_EQ( |
| 619 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview)); | 614 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview)); |
| 620 | 615 |
| 621 // |window1| remains active. Click on it to exit overview. | 616 // |window1| remains active. Click on it to exit overview. |
| 622 ASSERT_EQ(window1.get(), GetFocusedWindow()); | 617 ASSERT_EQ(window1.get(), wm::GetFocusedWindow()); |
| 623 ToggleOverview(); | 618 ToggleOverview(); |
| 624 ClickWindow(window1.get()); | 619 ClickWindow(window1.get()); |
| 625 EXPECT_EQ( | 620 EXPECT_EQ( |
| 626 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview)); | 621 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview)); |
| 627 | 622 |
| 628 // |window1| remains active. Select using the keyboard. | 623 // |window1| remains active. Select using the keyboard. |
| 629 ASSERT_EQ(window1.get(), GetFocusedWindow()); | 624 ASSERT_EQ(window1.get(), wm::GetFocusedWindow()); |
| 630 ToggleOverview(); | 625 ToggleOverview(); |
| 631 ASSERT_TRUE(SelectWindow(window1.get())); | 626 ASSERT_TRUE(SelectWindow(window1.get())); |
| 632 SendKey(ui::VKEY_RETURN); | 627 SendKey(ui::VKEY_RETURN); |
| 633 EXPECT_EQ( | 628 EXPECT_EQ( |
| 634 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview)); | 629 0, user_action_tester.GetActionCount(kActiveWindowChangedFromOverview)); |
| 635 | 630 |
| 636 // Entering and exiting overview without user input should not record | 631 // Entering and exiting overview without user input should not record |
| 637 // the action. | 632 // the action. |
| 638 ToggleOverview(); | 633 ToggleOverview(); |
| 639 ToggleOverview(); | 634 ToggleOverview(); |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 window2->Focus(); | 1044 window2->Focus(); |
| 1050 ToggleOverview(); | 1045 ToggleOverview(); |
| 1051 EXPECT_TRUE(IsSelecting()); | 1046 EXPECT_TRUE(IsSelecting()); |
| 1052 | 1047 |
| 1053 // A window being activated should exit overview mode. | 1048 // A window being activated should exit overview mode. |
| 1054 window1->Focus(); | 1049 window1->Focus(); |
| 1055 EXPECT_FALSE(IsSelecting()); | 1050 EXPECT_FALSE(IsSelecting()); |
| 1056 | 1051 |
| 1057 // window1 should be focused after exiting even though window2 was focused on | 1052 // window1 should be focused after exiting even though window2 was focused on |
| 1058 // entering overview because we exited due to an activation. | 1053 // entering overview because we exited due to an activation. |
| 1059 EXPECT_EQ(window1.get(), GetFocusedWindow()); | 1054 EXPECT_EQ(window1.get(), wm::GetFocusedWindow()); |
| 1060 } | 1055 } |
| 1061 | 1056 |
| 1062 // Tests that exiting overview mode without selecting a window restores focus | 1057 // Tests that exiting overview mode without selecting a window restores focus |
| 1063 // to the previously focused window. | 1058 // to the previously focused window. |
| 1064 TEST_F(WindowSelectorTest, CancelRestoresFocus) { | 1059 TEST_F(WindowSelectorTest, CancelRestoresFocus) { |
| 1065 gfx::Rect bounds(0, 0, 400, 400); | 1060 gfx::Rect bounds(0, 0, 400, 400); |
| 1066 std::unique_ptr<aura::Window> window(CreateWindow(bounds)); | 1061 std::unique_ptr<aura::Window> window(CreateWindow(bounds)); |
| 1067 wm::ActivateWindow(window.get()); | 1062 wm::ActivateWindow(window.get()); |
| 1068 EXPECT_EQ(window.get(), GetFocusedWindow()); | 1063 EXPECT_EQ(window.get(), wm::GetFocusedWindow()); |
| 1069 | 1064 |
| 1070 // In overview mode, the text filter widget should be focused. | 1065 // In overview mode, the text filter widget should be focused. |
| 1071 ToggleOverview(); | 1066 ToggleOverview(); |
| 1072 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), GetFocusedWindow()); | 1067 EXPECT_EQ(text_filter_widget()->GetNativeWindow(), wm::GetFocusedWindow()); |
| 1073 | 1068 |
| 1074 // If canceling overview mode, focus should be restored. | 1069 // If canceling overview mode, focus should be restored. |
| 1075 ToggleOverview(); | 1070 ToggleOverview(); |
| 1076 EXPECT_EQ(window.get(), GetFocusedWindow()); | 1071 EXPECT_EQ(window.get(), wm::GetFocusedWindow()); |
| 1077 } | 1072 } |
| 1078 | 1073 |
| 1079 // Tests that overview mode is exited if the last remaining window is destroyed. | 1074 // Tests that overview mode is exited if the last remaining window is destroyed. |
| 1080 TEST_F(WindowSelectorTest, LastWindowDestroyed) { | 1075 TEST_F(WindowSelectorTest, LastWindowDestroyed) { |
| 1081 gfx::Rect bounds(0, 0, 400, 400); | 1076 gfx::Rect bounds(0, 0, 400, 400); |
| 1082 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); | 1077 std::unique_ptr<aura::Window> window1(CreateWindow(bounds)); |
| 1083 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); | 1078 std::unique_ptr<aura::Window> window2(CreateWindow(bounds)); |
| 1084 ToggleOverview(); | 1079 ToggleOverview(); |
| 1085 | 1080 |
| 1086 window1.reset(); | 1081 window1.reset(); |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1859 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); | 1854 aura::client::WINDOW_MOVE_SOURCE_MOUSE)); |
| 1860 ASSERT_TRUE(resizer.get()); | 1855 ASSERT_TRUE(resizer.get()); |
| 1861 gfx::Point location = resizer->GetInitialLocation(); | 1856 gfx::Point location = resizer->GetInitialLocation(); |
| 1862 location.Offset(20, 20); | 1857 location.Offset(20, 20); |
| 1863 resizer->Drag(location, 0); | 1858 resizer->Drag(location, 0); |
| 1864 ToggleOverview(); | 1859 ToggleOverview(); |
| 1865 resizer->RevertDrag(); | 1860 resizer->RevertDrag(); |
| 1866 } | 1861 } |
| 1867 | 1862 |
| 1868 } // namespace ash | 1863 } // namespace ash |
| OLD | NEW |