| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/window_cycle_controller.h" | 5 #include "ash/wm/window_cycle_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/focus_cycler.h" | 10 #include "ash/focus_cycler.h" |
| 11 #include "ash/public/cpp/shell_window_ids.h" | 11 #include "ash/public/cpp/shell_window_ids.h" |
| 12 #include "ash/scoped_root_window_for_new_windows.h" | 12 #include "ash/scoped_root_window_for_new_windows.h" |
| 13 #include "ash/session/session_controller.h" | 13 #include "ash/session/session_controller.h" |
| 14 #include "ash/shelf/shelf_widget.h" | 14 #include "ash/shelf/shelf_widget.h" |
| 15 #include "ash/shelf/wm_shelf.h" | 15 #include "ash/shelf/wm_shelf.h" |
| 16 #include "ash/shell.h" | 16 #include "ash/shell.h" |
| 17 #include "ash/shell_port.h" |
| 17 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
| 18 #include "ash/test/shelf_view_test_api.h" | 19 #include "ash/test/shelf_view_test_api.h" |
| 19 #include "ash/test/test_app_list_view_presenter_impl.h" | 20 #include "ash/test/test_app_list_view_presenter_impl.h" |
| 20 #include "ash/test/test_session_controller_client.h" | 21 #include "ash/test/test_session_controller_client.h" |
| 21 #include "ash/test/test_shelf_delegate.h" | 22 #include "ash/test/test_shelf_delegate.h" |
| 22 #include "ash/test/test_shell_delegate.h" | 23 #include "ash/test/test_shell_delegate.h" |
| 23 #include "ash/wm/window_cycle_list.h" | 24 #include "ash/wm/window_cycle_list.h" |
| 24 #include "ash/wm/window_state.h" | 25 #include "ash/wm/window_state.h" |
| 25 #include "ash/wm/window_state_aura.h" | 26 #include "ash/wm/window_state_aura.h" |
| 26 #include "ash/wm/window_util.h" | 27 #include "ash/wm/window_util.h" |
| 27 #include "ash/wm/wm_event.h" | 28 #include "ash/wm/wm_event.h" |
| 28 #include "ash/wm_shell.h" | |
| 29 #include "ash/wm_window.h" | 29 #include "ash/wm_window.h" |
| 30 #include "ui/aura/client/aura_constants.h" | 30 #include "ui/aura/client/aura_constants.h" |
| 31 #include "ui/aura/client/screen_position_client.h" | 31 #include "ui/aura/client/screen_position_client.h" |
| 32 #include "ui/aura/env.h" | 32 #include "ui/aura/env.h" |
| 33 #include "ui/aura/test/test_windows.h" | 33 #include "ui/aura/test/test_windows.h" |
| 34 #include "ui/aura/window.h" | 34 #include "ui/aura/window.h" |
| 35 #include "ui/aura/window_event_dispatcher.h" | 35 #include "ui/aura/window_event_dispatcher.h" |
| 36 #include "ui/display/display_layout_builder.h" | 36 #include "ui/display/display_layout_builder.h" |
| 37 #include "ui/display/manager/display_layout_store.h" | 37 #include "ui/display/manager/display_layout_store.h" |
| 38 #include "ui/display/manager/display_manager.h" | 38 #include "ui/display/manager/display_manager.h" |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 | 475 |
| 476 // Showing the Alt+Tab UI does however deactivate the erstwhile active window. | 476 // Showing the Alt+Tab UI does however deactivate the erstwhile active window. |
| 477 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 477 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
| 478 | 478 |
| 479 controller->CompleteCycling(); | 479 controller->CompleteCycling(); |
| 480 } | 480 } |
| 481 | 481 |
| 482 // Tests that beginning window selection hides the app list. | 482 // Tests that beginning window selection hides the app list. |
| 483 TEST_F(WindowCycleControllerTest, SelectingHidesAppList) { | 483 TEST_F(WindowCycleControllerTest, SelectingHidesAppList) { |
| 484 // TODO: fails in mash because of AppListPresenter. http://crbug.com/696028. | 484 // TODO: fails in mash because of AppListPresenter. http://crbug.com/696028. |
| 485 if (WmShell::Get()->IsRunningInMash()) | 485 if (ShellPort::Get()->IsRunningInMash()) |
| 486 return; | 486 return; |
| 487 | 487 |
| 488 // The tested behavior relies on the app list presenter implementation. | 488 // The tested behavior relies on the app list presenter implementation. |
| 489 test::TestAppListViewPresenterImpl app_list_presenter_impl; | 489 test::TestAppListViewPresenterImpl app_list_presenter_impl; |
| 490 | 490 |
| 491 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); | 491 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 492 | 492 |
| 493 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 493 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 494 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 494 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 495 app_list_presenter_impl.Show( | 495 app_list_presenter_impl.Show( |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 panel0.reset(); | 607 panel0.reset(); |
| 608 // Cycling again should now select panel1. | 608 // Cycling again should now select panel1. |
| 609 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 609 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 610 controller->CompleteCycling(); | 610 controller->CompleteCycling(); |
| 611 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); | 611 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); |
| 612 } | 612 } |
| 613 | 613 |
| 614 // Tests that the tab key events are not sent to the window. | 614 // Tests that the tab key events are not sent to the window. |
| 615 TEST_F(WindowCycleControllerTest, TabKeyNotLeaked) { | 615 TEST_F(WindowCycleControllerTest, TabKeyNotLeaked) { |
| 616 // TODO: investigate failure in mash. http://crbug.com/698894. | 616 // TODO: investigate failure in mash. http://crbug.com/698894. |
| 617 if (WmShell::Get()->IsRunningInMash()) | 617 if (ShellPort::Get()->IsRunningInMash()) |
| 618 return; | 618 return; |
| 619 | 619 |
| 620 std::unique_ptr<Window> w0(CreateTestWindowInShellWithId(0)); | 620 std::unique_ptr<Window> w0(CreateTestWindowInShellWithId(0)); |
| 621 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1)); | 621 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1)); |
| 622 EventCounter event_count; | 622 EventCounter event_count; |
| 623 w0->AddPreTargetHandler(&event_count); | 623 w0->AddPreTargetHandler(&event_count); |
| 624 w1->AddPreTargetHandler(&event_count); | 624 w1->AddPreTargetHandler(&event_count); |
| 625 ui::test::EventGenerator& generator = GetEventGenerator(); | 625 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 626 wm::GetWindowState(w0.get())->Activate(); | 626 wm::GetWindowState(w0.get())->Activate(); |
| 627 generator.PressKey(ui::VKEY_MENU, ui::EF_NONE); | 627 generator.PressKey(ui::VKEY_MENU, ui::EF_NONE); |
| 628 EXPECT_EQ(1, event_count.GetKeyEventCountAndReset()); | 628 EXPECT_EQ(1, event_count.GetKeyEventCountAndReset()); |
| 629 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 629 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
| 630 EXPECT_EQ(0, event_count.GetKeyEventCountAndReset()); | 630 EXPECT_EQ(0, event_count.GetKeyEventCountAndReset()); |
| 631 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 631 generator.ReleaseKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
| 632 EXPECT_EQ(0, event_count.GetKeyEventCountAndReset()); | 632 EXPECT_EQ(0, event_count.GetKeyEventCountAndReset()); |
| 633 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE); | 633 generator.ReleaseKey(ui::VKEY_MENU, ui::EF_NONE); |
| 634 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsActive()); | 634 EXPECT_TRUE(wm::GetWindowState(w1.get())->IsActive()); |
| 635 EXPECT_EQ(0, event_count.GetKeyEventCountAndReset()); | 635 EXPECT_EQ(0, event_count.GetKeyEventCountAndReset()); |
| 636 } | 636 } |
| 637 | 637 |
| 638 // While the UI is active, mouse events are captured. | 638 // While the UI is active, mouse events are captured. |
| 639 TEST_F(WindowCycleControllerTest, MouseEventsCaptured) { | 639 TEST_F(WindowCycleControllerTest, MouseEventsCaptured) { |
| 640 // TODO: investigate failure in mash. http://crbug.com/698894. | 640 // TODO: investigate failure in mash. http://crbug.com/698894. |
| 641 if (WmShell::Get()->IsRunningInMash()) | 641 if (ShellPort::Get()->IsRunningInMash()) |
| 642 return; | 642 return; |
| 643 | 643 |
| 644 // This delegate allows the window to receive mouse events. | 644 // This delegate allows the window to receive mouse events. |
| 645 aura::test::TestWindowDelegate delegate; | 645 aura::test::TestWindowDelegate delegate; |
| 646 std::unique_ptr<Window> w0(CreateTestWindowInShellWithDelegate( | 646 std::unique_ptr<Window> w0(CreateTestWindowInShellWithDelegate( |
| 647 &delegate, 0, gfx::Rect(0, 0, 100, 100))); | 647 &delegate, 0, gfx::Rect(0, 0, 100, 100))); |
| 648 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1)); | 648 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1)); |
| 649 EventCounter event_count; | 649 EventCounter event_count; |
| 650 w0->AddPreTargetHandler(&event_count); | 650 w0->AddPreTargetHandler(&event_count); |
| 651 w1->SetTargetHandler(&event_count); | 651 w1->SetTargetHandler(&event_count); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 w0->AddPreTargetHandler(&event_count); | 709 w0->AddPreTargetHandler(&event_count); |
| 710 w1->AddPreTargetHandler(&event_count); | 710 w1->AddPreTargetHandler(&event_count); |
| 711 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 711 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
| 712 EXPECT_EQ(1, event_count.GetKeyEventCountAndReset()); | 712 EXPECT_EQ(1, event_count.GetKeyEventCountAndReset()); |
| 713 } | 713 } |
| 714 | 714 |
| 715 // Tests that the Alt+Tab UI's position isn't affected by the origin of the | 715 // Tests that the Alt+Tab UI's position isn't affected by the origin of the |
| 716 // display it's on. See crbug.com/675718 | 716 // display it's on. See crbug.com/675718 |
| 717 TEST_F(WindowCycleControllerTest, MultiDisplayPositioning) { | 717 TEST_F(WindowCycleControllerTest, MultiDisplayPositioning) { |
| 718 // TODO: investigate failure in mash. http://crbug.com/698894. | 718 // TODO: investigate failure in mash. http://crbug.com/698894. |
| 719 if (WmShell::Get()->IsRunningInMash()) | 719 if (ShellPort::Get()->IsRunningInMash()) |
| 720 return; | 720 return; |
| 721 | 721 |
| 722 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 722 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 723 display::DisplayIdList list = | 723 display::DisplayIdList list = |
| 724 display::test::CreateDisplayIdListN(2, primary_id, primary_id + 1); | 724 display::test::CreateDisplayIdListN(2, primary_id, primary_id + 1); |
| 725 | 725 |
| 726 auto placements = { | 726 auto placements = { |
| 727 display::DisplayPlacement::BOTTOM, display::DisplayPlacement::TOP, | 727 display::DisplayPlacement::BOTTOM, display::DisplayPlacement::TOP, |
| 728 display::DisplayPlacement::LEFT, display::DisplayPlacement::RIGHT, | 728 display::DisplayPlacement::LEFT, display::DisplayPlacement::RIGHT, |
| 729 }; | 729 }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 // Base case sets the expectation for other cases. | 763 // Base case sets the expectation for other cases. |
| 764 if (expected_bounds.IsEmpty()) | 764 if (expected_bounds.IsEmpty()) |
| 765 expected_bounds = display_relative_bounds; | 765 expected_bounds = display_relative_bounds; |
| 766 else | 766 else |
| 767 EXPECT_EQ(expected_bounds, display_relative_bounds); | 767 EXPECT_EQ(expected_bounds, display_relative_bounds); |
| 768 controller->CompleteCycling(); | 768 controller->CompleteCycling(); |
| 769 } | 769 } |
| 770 } | 770 } |
| 771 | 771 |
| 772 } // namespace ash | 772 } // namespace ash |
| OLD | NEW |