Avi Drissman | 3a215d1e | 2022-09-07 19:43:09 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 5 | #include "ash/focus_cycler.h" |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 6 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 7 | #include <memory> |
| 8 | |
James Cook | 840177e | 2017-05-25 02:20:01 | [diff] [blame] | 9 | #include "ash/shelf/shelf.h" |
Manu Cornet | e11c3c35 | 2019-07-31 06:13:41 | [diff] [blame] | 10 | #include "ash/shelf/shelf_focus_cycler.h" |
| 11 | #include "ash/shelf/shelf_navigation_widget.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 12 | #include "ash/shelf/shelf_widget.h" |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 13 | #include "ash/shell.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 14 | #include "ash/system/status_area_widget.h" |
| 15 | #include "ash/system/status_area_widget_delegate.h" |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 16 | #include "ash/test/ash_test_base.h" |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 17 | #include "ash/wm/window_util.h" |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 18 | #include "ui/aura/test/test_windows.h" |
| 19 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 20 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 21 | #include "ui/events/test/event_generator.h" |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 22 | #include "ui/views/accessible_pane_view.h" |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 23 | #include "ui/views/controls/button/menu_button.h" |
| 24 | #include "ui/views/widget/widget.h" |
| 25 | |
| 26 | namespace ash { |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 27 | |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 28 | using aura::Window; |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 29 | |
[email protected] | 8676f047 | 2012-03-29 20:30:12 | [diff] [blame] | 30 | namespace { |
| 31 | |
[email protected] | 093b8d64 | 2014-04-03 20:59:28 | [diff] [blame] | 32 | StatusAreaWidgetDelegate* GetStatusAreaWidgetDelegate(views::Widget* widget) { |
| 33 | return static_cast<StatusAreaWidgetDelegate*>(widget->GetContentsView()); |
[email protected] | 8676f047 | 2012-03-29 20:30:12 | [diff] [blame] | 34 | } |
| 35 | |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 36 | class PanedWidgetDelegate : public views::WidgetDelegate { |
| 37 | public: |
| 38 | PanedWidgetDelegate(views::Widget* widget) : widget_(widget) {} |
| 39 | |
| 40 | void SetAccessiblePanes(const std::vector<views::View*>& panes) { |
| 41 | accessible_panes_ = panes; |
| 42 | } |
| 43 | |
Peter Kasting | 9ffb58bc7 | 2020-01-13 17:28:05 | [diff] [blame] | 44 | // views::WidgetDelegate: |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 45 | void GetAccessiblePanes(std::vector<views::View*>* panes) override { |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 46 | std::copy(accessible_panes_.begin(), accessible_panes_.end(), |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 47 | std::back_inserter(*panes)); |
| 48 | } |
Allen Bauer | d66100e | 2020-02-10 18:11:43 | [diff] [blame] | 49 | views::Widget* GetWidget() override { return widget_; } |
| 50 | const views::Widget* GetWidget() const override { return widget_; } |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | views::Widget* widget_; |
| 54 | std::vector<views::View*> accessible_panes_; |
| 55 | }; |
| 56 | |
[email protected] | 8676f047 | 2012-03-29 20:30:12 | [diff] [blame] | 57 | } // namespace |
| 58 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 59 | class FocusCyclerTest : public AshTestBase { |
| 60 | public: |
Chris Watkins | c24daf6 | 2017-11-28 03:43:09 | [diff] [blame] | 61 | FocusCyclerTest() = default; |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 62 | |
Peter Boström | 5fc1d31 | 2021-09-24 02:32:15 | [diff] [blame] | 63 | FocusCyclerTest(const FocusCyclerTest&) = delete; |
| 64 | FocusCyclerTest& operator=(const FocusCyclerTest&) = delete; |
| 65 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 66 | void SetUp() override { |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 67 | AshTestBase::SetUp(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 68 | |
Peter Boström | 6b70182 | 2021-04-15 03:53:08 | [diff] [blame] | 69 | focus_cycler_ = std::make_unique<FocusCycler>(); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 70 | } |
| 71 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 72 | void TearDown() override { |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 73 | GetStatusAreaWidgetDelegate(GetPrimaryStatusAreaWidget()) |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 74 | ->SetFocusCyclerForTesting(nullptr); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 75 | |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 76 | GetPrimaryShelf()->shelf_widget()->SetFocusCycler(nullptr); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 77 | |
| 78 | focus_cycler_.reset(); |
| 79 | |
| 80 | AshTestBase::TearDown(); |
| 81 | } |
| 82 | |
| 83 | protected: |
jamescook | fe89c29 | 2017-03-10 18:03:23 | [diff] [blame] | 84 | // Setup the system tray focus cycler. |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 85 | void SetUpTrayFocusCycle() { |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 86 | views::Widget* system_tray_widget = GetPrimaryStatusAreaWidget(); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 87 | ASSERT_TRUE(system_tray_widget); |
| 88 | focus_cycler_->AddWidget(system_tray_widget); |
| 89 | GetStatusAreaWidgetDelegate(system_tray_widget) |
| 90 | ->SetFocusCyclerForTesting(focus_cycler()); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 91 | } |
| 92 | |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 93 | views::Widget* GetPrimaryStatusAreaWidget() { |
| 94 | return GetPrimaryShelf()->GetStatusAreaWidget(); |
| 95 | } |
| 96 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 97 | FocusCycler* focus_cycler() { return focus_cycler_.get(); } |
| 98 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 99 | void InstallFocusCycleOnShelf() { |
| 100 | // Add the shelf. |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 101 | GetPrimaryShelf()->hotseat_widget()->SetFocusCycler(focus_cycler()); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | private: |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 105 | std::unique_ptr<FocusCycler> focus_cycler_; |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 109 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 110 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 111 | wm::ActivateWindow(window0.get()); |
| 112 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 113 | |
| 114 | // Cycle the window |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 115 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 116 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 117 | } |
| 118 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 119 | TEST_F(FocusCyclerTest, CycleFocusForward) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 120 | SetUpTrayFocusCycle(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 121 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 122 | InstallFocusCycleOnShelf(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 123 | |
| 124 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 125 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 126 | wm::ActivateWindow(window0.get()); |
| 127 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 128 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 129 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 130 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 131 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 132 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 133 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 134 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 135 | EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive()); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 136 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 137 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 138 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 139 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 140 | } |
| 141 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 142 | TEST_F(FocusCyclerTest, CycleFocusBackward) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 143 | SetUpTrayFocusCycle(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 144 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 145 | InstallFocusCycleOnShelf(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 146 | |
| 147 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 148 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 149 | wm::ActivateWindow(window0.get()); |
| 150 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 151 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 152 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 153 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 154 | EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive()); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 155 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 156 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 157 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 158 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 159 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 160 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 161 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 162 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 163 | } |
| 164 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 165 | TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 166 | SetUpTrayFocusCycle(); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 167 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 168 | InstallFocusCycleOnShelf(); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 169 | |
| 170 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 171 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 172 | wm::ActivateWindow(window0.get()); |
| 173 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 174 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 175 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 176 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 177 | EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 178 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 179 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 180 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 181 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 182 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 183 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 184 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 185 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 186 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 187 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 188 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 189 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 190 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 191 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 192 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 193 | EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 194 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 195 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 196 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 197 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 198 | } |
| 199 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 200 | TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 201 | SetUpTrayFocusCycle(); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 202 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 203 | InstallFocusCycleOnShelf(); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 204 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 205 | // Add the shelf and focus it. |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 206 | focus_cycler()->FocusWidget(GetPrimaryShelf()->hotseat_widget()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 207 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 208 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 209 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 210 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 211 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 212 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 213 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 214 | EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 215 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 216 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 217 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 218 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 219 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 220 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 221 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 222 | EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 223 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 224 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 225 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 226 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 227 | } |
| 228 | |
[email protected] | fba1eb2 | 2014-03-12 21:12:50 | [diff] [blame] | 229 | // Tests that focus cycles from the active browser to the status area and back. |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 230 | TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 231 | SetUpTrayFocusCycle(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 232 | InstallFocusCycleOnShelf(); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 233 | GetPrimaryShelf()->hotseat_widget()->Hide(); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 234 | |
[email protected] | fba1eb2 | 2014-03-12 21:12:50 | [diff] [blame] | 235 | // Create two test windows. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 236 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 237 | std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
[email protected] | fba1eb2 | 2014-03-12 21:12:50 | [diff] [blame] | 238 | wm::ActivateWindow(window1.get()); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 239 | wm::ActivateWindow(window0.get()); |
| 240 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 241 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 242 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 243 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 244 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 245 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 246 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 247 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 248 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | fba1eb2 | 2014-03-12 21:12:50 | [diff] [blame] | 249 | |
| 250 | // Cycle focus to the status area. |
| 251 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 252 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 253 | } |
| 254 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 255 | TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 256 | SetUpTrayFocusCycle(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 257 | InstallFocusCycleOnShelf(); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 258 | GetPrimaryShelf()->hotseat_widget()->Hide(); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 259 | |
| 260 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 261 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 262 | wm::ActivateWindow(window0.get()); |
| 263 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 264 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 265 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 266 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 267 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 268 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 269 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 270 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 271 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 272 | } |
| 273 | |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 274 | TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 275 | SetUpTrayFocusCycle(); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 276 | |
| 277 | InstallFocusCycleOnShelf(); |
| 278 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 279 | std::unique_ptr<PanedWidgetDelegate> test_widget_delegate; |
| 280 | std::unique_ptr<views::Widget> browser_widget(new views::Widget); |
Peter Boström | 6b70182 | 2021-04-15 03:53:08 | [diff] [blame] | 281 | test_widget_delegate = |
| 282 | std::make_unique<PanedWidgetDelegate>(browser_widget.get()); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 283 | views::Widget::InitParams widget_params( |
| 284 | views::Widget::InitParams::TYPE_WINDOW); |
[email protected] | 464a001 | 2013-11-12 18:22:44 | [diff] [blame] | 285 | widget_params.delegate = test_widget_delegate.get(); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 286 | widget_params.ownership = |
| 287 | views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
Peter Kasting | 97defc9 | 2020-03-05 18:49:02 | [diff] [blame] | 288 | widget_params.context = GetContext(); |
Ahmed Fakhry | 32f3c45 | 2019-08-01 16:36:34 | [diff] [blame] | 289 | browser_widget->Init(std::move(widget_params)); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 290 | browser_widget->Show(); |
| 291 | |
| 292 | aura::Window* browser_window = browser_widget->GetNativeView(); |
| 293 | |
| 294 | views::View* root_view = browser_widget->GetRootView(); |
| 295 | |
Manu Cornet | e11c3c35 | 2019-07-31 06:13:41 | [diff] [blame] | 296 | // pane1 contains view1 and view2, pane2 contains view3 and view4. |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 297 | views::AccessiblePaneView* pane1 = new views::AccessiblePaneView(); |
| 298 | root_view->AddChildView(pane1); |
| 299 | |
| 300 | views::View* view1 = new views::View; |
karandeepb | e7ad02a | 2016-04-27 23:57:22 | [diff] [blame] | 301 | view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 302 | pane1->AddChildView(view1); |
| 303 | |
| 304 | views::View* view2 = new views::View; |
karandeepb | e7ad02a | 2016-04-27 23:57:22 | [diff] [blame] | 305 | view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 306 | pane1->AddChildView(view2); |
| 307 | |
| 308 | views::AccessiblePaneView* pane2 = new views::AccessiblePaneView(); |
| 309 | root_view->AddChildView(pane2); |
| 310 | |
| 311 | views::View* view3 = new views::View; |
karandeepb | e7ad02a | 2016-04-27 23:57:22 | [diff] [blame] | 312 | view3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 313 | pane2->AddChildView(view3); |
| 314 | |
| 315 | views::View* view4 = new views::View; |
karandeepb | e7ad02a | 2016-04-27 23:57:22 | [diff] [blame] | 316 | view4->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 317 | pane2->AddChildView(view4); |
| 318 | |
| 319 | std::vector<views::View*> panes; |
| 320 | panes.push_back(pane1); |
| 321 | panes.push_back(pane2); |
| 322 | |
| 323 | test_widget_delegate->SetAccessiblePanes(panes); |
| 324 | |
| 325 | views::FocusManager* focus_manager = browser_widget->GetFocusManager(); |
| 326 | |
| 327 | // Cycle focus to the status area. |
| 328 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 329 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 330 | |
| 331 | // Cycle focus to the shelf. |
| 332 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 333 | EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive()); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 334 | |
| 335 | // Cycle focus to the first pane in the browser. |
| 336 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 337 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 338 | EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 339 | |
| 340 | // Cycle focus to the second pane in the browser. |
| 341 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 342 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 343 | EXPECT_EQ(focus_manager->GetFocusedView(), view3); |
| 344 | |
| 345 | // Cycle focus back to the status area. |
| 346 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 347 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 348 | |
| 349 | // Reverse direction - back to the second pane in the browser. |
| 350 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 351 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 352 | EXPECT_EQ(focus_manager->GetFocusedView(), view3); |
| 353 | |
| 354 | // Back to the first pane in the browser. |
| 355 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 356 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 357 | EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 358 | |
| 359 | // Back to the shelf. |
| 360 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 361 | EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive()); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 362 | |
| 363 | // Back to the status area. |
| 364 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
Tetsui Ohkubo | 2b2fe2d | 2018-06-01 17:01:23 | [diff] [blame] | 365 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 366 | |
| 367 | // Pressing "Escape" while on the status area should |
| 368 | // deactivate it, and activate the browser window. |
James Cook | 70501b2 | 2021-08-09 17:19:18 | [diff] [blame] | 369 | PressAndReleaseKey(ui::VKEY_ESCAPE); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 370 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 371 | EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 372 | |
Manu Cornet | e11c3c35 | 2019-07-31 06:13:41 | [diff] [blame] | 373 | // Similarly, pressing "Escape" while on the shelf should do the same thing. |
| 374 | // Focus the navigation widget directly because the shelf has no apps here. |
| 375 | GetPrimaryShelf()->shelf_focus_cycler()->FocusNavigation(false /* last */); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 376 | EXPECT_TRUE(GetPrimaryShelf()->navigation_widget()->IsActive()); |
James Cook | 70501b2 | 2021-08-09 17:19:18 | [diff] [blame] | 377 | PressAndReleaseKey(ui::VKEY_ESCAPE); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 378 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 379 | EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 380 | } |
| 381 | |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 382 | // Test that when the shelf widget & status area widget are removed, they should |
| 383 | // also be removed from focus cycler. |
| 384 | TEST_F(FocusCyclerTest, RemoveWidgetOnDisplayRemoved) { |
| 385 | // Two displays are added, so two shelf widgets and two status area widgets |
| 386 | // are added to focus cycler. |
Mitsuru Oshima | a97d1e5 | 2021-10-05 08:27:42 | [diff] [blame] | 387 | UpdateDisplay("800x700, 600x500"); |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 388 | // Remove one display. Its shelf widget and status area widget should also be |
| 389 | // removed from focus cycler. |
Mitsuru Oshima | 53bbcd7 | 2021-08-14 03:59:21 | [diff] [blame] | 390 | UpdateDisplay("800x700"); |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 391 | |
| 392 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 393 | std::unique_ptr<Window> window(CreateTestWindowInShellWithId(0)); |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 394 | wm::ActivateWindow(window.get()); |
| 395 | EXPECT_TRUE(wm::IsActiveWindow(window.get())); |
| 396 | |
Manu Cornet | e11c3c35 | 2019-07-31 06:13:41 | [diff] [blame] | 397 | // Cycle focus to the navigation widget. |
| 398 | Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 399 | EXPECT_TRUE(GetPrimaryShelf()->navigation_widget()->IsActive()); |
Manu Cornet | e11c3c35 | 2019-07-31 06:13:41 | [diff] [blame] | 400 | |
Manu Cornet | aef0c11 | 2019-08-19 19:35:24 | [diff] [blame] | 401 | // Cycle focus to the hotseat widget. |
| 402 | Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
Manu Cornet | 55cfe06 | 2020-02-03 22:28:22 | [diff] [blame] | 403 | EXPECT_TRUE(GetPrimaryShelf()->hotseat_widget()->IsActive()); |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 404 | |
Alex Newcomer | 6be0833 | 2020-04-17 19:00:43 | [diff] [blame] | 405 | // Cycle focus to the status area. |
| 406 | Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 407 | EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive()); |
| 408 | |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 409 | // Cycle focus should go back to the browser. |
sky | 79fa3471 | 2017-03-20 23:46:47 | [diff] [blame] | 410 | Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 411 | EXPECT_TRUE(wm::IsActiveWindow(window.get())); |
| 412 | } |
| 413 | |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 414 | } // namespace ash |