blob: 695896420aacf4fd3f7512a2e3353052812ebfe1 [file] [log] [blame]
[email protected]df1c9862012-02-27 10:37:311// 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 Cookb0bf8e82017-04-09 17:01:445#include "ash/focus_cycler.h"
[email protected]df1c9862012-02-27 10:37:316
dchenga94547472016-04-08 08:41:117#include <memory>
8
James Cook840177e2017-05-25 02:20:019#include "ash/shelf/shelf.h"
Manu Cornete11c3c352019-07-31 06:13:4110#include "ash/shelf/shelf_focus_cycler.h"
11#include "ash/shelf/shelf_navigation_widget.h"
James Cookb0bf8e82017-04-09 17:01:4412#include "ash/shelf/shelf_widget.h"
sky79fa34712017-03-20 23:46:4713#include "ash/shell.h"
James Cookb0bf8e82017-04-09 17:01:4414#include "ash/system/status_area_widget.h"
15#include "ash/system/status_area_widget_delegate.h"
[email protected]df1c9862012-02-27 10:37:3116#include "ash/test/ash_test_base.h"
[email protected]864b58552013-12-19 04:19:3817#include "ash/wm/window_util.h"
[email protected]df1c9862012-02-27 10:37:3118#include "ui/aura/test/test_windows.h"
19#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2620#include "ui/aura/window_event_dispatcher.h"
[email protected]73c9fd02014-07-28 01:48:5221#include "ui/events/test/event_generator.h"
[email protected]242aa4f2013-04-30 01:04:0822#include "ui/views/accessible_pane_view.h"
[email protected]df1c9862012-02-27 10:37:3123#include "ui/views/controls/button/menu_button.h"
24#include "ui/views/widget/widget.h"
25
26namespace ash {
[email protected]df1c9862012-02-27 10:37:3127
[email protected]df1c9862012-02-27 10:37:3128using aura::Window;
[email protected]df1c9862012-02-27 10:37:3129
[email protected]8676f0472012-03-29 20:30:1230namespace {
31
[email protected]093b8d642014-04-03 20:59:2832StatusAreaWidgetDelegate* GetStatusAreaWidgetDelegate(views::Widget* widget) {
33 return static_cast<StatusAreaWidgetDelegate*>(widget->GetContentsView());
[email protected]8676f0472012-03-29 20:30:1234}
35
[email protected]242aa4f2013-04-30 01:04:0836class 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.
dcheng222b9c72015-01-16 00:48:0145 void GetAccessiblePanes(std::vector<views::View*>* panes) override {
jamescookb8dcef522016-06-25 14:42:5546 std::copy(accessible_panes_.begin(), accessible_panes_.end(),
[email protected]242aa4f2013-04-30 01:04:0847 std::back_inserter(*panes));
48 }
Nico Weber1ed20762019-02-25 19:37:5849 views::Widget* GetWidget() override { return widget_; }
dcheng222b9c72015-01-16 00:48:0150 const views::Widget* GetWidget() const override { return widget_; }
[email protected]242aa4f2013-04-30 01:04:0851
52 private:
53 views::Widget* widget_;
54 std::vector<views::View*> accessible_panes_;
55};
56
[email protected]8676f0472012-03-29 20:30:1257} // namespace
58
[email protected]eb5a0ab2012-10-20 00:50:2559class FocusCyclerTest : public AshTestBase {
60 public:
Chris Watkinsc24daf62017-11-28 03:43:0961 FocusCyclerTest() = default;
[email protected]df1c9862012-02-27 10:37:3162
dcheng222b9c72015-01-16 00:48:0163 void SetUp() override {
[email protected]eb5a0ab2012-10-20 00:50:2564 AshTestBase::SetUp();
[email protected]df1c9862012-02-27 10:37:3165
[email protected]eb5a0ab2012-10-20 00:50:2566 focus_cycler_.reset(new FocusCycler());
[email protected]eb5a0ab2012-10-20 00:50:2567 }
68
dcheng222b9c72015-01-16 00:48:0169 void TearDown() override {
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:2370 GetStatusAreaWidgetDelegate(GetPrimaryStatusAreaWidget())
warx7f3974192016-06-25 00:12:5671 ->SetFocusCyclerForTesting(nullptr);
[email protected]eb5a0ab2012-10-20 00:50:2572
Manu Cornetaef0c112019-08-19 19:35:2473 shelf_widget()->hotseat_widget()->SetFocusCycler(nullptr);
[email protected]eb5a0ab2012-10-20 00:50:2574
75 focus_cycler_.reset();
76
77 AshTestBase::TearDown();
78 }
79
80 protected:
jamescookfe89c292017-03-10 18:03:2381 // Setup the system tray focus cycler.
warx7f3974192016-06-25 00:12:5682 void SetUpTrayFocusCycle() {
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:2383 views::Widget* system_tray_widget = GetPrimaryStatusAreaWidget();
warx7f3974192016-06-25 00:12:5684 ASSERT_TRUE(system_tray_widget);
85 focus_cycler_->AddWidget(system_tray_widget);
86 GetStatusAreaWidgetDelegate(system_tray_widget)
87 ->SetFocusCyclerForTesting(focus_cycler());
[email protected]eb5a0ab2012-10-20 00:50:2588 }
89
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:2390 views::Widget* GetPrimaryStatusAreaWidget() {
91 return GetPrimaryShelf()->GetStatusAreaWidget();
92 }
93
[email protected]eb5a0ab2012-10-20 00:50:2594 FocusCycler* focus_cycler() { return focus_cycler_.get(); }
95
jamescook1cad77e92016-08-31 00:02:2696 ShelfWidget* shelf_widget() { return GetPrimaryShelf()->shelf_widget(); }
[email protected]eb5a0ab2012-10-20 00:50:2597
[email protected]478c6c32013-03-09 02:50:5898 void InstallFocusCycleOnShelf() {
99 // Add the shelf.
Manu Cornetaef0c112019-08-19 19:35:24100 shelf_widget()->hotseat_widget()->SetFocusCycler(focus_cycler());
[email protected]eb5a0ab2012-10-20 00:50:25101 }
102
103 private:
dchenga94547472016-04-08 08:41:11104 std::unique_ptr<FocusCycler> focus_cycler_;
[email protected]eb5a0ab2012-10-20 00:50:25105
106 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest);
107};
108
109TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) {
[email protected]df1c9862012-02-27 10:37:31110 // Create a single test window.
dchenga94547472016-04-08 08:41:11111 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54112 wm::ActivateWindow(window0.get());
113 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31114
115 // Cycle the window
[email protected]eb5a0ab2012-10-20 00:50:25116 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]f3c7b252012-02-27 12:17:54117 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31118}
119
[email protected]eb5a0ab2012-10-20 00:50:25120TEST_F(FocusCyclerTest, CycleFocusForward) {
warx7f3974192016-06-25 00:12:56121 SetUpTrayFocusCycle();
[email protected]df1c9862012-02-27 10:37:31122
[email protected]478c6c32013-03-09 02:50:58123 InstallFocusCycleOnShelf();
[email protected]df1c9862012-02-27 10:37:31124
125 // Create a single test window.
dchenga94547472016-04-08 08:41:11126 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54127 wm::ActivateWindow(window0.get());
128 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31129
[email protected]478c6c32013-03-09 02:50:58130 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25131 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23132 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31133
[email protected]478c6c32013-03-09 02:50:58134 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25135 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Manu Cornetaef0c112019-08-19 19:35:24136 EXPECT_TRUE(shelf_widget()->hotseat_widget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31137
[email protected]478c6c32013-03-09 02:50:58138 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25139 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]f3c7b252012-02-27 12:17:54140 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31141}
142
[email protected]eb5a0ab2012-10-20 00:50:25143TEST_F(FocusCyclerTest, CycleFocusBackward) {
warx7f3974192016-06-25 00:12:56144 SetUpTrayFocusCycle();
[email protected]df1c9862012-02-27 10:37:31145
[email protected]478c6c32013-03-09 02:50:58146 InstallFocusCycleOnShelf();
[email protected]df1c9862012-02-27 10:37:31147
148 // Create a single test window.
dchenga94547472016-04-08 08:41:11149 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54150 wm::ActivateWindow(window0.get());
151 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31152
[email protected]478c6c32013-03-09 02:50:58153 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25154 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Manu Cornetaef0c112019-08-19 19:35:24155 EXPECT_TRUE(shelf_widget()->hotseat_widget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31156
[email protected]478c6c32013-03-09 02:50:58157 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25158 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23159 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31160
[email protected]478c6c32013-03-09 02:50:58161 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25162 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]f3c7b252012-02-27 12:17:54163 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31164}
165
[email protected]eb5a0ab2012-10-20 00:50:25166TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
warx7f3974192016-06-25 00:12:56167 SetUpTrayFocusCycle();
[email protected]ce711ac2012-06-14 07:05:41168
[email protected]478c6c32013-03-09 02:50:58169 InstallFocusCycleOnShelf();
[email protected]ce711ac2012-06-14 07:05:41170
171 // Create a single test window.
dchenga94547472016-04-08 08:41:11172 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]ce711ac2012-06-14 07:05:41173 wm::ActivateWindow(window0.get());
174 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
175
[email protected]478c6c32013-03-09 02:50:58176 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25177 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Manu Cornetaef0c112019-08-19 19:35:24178 EXPECT_TRUE(shelf_widget()->hotseat_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41179
[email protected]478c6c32013-03-09 02:50:58180 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25181 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23182 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41183
[email protected]478c6c32013-03-09 02:50:58184 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25185 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]ce711ac2012-06-14 07:05:41186 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
187
[email protected]478c6c32013-03-09 02:50:58188 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25189 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23190 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41191
[email protected]478c6c32013-03-09 02:50:58192 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25193 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Manu Cornetaef0c112019-08-19 19:35:24194 EXPECT_TRUE(shelf_widget()->hotseat_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41195
[email protected]478c6c32013-03-09 02:50:58196 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25197 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]ce711ac2012-06-14 07:05:41198 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
199}
200
[email protected]eb5a0ab2012-10-20 00:50:25201TEST_F(FocusCyclerTest, CycleFocusNoBrowser) {
warx7f3974192016-06-25 00:12:56202 SetUpTrayFocusCycle();
[email protected]ce711ac2012-06-14 07:05:41203
[email protected]478c6c32013-03-09 02:50:58204 InstallFocusCycleOnShelf();
[email protected]ce711ac2012-06-14 07:05:41205
[email protected]478c6c32013-03-09 02:50:58206 // Add the shelf and focus it.
Manu Cornetaef0c112019-08-19 19:35:24207 focus_cycler()->FocusWidget(shelf_widget()->hotseat_widget());
[email protected]ce711ac2012-06-14 07:05:41208
[email protected]478c6c32013-03-09 02:50:58209 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25210 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23211 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41212
[email protected]478c6c32013-03-09 02:50:58213 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25214 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Manu Cornetaef0c112019-08-19 19:35:24215 EXPECT_TRUE(shelf_widget()->hotseat_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41216
[email protected]478c6c32013-03-09 02:50:58217 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25218 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23219 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41220
[email protected]478c6c32013-03-09 02:50:58221 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25222 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Manu Cornetaef0c112019-08-19 19:35:24223 EXPECT_TRUE(shelf_widget()->hotseat_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41224
[email protected]478c6c32013-03-09 02:50:58225 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25226 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23227 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41228}
229
[email protected]fba1eb22014-03-12 21:12:50230// Tests that focus cycles from the active browser to the status area and back.
[email protected]478c6c32013-03-09 02:50:58231TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) {
warx7f3974192016-06-25 00:12:56232 SetUpTrayFocusCycle();
[email protected]478c6c32013-03-09 02:50:58233 InstallFocusCycleOnShelf();
Manu Cornetaef0c112019-08-19 19:35:24234 shelf_widget()->hotseat_widget()->Hide();
[email protected]057dc5752012-03-06 23:59:31235
[email protected]fba1eb22014-03-12 21:12:50236 // Create two test windows.
dchenga94547472016-04-08 08:41:11237 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
238 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1));
[email protected]fba1eb22014-03-12 21:12:50239 wm::ActivateWindow(window1.get());
[email protected]057dc5752012-03-06 23:59:31240 wm::ActivateWindow(window0.get());
241 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
242
[email protected]478c6c32013-03-09 02:50:58243 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25244 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23245 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31246
[email protected]478c6c32013-03-09 02:50:58247 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25248 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]057dc5752012-03-06 23:59:31249 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]fba1eb22014-03-12 21:12:50250
251 // Cycle focus to the status area.
252 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23253 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31254}
255
[email protected]478c6c32013-03-09 02:50:58256TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) {
warx7f3974192016-06-25 00:12:56257 SetUpTrayFocusCycle();
[email protected]478c6c32013-03-09 02:50:58258 InstallFocusCycleOnShelf();
Manu Cornetaef0c112019-08-19 19:35:24259 shelf_widget()->hotseat_widget()->Hide();
[email protected]057dc5752012-03-06 23:59:31260
261 // Create a single test window.
dchenga94547472016-04-08 08:41:11262 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]057dc5752012-03-06 23:59:31263 wm::ActivateWindow(window0.get());
264 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
265
[email protected]478c6c32013-03-09 02:50:58266 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25267 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23268 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31269
[email protected]478c6c32013-03-09 02:50:58270 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25271 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]057dc5752012-03-06 23:59:31272 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
273}
274
[email protected]242aa4f2013-04-30 01:04:08275TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) {
warx7f3974192016-06-25 00:12:56276 SetUpTrayFocusCycle();
[email protected]242aa4f2013-04-30 01:04:08277
278 InstallFocusCycleOnShelf();
279
dchenga94547472016-04-08 08:41:11280 std::unique_ptr<PanedWidgetDelegate> test_widget_delegate;
281 std::unique_ptr<views::Widget> browser_widget(new views::Widget);
[email protected]464a0012013-11-12 18:22:44282 test_widget_delegate.reset(new PanedWidgetDelegate(browser_widget.get()));
[email protected]242aa4f2013-04-30 01:04:08283 views::Widget::InitParams widget_params(
284 views::Widget::InitParams::TYPE_WINDOW);
[email protected]464a0012013-11-12 18:22:44285 widget_params.delegate = test_widget_delegate.get();
[email protected]242aa4f2013-04-30 01:04:08286 widget_params.ownership =
287 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
Scott Violet786483c2018-08-10 20:47:29288 widget_params.context = CurrentContext();
Ahmed Fakhry32f3c452019-08-01 16:36:34289 browser_widget->Init(std::move(widget_params));
[email protected]242aa4f2013-04-30 01:04:08290 browser_widget->Show();
291
292 aura::Window* browser_window = browser_widget->GetNativeView();
293
294 views::View* root_view = browser_widget->GetRootView();
295
Manu Cornete11c3c352019-07-31 06:13:41296 // pane1 contains view1 and view2, pane2 contains view3 and view4.
[email protected]242aa4f2013-04-30 01:04:08297 views::AccessiblePaneView* pane1 = new views::AccessiblePaneView();
298 root_view->AddChildView(pane1);
299
300 views::View* view1 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22301 view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08302 pane1->AddChildView(view1);
303
304 views::View* view2 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22305 view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08306 pane1->AddChildView(view2);
307
308 views::AccessiblePaneView* pane2 = new views::AccessiblePaneView();
309 root_view->AddChildView(pane2);
310
311 views::View* view3 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22312 view3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08313 pane2->AddChildView(view3);
314
315 views::View* view4 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22316 view4->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08317 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 Ohkubo2b2fe2d2018-06-01 17:01:23329 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08330
331 // Cycle focus to the shelf.
332 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Manu Cornetaef0c112019-08-19 19:35:24333 EXPECT_TRUE(shelf_widget()->hotseat_widget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08334
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 Ohkubo2b2fe2d2018-06-01 17:01:23347 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08348
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 Cornetaef0c112019-08-19 19:35:24361 EXPECT_TRUE(shelf_widget()->hotseat_widget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08362
363 // Back to the status area.
364 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23365 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08366
367 // Pressing "Escape" while on the status area should
368 // deactivate it, and activate the browser window.
Darren Shen31fb6ead2018-07-04 04:59:04369 ui::test::EventGenerator* event_generator = GetEventGenerator();
370 event_generator->PressKey(ui::VKEY_ESCAPE, 0);
[email protected]242aa4f2013-04-30 01:04:08371 EXPECT_TRUE(wm::IsActiveWindow(browser_window));
372 EXPECT_EQ(focus_manager->GetFocusedView(), view1);
373
Manu Cornete11c3c352019-07-31 06:13:41374 // Similarly, pressing "Escape" while on the shelf should do the same thing.
375 // Focus the navigation widget directly because the shelf has no apps here.
376 GetPrimaryShelf()->shelf_focus_cycler()->FocusNavigation(false /* last */);
377 EXPECT_TRUE(shelf_widget()->navigation_widget()->IsActive());
Darren Shen31fb6ead2018-07-04 04:59:04378 event_generator->PressKey(ui::VKEY_ESCAPE, 0);
[email protected]242aa4f2013-04-30 01:04:08379 EXPECT_TRUE(wm::IsActiveWindow(browser_window));
380 EXPECT_EQ(focus_manager->GetFocusedView(), view1);
381}
382
xdai063763f2015-09-29 00:09:07383// Test that when the shelf widget & status area widget are removed, they should
384// also be removed from focus cycler.
385TEST_F(FocusCyclerTest, RemoveWidgetOnDisplayRemoved) {
386 // Two displays are added, so two shelf widgets and two status area widgets
387 // are added to focus cycler.
388 UpdateDisplay("800x800, 500x500");
389 // Remove one display. Its shelf widget and status area widget should also be
390 // removed from focus cycler.
391 UpdateDisplay("800x800");
392
393 // Create a single test window.
dchenga94547472016-04-08 08:41:11394 std::unique_ptr<Window> window(CreateTestWindowInShellWithId(0));
xdai063763f2015-09-29 00:09:07395 wm::ActivateWindow(window.get());
396 EXPECT_TRUE(wm::IsActiveWindow(window.get()));
397
Manu Cornete11c3c352019-07-31 06:13:41398 // Cycle focus to the navigation widget.
399 Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Manu Cornetaef0c112019-08-19 19:35:24400 EXPECT_TRUE(shelf_widget()->navigation_widget()->IsActive());
Manu Cornete11c3c352019-07-31 06:13:41401
Manu Cornetaef0c112019-08-19 19:35:24402 // Cycle focus to the status area.
sky79fa34712017-03-20 23:46:47403 Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Manu Cornetaef0c112019-08-19 19:35:24404 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
405
406 // Cycle focus to the hotseat widget.
407 Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
408 EXPECT_TRUE(shelf_widget()->hotseat_widget()->IsActive());
xdai063763f2015-09-29 00:09:07409
410 // Cycle focus should go back to the browser.
sky79fa34712017-03-20 23:46:47411 Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07412 EXPECT_TRUE(wm::IsActiveWindow(window.get()));
413}
414
[email protected]df1c9862012-02-27 10:37:31415} // namespace ash