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