Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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/wm/window_cycle_controller.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 | |
| 9 #include "ash/session/session_state_delegate.h" | |
| 10 #include "ash/shelf/shelf.h" | |
| 11 #include "ash/shelf/shelf_widget.h" | |
| 12 #include "ash/shell.h" | |
| 13 #include "ash/shell_window_ids.h" | |
| 14 #include "ash/test/ash_test_base.h" | |
| 15 #include "ash/test/shelf_test_api.h" | |
| 16 #include "ash/test/shelf_view_test_api.h" | |
| 17 #include "ash/test/test_shelf_delegate.h" | |
| 18 #include "ash/test/test_shell_delegate.h" | |
| 19 #include "ash/wm/window_cycle_list.h" | |
| 20 #include "ash/wm/window_state.h" | |
| 21 #include "ash/wm/window_util.h" | |
| 22 #include "base/memory/scoped_ptr.h" | |
| 23 #include "ui/aura/client/aura_constants.h" | |
| 24 #include "ui/aura/client/screen_position_client.h" | |
| 25 #include "ui/aura/env.h" | |
| 26 #include "ui/aura/test/test_windows.h" | |
| 27 #include "ui/aura/window.h" | |
| 28 #include "ui/aura/window_event_dispatcher.h" | |
| 29 #include "ui/gfx/rect.h" | |
| 30 #include "ui/gfx/screen.h" | |
| 31 | |
| 32 namespace ash { | |
| 33 | |
| 34 using aura::test::CreateTestWindowWithId; | |
| 35 using aura::test::TestWindowDelegate; | |
| 36 using aura::Window; | |
| 37 | |
| 38 class WindowCycleControllerTest : public test::AshTestBase { | |
| 39 public: | |
| 40 WindowCycleControllerTest() {} | |
| 41 virtual ~WindowCycleControllerTest() {} | |
| 42 | |
| 43 virtual void SetUp() OVERRIDE { | |
| 44 test::AshTestBase::SetUp(); | |
| 45 ASSERT_TRUE(test::TestShelfDelegate::instance()); | |
| 46 | |
| 47 shelf_view_test_.reset(new test::ShelfViewTestAPI( | |
| 48 test::ShelfTestAPI(Shelf::ForPrimaryDisplay()).shelf_view())); | |
| 49 shelf_view_test_->SetAnimationDuration(1); | |
| 50 } | |
| 51 | |
| 52 aura::Window* CreatePanelWindow() { | |
| 53 gfx::Rect rect(100, 100); | |
| 54 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | |
| 55 NULL, ui::wm::WINDOW_TYPE_PANEL, 0, rect); | |
| 56 test::TestShelfDelegate::instance()->AddShelfItem(window); | |
| 57 shelf_view_test_->RunMessageLoopUntilAnimationsDone(); | |
| 58 return window; | |
| 59 } | |
| 60 | |
| 61 private: | |
| 62 scoped_ptr<test::ShelfViewTestAPI> shelf_view_test_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(WindowCycleControllerTest); | |
| 65 }; | |
| 66 | |
| 67 TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) { | |
|
tdanderson
2014/05/01 18:51:39
Include TEST=... in the issue description with any
Nina
2014/05/01 20:41:16
This unittest class existed in the past. I had to
tdanderson
2014/05/01 21:58:33
Ok, so if you're not adding new tests, then you ca
| |
| 68 WindowCycleController* controller = | |
| 69 Shell::GetInstance()->window_cycle_controller(); | |
| 70 | |
| 71 // Cycling doesn't crash if there are no windows. | |
| 72 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 73 | |
| 74 // Create a single test window. | |
| 75 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | |
| 76 wm::ActivateWindow(window0.get()); | |
| 77 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 78 | |
| 79 // Cycling works for a single window, even though nothing changes. | |
| 80 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 81 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 82 } | |
| 83 | |
| 84 // Verifies if there is only one window and it isn't active that cycling | |
| 85 // activates it. | |
| 86 TEST_F(WindowCycleControllerTest, SingleWindowNotActive) { | |
| 87 WindowCycleController* controller = | |
| 88 Shell::GetInstance()->window_cycle_controller(); | |
| 89 | |
| 90 // Create a single test window. | |
| 91 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | |
| 92 wm::ActivateWindow(window0.get()); | |
| 93 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 94 | |
| 95 // Rotate focus, this should move focus to another window that isn't part of | |
| 96 // the default container. | |
| 97 Shell::GetInstance()->RotateFocus(Shell::FORWARD); | |
| 98 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); | |
| 99 | |
| 100 // Cycling should activate the window. | |
| 101 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 102 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 103 } | |
| 104 | |
| 105 TEST_F(WindowCycleControllerTest, HandleCycleWindow) { | |
| 106 WindowCycleController* controller = | |
| 107 Shell::GetInstance()->window_cycle_controller(); | |
| 108 | |
| 109 // Set up several windows to use to test cycling. Create them in reverse | |
| 110 // order so they are stacked 0 over 1 over 2. | |
| 111 scoped_ptr<Window> window2(CreateTestWindowInShellWithId(2)); | |
| 112 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | |
| 113 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | |
| 114 wm::ActivateWindow(window0.get()); | |
| 115 | |
| 116 // Simulate pressing and releasing Alt-tab. | |
| 117 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 118 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 119 | |
| 120 // Window lists should return the topmost window in front. | |
| 121 ASSERT_TRUE(controller->windows()); | |
| 122 ASSERT_EQ(3u, controller->windows()->windows().size()); | |
| 123 ASSERT_EQ(window0.get(), controller->windows()->windows()[0]); | |
| 124 ASSERT_EQ(window1.get(), controller->windows()->windows()[1]); | |
| 125 ASSERT_EQ(window2.get(), controller->windows()->windows()[2]); | |
| 126 | |
| 127 controller->AltKeyReleased(); | |
| 128 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 129 | |
| 130 // Pressing and releasing Alt-tab again should cycle back to the most- | |
| 131 // recently-used window in the current child order. | |
| 132 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 133 controller->AltKeyReleased(); | |
| 134 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 135 | |
| 136 // Pressing Alt-tab multiple times without releasing Alt should cycle through | |
| 137 // all the windows and wrap around. | |
| 138 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 139 EXPECT_TRUE(controller->IsCycling()); | |
| 140 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 141 | |
| 142 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 143 EXPECT_TRUE(controller->IsCycling()); | |
| 144 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 145 | |
| 146 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 147 EXPECT_TRUE(controller->IsCycling()); | |
| 148 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 149 | |
| 150 controller->AltKeyReleased(); | |
| 151 EXPECT_FALSE(controller->IsCycling()); | |
| 152 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 153 | |
| 154 // Reset our stacking order. | |
| 155 wm::ActivateWindow(window2.get()); | |
| 156 wm::ActivateWindow(window1.get()); | |
| 157 wm::ActivateWindow(window0.get()); | |
| 158 | |
| 159 // Likewise we can cycle backwards through all the windows. | |
| 160 controller->HandleCycleWindow(WindowCycleController::BACKWARD); | |
| 161 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 162 controller->HandleCycleWindow(WindowCycleController::BACKWARD); | |
| 163 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 164 controller->HandleCycleWindow(WindowCycleController::BACKWARD); | |
| 165 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 166 controller->AltKeyReleased(); | |
| 167 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 168 | |
| 169 // When the screen is locked, cycling window does not take effect. | |
| 170 Shell::GetInstance()->session_state_delegate()->LockScreen(); | |
| 171 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 172 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 173 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 174 controller->HandleCycleWindow(WindowCycleController::BACKWARD); | |
| 175 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 176 | |
| 177 Shell::GetInstance()->session_state_delegate()->UnlockScreen(); | |
| 178 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 179 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 180 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 181 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 182 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 183 | |
| 184 // When a modal window is active, cycling window does not take effect. | |
| 185 aura::Window* modal_container = | |
| 186 ash::Shell::GetContainer( | |
| 187 Shell::GetPrimaryRootWindow(), | |
| 188 kShellWindowId_SystemModalContainer); | |
| 189 scoped_ptr<Window> modal_window( | |
| 190 CreateTestWindowWithId(-2, modal_container)); | |
| 191 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | |
| 192 wm::ActivateWindow(modal_window.get()); | |
| 193 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get())); | |
| 194 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 195 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get())); | |
| 196 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); | |
| 197 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | |
| 198 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | |
| 199 controller->HandleCycleWindow(WindowCycleController::BACKWARD); | |
| 200 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get())); | |
| 201 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); | |
| 202 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | |
| 203 EXPECT_FALSE(wm::IsActiveWindow(window2.get())); | |
| 204 } | |
| 205 | |
| 206 // Cycles between a maximized and normal window. | |
| 207 TEST_F(WindowCycleControllerTest, MaximizedWindow) { | |
| 208 // Create a couple of test windows. | |
| 209 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | |
| 210 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | |
| 211 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 212 window1_state->Maximize(); | |
| 213 window1_state->Activate(); | |
| 214 EXPECT_TRUE(window1_state->IsActive()); | |
| 215 | |
| 216 // Rotate focus, this should move focus to window0. | |
| 217 WindowCycleController* controller = | |
| 218 Shell::GetInstance()->window_cycle_controller(); | |
| 219 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 220 EXPECT_TRUE(wm::GetWindowState(window0.get())->IsActive()); | |
| 221 | |
| 222 // One more time. | |
| 223 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 224 EXPECT_TRUE(window1_state->IsActive()); | |
| 225 } | |
| 226 | |
| 227 // Cycles to a minimized window. | |
| 228 TEST_F(WindowCycleControllerTest, Minimized) { | |
| 229 // Create a couple of test windows. | |
| 230 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | |
| 231 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | |
| 232 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); | |
| 233 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | |
| 234 | |
| 235 window1_state->Minimize(); | |
| 236 window0_state->Activate(); | |
| 237 EXPECT_TRUE(window0_state->IsActive()); | |
| 238 | |
| 239 // Rotate focus, this should move focus to window1 and unminimize it. | |
| 240 WindowCycleController* controller = | |
| 241 Shell::GetInstance()->window_cycle_controller(); | |
| 242 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 243 EXPECT_FALSE(window1_state->IsMinimized()); | |
| 244 EXPECT_TRUE(window1_state->IsActive()); | |
| 245 | |
| 246 // One more time back to w0. | |
| 247 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 248 EXPECT_TRUE(window0_state->IsActive()); | |
| 249 } | |
| 250 | |
| 251 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) { | |
| 252 WindowCycleController* controller = | |
| 253 Shell::GetInstance()->window_cycle_controller(); | |
| 254 | |
| 255 // Set up several windows to use to test cycling. | |
| 256 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | |
| 257 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | |
| 258 | |
| 259 Window* top_container = | |
| 260 Shell::GetContainer( | |
| 261 Shell::GetPrimaryRootWindow(), | |
| 262 kShellWindowId_AlwaysOnTopContainer); | |
| 263 scoped_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); | |
| 264 wm::ActivateWindow(window0.get()); | |
| 265 | |
| 266 // Simulate pressing and releasing Alt-tab. | |
| 267 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 268 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 269 | |
| 270 // Window lists should return the topmost window in front. | |
| 271 ASSERT_TRUE(controller->windows()); | |
| 272 ASSERT_EQ(3u, controller->windows()->windows().size()); | |
| 273 EXPECT_EQ(window0.get(), controller->windows()->windows()[0]); | |
| 274 EXPECT_EQ(window2.get(), controller->windows()->windows()[1]); | |
| 275 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); | |
| 276 | |
| 277 controller->AltKeyReleased(); | |
| 278 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 279 | |
| 280 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 281 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 282 | |
| 283 controller->AltKeyReleased(); | |
| 284 | |
| 285 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 286 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 287 | |
| 288 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 289 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 290 | |
| 291 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 292 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 293 } | |
| 294 | |
| 295 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultiWindow) { | |
| 296 WindowCycleController* controller = | |
| 297 Shell::GetInstance()->window_cycle_controller(); | |
| 298 | |
| 299 // Set up several windows to use to test cycling. | |
| 300 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | |
| 301 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | |
| 302 | |
| 303 Window* top_container = | |
| 304 Shell::GetContainer( | |
| 305 Shell::GetPrimaryRootWindow(), | |
| 306 kShellWindowId_AlwaysOnTopContainer); | |
| 307 scoped_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); | |
| 308 scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container)); | |
| 309 wm::ActivateWindow(window0.get()); | |
| 310 | |
| 311 // Simulate pressing and releasing Alt-tab. | |
| 312 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 313 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 314 | |
| 315 // Window lists should return the topmost window in front. | |
| 316 ASSERT_TRUE(controller->windows()); | |
| 317 ASSERT_EQ(4u, controller->windows()->windows().size()); | |
| 318 EXPECT_EQ(window0.get(), controller->windows()->windows()[0]); | |
| 319 EXPECT_EQ(window3.get(), controller->windows()->windows()[1]); | |
| 320 EXPECT_EQ(window2.get(), controller->windows()->windows()[2]); | |
| 321 EXPECT_EQ(window1.get(), controller->windows()->windows()[3]); | |
| 322 | |
| 323 controller->AltKeyReleased(); | |
| 324 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); | |
| 325 | |
| 326 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 327 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 328 | |
| 329 controller->AltKeyReleased(); | |
| 330 | |
| 331 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 332 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); | |
| 333 | |
| 334 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 335 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 336 | |
| 337 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 338 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 339 | |
| 340 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 341 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 342 } | |
| 343 | |
| 344 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultipleRootWindows) { | |
| 345 if (!SupportsMultipleDisplays()) | |
| 346 return; | |
| 347 | |
| 348 // Set up a second root window | |
| 349 UpdateDisplay("1000x600,600x400"); | |
| 350 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | |
| 351 ASSERT_EQ(2U, root_windows.size()); | |
| 352 | |
| 353 WindowCycleController* controller = | |
| 354 Shell::GetInstance()->window_cycle_controller(); | |
| 355 | |
| 356 Shell::GetInstance()->set_target_root_window(root_windows[0]); | |
| 357 | |
| 358 // Create two windows in the primary root. | |
| 359 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | |
| 360 EXPECT_EQ(root_windows[0], window0->GetRootWindow()); | |
| 361 Window* top_container0 = | |
| 362 Shell::GetContainer( | |
| 363 root_windows[0], | |
| 364 kShellWindowId_AlwaysOnTopContainer); | |
| 365 scoped_ptr<Window> window1(CreateTestWindowWithId(1, top_container0)); | |
| 366 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); | |
| 367 | |
| 368 // And two on the secondary root. | |
| 369 Shell::GetInstance()->set_target_root_window(root_windows[1]); | |
| 370 scoped_ptr<Window> window2(CreateTestWindowInShellWithId(2)); | |
| 371 EXPECT_EQ(root_windows[1], window2->GetRootWindow()); | |
| 372 | |
| 373 Window* top_container1 = | |
| 374 Shell::GetContainer( | |
| 375 root_windows[1], | |
| 376 kShellWindowId_AlwaysOnTopContainer); | |
| 377 scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container1)); | |
| 378 EXPECT_EQ(root_windows[1], window3->GetRootWindow()); | |
| 379 | |
| 380 // Move the active root window to the secondary. | |
| 381 Shell::GetInstance()->set_target_root_window(root_windows[1]); | |
| 382 | |
| 383 wm::ActivateWindow(window2.get()); | |
| 384 | |
| 385 EXPECT_EQ(root_windows[0], window0->GetRootWindow()); | |
| 386 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); | |
| 387 EXPECT_EQ(root_windows[1], window2->GetRootWindow()); | |
| 388 EXPECT_EQ(root_windows[1], window3->GetRootWindow()); | |
| 389 | |
| 390 // Simulate pressing and releasing Alt-tab. | |
| 391 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 392 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 393 | |
| 394 // Window lists should return the topmost window in front. | |
| 395 ASSERT_TRUE(controller->windows()); | |
| 396 ASSERT_EQ(4u, controller->windows()->windows().size()); | |
| 397 EXPECT_EQ(window2.get(), controller->windows()->windows()[0]); | |
| 398 EXPECT_EQ(window3.get(), controller->windows()->windows()[1]); | |
| 399 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); | |
| 400 EXPECT_EQ(window0.get(), controller->windows()->windows()[3]); | |
| 401 | |
| 402 controller->AltKeyReleased(); | |
| 403 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); | |
| 404 | |
| 405 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 406 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 407 | |
| 408 controller->AltKeyReleased(); | |
| 409 | |
| 410 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 411 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); | |
| 412 | |
| 413 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 414 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 415 | |
| 416 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 417 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 418 | |
| 419 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 420 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 421 } | |
| 422 | |
| 423 TEST_F(WindowCycleControllerTest, MostRecentlyUsed) { | |
| 424 WindowCycleController* controller = | |
| 425 Shell::GetInstance()->window_cycle_controller(); | |
| 426 | |
| 427 // Set up several windows to use to test cycling. | |
| 428 scoped_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | |
| 429 scoped_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | |
| 430 scoped_ptr<Window> window2(CreateTestWindowInShellWithId(2)); | |
| 431 | |
| 432 wm::ActivateWindow(window0.get()); | |
| 433 | |
| 434 // Simulate pressing and releasing Alt-tab. | |
| 435 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 436 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 437 | |
| 438 // Window lists should return the topmost window in front. | |
| 439 ASSERT_TRUE(controller->windows()); | |
| 440 ASSERT_EQ(3u, controller->windows()->windows().size()); | |
| 441 EXPECT_EQ(window0.get(), controller->windows()->windows()[0]); | |
| 442 EXPECT_EQ(window2.get(), controller->windows()->windows()[1]); | |
| 443 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); | |
| 444 | |
| 445 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 446 controller->AltKeyReleased(); | |
| 447 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 448 | |
| 449 | |
| 450 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 451 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 452 | |
| 453 controller->AltKeyReleased(); | |
| 454 | |
| 455 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 456 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | |
| 457 | |
| 458 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 459 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 460 | |
| 461 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 462 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 463 } | |
| 464 | |
| 465 // Tests that beginning window selection hides the app list. | |
| 466 TEST_F(WindowCycleControllerTest, SelectingHidesAppList) { | |
| 467 WindowCycleController* controller = | |
| 468 Shell::GetInstance()->window_cycle_controller(); | |
| 469 | |
| 470 gfx::Rect bounds(0, 0, 400, 400); | |
| 471 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | |
| 472 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | |
| 473 Shell::GetInstance()->ToggleAppList(NULL); | |
| 474 EXPECT_TRUE(Shell::GetInstance()->GetAppListTargetVisibility()); | |
| 475 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 476 EXPECT_FALSE(Shell::GetInstance()->GetAppListTargetVisibility()); | |
| 477 } | |
| 478 | |
| 479 // Tests that cycling through windows shows and minimizes windows as they | |
| 480 // are passed. | |
| 481 TEST_F(WindowCycleControllerTest, CyclePreservesMinimization) { | |
| 482 WindowCycleController* controller = | |
| 483 Shell::GetInstance()->window_cycle_controller(); | |
| 484 | |
| 485 gfx::Rect bounds(0, 0, 400, 400); | |
| 486 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | |
| 487 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | |
| 488 wm::ActivateWindow(window1.get()); | |
| 489 wm::GetWindowState(window1.get())->Minimize(); | |
| 490 wm::ActivateWindow(window0.get()); | |
| 491 EXPECT_TRUE(wm::IsWindowMinimized(window1.get())); | |
| 492 | |
| 493 // On window 2. | |
| 494 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 495 EXPECT_FALSE(wm::IsWindowMinimized(window1.get())); | |
| 496 | |
| 497 // Back on window 1. | |
| 498 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 499 EXPECT_TRUE(wm::IsWindowMinimized(window1.get())); | |
| 500 | |
| 501 controller->AltKeyReleased(); | |
| 502 | |
| 503 EXPECT_TRUE(wm::IsWindowMinimized(window1.get())); | |
| 504 } | |
| 505 | |
| 506 // Tests cycles between panel and normal windows. | |
| 507 TEST_F(WindowCycleControllerTest, CyclePanels) { | |
| 508 WindowCycleController* controller = | |
| 509 Shell::GetInstance()->window_cycle_controller(); | |
| 510 | |
| 511 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | |
| 512 scoped_ptr<aura::Window> panel0(CreatePanelWindow()); | |
| 513 scoped_ptr<aura::Window> panel1(CreatePanelWindow()); | |
| 514 wm::ActivateWindow(window0.get()); | |
| 515 wm::ActivateWindow(panel1.get()); | |
| 516 wm::ActivateWindow(panel0.get()); | |
| 517 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); | |
| 518 | |
| 519 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 520 controller->AltKeyReleased(); | |
| 521 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); | |
| 522 | |
| 523 // Cycling again should select the most recently used panel. | |
| 524 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 525 controller->AltKeyReleased(); | |
| 526 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); | |
| 527 | |
| 528 // Cycling twice again should select the first window. | |
| 529 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 530 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 531 controller->AltKeyReleased(); | |
| 532 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 533 } | |
| 534 | |
| 535 // Tests cycles between panel and normal windows. | |
| 536 TEST_F(WindowCycleControllerTest, CyclePanelsDestroyed) { | |
| 537 WindowCycleController* controller = | |
| 538 Shell::GetInstance()->window_cycle_controller(); | |
| 539 | |
| 540 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | |
| 541 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | |
| 542 scoped_ptr<aura::Window> window2(CreateTestWindowInShellWithId(2)); | |
| 543 scoped_ptr<aura::Window> panel0(CreatePanelWindow()); | |
| 544 scoped_ptr<aura::Window> panel1(CreatePanelWindow()); | |
| 545 wm::ActivateWindow(window2.get()); | |
| 546 wm::ActivateWindow(panel1.get()); | |
| 547 wm::ActivateWindow(panel0.get()); | |
| 548 wm::ActivateWindow(window1.get()); | |
| 549 wm::ActivateWindow(window0.get()); | |
| 550 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 551 | |
| 552 // Cycling once highlights window2. | |
| 553 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 554 // All panels are destroyed. | |
| 555 panel0.reset(); | |
| 556 panel1.reset(); | |
| 557 // Cycling again should now select window3. | |
| 558 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 559 controller->AltKeyReleased(); | |
| 560 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | |
| 561 } | |
| 562 | |
| 563 // Tests cycles between panel and normal windows. | |
| 564 TEST_F(WindowCycleControllerTest, CycleMruPanelDestroyed) { | |
| 565 WindowCycleController* controller = | |
| 566 Shell::GetInstance()->window_cycle_controller(); | |
| 567 | |
| 568 scoped_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | |
| 569 scoped_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | |
| 570 scoped_ptr<aura::Window> panel0(CreatePanelWindow()); | |
| 571 scoped_ptr<aura::Window> panel1(CreatePanelWindow()); | |
| 572 wm::ActivateWindow(panel1.get()); | |
| 573 wm::ActivateWindow(panel0.get()); | |
| 574 wm::ActivateWindow(window1.get()); | |
| 575 wm::ActivateWindow(window0.get()); | |
| 576 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | |
| 577 | |
| 578 // Cycling once highlights window2. | |
| 579 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 580 | |
| 581 // Panel 1 is the next item as the MRU panel, removing it should make panel 2 | |
| 582 // the next window to be selected. | |
| 583 panel0.reset(); | |
| 584 // Cycling again should now select window3. | |
| 585 controller->HandleCycleWindow(WindowCycleController::FORWARD); | |
| 586 controller->AltKeyReleased(); | |
| 587 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); | |
| 588 } | |
| 589 | |
| 590 } // namespace ash | |
| OLD | NEW |