| 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/focus_cycler.h" | 5 #include "ash/common/focus_cycler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf.h" | |
| 10 #include "ash/common/shelf/shelf_widget.h" | 9 #include "ash/common/shelf/shelf_widget.h" |
| 10 #include "ash/common/shelf/wm_shelf.h" |
| 11 #include "ash/common/system/status_area_widget.h" | 11 #include "ash/common/system/status_area_widget.h" |
| 12 #include "ash/common/system/status_area_widget_delegate.h" | 12 #include "ash/common/system/status_area_widget_delegate.h" |
| 13 #include "ash/common/system/tray/system_tray.h" | 13 #include "ash/common/system/tray/system_tray.h" |
| 14 #include "ash/common/wm_shell.h" | 14 #include "ash/common/wm_shell.h" |
| 15 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
| 16 #include "ash/test/status_area_widget_test_helper.h" | 16 #include "ash/test/status_area_widget_test_helper.h" |
| 17 #include "ash/wm/window_util.h" | 17 #include "ash/wm/window_util.h" |
| 18 #include "ui/aura/test/test_windows.h" | 18 #include "ui/aura/test/test_windows.h" |
| 19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_event_dispatcher.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 // TODO(jamescook): Migrate this test to //ash/common after the status area | 60 // TODO(jamescook): Migrate this test to //ash/common after the status area |
| 61 // widget moves. http://crbug.com/620955 | 61 // widget moves. http://crbug.com/620955 |
| 62 class FocusCyclerTest : public AshTestBase { | 62 class FocusCyclerTest : public AshTestBase { |
| 63 public: | 63 public: |
| 64 FocusCyclerTest() {} | 64 FocusCyclerTest() {} |
| 65 | 65 |
| 66 void SetUp() override { | 66 void SetUp() override { |
| 67 AshTestBase::SetUp(); | 67 AshTestBase::SetUp(); |
| 68 | 68 |
| 69 focus_cycler_.reset(new FocusCycler()); | 69 focus_cycler_.reset(new FocusCycler()); |
| 70 | |
| 71 ASSERT_TRUE(Shelf::ForPrimaryDisplay()); | |
| 72 } | 70 } |
| 73 | 71 |
| 74 void TearDown() override { | 72 void TearDown() override { |
| 75 GetStatusAreaWidgetDelegate(GetPrimarySystemTray()->GetWidget()) | 73 GetStatusAreaWidgetDelegate(GetPrimarySystemTray()->GetWidget()) |
| 76 ->SetFocusCyclerForTesting(nullptr); | 74 ->SetFocusCyclerForTesting(nullptr); |
| 77 | 75 |
| 78 shelf_widget()->SetFocusCycler(nullptr); | 76 shelf_widget()->SetFocusCycler(nullptr); |
| 79 | 77 |
| 80 focus_cycler_.reset(); | 78 focus_cycler_.reset(); |
| 81 | 79 |
| 82 AshTestBase::TearDown(); | 80 AshTestBase::TearDown(); |
| 83 } | 81 } |
| 84 | 82 |
| 85 protected: | 83 protected: |
| 86 // Setup the system tray using StatusAreaWidgetTestHelper and focus_cycler. | 84 // Setup the system tray using StatusAreaWidgetTestHelper and focus_cycler. |
| 87 void SetUpTrayFocusCycle() { | 85 void SetUpTrayFocusCycle() { |
| 88 StatusAreaWidget* widget = | 86 StatusAreaWidget* widget = |
| 89 StatusAreaWidgetTestHelper::GetStatusAreaWidget(); | 87 StatusAreaWidgetTestHelper::GetStatusAreaWidget(); |
| 90 widget->CreateTrayViews(); | 88 widget->CreateTrayViews(); |
| 91 widget->Show(); | 89 widget->Show(); |
| 92 views::Widget* system_tray_widget = GetPrimarySystemTray()->GetWidget(); | 90 views::Widget* system_tray_widget = GetPrimarySystemTray()->GetWidget(); |
| 93 ASSERT_TRUE(system_tray_widget); | 91 ASSERT_TRUE(system_tray_widget); |
| 94 focus_cycler_->AddWidget(system_tray_widget); | 92 focus_cycler_->AddWidget(system_tray_widget); |
| 95 GetStatusAreaWidgetDelegate(system_tray_widget) | 93 GetStatusAreaWidgetDelegate(system_tray_widget) |
| 96 ->SetFocusCyclerForTesting(focus_cycler()); | 94 ->SetFocusCyclerForTesting(focus_cycler()); |
| 97 } | 95 } |
| 98 | 96 |
| 99 FocusCycler* focus_cycler() { return focus_cycler_.get(); } | 97 FocusCycler* focus_cycler() { return focus_cycler_.get(); } |
| 100 | 98 |
| 101 ShelfWidget* shelf_widget() { | 99 ShelfWidget* shelf_widget() { return GetPrimaryShelf()->shelf_widget(); } |
| 102 return Shelf::ForPrimaryDisplay()->shelf_widget(); | |
| 103 } | |
| 104 | 100 |
| 105 void InstallFocusCycleOnShelf() { | 101 void InstallFocusCycleOnShelf() { |
| 106 // Add the shelf. | 102 // Add the shelf. |
| 107 shelf_widget()->SetFocusCycler(focus_cycler()); | 103 shelf_widget()->SetFocusCycler(focus_cycler()); |
| 108 } | 104 } |
| 109 | 105 |
| 110 private: | 106 private: |
| 111 std::unique_ptr<FocusCycler> focus_cycler_; | 107 std::unique_ptr<FocusCycler> focus_cycler_; |
| 112 | 108 |
| 113 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest); | 109 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest); |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 // Cycle focus to the shelf. | 404 // Cycle focus to the shelf. |
| 409 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 405 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 410 | 406 |
| 411 // Cycle focus should go back to the browser. | 407 // Cycle focus should go back to the browser. |
| 412 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 408 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 413 EXPECT_TRUE(wm::IsActiveWindow(window.get())); | 409 EXPECT_TRUE(wm::IsActiveWindow(window.get())); |
| 414 } | 410 } |
| 415 | 411 |
| 416 } // namespace test | 412 } // namespace test |
| 417 } // namespace ash | 413 } // namespace ash |
| OLD | NEW |