blob: 078093967c7794fd272425007cd8f08567fb91b9 [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"
warx7f3974192016-06-25 00:12:5616#include "ash/test/status_area_widget_test_helper.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 {
27namespace test {
28
[email protected]df1c9862012-02-27 10:37:3129using aura::Window;
[email protected]df1c9862012-02-27 10:37:3130
[email protected]8676f0472012-03-29 20:30:1231namespace {
32
[email protected]093b8d642014-04-03 20:59:2833StatusAreaWidgetDelegate* GetStatusAreaWidgetDelegate(views::Widget* widget) {
34 return static_cast<StatusAreaWidgetDelegate*>(widget->GetContentsView());
[email protected]8676f0472012-03-29 20:30:1235}
36
[email protected]242aa4f2013-04-30 01:04:0837class PanedWidgetDelegate : public views::WidgetDelegate {
38 public:
39 PanedWidgetDelegate(views::Widget* widget) : widget_(widget) {}
40
41 void SetAccessiblePanes(const std::vector<views::View*>& panes) {
42 accessible_panes_ = panes;
43 }
44
45 // views::WidgetDelegate.
dcheng222b9c72015-01-16 00:48:0146 void GetAccessiblePanes(std::vector<views::View*>* panes) override {
jamescookb8dcef522016-06-25 14:42:5547 std::copy(accessible_panes_.begin(), accessible_panes_.end(),
[email protected]242aa4f2013-04-30 01:04:0848 std::back_inserter(*panes));
49 }
dcheng222b9c72015-01-16 00:48:0150 views::Widget* GetWidget() override { return widget_; };
51 const views::Widget* GetWidget() const override { return widget_; }
[email protected]242aa4f2013-04-30 01:04:0852
53 private:
54 views::Widget* widget_;
55 std::vector<views::View*> accessible_panes_;
56};
57
[email protected]8676f0472012-03-29 20:30:1258} // namespace
59
[email protected]eb5a0ab2012-10-20 00:50:2560class FocusCyclerTest : public AshTestBase {
61 public:
62 FocusCyclerTest() {}
[email protected]df1c9862012-02-27 10:37:3163
dcheng222b9c72015-01-16 00:48:0164 void SetUp() override {
[email protected]eb5a0ab2012-10-20 00:50:2565 AshTestBase::SetUp();
[email protected]df1c9862012-02-27 10:37:3166
[email protected]eb5a0ab2012-10-20 00:50:2567 focus_cycler_.reset(new FocusCycler());
[email protected]eb5a0ab2012-10-20 00:50:2568 }
69
dcheng222b9c72015-01-16 00:48:0170 void TearDown() override {
warx7f3974192016-06-25 00:12:5671 GetStatusAreaWidgetDelegate(GetPrimarySystemTray()->GetWidget())
72 ->SetFocusCyclerForTesting(nullptr);
[email protected]eb5a0ab2012-10-20 00:50:2573
warx7f3974192016-06-25 00:12:5674 shelf_widget()->SetFocusCycler(nullptr);
[email protected]eb5a0ab2012-10-20 00:50:2575
76 focus_cycler_.reset();
77
78 AshTestBase::TearDown();
79 }
80
81 protected:
warx7f3974192016-06-25 00:12:5682 // Setup the system tray using StatusAreaWidgetTestHelper and focus_cycler.
83 void SetUpTrayFocusCycle() {
84 StatusAreaWidget* widget =
85 StatusAreaWidgetTestHelper::GetStatusAreaWidget();
[email protected]51ed5992012-11-07 10:14:3986 widget->CreateTrayViews();
[email protected]eb5a0ab2012-10-20 00:50:2587 widget->Show();
warx7f3974192016-06-25 00:12:5688 views::Widget* system_tray_widget = GetPrimarySystemTray()->GetWidget();
89 ASSERT_TRUE(system_tray_widget);
90 focus_cycler_->AddWidget(system_tray_widget);
91 GetStatusAreaWidgetDelegate(system_tray_widget)
92 ->SetFocusCyclerForTesting(focus_cycler());
[email protected]eb5a0ab2012-10-20 00:50:2593 }
94
95 FocusCycler* focus_cycler() { return focus_cycler_.get(); }
96
jamescook1cad77e92016-08-31 00:02:2697 ShelfWidget* shelf_widget() { return GetPrimaryShelf()->shelf_widget(); }
[email protected]eb5a0ab2012-10-20 00:50:2598
[email protected]478c6c32013-03-09 02:50:5899 void InstallFocusCycleOnShelf() {
100 // Add the shelf.
101 shelf_widget()->SetFocusCycler(focus_cycler());
[email protected]eb5a0ab2012-10-20 00:50:25102 }
103
104 private:
dchenga94547472016-04-08 08:41:11105 std::unique_ptr<FocusCycler> focus_cycler_;
[email protected]eb5a0ab2012-10-20 00:50:25106
107 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest);
108};
109
110TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) {
[email protected]df1c9862012-02-27 10:37:31111 // Create a single test window.
dchenga94547472016-04-08 08:41:11112 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54113 wm::ActivateWindow(window0.get());
114 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31115
116 // Cycle the window
[email protected]eb5a0ab2012-10-20 00:50:25117 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]f3c7b252012-02-27 12:17:54118 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31119}
120
[email protected]eb5a0ab2012-10-20 00:50:25121TEST_F(FocusCyclerTest, CycleFocusForward) {
warx7f3974192016-06-25 00:12:56122 SetUpTrayFocusCycle();
[email protected]df1c9862012-02-27 10:37:31123
[email protected]478c6c32013-03-09 02:50:58124 InstallFocusCycleOnShelf();
[email protected]df1c9862012-02-27 10:37:31125
126 // Create a single test window.
dchenga94547472016-04-08 08:41:11127 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54128 wm::ActivateWindow(window0.get());
129 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31130
[email protected]478c6c32013-03-09 02:50:58131 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25132 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56133 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31134
[email protected]478c6c32013-03-09 02:50:58135 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25136 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]478c6c32013-03-09 02:50:58137 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31138
[email protected]478c6c32013-03-09 02:50:58139 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25140 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]f3c7b252012-02-27 12:17:54141 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31142}
143
[email protected]eb5a0ab2012-10-20 00:50:25144TEST_F(FocusCyclerTest, CycleFocusBackward) {
warx7f3974192016-06-25 00:12:56145 SetUpTrayFocusCycle();
[email protected]df1c9862012-02-27 10:37:31146
[email protected]478c6c32013-03-09 02:50:58147 InstallFocusCycleOnShelf();
[email protected]df1c9862012-02-27 10:37:31148
149 // Create a single test window.
dchenga94547472016-04-08 08:41:11150 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]f3c7b252012-02-27 12:17:54151 wm::ActivateWindow(window0.get());
152 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31153
[email protected]478c6c32013-03-09 02:50:58154 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25155 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]478c6c32013-03-09 02:50:58156 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31157
[email protected]478c6c32013-03-09 02:50:58158 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25159 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
warx7f3974192016-06-25 00:12:56160 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]df1c9862012-02-27 10:37:31161
[email protected]478c6c32013-03-09 02:50:58162 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25163 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]f3c7b252012-02-27 12:17:54164 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]df1c9862012-02-27 10:37:31165}
166
[email protected]eb5a0ab2012-10-20 00:50:25167TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
warx7f3974192016-06-25 00:12:56168 SetUpTrayFocusCycle();
[email protected]ce711ac2012-06-14 07:05:41169
[email protected]478c6c32013-03-09 02:50:58170 InstallFocusCycleOnShelf();
[email protected]ce711ac2012-06-14 07:05:41171
172 // Create a single test window.
dchenga94547472016-04-08 08:41:11173 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]ce711ac2012-06-14 07:05:41174 wm::ActivateWindow(window0.get());
175 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
176
[email protected]478c6c32013-03-09 02:50:58177 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25178 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]478c6c32013-03-09 02:50:58179 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41180
[email protected]478c6c32013-03-09 02:50:58181 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25182 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
warx7f3974192016-06-25 00:12:56183 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41184
[email protected]478c6c32013-03-09 02:50:58185 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25186 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]ce711ac2012-06-14 07:05:41187 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
188
[email protected]478c6c32013-03-09 02:50:58189 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25190 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56191 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41192
[email protected]478c6c32013-03-09 02:50:58193 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25194 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]478c6c32013-03-09 02:50:58195 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41196
[email protected]478c6c32013-03-09 02:50:58197 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25198 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]ce711ac2012-06-14 07:05:41199 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
200}
201
[email protected]eb5a0ab2012-10-20 00:50:25202TEST_F(FocusCyclerTest, CycleFocusNoBrowser) {
warx7f3974192016-06-25 00:12:56203 SetUpTrayFocusCycle();
[email protected]ce711ac2012-06-14 07:05:41204
[email protected]478c6c32013-03-09 02:50:58205 InstallFocusCycleOnShelf();
[email protected]ce711ac2012-06-14 07:05:41206
[email protected]478c6c32013-03-09 02:50:58207 // Add the shelf and focus it.
208 focus_cycler()->FocusWidget(shelf_widget());
[email protected]ce711ac2012-06-14 07:05:41209
[email protected]478c6c32013-03-09 02:50:58210 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25211 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56212 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41213
[email protected]478c6c32013-03-09 02:50:58214 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25215 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]478c6c32013-03-09 02:50:58216 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41217
[email protected]478c6c32013-03-09 02:50:58218 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25219 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56220 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41221
[email protected]478c6c32013-03-09 02:50:58222 // Cycle focus to the shelf.
[email protected]eb5a0ab2012-10-20 00:50:25223 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]478c6c32013-03-09 02:50:58224 EXPECT_TRUE(shelf_widget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41225
[email protected]478c6c32013-03-09 02:50:58226 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25227 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
warx7f3974192016-06-25 00:12:56228 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]ce711ac2012-06-14 07:05:41229}
230
[email protected]fba1eb22014-03-12 21:12:50231// Tests that focus cycles from the active browser to the status area and back.
[email protected]478c6c32013-03-09 02:50:58232TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) {
warx7f3974192016-06-25 00:12:56233 SetUpTrayFocusCycle();
[email protected]478c6c32013-03-09 02:50:58234 InstallFocusCycleOnShelf();
235 shelf_widget()->Hide();
[email protected]057dc5752012-03-06 23:59:31236
[email protected]fba1eb22014-03-12 21:12:50237 // Create two test windows.
dchenga94547472016-04-08 08:41:11238 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
239 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1));
[email protected]fba1eb22014-03-12 21:12:50240 wm::ActivateWindow(window1.get());
[email protected]057dc5752012-03-06 23:59:31241 wm::ActivateWindow(window0.get());
242 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
243
[email protected]478c6c32013-03-09 02:50:58244 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25245 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56246 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31247
[email protected]478c6c32013-03-09 02:50:58248 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25249 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
[email protected]057dc5752012-03-06 23:59:31250 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
[email protected]fba1eb22014-03-12 21:12:50251
252 // Cycle focus to the status area.
253 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
warx7f3974192016-06-25 00:12:56254 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31255}
256
[email protected]478c6c32013-03-09 02:50:58257TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) {
warx7f3974192016-06-25 00:12:56258 SetUpTrayFocusCycle();
[email protected]478c6c32013-03-09 02:50:58259 InstallFocusCycleOnShelf();
260 shelf_widget()->Hide();
[email protected]057dc5752012-03-06 23:59:31261
262 // Create a single test window.
dchenga94547472016-04-08 08:41:11263 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0));
[email protected]057dc5752012-03-06 23:59:31264 wm::ActivateWindow(window0.get());
265 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
266
[email protected]478c6c32013-03-09 02:50:58267 // Cycle focus to the status area.
[email protected]eb5a0ab2012-10-20 00:50:25268 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
warx7f3974192016-06-25 00:12:56269 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]057dc5752012-03-06 23:59:31270
[email protected]478c6c32013-03-09 02:50:58271 // Cycle focus to the browser.
[email protected]eb5a0ab2012-10-20 00:50:25272 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
[email protected]057dc5752012-03-06 23:59:31273 EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
274}
275
[email protected]242aa4f2013-04-30 01:04:08276TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) {
warx7f3974192016-06-25 00:12:56277 SetUpTrayFocusCycle();
[email protected]242aa4f2013-04-30 01:04:08278
279 InstallFocusCycleOnShelf();
280
dchenga94547472016-04-08 08:41:11281 std::unique_ptr<PanedWidgetDelegate> test_widget_delegate;
282 std::unique_ptr<views::Widget> browser_widget(new views::Widget);
[email protected]464a0012013-11-12 18:22:44283 test_widget_delegate.reset(new PanedWidgetDelegate(browser_widget.get()));
[email protected]242aa4f2013-04-30 01:04:08284 views::Widget::InitParams widget_params(
285 views::Widget::InitParams::TYPE_WINDOW);
286 widget_params.context = CurrentContext();
[email protected]464a0012013-11-12 18:22:44287 widget_params.delegate = test_widget_delegate.get();
[email protected]242aa4f2013-04-30 01:04:08288 widget_params.ownership =
289 views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
290 browser_widget->Init(widget_params);
291 browser_widget->Show();
292
293 aura::Window* browser_window = browser_widget->GetNativeView();
294
295 views::View* root_view = browser_widget->GetRootView();
296
297 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);
warx7f3974192016-06-25 00:12:56329 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->IsActive());
[email protected]242aa4f2013-04-30 01:04:08330
331 // Cycle focus to the shelf.
332 focus_cycler()->RotateFocus(FocusCycler::FORWARD);
333 EXPECT_TRUE(shelf_widget()->IsActive());
334
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);
warx7f3974192016-06-25 00:12:56347 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->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);
361 EXPECT_TRUE(shelf_widget()->IsActive());
362
363 // Back to the status area.
364 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
warx7f3974192016-06-25 00:12:56365 EXPECT_TRUE(GetPrimarySystemTray()->GetWidget()->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.
jamescook26f32092016-06-17 04:26:52369 ui::test::EventGenerator& event_generator = GetEventGenerator();
[email protected]242aa4f2013-04-30 01:04:08370 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
371 EXPECT_TRUE(wm::IsActiveWindow(browser_window));
372 EXPECT_EQ(focus_manager->GetFocusedView(), view1);
373
374 // Similarly, pressing "Escape" while on the shelf.
375 // should do the same thing.
376 focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
377 EXPECT_TRUE(shelf_widget()->IsActive());
378 event_generator.PressKey(ui::VKEY_ESCAPE, 0);
379 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
398 // Cycle focus to the status area.
jamescook26f32092016-06-17 04:26:52399 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07400 EXPECT_FALSE(wm::IsActiveWindow(window.get()));
401
402 // Cycle focus to the shelf.
jamescook26f32092016-06-17 04:26:52403 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07404
405 // Cycle focus should go back to the browser.
jamescook26f32092016-06-17 04:26:52406 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD);
xdai063763f2015-09-29 00:09:07407 EXPECT_TRUE(wm::IsActiveWindow(window.get()));
408}
409
[email protected]df1c9862012-02-27 10:37:31410} // namespace test
411} // namespace ash