blob: ef32f009ef8a43504f23b79fb72e3b3443227206 [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"
James Cookb0bf8e82017-04-09 17:01:4410#include "ash/shelf/shelf_widget.h"
sky79fa34712017-03-20 23:46:4711#include "ash/shell.h"
James Cookb0bf8e82017-04-09 17:01:4412#include "ash/system/status_area_widget.h"
13#include "ash/system/status_area_widget_delegate.h"
14#include "ash/system/tray/system_tray.h"
[email protected]df1c9862012-02-27 10:37:3115#include "ash/test/ash_test_base.h"
[email protected]864b58552013-12-19 04:19:3816#include "ash/wm/window_util.h"
[email protected]df1c9862012-02-27 10:37:3117#include "ui/aura/test/test_windows.h"
18#include "ui/aura/window.h"
[email protected]fcc51c952014-02-21 21:31:2619#include "ui/aura/window_event_dispatcher.h"
[email protected]73c9fd02014-07-28 01:48:5220#include "ui/events/test/event_generator.h"
[email protected]242aa4f2013-04-30 01:04:0821#include "ui/views/accessible_pane_view.h"
[email protected]df1c9862012-02-27 10:37:3122#include "ui/views/controls/button/menu_button.h"
23#include "ui/views/widget/widget.h"
24
25namespace ash {
[email protected]df1c9862012-02-27 10:37:3126
[email protected]df1c9862012-02-27 10:37:3127using aura::Window;
[email protected]df1c9862012-02-27 10:37:3128
[email protected]8676f0472012-03-29 20:30:1229namespace {
30
[email protected]093b8d642014-04-03 20:59:2831StatusAreaWidgetDelegate* GetStatusAreaWidgetDelegate(views::Widget* widget) {
32 return static_cast<StatusAreaWidgetDelegate*>(widget->GetContentsView());
[email protected]8676f0472012-03-29 20:30:1233}
34
[email protected]242aa4f2013-04-30 01:04:0835class PanedWidgetDelegate : public views::WidgetDelegate {
36 public:
37 PanedWidgetDelegate(views::Widget* widget) : widget_(widget) {}
38
39 void SetAccessiblePanes(const std::vector<views::View*>& panes) {
40 accessible_panes_ = panes;
41 }
42
43 // views::WidgetDelegate.
dcheng222b9c72015-01-16 00:48:0144 void GetAccessiblePanes(std::vector<views::View*>* panes) override {
jamescookb8dcef522016-06-25 14:42:5545 std::copy(accessible_panes_.begin(), accessible_panes_.end(),
[email protected]242aa4f2013-04-30 01:04:0846 std::back_inserter(*panes));
47 }
dcheng222b9c72015-01-16 00:48:0148 views::Widget* GetWidget() override { return widget_; };
49 const views::Widget* GetWidget() const override { return widget_; }
[email protected]242aa4f2013-04-30 01:04:0850
51 private:
52 views::Widget* widget_;
53 std::vector<views::View*> accessible_panes_;
54};
55
[email protected]8676f0472012-03-29 20:30:1256} // namespace
57
[email protected]eb5a0ab2012-10-20 00:50:2558class FocusCyclerTest : public AshTestBase {
59 public:
Chris Watkinsc24daf62017-11-28 03:43:0960 FocusCyclerTest() = default;
[email protected]df1c9862012-02-27 10:37:3161
dcheng222b9c72015-01-16 00:48:0162 void SetUp() override {
[email protected]eb5a0ab2012-10-20 00:50:2563 AshTestBase::SetUp();
[email protected]df1c9862012-02-27 10:37:3164
[email protected]eb5a0ab2012-10-20 00:50:2565 focus_cycler_.reset(new FocusCycler());
[email protected]eb5a0ab2012-10-20 00:50:2566 }
67
dcheng222b9c72015-01-16 00:48:0168 void TearDown() override {
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:2369 GetStatusAreaWidgetDelegate(GetPrimaryStatusAreaWidget())
warx7f3974192016-06-25 00:12:5670 ->SetFocusCyclerForTesting(nullptr);
[email protected]eb5a0ab2012-10-20 00:50:2571
warx7f3974192016-06-25 00:12:5672 shelf_widget()->SetFocusCycler(nullptr);
[email protected]eb5a0ab2012-10-20 00:50:2573
74 focus_cycler_.reset();
75
76 AshTestBase::TearDown();
77 }
78
79 protected:
jamescookfe89c292017-03-10 18:03:2380 // Setup the system tray focus cycler.
warx7f3974192016-06-25 00:12:5681 void SetUpTrayFocusCycle() {
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:2382 views::Widget* system_tray_widget = GetPrimaryStatusAreaWidget();
warx7f3974192016-06-25 00:12:5683 ASSERT_TRUE(system_tray_widget);
84 focus_cycler_->AddWidget(system_tray_widget);
85 GetStatusAreaWidgetDelegate(system_tray_widget)
86 ->SetFocusCyclerForTesting(focus_cycler());
[email protected]eb5a0ab2012-10-20 00:50:2587 }
88
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:2389 views::Widget* GetPrimaryStatusAreaWidget() {
90 return GetPrimaryShelf()->GetStatusAreaWidget();
91 }
92
[email protected]eb5a0ab2012-10-20 00:50:2593 FocusCycler* focus_cycler() { return focus_cycler_.get(); }
94
jamescook1cad77e92016-08-31 00:02:2695 ShelfWidget* shelf_widget() { return GetPrimaryShelf()->shelf_widget(); }
[email protected]eb5a0ab2012-10-20 00:50:2596
[email protected]478c6c32013-03-09 02:50:5897 void InstallFocusCycleOnShelf() {
98 // Add the shelf.
99 shelf_widget()->SetFocusCycler(focus_cycler());
[email protected]eb5a0ab2012-10-20 00:50:25100 }
101
102 private:
dchenga94547472016-04-08 08:41:11103 std::unique_ptr<FocusCycler> focus_cycler_;
[email protected]eb5a0ab2012-10-20 00:50:25104
105 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest);
106};
107
108TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) {
[email protected]df1c9862012-02-27 10:37:31109 // Create a single test window.
dchenga94547472016-04-08 08:41:11110 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54111 wm::ActivateWindow(window0.get());
112 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31113
114 // Cycle the window
[email protected]eb5a0ab2012-10-20 00:50:25115 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]f3c7b252012-02-27 12:17:54116 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31117}
118
[email protected]eb5a0ab2012-10-20 00:50:25119TEST_F(FocusCyclerTest, CycleFocusForward) {
warx7f3974192016-06-25 00:12:56120 SetUpTrayFocusCycle();
[email protected]df1c9862012-02-27 10:37:31121
[email protected]478c6c32013-03-09 02:50:58122 InstallFocusCycleOnShelf();
[email protected]df1c9862012-02-27 10:37:31123
124 // Create a single test window.
dchenga94547472016-04-08 08:41:11125 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54126 wm::ActivateWindow(window0.get());
127 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31128
[email protected]478c6c32013-03-09 02:50:58129 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25130 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23131 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31132
[email protected]478c6c32013-03-09 02:50:58133 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25134 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]478c6c32013-03-09 02:50:58135 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31136
[email protected]478c6c32013-03-09 02:50:58137 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25138 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]f3c7b252012-02-27 12:17:54139 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31140}
141
[email protected]eb5a0ab2012-10-20 00:50:25142TEST_F(FocusCyclerTest, CycleFocusBackward) {
warx7f3974192016-06-25 00:12:56143 SetUpTrayFocusCycle();
[email protected]df1c9862012-02-27 10:37:31144
[email protected]478c6c32013-03-09 02:50:58145 InstallFocusCycleOnShelf();
[email protected]df1c9862012-02-27 10:37:31146
147 // Create a single test window.
dchenga94547472016-04-08 08:41:11148 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54149 wm::ActivateWindow(window0.get());
150 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31151
[email protected]478c6c32013-03-09 02:50:58152 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25153 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]478c6c32013-03-09 02:50:58154 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31155
[email protected]478c6c32013-03-09 02:50:58156 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25157 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23158 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31159
[email protected]478c6c32013-03-09 02:50:58160 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25161 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]f3c7b252012-02-27 12:17:54162 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31163}
164
[email protected]eb5a0ab2012-10-20 00:50:25165TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
warx7f3974192016-06-25 00:12:56166 SetUpTrayFocusCycle();
[email protected]ce711ac2012-06-14 07:05:41167
[email protected]478c6c32013-03-09 02:50:58168 InstallFocusCycleOnShelf();
[email protected]ce711ac2012-06-14 07:05:41169
170 // Create a single test window.
dchenga94547472016-04-08 08:41:11171 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]ce711ac2012-06-14 07:05:41172 wm::ActivateWindow(window0.get());
173 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
174
[email protected]478c6c32013-03-09 02:50:58175 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25176 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]478c6c32013-03-09 02:50:58177 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41178
[email protected]478c6c32013-03-09 02:50:58179 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25180 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23181 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41182
[email protected]478c6c32013-03-09 02:50:58183 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25184 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]ce711ac2012-06-14 07:05:41185 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
186
[email protected]478c6c32013-03-09 02:50:58187 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25188 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23189 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41190
[email protected]478c6c32013-03-09 02:50:58191 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25192 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]478c6c32013-03-09 02:50:58193 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41194
[email protected]478c6c32013-03-09 02:50:58195 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25196 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]ce711ac2012-06-14 07:05:41197 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
198}
199
[email protected]eb5a0ab2012-10-20 00:50:25200TEST_F(FocusCyclerTest, CycleFocusNoBrowser) {
warx7f3974192016-06-25 00:12:56201 SetUpTrayFocusCycle();
[email protected]ce711ac2012-06-14 07:05:41202
[email protected]478c6c32013-03-09 02:50:58203 InstallFocusCycleOnShelf();
[email protected]ce711ac2012-06-14 07:05:41204
[email protected]478c6c32013-03-09 02:50:58205 // Add the shelf and focus it.
206 focus_cycler()->FocusWidget(shelf_widget());
[email protected]ce711ac2012-06-14 07:05:41207
[email protected]478c6c32013-03-09 02:50:58208 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25209 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23210 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41211
[email protected]478c6c32013-03-09 02:50:58212 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25213 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]478c6c32013-03-09 02:50:58214 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41215
[email protected]478c6c32013-03-09 02:50:58216 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25217 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23218 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41219
[email protected]478c6c32013-03-09 02:50:58220 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25221 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]478c6c32013-03-09 02:50:58222 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41223
[email protected]478c6c32013-03-09 02:50:58224 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25225 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23226 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41227}
228
[email protected]fba1eb22014-03-12 21:12:50229// Tests that focus cycles from the active browser to the status area and back.
[email protected]478c6c32013-03-09 02:50:58230TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) {
warx7f3974192016-06-25 00:12:56231 SetUpTrayFocusCycle();
[email protected]478c6c32013-03-09 02:50:58232 InstallFocusCycleOnShelf();
233 shelf_widget()->Hide();
[email protected]057dc5752012-03-06 23:59:31234
[email protected]fba1eb22014-03-12 21:12:50235 // Create two test windows.
dchenga94547472016-04-08 08:41:11236 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
237 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1));
[email protected]fba1eb22014-03-12 21:12:50238 wm::ActivateWindow(window1.get());
[email protected]057dc5752012-03-06 23:59:31239 wm::ActivateWindow(window0.get());
240 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
241
[email protected]478c6c32013-03-09 02:50:58242 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25243 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23244 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31245
[email protected]478c6c32013-03-09 02:50:58246 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25247 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]057dc5752012-03-06 23:59:31248 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]fba1eb22014-03-12 21:12:50249
250 // Cycle focus to the status area.
251 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23252 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31253}
254
[email protected]478c6c32013-03-09 02:50:58255TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) {
warx7f3974192016-06-25 00:12:56256 SetUpTrayFocusCycle();
[email protected]478c6c32013-03-09 02:50:58257 InstallFocusCycleOnShelf();
258 shelf_widget()->Hide();
[email protected]057dc5752012-03-06 23:59:31259
260 // Create a single test window.
dchenga94547472016-04-08 08:41:11261 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]057dc5752012-03-06 23:59:31262 wm::ActivateWindow(window0.get());
263 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
264
[email protected]478c6c32013-03-09 02:50:58265 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25266 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23267 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31268
[email protected]478c6c32013-03-09 02:50:58269 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25270 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]057dc5752012-03-06 23:59:31271 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
272}
273
[email protected]242aa4f2013-04-30 01:04:08274TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) {
warx7f3974192016-06-25 00:12:56275 SetUpTrayFocusCycle();
[email protected]242aa4f2013-04-30 01:04:08276
277 InstallFocusCycleOnShelf();
278
dchenga94547472016-04-08 08:41:11279 std::unique_ptr<PanedWidgetDelegate> test_widget_delegate;
280 std::unique_ptr<views::Widget> browser_widget(new views::Widget);
[email protected]464a0012013-11-12 18:22:44281 test_widget_delegate.reset(new PanedWidgetDelegate(browser_widget.get()));
[email protected]242aa4f2013-04-30 01:04:08282 views::Widget::InitParams widget_params(
283 views::Widget::InitParams::TYPE_WINDOW);
[email protected]464a0012013-11-12 18:22:44284 widget_params.delegate = test_widget_delegate.get();
[email protected]242aa4f2013-04-30 01:04:08285 widget_params.ownership =
286 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
Scott Violet786483c2018-08-10 20:47:29287 widget_params.context = CurrentContext();
[email protected]242aa4f2013-04-30 01:04:08288 browser_widget->Init(widget_params);
289 browser_widget->Show();
290
291 aura::Window* browser_window = browser_widget->GetNativeView();
292
293 views::View* root_view = browser_widget->GetRootView();
294
295 views::AccessiblePaneView* pane1 = new views::AccessiblePaneView();
296 root_view->AddChildView(pane1);
297
298 views::View* view1 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22299 view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08300 pane1->AddChildView(view1);
301
302 views::View* view2 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22303 view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08304 pane1->AddChildView(view2);
305
306 views::AccessiblePaneView* pane2 = new views::AccessiblePaneView();
307 root_view->AddChildView(pane2);
308
309 views::View* view3 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22310 view3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08311 pane2->AddChildView(view3);
312
313 views::View* view4 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22314 view4->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08315 pane2->AddChildView(view4);
316
317 std::vector<views::View*> panes;
318 panes.push_back(pane1);
319 panes.push_back(pane2);
320
321 test_widget_delegate->SetAccessiblePanes(panes);
322
323 views::FocusManager* focus_manager = browser_widget->GetFocusManager();
324
325 // Cycle focus to the status area.
326 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23327 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08328
329 // Cycle focus to the shelf.
330 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
331 EXPECT_TRUE(shelf_widget()->IsActive());
332
333 // Cycle focus to the first pane in the browser.
334 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
335 EXPECT_TRUE(wm::IsActiveWindow(browser_window));
336 EXPECT_EQ(focus_manager->GetFocusedView(), view1);
337
338 // Cycle focus to the second pane in the browser.
339 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
340 EXPECT_TRUE(wm::IsActiveWindow(browser_window));
341 EXPECT_EQ(focus_manager->GetFocusedView(), view3);
342
343 // Cycle focus back to the status area.
344 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23345 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08346
347 // Reverse direction - back to the second pane in the browser.
348 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
349 EXPECT_TRUE(wm::IsActiveWindow(browser_window));
350 EXPECT_EQ(focus_manager->GetFocusedView(), view3);
351
352 // Back to the first pane in the browser.
353 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
354 EXPECT_TRUE(wm::IsActiveWindow(browser_window));
355 EXPECT_EQ(focus_manager->GetFocusedView(), view1);
356
357 // Back to the shelf.
358 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
359 EXPECT_TRUE(shelf_widget()->IsActive());
360
361 // Back to the status area.
362 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
Tetsui Ohkubo2b2fe2d2018-06-01 17:01:23363 EXPECT_TRUE(GetPrimaryStatusAreaWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08364
365 // Pressing "Escape" while on the status area should
366 // deactivate it, and activate the browser window.
Darren Shen31fb6ead2018-07-04 04:59:04367 ui::test::EventGenerator* event_generator = GetEventGenerator();
368 event_generator->PressKey(ui::VKEY_ESCAPE, 0);
[email protected]242aa4f2013-04-30 01:04:08369 EXPECT_TRUE(wm::IsActiveWindow(browser_window));
370 EXPECT_EQ(focus_manager->GetFocusedView(), view1);
371
372 // Similarly, pressing "Escape" while on the shelf.
373 // should do the same thing.
374 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
375 EXPECT_TRUE(shelf_widget()->IsActive());
Darren Shen31fb6ead2018-07-04 04:59:04376 event_generator->PressKey(ui::VKEY_ESCAPE, 0);
[email protected]242aa4f2013-04-30 01:04:08377 EXPECT_TRUE(wm::IsActiveWindow(browser_window));
378 EXPECT_EQ(focus_manager->GetFocusedView(), view1);
379}
380
xdai063763f2015-09-29 00:09:07381// Test that when the shelf widget & status area widget are removed, they should
382// also be removed from focus cycler.
383TEST_F(FocusCyclerTest, RemoveWidgetOnDisplayRemoved) {
384 // Two displays are added, so two shelf widgets and two status area widgets
385 // are added to focus cycler.
386 UpdateDisplay("800x800, 500x500");
387 // Remove one display. Its shelf widget and status area widget should also be
388 // removed from focus cycler.
389 UpdateDisplay("800x800");
390
391 // Create a single test window.
dchenga94547472016-04-08 08:41:11392 std::unique_ptr<Window> window(CreateTestWindowInShellWithId(0));
xdai063763f2015-09-29 00:09:07393 wm::ActivateWindow(window.get());
394 EXPECT_TRUE(wm::IsActiveWindow(window.get()));
395
396 // Cycle focus to the status area.
sky79fa34712017-03-20 23:46:47397 Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07398 EXPECT_FALSE(wm::IsActiveWindow(window.get()));
399
400 // Cycle focus to the shelf.
sky79fa34712017-03-20 23:46:47401 Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07402
403 // Cycle focus should go back to the browser.
sky79fa34712017-03-20 23:46:47404 Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07405 EXPECT_TRUE(wm::IsActiveWindow(window.get()));
406}
407
[email protected]df1c9862012-02-27 10:37:31408} // namespace ash