[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
James Cook | 6316a55 | 2017-03-05 21:46:21 | [diff] [blame] | 5 | #include "ash/common/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 | 643b718 | 2017-03-05 22:02:58 | [diff] [blame] | 9 | #include "ash/common/shelf/shelf_widget.h" |
| 10 | #include "ash/common/shelf/wm_shelf.h" |
James Cook | 6def4d9d | 2017-03-05 22:13:47 | [diff] [blame] | 11 | #include "ash/common/system/status_area_widget.h" |
| 12 | #include "ash/common/system/status_area_widget_delegate.h" |
| 13 | #include "ash/common/system/tray/system_tray.h" |
James Cook | 6316a55 | 2017-03-05 21:46:21 | [diff] [blame] | 14 | #include "ash/common/wm_shell.h" |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 15 | #include "ash/test/ash_test_base.h" |
[email protected] | 864b5855 | 2013-12-19 04:19:38 | [diff] [blame] | 16 | #include "ash/wm/window_util.h" |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 17 | #include "ui/aura/test/test_windows.h" |
| 18 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 19 | #include "ui/aura/window_event_dispatcher.h" |
[email protected] | 73c9fd0 | 2014-07-28 01:48:52 | [diff] [blame] | 20 | #include "ui/events/test/event_generator.h" |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 21 | #include "ui/views/accessible_pane_view.h" |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 22 | #include "ui/views/controls/button/menu_button.h" |
| 23 | #include "ui/views/widget/widget.h" |
| 24 | |
| 25 | namespace ash { |
| 26 | namespace test { |
| 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 | |
| 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 | } |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [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: |
| 61 | FocusCyclerTest() {} |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 62 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 63 | void SetUp() override { |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 64 | AshTestBase::SetUp(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 65 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 66 | focus_cycler_.reset(new FocusCycler()); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 67 | } |
| 68 | |
dcheng | 222b9c7 | 2015-01-16 00:48:01 | [diff] [blame] | 69 | void TearDown() override { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 70 | GetStatusAreaWidgetDelegate(GetPrimarySystemTray()->GetWidget()) |
| 71 | ->SetFocusCyclerForTesting(nullptr); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 72 | |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 73 | shelf_widget()->SetFocusCycler(nullptr); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 74 | |
| 75 | focus_cycler_.reset(); |
| 76 | |
| 77 | AshTestBase::TearDown(); |
| 78 | } |
| 79 | |
| 80 | protected: |
jamescook | fe89c29 | 2017-03-10 18:03:23 | [diff] [blame^] | 81 | // Setup the system tray focus cycler. |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 82 | void SetUpTrayFocusCycle() { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 83 | views::Widget* system_tray_widget = GetPrimarySystemTray()->GetWidget(); |
| 84 | ASSERT_TRUE(system_tray_widget); |
| 85 | focus_cycler_->AddWidget(system_tray_widget); |
| 86 | GetStatusAreaWidgetDelegate(system_tray_widget) |
| 87 | ->SetFocusCyclerForTesting(focus_cycler()); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | FocusCycler* focus_cycler() { return focus_cycler_.get(); } |
| 91 | |
jamescook | 1cad77e9 | 2016-08-31 00:02:26 | [diff] [blame] | 92 | ShelfWidget* shelf_widget() { return GetPrimaryShelf()->shelf_widget(); } |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 93 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 94 | void InstallFocusCycleOnShelf() { |
| 95 | // Add the shelf. |
| 96 | shelf_widget()->SetFocusCycler(focus_cycler()); |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | private: |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 100 | std::unique_ptr<FocusCycler> focus_cycler_; |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 101 | |
| 102 | DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest); |
| 103 | }; |
| 104 | |
| 105 | TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 106 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 107 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 108 | wm::ActivateWindow(window0.get()); |
| 109 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 110 | |
| 111 | // Cycle the window |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 112 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 113 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 114 | } |
| 115 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 116 | TEST_F(FocusCyclerTest, CycleFocusForward) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 117 | SetUpTrayFocusCycle(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 118 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 119 | InstallFocusCycleOnShelf(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 120 | |
| 121 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 122 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 123 | wm::ActivateWindow(window0.get()); |
| 124 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 125 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 126 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 127 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 128 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 129 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 130 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 131 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 132 | EXPECT_TRUE(shelf_widget()->IsActive()); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 133 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 134 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 135 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 136 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 137 | } |
| 138 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 139 | TEST_F(FocusCyclerTest, CycleFocusBackward) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 140 | SetUpTrayFocusCycle(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 141 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 142 | InstallFocusCycleOnShelf(); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 143 | |
| 144 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 145 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 146 | wm::ActivateWindow(window0.get()); |
| 147 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 148 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 149 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 150 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 151 | EXPECT_TRUE(shelf_widget()->IsActive()); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 152 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 153 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 154 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 155 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 156 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 157 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 158 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
[email protected] | f3c7b25 | 2012-02-27 12:17:54 | [diff] [blame] | 159 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 160 | } |
| 161 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 162 | TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 163 | SetUpTrayFocusCycle(); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 164 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 165 | InstallFocusCycleOnShelf(); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 166 | |
| 167 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 168 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 169 | wm::ActivateWindow(window0.get()); |
| 170 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 171 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 172 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 173 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 174 | EXPECT_TRUE(shelf_widget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 175 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 176 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 177 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 178 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 179 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 180 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 181 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 182 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 183 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 184 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 185 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 186 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 187 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 188 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 189 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 190 | EXPECT_TRUE(shelf_widget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 191 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 192 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 193 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 194 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 195 | } |
| 196 | |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 197 | TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 198 | SetUpTrayFocusCycle(); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 199 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 200 | InstallFocusCycleOnShelf(); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 201 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 202 | // Add the shelf and focus it. |
| 203 | focus_cycler()->FocusWidget(shelf_widget()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 204 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 205 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 206 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 207 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 208 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 209 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 210 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 211 | EXPECT_TRUE(shelf_widget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 212 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 213 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 214 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 215 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 216 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 217 | // Cycle focus to the shelf. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 218 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 219 | EXPECT_TRUE(shelf_widget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 220 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 221 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 222 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 223 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | ce711ac | 2012-06-14 07:05:41 | [diff] [blame] | 224 | } |
| 225 | |
[email protected] | fba1eb2 | 2014-03-12 21:12:50 | [diff] [blame] | 226 | // 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] | 227 | TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 228 | SetUpTrayFocusCycle(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 229 | InstallFocusCycleOnShelf(); |
| 230 | shelf_widget()->Hide(); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 231 | |
[email protected] | fba1eb2 | 2014-03-12 21:12:50 | [diff] [blame] | 232 | // Create two test windows. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 233 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 234 | std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
[email protected] | fba1eb2 | 2014-03-12 21:12:50 | [diff] [blame] | 235 | wm::ActivateWindow(window1.get()); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 236 | wm::ActivateWindow(window0.get()); |
| 237 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 238 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 239 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 240 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 241 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 242 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 243 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 244 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 245 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
[email protected] | fba1eb2 | 2014-03-12 21:12:50 | [diff] [blame] | 246 | |
| 247 | // Cycle focus to the status area. |
| 248 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 249 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 250 | } |
| 251 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 252 | TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 253 | SetUpTrayFocusCycle(); |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 254 | InstallFocusCycleOnShelf(); |
| 255 | shelf_widget()->Hide(); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 256 | |
| 257 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 258 | std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 259 | wm::ActivateWindow(window0.get()); |
| 260 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 261 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 262 | // Cycle focus to the status area. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 263 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 264 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 265 | |
[email protected] | 478c6c3 | 2013-03-09 02:50:58 | [diff] [blame] | 266 | // Cycle focus to the browser. |
[email protected] | eb5a0ab | 2012-10-20 00:50:25 | [diff] [blame] | 267 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
[email protected] | 057dc575 | 2012-03-06 23:59:31 | [diff] [blame] | 268 | EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 269 | } |
| 270 | |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 271 | TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) { |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 272 | SetUpTrayFocusCycle(); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 273 | |
| 274 | InstallFocusCycleOnShelf(); |
| 275 | |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 276 | std::unique_ptr<PanedWidgetDelegate> test_widget_delegate; |
| 277 | std::unique_ptr<views::Widget> browser_widget(new views::Widget); |
[email protected] | 464a001 | 2013-11-12 18:22:44 | [diff] [blame] | 278 | test_widget_delegate.reset(new PanedWidgetDelegate(browser_widget.get())); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 279 | views::Widget::InitParams widget_params( |
| 280 | views::Widget::InitParams::TYPE_WINDOW); |
| 281 | widget_params.context = CurrentContext(); |
[email protected] | 464a001 | 2013-11-12 18:22:44 | [diff] [blame] | 282 | widget_params.delegate = test_widget_delegate.get(); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 283 | widget_params.ownership = |
| 284 | views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 285 | browser_widget->Init(widget_params); |
| 286 | browser_widget->Show(); |
| 287 | |
| 288 | aura::Window* browser_window = browser_widget->GetNativeView(); |
| 289 | |
| 290 | views::View* root_view = browser_widget->GetRootView(); |
| 291 | |
| 292 | views::AccessiblePaneView* pane1 = new views::AccessiblePaneView(); |
| 293 | root_view->AddChildView(pane1); |
| 294 | |
| 295 | views::View* view1 = new views::View; |
karandeepb | e7ad02a | 2016-04-27 23:57:22 | [diff] [blame] | 296 | view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 297 | pane1->AddChildView(view1); |
| 298 | |
| 299 | views::View* view2 = new views::View; |
karandeepb | e7ad02a | 2016-04-27 23:57:22 | [diff] [blame] | 300 | view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 301 | pane1->AddChildView(view2); |
| 302 | |
| 303 | views::AccessiblePaneView* pane2 = new views::AccessiblePaneView(); |
| 304 | root_view->AddChildView(pane2); |
| 305 | |
| 306 | views::View* view3 = new views::View; |
karandeepb | e7ad02a | 2016-04-27 23:57:22 | [diff] [blame] | 307 | view3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 308 | pane2->AddChildView(view3); |
| 309 | |
| 310 | views::View* view4 = new views::View; |
karandeepb | e7ad02a | 2016-04-27 23:57:22 | [diff] [blame] | 311 | view4->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 312 | pane2->AddChildView(view4); |
| 313 | |
| 314 | std::vector<views::View*> panes; |
| 315 | panes.push_back(pane1); |
| 316 | panes.push_back(pane2); |
| 317 | |
| 318 | test_widget_delegate->SetAccessiblePanes(panes); |
| 319 | |
| 320 | views::FocusManager* focus_manager = browser_widget->GetFocusManager(); |
| 321 | |
| 322 | // Cycle focus to the status area. |
| 323 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 324 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 325 | |
| 326 | // Cycle focus to the shelf. |
| 327 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 328 | EXPECT_TRUE(shelf_widget()->IsActive()); |
| 329 | |
| 330 | // Cycle focus to the first pane in the browser. |
| 331 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 332 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 333 | EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 334 | |
| 335 | // Cycle focus to the second pane in the browser. |
| 336 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 337 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 338 | EXPECT_EQ(focus_manager->GetFocusedView(), view3); |
| 339 | |
| 340 | // Cycle focus back to the status area. |
| 341 | focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 342 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 343 | |
| 344 | // Reverse direction - back to the second pane in the browser. |
| 345 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 346 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 347 | EXPECT_EQ(focus_manager->GetFocusedView(), view3); |
| 348 | |
| 349 | // Back to the first pane in the browser. |
| 350 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 351 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 352 | EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 353 | |
| 354 | // Back to the shelf. |
| 355 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 356 | EXPECT_TRUE(shelf_widget()->IsActive()); |
| 357 | |
| 358 | // Back to the status area. |
| 359 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
warx | 7f397419 | 2016-06-25 00:12:56 | [diff] [blame] | 360 | EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive()); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 361 | |
| 362 | // Pressing "Escape" while on the status area should |
| 363 | // deactivate it, and activate the browser window. |
jamescook | 26f3209 | 2016-06-17 04:26:52 | [diff] [blame] | 364 | ui::test::EventGenerator& event_generator = GetEventGenerator(); |
[email protected] | 242aa4f | 2013-04-30 01:04:08 | [diff] [blame] | 365 | event_generator.PressKey(ui::VKEY_ESCAPE, 0); |
| 366 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 367 | EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 368 | |
| 369 | // Similarly, pressing "Escape" while on the shelf. |
| 370 | // should do the same thing. |
| 371 | focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 372 | EXPECT_TRUE(shelf_widget()->IsActive()); |
| 373 | event_generator.PressKey(ui::VKEY_ESCAPE, 0); |
| 374 | EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 375 | EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 376 | } |
| 377 | |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 378 | // Test that when the shelf widget & status area widget are removed, they should |
| 379 | // also be removed from focus cycler. |
| 380 | TEST_F(FocusCyclerTest, RemoveWidgetOnDisplayRemoved) { |
| 381 | // Two displays are added, so two shelf widgets and two status area widgets |
| 382 | // are added to focus cycler. |
| 383 | UpdateDisplay("800x800, 500x500"); |
| 384 | // Remove one display. Its shelf widget and status area widget should also be |
| 385 | // removed from focus cycler. |
| 386 | UpdateDisplay("800x800"); |
| 387 | |
| 388 | // Create a single test window. |
dcheng | a9454747 | 2016-04-08 08:41:11 | [diff] [blame] | 389 | std::unique_ptr<Window> window(CreateTestWindowInShellWithId(0)); |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 390 | wm::ActivateWindow(window.get()); |
| 391 | EXPECT_TRUE(wm::IsActiveWindow(window.get())); |
| 392 | |
| 393 | // Cycle focus to the status area. |
jamescook | 26f3209 | 2016-06-17 04:26:52 | [diff] [blame] | 394 | WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 395 | EXPECT_FALSE(wm::IsActiveWindow(window.get())); |
| 396 | |
| 397 | // Cycle focus to the shelf. |
jamescook | 26f3209 | 2016-06-17 04:26:52 | [diff] [blame] | 398 | WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 399 | |
| 400 | // Cycle focus should go back to the browser. |
jamescook | 26f3209 | 2016-06-17 04:26:52 | [diff] [blame] | 401 | WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
xdai | 063763f | 2015-09-29 00:09:07 | [diff] [blame] | 402 | EXPECT_TRUE(wm::IsActiveWindow(window.get())); |
| 403 | } |
| 404 | |
[email protected] | df1c986 | 2012-02-27 10:37:31 | [diff] [blame] | 405 | } // namespace test |
| 406 | } // namespace ash |