| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/wm/window_cycle_controller.h" | 5 #include "ash/common/wm/window_cycle_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "ash/aura/wm_window_aura.h" | 10 #include "ash/aura/wm_window_aura.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 163 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 164 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 164 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 165 | 165 |
| 166 // Window lists should return the topmost window in front. | 166 // Window lists should return the topmost window in front. |
| 167 ASSERT_TRUE(controller->window_cycle_list()); | 167 ASSERT_TRUE(controller->window_cycle_list()); |
| 168 ASSERT_EQ(3u, GetWindows(controller).size()); | 168 ASSERT_EQ(3u, GetWindows(controller).size()); |
| 169 ASSERT_EQ(window0.get(), GetWindows(controller)[0]); | 169 ASSERT_EQ(window0.get(), GetWindows(controller)[0]); |
| 170 ASSERT_EQ(window1.get(), GetWindows(controller)[1]); | 170 ASSERT_EQ(window1.get(), GetWindows(controller)[1]); |
| 171 ASSERT_EQ(window2.get(), GetWindows(controller)[2]); | 171 ASSERT_EQ(window2.get(), GetWindows(controller)[2]); |
| 172 | 172 |
| 173 controller->StopCycling(); | 173 controller->CompleteCycling(); |
| 174 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 174 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 175 | 175 |
| 176 // Pressing and releasing Alt-tab again should cycle back to the most- | 176 // Pressing and releasing Alt-tab again should cycle back to the most- |
| 177 // recently-used window in the current child order. | 177 // recently-used window in the current child order. |
| 178 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 178 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 179 controller->StopCycling(); | 179 controller->CompleteCycling(); |
| 180 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 181 |
| 182 // Cancelled cycling shouldn't move the active window. |
| 183 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 184 controller->CancelCycling(); |
| 180 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 185 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 181 | 186 |
| 182 // Pressing Alt-tab multiple times without releasing Alt should cycle through | 187 // Pressing Alt-tab multiple times without releasing Alt should cycle through |
| 183 // all the windows and wrap around. | 188 // all the windows and wrap around. |
| 184 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 189 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 185 EXPECT_TRUE(controller->IsCycling()); | 190 EXPECT_TRUE(controller->IsCycling()); |
| 186 | 191 |
| 187 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 192 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 188 EXPECT_TRUE(controller->IsCycling()); | 193 EXPECT_TRUE(controller->IsCycling()); |
| 189 | 194 |
| 190 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 195 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 191 EXPECT_TRUE(controller->IsCycling()); | 196 EXPECT_TRUE(controller->IsCycling()); |
| 192 | 197 |
| 193 controller->StopCycling(); | 198 controller->CompleteCycling(); |
| 194 EXPECT_FALSE(controller->IsCycling()); | 199 EXPECT_FALSE(controller->IsCycling()); |
| 195 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 200 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 196 | 201 |
| 197 // Reset our stacking order. | 202 // Reset our stacking order. |
| 198 wm::ActivateWindow(window2.get()); | 203 wm::ActivateWindow(window2.get()); |
| 199 wm::ActivateWindow(window1.get()); | 204 wm::ActivateWindow(window1.get()); |
| 200 wm::ActivateWindow(window0.get()); | 205 wm::ActivateWindow(window0.get()); |
| 201 | 206 |
| 202 // Likewise we can cycle backwards through the windows. | 207 // Likewise we can cycle backwards through the windows. |
| 203 controller->HandleCycleWindow(WindowCycleController::BACKWARD); | 208 controller->HandleCycleWindow(WindowCycleController::BACKWARD); |
| 204 controller->HandleCycleWindow(WindowCycleController::BACKWARD); | 209 controller->HandleCycleWindow(WindowCycleController::BACKWARD); |
| 205 controller->StopCycling(); | 210 controller->CompleteCycling(); |
| 206 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 211 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 207 | 212 |
| 208 // Reset our stacking order. | 213 // Reset our stacking order. |
| 209 wm::ActivateWindow(window2.get()); | 214 wm::ActivateWindow(window2.get()); |
| 210 wm::ActivateWindow(window1.get()); | 215 wm::ActivateWindow(window1.get()); |
| 211 wm::ActivateWindow(window0.get()); | 216 wm::ActivateWindow(window0.get()); |
| 212 | 217 |
| 213 // When the screen is locked, cycling window does not take effect. | 218 // When the screen is locked, cycling window does not take effect. |
| 214 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); | 219 WmShell::Get()->GetSessionStateDelegate()->LockScreen(); |
| 215 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 220 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 216 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 221 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 217 EXPECT_FALSE(controller->IsCycling()); | 222 EXPECT_FALSE(controller->IsCycling()); |
| 218 | 223 |
| 219 // Unlock, it works again. | 224 // Unlock, it works again. |
| 220 WmShell::Get()->GetSessionStateDelegate()->UnlockScreen(); | 225 WmShell::Get()->GetSessionStateDelegate()->UnlockScreen(); |
| 221 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 226 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 222 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 227 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 223 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 228 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 224 controller->StopCycling(); | 229 controller->CompleteCycling(); |
| 225 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | 230 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 226 | 231 |
| 227 // When a modal window is active, cycling window does not take effect. | 232 // When a modal window is active, cycling window does not take effect. |
| 228 aura::Window* modal_container = Shell::GetContainer( | 233 aura::Window* modal_container = Shell::GetContainer( |
| 229 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer); | 234 Shell::GetPrimaryRootWindow(), kShellWindowId_SystemModalContainer); |
| 230 std::unique_ptr<Window> modal_window( | 235 std::unique_ptr<Window> modal_window( |
| 231 CreateTestWindowWithId(-2, modal_container)); | 236 CreateTestWindowWithId(-2, modal_container)); |
| 232 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); | 237 modal_window->SetProperty(aura::client::kModalKey, ui::MODAL_TYPE_SYSTEM); |
| 233 wm::ActivateWindow(modal_window.get()); | 238 wm::ActivateWindow(modal_window.get()); |
| 234 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get())); | 239 EXPECT_TRUE(wm::IsActiveWindow(modal_window.get())); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 252 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 257 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 253 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 258 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 254 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 259 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 255 window1_state->Maximize(); | 260 window1_state->Maximize(); |
| 256 window1_state->Activate(); | 261 window1_state->Activate(); |
| 257 EXPECT_TRUE(window1_state->IsActive()); | 262 EXPECT_TRUE(window1_state->IsActive()); |
| 258 | 263 |
| 259 // Rotate focus, this should move focus to window0. | 264 // Rotate focus, this should move focus to window0. |
| 260 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 265 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 261 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 266 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 262 controller->StopCycling(); | 267 controller->CompleteCycling(); |
| 263 EXPECT_TRUE(wm::GetWindowState(window0.get())->IsActive()); | 268 EXPECT_TRUE(wm::GetWindowState(window0.get())->IsActive()); |
| 264 EXPECT_FALSE(window1_state->IsActive()); | 269 EXPECT_FALSE(window1_state->IsActive()); |
| 265 | 270 |
| 266 // One more time. | 271 // One more time. |
| 267 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 272 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 268 controller->StopCycling(); | 273 controller->CompleteCycling(); |
| 269 EXPECT_TRUE(window1_state->IsActive()); | 274 EXPECT_TRUE(window1_state->IsActive()); |
| 270 } | 275 } |
| 271 | 276 |
| 272 // Cycles to a minimized window. | 277 // Cycles to a minimized window. |
| 273 TEST_F(WindowCycleControllerTest, Minimized) { | 278 TEST_F(WindowCycleControllerTest, Minimized) { |
| 274 // Create a couple of test windows. | 279 // Create a couple of test windows. |
| 275 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 280 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 276 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 281 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 277 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); | 282 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); |
| 278 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 283 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 279 | 284 |
| 280 window1_state->Minimize(); | 285 window1_state->Minimize(); |
| 281 window0_state->Activate(); | 286 window0_state->Activate(); |
| 282 EXPECT_TRUE(window0_state->IsActive()); | 287 EXPECT_TRUE(window0_state->IsActive()); |
| 283 | 288 |
| 284 // Rotate focus, this should move focus to window1 and unminimize it. | 289 // Rotate focus, this should move focus to window1 and unminimize it. |
| 285 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 290 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 286 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 291 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 287 controller->StopCycling(); | 292 controller->CompleteCycling(); |
| 288 EXPECT_FALSE(window0_state->IsActive()); | 293 EXPECT_FALSE(window0_state->IsActive()); |
| 289 EXPECT_FALSE(window1_state->IsMinimized()); | 294 EXPECT_FALSE(window1_state->IsMinimized()); |
| 290 EXPECT_TRUE(window1_state->IsActive()); | 295 EXPECT_TRUE(window1_state->IsActive()); |
| 291 | 296 |
| 292 // One more time back to w0. | 297 // One more time back to w0. |
| 293 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 298 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 294 controller->StopCycling(); | 299 controller->CompleteCycling(); |
| 295 EXPECT_TRUE(window0_state->IsActive()); | 300 EXPECT_TRUE(window0_state->IsActive()); |
| 296 } | 301 } |
| 297 | 302 |
| 298 // Tests that when all windows are minimized, cycling starts with the first one | 303 // Tests that when all windows are minimized, cycling starts with the first one |
| 299 // rather than the second. | 304 // rather than the second. |
| 300 TEST_F(WindowCycleControllerTest, AllAreMinimized) { | 305 TEST_F(WindowCycleControllerTest, AllAreMinimized) { |
| 301 // Create a couple of test windows. | 306 // Create a couple of test windows. |
| 302 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 307 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 303 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 308 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 304 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); | 309 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); |
| 305 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 310 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 306 | 311 |
| 307 window0_state->Minimize(); | 312 window0_state->Minimize(); |
| 308 window1_state->Minimize(); | 313 window1_state->Minimize(); |
| 309 | 314 |
| 310 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 315 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 311 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 316 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 312 controller->StopCycling(); | 317 controller->CompleteCycling(); |
| 313 EXPECT_TRUE(window0_state->IsActive()); | 318 EXPECT_TRUE(window0_state->IsActive()); |
| 314 EXPECT_FALSE(window0_state->IsMinimized()); | 319 EXPECT_FALSE(window0_state->IsMinimized()); |
| 315 EXPECT_TRUE(window1_state->IsMinimized()); | 320 EXPECT_TRUE(window1_state->IsMinimized()); |
| 316 | 321 |
| 317 // But it's business as usual when cycling backwards. | 322 // But it's business as usual when cycling backwards. |
| 318 window0_state->Minimize(); | 323 window0_state->Minimize(); |
| 319 window1_state->Minimize(); | 324 window1_state->Minimize(); |
| 320 controller->HandleCycleWindow(WindowCycleController::BACKWARD); | 325 controller->HandleCycleWindow(WindowCycleController::BACKWARD); |
| 321 controller->StopCycling(); | 326 controller->CompleteCycling(); |
| 322 EXPECT_TRUE(window0_state->IsMinimized()); | 327 EXPECT_TRUE(window0_state->IsMinimized()); |
| 323 EXPECT_TRUE(window1_state->IsActive()); | 328 EXPECT_TRUE(window1_state->IsActive()); |
| 324 EXPECT_FALSE(window1_state->IsMinimized()); | 329 EXPECT_FALSE(window1_state->IsMinimized()); |
| 325 } | 330 } |
| 326 | 331 |
| 327 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) { | 332 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) { |
| 328 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 333 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 329 | 334 |
| 330 // Set up several windows to use to test cycling. | 335 // Set up several windows to use to test cycling. |
| 331 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 336 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 332 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 337 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 333 | 338 |
| 334 Window* top_container = Shell::GetContainer( | 339 Window* top_container = Shell::GetContainer( |
| 335 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); | 340 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); |
| 336 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); | 341 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); |
| 337 wm::ActivateWindow(window0.get()); | 342 wm::ActivateWindow(window0.get()); |
| 338 | 343 |
| 339 // Simulate pressing and releasing Alt-tab. | 344 // Simulate pressing and releasing Alt-tab. |
| 340 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 345 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 341 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 346 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 342 | 347 |
| 343 // Window lists should return the topmost window in front. | 348 // Window lists should return the topmost window in front. |
| 344 ASSERT_TRUE(controller->window_cycle_list()); | 349 ASSERT_TRUE(controller->window_cycle_list()); |
| 345 ASSERT_EQ(3u, GetWindows(controller).size()); | 350 ASSERT_EQ(3u, GetWindows(controller).size()); |
| 346 EXPECT_EQ(window0.get(), GetWindows(controller)[0]); | 351 EXPECT_EQ(window0.get(), GetWindows(controller)[0]); |
| 347 EXPECT_EQ(window2.get(), GetWindows(controller)[1]); | 352 EXPECT_EQ(window2.get(), GetWindows(controller)[1]); |
| 348 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); | 353 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); |
| 349 | 354 |
| 350 controller->StopCycling(); | 355 controller->CompleteCycling(); |
| 351 } | 356 } |
| 352 | 357 |
| 353 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultiWindow) { | 358 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultiWindow) { |
| 354 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 359 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 355 | 360 |
| 356 // Set up several windows to use to test cycling. | 361 // Set up several windows to use to test cycling. |
| 357 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 362 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 358 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 363 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 359 | 364 |
| 360 Window* top_container = Shell::GetContainer( | 365 Window* top_container = Shell::GetContainer( |
| 361 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); | 366 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); |
| 362 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); | 367 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); |
| 363 std::unique_ptr<Window> window3(CreateTestWindowWithId(3, top_container)); | 368 std::unique_ptr<Window> window3(CreateTestWindowWithId(3, top_container)); |
| 364 wm::ActivateWindow(window0.get()); | 369 wm::ActivateWindow(window0.get()); |
| 365 | 370 |
| 366 // Simulate pressing and releasing Alt-tab. | 371 // Simulate pressing and releasing Alt-tab. |
| 367 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 372 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 368 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 373 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 369 | 374 |
| 370 // Window lists should return the topmost window in front. | 375 // Window lists should return the topmost window in front. |
| 371 ASSERT_TRUE(controller->window_cycle_list()); | 376 ASSERT_TRUE(controller->window_cycle_list()); |
| 372 ASSERT_EQ(4u, GetWindows(controller).size()); | 377 ASSERT_EQ(4u, GetWindows(controller).size()); |
| 373 EXPECT_EQ(window0.get(), GetWindows(controller)[0]); | 378 EXPECT_EQ(window0.get(), GetWindows(controller)[0]); |
| 374 EXPECT_EQ(window3.get(), GetWindows(controller)[1]); | 379 EXPECT_EQ(window3.get(), GetWindows(controller)[1]); |
| 375 EXPECT_EQ(window2.get(), GetWindows(controller)[2]); | 380 EXPECT_EQ(window2.get(), GetWindows(controller)[2]); |
| 376 EXPECT_EQ(window1.get(), GetWindows(controller)[3]); | 381 EXPECT_EQ(window1.get(), GetWindows(controller)[3]); |
| 377 | 382 |
| 378 controller->StopCycling(); | 383 controller->CompleteCycling(); |
| 379 } | 384 } |
| 380 | 385 |
| 381 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultipleRootWindows) { | 386 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultipleRootWindows) { |
| 382 if (!SupportsMultipleDisplays()) | 387 if (!SupportsMultipleDisplays()) |
| 383 return; | 388 return; |
| 384 | 389 |
| 385 // Set up a second root window | 390 // Set up a second root window |
| 386 UpdateDisplay("1000x600,600x400"); | 391 UpdateDisplay("1000x600,600x400"); |
| 387 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 392 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 388 ASSERT_EQ(2U, root_windows.size()); | 393 ASSERT_EQ(2U, root_windows.size()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 425 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 421 | 426 |
| 422 // Window lists should return the topmost window in front. | 427 // Window lists should return the topmost window in front. |
| 423 ASSERT_TRUE(controller->window_cycle_list()); | 428 ASSERT_TRUE(controller->window_cycle_list()); |
| 424 ASSERT_EQ(4u, GetWindows(controller).size()); | 429 ASSERT_EQ(4u, GetWindows(controller).size()); |
| 425 EXPECT_EQ(window2.get(), GetWindows(controller)[0]); | 430 EXPECT_EQ(window2.get(), GetWindows(controller)[0]); |
| 426 EXPECT_EQ(window3.get(), GetWindows(controller)[1]); | 431 EXPECT_EQ(window3.get(), GetWindows(controller)[1]); |
| 427 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); | 432 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); |
| 428 EXPECT_EQ(window0.get(), GetWindows(controller)[3]); | 433 EXPECT_EQ(window0.get(), GetWindows(controller)[3]); |
| 429 | 434 |
| 430 controller->StopCycling(); | 435 controller->CompleteCycling(); |
| 431 } | 436 } |
| 432 | 437 |
| 433 TEST_F(WindowCycleControllerTest, MostRecentlyUsed) { | 438 TEST_F(WindowCycleControllerTest, MostRecentlyUsed) { |
| 434 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 439 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 435 | 440 |
| 436 // Set up several windows to use to test cycling. | 441 // Set up several windows to use to test cycling. |
| 437 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 442 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 438 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 443 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 439 std::unique_ptr<Window> window2(CreateTestWindowInShellWithId(2)); | 444 std::unique_ptr<Window> window2(CreateTestWindowInShellWithId(2)); |
| 440 | 445 |
| 441 wm::ActivateWindow(window0.get()); | 446 wm::ActivateWindow(window0.get()); |
| 442 | 447 |
| 443 // Simulate pressing and releasing Alt-tab. | 448 // Simulate pressing and releasing Alt-tab. |
| 444 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 449 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 445 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 450 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 446 | 451 |
| 447 // Window lists should return the topmost window in front. | 452 // Window lists should return the topmost window in front. |
| 448 ASSERT_TRUE(controller->window_cycle_list()); | 453 ASSERT_TRUE(controller->window_cycle_list()); |
| 449 ASSERT_EQ(3u, GetWindows(controller).size()); | 454 ASSERT_EQ(3u, GetWindows(controller).size()); |
| 450 EXPECT_EQ(window0.get(), GetWindows(controller)[0]); | 455 EXPECT_EQ(window0.get(), GetWindows(controller)[0]); |
| 451 EXPECT_EQ(window2.get(), GetWindows(controller)[1]); | 456 EXPECT_EQ(window2.get(), GetWindows(controller)[1]); |
| 452 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); | 457 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); |
| 453 | 458 |
| 454 // Cycling through then stopping the cycling will activate a window. | 459 // Cycling through then stopping the cycling will activate a window. |
| 455 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 460 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 456 controller->StopCycling(); | 461 controller->CompleteCycling(); |
| 457 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 462 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 458 | 463 |
| 459 // Cycling alone (without StopCycling()) doesn't activate. | 464 // Cycling alone (without CompleteCycling()) doesn't activate. |
| 460 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 465 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 461 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); | 466 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); |
| 462 | 467 |
| 463 // Showing the Alt+Tab UI does however deactivate the erstwhile active window. | 468 // Showing the Alt+Tab UI does however deactivate the erstwhile active window. |
| 464 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 469 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
| 465 | 470 |
| 466 controller->StopCycling(); | 471 controller->CompleteCycling(); |
| 467 } | 472 } |
| 468 | 473 |
| 469 // Tests that beginning window selection hides the app list. | 474 // Tests that beginning window selection hides the app list. |
| 470 TEST_F(WindowCycleControllerTest, SelectingHidesAppList) { | 475 TEST_F(WindowCycleControllerTest, SelectingHidesAppList) { |
| 471 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 476 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 472 | 477 |
| 473 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 478 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 474 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 479 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 475 WmShell::Get()->ShowAppList(); | 480 WmShell::Get()->ShowAppList(); |
| 476 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); | 481 EXPECT_TRUE(WmShell::Get()->GetAppListTargetVisibility()); |
| 477 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 482 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 478 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); | 483 EXPECT_FALSE(WmShell::Get()->GetAppListTargetVisibility()); |
| 479 | 484 |
| 480 // Make sure that dismissing the app list this way doesn't pass activation | 485 // Make sure that dismissing the app list this way doesn't pass activation |
| 481 // to a different window. | 486 // to a different window. |
| 482 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); | 487 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); |
| 483 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 488 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
| 484 | 489 |
| 485 controller->StopCycling(); | 490 controller->CompleteCycling(); |
| 486 } | 491 } |
| 487 | 492 |
| 488 // Tests that cycling through windows doesn't change their minimized state. | 493 // Tests that cycling through windows doesn't change their minimized state. |
| 489 TEST_F(WindowCycleControllerTest, CyclePreservesMinimization) { | 494 TEST_F(WindowCycleControllerTest, CyclePreservesMinimization) { |
| 490 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 495 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 491 | 496 |
| 492 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 497 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 493 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 498 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 494 wm::ActivateWindow(window1.get()); | 499 wm::ActivateWindow(window1.get()); |
| 495 wm::GetWindowState(window1.get())->Minimize(); | 500 wm::GetWindowState(window1.get())->Minimize(); |
| 496 wm::ActivateWindow(window0.get()); | 501 wm::ActivateWindow(window0.get()); |
| 497 EXPECT_TRUE(IsWindowMinimized(window1.get())); | 502 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 498 | 503 |
| 499 // On window 2. | 504 // On window 2. |
| 500 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 505 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 501 EXPECT_TRUE(IsWindowMinimized(window1.get())); | 506 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 502 | 507 |
| 503 // Back on window 1. | 508 // Back on window 1. |
| 504 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 509 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 505 EXPECT_TRUE(IsWindowMinimized(window1.get())); | 510 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 506 | 511 |
| 507 controller->StopCycling(); | 512 controller->CompleteCycling(); |
| 508 | 513 |
| 509 EXPECT_TRUE(IsWindowMinimized(window1.get())); | 514 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 510 } | 515 } |
| 511 | 516 |
| 512 // Tests cycles between panel and normal windows. | 517 // Tests cycles between panel and normal windows. |
| 513 TEST_F(WindowCycleControllerTest, CyclePanels) { | 518 TEST_F(WindowCycleControllerTest, CyclePanels) { |
| 514 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 519 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 515 | 520 |
| 516 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 521 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 517 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); | 522 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); |
| 518 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); | 523 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); |
| 519 wm::ActivateWindow(window0.get()); | 524 wm::ActivateWindow(window0.get()); |
| 520 wm::ActivateWindow(panel1.get()); | 525 wm::ActivateWindow(panel1.get()); |
| 521 wm::ActivateWindow(panel0.get()); | 526 wm::ActivateWindow(panel0.get()); |
| 522 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); | 527 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); |
| 523 | 528 |
| 524 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 529 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 525 controller->StopCycling(); | 530 controller->CompleteCycling(); |
| 526 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); | 531 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); |
| 527 | 532 |
| 528 // Cycling again should select the most recently used panel. | 533 // Cycling again should select the most recently used panel. |
| 529 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 534 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 530 controller->StopCycling(); | 535 controller->CompleteCycling(); |
| 531 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); | 536 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); |
| 532 | 537 |
| 533 // Cycling twice again should select the first window. | 538 // Cycling twice again should select the first window. |
| 534 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 539 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 535 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 540 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 536 controller->StopCycling(); | 541 controller->CompleteCycling(); |
| 537 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 542 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 538 } | 543 } |
| 539 | 544 |
| 540 // Tests cycles between panel and normal windows. | 545 // Tests cycles between panel and normal windows. |
| 541 TEST_F(WindowCycleControllerTest, CyclePanelsDestroyed) { | 546 TEST_F(WindowCycleControllerTest, CyclePanelsDestroyed) { |
| 542 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 547 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 543 | 548 |
| 544 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 549 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 545 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 550 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 546 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(2)); | 551 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(2)); |
| 547 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); | 552 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); |
| 548 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); | 553 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); |
| 549 wm::ActivateWindow(window2.get()); | 554 wm::ActivateWindow(window2.get()); |
| 550 wm::ActivateWindow(panel1.get()); | 555 wm::ActivateWindow(panel1.get()); |
| 551 wm::ActivateWindow(panel0.get()); | 556 wm::ActivateWindow(panel0.get()); |
| 552 wm::ActivateWindow(window1.get()); | 557 wm::ActivateWindow(window1.get()); |
| 553 wm::ActivateWindow(window0.get()); | 558 wm::ActivateWindow(window0.get()); |
| 554 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 559 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 555 | 560 |
| 556 // Cycling once highlights window2. | 561 // Cycling once highlights window2. |
| 557 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 562 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 558 // All panels are destroyed. | 563 // All panels are destroyed. |
| 559 panel0.reset(); | 564 panel0.reset(); |
| 560 panel1.reset(); | 565 panel1.reset(); |
| 561 // Cycling again should now select window2. | 566 // Cycling again should now select window2. |
| 562 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 567 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 563 controller->StopCycling(); | 568 controller->CompleteCycling(); |
| 564 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | 569 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 565 } | 570 } |
| 566 | 571 |
| 567 // Tests cycles between panel and normal windows. | 572 // Tests cycles between panel and normal windows. |
| 568 TEST_F(WindowCycleControllerTest, CycleMruPanelDestroyed) { | 573 TEST_F(WindowCycleControllerTest, CycleMruPanelDestroyed) { |
| 569 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 574 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 570 | 575 |
| 571 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 576 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 572 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 577 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 573 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); | 578 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); |
| 574 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); | 579 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); |
| 575 wm::ActivateWindow(panel1.get()); | 580 wm::ActivateWindow(panel1.get()); |
| 576 wm::ActivateWindow(panel0.get()); | 581 wm::ActivateWindow(panel0.get()); |
| 577 wm::ActivateWindow(window1.get()); | 582 wm::ActivateWindow(window1.get()); |
| 578 wm::ActivateWindow(window0.get()); | 583 wm::ActivateWindow(window0.get()); |
| 579 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 584 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 580 | 585 |
| 581 // Cycling once highlights window2. | 586 // Cycling once highlights window2. |
| 582 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 587 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 583 | 588 |
| 584 // Panel 1 is the next item as the MRU panel, removing it should make panel 2 | 589 // Panel 1 is the next item as the MRU panel, removing it should make panel 2 |
| 585 // the next window to be selected. | 590 // the next window to be selected. |
| 586 panel0.reset(); | 591 panel0.reset(); |
| 587 // Cycling again should now select panel1. | 592 // Cycling again should now select panel1. |
| 588 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 593 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 589 controller->StopCycling(); | 594 controller->CompleteCycling(); |
| 590 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); | 595 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); |
| 591 } | 596 } |
| 592 | 597 |
| 593 // Tests that the tab key events are not sent to the window. | 598 // Tests that the tab key events are not sent to the window. |
| 594 TEST_F(WindowCycleControllerTest, TabKeyNotLeaked) { | 599 TEST_F(WindowCycleControllerTest, TabKeyNotLeaked) { |
| 595 std::unique_ptr<Window> w0(CreateTestWindowInShellWithId(0)); | 600 std::unique_ptr<Window> w0(CreateTestWindowInShellWithId(0)); |
| 596 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1)); | 601 std::unique_ptr<Window> w1(CreateTestWindowInShellWithId(1)); |
| 597 EventCounter event_count; | 602 EventCounter event_count; |
| 598 w0->AddPreTargetHandler(&event_count); | 603 w0->AddPreTargetHandler(&event_count); |
| 599 w1->AddPreTargetHandler(&event_count); | 604 w1->AddPreTargetHandler(&event_count); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 630 | 635 |
| 631 // Start cycling. | 636 // Start cycling. |
| 632 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 637 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); |
| 633 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 638 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 634 | 639 |
| 635 // Events don't get through. | 640 // Events don't get through. |
| 636 generator.ClickLeftButton(); | 641 generator.ClickLeftButton(); |
| 637 EXPECT_EQ(0, event_count.GetMouseEventCountAndReset()); | 642 EXPECT_EQ(0, event_count.GetMouseEventCountAndReset()); |
| 638 | 643 |
| 639 // Stop cycling: once again, events get through. | 644 // Stop cycling: once again, events get through. |
| 640 controller->StopCycling(); | 645 controller->CompleteCycling(); |
| 641 generator.ClickLeftButton(); | 646 generator.ClickLeftButton(); |
| 642 EXPECT_LT(0, event_count.GetMouseEventCountAndReset()); | 647 EXPECT_LT(0, event_count.GetMouseEventCountAndReset()); |
| 643 } | 648 } |
| 644 | 649 |
| 645 // If mouse capture is lost, the UI closes. | 650 // If mouse capture is lost, the UI closes. |
| 646 TEST_F(WindowCycleControllerTest, MouseCaptureLost) { | 651 TEST_F(WindowCycleControllerTest, MouseCaptureLost) { |
| 647 // This delegate allows the window to receive mouse events. | 652 // This delegate allows the window to receive mouse events. |
| 648 aura::test::TestWindowDelegate delegate; | 653 aura::test::TestWindowDelegate delegate; |
| 649 std::unique_ptr<Window> w0(CreateTestWindowInShellWithDelegate( | 654 std::unique_ptr<Window> w0(CreateTestWindowInShellWithDelegate( |
| 650 &delegate, 0, gfx::Rect(0, 0, 100, 100))); | 655 &delegate, 0, gfx::Rect(0, 0, 100, 100))); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 // without the new alt+tab selector we check for the event on either | 697 // without the new alt+tab selector we check for the event on either |
| 693 // fullscreen window. | 698 // fullscreen window. |
| 694 EventCounter event_count; | 699 EventCounter event_count; |
| 695 w0->AddPreTargetHandler(&event_count); | 700 w0->AddPreTargetHandler(&event_count); |
| 696 w1->AddPreTargetHandler(&event_count); | 701 w1->AddPreTargetHandler(&event_count); |
| 697 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); | 702 generator.PressKey(ui::VKEY_TAB, ui::EF_ALT_DOWN); |
| 698 EXPECT_EQ(1, event_count.GetKeyEventCountAndReset()); | 703 EXPECT_EQ(1, event_count.GetKeyEventCountAndReset()); |
| 699 } | 704 } |
| 700 | 705 |
| 701 } // namespace ash | 706 } // namespace ash |
| OLD | NEW |