| 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/focus_cycler.h" | 5 #include "ash/common/focus_cycler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 11 #include "ash/common/wm_window.h" | 11 #include "ash/common/wm_window.h" |
| 12 #include "ash/shelf/shelf.h" | 12 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shelf/shelf_widget.h" | 13 #include "ash/shelf/shelf_widget.h" |
| 14 #include "ash/shell.h" | |
| 15 #include "ash/shell_factory.h" | |
| 16 #include "ash/system/status_area_widget.h" | 14 #include "ash/system/status_area_widget.h" |
| 17 #include "ash/system/status_area_widget_delegate.h" | 15 #include "ash/system/status_area_widget_delegate.h" |
| 18 #include "ash/system/tray/system_tray.h" | 16 #include "ash/system/tray/system_tray.h" |
| 19 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
| 20 #include "ash/wm/window_util.h" | 18 #include "ash/wm/window_util.h" |
| 21 #include "ui/aura/test/test_windows.h" | 19 #include "ui/aura/test/test_windows.h" |
| 22 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 23 #include "ui/aura/window_event_dispatcher.h" | 21 #include "ui/aura/window_event_dispatcher.h" |
| 24 #include "ui/events/test/event_generator.h" | 22 #include "ui/events/test/event_generator.h" |
| 25 #include "ui/views/accessible_pane_view.h" | 23 #include "ui/views/accessible_pane_view.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 54 views::Widget* GetWidget() override { return widget_; }; | 52 views::Widget* GetWidget() override { return widget_; }; |
| 55 const views::Widget* GetWidget() const override { return widget_; } | 53 const views::Widget* GetWidget() const override { return widget_; } |
| 56 | 54 |
| 57 private: | 55 private: |
| 58 views::Widget* widget_; | 56 views::Widget* widget_; |
| 59 std::vector<views::View*> accessible_panes_; | 57 std::vector<views::View*> accessible_panes_; |
| 60 }; | 58 }; |
| 61 | 59 |
| 62 } // namespace | 60 } // namespace |
| 63 | 61 |
| 62 // TODO(jamescook): Migrate this test to //ash/common after the status area |
| 63 // widget moves. http://crbug.com/620955 |
| 64 class FocusCyclerTest : public AshTestBase { | 64 class FocusCyclerTest : public AshTestBase { |
| 65 public: | 65 public: |
| 66 FocusCyclerTest() {} | 66 FocusCyclerTest() {} |
| 67 | 67 |
| 68 void SetUp() override { | 68 void SetUp() override { |
| 69 AshTestBase::SetUp(); | 69 AshTestBase::SetUp(); |
| 70 | 70 |
| 71 focus_cycler_.reset(new FocusCycler()); | 71 focus_cycler_.reset(new FocusCycler()); |
| 72 | 72 |
| 73 ASSERT_TRUE(Shelf::ForPrimaryDisplay()); | 73 ASSERT_TRUE(Shelf::ForPrimaryDisplay()); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 // Back to the shelf. | 380 // Back to the shelf. |
| 381 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 381 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 382 EXPECT_TRUE(shelf_widget()->IsActive()); | 382 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 383 | 383 |
| 384 // Back to the status area. | 384 // Back to the status area. |
| 385 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 385 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 386 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 386 EXPECT_TRUE(tray()->GetWidget()->IsActive()); |
| 387 | 387 |
| 388 // Pressing "Escape" while on the status area should | 388 // Pressing "Escape" while on the status area should |
| 389 // deactivate it, and activate the browser window. | 389 // deactivate it, and activate the browser window. |
| 390 aura::Window* root = Shell::GetPrimaryRootWindow(); | 390 ui::test::EventGenerator& event_generator = GetEventGenerator(); |
| 391 ui::test::EventGenerator event_generator(root, root); | |
| 392 event_generator.PressKey(ui::VKEY_ESCAPE, 0); | 391 event_generator.PressKey(ui::VKEY_ESCAPE, 0); |
| 393 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); | 392 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 394 EXPECT_EQ(focus_manager->GetFocusedView(), view1); | 393 EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 395 | 394 |
| 396 // Similarly, pressing "Escape" while on the shelf. | 395 // Similarly, pressing "Escape" while on the shelf. |
| 397 // should do the same thing. | 396 // should do the same thing. |
| 398 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 397 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 399 EXPECT_TRUE(shelf_widget()->IsActive()); | 398 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 400 event_generator.PressKey(ui::VKEY_ESCAPE, 0); | 399 event_generator.PressKey(ui::VKEY_ESCAPE, 0); |
| 401 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); | 400 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 402 EXPECT_EQ(focus_manager->GetFocusedView(), view1); | 401 EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 403 } | 402 } |
| 404 | 403 |
| 405 // Test that when the shelf widget & status area widget are removed, they should | 404 // Test that when the shelf widget & status area widget are removed, they should |
| 406 // also be removed from focus cycler. | 405 // also be removed from focus cycler. |
| 407 TEST_F(FocusCyclerTest, RemoveWidgetOnDisplayRemoved) { | 406 TEST_F(FocusCyclerTest, RemoveWidgetOnDisplayRemoved) { |
| 408 // Two displays are added, so two shelf widgets and two status area widgets | 407 // Two displays are added, so two shelf widgets and two status area widgets |
| 409 // are added to focus cycler. | 408 // are added to focus cycler. |
| 410 UpdateDisplay("800x800, 500x500"); | 409 UpdateDisplay("800x800, 500x500"); |
| 411 // Remove one display. Its shelf widget and status area widget should also be | 410 // Remove one display. Its shelf widget and status area widget should also be |
| 412 // removed from focus cycler. | 411 // removed from focus cycler. |
| 413 UpdateDisplay("800x800"); | 412 UpdateDisplay("800x800"); |
| 414 | 413 |
| 415 // Create a single test window. | 414 // Create a single test window. |
| 416 std::unique_ptr<Window> window(CreateTestWindowInShellWithId(0)); | 415 std::unique_ptr<Window> window(CreateTestWindowInShellWithId(0)); |
| 417 wm::ActivateWindow(window.get()); | 416 wm::ActivateWindow(window.get()); |
| 418 EXPECT_TRUE(wm::IsActiveWindow(window.get())); | 417 EXPECT_TRUE(wm::IsActiveWindow(window.get())); |
| 419 | 418 |
| 420 // Cycle focus to the status area. | 419 // Cycle focus to the status area. |
| 421 Shell::GetInstance()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 420 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 422 EXPECT_FALSE(wm::IsActiveWindow(window.get())); | 421 EXPECT_FALSE(wm::IsActiveWindow(window.get())); |
| 423 | 422 |
| 424 // Cycle focus to the shelf. | 423 // Cycle focus to the shelf. |
| 425 Shell::GetInstance()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 424 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 426 | 425 |
| 427 // Cycle focus should go back to the browser. | 426 // Cycle focus should go back to the browser. |
| 428 Shell::GetInstance()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 427 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 429 EXPECT_TRUE(wm::IsActiveWindow(window.get())); | 428 EXPECT_TRUE(wm::IsActiveWindow(window.get())); |
| 430 } | 429 } |
| 431 | 430 |
| 432 } // namespace test | 431 } // namespace test |
| 433 } // namespace ash | 432 } // namespace ash |
| OLD | NEW |