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/wm/window_cycle_controller.h" | 5 #include "ash/wm/window_cycle_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
| 9 #include "ash/display/display_controller.h" |
| 10 #include "ash/display/multi_display_manager.h" |
9 #include "ash/shell.h" | 11 #include "ash/shell.h" |
10 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
11 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
12 #include "ash/test/test_shell_delegate.h" | 14 #include "ash/test/test_shell_delegate.h" |
13 #include "ash/wm/window_cycle_list.h" | 15 #include "ash/wm/window_cycle_list.h" |
14 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
15 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "ui/aura/env.h" |
16 #include "ui/aura/test/test_windows.h" | 19 #include "ui/aura/test/test_windows.h" |
17 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
18 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
19 | 22 |
20 namespace ash { | 23 namespace ash { |
21 | 24 |
22 namespace { | 25 namespace { |
23 | 26 |
24 using aura::test::CreateTestWindowWithId; | 27 using aura::test::CreateTestWindowWithId; |
25 using aura::test::TestWindowDelegate; | 28 using aura::test::TestWindowDelegate; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 Shell::GetInstance()->window_cycle_controller(); | 233 Shell::GetInstance()->window_cycle_controller(); |
231 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); | 234 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
232 EXPECT_FALSE(wm::IsWindowMinimized(window1.get())); | 235 EXPECT_FALSE(wm::IsWindowMinimized(window1.get())); |
233 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); | 236 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
234 | 237 |
235 // One more time back to w0. | 238 // One more time back to w0. |
236 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); | 239 controller->HandleCycleWindow(WindowCycleController::FORWARD, false); |
237 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 240 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
238 } | 241 } |
239 | 242 |
| 243 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) { |
| 244 WindowCycleController* controller = |
| 245 Shell::GetInstance()->window_cycle_controller(); |
| 246 |
| 247 // Set up several windows to use to test cycling. |
| 248 Window* default_container = |
| 249 Shell::GetContainer( |
| 250 Shell::GetPrimaryRootWindow(), |
| 251 internal::kShellWindowId_DefaultContainer); |
| 252 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); |
| 253 scoped_ptr<Window> window1(CreateTestWindowWithId(1, default_container)); |
| 254 |
| 255 Window* top_container = |
| 256 Shell::GetContainer( |
| 257 Shell::GetPrimaryRootWindow(), |
| 258 internal::kShellWindowId_AlwaysOnTopContainer); |
| 259 scoped_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); |
| 260 wm::ActivateWindow(window0.get()); |
| 261 |
| 262 // Simulate pressing and releasing Alt-tab. |
| 263 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 264 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 265 |
| 266 // Window lists should return the topmost window in front. |
| 267 ASSERT_TRUE(controller->windows()); |
| 268 ASSERT_EQ(3u, controller->windows()->windows().size()); |
| 269 EXPECT_EQ(window0.get(), controller->windows()->windows()[0]); |
| 270 EXPECT_EQ(window2.get(), controller->windows()->windows()[1]); |
| 271 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); |
| 272 |
| 273 controller->AltKeyReleased(); |
| 274 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 275 |
| 276 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 277 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 278 |
| 279 controller->AltKeyReleased(); |
| 280 |
| 281 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 282 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 283 |
| 284 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 285 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 286 |
| 287 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 288 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 289 } |
| 290 |
| 291 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultiWindow) { |
| 292 WindowCycleController* controller = |
| 293 Shell::GetInstance()->window_cycle_controller(); |
| 294 |
| 295 // Set up several windows to use to test cycling. |
| 296 Window* default_container = |
| 297 Shell::GetContainer( |
| 298 Shell::GetPrimaryRootWindow(), |
| 299 internal::kShellWindowId_DefaultContainer); |
| 300 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); |
| 301 scoped_ptr<Window> window1(CreateTestWindowWithId(1, default_container)); |
| 302 |
| 303 Window* top_container = |
| 304 Shell::GetContainer( |
| 305 Shell::GetPrimaryRootWindow(), |
| 306 internal::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, true); |
| 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, true); |
| 327 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 328 |
| 329 controller->AltKeyReleased(); |
| 330 |
| 331 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 332 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 333 |
| 334 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 335 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 336 |
| 337 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 338 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 339 |
| 340 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 341 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 342 } |
| 343 |
| 344 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultipleRootWindows) { |
| 345 // Set up a second root window |
| 346 UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
| 347 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 348 ASSERT_EQ(2U, root_windows.size()); |
| 349 |
| 350 // Move the active root window to the secondary. |
| 351 Shell::GetInstance()->set_active_root_window(root_windows[1]); |
| 352 |
| 353 WindowCycleController* controller = |
| 354 Shell::GetInstance()->window_cycle_controller(); |
| 355 |
| 356 // Set up several windows to use to test cycling. |
| 357 Window* default_container0 = |
| 358 Shell::GetContainer( |
| 359 root_windows[0], |
| 360 internal::kShellWindowId_DefaultContainer); |
| 361 scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container0)); |
| 362 |
| 363 Window* top_container0 = |
| 364 Shell::GetContainer( |
| 365 root_windows[0], |
| 366 internal::kShellWindowId_AlwaysOnTopContainer); |
| 367 scoped_ptr<Window> window1(CreateTestWindowWithId(1, top_container0)); |
| 368 |
| 369 // Set up several windows to use to test cycling. |
| 370 Window* default_container1 = |
| 371 Shell::GetContainer( |
| 372 root_windows[1], |
| 373 internal::kShellWindowId_DefaultContainer); |
| 374 scoped_ptr<Window> window2(CreateTestWindowWithId(2, default_container1)); |
| 375 |
| 376 Window* top_container1 = |
| 377 Shell::GetContainer( |
| 378 root_windows[1], |
| 379 internal::kShellWindowId_AlwaysOnTopContainer); |
| 380 scoped_ptr<Window> window3(CreateTestWindowWithId(3, top_container1)); |
| 381 |
| 382 |
| 383 wm::ActivateWindow(window2.get()); |
| 384 |
| 385 // Simulate pressing and releasing Alt-tab. |
| 386 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 387 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 388 |
| 389 // Window lists should return the topmost window in front. |
| 390 ASSERT_TRUE(controller->windows()); |
| 391 ASSERT_EQ(4u, controller->windows()->windows().size()); |
| 392 EXPECT_EQ(window2.get(), controller->windows()->windows()[0]); |
| 393 EXPECT_EQ(window3.get(), controller->windows()->windows()[1]); |
| 394 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); |
| 395 EXPECT_EQ(window0.get(), controller->windows()->windows()[3]); |
| 396 |
| 397 controller->AltKeyReleased(); |
| 398 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 399 |
| 400 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 401 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 402 |
| 403 controller->AltKeyReleased(); |
| 404 |
| 405 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 406 EXPECT_TRUE(wm::IsActiveWindow(window3.get())); |
| 407 |
| 408 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 409 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 410 |
| 411 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 412 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 413 |
| 414 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 415 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 416 } |
| 417 |
| 418 TEST_F(WindowCycleControllerTest, MostRecentlyUsed) { |
| 419 WindowCycleController* controller = |
| 420 Shell::GetInstance()->window_cycle_controller(); |
| 421 |
| 422 // Set up several windows to use to test cycling. |
| 423 Window* container = |
| 424 Shell::GetContainer( |
| 425 Shell::GetPrimaryRootWindow(), |
| 426 internal::kShellWindowId_DefaultContainer); |
| 427 scoped_ptr<Window> window0(CreateTestWindowWithId(0, container)); |
| 428 scoped_ptr<Window> window1(CreateTestWindowWithId(1, container)); |
| 429 scoped_ptr<Window> window2(CreateTestWindowWithId(2, container)); |
| 430 |
| 431 wm::ActivateWindow(window0.get()); |
| 432 |
| 433 // Simulate pressing and releasing Alt-tab. |
| 434 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 435 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 436 |
| 437 // Window lists should return the topmost window in front. |
| 438 ASSERT_TRUE(controller->windows()); |
| 439 ASSERT_EQ(3u, controller->windows()->windows().size()); |
| 440 EXPECT_EQ(window0.get(), controller->windows()->windows()[0]); |
| 441 EXPECT_EQ(window2.get(), controller->windows()->windows()[1]); |
| 442 EXPECT_EQ(window1.get(), controller->windows()->windows()[2]); |
| 443 |
| 444 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 445 controller->AltKeyReleased(); |
| 446 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 447 |
| 448 |
| 449 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 450 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 451 |
| 452 controller->AltKeyReleased(); |
| 453 |
| 454 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 455 EXPECT_TRUE(wm::IsActiveWindow(window1.get())); |
| 456 |
| 457 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 458 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 459 |
| 460 controller->HandleCycleWindow(WindowCycleController::FORWARD, true); |
| 461 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 462 } |
| 463 |
240 } // namespace | 464 } // namespace |
241 | 465 |
242 } // namespace ash | 466 } // namespace ash |
OLD | NEW |