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