Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/focus_cycler.h" | 5 #include "ash/common/focus_cycler.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
| 10 #include "ash/common/wm_root_window_controller.h" | |
| 10 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 11 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
| 12 #include "ash/shelf/shelf.h" | 13 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shelf/shelf_widget.h" | 14 #include "ash/shelf/shelf_widget.h" |
| 14 #include "ash/system/status_area_widget.h" | 15 #include "ash/system/status_area_widget.h" |
| 15 #include "ash/system/status_area_widget_delegate.h" | 16 #include "ash/system/status_area_widget_delegate.h" |
| 16 #include "ash/system/tray/system_tray.h" | 17 #include "ash/system/tray/system_tray.h" |
| 17 #include "ash/test/ash_test_base.h" | 18 #include "ash/test/ash_test_base.h" |
| 19 #include "ash/test/status_area_widget_test_helper.h" | |
| 18 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
| 19 #include "ui/aura/test/test_windows.h" | 21 #include "ui/aura/test/test_windows.h" |
| 20 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 21 #include "ui/aura/window_event_dispatcher.h" | 23 #include "ui/aura/window_event_dispatcher.h" |
| 22 #include "ui/events/test/event_generator.h" | 24 #include "ui/events/test/event_generator.h" |
| 23 #include "ui/views/accessible_pane_view.h" | 25 #include "ui/views/accessible_pane_view.h" |
| 24 #include "ui/views/controls/button/menu_button.h" | 26 #include "ui/views/controls/button/menu_button.h" |
| 25 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 26 | 28 |
| 27 namespace ash { | 29 namespace ash { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 50 std::back_inserter(*panes)); | 52 std::back_inserter(*panes)); |
| 51 } | 53 } |
| 52 views::Widget* GetWidget() override { return widget_; }; | 54 views::Widget* GetWidget() override { return widget_; }; |
| 53 const views::Widget* GetWidget() const override { return widget_; } | 55 const views::Widget* GetWidget() const override { return widget_; } |
| 54 | 56 |
| 55 private: | 57 private: |
| 56 views::Widget* widget_; | 58 views::Widget* widget_; |
| 57 std::vector<views::View*> accessible_panes_; | 59 std::vector<views::View*> accessible_panes_; |
| 58 }; | 60 }; |
| 59 | 61 |
| 62 SystemTray* GetSystemTray() { | |
|
James Cook
2016/06/24 22:31:42
Use AshTestBase::GetPrimarySystemTray() instead of
Qiang(Joe) Xu
2016/06/24 22:56:37
Done.
| |
| 63 return StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray(); | |
| 64 } | |
| 65 | |
| 60 } // namespace | 66 } // namespace |
| 61 | 67 |
| 62 // TODO(jamescook): Migrate this test to //ash/common after the status area | 68 // TODO(jamescook): Migrate this test to //ash/common after the status area |
| 63 // widget moves. http://crbug.com/620955 | 69 // widget moves. http://crbug.com/620955 |
| 64 class FocusCyclerTest : public AshTestBase { | 70 class FocusCyclerTest : public AshTestBase { |
| 65 public: | 71 public: |
| 66 FocusCyclerTest() {} | 72 FocusCyclerTest() {} |
| 67 | 73 |
| 68 void SetUp() override { | 74 void SetUp() override { |
| 69 AshTestBase::SetUp(); | 75 AshTestBase::SetUp(); |
| 70 | 76 |
| 71 focus_cycler_.reset(new FocusCycler()); | 77 focus_cycler_.reset(new FocusCycler()); |
| 72 | 78 |
| 73 ASSERT_TRUE(Shelf::ForPrimaryDisplay()); | 79 ASSERT_TRUE(Shelf::ForPrimaryDisplay()); |
| 74 } | 80 } |
| 75 | 81 |
| 82 // Setup the system tray using StatusAreaWidgetTestHelper, returning true | |
| 83 // on success. | |
| 84 bool SetUpTrayFocusCycle() { | |
|
James Cook
2016/06/24 22:31:42
Keep this protected.
Qiang(Joe) Xu
2016/06/24 22:56:37
Done.
| |
| 85 StatusAreaWidget* widget = | |
| 86 StatusAreaWidgetTestHelper::GetStatusAreaWidget(); | |
| 87 widget->CreateTrayViews(); | |
| 88 widget->Show(); | |
| 89 if (!GetSystemTray()->GetWidget()) | |
|
James Cook
2016/06/24 22:31:42
GetWidget() should always return a non-null pointe
Qiang(Joe) Xu
2016/06/24 22:56:37
Done.
| |
| 90 return false; | |
| 91 focus_cycler_->AddWidget(GetSystemTray()->GetWidget()); | |
|
James Cook
2016/06/24 22:31:42
nit: cache GetSystemTray()->GetWidget() in a local
Qiang(Joe) Xu
2016/06/24 22:56:37
Done.
| |
| 92 GetStatusAreaWidgetDelegate(GetSystemTray()->GetWidget()) | |
| 93 ->SetFocusCyclerForTesting(focus_cycler()); | |
| 94 return true; | |
| 95 } | |
| 96 | |
| 76 void TearDown() override { | 97 void TearDown() override { |
| 77 if (tray_) { | 98 GetStatusAreaWidgetDelegate(GetSystemTray()->GetWidget()) |
| 78 GetStatusAreaWidgetDelegate(tray_->GetWidget())-> | 99 ->SetFocusCyclerForTesting(nullptr); |
| 79 SetFocusCyclerForTesting(NULL); | |
| 80 tray_.reset(); | |
| 81 } | |
| 82 | 100 |
| 83 shelf_widget()->SetFocusCycler(NULL); | 101 shelf_widget()->SetFocusCycler(nullptr); |
|
James Cook
2016/06/24 22:31:42
Thanks for fixing these.
| |
| 84 | 102 |
| 85 focus_cycler_.reset(); | 103 focus_cycler_.reset(); |
| 86 | 104 |
| 87 AshTestBase::TearDown(); | 105 AshTestBase::TearDown(); |
| 88 } | 106 } |
| 89 | 107 |
| 90 protected: | 108 protected: |
| 91 // Creates the system tray, returning true on success. | |
| 92 bool CreateTray() { | |
| 93 if (tray_) | |
| 94 return false; | |
| 95 WmWindow* parent = | |
| 96 WmShell::Get()->GetRootWindowForNewWindows()->GetChildByShellWindowId( | |
| 97 kShellWindowId_StatusContainer); | |
| 98 | |
| 99 StatusAreaWidget* widget = new StatusAreaWidget(parent, GetPrimaryShelf()); | |
| 100 widget->CreateTrayViews(); | |
| 101 widget->Show(); | |
| 102 tray_.reset(widget->system_tray()); | |
| 103 if (!tray_->GetWidget()) | |
| 104 return false; | |
| 105 focus_cycler_->AddWidget(tray()->GetWidget()); | |
| 106 GetStatusAreaWidgetDelegate(tray_->GetWidget())->SetFocusCyclerForTesting( | |
| 107 focus_cycler()); | |
| 108 return true; | |
| 109 } | |
| 110 | |
| 111 FocusCycler* focus_cycler() { return focus_cycler_.get(); } | 109 FocusCycler* focus_cycler() { return focus_cycler_.get(); } |
| 112 | 110 |
| 113 SystemTray* tray() { return tray_.get(); } | |
| 114 | |
| 115 ShelfWidget* shelf_widget() { | 111 ShelfWidget* shelf_widget() { |
| 116 return Shelf::ForPrimaryDisplay()->shelf_widget(); | 112 return Shelf::ForPrimaryDisplay()->shelf_widget(); |
| 117 } | 113 } |
| 118 | 114 |
| 119 void InstallFocusCycleOnShelf() { | 115 void InstallFocusCycleOnShelf() { |
| 120 // Add the shelf. | 116 // Add the shelf. |
| 121 shelf_widget()->SetFocusCycler(focus_cycler()); | 117 shelf_widget()->SetFocusCycler(focus_cycler()); |
| 122 } | 118 } |
| 123 | 119 |
| 124 private: | 120 private: |
| 125 std::unique_ptr<FocusCycler> focus_cycler_; | 121 std::unique_ptr<FocusCycler> focus_cycler_; |
| 126 std::unique_ptr<SystemTray> tray_; | |
| 127 | 122 |
| 128 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest); | 123 DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest); |
| 129 }; | 124 }; |
| 130 | 125 |
| 131 TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { | 126 TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { |
| 132 // Create a single test window. | 127 // Create a single test window. |
| 133 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 128 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 134 wm::ActivateWindow(window0.get()); | 129 wm::ActivateWindow(window0.get()); |
| 135 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 130 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 136 | 131 |
| 137 // Cycle the window | 132 // Cycle the window |
| 138 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 133 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 139 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 134 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 140 } | 135 } |
| 141 | 136 |
| 142 TEST_F(FocusCyclerTest, CycleFocusForward) { | 137 TEST_F(FocusCyclerTest, CycleFocusForward) { |
| 143 ASSERT_TRUE(CreateTray()); | 138 ASSERT_TRUE(SetUpTrayFocusCycle()); |
|
James Cook
2016/06/24 22:31:42
with the assert above you won't need all these oth
| |
| 144 | 139 |
| 145 InstallFocusCycleOnShelf(); | 140 InstallFocusCycleOnShelf(); |
| 146 | 141 |
| 147 // Create a single test window. | 142 // Create a single test window. |
| 148 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 143 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 149 wm::ActivateWindow(window0.get()); | 144 wm::ActivateWindow(window0.get()); |
| 150 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 145 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 151 | 146 |
| 152 // Cycle focus to the status area. | 147 // Cycle focus to the status area. |
| 153 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 148 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 154 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 149 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 155 | 150 |
| 156 // Cycle focus to the shelf. | 151 // Cycle focus to the shelf. |
| 157 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 152 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 158 EXPECT_TRUE(shelf_widget()->IsActive()); | 153 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 159 | 154 |
| 160 // Cycle focus to the browser. | 155 // Cycle focus to the browser. |
| 161 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 156 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 162 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 157 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 163 } | 158 } |
| 164 | 159 |
| 165 TEST_F(FocusCyclerTest, CycleFocusBackward) { | 160 TEST_F(FocusCyclerTest, CycleFocusBackward) { |
| 166 ASSERT_TRUE(CreateTray()); | 161 ASSERT_TRUE(SetUpTrayFocusCycle()); |
| 167 | 162 |
| 168 InstallFocusCycleOnShelf(); | 163 InstallFocusCycleOnShelf(); |
| 169 | 164 |
| 170 // Create a single test window. | 165 // Create a single test window. |
| 171 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 166 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 172 wm::ActivateWindow(window0.get()); | 167 wm::ActivateWindow(window0.get()); |
| 173 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 168 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 174 | 169 |
| 175 // Cycle focus to the shelf. | 170 // Cycle focus to the shelf. |
| 176 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 171 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 177 EXPECT_TRUE(shelf_widget()->IsActive()); | 172 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 178 | 173 |
| 179 // Cycle focus to the status area. | 174 // Cycle focus to the status area. |
| 180 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 175 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 181 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 176 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 182 | 177 |
| 183 // Cycle focus to the browser. | 178 // Cycle focus to the browser. |
| 184 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 179 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 185 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 180 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 186 } | 181 } |
| 187 | 182 |
| 188 TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { | 183 TEST_F(FocusCyclerTest, CycleFocusForwardBackward) { |
| 189 ASSERT_TRUE(CreateTray()); | 184 ASSERT_TRUE(SetUpTrayFocusCycle()); |
| 190 | 185 |
| 191 InstallFocusCycleOnShelf(); | 186 InstallFocusCycleOnShelf(); |
| 192 | 187 |
| 193 // Create a single test window. | 188 // Create a single test window. |
| 194 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 189 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 195 wm::ActivateWindow(window0.get()); | 190 wm::ActivateWindow(window0.get()); |
| 196 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 191 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 197 | 192 |
| 198 // Cycle focus to the shelf. | 193 // Cycle focus to the shelf. |
| 199 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 194 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 200 EXPECT_TRUE(shelf_widget()->IsActive()); | 195 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 201 | 196 |
| 202 // Cycle focus to the status area. | 197 // Cycle focus to the status area. |
| 203 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 198 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 204 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 199 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 205 | 200 |
| 206 // Cycle focus to the browser. | 201 // Cycle focus to the browser. |
| 207 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 202 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 208 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 203 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 209 | 204 |
| 210 // Cycle focus to the status area. | 205 // Cycle focus to the status area. |
| 211 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 206 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 212 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 207 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 213 | 208 |
| 214 // Cycle focus to the shelf. | 209 // Cycle focus to the shelf. |
| 215 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 210 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 216 EXPECT_TRUE(shelf_widget()->IsActive()); | 211 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 217 | 212 |
| 218 // Cycle focus to the browser. | 213 // Cycle focus to the browser. |
| 219 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 214 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 220 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 215 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 221 } | 216 } |
| 222 | 217 |
| 223 TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { | 218 TEST_F(FocusCyclerTest, CycleFocusNoBrowser) { |
| 224 ASSERT_TRUE(CreateTray()); | 219 ASSERT_TRUE(SetUpTrayFocusCycle()); |
| 225 | 220 |
| 226 InstallFocusCycleOnShelf(); | 221 InstallFocusCycleOnShelf(); |
| 227 | 222 |
| 228 // Add the shelf and focus it. | 223 // Add the shelf and focus it. |
| 229 focus_cycler()->FocusWidget(shelf_widget()); | 224 focus_cycler()->FocusWidget(shelf_widget()); |
| 230 | 225 |
| 231 // Cycle focus to the status area. | 226 // Cycle focus to the status area. |
| 232 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 227 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 233 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 228 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 234 | 229 |
| 235 // Cycle focus to the shelf. | 230 // Cycle focus to the shelf. |
| 236 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 231 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 237 EXPECT_TRUE(shelf_widget()->IsActive()); | 232 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 238 | 233 |
| 239 // Cycle focus to the status area. | 234 // Cycle focus to the status area. |
| 240 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 235 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 241 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 236 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 242 | 237 |
| 243 // Cycle focus to the shelf. | 238 // Cycle focus to the shelf. |
| 244 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 239 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 245 EXPECT_TRUE(shelf_widget()->IsActive()); | 240 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 246 | 241 |
| 247 // Cycle focus to the status area. | 242 // Cycle focus to the status area. |
| 248 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 243 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 249 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 244 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 250 } | 245 } |
| 251 | 246 |
| 252 // Tests that focus cycles from the active browser to the status area and back. | 247 // Tests that focus cycles from the active browser to the status area and back. |
| 253 TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) { | 248 TEST_F(FocusCyclerTest, Shelf_CycleFocusForward) { |
| 254 ASSERT_TRUE(CreateTray()); | 249 ASSERT_TRUE(SetUpTrayFocusCycle()); |
| 255 InstallFocusCycleOnShelf(); | 250 InstallFocusCycleOnShelf(); |
| 256 shelf_widget()->Hide(); | 251 shelf_widget()->Hide(); |
| 257 | 252 |
| 258 // Create two test windows. | 253 // Create two test windows. |
| 259 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 254 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 260 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 255 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 261 wm::ActivateWindow(window1.get()); | 256 wm::ActivateWindow(window1.get()); |
| 262 wm::ActivateWindow(window0.get()); | 257 wm::ActivateWindow(window0.get()); |
| 263 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 258 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 264 | 259 |
| 265 // Cycle focus to the status area. | 260 // Cycle focus to the status area. |
| 266 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 261 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 267 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 262 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 268 | 263 |
| 269 // Cycle focus to the browser. | 264 // Cycle focus to the browser. |
| 270 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 265 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 271 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 266 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 272 | 267 |
| 273 // Cycle focus to the status area. | 268 // Cycle focus to the status area. |
| 274 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 269 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 275 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 270 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 276 } | 271 } |
| 277 | 272 |
| 278 TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) { | 273 TEST_F(FocusCyclerTest, Shelf_CycleFocusBackwardInvisible) { |
| 279 ASSERT_TRUE(CreateTray()); | 274 ASSERT_TRUE(SetUpTrayFocusCycle()); |
| 280 InstallFocusCycleOnShelf(); | 275 InstallFocusCycleOnShelf(); |
| 281 shelf_widget()->Hide(); | 276 shelf_widget()->Hide(); |
| 282 | 277 |
| 283 // Create a single test window. | 278 // Create a single test window. |
| 284 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 279 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 285 wm::ActivateWindow(window0.get()); | 280 wm::ActivateWindow(window0.get()); |
| 286 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 281 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 287 | 282 |
| 288 // Cycle focus to the status area. | 283 // Cycle focus to the status area. |
| 289 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 284 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 290 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 285 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 291 | 286 |
| 292 // Cycle focus to the browser. | 287 // Cycle focus to the browser. |
| 293 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 288 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 294 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 289 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 295 } | 290 } |
| 296 | 291 |
| 297 TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) { | 292 TEST_F(FocusCyclerTest, CycleFocusThroughWindowWithPanes) { |
| 298 ASSERT_TRUE(CreateTray()); | 293 ASSERT_TRUE(SetUpTrayFocusCycle()); |
| 299 | 294 |
| 300 InstallFocusCycleOnShelf(); | 295 InstallFocusCycleOnShelf(); |
| 301 | 296 |
| 302 std::unique_ptr<PanedWidgetDelegate> test_widget_delegate; | 297 std::unique_ptr<PanedWidgetDelegate> test_widget_delegate; |
| 303 std::unique_ptr<views::Widget> browser_widget(new views::Widget); | 298 std::unique_ptr<views::Widget> browser_widget(new views::Widget); |
| 304 test_widget_delegate.reset(new PanedWidgetDelegate(browser_widget.get())); | 299 test_widget_delegate.reset(new PanedWidgetDelegate(browser_widget.get())); |
| 305 views::Widget::InitParams widget_params( | 300 views::Widget::InitParams widget_params( |
| 306 views::Widget::InitParams::TYPE_WINDOW); | 301 views::Widget::InitParams::TYPE_WINDOW); |
| 307 widget_params.context = CurrentContext(); | 302 widget_params.context = CurrentContext(); |
| 308 widget_params.delegate = test_widget_delegate.get(); | 303 widget_params.delegate = test_widget_delegate.get(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 std::vector<views::View*> panes; | 335 std::vector<views::View*> panes; |
| 341 panes.push_back(pane1); | 336 panes.push_back(pane1); |
| 342 panes.push_back(pane2); | 337 panes.push_back(pane2); |
| 343 | 338 |
| 344 test_widget_delegate->SetAccessiblePanes(panes); | 339 test_widget_delegate->SetAccessiblePanes(panes); |
| 345 | 340 |
| 346 views::FocusManager* focus_manager = browser_widget->GetFocusManager(); | 341 views::FocusManager* focus_manager = browser_widget->GetFocusManager(); |
| 347 | 342 |
| 348 // Cycle focus to the status area. | 343 // Cycle focus to the status area. |
| 349 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 344 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 350 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 345 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 351 | 346 |
| 352 // Cycle focus to the shelf. | 347 // Cycle focus to the shelf. |
| 353 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 348 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 354 EXPECT_TRUE(shelf_widget()->IsActive()); | 349 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 355 | 350 |
| 356 // Cycle focus to the first pane in the browser. | 351 // Cycle focus to the first pane in the browser. |
| 357 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 352 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 358 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); | 353 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 359 EXPECT_EQ(focus_manager->GetFocusedView(), view1); | 354 EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 360 | 355 |
| 361 // Cycle focus to the second pane in the browser. | 356 // Cycle focus to the second pane in the browser. |
| 362 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 357 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 363 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); | 358 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 364 EXPECT_EQ(focus_manager->GetFocusedView(), view3); | 359 EXPECT_EQ(focus_manager->GetFocusedView(), view3); |
| 365 | 360 |
| 366 // Cycle focus back to the status area. | 361 // Cycle focus back to the status area. |
| 367 focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 362 focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 368 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 363 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 369 | 364 |
| 370 // Reverse direction - back to the second pane in the browser. | 365 // Reverse direction - back to the second pane in the browser. |
| 371 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 366 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 372 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); | 367 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 373 EXPECT_EQ(focus_manager->GetFocusedView(), view3); | 368 EXPECT_EQ(focus_manager->GetFocusedView(), view3); |
| 374 | 369 |
| 375 // Back to the first pane in the browser. | 370 // Back to the first pane in the browser. |
| 376 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 371 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 377 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); | 372 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 378 EXPECT_EQ(focus_manager->GetFocusedView(), view1); | 373 EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 379 | 374 |
| 380 // Back to the shelf. | 375 // Back to the shelf. |
| 381 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 376 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 382 EXPECT_TRUE(shelf_widget()->IsActive()); | 377 EXPECT_TRUE(shelf_widget()->IsActive()); |
| 383 | 378 |
| 384 // Back to the status area. | 379 // Back to the status area. |
| 385 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); | 380 focus_cycler()->RotateFocus(FocusCycler::BACKWARD); |
| 386 EXPECT_TRUE(tray()->GetWidget()->IsActive()); | 381 EXPECT_TRUE(GetSystemTray()->GetWidget()->IsActive()); |
| 387 | 382 |
| 388 // Pressing "Escape" while on the status area should | 383 // Pressing "Escape" while on the status area should |
| 389 // deactivate it, and activate the browser window. | 384 // deactivate it, and activate the browser window. |
| 390 ui::test::EventGenerator& event_generator = GetEventGenerator(); | 385 ui::test::EventGenerator& event_generator = GetEventGenerator(); |
| 391 event_generator.PressKey(ui::VKEY_ESCAPE, 0); | 386 event_generator.PressKey(ui::VKEY_ESCAPE, 0); |
| 392 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); | 387 EXPECT_TRUE(wm::IsActiveWindow(browser_window)); |
| 393 EXPECT_EQ(focus_manager->GetFocusedView(), view1); | 388 EXPECT_EQ(focus_manager->GetFocusedView(), view1); |
| 394 | 389 |
| 395 // Similarly, pressing "Escape" while on the shelf. | 390 // Similarly, pressing "Escape" while on the shelf. |
| 396 // should do the same thing. | 391 // should do the same thing. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 423 // Cycle focus to the shelf. | 418 // Cycle focus to the shelf. |
| 424 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 419 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 425 | 420 |
| 426 // Cycle focus should go back to the browser. | 421 // Cycle focus should go back to the browser. |
| 427 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 422 WmShell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 428 EXPECT_TRUE(wm::IsActiveWindow(window.get())); | 423 EXPECT_TRUE(wm::IsActiveWindow(window.get())); |
| 429 } | 424 } |
| 430 | 425 |
| 431 } // namespace test | 426 } // namespace test |
| 432 } // namespace ash | 427 } // namespace ash |
| OLD | NEW |