| 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/common/focus_cycler.h" | 10 #include "ash/common/focus_cycler.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 test::TestShelfDelegate::instance()->AddShelfItem(WmWindow::Get(window)); | 105 test::TestShelfDelegate::instance()->AddShelfItem(WmWindow::Get(window)); |
| 106 shelf_view_test_->RunMessageLoopUntilAnimationsDone(); | 106 shelf_view_test_->RunMessageLoopUntilAnimationsDone(); |
| 107 return window; | 107 return window; |
| 108 } | 108 } |
| 109 | 109 |
| 110 const aura::Window::Windows GetWindows(WindowCycleController* controller) { | 110 const aura::Window::Windows GetWindows(WindowCycleController* controller) { |
| 111 return WmWindow::ToAuraWindows(controller->window_cycle_list()->windows()); | 111 return WmWindow::ToAuraWindows(controller->window_cycle_list()->windows()); |
| 112 } | 112 } |
| 113 | 113 |
| 114 const views::Widget* GetWindowCycleListWidget() const { | 114 const views::Widget* GetWindowCycleListWidget() const { |
| 115 return WmShell::Get() | 115 return Shell::Get() |
| 116 ->window_cycle_controller() | 116 ->window_cycle_controller() |
| 117 ->window_cycle_list() | 117 ->window_cycle_list() |
| 118 ->widget(); | 118 ->widget(); |
| 119 } | 119 } |
| 120 | 120 |
| 121 private: | 121 private: |
| 122 std::unique_ptr<test::ShelfViewTestAPI> shelf_view_test_; | 122 std::unique_ptr<test::ShelfViewTestAPI> shelf_view_test_; |
| 123 | 123 |
| 124 DISALLOW_COPY_AND_ASSIGN(WindowCycleControllerTest); | 124 DISALLOW_COPY_AND_ASSIGN(WindowCycleControllerTest); |
| 125 }; | 125 }; |
| 126 | 126 |
| 127 TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) { | 127 TEST_F(WindowCycleControllerTest, HandleCycleWindowBaseCases) { |
| 128 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 128 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 129 | 129 |
| 130 // Cycling doesn't crash if there are no windows. | 130 // Cycling doesn't crash if there are no windows. |
| 131 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 131 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 132 | 132 |
| 133 // Create a single test window. | 133 // Create a single test window. |
| 134 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 134 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 135 wm::ActivateWindow(window0.get()); | 135 wm::ActivateWindow(window0.get()); |
| 136 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 136 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 137 | 137 |
| 138 // Cycling works for a single window, even though nothing changes. | 138 // Cycling works for a single window, even though nothing changes. |
| 139 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 139 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 140 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 140 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 141 } | 141 } |
| 142 | 142 |
| 143 // Verifies if there is only one window and it isn't active that cycling | 143 // Verifies if there is only one window and it isn't active that cycling |
| 144 // activates it. | 144 // activates it. |
| 145 TEST_F(WindowCycleControllerTest, SingleWindowNotActive) { | 145 TEST_F(WindowCycleControllerTest, SingleWindowNotActive) { |
| 146 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 146 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 147 | 147 |
| 148 // Create a single test window. | 148 // Create a single test window. |
| 149 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 149 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 150 wm::ActivateWindow(window0.get()); | 150 wm::ActivateWindow(window0.get()); |
| 151 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 151 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 152 | 152 |
| 153 // Rotate focus, this should move focus to another window that isn't part of | 153 // Rotate focus, this should move focus to another window that isn't part of |
| 154 // the default container. | 154 // the default container. |
| 155 Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); | 155 Shell::Get()->focus_cycler()->RotateFocus(FocusCycler::FORWARD); |
| 156 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); | 156 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); |
| 157 | 157 |
| 158 // Cycling should activate the window. | 158 // Cycling should activate the window. |
| 159 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 159 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 160 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 160 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 161 } | 161 } |
| 162 | 162 |
| 163 TEST_F(WindowCycleControllerTest, HandleCycleWindow) { | 163 TEST_F(WindowCycleControllerTest, HandleCycleWindow) { |
| 164 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 164 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 165 | 165 |
| 166 // Set up several windows to use to test cycling. Create them in reverse | 166 // Set up several windows to use to test cycling. Create them in reverse |
| 167 // order so they are stacked 0 over 1 over 2. | 167 // order so they are stacked 0 over 1 over 2. |
| 168 std::unique_ptr<Window> window2(CreateTestWindowInShellWithId(2)); | 168 std::unique_ptr<Window> window2(CreateTestWindowInShellWithId(2)); |
| 169 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 169 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 170 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 170 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 171 wm::ActivateWindow(window0.get()); | 171 wm::ActivateWindow(window0.get()); |
| 172 | 172 |
| 173 // Simulate pressing and releasing Alt-tab. | 173 // Simulate pressing and releasing Alt-tab. |
| 174 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 174 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 TEST_F(WindowCycleControllerTest, MaximizedWindow) { | 266 TEST_F(WindowCycleControllerTest, MaximizedWindow) { |
| 267 // Create a couple of test windows. | 267 // Create a couple of test windows. |
| 268 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 268 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 269 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 269 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 270 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 270 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 271 window1_state->Maximize(); | 271 window1_state->Maximize(); |
| 272 window1_state->Activate(); | 272 window1_state->Activate(); |
| 273 EXPECT_TRUE(window1_state->IsActive()); | 273 EXPECT_TRUE(window1_state->IsActive()); |
| 274 | 274 |
| 275 // Rotate focus, this should move focus to window0. | 275 // Rotate focus, this should move focus to window0. |
| 276 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 276 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 277 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 277 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 278 controller->CompleteCycling(); | 278 controller->CompleteCycling(); |
| 279 EXPECT_TRUE(wm::GetWindowState(window0.get())->IsActive()); | 279 EXPECT_TRUE(wm::GetWindowState(window0.get())->IsActive()); |
| 280 EXPECT_FALSE(window1_state->IsActive()); | 280 EXPECT_FALSE(window1_state->IsActive()); |
| 281 | 281 |
| 282 // One more time. | 282 // One more time. |
| 283 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 283 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 284 controller->CompleteCycling(); | 284 controller->CompleteCycling(); |
| 285 EXPECT_TRUE(window1_state->IsActive()); | 285 EXPECT_TRUE(window1_state->IsActive()); |
| 286 } | 286 } |
| 287 | 287 |
| 288 // Cycles to a minimized window. | 288 // Cycles to a minimized window. |
| 289 TEST_F(WindowCycleControllerTest, Minimized) { | 289 TEST_F(WindowCycleControllerTest, Minimized) { |
| 290 // Create a couple of test windows. | 290 // Create a couple of test windows. |
| 291 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 291 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 292 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 292 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 293 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); | 293 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); |
| 294 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 294 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 295 | 295 |
| 296 window1_state->Minimize(); | 296 window1_state->Minimize(); |
| 297 window0_state->Activate(); | 297 window0_state->Activate(); |
| 298 EXPECT_TRUE(window0_state->IsActive()); | 298 EXPECT_TRUE(window0_state->IsActive()); |
| 299 | 299 |
| 300 // Rotate focus, this should move focus to window1 and unminimize it. | 300 // Rotate focus, this should move focus to window1 and unminimize it. |
| 301 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 301 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 302 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 302 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 303 controller->CompleteCycling(); | 303 controller->CompleteCycling(); |
| 304 EXPECT_FALSE(window0_state->IsActive()); | 304 EXPECT_FALSE(window0_state->IsActive()); |
| 305 EXPECT_FALSE(window1_state->IsMinimized()); | 305 EXPECT_FALSE(window1_state->IsMinimized()); |
| 306 EXPECT_TRUE(window1_state->IsActive()); | 306 EXPECT_TRUE(window1_state->IsActive()); |
| 307 | 307 |
| 308 // One more time back to w0. | 308 // One more time back to w0. |
| 309 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 309 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 310 controller->CompleteCycling(); | 310 controller->CompleteCycling(); |
| 311 EXPECT_TRUE(window0_state->IsActive()); | 311 EXPECT_TRUE(window0_state->IsActive()); |
| 312 } | 312 } |
| 313 | 313 |
| 314 // Tests that when all windows are minimized, cycling starts with the first one | 314 // Tests that when all windows are minimized, cycling starts with the first one |
| 315 // rather than the second. | 315 // rather than the second. |
| 316 TEST_F(WindowCycleControllerTest, AllAreMinimized) { | 316 TEST_F(WindowCycleControllerTest, AllAreMinimized) { |
| 317 // Create a couple of test windows. | 317 // Create a couple of test windows. |
| 318 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 318 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 319 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 319 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 320 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); | 320 wm::WindowState* window0_state = wm::GetWindowState(window0.get()); |
| 321 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); | 321 wm::WindowState* window1_state = wm::GetWindowState(window1.get()); |
| 322 | 322 |
| 323 window0_state->Minimize(); | 323 window0_state->Minimize(); |
| 324 window1_state->Minimize(); | 324 window1_state->Minimize(); |
| 325 | 325 |
| 326 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 326 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 327 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 327 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 328 controller->CompleteCycling(); | 328 controller->CompleteCycling(); |
| 329 EXPECT_TRUE(window0_state->IsActive()); | 329 EXPECT_TRUE(window0_state->IsActive()); |
| 330 EXPECT_FALSE(window0_state->IsMinimized()); | 330 EXPECT_FALSE(window0_state->IsMinimized()); |
| 331 EXPECT_TRUE(window1_state->IsMinimized()); | 331 EXPECT_TRUE(window1_state->IsMinimized()); |
| 332 | 332 |
| 333 // But it's business as usual when cycling backwards. | 333 // But it's business as usual when cycling backwards. |
| 334 window0_state->Minimize(); | 334 window0_state->Minimize(); |
| 335 window1_state->Minimize(); | 335 window1_state->Minimize(); |
| 336 controller->HandleCycleWindow(WindowCycleController::BACKWARD); | 336 controller->HandleCycleWindow(WindowCycleController::BACKWARD); |
| 337 controller->CompleteCycling(); | 337 controller->CompleteCycling(); |
| 338 EXPECT_TRUE(window0_state->IsMinimized()); | 338 EXPECT_TRUE(window0_state->IsMinimized()); |
| 339 EXPECT_TRUE(window1_state->IsActive()); | 339 EXPECT_TRUE(window1_state->IsActive()); |
| 340 EXPECT_FALSE(window1_state->IsMinimized()); | 340 EXPECT_FALSE(window1_state->IsMinimized()); |
| 341 } | 341 } |
| 342 | 342 |
| 343 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) { | 343 TEST_F(WindowCycleControllerTest, AlwaysOnTopWindow) { |
| 344 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 344 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 345 | 345 |
| 346 // Set up several windows to use to test cycling. | 346 // Set up several windows to use to test cycling. |
| 347 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 347 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 348 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 348 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 349 | 349 |
| 350 Window* top_container = Shell::GetContainer( | 350 Window* top_container = Shell::GetContainer( |
| 351 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); | 351 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); |
| 352 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); | 352 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); |
| 353 wm::ActivateWindow(window0.get()); | 353 wm::ActivateWindow(window0.get()); |
| 354 | 354 |
| 355 // Simulate pressing and releasing Alt-tab. | 355 // Simulate pressing and releasing Alt-tab. |
| 356 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 356 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 357 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 357 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 358 | 358 |
| 359 // Window lists should return the topmost window in front. | 359 // Window lists should return the topmost window in front. |
| 360 ASSERT_TRUE(controller->window_cycle_list()); | 360 ASSERT_TRUE(controller->window_cycle_list()); |
| 361 ASSERT_EQ(3u, GetWindows(controller).size()); | 361 ASSERT_EQ(3u, GetWindows(controller).size()); |
| 362 EXPECT_EQ(window0.get(), GetWindows(controller)[0]); | 362 EXPECT_EQ(window0.get(), GetWindows(controller)[0]); |
| 363 EXPECT_EQ(window2.get(), GetWindows(controller)[1]); | 363 EXPECT_EQ(window2.get(), GetWindows(controller)[1]); |
| 364 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); | 364 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); |
| 365 | 365 |
| 366 controller->CompleteCycling(); | 366 controller->CompleteCycling(); |
| 367 } | 367 } |
| 368 | 368 |
| 369 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultiWindow) { | 369 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultiWindow) { |
| 370 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 370 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 371 | 371 |
| 372 // Set up several windows to use to test cycling. | 372 // Set up several windows to use to test cycling. |
| 373 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 373 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 374 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 374 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 375 | 375 |
| 376 Window* top_container = Shell::GetContainer( | 376 Window* top_container = Shell::GetContainer( |
| 377 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); | 377 Shell::GetPrimaryRootWindow(), kShellWindowId_AlwaysOnTopContainer); |
| 378 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); | 378 std::unique_ptr<Window> window2(CreateTestWindowWithId(2, top_container)); |
| 379 std::unique_ptr<Window> window3(CreateTestWindowWithId(3, top_container)); | 379 std::unique_ptr<Window> window3(CreateTestWindowWithId(3, top_container)); |
| 380 wm::ActivateWindow(window0.get()); | 380 wm::ActivateWindow(window0.get()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 393 | 393 |
| 394 controller->CompleteCycling(); | 394 controller->CompleteCycling(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultipleRootWindows) { | 397 TEST_F(WindowCycleControllerTest, AlwaysOnTopMultipleRootWindows) { |
| 398 // Set up a second root window | 398 // Set up a second root window |
| 399 UpdateDisplay("1000x600,600x400"); | 399 UpdateDisplay("1000x600,600x400"); |
| 400 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 400 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 401 ASSERT_EQ(2U, root_windows.size()); | 401 ASSERT_EQ(2U, root_windows.size()); |
| 402 | 402 |
| 403 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 403 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 404 | 404 |
| 405 // Create two windows in the primary root. | 405 // Create two windows in the primary root. |
| 406 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 406 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 407 EXPECT_EQ(root_windows[0], window0->GetRootWindow()); | 407 EXPECT_EQ(root_windows[0], window0->GetRootWindow()); |
| 408 Window* top_container0 = | 408 Window* top_container0 = |
| 409 Shell::GetContainer(root_windows[0], kShellWindowId_AlwaysOnTopContainer); | 409 Shell::GetContainer(root_windows[0], kShellWindowId_AlwaysOnTopContainer); |
| 410 std::unique_ptr<Window> window1(CreateTestWindowWithId(1, top_container0)); | 410 std::unique_ptr<Window> window1(CreateTestWindowWithId(1, top_container0)); |
| 411 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); | 411 EXPECT_EQ(root_windows[0], window1->GetRootWindow()); |
| 412 | 412 |
| 413 // Move the active root window to the secondary root and create two windows. | 413 // Move the active root window to the secondary root and create two windows. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 437 ASSERT_EQ(4u, GetWindows(controller).size()); | 437 ASSERT_EQ(4u, GetWindows(controller).size()); |
| 438 EXPECT_EQ(window2.get(), GetWindows(controller)[0]); | 438 EXPECT_EQ(window2.get(), GetWindows(controller)[0]); |
| 439 EXPECT_EQ(window3.get(), GetWindows(controller)[1]); | 439 EXPECT_EQ(window3.get(), GetWindows(controller)[1]); |
| 440 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); | 440 EXPECT_EQ(window1.get(), GetWindows(controller)[2]); |
| 441 EXPECT_EQ(window0.get(), GetWindows(controller)[3]); | 441 EXPECT_EQ(window0.get(), GetWindows(controller)[3]); |
| 442 | 442 |
| 443 controller->CompleteCycling(); | 443 controller->CompleteCycling(); |
| 444 } | 444 } |
| 445 | 445 |
| 446 TEST_F(WindowCycleControllerTest, MostRecentlyUsed) { | 446 TEST_F(WindowCycleControllerTest, MostRecentlyUsed) { |
| 447 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 447 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 448 | 448 |
| 449 // Set up several windows to use to test cycling. | 449 // Set up several windows to use to test cycling. |
| 450 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); | 450 std::unique_ptr<Window> window0(CreateTestWindowInShellWithId(0)); |
| 451 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); | 451 std::unique_ptr<Window> window1(CreateTestWindowInShellWithId(1)); |
| 452 std::unique_ptr<Window> window2(CreateTestWindowInShellWithId(2)); | 452 std::unique_ptr<Window> window2(CreateTestWindowInShellWithId(2)); |
| 453 | 453 |
| 454 wm::ActivateWindow(window0.get()); | 454 wm::ActivateWindow(window0.get()); |
| 455 | 455 |
| 456 // Simulate pressing and releasing Alt-tab. | 456 // Simulate pressing and releasing Alt-tab. |
| 457 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 457 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 481 | 481 |
| 482 // Tests that beginning window selection hides the app list. | 482 // Tests that beginning window selection hides the app list. |
| 483 TEST_F(WindowCycleControllerTest, SelectingHidesAppList) { | 483 TEST_F(WindowCycleControllerTest, SelectingHidesAppList) { |
| 484 // TODO: fails in mash because of AppListPresenter. http://crbug.com/696028. | 484 // TODO: fails in mash because of AppListPresenter. http://crbug.com/696028. |
| 485 if (WmShell::Get()->IsRunningInMash()) | 485 if (WmShell::Get()->IsRunningInMash()) |
| 486 return; | 486 return; |
| 487 | 487 |
| 488 // The tested behavior relies on the app list presenter implementation. | 488 // The tested behavior relies on the app list presenter implementation. |
| 489 test::TestAppListViewPresenterImpl app_list_presenter_impl; | 489 test::TestAppListViewPresenterImpl app_list_presenter_impl; |
| 490 | 490 |
| 491 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 491 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 492 | 492 |
| 493 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 493 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 494 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 494 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 495 app_list_presenter_impl.Show(display_manager()->first_display_id()); | 495 app_list_presenter_impl.Show(display_manager()->first_display_id()); |
| 496 EXPECT_TRUE(app_list_presenter_impl.IsVisible()); | 496 EXPECT_TRUE(app_list_presenter_impl.IsVisible()); |
| 497 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 497 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 498 EXPECT_FALSE(app_list_presenter_impl.IsVisible()); | 498 EXPECT_FALSE(app_list_presenter_impl.IsVisible()); |
| 499 | 499 |
| 500 // Make sure that dismissing the app list this way doesn't pass activation | 500 // Make sure that dismissing the app list this way doesn't pass activation |
| 501 // to a different window. | 501 // to a different window. |
| 502 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); | 502 EXPECT_FALSE(wm::IsActiveWindow(window0.get())); |
| 503 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); | 503 EXPECT_FALSE(wm::IsActiveWindow(window1.get())); |
| 504 | 504 |
| 505 controller->CompleteCycling(); | 505 controller->CompleteCycling(); |
| 506 } | 506 } |
| 507 | 507 |
| 508 // Tests that cycling through windows doesn't change their minimized state. | 508 // Tests that cycling through windows doesn't change their minimized state. |
| 509 TEST_F(WindowCycleControllerTest, CyclePreservesMinimization) { | 509 TEST_F(WindowCycleControllerTest, CyclePreservesMinimization) { |
| 510 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 510 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 511 | 511 |
| 512 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 512 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 513 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 513 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 514 wm::ActivateWindow(window1.get()); | 514 wm::ActivateWindow(window1.get()); |
| 515 wm::GetWindowState(window1.get())->Minimize(); | 515 wm::GetWindowState(window1.get())->Minimize(); |
| 516 wm::ActivateWindow(window0.get()); | 516 wm::ActivateWindow(window0.get()); |
| 517 EXPECT_TRUE(IsWindowMinimized(window1.get())); | 517 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 518 | 518 |
| 519 // On window 2. | 519 // On window 2. |
| 520 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 520 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 521 EXPECT_TRUE(IsWindowMinimized(window1.get())); | 521 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 522 | 522 |
| 523 // Back on window 1. | 523 // Back on window 1. |
| 524 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 524 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 525 EXPECT_TRUE(IsWindowMinimized(window1.get())); | 525 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 526 | 526 |
| 527 controller->CompleteCycling(); | 527 controller->CompleteCycling(); |
| 528 | 528 |
| 529 EXPECT_TRUE(IsWindowMinimized(window1.get())); | 529 EXPECT_TRUE(IsWindowMinimized(window1.get())); |
| 530 } | 530 } |
| 531 | 531 |
| 532 // Tests cycles between panel and normal windows. | 532 // Tests cycles between panel and normal windows. |
| 533 TEST_F(WindowCycleControllerTest, CyclePanels) { | 533 TEST_F(WindowCycleControllerTest, CyclePanels) { |
| 534 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 534 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 535 | 535 |
| 536 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 536 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 537 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); | 537 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); |
| 538 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); | 538 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); |
| 539 wm::ActivateWindow(window0.get()); | 539 wm::ActivateWindow(window0.get()); |
| 540 wm::ActivateWindow(panel1.get()); | 540 wm::ActivateWindow(panel1.get()); |
| 541 wm::ActivateWindow(panel0.get()); | 541 wm::ActivateWindow(panel0.get()); |
| 542 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); | 542 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); |
| 543 | 543 |
| 544 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 544 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 545 controller->CompleteCycling(); | 545 controller->CompleteCycling(); |
| 546 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); | 546 EXPECT_TRUE(wm::IsActiveWindow(panel1.get())); |
| 547 | 547 |
| 548 // Cycling again should select the most recently used panel. | 548 // Cycling again should select the most recently used panel. |
| 549 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 549 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 550 controller->CompleteCycling(); | 550 controller->CompleteCycling(); |
| 551 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); | 551 EXPECT_TRUE(wm::IsActiveWindow(panel0.get())); |
| 552 | 552 |
| 553 // Cycling twice again should select the first window. | 553 // Cycling twice again should select the first window. |
| 554 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 554 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 555 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 555 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 556 controller->CompleteCycling(); | 556 controller->CompleteCycling(); |
| 557 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 557 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 558 } | 558 } |
| 559 | 559 |
| 560 // Tests cycles between panel and normal windows. | 560 // Tests cycles between panel and normal windows. |
| 561 TEST_F(WindowCycleControllerTest, CyclePanelsDestroyed) { | 561 TEST_F(WindowCycleControllerTest, CyclePanelsDestroyed) { |
| 562 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 562 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 563 | 563 |
| 564 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 564 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 565 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 565 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 566 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(2)); | 566 std::unique_ptr<aura::Window> window2(CreateTestWindowInShellWithId(2)); |
| 567 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); | 567 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); |
| 568 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); | 568 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); |
| 569 wm::ActivateWindow(window2.get()); | 569 wm::ActivateWindow(window2.get()); |
| 570 wm::ActivateWindow(panel1.get()); | 570 wm::ActivateWindow(panel1.get()); |
| 571 wm::ActivateWindow(panel0.get()); | 571 wm::ActivateWindow(panel0.get()); |
| 572 wm::ActivateWindow(window1.get()); | 572 wm::ActivateWindow(window1.get()); |
| 573 wm::ActivateWindow(window0.get()); | 573 wm::ActivateWindow(window0.get()); |
| 574 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 574 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| 575 | 575 |
| 576 // Cycling once highlights window2. | 576 // Cycling once highlights window2. |
| 577 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 577 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 578 // All panels are destroyed. | 578 // All panels are destroyed. |
| 579 panel0.reset(); | 579 panel0.reset(); |
| 580 panel1.reset(); | 580 panel1.reset(); |
| 581 // Cycling again should now select window2. | 581 // Cycling again should now select window2. |
| 582 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 582 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 583 controller->CompleteCycling(); | 583 controller->CompleteCycling(); |
| 584 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); | 584 EXPECT_TRUE(wm::IsActiveWindow(window2.get())); |
| 585 } | 585 } |
| 586 | 586 |
| 587 // Tests cycles between panel and normal windows. | 587 // Tests cycles between panel and normal windows. |
| 588 TEST_F(WindowCycleControllerTest, CycleMruPanelDestroyed) { | 588 TEST_F(WindowCycleControllerTest, CycleMruPanelDestroyed) { |
| 589 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 589 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 590 | 590 |
| 591 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); | 591 std::unique_ptr<aura::Window> window0(CreateTestWindowInShellWithId(0)); |
| 592 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); | 592 std::unique_ptr<aura::Window> window1(CreateTestWindowInShellWithId(1)); |
| 593 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); | 593 std::unique_ptr<aura::Window> panel0(CreatePanelWindow()); |
| 594 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); | 594 std::unique_ptr<aura::Window> panel1(CreatePanelWindow()); |
| 595 wm::ActivateWindow(panel1.get()); | 595 wm::ActivateWindow(panel1.get()); |
| 596 wm::ActivateWindow(panel0.get()); | 596 wm::ActivateWindow(panel0.get()); |
| 597 wm::ActivateWindow(window1.get()); | 597 wm::ActivateWindow(window1.get()); |
| 598 wm::ActivateWindow(window0.get()); | 598 wm::ActivateWindow(window0.get()); |
| 599 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); | 599 EXPECT_TRUE(wm::IsActiveWindow(window0.get())); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 w1->SetTargetHandler(&event_count); | 650 w1->SetTargetHandler(&event_count); |
| 651 ui::test::EventGenerator& generator = GetEventGenerator(); | 651 ui::test::EventGenerator& generator = GetEventGenerator(); |
| 652 wm::ActivateWindow(w0.get()); | 652 wm::ActivateWindow(w0.get()); |
| 653 | 653 |
| 654 // Events get through. | 654 // Events get through. |
| 655 generator.MoveMouseToCenterOf(w0.get()); | 655 generator.MoveMouseToCenterOf(w0.get()); |
| 656 generator.ClickLeftButton(); | 656 generator.ClickLeftButton(); |
| 657 EXPECT_LT(0, event_count.GetMouseEventCountAndReset()); | 657 EXPECT_LT(0, event_count.GetMouseEventCountAndReset()); |
| 658 | 658 |
| 659 // Start cycling. | 659 // Start cycling. |
| 660 WindowCycleController* controller = WmShell::Get()->window_cycle_controller(); | 660 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 661 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 661 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 662 | 662 |
| 663 // Most mouse events don't get through. | 663 // Most mouse events don't get through. |
| 664 generator.PressLeftButton(); | 664 generator.PressLeftButton(); |
| 665 EXPECT_EQ(0, event_count.GetMouseEventCountAndReset()); | 665 EXPECT_EQ(0, event_count.GetMouseEventCountAndReset()); |
| 666 | 666 |
| 667 // Although releases do. | 667 // Although releases do. |
| 668 generator.ReleaseLeftButton(); | 668 generator.ReleaseLeftButton(); |
| 669 EXPECT_LT(0, event_count.GetMouseEventCountAndReset()); | 669 EXPECT_LT(0, event_count.GetMouseEventCountAndReset()); |
| 670 | 670 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 gfx::Rect second_display_bounds = | 742 gfx::Rect second_display_bounds = |
| 743 display_manager()->GetDisplayAt(1).bounds(); | 743 display_manager()->GetDisplayAt(1).bounds(); |
| 744 std::unique_ptr<Window> window0( | 744 std::unique_ptr<Window> window0( |
| 745 CreateTestWindowInShellWithBounds(second_display_bounds)); | 745 CreateTestWindowInShellWithBounds(second_display_bounds)); |
| 746 // Activate this window so that the secondary display becomes the one where | 746 // Activate this window so that the secondary display becomes the one where |
| 747 // the Alt+Tab UI is shown. | 747 // the Alt+Tab UI is shown. |
| 748 wm::ActivateWindow(window0.get()); | 748 wm::ActivateWindow(window0.get()); |
| 749 std::unique_ptr<Window> window1( | 749 std::unique_ptr<Window> window1( |
| 750 CreateTestWindowInShellWithBounds(second_display_bounds)); | 750 CreateTestWindowInShellWithBounds(second_display_bounds)); |
| 751 | 751 |
| 752 WindowCycleController* controller = | 752 WindowCycleController* controller = Shell::Get()->window_cycle_controller(); |
| 753 WmShell::Get()->window_cycle_controller(); | |
| 754 controller->HandleCycleWindow(WindowCycleController::FORWARD); | 753 controller->HandleCycleWindow(WindowCycleController::FORWARD); |
| 755 | 754 |
| 756 const gfx::Rect bounds = | 755 const gfx::Rect bounds = |
| 757 GetWindowCycleListWidget()->GetWindowBoundsInScreen(); | 756 GetWindowCycleListWidget()->GetWindowBoundsInScreen(); |
| 758 EXPECT_TRUE(second_display_bounds.Contains(bounds)); | 757 EXPECT_TRUE(second_display_bounds.Contains(bounds)); |
| 759 EXPECT_FALSE( | 758 EXPECT_FALSE( |
| 760 display_manager()->GetDisplayAt(0).bounds().Intersects(bounds)); | 759 display_manager()->GetDisplayAt(0).bounds().Intersects(bounds)); |
| 761 const gfx::Rect display_relative_bounds = | 760 const gfx::Rect display_relative_bounds = |
| 762 bounds - second_display_bounds.OffsetFromOrigin(); | 761 bounds - second_display_bounds.OffsetFromOrigin(); |
| 763 // Base case sets the expectation for other cases. | 762 // Base case sets the expectation for other cases. |
| 764 if (expected_bounds.IsEmpty()) | 763 if (expected_bounds.IsEmpty()) |
| 765 expected_bounds = display_relative_bounds; | 764 expected_bounds = display_relative_bounds; |
| 766 else | 765 else |
| 767 EXPECT_EQ(expected_bounds, display_relative_bounds); | 766 EXPECT_EQ(expected_bounds, display_relative_bounds); |
| 768 controller->CompleteCycling(); | 767 controller->CompleteCycling(); |
| 769 } | 768 } |
| 770 } | 769 } |
| 771 | 770 |
| 772 } // namespace ash | 771 } // namespace ash |
| OLD | NEW |