blob: 1c42b81e39e4ffed78138e69d1c2e0db99c65468 [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 Cook6316a552017-03-05 21:46:215#include "ash/common/focus_cycler.h"
[email protected]df1c9862012-02-27 10:37:316
dchenga94547472016-04-08 08:41:117#include <memory>
8
James Cook643b7182017-03-05 22:02:589#include "ash/common/shelf/shelf_widget.h"
10#include "ash/common/shelf/wm_shelf.h"
James Cook6def4d9d2017-03-05 22:13:4711#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 Cook6316a552017-03-05 21:46:2114#include "ash/common/wm_shell.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 {
26namespace test {
27
[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 }
dcheng222b9c72015-01-16 00:48:0149 views::Widget* GetWidget() override { return widget_; };
50 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:
61 FocusCyclerTest() {}
[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 {
warx7f3974192016-06-25 00:12:5670 GetStatusAreaWidgetDelegate(GetPrimarySystemTray()->GetWidget())
71 ->SetFocusCyclerForTesting(nullptr);
[email protected]eb5a0ab2012-10-20 00:50:2572
warx7f3974192016-06-25 00:12:5673 shelf_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() {
warx7f3974192016-06-25 00:12:5683 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]eb5a0ab2012-10-20 00:50:2588 }
89
90 FocusCycler* focus_cycler() { return focus_cycler_.get(); }
91
jamescook1cad77e92016-08-31 00:02:2692 ShelfWidget* shelf_widget() { return GetPrimaryShelf()->shelf_widget(); }
[email protected]eb5a0ab2012-10-20 00:50:2593
[email protected]478c6c32013-03-09 02:50:5894 void InstallFocusCycleOnShelf() {
95 // Add the shelf.
96 shelf_widget()->SetFocusCycler(focus_cycler());
[email protected]eb5a0ab2012-10-20 00:50:2597 }
98
99 private:
dchenga94547472016-04-08 08:41:11100 std::unique_ptr<FocusCycler> focus_cycler_;
[email protected]eb5a0ab2012-10-20 00:50:25101
102 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest);
103};
104
105TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) {
[email protected]df1c9862012-02-27 10:37:31106 // Create a single test window.
dchenga94547472016-04-08 08:41:11107 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54108 wm::ActivateWindow(window0.get());
109 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31110
111 // Cycle the window
[email protected]eb5a0ab2012-10-20 00:50:25112 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]f3c7b252012-02-27 12:17:54113 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31114}
115
[email protected]eb5a0ab2012-10-20 00:50:25116TEST_F(FocusCyclerTest, CycleFocusForward) {
warx7f3974192016-06-25 00:12:56117 SetUpTrayFocusCycle();
[email protected]df1c9862012-02-27 10:37:31118
[email protected]478c6c32013-03-09 02:50:58119 InstallFocusCycleOnShelf();
[email protected]df1c9862012-02-27 10:37:31120
121 // Create a single test window.
dchenga94547472016-04-08 08:41:11122 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54123 wm::ActivateWindow(window0.get());
124 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31125
[email protected]478c6c32013-03-09 02:50:58126 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25127 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56128 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31129
[email protected]478c6c32013-03-09 02:50:58130 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25131 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]478c6c32013-03-09 02:50:58132 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31133
[email protected]478c6c32013-03-09 02:50:58134 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25135 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]f3c7b252012-02-27 12:17:54136 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31137}
138
[email protected]eb5a0ab2012-10-20 00:50:25139TEST_F(FocusCyclerTest, CycleFocusBackward) {
warx7f3974192016-06-25 00:12:56140 SetUpTrayFocusCycle();
[email protected]df1c9862012-02-27 10:37:31141
[email protected]478c6c32013-03-09 02:50:58142 InstallFocusCycleOnShelf();
[email protected]df1c9862012-02-27 10:37:31143
144 // Create a single test window.
dchenga94547472016-04-08 08:41:11145 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54146 wm::ActivateWindow(window0.get());
147 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31148
[email protected]478c6c32013-03-09 02:50:58149 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25150 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]478c6c32013-03-09 02:50:58151 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31152
[email protected]478c6c32013-03-09 02:50:58153 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25154 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
warx7f3974192016-06-25 00:12:56155 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31156
[email protected]478c6c32013-03-09 02:50:58157 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25158 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]f3c7b252012-02-27 12:17:54159 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31160}
161
[email protected]eb5a0ab2012-10-20 00:50:25162TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
warx7f3974192016-06-25 00:12:56163 SetUpTrayFocusCycle();
[email protected]ce711ac2012-06-14 07:05:41164
[email protected]478c6c32013-03-09 02:50:58165 InstallFocusCycleOnShelf();
[email protected]ce711ac2012-06-14 07:05:41166
167 // Create a single test window.
dchenga94547472016-04-08 08:41:11168 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]ce711ac2012-06-14 07:05:41169 wm::ActivateWindow(window0.get());
170 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
171
[email protected]478c6c32013-03-09 02:50:58172 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25173 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]478c6c32013-03-09 02:50:58174 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41175
[email protected]478c6c32013-03-09 02:50:58176 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25177 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
warx7f3974192016-06-25 00:12:56178 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41179
[email protected]478c6c32013-03-09 02:50:58180 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25181 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]ce711ac2012-06-14 07:05:41182 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
183
[email protected]478c6c32013-03-09 02:50:58184 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25185 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56186 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41187
[email protected]478c6c32013-03-09 02:50:58188 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25189 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]478c6c32013-03-09 02:50:58190 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41191
[email protected]478c6c32013-03-09 02:50:58192 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25193 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]ce711ac2012-06-14 07:05:41194 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
195}
196
[email protected]eb5a0ab2012-10-20 00:50:25197TEST_F(FocusCyclerTest, CycleFocusNoBrowser) {
warx7f3974192016-06-25 00:12:56198 SetUpTrayFocusCycle();
[email protected]ce711ac2012-06-14 07:05:41199
[email protected]478c6c32013-03-09 02:50:58200 InstallFocusCycleOnShelf();
[email protected]ce711ac2012-06-14 07:05:41201
[email protected]478c6c32013-03-09 02:50:58202 // Add the shelf and focus it.
203 focus_cycler()->FocusWidget(shelf_widget());
[email protected]ce711ac2012-06-14 07:05:41204
[email protected]478c6c32013-03-09 02:50:58205 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25206 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56207 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41208
[email protected]478c6c32013-03-09 02:50:58209 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25210 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]478c6c32013-03-09 02:50:58211 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41212
[email protected]478c6c32013-03-09 02:50:58213 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25214 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56215 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41216
[email protected]478c6c32013-03-09 02:50:58217 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25218 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]478c6c32013-03-09 02:50:58219 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41220
[email protected]478c6c32013-03-09 02:50:58221 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25222 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
warx7f3974192016-06-25 00:12:56223 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41224}
225
[email protected]fba1eb22014-03-12 21:12:50226// Tests that focus cycles from the active browser to the status area and back.
[email protected]478c6c32013-03-09 02:50:58227TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) {
warx7f3974192016-06-25 00:12:56228 SetUpTrayFocusCycle();
[email protected]478c6c32013-03-09 02:50:58229 InstallFocusCycleOnShelf();
230 shelf_widget()->Hide();
[email protected]057dc5752012-03-06 23:59:31231
[email protected]fba1eb22014-03-12 21:12:50232 // Create two test windows.
dchenga94547472016-04-08 08:41:11233 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
234 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1));
[email protected]fba1eb22014-03-12 21:12:50235 wm::ActivateWindow(window1.get());
[email protected]057dc5752012-03-06 23:59:31236 wm::ActivateWindow(window0.get());
237 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
238
[email protected]478c6c32013-03-09 02:50:58239 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25240 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56241 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31242
[email protected]478c6c32013-03-09 02:50:58243 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25244 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]057dc5752012-03-06 23:59:31245 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]fba1eb22014-03-12 21:12:50246
247 // Cycle focus to the status area.
248 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56249 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31250}
251
[email protected]478c6c32013-03-09 02:50:58252TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) {
warx7f3974192016-06-25 00:12:56253 SetUpTrayFocusCycle();
[email protected]478c6c32013-03-09 02:50:58254 InstallFocusCycleOnShelf();
255 shelf_widget()->Hide();
[email protected]057dc5752012-03-06 23:59:31256
257 // Create a single test window.
dchenga94547472016-04-08 08:41:11258 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]057dc5752012-03-06 23:59:31259 wm::ActivateWindow(window0.get());
260 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
261
[email protected]478c6c32013-03-09 02:50:58262 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25263 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
warx7f3974192016-06-25 00:12:56264 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31265
[email protected]478c6c32013-03-09 02:50:58266 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25267 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]057dc5752012-03-06 23:59:31268 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
269}
270
[email protected]242aa4f2013-04-30 01:04:08271TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) {
warx7f3974192016-06-25 00:12:56272 SetUpTrayFocusCycle();
[email protected]242aa4f2013-04-30 01:04:08273
274 InstallFocusCycleOnShelf();
275
dchenga94547472016-04-08 08:41:11276 std::unique_ptr<PanedWidgetDelegate> test_widget_delegate;
277 std::unique_ptr<views::Widget> browser_widget(new views::Widget);
[email protected]464a0012013-11-12 18:22:44278 test_widget_delegate.reset(new PanedWidgetDelegate(browser_widget.get()));
[email protected]242aa4f2013-04-30 01:04:08279 views::Widget::InitParams widget_params(
280 views::Widget::InitParams::TYPE_WINDOW);
281 widget_params.context = CurrentContext();
[email protected]464a0012013-11-12 18:22:44282 widget_params.delegate = test_widget_delegate.get();
[email protected]242aa4f2013-04-30 01:04:08283 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;
karandeepbe7ad02a2016-04-27 23:57:22296 view1->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08297 pane1->AddChildView(view1);
298
299 views::View* view2 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22300 view2->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08301 pane1->AddChildView(view2);
302
303 views::AccessiblePaneView* pane2 = new views::AccessiblePaneView();
304 root_view->AddChildView(pane2);
305
306 views::View* view3 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22307 view3->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08308 pane2->AddChildView(view3);
309
310 views::View* view4 = new views::View;
karandeepbe7ad02a2016-04-27 23:57:22311 view4->SetFocusBehavior(views::View::FocusBehavior::ALWAYS);
[email protected]242aa4f2013-04-30 01:04:08312 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);
warx7f3974192016-06-25 00:12:56324 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08325
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);
warx7f3974192016-06-25 00:12:56342 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08343
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);
warx7f3974192016-06-25 00:12:56360 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08361
362 // Pressing "Escape" while on the status area should
363 // deactivate it, and activate the browser window.
jamescook26f32092016-06-17 04:26:52364 ui::test::EventGenerator& event_generator = GetEventGenerator();
[email protected]242aa4f2013-04-30 01:04:08365 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
xdai063763f2015-09-29 00:09:07378// Test that when the shelf widget & status area widget are removed, they should
379// also be removed from focus cycler.
380TEST_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.
dchenga94547472016-04-08 08:41:11389 std::unique_ptr<Window> window(CreateTestWindowInShellWithId(0));
xdai063763f2015-09-29 00:09:07390 wm::ActivateWindow(window.get());
391 EXPECT_TRUE(wm::IsActiveWindow(window.get()));
392
393 // Cycle focus to the status area.
jamescook26f32092016-06-17 04:26:52394 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07395 EXPECT_FALSE(wm::IsActiveWindow(window.get()));
396
397 // Cycle focus to the shelf.
jamescook26f32092016-06-17 04:26:52398 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07399
400 // Cycle focus should go back to the browser.
jamescook26f32092016-06-17 04:26:52401 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07402 EXPECT_TRUE(wm::IsActiveWindow(window.get()));
403}
404
[email protected]df1c9862012-02-27 10:37:31405} // namespace test
406} // namespace ash